MessageHandler.c 991 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181318231833184318531863187318831893190319131923193319431953196319731983199320032013202320332043205320632073208320932103211321232133214321532163217321832193220322132223223322432253226322732283229323032313232323332343235323632373238323932403241324232433244324532463247324832493250325132523253325432553256325732583259326032613262326332643265326632673268326932703271327232733274327532763277327832793280328132823283328432853286328732883289329032913292329332943295329632973298329933003301330233033304330533063307330833093310331133123313331433153316331733183319332033213322332333243325332633273328332933303331333233333334333533363337333833393340334133423343334433453346334733483349335033513352335333543355335633573358335933603361336233633364336533663367336833693370337133723373337433753376337733783379338033813382338333843385338633873388338933903391339233933394339533963397339833993400340134023403340434053406340734083409341034113412341334143415341634173418341934203421342234233424342534263427342834293430343134323433343434353436343734383439344034413442344334443445344634473448344934503451345234533454345534563457345834593460346134623463346434653466346734683469347034713472347334743475347634773478347934803481348234833484348534863487348834893490349134923493349434953496349734983499350035013502350335043505350635073508350935103511351235133514351535163517351835193520352135223523352435253526352735283529353035313532353335343535353635373538353935403541354235433544354535463547354835493550355135523553355435553556355735583559356035613562356335643565356635673568356935703571357235733574357535763577357835793580358135823583358435853586358735883589359035913592359335943595359635973598359936003601360236033604360536063607360836093610361136123613361436153616361736183619362036213622362336243625362636273628362936303631363236333634363536363637363836393640364136423643364436453646364736483649365036513652365336543655365636573658365936603661366236633664366536663667366836693670367136723673367436753676367736783679368036813682368336843685368636873688368936903691369236933694369536963697369836993700370137023703370437053706370737083709371037113712371337143715371637173718371937203721372237233724372537263727372837293730373137323733373437353736373737383739374037413742374337443745374637473748374937503751375237533754375537563757375837593760376137623763376437653766376737683769377037713772377337743775377637773778377937803781378237833784378537863787378837893790379137923793379437953796379737983799380038013802380338043805380638073808380938103811381238133814381538163817381838193820382138223823382438253826382738283829383038313832383338343835383638373838383938403841384238433844384538463847384838493850385138523853385438553856385738583859386038613862386338643865386638673868386938703871387238733874387538763877387838793880388138823883388438853886388738883889389038913892389338943895389638973898389939003901390239033904390539063907390839093910391139123913391439153916391739183919392039213922392339243925392639273928392939303931393239333934393539363937393839393940394139423943394439453946394739483949395039513952395339543955395639573958395939603961396239633964396539663967396839693970397139723973397439753976397739783979398039813982398339843985398639873988398939903991399239933994399539963997399839994000400140024003400440054006400740084009401040114012401340144015401640174018401940204021402240234024402540264027402840294030403140324033403440354036403740384039404040414042404340444045404640474048404940504051405240534054405540564057405840594060406140624063406440654066406740684069407040714072407340744075407640774078407940804081408240834084408540864087408840894090409140924093409440954096409740984099410041014102410341044105410641074108410941104111411241134114411541164117411841194120412141224123412441254126412741284129413041314132413341344135413641374138413941404141414241434144414541464147414841494150415141524153415441554156415741584159416041614162416341644165416641674168416941704171417241734174417541764177417841794180418141824183418441854186418741884189419041914192419341944195419641974198419942004201420242034204420542064207420842094210421142124213421442154216421742184219422042214222422342244225422642274228422942304231423242334234423542364237423842394240424142424243424442454246424742484249425042514252425342544255425642574258425942604261426242634264426542664267426842694270427142724273427442754276427742784279428042814282428342844285428642874288428942904291429242934294429542964297429842994300430143024303430443054306430743084309431043114312431343144315431643174318431943204321432243234324432543264327432843294330433143324333433443354336433743384339434043414342434343444345434643474348434943504351435243534354435543564357435843594360436143624363436443654366436743684369437043714372437343744375437643774378437943804381438243834384438543864387438843894390439143924393439443954396439743984399440044014402440344044405440644074408440944104411441244134414441544164417441844194420442144224423442444254426442744284429443044314432443344344435443644374438443944404441444244434444444544464447444844494450445144524453445444554456445744584459446044614462446344644465446644674468446944704471447244734474447544764477447844794480448144824483448444854486448744884489449044914492449344944495449644974498449945004501450245034504450545064507450845094510451145124513451445154516451745184519452045214522452345244525452645274528452945304531453245334534453545364537453845394540454145424543454445454546454745484549455045514552455345544555455645574558455945604561456245634564456545664567456845694570457145724573457445754576457745784579458045814582458345844585458645874588458945904591459245934594459545964597459845994600460146024603460446054606460746084609461046114612461346144615461646174618461946204621462246234624462546264627462846294630463146324633463446354636463746384639464046414642464346444645464646474648464946504651465246534654465546564657465846594660466146624663466446654666466746684669467046714672467346744675467646774678467946804681468246834684468546864687468846894690469146924693469446954696469746984699470047014702470347044705470647074708470947104711471247134714471547164717471847194720472147224723472447254726472747284729473047314732473347344735473647374738473947404741474247434744474547464747474847494750475147524753475447554756475747584759476047614762476347644765476647674768476947704771477247734774477547764777477847794780478147824783478447854786478747884789479047914792479347944795479647974798479948004801480248034804480548064807480848094810481148124813481448154816481748184819482048214822482348244825482648274828482948304831483248334834483548364837483848394840484148424843484448454846484748484849485048514852485348544855485648574858485948604861486248634864486548664867486848694870487148724873487448754876487748784879488048814882488348844885488648874888488948904891489248934894489548964897489848994900490149024903490449054906490749084909491049114912491349144915491649174918491949204921492249234924492549264927492849294930493149324933493449354936493749384939494049414942494349444945494649474948494949504951495249534954495549564957495849594960496149624963496449654966496749684969497049714972497349744975497649774978497949804981498249834984498549864987498849894990499149924993499449954996499749984999500050015002500350045005500650075008500950105011501250135014501550165017501850195020502150225023502450255026502750285029503050315032503350345035503650375038503950405041504250435044504550465047504850495050505150525053505450555056505750585059506050615062506350645065506650675068506950705071507250735074507550765077507850795080508150825083508450855086508750885089509050915092509350945095509650975098509951005101510251035104510551065107510851095110511151125113511451155116511751185119512051215122512351245125512651275128512951305131513251335134513551365137513851395140514151425143514451455146514751485149515051515152515351545155515651575158515951605161516251635164516551665167516851695170517151725173517451755176517751785179518051815182518351845185518651875188518951905191519251935194519551965197519851995200520152025203520452055206520752085209521052115212521352145215521652175218521952205221522252235224522552265227522852295230523152325233523452355236523752385239524052415242524352445245524652475248524952505251525252535254525552565257525852595260526152625263526452655266526752685269527052715272527352745275527652775278527952805281528252835284528552865287528852895290529152925293529452955296529752985299530053015302530353045305530653075308530953105311531253135314531553165317531853195320532153225323532453255326532753285329533053315332533353345335533653375338533953405341534253435344534553465347534853495350535153525353535453555356535753585359536053615362536353645365536653675368536953705371537253735374537553765377537853795380538153825383538453855386538753885389539053915392539353945395539653975398539954005401540254035404540554065407540854095410541154125413541454155416541754185419542054215422542354245425542654275428542954305431543254335434543554365437543854395440544154425443544454455446544754485449545054515452545354545455545654575458545954605461546254635464546554665467546854695470547154725473547454755476547754785479548054815482548354845485548654875488548954905491549254935494549554965497549854995500550155025503550455055506550755085509551055115512551355145515551655175518551955205521552255235524552555265527552855295530553155325533553455355536553755385539554055415542554355445545554655475548554955505551555255535554555555565557555855595560556155625563556455655566556755685569557055715572557355745575557655775578557955805581558255835584558555865587558855895590559155925593559455955596559755985599560056015602560356045605560656075608560956105611561256135614561556165617561856195620562156225623562456255626562756285629563056315632563356345635563656375638563956405641564256435644564556465647564856495650565156525653565456555656565756585659566056615662566356645665566656675668566956705671567256735674567556765677567856795680568156825683568456855686568756885689569056915692569356945695569656975698569957005701570257035704570557065707570857095710571157125713571457155716571757185719572057215722572357245725572657275728572957305731573257335734573557365737573857395740574157425743574457455746574757485749575057515752575357545755575657575758575957605761576257635764576557665767576857695770577157725773577457755776577757785779578057815782578357845785578657875788578957905791579257935794579557965797579857995800580158025803580458055806580758085809581058115812581358145815581658175818581958205821582258235824582558265827582858295830583158325833583458355836583758385839584058415842584358445845584658475848584958505851585258535854585558565857585858595860586158625863586458655866586758685869587058715872587358745875587658775878587958805881588258835884588558865887588858895890589158925893589458955896589758985899590059015902590359045905590659075908590959105911591259135914591559165917591859195920592159225923592459255926592759285929593059315932593359345935593659375938593959405941594259435944594559465947594859495950595159525953595459555956595759585959596059615962596359645965596659675968596959705971597259735974597559765977597859795980598159825983598459855986598759885989599059915992599359945995599659975998599960006001600260036004600560066007600860096010601160126013601460156016601760186019602060216022602360246025602660276028602960306031603260336034603560366037603860396040604160426043604460456046604760486049605060516052605360546055605660576058605960606061606260636064606560666067606860696070607160726073607460756076607760786079608060816082608360846085608660876088608960906091609260936094609560966097609860996100610161026103610461056106610761086109611061116112611361146115611661176118611961206121612261236124612561266127612861296130613161326133613461356136613761386139614061416142614361446145614661476148614961506151615261536154615561566157615861596160616161626163616461656166616761686169617061716172617361746175617661776178617961806181618261836184618561866187618861896190619161926193619461956196619761986199620062016202620362046205620662076208620962106211621262136214621562166217621862196220622162226223622462256226622762286229623062316232623362346235623662376238623962406241624262436244624562466247624862496250625162526253625462556256625762586259626062616262626362646265626662676268626962706271627262736274627562766277627862796280628162826283628462856286628762886289629062916292629362946295629662976298629963006301630263036304630563066307630863096310631163126313631463156316631763186319632063216322632363246325632663276328632963306331633263336334633563366337633863396340634163426343634463456346634763486349635063516352635363546355635663576358635963606361636263636364636563666367636863696370637163726373637463756376637763786379638063816382638363846385638663876388638963906391639263936394639563966397639863996400640164026403640464056406640764086409641064116412641364146415641664176418641964206421642264236424642564266427642864296430643164326433643464356436643764386439644064416442644364446445644664476448644964506451645264536454645564566457645864596460646164626463646464656466646764686469647064716472647364746475647664776478647964806481648264836484648564866487648864896490649164926493649464956496649764986499650065016502650365046505650665076508650965106511651265136514651565166517651865196520652165226523652465256526652765286529653065316532653365346535653665376538653965406541654265436544654565466547654865496550655165526553655465556556655765586559656065616562656365646565656665676568656965706571657265736574657565766577657865796580658165826583658465856586658765886589659065916592659365946595659665976598659966006601660266036604660566066607660866096610661166126613661466156616661766186619662066216622662366246625662666276628662966306631663266336634663566366637663866396640664166426643664466456646664766486649665066516652665366546655665666576658665966606661666266636664666566666667666866696670667166726673667466756676667766786679668066816682668366846685668666876688668966906691669266936694669566966697669866996700670167026703670467056706670767086709671067116712671367146715671667176718671967206721672267236724672567266727672867296730673167326733673467356736673767386739674067416742674367446745674667476748674967506751675267536754675567566757675867596760676167626763676467656766676767686769677067716772677367746775677667776778677967806781678267836784678567866787678867896790679167926793679467956796679767986799680068016802680368046805680668076808680968106811681268136814681568166817681868196820682168226823682468256826682768286829683068316832683368346835683668376838683968406841684268436844684568466847684868496850685168526853685468556856685768586859686068616862686368646865686668676868686968706871687268736874687568766877687868796880688168826883688468856886688768886889689068916892689368946895689668976898689969006901690269036904690569066907690869096910691169126913691469156916691769186919692069216922692369246925692669276928692969306931693269336934693569366937693869396940694169426943694469456946694769486949695069516952695369546955695669576958695969606961696269636964696569666967696869696970697169726973697469756976697769786979698069816982698369846985698669876988698969906991699269936994699569966997699869997000700170027003700470057006700770087009701070117012701370147015701670177018701970207021702270237024702570267027702870297030703170327033703470357036703770387039704070417042704370447045704670477048704970507051705270537054705570567057705870597060706170627063706470657066706770687069707070717072707370747075707670777078707970807081708270837084708570867087708870897090709170927093709470957096709770987099710071017102710371047105710671077108710971107111711271137114711571167117711871197120712171227123712471257126712771287129713071317132713371347135713671377138713971407141714271437144714571467147714871497150715171527153715471557156715771587159716071617162716371647165716671677168716971707171717271737174717571767177717871797180718171827183718471857186718771887189719071917192719371947195719671977198719972007201720272037204720572067207720872097210721172127213721472157216721772187219722072217222722372247225722672277228722972307231723272337234723572367237723872397240724172427243724472457246724772487249725072517252725372547255725672577258725972607261726272637264726572667267726872697270727172727273727472757276727772787279728072817282728372847285728672877288728972907291729272937294729572967297729872997300730173027303730473057306730773087309731073117312731373147315731673177318731973207321732273237324732573267327732873297330733173327333733473357336733773387339734073417342734373447345734673477348734973507351735273537354735573567357735873597360736173627363736473657366736773687369737073717372737373747375737673777378737973807381738273837384738573867387738873897390739173927393739473957396739773987399740074017402740374047405740674077408740974107411741274137414741574167417741874197420742174227423742474257426742774287429743074317432743374347435743674377438743974407441744274437444744574467447744874497450745174527453745474557456745774587459746074617462746374647465746674677468746974707471747274737474747574767477747874797480748174827483748474857486748774887489749074917492749374947495749674977498749975007501750275037504750575067507750875097510751175127513751475157516751775187519752075217522752375247525752675277528752975307531753275337534753575367537753875397540754175427543754475457546754775487549755075517552755375547555755675577558755975607561756275637564756575667567756875697570757175727573757475757576757775787579758075817582758375847585758675877588758975907591759275937594759575967597759875997600760176027603760476057606760776087609761076117612761376147615761676177618761976207621762276237624762576267627762876297630763176327633763476357636763776387639764076417642764376447645764676477648764976507651765276537654765576567657765876597660766176627663766476657666766776687669767076717672767376747675767676777678767976807681768276837684768576867687768876897690769176927693769476957696769776987699770077017702770377047705770677077708770977107711771277137714771577167717771877197720772177227723772477257726772777287729773077317732773377347735773677377738773977407741774277437744774577467747774877497750775177527753775477557756775777587759776077617762776377647765776677677768776977707771777277737774777577767777777877797780778177827783778477857786778777887789779077917792779377947795779677977798779978007801780278037804780578067807780878097810781178127813781478157816781778187819782078217822782378247825782678277828782978307831783278337834783578367837783878397840784178427843784478457846784778487849785078517852785378547855785678577858785978607861786278637864786578667867786878697870787178727873787478757876787778787879788078817882788378847885788678877888788978907891789278937894789578967897789878997900790179027903790479057906790779087909791079117912791379147915791679177918791979207921792279237924792579267927792879297930793179327933793479357936793779387939794079417942794379447945794679477948794979507951795279537954795579567957795879597960796179627963796479657966796779687969797079717972797379747975797679777978797979807981798279837984798579867987798879897990799179927993799479957996799779987999800080018002800380048005800680078008800980108011801280138014801580168017801880198020802180228023802480258026802780288029803080318032803380348035803680378038803980408041804280438044804580468047804880498050805180528053805480558056805780588059806080618062806380648065806680678068806980708071807280738074807580768077807880798080808180828083808480858086808780888089809080918092809380948095809680978098809981008101810281038104810581068107810881098110811181128113811481158116811781188119812081218122812381248125812681278128812981308131813281338134813581368137813881398140814181428143814481458146814781488149815081518152815381548155815681578158815981608161816281638164816581668167816881698170817181728173817481758176817781788179818081818182818381848185818681878188818981908191819281938194819581968197819881998200820182028203820482058206820782088209821082118212821382148215821682178218821982208221822282238224822582268227822882298230823182328233823482358236823782388239824082418242824382448245824682478248824982508251825282538254825582568257825882598260826182628263826482658266826782688269827082718272827382748275827682778278827982808281828282838284828582868287828882898290829182928293829482958296829782988299830083018302830383048305830683078308830983108311831283138314831583168317831883198320832183228323832483258326832783288329833083318332833383348335833683378338833983408341834283438344834583468347834883498350835183528353835483558356835783588359836083618362836383648365836683678368836983708371837283738374837583768377837883798380838183828383838483858386838783888389839083918392839383948395839683978398839984008401840284038404840584068407840884098410841184128413841484158416841784188419842084218422842384248425842684278428842984308431843284338434843584368437843884398440844184428443844484458446844784488449845084518452845384548455845684578458845984608461846284638464846584668467846884698470847184728473847484758476847784788479848084818482848384848485848684878488848984908491849284938494849584968497849884998500850185028503850485058506850785088509851085118512851385148515851685178518851985208521852285238524852585268527852885298530853185328533853485358536853785388539854085418542854385448545854685478548854985508551855285538554855585568557855885598560856185628563856485658566856785688569857085718572857385748575857685778578857985808581858285838584858585868587858885898590859185928593859485958596859785988599860086018602860386048605860686078608860986108611861286138614861586168617861886198620862186228623862486258626862786288629863086318632863386348635863686378638863986408641864286438644864586468647864886498650865186528653865486558656865786588659866086618662866386648665866686678668866986708671867286738674867586768677867886798680868186828683868486858686868786888689869086918692869386948695869686978698869987008701870287038704870587068707870887098710871187128713871487158716871787188719872087218722872387248725872687278728872987308731873287338734873587368737873887398740874187428743874487458746874787488749875087518752875387548755875687578758875987608761876287638764876587668767876887698770877187728773877487758776877787788779878087818782878387848785878687878788878987908791879287938794879587968797879887998800880188028803880488058806880788088809881088118812881388148815881688178818881988208821882288238824882588268827882888298830883188328833883488358836883788388839884088418842884388448845884688478848884988508851885288538854885588568857885888598860886188628863886488658866886788688869887088718872887388748875887688778878887988808881888288838884888588868887888888898890889188928893889488958896889788988899890089018902890389048905890689078908890989108911891289138914891589168917891889198920892189228923892489258926892789288929893089318932893389348935893689378938893989408941894289438944894589468947894889498950895189528953895489558956895789588959896089618962896389648965896689678968896989708971897289738974897589768977897889798980898189828983898489858986898789888989899089918992899389948995899689978998899990009001900290039004900590069007900890099010901190129013901490159016901790189019902090219022902390249025902690279028902990309031903290339034903590369037903890399040904190429043904490459046904790489049905090519052905390549055905690579058905990609061906290639064906590669067906890699070907190729073907490759076907790789079908090819082908390849085908690879088908990909091909290939094909590969097909890999100910191029103910491059106910791089109911091119112911391149115911691179118911991209121912291239124912591269127912891299130913191329133913491359136913791389139914091419142914391449145914691479148914991509151915291539154915591569157915891599160916191629163916491659166916791689169917091719172917391749175917691779178917991809181918291839184918591869187918891899190919191929193919491959196919791989199920092019202920392049205920692079208920992109211921292139214921592169217921892199220922192229223922492259226922792289229923092319232923392349235923692379238923992409241924292439244924592469247924892499250925192529253925492559256925792589259926092619262926392649265926692679268926992709271927292739274927592769277927892799280928192829283928492859286928792889289929092919292929392949295929692979298929993009301930293039304930593069307930893099310931193129313931493159316931793189319932093219322932393249325932693279328932993309331933293339334933593369337933893399340934193429343934493459346934793489349935093519352935393549355935693579358935993609361936293639364936593669367936893699370937193729373937493759376937793789379938093819382938393849385938693879388938993909391939293939394939593969397939893999400940194029403940494059406940794089409941094119412941394149415941694179418941994209421942294239424942594269427942894299430943194329433943494359436943794389439944094419442944394449445944694479448944994509451945294539454945594569457945894599460946194629463946494659466946794689469947094719472947394749475947694779478947994809481948294839484948594869487948894899490949194929493949494959496949794989499950095019502950395049505950695079508950995109511951295139514951595169517951895199520952195229523952495259526952795289529953095319532953395349535953695379538953995409541954295439544954595469547954895499550955195529553955495559556955795589559956095619562956395649565956695679568956995709571957295739574957595769577957895799580958195829583958495859586958795889589959095919592959395949595959695979598959996009601960296039604960596069607960896099610961196129613961496159616961796189619962096219622962396249625962696279628962996309631963296339634963596369637963896399640964196429643964496459646964796489649965096519652965396549655965696579658965996609661966296639664966596669667966896699670967196729673967496759676967796789679968096819682968396849685968696879688968996909691969296939694969596969697969896999700970197029703970497059706970797089709971097119712971397149715971697179718971997209721972297239724972597269727972897299730973197329733973497359736973797389739974097419742974397449745974697479748974997509751975297539754975597569757975897599760976197629763976497659766976797689769977097719772977397749775977697779778977997809781978297839784978597869787978897899790979197929793979497959796979797989799980098019802980398049805980698079808980998109811981298139814981598169817981898199820982198229823982498259826982798289829983098319832983398349835983698379838983998409841984298439844984598469847984898499850985198529853985498559856985798589859986098619862986398649865986698679868986998709871987298739874987598769877987898799880988198829883988498859886988798889889989098919892989398949895989698979898989999009901990299039904990599069907990899099910991199129913991499159916991799189919992099219922992399249925992699279928992999309931993299339934993599369937993899399940994199429943994499459946994799489949995099519952995399549955995699579958995999609961996299639964996599669967996899699970997199729973997499759976997799789979998099819982998399849985998699879988998999909991999299939994999599969997999899991000010001100021000310004100051000610007100081000910010100111001210013100141001510016100171001810019100201002110022100231002410025100261002710028100291003010031100321003310034100351003610037100381003910040100411004210043100441004510046100471004810049100501005110052100531005410055100561005710058100591006010061100621006310064100651006610067100681006910070100711007210073100741007510076100771007810079100801008110082100831008410085100861008710088100891009010091100921009310094100951009610097100981009910100101011010210103101041010510106101071010810109101101011110112101131011410115101161011710118101191012010121101221012310124101251012610127101281012910130101311013210133101341013510136101371013810139101401014110142101431014410145101461014710148101491015010151101521015310154101551015610157101581015910160101611016210163101641016510166101671016810169101701017110172101731017410175101761017710178101791018010181101821018310184101851018610187101881018910190101911019210193101941019510196101971019810199102001020110202102031020410205102061020710208102091021010211102121021310214102151021610217102181021910220102211022210223102241022510226102271022810229102301023110232102331023410235102361023710238102391024010241102421024310244102451024610247102481024910250102511025210253102541025510256102571025810259102601026110262102631026410265102661026710268102691027010271102721027310274102751027610277102781027910280102811028210283102841028510286102871028810289102901029110292102931029410295102961029710298102991030010301103021030310304103051030610307103081030910310103111031210313103141031510316103171031810319103201032110322103231032410325103261032710328103291033010331103321033310334103351033610337103381033910340103411034210343103441034510346103471034810349103501035110352103531035410355103561035710358103591036010361103621036310364103651036610367103681036910370103711037210373103741037510376103771037810379103801038110382103831038410385103861038710388103891039010391103921039310394103951039610397103981039910400104011040210403104041040510406104071040810409104101041110412104131041410415104161041710418104191042010421104221042310424104251042610427104281042910430104311043210433104341043510436104371043810439104401044110442104431044410445104461044710448104491045010451104521045310454104551045610457104581045910460104611046210463104641046510466104671046810469104701047110472104731047410475104761047710478104791048010481104821048310484104851048610487104881048910490104911049210493104941049510496104971049810499105001050110502105031050410505105061050710508105091051010511105121051310514105151051610517105181051910520105211052210523105241052510526105271052810529105301053110532105331053410535105361053710538105391054010541105421054310544105451054610547105481054910550105511055210553105541055510556105571055810559105601056110562105631056410565105661056710568105691057010571105721057310574105751057610577105781057910580105811058210583105841058510586105871058810589105901059110592105931059410595105961059710598105991060010601106021060310604106051060610607106081060910610106111061210613106141061510616106171061810619106201062110622106231062410625106261062710628106291063010631106321063310634106351063610637106381063910640106411064210643106441064510646106471064810649106501065110652106531065410655106561065710658106591066010661106621066310664106651066610667106681066910670106711067210673106741067510676106771067810679106801068110682106831068410685106861068710688106891069010691106921069310694106951069610697106981069910700107011070210703107041070510706107071070810709107101071110712107131071410715107161071710718107191072010721107221072310724107251072610727107281072910730107311073210733107341073510736107371073810739107401074110742107431074410745107461074710748107491075010751107521075310754107551075610757107581075910760107611076210763107641076510766107671076810769107701077110772107731077410775107761077710778107791078010781107821078310784107851078610787107881078910790107911079210793107941079510796107971079810799108001080110802108031080410805108061080710808108091081010811108121081310814108151081610817108181081910820108211082210823108241082510826108271082810829108301083110832108331083410835108361083710838108391084010841108421084310844108451084610847108481084910850108511085210853108541085510856108571085810859108601086110862108631086410865108661086710868108691087010871108721087310874108751087610877108781087910880108811088210883108841088510886108871088810889108901089110892108931089410895108961089710898108991090010901109021090310904109051090610907109081090910910109111091210913109141091510916109171091810919109201092110922109231092410925109261092710928109291093010931109321093310934109351093610937109381093910940109411094210943109441094510946109471094810949109501095110952109531095410955109561095710958109591096010961109621096310964109651096610967109681096910970109711097210973109741097510976109771097810979109801098110982109831098410985109861098710988109891099010991109921099310994109951099610997109981099911000110011100211003110041100511006110071100811009110101101111012110131101411015110161101711018110191102011021110221102311024110251102611027110281102911030110311103211033110341103511036110371103811039110401104111042110431104411045110461104711048110491105011051110521105311054110551105611057110581105911060110611106211063110641106511066110671106811069110701107111072110731107411075110761107711078110791108011081110821108311084110851108611087110881108911090110911109211093110941109511096110971109811099111001110111102111031110411105111061110711108111091111011111111121111311114111151111611117111181111911120111211112211123111241112511126111271112811129111301113111132111331113411135111361113711138111391114011141111421114311144111451114611147111481114911150111511115211153111541115511156111571115811159111601116111162111631116411165111661116711168111691117011171111721117311174111751117611177111781117911180111811118211183111841118511186111871118811189111901119111192111931119411195111961119711198111991120011201112021120311204112051120611207112081120911210112111121211213112141121511216112171121811219112201122111222112231122411225112261122711228112291123011231112321123311234112351123611237112381123911240112411124211243112441124511246112471124811249112501125111252112531125411255112561125711258112591126011261112621126311264112651126611267112681126911270112711127211273112741127511276112771127811279112801128111282112831128411285112861128711288112891129011291112921129311294112951129611297112981129911300113011130211303113041130511306113071130811309113101131111312113131131411315113161131711318113191132011321113221132311324113251132611327113281132911330113311133211333113341133511336113371133811339113401134111342113431134411345113461134711348113491135011351113521135311354113551135611357113581135911360113611136211363113641136511366113671136811369113701137111372113731137411375113761137711378113791138011381113821138311384113851138611387113881138911390113911139211393113941139511396113971139811399114001140111402114031140411405114061140711408114091141011411114121141311414114151141611417114181141911420114211142211423114241142511426114271142811429114301143111432114331143411435114361143711438114391144011441114421144311444114451144611447114481144911450114511145211453114541145511456114571145811459114601146111462114631146411465114661146711468114691147011471114721147311474114751147611477114781147911480114811148211483114841148511486114871148811489114901149111492114931149411495114961149711498114991150011501115021150311504115051150611507115081150911510115111151211513115141151511516115171151811519115201152111522115231152411525115261152711528115291153011531115321153311534115351153611537115381153911540115411154211543115441154511546115471154811549115501155111552115531155411555115561155711558115591156011561115621156311564115651156611567115681156911570115711157211573115741157511576115771157811579115801158111582115831158411585115861158711588115891159011591115921159311594115951159611597115981159911600116011160211603116041160511606116071160811609116101161111612116131161411615116161161711618116191162011621116221162311624116251162611627116281162911630116311163211633116341163511636116371163811639116401164111642116431164411645116461164711648116491165011651116521165311654116551165611657116581165911660116611166211663116641166511666116671166811669116701167111672116731167411675116761167711678116791168011681116821168311684116851168611687116881168911690116911169211693116941169511696116971169811699117001170111702117031170411705117061170711708117091171011711117121171311714117151171611717117181171911720117211172211723117241172511726117271172811729117301173111732117331173411735117361173711738117391174011741117421174311744117451174611747117481174911750117511175211753117541175511756117571175811759117601176111762117631176411765117661176711768117691177011771117721177311774117751177611777117781177911780117811178211783117841178511786117871178811789117901179111792117931179411795117961179711798117991180011801118021180311804118051180611807118081180911810118111181211813118141181511816118171181811819118201182111822118231182411825118261182711828118291183011831118321183311834118351183611837118381183911840118411184211843118441184511846118471184811849118501185111852118531185411855118561185711858118591186011861118621186311864118651186611867118681186911870118711187211873118741187511876118771187811879118801188111882118831188411885118861188711888118891189011891118921189311894118951189611897118981189911900119011190211903119041190511906119071190811909119101191111912119131191411915119161191711918119191192011921119221192311924119251192611927119281192911930119311193211933119341193511936119371193811939119401194111942119431194411945119461194711948119491195011951119521195311954119551195611957119581195911960119611196211963119641196511966119671196811969119701197111972119731197411975119761197711978119791198011981119821198311984119851198611987119881198911990119911199211993119941199511996119971199811999120001200112002120031200412005120061200712008120091201012011120121201312014120151201612017120181201912020120211202212023120241202512026120271202812029120301203112032120331203412035120361203712038120391204012041120421204312044120451204612047120481204912050120511205212053120541205512056120571205812059120601206112062120631206412065120661206712068120691207012071120721207312074120751207612077120781207912080120811208212083120841208512086120871208812089120901209112092120931209412095120961209712098120991210012101121021210312104121051210612107121081210912110121111211212113121141211512116121171211812119121201212112122121231212412125121261212712128121291213012131121321213312134121351213612137121381213912140121411214212143121441214512146121471214812149121501215112152121531215412155121561215712158121591216012161121621216312164121651216612167121681216912170121711217212173121741217512176121771217812179121801218112182121831218412185121861218712188121891219012191121921219312194121951219612197121981219912200122011220212203122041220512206122071220812209122101221112212122131221412215122161221712218122191222012221122221222312224122251222612227122281222912230122311223212233122341223512236122371223812239122401224112242122431224412245122461224712248122491225012251122521225312254122551225612257122581225912260122611226212263122641226512266122671226812269122701227112272122731227412275122761227712278122791228012281122821228312284122851228612287122881228912290122911229212293122941229512296122971229812299123001230112302123031230412305123061230712308123091231012311123121231312314123151231612317123181231912320123211232212323123241232512326123271232812329123301233112332123331233412335123361233712338123391234012341123421234312344123451234612347123481234912350123511235212353123541235512356123571235812359123601236112362123631236412365123661236712368123691237012371123721237312374123751237612377123781237912380123811238212383123841238512386123871238812389123901239112392123931239412395123961239712398123991240012401124021240312404124051240612407124081240912410124111241212413124141241512416124171241812419124201242112422124231242412425124261242712428124291243012431124321243312434124351243612437124381243912440124411244212443124441244512446124471244812449124501245112452124531245412455124561245712458124591246012461124621246312464124651246612467124681246912470124711247212473124741247512476124771247812479124801248112482124831248412485124861248712488124891249012491124921249312494124951249612497124981249912500125011250212503125041250512506125071250812509125101251112512125131251412515125161251712518125191252012521125221252312524125251252612527125281252912530125311253212533125341253512536125371253812539125401254112542125431254412545125461254712548125491255012551125521255312554125551255612557125581255912560125611256212563125641256512566125671256812569125701257112572125731257412575125761257712578125791258012581125821258312584125851258612587125881258912590125911259212593125941259512596125971259812599126001260112602126031260412605126061260712608126091261012611126121261312614126151261612617126181261912620126211262212623126241262512626126271262812629126301263112632126331263412635126361263712638126391264012641126421264312644126451264612647126481264912650126511265212653126541265512656126571265812659126601266112662126631266412665126661266712668126691267012671126721267312674126751267612677126781267912680126811268212683126841268512686126871268812689126901269112692126931269412695126961269712698126991270012701127021270312704127051270612707127081270912710127111271212713127141271512716127171271812719127201272112722127231272412725127261272712728127291273012731127321273312734127351273612737127381273912740127411274212743127441274512746127471274812749127501275112752127531275412755127561275712758127591276012761127621276312764127651276612767127681276912770127711277212773127741277512776127771277812779127801278112782127831278412785127861278712788127891279012791127921279312794127951279612797127981279912800128011280212803128041280512806128071280812809128101281112812128131281412815128161281712818128191282012821128221282312824128251282612827128281282912830128311283212833128341283512836128371283812839128401284112842128431284412845128461284712848128491285012851128521285312854128551285612857128581285912860128611286212863128641286512866128671286812869128701287112872128731287412875128761287712878128791288012881128821288312884128851288612887128881288912890128911289212893128941289512896128971289812899129001290112902129031290412905129061290712908129091291012911129121291312914129151291612917129181291912920129211292212923129241292512926129271292812929129301293112932129331293412935129361293712938129391294012941129421294312944129451294612947129481294912950129511295212953129541295512956129571295812959129601296112962129631296412965129661296712968129691297012971129721297312974129751297612977129781297912980129811298212983129841298512986129871298812989129901299112992129931299412995129961299712998129991300013001130021300313004130051300613007130081300913010130111301213013130141301513016130171301813019130201302113022130231302413025130261302713028130291303013031130321303313034130351303613037130381303913040130411304213043130441304513046130471304813049130501305113052130531305413055130561305713058130591306013061130621306313064130651306613067130681306913070130711307213073130741307513076130771307813079130801308113082130831308413085130861308713088130891309013091130921309313094130951309613097130981309913100131011310213103131041310513106131071310813109131101311113112131131311413115131161311713118131191312013121131221312313124131251312613127131281312913130131311313213133131341313513136131371313813139131401314113142131431314413145131461314713148131491315013151131521315313154131551315613157131581315913160131611316213163131641316513166131671316813169131701317113172131731317413175131761317713178131791318013181131821318313184131851318613187131881318913190131911319213193131941319513196131971319813199132001320113202132031320413205132061320713208132091321013211132121321313214132151321613217132181321913220132211322213223132241322513226132271322813229132301323113232132331323413235132361323713238132391324013241132421324313244132451324613247132481324913250132511325213253132541325513256132571325813259132601326113262132631326413265132661326713268132691327013271132721327313274132751327613277132781327913280132811328213283132841328513286132871328813289132901329113292132931329413295132961329713298132991330013301133021330313304133051330613307133081330913310133111331213313133141331513316133171331813319133201332113322133231332413325133261332713328133291333013331133321333313334133351333613337133381333913340133411334213343133441334513346133471334813349133501335113352133531335413355133561335713358133591336013361133621336313364133651336613367133681336913370133711337213373133741337513376133771337813379133801338113382133831338413385133861338713388133891339013391133921339313394133951339613397133981339913400134011340213403134041340513406134071340813409134101341113412134131341413415134161341713418134191342013421134221342313424134251342613427134281342913430134311343213433134341343513436134371343813439134401344113442134431344413445134461344713448134491345013451134521345313454134551345613457134581345913460134611346213463134641346513466134671346813469134701347113472134731347413475134761347713478134791348013481134821348313484134851348613487134881348913490134911349213493134941349513496134971349813499135001350113502135031350413505135061350713508135091351013511135121351313514135151351613517135181351913520135211352213523135241352513526135271352813529135301353113532135331353413535135361353713538135391354013541135421354313544135451354613547135481354913550135511355213553135541355513556135571355813559135601356113562135631356413565135661356713568135691357013571135721357313574135751357613577135781357913580135811358213583135841358513586135871358813589135901359113592135931359413595135961359713598135991360013601136021360313604136051360613607136081360913610136111361213613136141361513616136171361813619136201362113622136231362413625136261362713628136291363013631136321363313634136351363613637136381363913640136411364213643136441364513646136471364813649136501365113652136531365413655136561365713658136591366013661136621366313664136651366613667136681366913670136711367213673136741367513676136771367813679136801368113682136831368413685136861368713688136891369013691136921369313694136951369613697136981369913700137011370213703137041370513706137071370813709137101371113712137131371413715137161371713718137191372013721137221372313724137251372613727137281372913730137311373213733137341373513736137371373813739137401374113742137431374413745137461374713748137491375013751137521375313754137551375613757137581375913760137611376213763137641376513766137671376813769137701377113772137731377413775137761377713778137791378013781137821378313784137851378613787137881378913790137911379213793137941379513796137971379813799138001380113802138031380413805138061380713808138091381013811138121381313814138151381613817138181381913820138211382213823138241382513826138271382813829138301383113832138331383413835138361383713838138391384013841138421384313844138451384613847138481384913850138511385213853138541385513856138571385813859138601386113862138631386413865138661386713868138691387013871138721387313874138751387613877138781387913880138811388213883138841388513886138871388813889138901389113892138931389413895138961389713898138991390013901139021390313904139051390613907139081390913910139111391213913139141391513916139171391813919139201392113922139231392413925139261392713928139291393013931139321393313934139351393613937139381393913940139411394213943139441394513946139471394813949139501395113952139531395413955139561395713958139591396013961139621396313964139651396613967139681396913970139711397213973139741397513976139771397813979139801398113982139831398413985139861398713988139891399013991139921399313994139951399613997139981399914000140011400214003140041400514006140071400814009140101401114012140131401414015140161401714018140191402014021140221402314024140251402614027140281402914030140311403214033140341403514036140371403814039140401404114042140431404414045140461404714048140491405014051140521405314054140551405614057140581405914060140611406214063140641406514066140671406814069140701407114072140731407414075140761407714078140791408014081140821408314084140851408614087140881408914090140911409214093140941409514096140971409814099141001410114102141031410414105141061410714108141091411014111141121411314114141151411614117141181411914120141211412214123141241412514126141271412814129141301413114132141331413414135141361413714138141391414014141141421414314144141451414614147141481414914150141511415214153141541415514156141571415814159141601416114162141631416414165141661416714168141691417014171141721417314174141751417614177141781417914180141811418214183141841418514186141871418814189141901419114192141931419414195141961419714198141991420014201142021420314204142051420614207142081420914210142111421214213142141421514216142171421814219142201422114222142231422414225142261422714228142291423014231142321423314234142351423614237142381423914240142411424214243142441424514246142471424814249142501425114252142531425414255142561425714258142591426014261142621426314264142651426614267142681426914270142711427214273142741427514276142771427814279142801428114282142831428414285142861428714288142891429014291142921429314294142951429614297142981429914300143011430214303143041430514306143071430814309143101431114312143131431414315143161431714318143191432014321143221432314324143251432614327143281432914330143311433214333143341433514336143371433814339143401434114342143431434414345143461434714348143491435014351143521435314354143551435614357143581435914360143611436214363143641436514366143671436814369143701437114372143731437414375143761437714378143791438014381143821438314384143851438614387143881438914390143911439214393143941439514396143971439814399144001440114402144031440414405144061440714408144091441014411144121441314414144151441614417144181441914420144211442214423144241442514426144271442814429144301443114432144331443414435144361443714438144391444014441144421444314444144451444614447144481444914450144511445214453144541445514456144571445814459144601446114462144631446414465144661446714468144691447014471144721447314474144751447614477144781447914480144811448214483144841448514486144871448814489144901449114492144931449414495144961449714498144991450014501145021450314504145051450614507145081450914510145111451214513145141451514516145171451814519145201452114522145231452414525145261452714528145291453014531145321453314534145351453614537145381453914540145411454214543145441454514546145471454814549145501455114552145531455414555145561455714558145591456014561145621456314564145651456614567145681456914570145711457214573145741457514576145771457814579145801458114582145831458414585145861458714588145891459014591145921459314594145951459614597145981459914600146011460214603146041460514606146071460814609146101461114612146131461414615146161461714618146191462014621146221462314624146251462614627146281462914630146311463214633146341463514636146371463814639146401464114642146431464414645146461464714648146491465014651146521465314654146551465614657146581465914660146611466214663146641466514666146671466814669146701467114672146731467414675146761467714678146791468014681146821468314684146851468614687146881468914690146911469214693146941469514696146971469814699147001470114702147031470414705147061470714708147091471014711147121471314714147151471614717147181471914720147211472214723147241472514726147271472814729147301473114732147331473414735147361473714738147391474014741147421474314744147451474614747147481474914750147511475214753147541475514756147571475814759147601476114762147631476414765147661476714768147691477014771147721477314774147751477614777147781477914780147811478214783147841478514786147871478814789147901479114792147931479414795147961479714798147991480014801148021480314804148051480614807148081480914810148111481214813148141481514816148171481814819148201482114822148231482414825148261482714828148291483014831148321483314834148351483614837148381483914840148411484214843148441484514846148471484814849148501485114852148531485414855148561485714858148591486014861148621486314864148651486614867148681486914870148711487214873148741487514876148771487814879148801488114882148831488414885148861488714888148891489014891148921489314894148951489614897148981489914900149011490214903149041490514906149071490814909149101491114912149131491414915149161491714918149191492014921149221492314924149251492614927149281492914930149311493214933149341493514936149371493814939149401494114942149431494414945149461494714948149491495014951149521495314954149551495614957149581495914960149611496214963149641496514966149671496814969149701497114972149731497414975149761497714978149791498014981149821498314984149851498614987149881498914990149911499214993149941499514996149971499814999150001500115002150031500415005150061500715008150091501015011150121501315014150151501615017150181501915020150211502215023150241502515026150271502815029150301503115032150331503415035150361503715038150391504015041150421504315044150451504615047150481504915050150511505215053150541505515056150571505815059150601506115062150631506415065150661506715068150691507015071150721507315074150751507615077150781507915080150811508215083150841508515086150871508815089150901509115092150931509415095150961509715098150991510015101151021510315104151051510615107151081510915110151111511215113151141511515116151171511815119151201512115122151231512415125151261512715128151291513015131151321513315134151351513615137151381513915140151411514215143151441514515146151471514815149151501515115152151531515415155151561515715158151591516015161151621516315164151651516615167151681516915170151711517215173151741517515176151771517815179151801518115182151831518415185151861518715188151891519015191151921519315194151951519615197151981519915200152011520215203152041520515206152071520815209152101521115212152131521415215152161521715218152191522015221152221522315224152251522615227152281522915230152311523215233152341523515236152371523815239152401524115242152431524415245152461524715248152491525015251152521525315254152551525615257152581525915260152611526215263152641526515266152671526815269152701527115272152731527415275152761527715278152791528015281152821528315284152851528615287152881528915290152911529215293152941529515296152971529815299153001530115302153031530415305153061530715308153091531015311153121531315314153151531615317153181531915320153211532215323153241532515326153271532815329153301533115332153331533415335153361533715338153391534015341153421534315344153451534615347153481534915350153511535215353153541535515356153571535815359153601536115362153631536415365153661536715368153691537015371153721537315374153751537615377153781537915380153811538215383153841538515386153871538815389153901539115392153931539415395153961539715398153991540015401154021540315404154051540615407154081540915410154111541215413154141541515416154171541815419154201542115422154231542415425154261542715428154291543015431154321543315434154351543615437154381543915440154411544215443154441544515446154471544815449154501545115452154531545415455154561545715458154591546015461154621546315464154651546615467154681546915470154711547215473154741547515476154771547815479154801548115482154831548415485154861548715488154891549015491154921549315494154951549615497154981549915500155011550215503155041550515506155071550815509155101551115512155131551415515155161551715518155191552015521155221552315524155251552615527155281552915530155311553215533155341553515536155371553815539155401554115542155431554415545155461554715548155491555015551155521555315554155551555615557155581555915560155611556215563155641556515566155671556815569155701557115572155731557415575155761557715578155791558015581155821558315584155851558615587155881558915590155911559215593155941559515596155971559815599156001560115602156031560415605156061560715608156091561015611156121561315614156151561615617156181561915620156211562215623156241562515626156271562815629156301563115632156331563415635156361563715638156391564015641156421564315644156451564615647156481564915650156511565215653156541565515656156571565815659156601566115662156631566415665156661566715668156691567015671156721567315674156751567615677156781567915680156811568215683156841568515686156871568815689156901569115692156931569415695156961569715698156991570015701157021570315704157051570615707157081570915710157111571215713157141571515716157171571815719157201572115722157231572415725157261572715728157291573015731157321573315734157351573615737157381573915740157411574215743157441574515746157471574815749157501575115752157531575415755157561575715758157591576015761157621576315764157651576615767157681576915770157711577215773157741577515776157771577815779157801578115782157831578415785157861578715788157891579015791157921579315794157951579615797157981579915800158011580215803158041580515806158071580815809158101581115812158131581415815158161581715818158191582015821158221582315824158251582615827158281582915830158311583215833158341583515836158371583815839158401584115842158431584415845158461584715848158491585015851158521585315854158551585615857158581585915860158611586215863158641586515866158671586815869158701587115872158731587415875158761587715878158791588015881158821588315884158851588615887158881588915890158911589215893158941589515896158971589815899159001590115902159031590415905159061590715908159091591015911159121591315914159151591615917159181591915920159211592215923159241592515926159271592815929159301593115932159331593415935159361593715938159391594015941159421594315944159451594615947159481594915950159511595215953159541595515956159571595815959159601596115962159631596415965159661596715968159691597015971159721597315974159751597615977159781597915980159811598215983159841598515986159871598815989159901599115992159931599415995159961599715998159991600016001160021600316004160051600616007160081600916010160111601216013160141601516016160171601816019160201602116022160231602416025160261602716028160291603016031160321603316034160351603616037160381603916040160411604216043160441604516046160471604816049160501605116052160531605416055160561605716058160591606016061160621606316064160651606616067160681606916070160711607216073160741607516076160771607816079160801608116082160831608416085160861608716088160891609016091160921609316094160951609616097160981609916100161011610216103161041610516106161071610816109161101611116112161131611416115161161611716118161191612016121161221612316124161251612616127161281612916130161311613216133161341613516136161371613816139161401614116142161431614416145161461614716148161491615016151161521615316154161551615616157161581615916160161611616216163161641616516166161671616816169161701617116172161731617416175161761617716178161791618016181161821618316184161851618616187161881618916190161911619216193161941619516196161971619816199162001620116202162031620416205162061620716208162091621016211162121621316214162151621616217162181621916220162211622216223162241622516226162271622816229162301623116232162331623416235162361623716238162391624016241162421624316244162451624616247162481624916250162511625216253162541625516256162571625816259162601626116262162631626416265162661626716268162691627016271162721627316274162751627616277162781627916280162811628216283162841628516286162871628816289162901629116292162931629416295162961629716298162991630016301163021630316304163051630616307163081630916310163111631216313163141631516316163171631816319163201632116322163231632416325163261632716328163291633016331163321633316334163351633616337163381633916340163411634216343163441634516346163471634816349163501635116352163531635416355163561635716358163591636016361163621636316364163651636616367163681636916370163711637216373163741637516376163771637816379163801638116382163831638416385163861638716388163891639016391163921639316394163951639616397163981639916400164011640216403164041640516406164071640816409164101641116412164131641416415164161641716418164191642016421164221642316424164251642616427164281642916430164311643216433164341643516436164371643816439164401644116442164431644416445164461644716448164491645016451164521645316454164551645616457164581645916460164611646216463164641646516466164671646816469164701647116472164731647416475164761647716478164791648016481164821648316484164851648616487164881648916490164911649216493164941649516496164971649816499165001650116502165031650416505165061650716508165091651016511165121651316514165151651616517165181651916520165211652216523165241652516526165271652816529165301653116532165331653416535165361653716538165391654016541165421654316544165451654616547165481654916550165511655216553165541655516556165571655816559165601656116562165631656416565165661656716568165691657016571165721657316574165751657616577165781657916580165811658216583165841658516586165871658816589165901659116592165931659416595165961659716598165991660016601166021660316604166051660616607166081660916610166111661216613166141661516616166171661816619166201662116622166231662416625166261662716628166291663016631166321663316634166351663616637166381663916640166411664216643166441664516646166471664816649166501665116652166531665416655166561665716658166591666016661166621666316664166651666616667166681666916670166711667216673166741667516676166771667816679166801668116682166831668416685166861668716688166891669016691166921669316694166951669616697166981669916700167011670216703167041670516706167071670816709167101671116712167131671416715167161671716718167191672016721167221672316724167251672616727167281672916730167311673216733167341673516736167371673816739167401674116742167431674416745167461674716748167491675016751167521675316754167551675616757167581675916760167611676216763167641676516766167671676816769167701677116772167731677416775167761677716778167791678016781167821678316784167851678616787167881678916790167911679216793167941679516796167971679816799168001680116802168031680416805168061680716808168091681016811168121681316814168151681616817168181681916820168211682216823168241682516826168271682816829168301683116832168331683416835168361683716838168391684016841168421684316844168451684616847168481684916850168511685216853168541685516856168571685816859168601686116862168631686416865168661686716868168691687016871168721687316874168751687616877168781687916880168811688216883168841688516886168871688816889168901689116892168931689416895168961689716898168991690016901169021690316904169051690616907169081690916910169111691216913169141691516916169171691816919169201692116922169231692416925169261692716928169291693016931169321693316934169351693616937169381693916940169411694216943169441694516946169471694816949169501695116952169531695416955169561695716958169591696016961169621696316964169651696616967169681696916970169711697216973169741697516976169771697816979169801698116982169831698416985169861698716988169891699016991169921699316994169951699616997169981699917000170011700217003170041700517006170071700817009170101701117012170131701417015170161701717018170191702017021170221702317024170251702617027170281702917030170311703217033170341703517036170371703817039170401704117042170431704417045170461704717048170491705017051170521705317054170551705617057170581705917060170611706217063170641706517066170671706817069170701707117072170731707417075170761707717078170791708017081170821708317084170851708617087170881708917090170911709217093170941709517096170971709817099171001710117102171031710417105171061710717108171091711017111171121711317114171151711617117171181711917120171211712217123171241712517126171271712817129171301713117132171331713417135171361713717138171391714017141171421714317144171451714617147171481714917150171511715217153171541715517156171571715817159171601716117162171631716417165171661716717168171691717017171171721717317174171751717617177171781717917180171811718217183171841718517186171871718817189171901719117192171931719417195171961719717198171991720017201172021720317204172051720617207172081720917210172111721217213172141721517216172171721817219172201722117222172231722417225172261722717228172291723017231172321723317234172351723617237172381723917240172411724217243172441724517246172471724817249172501725117252172531725417255172561725717258172591726017261172621726317264172651726617267172681726917270172711727217273172741727517276172771727817279172801728117282172831728417285172861728717288172891729017291172921729317294172951729617297172981729917300173011730217303173041730517306173071730817309173101731117312173131731417315173161731717318173191732017321173221732317324173251732617327173281732917330173311733217333173341733517336173371733817339173401734117342173431734417345173461734717348173491735017351173521735317354173551735617357173581735917360173611736217363173641736517366173671736817369173701737117372173731737417375173761737717378173791738017381173821738317384173851738617387173881738917390173911739217393173941739517396173971739817399174001740117402174031740417405174061740717408174091741017411174121741317414174151741617417174181741917420174211742217423174241742517426174271742817429174301743117432174331743417435174361743717438174391744017441174421744317444174451744617447174481744917450174511745217453174541745517456174571745817459174601746117462174631746417465174661746717468174691747017471174721747317474174751747617477174781747917480174811748217483174841748517486174871748817489174901749117492174931749417495174961749717498174991750017501175021750317504175051750617507175081750917510175111751217513175141751517516175171751817519175201752117522175231752417525175261752717528175291753017531175321753317534175351753617537175381753917540175411754217543175441754517546175471754817549175501755117552175531755417555175561755717558175591756017561175621756317564175651756617567175681756917570175711757217573175741757517576175771757817579175801758117582175831758417585175861758717588175891759017591175921759317594175951759617597175981759917600176011760217603176041760517606176071760817609176101761117612176131761417615176161761717618176191762017621176221762317624176251762617627176281762917630176311763217633176341763517636176371763817639176401764117642176431764417645176461764717648176491765017651176521765317654176551765617657176581765917660176611766217663176641766517666176671766817669176701767117672176731767417675176761767717678176791768017681176821768317684176851768617687176881768917690176911769217693176941769517696176971769817699177001770117702177031770417705177061770717708177091771017711177121771317714177151771617717177181771917720177211772217723177241772517726177271772817729177301773117732177331773417735177361773717738177391774017741177421774317744177451774617747177481774917750177511775217753177541775517756177571775817759177601776117762177631776417765177661776717768177691777017771177721777317774177751777617777177781777917780177811778217783177841778517786177871778817789177901779117792177931779417795177961779717798177991780017801178021780317804178051780617807178081780917810178111781217813178141781517816178171781817819178201782117822178231782417825178261782717828178291783017831178321783317834178351783617837178381783917840178411784217843178441784517846178471784817849178501785117852178531785417855178561785717858178591786017861178621786317864178651786617867178681786917870178711787217873178741787517876178771787817879178801788117882178831788417885178861788717888178891789017891178921789317894178951789617897178981789917900179011790217903179041790517906179071790817909179101791117912179131791417915179161791717918179191792017921179221792317924179251792617927179281792917930179311793217933179341793517936179371793817939179401794117942179431794417945179461794717948179491795017951179521795317954179551795617957179581795917960179611796217963179641796517966179671796817969179701797117972179731797417975179761797717978179791798017981179821798317984179851798617987179881798917990179911799217993179941799517996179971799817999180001800118002180031800418005180061800718008180091801018011180121801318014180151801618017180181801918020180211802218023180241802518026180271802818029180301803118032180331803418035180361803718038180391804018041180421804318044180451804618047180481804918050180511805218053180541805518056180571805818059180601806118062180631806418065180661806718068180691807018071180721807318074180751807618077180781807918080180811808218083180841808518086180871808818089180901809118092180931809418095180961809718098180991810018101181021810318104181051810618107181081810918110181111811218113181141811518116181171811818119181201812118122181231812418125181261812718128181291813018131181321813318134181351813618137181381813918140181411814218143181441814518146181471814818149181501815118152181531815418155181561815718158181591816018161181621816318164181651816618167181681816918170181711817218173181741817518176181771817818179181801818118182181831818418185181861818718188181891819018191181921819318194181951819618197181981819918200182011820218203182041820518206182071820818209182101821118212182131821418215182161821718218182191822018221182221822318224182251822618227182281822918230182311823218233182341823518236182371823818239182401824118242182431824418245182461824718248182491825018251182521825318254182551825618257182581825918260182611826218263182641826518266182671826818269182701827118272182731827418275182761827718278182791828018281182821828318284182851828618287182881828918290182911829218293182941829518296182971829818299183001830118302183031830418305183061830718308183091831018311183121831318314183151831618317183181831918320183211832218323183241832518326183271832818329183301833118332183331833418335183361833718338183391834018341183421834318344183451834618347183481834918350183511835218353183541835518356183571835818359183601836118362183631836418365183661836718368183691837018371183721837318374183751837618377183781837918380183811838218383183841838518386183871838818389183901839118392183931839418395183961839718398183991840018401184021840318404184051840618407184081840918410184111841218413184141841518416184171841818419184201842118422184231842418425184261842718428184291843018431184321843318434184351843618437184381843918440184411844218443184441844518446184471844818449184501845118452184531845418455184561845718458184591846018461184621846318464184651846618467184681846918470184711847218473184741847518476184771847818479184801848118482184831848418485184861848718488184891849018491184921849318494184951849618497184981849918500185011850218503185041850518506185071850818509185101851118512185131851418515185161851718518185191852018521185221852318524185251852618527185281852918530185311853218533185341853518536185371853818539185401854118542185431854418545185461854718548185491855018551185521855318554185551855618557185581855918560185611856218563185641856518566185671856818569185701857118572185731857418575185761857718578185791858018581185821858318584185851858618587185881858918590185911859218593185941859518596185971859818599186001860118602186031860418605186061860718608186091861018611186121861318614186151861618617186181861918620186211862218623186241862518626186271862818629186301863118632186331863418635186361863718638186391864018641186421864318644186451864618647186481864918650186511865218653186541865518656186571865818659186601866118662186631866418665186661866718668186691867018671186721867318674186751867618677186781867918680186811868218683186841868518686186871868818689186901869118692186931869418695186961869718698186991870018701187021870318704187051870618707187081870918710187111871218713187141871518716187171871818719187201872118722187231872418725187261872718728187291873018731187321873318734187351873618737187381873918740187411874218743187441874518746187471874818749187501875118752187531875418755187561875718758187591876018761187621876318764187651876618767187681876918770187711877218773187741877518776187771877818779187801878118782187831878418785187861878718788187891879018791187921879318794187951879618797187981879918800188011880218803188041880518806188071880818809188101881118812188131881418815188161881718818188191882018821188221882318824188251882618827188281882918830188311883218833188341883518836188371883818839188401884118842188431884418845188461884718848188491885018851188521885318854188551885618857188581885918860188611886218863188641886518866188671886818869188701887118872188731887418875188761887718878188791888018881188821888318884188851888618887188881888918890188911889218893188941889518896188971889818899189001890118902189031890418905189061890718908189091891018911189121891318914189151891618917189181891918920189211892218923189241892518926189271892818929189301893118932189331893418935189361893718938189391894018941189421894318944189451894618947189481894918950189511895218953189541895518956189571895818959189601896118962189631896418965189661896718968189691897018971189721897318974189751897618977189781897918980189811898218983189841898518986189871898818989189901899118992189931899418995189961899718998189991900019001190021900319004190051900619007190081900919010190111901219013190141901519016190171901819019190201902119022190231902419025190261902719028190291903019031190321903319034190351903619037190381903919040190411904219043190441904519046190471904819049190501905119052190531905419055190561905719058190591906019061190621906319064190651906619067190681906919070190711907219073190741907519076190771907819079190801908119082190831908419085190861908719088190891909019091190921909319094190951909619097190981909919100191011910219103191041910519106191071910819109191101911119112191131911419115191161911719118191191912019121191221912319124191251912619127191281912919130191311913219133191341913519136191371913819139191401914119142191431914419145191461914719148191491915019151191521915319154191551915619157191581915919160191611916219163191641916519166191671916819169191701917119172191731917419175191761917719178191791918019181191821918319184191851918619187191881918919190191911919219193191941919519196191971919819199192001920119202192031920419205192061920719208192091921019211192121921319214192151921619217192181921919220192211922219223192241922519226192271922819229192301923119232192331923419235192361923719238192391924019241192421924319244192451924619247192481924919250192511925219253192541925519256192571925819259192601926119262192631926419265192661926719268192691927019271192721927319274192751927619277192781927919280192811928219283192841928519286192871928819289192901929119292192931929419295192961929719298192991930019301193021930319304193051930619307193081930919310193111931219313193141931519316193171931819319193201932119322193231932419325193261932719328193291933019331193321933319334193351933619337193381933919340193411934219343193441934519346193471934819349193501935119352193531935419355193561935719358193591936019361193621936319364193651936619367193681936919370193711937219373193741937519376193771937819379193801938119382193831938419385193861938719388193891939019391193921939319394193951939619397193981939919400194011940219403194041940519406194071940819409194101941119412194131941419415194161941719418194191942019421194221942319424194251942619427194281942919430194311943219433194341943519436194371943819439194401944119442194431944419445194461944719448194491945019451194521945319454194551945619457194581945919460194611946219463194641946519466194671946819469194701947119472194731947419475194761947719478194791948019481194821948319484194851948619487194881948919490194911949219493194941949519496194971949819499195001950119502195031950419505195061950719508195091951019511195121951319514195151951619517195181951919520195211952219523195241952519526195271952819529195301953119532195331953419535195361953719538195391954019541195421954319544195451954619547195481954919550195511955219553195541955519556195571955819559195601956119562195631956419565195661956719568195691957019571195721957319574195751957619577195781957919580195811958219583195841958519586195871958819589195901959119592195931959419595195961959719598195991960019601196021960319604196051960619607196081960919610196111961219613196141961519616196171961819619196201962119622196231962419625196261962719628196291963019631196321963319634196351963619637196381963919640196411964219643196441964519646196471964819649196501965119652196531965419655196561965719658196591966019661196621966319664196651966619667196681966919670196711967219673196741967519676196771967819679196801968119682196831968419685196861968719688196891969019691196921969319694196951969619697196981969919700197011970219703197041970519706197071970819709197101971119712197131971419715197161971719718197191972019721197221972319724197251972619727197281972919730197311973219733197341973519736197371973819739197401974119742197431974419745197461974719748197491975019751197521975319754197551975619757197581975919760197611976219763197641976519766197671976819769197701977119772197731977419775197761977719778197791978019781197821978319784197851978619787197881978919790197911979219793197941979519796197971979819799198001980119802198031980419805198061980719808198091981019811198121981319814198151981619817198181981919820198211982219823198241982519826198271982819829198301983119832198331983419835198361983719838198391984019841198421984319844198451984619847198481984919850198511985219853198541985519856198571985819859198601986119862198631986419865198661986719868198691987019871198721987319874198751987619877198781987919880198811988219883198841988519886198871988819889198901989119892198931989419895198961989719898198991990019901199021990319904199051990619907199081990919910199111991219913199141991519916199171991819919199201992119922199231992419925199261992719928199291993019931199321993319934199351993619937199381993919940199411994219943199441994519946199471994819949199501995119952199531995419955199561995719958199591996019961199621996319964199651996619967199681996919970199711997219973199741997519976199771997819979199801998119982199831998419985199861998719988199891999019991199921999319994199951999619997199981999920000200012000220003200042000520006200072000820009200102001120012200132001420015200162001720018200192002020021200222002320024200252002620027200282002920030200312003220033200342003520036200372003820039200402004120042200432004420045200462004720048200492005020051200522005320054200552005620057200582005920060200612006220063200642006520066200672006820069200702007120072200732007420075200762007720078200792008020081200822008320084200852008620087200882008920090200912009220093200942009520096200972009820099201002010120102201032010420105201062010720108201092011020111201122011320114201152011620117201182011920120201212012220123201242012520126201272012820129201302013120132201332013420135201362013720138201392014020141201422014320144201452014620147201482014920150201512015220153201542015520156201572015820159201602016120162201632016420165201662016720168201692017020171201722017320174201752017620177201782017920180201812018220183201842018520186201872018820189201902019120192201932019420195201962019720198201992020020201202022020320204202052020620207202082020920210202112021220213202142021520216202172021820219202202022120222202232022420225202262022720228202292023020231202322023320234202352023620237202382023920240202412024220243202442024520246202472024820249202502025120252202532025420255202562025720258202592026020261202622026320264202652026620267202682026920270202712027220273202742027520276202772027820279202802028120282202832028420285202862028720288202892029020291202922029320294202952029620297202982029920300203012030220303203042030520306203072030820309203102031120312203132031420315203162031720318203192032020321203222032320324203252032620327203282032920330203312033220333203342033520336203372033820339203402034120342203432034420345203462034720348203492035020351203522035320354203552035620357203582035920360203612036220363203642036520366203672036820369203702037120372203732037420375203762037720378203792038020381203822038320384203852038620387203882038920390203912039220393203942039520396203972039820399204002040120402204032040420405204062040720408204092041020411204122041320414204152041620417204182041920420204212042220423204242042520426204272042820429204302043120432204332043420435204362043720438204392044020441204422044320444204452044620447204482044920450204512045220453204542045520456204572045820459204602046120462204632046420465204662046720468204692047020471204722047320474204752047620477204782047920480204812048220483204842048520486204872048820489204902049120492204932049420495204962049720498204992050020501205022050320504205052050620507205082050920510205112051220513205142051520516205172051820519205202052120522205232052420525205262052720528205292053020531205322053320534205352053620537205382053920540205412054220543205442054520546205472054820549205502055120552205532055420555205562055720558205592056020561205622056320564205652056620567205682056920570205712057220573205742057520576205772057820579205802058120582205832058420585205862058720588205892059020591205922059320594205952059620597205982059920600206012060220603206042060520606206072060820609206102061120612206132061420615206162061720618206192062020621206222062320624206252062620627206282062920630206312063220633206342063520636206372063820639206402064120642206432064420645206462064720648206492065020651206522065320654206552065620657206582065920660206612066220663206642066520666206672066820669206702067120672206732067420675206762067720678206792068020681206822068320684206852068620687206882068920690206912069220693206942069520696206972069820699207002070120702207032070420705207062070720708207092071020711207122071320714207152071620717207182071920720207212072220723207242072520726207272072820729207302073120732207332073420735207362073720738207392074020741207422074320744207452074620747207482074920750207512075220753207542075520756207572075820759207602076120762207632076420765207662076720768207692077020771207722077320774207752077620777207782077920780207812078220783207842078520786207872078820789207902079120792207932079420795207962079720798207992080020801208022080320804208052080620807208082080920810208112081220813208142081520816208172081820819208202082120822208232082420825208262082720828208292083020831208322083320834208352083620837208382083920840208412084220843208442084520846208472084820849208502085120852208532085420855208562085720858208592086020861208622086320864208652086620867208682086920870208712087220873208742087520876208772087820879208802088120882208832088420885208862088720888208892089020891208922089320894208952089620897208982089920900209012090220903209042090520906209072090820909209102091120912209132091420915209162091720918209192092020921209222092320924209252092620927209282092920930209312093220933209342093520936209372093820939209402094120942209432094420945209462094720948209492095020951209522095320954209552095620957209582095920960209612096220963209642096520966209672096820969209702097120972209732097420975209762097720978209792098020981209822098320984209852098620987209882098920990209912099220993209942099520996209972099820999210002100121002210032100421005210062100721008210092101021011210122101321014210152101621017210182101921020210212102221023210242102521026210272102821029210302103121032210332103421035210362103721038210392104021041210422104321044210452104621047210482104921050210512105221053210542105521056210572105821059210602106121062210632106421065210662106721068210692107021071210722107321074210752107621077210782107921080210812108221083210842108521086210872108821089210902109121092210932109421095210962109721098210992110021101211022110321104211052110621107211082110921110211112111221113211142111521116211172111821119211202112121122211232112421125211262112721128211292113021131211322113321134211352113621137211382113921140211412114221143211442114521146211472114821149211502115121152211532115421155211562115721158211592116021161211622116321164211652116621167211682116921170211712117221173211742117521176211772117821179211802118121182211832118421185211862118721188211892119021191211922119321194211952119621197211982119921200212012120221203212042120521206212072120821209212102121121212212132121421215212162121721218212192122021221212222122321224212252122621227212282122921230212312123221233212342123521236212372123821239212402124121242212432124421245212462124721248212492125021251212522125321254212552125621257212582125921260212612126221263212642126521266212672126821269212702127121272212732127421275212762127721278212792128021281212822128321284212852128621287212882128921290212912129221293212942129521296212972129821299213002130121302213032130421305213062130721308213092131021311213122131321314213152131621317213182131921320213212132221323213242132521326213272132821329213302133121332213332133421335213362133721338213392134021341213422134321344213452134621347213482134921350213512135221353213542135521356213572135821359213602136121362213632136421365213662136721368213692137021371213722137321374213752137621377213782137921380213812138221383213842138521386213872138821389213902139121392213932139421395213962139721398213992140021401214022140321404214052140621407214082140921410214112141221413214142141521416214172141821419214202142121422214232142421425214262142721428214292143021431214322143321434214352143621437214382143921440214412144221443214442144521446214472144821449214502145121452214532145421455214562145721458214592146021461214622146321464214652146621467214682146921470214712147221473214742147521476214772147821479214802148121482214832148421485214862148721488214892149021491214922149321494214952149621497214982149921500215012150221503215042150521506215072150821509215102151121512215132151421515215162151721518215192152021521215222152321524215252152621527215282152921530215312153221533215342153521536215372153821539215402154121542215432154421545215462154721548215492155021551215522155321554215552155621557215582155921560215612156221563215642156521566215672156821569215702157121572215732157421575215762157721578215792158021581215822158321584215852158621587215882158921590215912159221593215942159521596215972159821599216002160121602216032160421605216062160721608216092161021611216122161321614216152161621617216182161921620216212162221623216242162521626216272162821629216302163121632216332163421635216362163721638216392164021641216422164321644216452164621647216482164921650216512165221653216542165521656216572165821659216602166121662216632166421665216662166721668216692167021671216722167321674216752167621677216782167921680216812168221683216842168521686216872168821689216902169121692216932169421695216962169721698216992170021701217022170321704217052170621707217082170921710217112171221713217142171521716217172171821719217202172121722217232172421725217262172721728217292173021731217322173321734217352173621737217382173921740217412174221743217442174521746217472174821749217502175121752217532175421755217562175721758217592176021761217622176321764217652176621767217682176921770217712177221773217742177521776217772177821779217802178121782217832178421785217862178721788217892179021791217922179321794217952179621797217982179921800218012180221803218042180521806218072180821809218102181121812218132181421815218162181721818218192182021821218222182321824218252182621827218282182921830218312183221833218342183521836218372183821839218402184121842218432184421845218462184721848218492185021851218522185321854218552185621857218582185921860218612186221863218642186521866218672186821869218702187121872218732187421875218762187721878218792188021881218822188321884218852188621887218882188921890218912189221893218942189521896218972189821899219002190121902219032190421905219062190721908219092191021911219122191321914219152191621917219182191921920219212192221923219242192521926219272192821929219302193121932219332193421935219362193721938219392194021941219422194321944219452194621947219482194921950219512195221953219542195521956219572195821959219602196121962219632196421965219662196721968219692197021971219722197321974219752197621977219782197921980219812198221983219842198521986219872198821989219902199121992219932199421995219962199721998219992200022001220022200322004220052200622007220082200922010220112201222013220142201522016220172201822019220202202122022220232202422025220262202722028220292203022031220322203322034220352203622037220382203922040220412204222043220442204522046220472204822049220502205122052220532205422055220562205722058220592206022061220622206322064220652206622067220682206922070220712207222073220742207522076220772207822079220802208122082220832208422085220862208722088220892209022091220922209322094220952209622097220982209922100221012210222103221042210522106221072210822109221102211122112221132211422115221162211722118221192212022121221222212322124221252212622127221282212922130221312213222133221342213522136221372213822139221402214122142221432214422145221462214722148221492215022151221522215322154221552215622157221582215922160221612216222163221642216522166221672216822169221702217122172221732217422175221762217722178221792218022181221822218322184221852218622187221882218922190221912219222193221942219522196221972219822199222002220122202222032220422205222062220722208222092221022211222122221322214222152221622217222182221922220222212222222223222242222522226222272222822229222302223122232222332223422235222362223722238222392224022241222422224322244222452224622247222482224922250222512225222253222542225522256222572225822259222602226122262222632226422265222662226722268222692227022271222722227322274222752227622277222782227922280222812228222283222842228522286222872228822289222902229122292222932229422295222962229722298222992230022301223022230322304223052230622307223082230922310223112231222313223142231522316223172231822319223202232122322223232232422325223262232722328223292233022331223322233322334223352233622337223382233922340223412234222343223442234522346223472234822349223502235122352223532235422355223562235722358223592236022361223622236322364223652236622367223682236922370223712237222373223742237522376223772237822379223802238122382223832238422385223862238722388223892239022391223922239322394223952239622397223982239922400224012240222403224042240522406224072240822409224102241122412224132241422415224162241722418224192242022421224222242322424224252242622427224282242922430224312243222433224342243522436224372243822439224402244122442224432244422445224462244722448224492245022451224522245322454224552245622457224582245922460224612246222463224642246522466224672246822469224702247122472224732247422475224762247722478224792248022481224822248322484224852248622487224882248922490224912249222493224942249522496224972249822499225002250122502225032250422505225062250722508225092251022511225122251322514225152251622517225182251922520225212252222523225242252522526225272252822529225302253122532225332253422535225362253722538225392254022541225422254322544225452254622547225482254922550225512255222553225542255522556225572255822559225602256122562225632256422565225662256722568225692257022571225722257322574225752257622577225782257922580225812258222583225842258522586225872258822589225902259122592225932259422595225962259722598225992260022601226022260322604226052260622607226082260922610226112261222613226142261522616226172261822619226202262122622226232262422625226262262722628226292263022631226322263322634226352263622637226382263922640226412264222643226442264522646226472264822649226502265122652226532265422655226562265722658226592266022661226622266322664226652266622667226682266922670226712267222673226742267522676226772267822679226802268122682226832268422685226862268722688226892269022691226922269322694226952269622697226982269922700227012270222703227042270522706227072270822709227102271122712227132271422715227162271722718227192272022721227222272322724227252272622727227282272922730227312273222733227342273522736227372273822739227402274122742227432274422745227462274722748227492275022751227522275322754227552275622757227582275922760227612276222763227642276522766227672276822769227702277122772227732277422775227762277722778227792278022781227822278322784227852278622787227882278922790227912279222793227942279522796227972279822799228002280122802228032280422805228062280722808228092281022811228122281322814228152281622817228182281922820228212282222823228242282522826228272282822829228302283122832228332283422835228362283722838228392284022841228422284322844228452284622847228482284922850228512285222853228542285522856228572285822859228602286122862228632286422865228662286722868228692287022871228722287322874228752287622877228782287922880228812288222883228842288522886228872288822889228902289122892228932289422895228962289722898228992290022901229022290322904229052290622907229082290922910229112291222913229142291522916229172291822919229202292122922
  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. //===============================
  42. // OCPP auth variable
  43. //===============================
  44. static int authorizeRetryTimes = 0; //number of Retry times
  45. //===============================
  46. // OCPP other variables
  47. //===============================
  48. static int HeartBeatWaitTime = 10;
  49. static int FirstHeartBeat = 0;
  50. static int FirmwareStatusNotificationStatus = FIRMWARE_STATUS_IDLE; // Idle
  51. static int DiagnosticsStatusNotificationStatus = DIAGNOSTIC_STATUS_IDLE; // Idle
  52. static char CurrentChargingProfileScheduleStr[30] = {0};
  53. static float periousPeriodicPowerConsumption[CONNECTOR_QUANTITY] = {0};
  54. static float periousClockPowerConsumption[CONNECTOR_QUANTITY] = {0};
  55. //========================================
  56. // OCPP status/previous related variables
  57. //========================================
  58. static int GunStatusInterval = 10;
  59. static uint8_t ChademoPreviousSystemStatus[(CHAdeMO_QUANTITY>0?CHAdeMO_QUANTITY:1)];
  60. static uint8_t CcsPreviousSystemStatus[(CCS_QUANTITY>0?CCS_QUANTITY:1)];
  61. static uint8_t GbPreviousSystemStatus[(GB_QUANTITY>0?GB_QUANTITY:1)];
  62. static uint8_t AcPreviousSystemStatus[(AC_QUANTITY>0?AC_QUANTITY:1)];
  63. static uint8_t DoPreviousSystemStatus[(CONNECTOR_QUANTITY>0?CONNECTOR_QUANTITY:1)];
  64. static uint8_t ChademoPreviousConnectorPlugIn[(CHAdeMO_QUANTITY>0?CHAdeMO_QUANTITY:1)];
  65. static uint8_t CcsPreviousConnectorPlugIn[(CCS_QUANTITY>0?CCS_QUANTITY:1)];
  66. static uint8_t GbPreviousConnectorPlugIn[(GB_QUANTITY>0?GB_QUANTITY:1)];
  67. static uint8_t AcPreviousConnectorPlugIn[(AC_QUANTITY>0?AC_QUANTITY:1)];
  68. static uint8_t DoPreviousConnectorPlugIn[(CONNECTOR_QUANTITY>0?CONNECTOR_QUANTITY:1)];
  69. static int TransactionMessageAttemptsValue = 0;
  70. static int TransactionMessageRetryIntervalValue = 0;
  71. static int TempMeterValueInterval = 0;
  72. static struct OCPPAuthLocalElemet
  73. {
  74. int listVersionInt;
  75. char idTagstr[21];
  76. char parentIdTag[21];
  77. char expiryDate[36];
  78. char idTagstatus[16];
  79. }idTagQuery;
  80. //============================================
  81. // OCPP MeterValue request flag
  82. //============================================
  83. uint8_t reqSampleMeter[CONNECTOR_QUANTITY]={0};
  84. uint8_t reqClockAlignMeter[CONNECTOR_QUANTITY]={0};
  85. //============================================
  86. // OCPP HeartBeat Response Not Receive Counts
  87. //============================================
  88. static int HeartBeatWithNOResponse = 0;
  89. //============================================
  90. // OCPP California Pricing Requirements
  91. //============================================
  92. static char dmsVersion[21] = {0};
  93. extern sqlite3 *db;
  94. int TransactionMessageAttemptsGet(void);
  95. int TransactionMessageRetryIntervalGet(void);
  96. int GetOcppConnStatus(void);
  97. void SetOcppConnStatus(uint8_t status);
  98. int setKeyValue(char *key, char *value);
  99. void OCPP_get_TableAuthlocalAllData(void);
  100. void processUnkownKey(void);
  101. struct InterLock
  102. {
  103. unsigned char isSentUnplug[CONNECTOR_QUANTITY];
  104. unsigned char isGetDiagnosticGoing:1;
  105. unsigned char isUpdateFirmwareGoing:1;
  106. }interLock;
  107. struct ClientTime
  108. {
  109. struct timespec Heartbeat;
  110. struct timespec StatusNotification[CONNECTOR_QUANTITY];
  111. struct timespec StartTransaction;
  112. struct timespec StopTransaction;
  113. struct timespec MeterValues[CONNECTOR_QUANTITY];
  114. struct timespec RemoteStartWait;
  115. struct timespec TcciQueryDeduct;
  116. struct timespec CharingProfileRefresh[CONNECTOR_QUANTITY];
  117. }clientTime;
  118. typedef union
  119. {
  120. //Operations Initiated by Central System
  121. unsigned char CsMsgValue[CONNECTOR_QUANTITY];
  122. struct
  123. {
  124. //CsMsgValue[0]
  125. unsigned char StatusNotificationReq:1; //bit 0,
  126. unsigned char StatusNotificationConf:1; //bit 1,
  127. unsigned char TriggerMeterValue:1; //bit 2,
  128. unsigned char TriggerStatusNotificationReq:1; //bit 3,
  129. unsigned char isOnCharging:1; //bit 4,
  130. unsigned char :3; //bit5~7
  131. }bits[CONNECTOR_QUANTITY];
  132. }CpinitiateMsg;
  133. CpinitiateMsg cpinitateMsg;
  134. //GetConfiguration Array
  135. struct StructConfigurationKeyItems staticKeyArray[GetConfigurationMaxKeysNUM]={0};
  136. struct StructConfigurationKey staticResponseConfigurationKeyArray[GetConfigurationMaxKeysNUM]={0};
  137. struct StructConfigurationKeyItems staticResponseUnknownKey[10]={0};
  138. struct StructLocalAuthorizationList staticLocalAuthorizationList[1]={0};
  139. static char *ChargePointErrorCodeStr[] = {
  140. MACROSTR(ConnectorLockFailure),
  141. MACROSTR(EVCommunicationError),
  142. MACROSTR(GroundFailure),
  143. MACROSTR(HighTemperature),
  144. MACROSTR(InternalError),
  145. MACROSTR(LocalListConflict),
  146. MACROSTR(NoError),
  147. MACROSTR(OtherError),
  148. MACROSTR(OverCurrentFailure),
  149. MACROSTR(OverVoltage),
  150. MACROSTR(PowerMeterFailure),
  151. MACROSTR(PowerSwitchFailure),
  152. MACROSTR(ReaderFailure),
  153. MACROSTR(ResetFailure),
  154. MACROSTR(UnderVoltage),
  155. MACROSTR(WeakSignal)
  156. };
  157. static char * ChargePointStatusStr[] = {
  158. MACROSTR(Available),
  159. MACROSTR(Preparing),
  160. MACROSTR(Charging),
  161. MACROSTR(SuspendedEVSE),
  162. MACROSTR(SuspendedEV),
  163. MACROSTR(Finishing),
  164. MACROSTR(Reserved),
  165. MACROSTR(Unavailable),
  166. MACROSTR(Faulted)
  167. };
  168. static char *RegistrationStatusStr[] = {
  169. MACROSTR(Accepted),
  170. MACROSTR(Pending),
  171. MACROSTR(Rejected)
  172. };
  173. static char *AvailabilityTypeStr[] = {
  174. MACROSTR(Inoperative),
  175. MACROSTR(Operative)
  176. };
  177. static char *AvailabilityStatusStr[] = {
  178. MACROSTR(Accepted),
  179. MACROSTR(Rejected),
  180. MACROSTR(Scheduled)
  181. };
  182. static char *ConfigurationStatusStr[] = {
  183. MACROSTR(Accepted),
  184. MACROSTR(Rejected),
  185. MACROSTR(RebootRequired),
  186. MACROSTR(NotSupported)
  187. };
  188. static char *ClearCacheStatusStr[] = {
  189. MACROSTR(Accepted),
  190. MACROSTR(Rejected)
  191. };
  192. static char *ChargingProfilePurposeTypeStr[] = {
  193. MACROSTR(ChargePointMaxProfile),
  194. MACROSTR(TxDefaultProfile),
  195. MACROSTR(TxProfile)
  196. };
  197. static char *ChargingProfileStatusStr[] = {
  198. MACROSTR(Accepted),
  199. MACROSTR(Rejected),
  200. MACROSTR(NotSupported)
  201. };
  202. static char *ClearChargingProfileStatusStr[] = {
  203. MACROSTR(Accepted),
  204. MACROSTR(Unknown)
  205. };
  206. static char *GetCompositeScheduleStatusStr[] = {
  207. MACROSTR(Accepted),
  208. MACROSTR(Rejected)
  209. };
  210. static char *UpdateTypeStr[] = {
  211. MACROSTR(Differential),
  212. MACROSTR(Full)
  213. };
  214. static char *UpdateStatusStr[] = {
  215. MACROSTR(Accepted),
  216. MACROSTR(Failed),
  217. MACROSTR(NotSupported),
  218. MACROSTR(VersionMismatch)
  219. };
  220. static char *RemoteStartStopStatusStr[] = {
  221. MACROSTR(Accepted),
  222. MACROSTR(Rejected)
  223. };
  224. static char *ReservationStatusStr[] = {
  225. MACROSTR(Accepted),
  226. MACROSTR(Faulted),
  227. MACROSTR(Occupied),
  228. MACROSTR(Rejected),
  229. MACROSTR(Unavailable)
  230. };
  231. static char *ResetTypeStr[] = {
  232. MACROSTR(Hard),
  233. MACROSTR(Soft)
  234. };
  235. static char *ResetStatusStr[] = {
  236. MACROSTR(Accepted),
  237. MACROSTR(Rejected)
  238. };
  239. static char * DiagnosticsStatusStr[] = {
  240. MACROSTR(Idle),
  241. MACROSTR(Uploaded),
  242. MACROSTR(UploadFailed),
  243. MACROSTR(Uploading)
  244. };
  245. static char * FirmwareStatusStr[] = {
  246. MACROSTR(Downloaded),
  247. MACROSTR(DownloadFailed),
  248. MACROSTR(Downloading),
  249. MACROSTR(Idle),
  250. MACROSTR(InstallationFailed),
  251. MACROSTR(Installing),
  252. MACROSTR(Installed)
  253. };
  254. static char * MessageTriggerStr[] = {
  255. MACROSTR(BootNotification),
  256. MACROSTR(DiagnosticsStatusNotification),
  257. MACROSTR(FirmwareStatusNotification),
  258. MACROSTR(Heartbeat),
  259. MACROSTR(MeterValues),
  260. MACROSTR(StatusNotification)
  261. };
  262. static char * TriggerMessageStatusStr[] = {
  263. MACROSTR(Accepted),
  264. MACROSTR(Rejected),
  265. MACROSTR(NotImplemented)
  266. };
  267. static char * UnlockStatusStr[] = {
  268. MACROSTR(Unlocked),
  269. MACROSTR(UnlockFailed),
  270. MACROSTR(NotSupported)
  271. };
  272. #if 0
  273. static char * StopTransactionReasonStr[] = {
  274. MACROSTR(EmergencyStop),
  275. MACROSTR(EVDisconnected),
  276. MACROSTR(HardReset),
  277. MACROSTR(Local),
  278. MACROSTR(Other),
  279. MACROSTR(PowerLoss),
  280. MACROSTR(Reboot),
  281. MACROSTR(Remote),
  282. MACROSTR(SoftReset),
  283. MACROSTR(UnlockCommand),
  284. MACROSTR(DeAuthorized)
  285. };
  286. #endif
  287. static char * CancelReservationStatusStr[] = {
  288. MACROSTR(Accepted),
  289. MACROSTR(Rejected)
  290. };
  291. static char * ReadingContextStr[] = {
  292. MACROSTR(Interruption.Begin),
  293. MACROSTR(Interruption.End),
  294. MACROSTR(Other),
  295. MACROSTR(Sample.Clock),
  296. MACROSTR(Sample.Periodic),
  297. MACROSTR(Transaction.Begin),
  298. MACROSTR(Transaction.End),
  299. MACROSTR(Trigger)
  300. };
  301. static char * ValueFormatStr[] = {
  302. MACROSTR(Raw),
  303. MACROSTR(SignedData)
  304. };
  305. static char * MeasurandStr[] = {
  306. MACROSTR(Current.Export),
  307. MACROSTR(Current.Import),
  308. MACROSTR(Current.Offered),
  309. MACROSTR(Energy.Active.Export.Register),
  310. MACROSTR(Energy.Active.Import.Register),
  311. MACROSTR(Energy.Reactive.Export.Register),
  312. MACROSTR(Energy.Reactive.Import.Register),
  313. MACROSTR(Energy.Active.Export.Interval),
  314. MACROSTR(Energy.Active.Import.Interval),
  315. MACROSTR(Energy.Reactive.Export.Interval),
  316. MACROSTR(Energy.Reactive.Import.Interval),
  317. MACROSTR(Frequency),
  318. MACROSTR(Power.Active.Export),
  319. MACROSTR(Power.Active.Import),
  320. MACROSTR(Power.Factor),
  321. MACROSTR(Power.Offered),
  322. MACROSTR(Power.Reactive.ExportMACROSTR),
  323. MACROSTR(Power.Reactive.Import),
  324. MACROSTR(RPM),
  325. MACROSTR(SoC),
  326. MACROSTR(Temperature),
  327. MACROSTR(Voltage)
  328. };
  329. static char * LocationStr[] = {
  330. MACROSTR(Body),
  331. MACROSTR(Cable),
  332. MACROSTR(EV),
  333. MACROSTR(Inlet),
  334. MACROSTR(Outlet)
  335. };
  336. static char * PhaseStr[] = {
  337. MACROSTR(L1),
  338. MACROSTR(L2),
  339. MACROSTR(L3),
  340. MACROSTR(N),
  341. MACROSTR(L1-N),
  342. MACROSTR(L2-N),
  343. MACROSTR(L3-N),
  344. MACROSTR(L1-L2),
  345. MACROSTR(L2-L3),
  346. MACROSTR(L3-L1)
  347. };
  348. static char * UnitOfMeasureStr[] = {
  349. MACROSTR(Wh),
  350. MACROSTR(kWh),
  351. MACROSTR(varh),
  352. MACROSTR(kvarh),
  353. MACROSTR(W),
  354. MACROSTR(kW),
  355. MACROSTR(VA),
  356. MACROSTR(kVA),
  357. MACROSTR(var),
  358. MACROSTR(kvar),
  359. MACROSTR(A),
  360. MACROSTR(V),
  361. MACROSTR(Celsius),
  362. MACROSTR(Fahrenheit),
  363. MACROSTR(K),
  364. MACROSTR(Percent)
  365. };
  366. //=========================================
  367. // Certificate related routine
  368. //=========================================
  369. int certVerify(char *privateKey, char *cert)
  370. {
  371. int result = PASS;
  372. SSL_CTX *ctx = SSL_CTX_new(TLS_method());
  373. // Load certificate file
  374. if(SSL_CTX_use_certificate_file(ctx, cert, SSL_FILETYPE_PEM) <= 0)
  375. {
  376. DEBUG_ERROR("Load certificate error!\n");
  377. result = FAIL;
  378. }
  379. // Load private key file
  380. if(SSL_CTX_use_PrivateKey_file(ctx, privateKey, SSL_FILETYPE_PEM) <= 0)
  381. {
  382. DEBUG_ERROR("Load private key error!\n");
  383. result = FAIL;
  384. }
  385. if(!SSL_CTX_check_private_key(ctx))
  386. {
  387. result = FAIL;
  388. }
  389. SSL_CTX_free(ctx);
  390. return result;
  391. }
  392. //=========================================
  393. // TTIA routine
  394. //=========================================
  395. int sendTTIAInfo(uint8_t gun_index)
  396. {
  397. static int sn = 0;
  398. int result = FAIL;
  399. struct hostent *server;
  400. int udp_socket_fd;
  401. struct sockaddr_in dest_addr = {0};
  402. uint8_t tx_buf[80] = {0};
  403. uint8_t logBuf[256]= {0};
  404. uint8_t tx_len, tempIndex, socStart, socEnd;
  405. uint16_t PresentChargedEnergy;
  406. struct tm tmStart, tmEnd;
  407. DEBUG_INFO("sendTTIAInfo...\n");
  408. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  409. {
  410. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  411. {
  412. tempIndex = ((gun_index==2) ? 1: 0);
  413. }
  414. else
  415. {
  416. tempIndex = gun_index;
  417. }
  418. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  419. {
  420. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  421. {
  422. socStart = ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].EvBatteryStartSoc;
  423. socEnd = ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].EvBatterySoc;
  424. PresentChargedEnergy = (uint16_t)(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargedEnergy*10);
  425. }
  426. }
  427. }
  428. else if(gunType[gun_index] == GUN_TYPE_CCS)
  429. {
  430. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  431. {
  432. tempIndex = ((gun_index==2) ? 1: 0);
  433. }
  434. else
  435. {
  436. tempIndex = gun_index;
  437. }
  438. for (int index = 0; index < CCS_QUANTITY; index++)
  439. {
  440. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  441. {
  442. socStart = ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].EvBatteryStartSoc;
  443. socEnd = ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].EvBatterySoc;
  444. PresentChargedEnergy = (uint16_t)(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargedEnergy*10);
  445. }
  446. }
  447. }
  448. else if(gunType[gun_index] == GUN_TYPE_GBT)
  449. {
  450. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  451. {
  452. tempIndex = ((gun_index==2) ? 1: 0);
  453. }
  454. else
  455. {
  456. tempIndex = gun_index;
  457. }
  458. for (int index = 0; index < GB_QUANTITY; index++)
  459. {
  460. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  461. {
  462. socStart = ShmSysConfigAndInfo->SysInfo.GbChargingData[index].EvBatteryStartSoc;
  463. socEnd = ShmSysConfigAndInfo->SysInfo.GbChargingData[index].EvBatterySoc;
  464. PresentChargedEnergy = (uint16_t)(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargedEnergy*10);
  465. }
  466. }
  467. }
  468. else if(gunType[gun_index] == GUN_TYPE_DO)
  469. {
  470. tempIndex = gun_index;
  471. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  472. {
  473. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  474. {
  475. socStart = ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.EvBatteryStartSoc;
  476. socEnd = ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.EvBatterySoc;
  477. PresentChargedEnergy = (uint16_t)(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PresentChargedEnergy*10);
  478. }
  479. }
  480. }
  481. else
  482. {
  483. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  484. {
  485. tempIndex = 2;
  486. }
  487. else
  488. {
  489. tempIndex = gun_index;
  490. }
  491. for (int index = 0; index < AC_QUANTITY; index++)
  492. {
  493. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  494. {
  495. socStart = ShmSysConfigAndInfo->SysInfo.AcChargingData[index].EvBatteryStartSoc;
  496. socEnd = ShmSysConfigAndInfo->SysInfo.AcChargingData[index].EvBatterySoc;
  497. PresentChargedEnergy = (uint16_t)(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargedEnergy*10);
  498. }
  499. }// END
  500. }
  501. // Message assembly
  502. sprintf((char*)&tx_buf[0], "APTS"); // Protocol ID
  503. tx_buf[4] = 0x02; // Protocol Version
  504. tx_buf[5] = 0xb0; // Message ID
  505. tx_buf[6] = ShmSysConfigAndInfo->SysConfig.TTIA_Info.busVenderId & 0xff; // CustomerID low byte
  506. tx_buf[7] = (ShmSysConfigAndInfo->SysConfig.TTIA_Info.busVenderId>>8) & 0xff; // CustomerID high byte
  507. tx_buf[8] = 0x00; // CarID low byte
  508. tx_buf[9] = 0x00; // CarID high byte
  509. tx_buf[10] = 0x00; // ID Storage
  510. tx_buf[11] = 0x00; // Driver lowest byte
  511. tx_buf[12] = 0x00; // Driver 2nd byte
  512. tx_buf[13] = 0x00; // Driver 3rd byte
  513. tx_buf[14] = 0x00; // Driver highest byte
  514. tx_buf[15] = sn & 0xff; // Sequence SN low byte
  515. tx_buf[16] = (sn>>8) & 0xff; // Sequence SN high byte
  516. tx_buf[17] = 0x00; // Reserve
  517. tx_buf[18] = 60 & 0xff; // Payload length low byte
  518. tx_buf[19] = (60>>8) & 0xff; // Payload length high byte
  519. // EVSE provider
  520. memcpy((char*)&tx_buf[20], ShmSysConfigAndInfo->SysConfig.TTIA_Info.EquipmentProvider, 15);
  521. // EVSE provider
  522. tx_buf[35] = ShmSysConfigAndInfo->SysConfig.TTIA_Info.TransportationCompanyNo;
  523. // EVSE id
  524. tx_buf[36] = ShmSysConfigAndInfo->SysConfig.TTIA_Info.ChargeBoxId;
  525. // Connector id
  526. tx_buf[37] = gun_index;
  527. // EVSE station
  528. memcpy((char*)&tx_buf[38], ShmSysConfigAndInfo->SysConfig.TTIA_Info.evseStation, 15);
  529. // Vehicle SN
  530. memcpy(&tx_buf[53], &ShmOCPP16Data->StartTransaction[gun_index].IdTag, 8);
  531. // Mileage
  532. tx_buf[61] = 0x00; // lowest byte
  533. tx_buf[62] = 0x00; // 2nd byte
  534. tx_buf[63] = 0x00; // highest byte
  535. // Start date time 6 bytes
  536. 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))
  537. {
  538. struct tm *tmTarget;
  539. struct timeb tbTarget;
  540. tmStart.tm_year -= 1900;
  541. tmStart.tm_mon -= 1;
  542. tmStart.tm_gmtoff = 0;
  543. tbTarget.time = mktime(&tmStart);
  544. tbTarget.timezone = 0;
  545. tbTarget.time += (8*3600);
  546. tmTarget = gmtime(&tbTarget.time);
  547. tx_buf[64] = ((tmTarget->tm_year+1900)-2000);
  548. tx_buf[65] = (tmTarget->tm_mon+1);
  549. tx_buf[66] = tmTarget->tm_mday;
  550. tx_buf[67] = tmTarget->tm_hour;
  551. tx_buf[68] = tmTarget->tm_min;
  552. tx_buf[69] = tmTarget->tm_sec;
  553. }
  554. // Stop date time 6 bytes
  555. 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))
  556. {
  557. struct tm *tmTarget;
  558. struct timeb tbTarget;
  559. tmEnd.tm_year -= 1900;
  560. tmEnd.tm_mon -= 1;
  561. tmEnd.tm_gmtoff = 0;
  562. tbTarget.time = mktime(&tmEnd);
  563. tbTarget.timezone = 0;
  564. tbTarget.time += (8*3600);
  565. tmTarget = gmtime(&tbTarget.time);
  566. tx_buf[70] = ((tmTarget->tm_year+1900)-2000);
  567. tx_buf[71] = (tmTarget->tm_mon+1);
  568. tx_buf[72] = tmTarget->tm_mday;
  569. tx_buf[73] = tmTarget->tm_hour;
  570. tx_buf[74] = tmTarget->tm_min;
  571. tx_buf[75] = tmTarget->tm_sec;
  572. }
  573. // Session energy 2 bytes
  574. tx_buf[76] = PresentChargedEnergy & 0xff;
  575. tx_buf[77] = (PresentChargedEnergy>>8) & 0xff;
  576. // Start SOC 1 byte
  577. tx_buf[78] = socStart;
  578. // Stop SOC 1 byte
  579. tx_buf[79] = socEnd;
  580. // Open socket
  581. udp_socket_fd = socket(AF_INET, SOCK_DGRAM, 0);
  582. if(udp_socket_fd == -1)
  583. {
  584. DEBUG_ERROR("UDP socket create failed!\n");
  585. }
  586. else
  587. {
  588. // Get server DNS entry
  589. server = gethostbyname((char*)ShmSysConfigAndInfo->SysConfig.TTIA_Info.server_addr);
  590. if (server == NULL)
  591. {
  592. DEBUG_ERROR("ERROR, no such host as %s\n", ShmSysConfigAndInfo->SysConfig.TTIA_Info.server_addr);
  593. }
  594. else
  595. {
  596. // Build the server's Internet address
  597. bzero((char *) &dest_addr, sizeof(dest_addr));
  598. dest_addr.sin_family = AF_INET;
  599. bcopy((char *)server->h_addr, (char *)&dest_addr.sin_addr.s_addr, server->h_length);
  600. dest_addr.sin_port = htons(ShmSysConfigAndInfo->SysConfig.TTIA_Info.server_port);
  601. if((tx_len = sendto(udp_socket_fd, tx_buf, ARRAY_SIZE(tx_buf), 0, &dest_addr, sizeof(dest_addr))) >= 0)
  602. {
  603. for(uint8_t idx=0;idx<ARRAY_SIZE(tx_buf);idx++)
  604. {
  605. sprintf((char*)logBuf, "%s %02X", logBuf, tx_buf[idx]);
  606. }
  607. DEBUG_TTIA_INFO("TX raw data length: %d\n", tx_len);
  608. DEBUG_TTIA_INFO("Message raw: %s\n", logBuf);
  609. DEBUG_TTIA_INFO("OCPP Transaction ID: %d\n", ShmOCPP16Data->StopTransaction[gun_index].TransactionId);
  610. DEBUG_TTIA_INFO("TTIA server address: %s\n", ShmSysConfigAndInfo->SysConfig.TTIA_Info.server_addr);
  611. DEBUG_TTIA_INFO("TTIA server port: %d\n", ShmSysConfigAndInfo->SysConfig.TTIA_Info.server_port);
  612. DEBUG_TTIA_INFO("---------- Header ----------\n");
  613. DEBUG_TTIA_INFO("ProtocolID: APTS\n");
  614. DEBUG_TTIA_INFO("ProtocolVer: 0x02\n");
  615. DEBUG_TTIA_INFO("MessageID: 0xB0\n");
  616. DEBUG_TTIA_INFO("CustomerID: 0x%04X\n", ShmSysConfigAndInfo->SysConfig.TTIA_Info.busVenderId);
  617. DEBUG_TTIA_INFO("CarID: 0x0000\n");
  618. DEBUG_TTIA_INFO("IDStorage: 0x00\n");
  619. DEBUG_TTIA_INFO("DriverID: 0x00000000\n");
  620. DEBUG_TTIA_INFO("Sequence: %d\n", sn);
  621. DEBUG_TTIA_INFO("Reserved: 0x00\n");
  622. DEBUG_TTIA_INFO("Len: 0x3C\n");
  623. DEBUG_TTIA_INFO("--------- Payload ---------\n");
  624. DEBUG_TTIA_INFO("EquipmentProvider: %s\n", ShmSysConfigAndInfo->SysConfig.TTIA_Info.EquipmentProvider);
  625. DEBUG_TTIA_INFO("TransportationCompanyNo: %d\n", ShmSysConfigAndInfo->SysConfig.TTIA_Info.TransportationCompanyNo);
  626. DEBUG_TTIA_INFO("ChargeBoxId: %d\n", ShmSysConfigAndInfo->SysConfig.TTIA_Info.ChargeBoxId);
  627. DEBUG_TTIA_INFO("Gun index: %d\n", gun_index);
  628. DEBUG_TTIA_INFO("evseStation: %s\n", ShmSysConfigAndInfo->SysConfig.TTIA_Info.evseStation);
  629. DEBUG_TTIA_INFO("EV vehicle: %s\n", ShmOCPP16Data->StartTransaction[gun_index].IdTag);
  630. DEBUG_TTIA_INFO("EV mileage: 000000\n");
  631. DEBUG_TTIA_INFO("Session start data time: %s\n", ShmOCPP16Data->StartTransaction[gun_index].Timestamp);
  632. DEBUG_TTIA_INFO("Session stop data time: %s\n", ShmOCPP16Data->StopTransaction[gun_index].Timestamp);
  633. DEBUG_TTIA_INFO("Session charged energy (kwh): %f\n", (PresentChargedEnergy/10.0));
  634. DEBUG_TTIA_INFO("Session start SOC: %d\n", socStart);
  635. DEBUG_TTIA_INFO("Session end SOC: %d\n", socEnd);
  636. DEBUG_TTIA_INFO("=========================================\n");
  637. sn++;
  638. result = PASS;
  639. }
  640. else
  641. {
  642. DEBUG_ERROR("UDP sent out fail.\n");
  643. }
  644. }
  645. }
  646. return result;
  647. }
  648. //=========================================
  649. // Save configuration
  650. //=========================================
  651. int runShellCmd(const char*cmd)
  652. {
  653. int result = FAIL;
  654. char buf[256];
  655. FILE *fp;
  656. fp = popen(cmd, "r");
  657. if(fp != NULL)
  658. {
  659. while(fgets(buf, sizeof(buf), fp) != NULL)
  660. {
  661. DEBUG_INFO("%s\n", buf);
  662. }
  663. result = PASS;
  664. }
  665. pclose(fp);
  666. return result;
  667. }
  668. int StoreUsrConfigData(struct SysConfigData *UsrData)
  669. {
  670. int result = PASS;
  671. int fd,wrd;
  672. unsigned int i,Chk;
  673. unsigned char *ptr, *BufTmp;
  674. int MtdBlockSize = 0x300000;
  675. Chk=0;
  676. ptr=(unsigned char *)UsrData;
  677. if((BufTmp=malloc(MtdBlockSize))!=NULL)
  678. {
  679. memset(BufTmp,0,MtdBlockSize);
  680. memcpy(BufTmp,ptr,sizeof(struct SysConfigData));
  681. for(i=ARRAY_SIZE(UsrData->CsuBootLoadFwRev);i<MtdBlockSize-4;i++)
  682. Chk+=*(BufTmp+i);
  683. memcpy(BufTmp+MtdBlockSize-4, &Chk, 4);
  684. // Output configuration to file.
  685. fd = open("/mnt/EvseConfig.bin", O_RDWR|O_CREAT);
  686. if (fd < 0)
  687. {
  688. DEBUG_ERROR("open /mnt/EvseConfig.bin NG\n");
  689. free(BufTmp);
  690. return 0;
  691. }
  692. wrd=write(fd, BufTmp, MtdBlockSize);
  693. close(fd);
  694. if(wrd<MtdBlockSize)
  695. {
  696. DEBUG_ERROR("write /mnt/EvseConfig.bin NG\n");
  697. free(BufTmp);
  698. return 0;
  699. }
  700. DEBUG_INFO("EvseConfig write to file in /mnt OK.\n");
  701. DEBUG_INFO("Erase /dev/mtd10.\n");
  702. runShellCmd("flash_erase /dev/mtd10 0 0");
  703. DEBUG_INFO("Write /dev/mtd10.\n");
  704. runShellCmd("nandwrite -p /dev/mtd10 /mnt/EvseConfig.bin");
  705. DEBUG_INFO("Erase /dev/mtd11.\n");
  706. runShellCmd("flash_erase /dev/mtd11 0 0");
  707. DEBUG_INFO("Write /dev/mtd11.\n");
  708. runShellCmd("nandwrite -p /dev/mtd11 /mnt/EvseConfig.bin");
  709. system("rm -f /mnt/EvseConfig.bin");
  710. DEBUG_INFO("EvseConfig write to flash OK\n");
  711. }
  712. else
  713. {
  714. DEBUG_ERROR("alloc BlockSize NG\r\n");
  715. result = FAIL;
  716. }
  717. if(BufTmp!=NULL)
  718. free(BufTmp);
  719. return result;
  720. }
  721. //=========================================
  722. // Sqlite3 related function
  723. //=========================================
  724. static int selectSqlCount = 0;
  725. static int callback(void *data, int argc, char **argv, char **azColName){
  726. int i;
  727. //printf("%s: ", (const char*)data);
  728. selectSqlCount = argc;
  729. for(i = 0; i<argc; i++){
  730. // printf("%s = %s\n", azColName[i], argv[i] ? argv[i] : "NULL");
  731. }
  732. //printf("\n");
  733. return 0;
  734. }
  735. static int versioncallback(void *data, int argc, char **argv, char **azColName){
  736. //int i;
  737. //printf("%s:\n", (const char*)data);
  738. locallistVersion = (argv[5] ? atoi(argv[5]) : 0);
  739. DEBUG_INFO("Callback query locallistVersion : %d\n", locallistVersion);
  740. return 0;
  741. }
  742. static int IdTagcallback(void *data, int columenCount, char **columnValue, char **columnName){
  743. //printf("%s:\n", (const char*)data);
  744. //idTag
  745. sprintf(idTagAuthorization,"%s", columnValue[1] ? columnValue[1] : "NULL");
  746. sprintf(idTagQuery.idTagstr,"%s", columnValue[1] ? columnValue[1] : "NULL");
  747. //parentIdTag
  748. sprintf(idTagQuery.parentIdTag,"%s", columnValue[2] ? columnValue[2] : "NULL");
  749. //expir_date
  750. sprintf(idTagQuery.expiryDate,"%s", columnValue[3] ? columnValue[3] : "NULL");
  751. //status
  752. sprintf(idTagQuery.idTagstatus,"%s", columnValue[4] ? columnValue[4] : "NULL");
  753. //version
  754. if(columenCount > 5)
  755. idTagQuery.listVersionInt = atoi(columnValue[5]);
  756. //DEBUG_INFO("IdTag=%s\n", idTagAuthorization);
  757. return 0;
  758. }
  759. static int deleteIdTagcallback(void *data, int argc, char **argv, char **azColName)
  760. {
  761. // localversion = argv[5] ? atoi(argv[5]) : 0;
  762. // printf("localversion=%d\n", localversion);
  763. return 0;
  764. }
  765. int sqlite3_exec_callback(void *data, int n_columns, char **col_values, char **col_names)
  766. {
  767. for (int i = 0; i < n_columns; i++)
  768. {
  769. DEBUG_INFO("%s\t", col_values[i]);
  770. }
  771. DEBUG_INFO("\n");
  772. return 0;
  773. }
  774. int OCPP_cleanLocalCache()
  775. {
  776. char * sqlcleanLocalList = "delete from ocpp_auth_cache";
  777. char *errMsg = 0;
  778. int rc =sqlite3_exec(db, sqlcleanLocalList, 0, 0, &errMsg);
  779. if (SQLITE_OK != rc)
  780. {
  781. DEBUG_INFO("SQL error: %s\n",errMsg);
  782. return FALSE;
  783. }
  784. return TRUE;
  785. }
  786. int OCPP_addLocalCache(char *idTag, char *parentTage, char *expiryDate, char *status)
  787. {
  788. int isSuccess = TRUE;
  789. int ret = 0;
  790. //const char* data = "Callback function called";
  791. char sql[300];
  792. char zErrMsg[200];
  793. memset(sql, 0, 300);
  794. memset(zErrMsg, 0, 200);
  795. 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);
  796. //* Execute SQL statement */
  797. ret = sqlite3_exec(db, sql, callback, 0, (char **)&zErrMsg);
  798. if( ret != SQLITE_OK )
  799. {
  800. DEBUG_INFO("SQL error: %s\n", zErrMsg);
  801. isSuccess = FALSE;
  802. }
  803. return isSuccess;
  804. }
  805. void OCPP_getIdTagFromLocalCache(char idTag[])
  806. {
  807. int rc = 0;
  808. char sql[100];
  809. char zErrMsg[100];
  810. memset(sql, 0, 100);
  811. memset(zErrMsg, 0, 100);
  812. memset(idTagAuthorization, 0, ARRAY_SIZE(idTagAuthorization));
  813. memset(&idTagQuery, 0, sizeof(idTagQuery));
  814. sprintf(sql,"select * from ocpp_auth_cache where idtag='%s'", idTag);
  815. /* Execute SQL statement */
  816. rc = sqlite3_exec(db, sql, IdTagcallback, 0, (char **)&zErrMsg);
  817. if( rc != SQLITE_OK )
  818. {
  819. DEBUG_INFO("SQL error: %s\n", zErrMsg);
  820. }
  821. }
  822. void OCPP_getListVerion()
  823. {
  824. int rc = 0;
  825. // const char* data = "Callback function called";
  826. char sql[100];
  827. char zErrMsg[100];
  828. memset(sql, 0, 100);
  829. memset(zErrMsg, 0, 100);
  830. strcpy(sql, "select * from ocpp_auth_local order by version desc, idx desc limit 1");
  831. /* Execute SQL statement */
  832. rc = sqlite3_exec(db, sql, versioncallback, 0, (char **)&zErrMsg);
  833. if( rc != SQLITE_OK )
  834. {
  835. DEBUG_INFO("SQL error: %s\n", zErrMsg);
  836. }
  837. }
  838. void OCPP_get_TableAuthlocalAllData(void)
  839. {
  840. int rc = 0;
  841. char sql[100];
  842. char zErrMsg[100];
  843. memset(sql, 0, 100);
  844. memset(zErrMsg, 0, 100);
  845. sprintf(sql,"select * from ocpp_auth_local ");
  846. /* Execute SQL statement */
  847. rc = sqlite3_exec(db, sql, &sqlite3_exec_callback, 0,(char **)&zErrMsg);
  848. if( rc != SQLITE_OK )
  849. {
  850. DEBUG_INFO("SQL error: %s\n", zErrMsg);
  851. }
  852. //return ver;
  853. }
  854. int OCPP_cleanLocalList()
  855. {
  856. char * sqlcleanLocalList = "delete from ocpp_auth_local";
  857. char *errMsg = 0;
  858. int rc =sqlite3_exec(db, sqlcleanLocalList, 0, 0, &errMsg);
  859. if (SQLITE_OK != rc)
  860. {
  861. DEBUG_INFO("%s\n",errMsg);
  862. return FALSE;
  863. }
  864. return TRUE;
  865. }
  866. int OCPP_addLocalList(int version, char *idTag, char *parentTage, char *expiryDate, char *status)
  867. {
  868. int isSuccess = FALSE;
  869. int ret = 0;
  870. //const char* data = "Callback function called";
  871. char sql[300];
  872. char zErrMsg[200];
  873. memset(sql, 0, 300);
  874. memset(zErrMsg, 0, 200);
  875. 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);
  876. //* Execute SQL statement */
  877. ret = sqlite3_exec(db, sql, callback, 0, (char **)&zErrMsg);
  878. if( ret != SQLITE_OK )
  879. {
  880. DEBUG_INFO("SQL error: %s\n", zErrMsg);
  881. return isSuccess;
  882. }
  883. memset(sql, 0, 300);
  884. sprintf(sql, "UPDATE ocpp_auth_local SET version=%d",version);
  885. ret = sqlite3_exec(db, sql, NULL, NULL, (char **)&zErrMsg);
  886. if( ret != SQLITE_OK )
  887. {
  888. DEBUG_INFO("SQL error: %s\n", zErrMsg);
  889. return isSuccess;
  890. }
  891. isSuccess = TRUE;
  892. return isSuccess;
  893. }
  894. void OCPP_getIdTagFromLocalList(char idTag[])
  895. {
  896. int rc = 0;
  897. // const char* data = "Callback function called";
  898. char sql[100];
  899. char zErrMsg[100];
  900. memset(sql, 0, 100);
  901. memset(zErrMsg, 0, 100);
  902. memset(idTagAuthorization, 0, ARRAY_SIZE(idTagAuthorization));
  903. memset(&idTagQuery, 0, sizeof(idTagQuery));
  904. //DEBUG_INFO("look up card: %s in ocpp_auth_local table", idTag);
  905. sprintf(sql,"select * from ocpp_auth_local where idtag='%s'", idTag);
  906. /* Execute SQL statement */
  907. rc = sqlite3_exec(db, sql, IdTagcallback, 0, (char **)&zErrMsg);
  908. if( rc != SQLITE_OK )
  909. {
  910. DEBUG_INFO("SQL error: %s\n", zErrMsg);
  911. }
  912. //return ver;
  913. }
  914. void OCPP_deleteIdTagFromLocalList(char idTag[])
  915. {
  916. //int ver = 0;
  917. //int isSuccess = FALSE;
  918. int rc = 0;
  919. char sql[100];
  920. char zErrMsg[100];
  921. memset(sql, 0, 100);
  922. memset(zErrMsg, 0, 100);
  923. sprintf(sql,"DELETE from ocpp_auth_local where idtag='%s'; SELECT * from ocpp_auth_local;", idTag);
  924. //* Execute SQL statement */
  925. rc = sqlite3_exec(db, sql, deleteIdTagcallback, 0,(char **)&zErrMsg);
  926. if( rc != SQLITE_OK )
  927. {
  928. DEBUG_INFO("SQL error: %s\n", zErrMsg);
  929. }
  930. }
  931. int getCurrentYear()
  932. {
  933. int result = 0;
  934. time_t CurrentTime;
  935. struct tm *tm;
  936. CurrentTime = time(NULL);
  937. tm=localtime(&CurrentTime);
  938. result = (tm->tm_year + 1900);
  939. return result;
  940. }
  941. int OCPP_insert_transaction_msg(uint8_t isStartTransaction, char *transactionMsg)
  942. {
  943. int result = PASS;
  944. char* errMsg = NULL;
  945. char sqlStr[8192];
  946. sprintf(sqlStr, "insert into ocpp_transaction_record(occurDatetime, message_type, message_content) values(CURRENT_TIMESTAMP, '%s', '%s');", (isStartTransaction?"startTransaction":"stopTransaction"), transactionMsg);
  947. if (sqlite3_exec(db, sqlStr, 0, 0, &errMsg) != SQLITE_OK)
  948. {
  949. result = FAIL;
  950. DEBUG_WARN( "Insert local transaction record error message: %s\n", errMsg);
  951. }
  952. 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));
  953. if (sqlite3_exec(db, sqlStr, 0, 0, &errMsg) != SQLITE_OK)
  954. {
  955. result = FAIL;
  956. DEBUG_WARN( "delete local transaction record error message: %s\n", errMsg);
  957. }
  958. return result;
  959. }
  960. int OCPP_updatePeriodEnergy(uint8_t gun_index)
  961. {
  962. int isSuccess = TRUE;
  963. int tempIndex;
  964. json_object *EnergyDataTransfer = json_object_new_object();
  965. json_object *periodEnergys = json_object_new_object();
  966. char sql[1024];
  967. char zErrMsg[200];
  968. memset(sql, 0, ARRAY_SIZE(sql));
  969. memset(zErrMsg, 0, ARRAY_SIZE(zErrMsg));
  970. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  971. {
  972. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  973. {
  974. tempIndex = ((gun_index==2) ? 1: 0);
  975. }
  976. else
  977. {
  978. tempIndex = gun_index;
  979. }
  980. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  981. {
  982. if ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex))
  983. {
  984. json_object_object_add(EnergyDataTransfer, "txId", json_object_new_int(ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId));
  985. for(uint8_t idxPeriod=0;idxPeriod<ARRAY_SIZE(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].presentChargedEnergyPeriod);idxPeriod++)
  986. {
  987. uint8_t period[3];
  988. sprintf((char*)period, "%d", idxPeriod);
  989. json_object_object_add(periodEnergys, (const char *)period, json_object_new_double(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].presentChargedEnergyPeriod[idxPeriod]));
  990. }
  991. json_object_object_add(EnergyDataTransfer, "periodEnergy", periodEnergys);
  992. } //end of the same index
  993. }//end of for CHAdeMO_QUANTITY
  994. }
  995. else if(gunType[gun_index] == GUN_TYPE_CCS)
  996. {
  997. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  998. {
  999. tempIndex = ((gun_index==2) ? 1: 0);
  1000. }
  1001. else
  1002. {
  1003. tempIndex = gun_index;
  1004. }
  1005. for (int index = 0; index < CCS_QUANTITY; index++)
  1006. {
  1007. if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  1008. {
  1009. json_object_object_add(EnergyDataTransfer, "txId", json_object_new_int(ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId));
  1010. for(uint8_t idxPeriod=0;idxPeriod<ARRAY_SIZE(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].presentChargedEnergyPeriod);idxPeriod++)
  1011. {
  1012. uint8_t period[3];
  1013. sprintf((char*)period, "%d", idxPeriod);
  1014. json_object_object_add(periodEnergys, (const char *)period, json_object_new_double(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].presentChargedEnergyPeriod[idxPeriod]));
  1015. }
  1016. json_object_object_add(EnergyDataTransfer, "periodEnergy", periodEnergys);
  1017. } //end of the same index
  1018. } // end of for CCS_QUANTITY
  1019. }
  1020. else if(gunType[gun_index] == GUN_TYPE_GBT)
  1021. {
  1022. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  1023. {
  1024. tempIndex = ((gun_index==2) ? 1: 0);
  1025. }
  1026. else
  1027. {
  1028. tempIndex = gun_index;
  1029. }
  1030. for (int index = 0; index < GB_QUANTITY; index++)
  1031. {
  1032. if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  1033. {
  1034. json_object_object_add(EnergyDataTransfer, "txId", json_object_new_int(ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId));
  1035. for(uint8_t idxPeriod=0;idxPeriod<ARRAY_SIZE(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].presentChargedEnergyPeriod);idxPeriod++)
  1036. {
  1037. uint8_t period[3];
  1038. sprintf((char*)period, "%d", idxPeriod);
  1039. json_object_object_add(periodEnergys, (const char *)period, json_object_new_double(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].presentChargedEnergyPeriod[idxPeriod]));
  1040. }
  1041. json_object_object_add(EnergyDataTransfer, "periodEnergy", periodEnergys);
  1042. } //end of the same index
  1043. } // end of for GB_QUANTITY
  1044. }
  1045. else if(gunType[gun_index] == GUN_TYPE_DO)
  1046. {
  1047. tempIndex = gun_index;
  1048. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  1049. {
  1050. if(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  1051. {
  1052. json_object_object_add(EnergyDataTransfer, "txId", json_object_new_int(ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId));
  1053. for(uint8_t idxPeriod=0;idxPeriod<ARRAY_SIZE(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.presentChargedEnergyPeriod);idxPeriod++)
  1054. {
  1055. uint8_t period[3];
  1056. sprintf((char*)period, "%d", idxPeriod);
  1057. json_object_object_add(periodEnergys, (const char *)period, json_object_new_double(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.presentChargedEnergyPeriod[idxPeriod]));
  1058. }
  1059. json_object_object_add(EnergyDataTransfer, "periodEnergy", periodEnergys);
  1060. } //end of the same index
  1061. }
  1062. }
  1063. else
  1064. {
  1065. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  1066. {
  1067. tempIndex = 2;
  1068. }
  1069. else
  1070. {
  1071. tempIndex = gun_index;
  1072. }
  1073. for (int index = 0; index < AC_QUANTITY; index++)
  1074. {
  1075. if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  1076. {
  1077. json_object_object_add(EnergyDataTransfer, "txId", json_object_new_int(ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId));
  1078. for(uint8_t idxPeriod=0;idxPeriod<ARRAY_SIZE(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].presentChargedEnergyPeriod);idxPeriod++)
  1079. {
  1080. uint8_t period[3];
  1081. sprintf((char*)period, "%d", idxPeriod);
  1082. json_object_object_add(periodEnergys, (const char *)period, json_object_new_double(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].presentChargedEnergyPeriod[idxPeriod]));
  1083. }
  1084. json_object_object_add(EnergyDataTransfer, "periodEnergy", periodEnergys);
  1085. }//end of the same index
  1086. }//end of for AC_QUANTITY
  1087. }
  1088. 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));
  1089. json_object_put(EnergyDataTransfer);
  1090. //* Execute SQL statement */
  1091. if( sqlite3_exec(db, sql, callback, 0, (char **)&zErrMsg) != SQLITE_OK )
  1092. {
  1093. DEBUG_WARN("SQL error: %s\n", zErrMsg);
  1094. isSuccess = FALSE;
  1095. }
  1096. sprintf(sql, "delete from ocpp_period_energy where (occurDatetime < '%04d-01-01 00:00:00');", (getCurrentYear()-3));
  1097. if (sqlite3_exec(db, sql, 0, 0, (char **)&zErrMsg) != SQLITE_OK)
  1098. {
  1099. DEBUG_WARN( "delete period energy record error message: %s\n", zErrMsg);
  1100. isSuccess = FALSE;
  1101. }
  1102. return isSuccess;
  1103. }
  1104. int OCPP_getPeriodEnergyToDataTransfer(int32_t transactionId)
  1105. {
  1106. int isSuccess = TRUE;
  1107. char sql[512];
  1108. char zErrMsg[200];
  1109. int rows, cols;
  1110. char **resultData;
  1111. sprintf(sql, "select * from ocpp_period_energy where transactionId=%d;", transactionId);
  1112. /* Execute SQL statement */
  1113. if( sqlite3_get_table(db, sql, &resultData, &rows, &cols, (char **)&zErrMsg) != SQLITE_OK)
  1114. {
  1115. DEBUG_WARN("SQL error: %s\n", zErrMsg);
  1116. isSuccess = FALSE;
  1117. }
  1118. else
  1119. {
  1120. if((rows > 0) && (atoi(resultData[4]) > 0))
  1121. {
  1122. sprintf((char*)ShmOCPP16Data->DataTransfer[0].ResponseData, "%s", resultData[7]);
  1123. }
  1124. else
  1125. {
  1126. DEBUG_WARN("There is not match transaction data.\n");
  1127. isSuccess = FALSE;
  1128. }
  1129. }
  1130. return isSuccess;
  1131. }
  1132. int OCPP_insert_deduct_info(int txId, char *creditNo, uint8_t deductResult, uint8_t isDonateInvoice, double amount, char *vemData, char *ROC, char *RRN, char *approvalNo, char *storeId)
  1133. {
  1134. int result = PASS;
  1135. char* errMsg = NULL;
  1136. char sqlStr[8192];
  1137. sprintf(sqlStr, "insert or replace into report_deduct_info(txId, creditNo, deductResult, isDonateInvoice, amount, vemData, ROC, RRN, approvalNo, storeId, isUploaded) values('%d', '%s', '%d', '%d', '%.2f', '%s', '%s', '%s', '%s', '%s', '0');",
  1138. txId, creditNo, deductResult, isDonateInvoice, amount, vemData, ROC, RRN, approvalNo, storeId);
  1139. if (sqlite3_exec(db, sqlStr, 0, 0, &errMsg) != SQLITE_OK)
  1140. {
  1141. result = FAIL;
  1142. DEBUG_WARN( "Insert local report_deduct_info error message: %s\n", errMsg);
  1143. }
  1144. sprintf(sqlStr, "delete from report_deduct_info where (idx < (select idx from report_deduct_info order by idx desc limit 1)-5000);");
  1145. if (sqlite3_exec(db, sqlStr, 0, 0, &errMsg) != SQLITE_OK)
  1146. {
  1147. result = FAIL;
  1148. DEBUG_WARN( "delete local report_deduct_info error message: %s\n", errMsg);
  1149. }
  1150. return result;
  1151. }
  1152. int OCPP_update_deduct_info(int txId, char *creditNo)
  1153. {
  1154. int result = PASS;
  1155. char* errMsg = NULL;
  1156. char sqlStr[8192];
  1157. sprintf(sqlStr, "update report_deduct_info set isUploaded='1' where txId='%d' and creditNo='%s';", txId, creditNo);
  1158. if (sqlite3_exec(db, sqlStr, 0, 0, &errMsg) != SQLITE_OK)
  1159. {
  1160. result = FAIL;
  1161. DEBUG_WARN( "Update local report_deduct_info error message: %s\n", errMsg);
  1162. }
  1163. return result;
  1164. }
  1165. int queryDeductCallBack(void *data, int columenCount, char **columnValue, char **columnName)
  1166. {
  1167. sprintf((char*)ShmOCPP16Data->DataTransfer[0].VendorId, "%s", ShmSysConfigAndInfo->SysConfig.chargePointVendor);
  1168. sprintf((char*)ShmOCPP16Data->DataTransfer[0].MessageId,"%s","ID_CreditDeductResult");
  1169. sprintf((char*)ShmOCPP16Data->DataTransfer[0].Data, "{\\\"txId\\\":%d,\\\"creditNo\\\":\\\"%s\\\",\\\"deductResult\\\":%s,\\\"isDonateInvoice\\\":%s,\\\"amount\\\":%s,\\\"approvalNo\\\":\\\"%s\\\"}",
  1170. atoi(columnValue[1]),
  1171. columnValue[2],
  1172. atoi(columnValue[3])==1?"true":"false",
  1173. atoi(columnValue[4])==1?"true":"false",
  1174. columnValue[5],
  1175. columnValue[9]);
  1176. ShmOCPP16Data->CsMsg.bits[0].DataTransferReq = 1;
  1177. return 0;
  1178. }
  1179. void OCPP_query_deduct_info()
  1180. {
  1181. int rc = 0;
  1182. char sql[100];
  1183. char zErrMsg[100];
  1184. sprintf(sql,"select * from report_deduct_info where isUploaded='0' order by idx limit 1");
  1185. /* Execute SQL statement */
  1186. rc = sqlite3_exec(db, sql, queryDeductCallBack, 0, (char **)&zErrMsg);
  1187. if( rc != SQLITE_OK )
  1188. {
  1189. DEBUG_INFO("SQL error: %s\n", zErrMsg);
  1190. }
  1191. }
  1192. void reportReaderStatus(int gun_index)
  1193. {
  1194. struct timeval tmnow;
  1195. struct tm *tm;
  1196. char buf[28];//, usec_buf[6];
  1197. gettimeofday(&tmnow, NULL);
  1198. time_t t;
  1199. t = time(NULL);
  1200. /*UTC time and date*/
  1201. tm = gmtime(&t);
  1202. strftime(buf,28,"%Y-%m-%dT%H:%M:%SZ", tm);
  1203. #if 0 // remove temporally
  1204. strftime(buf,30,"%Y-%m-%dT%H:%M:%S", tm);
  1205. strcat(buf,".");
  1206. sprintf(usec_buf,"%dZ",(int)tmnow.tv_usec);
  1207. strcat(buf,usec_buf);
  1208. #endif
  1209. sprintf((char*)ShmOCPP16Data->DataTransfer[gun_index].VendorId, "%s", ShmSysConfigAndInfo->SysConfig.chargePointVendor);
  1210. sprintf((char*)ShmOCPP16Data->DataTransfer[gun_index].MessageId,"%s","ID_ReaderStatus");
  1211. sprintf((char*)ShmOCPP16Data->DataTransfer[gun_index].Data, "{\\\"connectorId\\\":%d,\\\"readerStatus\\\":%d,\\\"timestamp\\\":\\\"%s\\\",\\\"SerialNo\\\":\\\"%s\\\",\\\"creditNo\\\":\\\"%s\\\",\\\"VEMData\\\":\\\"%s\\\"}",
  1212. (gun_index+1),
  1213. ShmOCPP16Data->TcciCustomData.ReaderStatus[gun_index].readerStatus,
  1214. buf,
  1215. ShmOCPP16Data->TcciCustomData.SerialNo[gun_index],
  1216. ShmOCPP16Data->TcciCustomData.ReaderStatus[gun_index].creditNo,
  1217. ShmOCPP16Data->TcciCustomData.VEMData[gun_index]);
  1218. ShmOCPP16Data->CsMsg.bits[gun_index].DataTransferReq = 1;
  1219. }
  1220. //==========================================
  1221. // Check time passed since today
  1222. //==========================================
  1223. long long DiffTimebWithNow(struct timeb ST)
  1224. {
  1225. //return milli-second
  1226. struct timeb ET;
  1227. long long StartTime,StopTime;
  1228. ftime(&ET);
  1229. StartTime=(long long)ST.time;
  1230. StopTime=(long long)ET.time;
  1231. return ((StopTime-StartTime)*1000) + (ET.millitm-ST.millitm);
  1232. }
  1233. int getTimePassSinceToday(uint8_t gun_index)
  1234. {
  1235. int result = -1;
  1236. static time_t lastTime[4];
  1237. time_t t;
  1238. struct tm *tmStartToday;
  1239. struct timeb tbStartToday;
  1240. t=time(NULL);
  1241. if(difftime(t, lastTime[gun_index])>0)
  1242. {
  1243. tmStartToday=localtime(&t);
  1244. tmStartToday->tm_hour = 0;
  1245. tmStartToday->tm_min = 0;
  1246. tmStartToday->tm_sec = 0;
  1247. tbStartToday.time = mktime(tmStartToday);
  1248. tbStartToday.millitm = 0;
  1249. result = DiffTimebWithNow(tbStartToday)/1000;
  1250. lastTime[gun_index] = t;
  1251. }
  1252. return result;
  1253. }
  1254. void getNowDatetime(uint8_t *data)
  1255. {
  1256. time_t t = time(NULL);
  1257. struct tm tm = *localtime(&t);
  1258. 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);
  1259. }
  1260. int syncDateTimeRTC(uint8_t *data)
  1261. {
  1262. struct ParsingResult
  1263. {
  1264. int result;
  1265. int scanedElement;
  1266. int year;
  1267. int month;
  1268. int mday;
  1269. int hour;
  1270. int min;
  1271. int sec;
  1272. int tz_hour;
  1273. int tz_min;
  1274. float minSec;
  1275. }result;
  1276. struct tm tmOrg;
  1277. struct tm *tmTarget;
  1278. struct timeb tbTarget;
  1279. char buf[128];
  1280. memset(&result, 0x00, sizeof(struct ParsingResult));
  1281. result.result = PASS;
  1282. if(strstr((char*)data, ".") != NULL)
  1283. {
  1284. // Original data with mini second
  1285. if(strstr((char*)data, "Z") != NULL)
  1286. {
  1287. // Original data with Z
  1288. result.scanedElement = sscanf((char*)data, "%d-%d-%dT%d:%d:%d.%fZ",
  1289. &result.year,
  1290. &result.month,
  1291. &result.mday,
  1292. &result.hour,
  1293. &result.min,
  1294. &result.sec,
  1295. &result.minSec);
  1296. }
  1297. else
  1298. {
  1299. // Original data without Z
  1300. result.scanedElement = sscanf((char*)data, "%d-%d-%dT%d:%d:%d.%f%d:%d",
  1301. &result.year,
  1302. &result.month,
  1303. &result.mday,
  1304. &result.hour,
  1305. &result.min,
  1306. &result.sec,
  1307. &result.minSec,
  1308. &result.tz_hour,
  1309. &result.tz_min);
  1310. }
  1311. }
  1312. else
  1313. {
  1314. // Original data without mini second
  1315. if(strstr((char*)data, "Z") != NULL)
  1316. {
  1317. // Original data with Z
  1318. result.scanedElement = sscanf((char*)data, "%d-%d-%dT%d:%d:%dZ",
  1319. &result.year,
  1320. &result.month,
  1321. &result.mday,
  1322. &result.hour,
  1323. &result.min,
  1324. &result.sec);
  1325. }
  1326. else
  1327. {
  1328. // Original data without Z
  1329. result.scanedElement = sscanf((char*)data, "%d-%d-%dT%d:%d:%d%d:%d",
  1330. &result.year,
  1331. &result.month,
  1332. &result.mday,
  1333. &result.hour,
  1334. &result.min,
  1335. &result.sec,
  1336. &result.tz_hour,
  1337. &result.tz_min);
  1338. }
  1339. }
  1340. tmOrg.tm_year = result.year - 1900;
  1341. tmOrg.tm_mon = result.month - 1;
  1342. tmOrg.tm_mday = result.mday;
  1343. tmOrg.tm_hour = result.hour;
  1344. tmOrg.tm_min = result.min;
  1345. tmOrg.tm_sec = result.sec;
  1346. tmOrg.tm_gmtoff = 0;
  1347. tbTarget.time = mktime(&tmOrg);
  1348. tbTarget.timezone = 0;
  1349. tbTarget.time -= (result.tz_hour*3600) + (result.tz_min*60*(result.tz_hour>=0?1:-1));
  1350. tmTarget = gmtime(&tbTarget.time);
  1351. 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);
  1352. //DEBUG_INFO(" org date time: %s\n", data);
  1353. //DEBUG_INFO("parse date time: %s\n", buf);
  1354. system(buf);
  1355. system("/sbin/hwclock -w --systohc");
  1356. if(result.scanedElement < 6)
  1357. result.result = FAIL;
  1358. return result.result;
  1359. }
  1360. //==========================================
  1361. // GetCompositeSchedule logic related function
  1362. //==========================================
  1363. int DiffTimebSec(struct timeb ST, struct timeb ET)
  1364. {
  1365. //return milli-second
  1366. unsigned int StartTime,StopTime;
  1367. StartTime=(unsigned int)ST.time;
  1368. StopTime=(unsigned int)ET.time;
  1369. return (StopTime-StartTime);
  1370. }
  1371. int DiffTimebWithNowSec(struct timeb ST)
  1372. {
  1373. //return milli-second
  1374. struct timeb ET;
  1375. unsigned int StartTime,StopTime;
  1376. ftime(&ET);
  1377. StartTime=(unsigned int)ST.time;
  1378. StopTime=(unsigned int)ET.time;
  1379. return (StopTime-StartTime);
  1380. }
  1381. int getStartStop(uint8_t *start, uint8_t *stop)
  1382. {
  1383. struct ParsingResult
  1384. {
  1385. int result;
  1386. int scanedElement;
  1387. int year;
  1388. int month;
  1389. int mday;
  1390. int hour;
  1391. int min;
  1392. int sec;
  1393. int tz_hour;
  1394. int tz_min;
  1395. float minSec;
  1396. };
  1397. struct ParsingResult parseStart;
  1398. struct ParsingResult parseStop;
  1399. int result = -1;
  1400. struct tm tmStart;
  1401. struct timeb tbStart;
  1402. struct tm tmStop;
  1403. struct timeb tbStop;
  1404. memset(&parseStart, 0x00, sizeof(struct ParsingResult));
  1405. memset(&parseStop, 0x00, sizeof(struct ParsingResult));
  1406. // Scan start & stop date time
  1407. if(strstr((char*)start, ".") != NULL)
  1408. {
  1409. // Original data with mini second
  1410. if(strstr((char*)start, "Z") != NULL)
  1411. {
  1412. // Original data with Z
  1413. parseStart.scanedElement = sscanf((char*)start, "%d-%d-%dT%d:%d:%d.%fZ",
  1414. &parseStart.year,
  1415. &parseStart.month,
  1416. &parseStart.mday,
  1417. &parseStart.hour,
  1418. &parseStart.min,
  1419. &parseStart.sec,
  1420. &parseStart.minSec);
  1421. }
  1422. else
  1423. {
  1424. // Original data without Z
  1425. parseStart.scanedElement = sscanf((char*)start, "%d-%d-%dT%d:%d:%d.%f%d:%d",
  1426. &parseStart.year,
  1427. &parseStart.month,
  1428. &parseStart.mday,
  1429. &parseStart.hour,
  1430. &parseStart.min,
  1431. &parseStart.sec,
  1432. &parseStart.minSec,
  1433. &parseStart.tz_hour,
  1434. &parseStart.tz_min);
  1435. }
  1436. }
  1437. else
  1438. {
  1439. // Original data without mini second
  1440. if(strstr((char*)start, "Z") != NULL)
  1441. {
  1442. // Original data with Z
  1443. parseStart.scanedElement = sscanf((char*)start, "%d-%d-%dT%d:%d:%dZ",
  1444. &parseStart.year,
  1445. &parseStart.month,
  1446. &parseStart.mday,
  1447. &parseStart.hour,
  1448. &parseStart.min,
  1449. &parseStart.sec);
  1450. }
  1451. else
  1452. {
  1453. // Original data without Z
  1454. parseStart.scanedElement = sscanf((char*)start, "%d-%d-%dT%d:%d:%d%d:%d",
  1455. &parseStart.year,
  1456. &parseStart.month,
  1457. &parseStart.mday,
  1458. &parseStart.hour,
  1459. &parseStart.min,
  1460. &parseStart.sec,
  1461. &parseStart.tz_hour,
  1462. &parseStart.tz_min);
  1463. }
  1464. }
  1465. if(strstr((char*)stop, ".") != NULL)
  1466. {
  1467. // Original data with mini second
  1468. if(strstr((char*)stop, "Z") != NULL)
  1469. {
  1470. // Original data with Z
  1471. parseStop.scanedElement = sscanf((char*)stop, "%d-%d-%dT%d:%d:%d.%fZ",
  1472. &parseStop.year,
  1473. &parseStop.month,
  1474. &parseStop.mday,
  1475. &parseStop.hour,
  1476. &parseStop.min,
  1477. &parseStop.sec,
  1478. &parseStop.minSec);
  1479. }
  1480. else
  1481. {
  1482. // Original data without Z
  1483. parseStop.scanedElement = sscanf((char*)stop, "%d-%d-%dT%d:%d:%d.%f%d:%d",
  1484. &parseStop.year,
  1485. &parseStop.month,
  1486. &parseStop.mday,
  1487. &parseStop.hour,
  1488. &parseStop.min,
  1489. &parseStop.sec,
  1490. &parseStop.minSec,
  1491. &parseStop.tz_hour,
  1492. &parseStop.tz_min);
  1493. }
  1494. }
  1495. else
  1496. {
  1497. // Original data without mini second
  1498. if(strstr((char*)stop, "Z") != NULL)
  1499. {
  1500. // Original data with Z
  1501. parseStop.scanedElement = sscanf((char*)stop, "%d-%d-%dT%d:%d:%dZ",
  1502. &parseStop.year,
  1503. &parseStop.month,
  1504. &parseStop.mday,
  1505. &parseStop.hour,
  1506. &parseStop.min,
  1507. &parseStop.sec);
  1508. }
  1509. else
  1510. {
  1511. // Original data without Z
  1512. parseStop.scanedElement = sscanf((char*)stop, "%d-%d-%dT%d:%d:%d%d:%d",
  1513. &parseStop.year,
  1514. &parseStop.month,
  1515. &parseStop.mday,
  1516. &parseStop.hour,
  1517. &parseStop.min,
  1518. &parseStop.sec,
  1519. &parseStop.tz_hour,
  1520. &parseStop.tz_min);
  1521. }
  1522. }
  1523. // Calculate date time difference
  1524. if((parseStart.scanedElement >=6) &&
  1525. (parseStop.scanedElement >=6))
  1526. {
  1527. //DEBUG_INFO("Start: %04d-%02d-%02d %02d:%02d:%02d(%02d:%02d)\n", parseStart.year, parseStart.month, parseStart.mday, parseStart.hour, parseStart.min, parseStart.sec, parseStart.tz_hour, parseStart.tz_min);
  1528. //DEBUG_INFO("Stop: %04d-%02d-%02d %02d:%02d:%02d(%02d:%02d)\n", parseStop.year, parseStop.month, parseStop.mday, parseStop.hour, parseStop.min, parseStop.sec, parseStop.tz_hour, parseStop.tz_min);
  1529. tmStart.tm_year = parseStart.year - 1900;
  1530. tmStart.tm_mon = parseStart.month - 1;
  1531. tmStart.tm_mday = parseStart.mday;
  1532. tmStart.tm_hour = parseStart.hour;
  1533. tmStart.tm_min = parseStart.min;
  1534. tmStart.tm_sec = parseStart.sec;
  1535. tmStart.tm_gmtoff = 0;
  1536. tbStart.time = mktime(&tmStart);
  1537. tbStart.timezone = 0;
  1538. tbStart.time -= (parseStart.tz_hour*3600) + (parseStart.tz_min*60*(parseStart.tz_hour>=0?1:-1));
  1539. tmStop.tm_year = parseStop.year - 1900;
  1540. tmStop.tm_mon = parseStop.month - 1;
  1541. tmStop.tm_mday = parseStop.mday;
  1542. tmStop.tm_hour = parseStop.hour;
  1543. tmStop.tm_min = parseStop.min;
  1544. tmStop.tm_sec = parseStop.sec;
  1545. tmStop.tm_gmtoff = 0;
  1546. tbStop.time = mktime(&tmStop);
  1547. tbStop.timezone = 0;
  1548. tbStop.time -= (parseStop.tz_hour*3600) + (parseStop.tz_min*60*(parseStop.tz_hour>=0?1:-1));
  1549. result = DiffTimebSec(tbStart, tbStop);
  1550. //DEBUG_INFO("getStartStop(): %d\n", result);
  1551. }
  1552. else
  1553. {
  1554. DEBUG_WARN("Start or stop date parsing error.\r\n");
  1555. }
  1556. return result;
  1557. }
  1558. int isOvertNow(uint8_t *start)
  1559. {
  1560. int result = NO;
  1561. struct ParsingResult
  1562. {
  1563. int result;
  1564. int scanedElement;
  1565. int year;
  1566. int month;
  1567. int mday;
  1568. int hour;
  1569. int min;
  1570. int sec;
  1571. int tz_hour;
  1572. int tz_min;
  1573. float minSec;
  1574. }parsingResult;
  1575. struct tm tmStart;
  1576. struct timeb tbStart;
  1577. memset(&parsingResult, 0x00, sizeof(struct ParsingResult));
  1578. if(strstr((char*)start, ".") != NULL)
  1579. {
  1580. // Original data with mini second
  1581. if(strstr((char*)start, "Z") != NULL)
  1582. {
  1583. // Original data with Z
  1584. parsingResult.scanedElement = sscanf((char*)start, "%d-%d-%dT%d:%d:%d.%fZ",
  1585. &parsingResult.year,
  1586. &parsingResult.month,
  1587. &parsingResult.mday,
  1588. &parsingResult.hour,
  1589. &parsingResult.min,
  1590. &parsingResult.sec,
  1591. &parsingResult.minSec);
  1592. }
  1593. else
  1594. {
  1595. // Original data without Z
  1596. parsingResult.scanedElement = sscanf((char*)start, "%d-%d-%dT%d:%d:%d.%f%d:%d",
  1597. &parsingResult.year,
  1598. &parsingResult.month,
  1599. &parsingResult.mday,
  1600. &parsingResult.hour,
  1601. &parsingResult.min,
  1602. &parsingResult.sec,
  1603. &parsingResult.minSec,
  1604. &parsingResult.tz_hour,
  1605. &parsingResult.tz_min);
  1606. }
  1607. }
  1608. else
  1609. {
  1610. // Original data without mini second
  1611. if(strstr((char*)start, "Z") != NULL)
  1612. {
  1613. // Original data with Z
  1614. parsingResult.scanedElement = sscanf((char*)start, "%d-%d-%dT%d:%d:%dZ",
  1615. &parsingResult.year,
  1616. &parsingResult.month,
  1617. &parsingResult.mday,
  1618. &parsingResult.hour,
  1619. &parsingResult.min,
  1620. &parsingResult.sec);
  1621. }
  1622. else
  1623. {
  1624. // Original data without Z
  1625. parsingResult.scanedElement = sscanf((char*)start, "%d-%d-%dT%d:%d:%d%d:%d",
  1626. &parsingResult.year,
  1627. &parsingResult.month,
  1628. &parsingResult.mday,
  1629. &parsingResult.hour,
  1630. &parsingResult.min,
  1631. &parsingResult.sec,
  1632. &parsingResult.tz_hour,
  1633. &parsingResult.tz_min);
  1634. }
  1635. }
  1636. if(parsingResult.scanedElement >= 6)
  1637. {
  1638. tmStart.tm_year = parsingResult.year - 1900;
  1639. tmStart.tm_mon = parsingResult.month - 1;
  1640. tmStart.tm_mday = parsingResult.mday;
  1641. tmStart.tm_hour = parsingResult.hour;
  1642. tmStart.tm_min = parsingResult.min;
  1643. tmStart.tm_sec = parsingResult.sec;
  1644. tmStart.tm_gmtoff = 0;
  1645. tbStart.time = mktime(&tmStart);
  1646. tbStart.timezone = 0;
  1647. tbStart.millitm = 0;
  1648. tbStart.time -= (parsingResult.tz_hour*3600) + (parsingResult.tz_min*60*(parsingResult.tz_hour>=0?1:-1));
  1649. if(DiffTimebWithNowSec(tbStart) <= 0)
  1650. result = NO;
  1651. else
  1652. result = YES;
  1653. }
  1654. else
  1655. {
  1656. DEBUG_WARN("Start date parsing error.\n");
  1657. }
  1658. return result;
  1659. }
  1660. int getStartSinceRecurring(uint8_t *start, uint8_t *stop, uint8_t isDaily)
  1661. {
  1662. struct ParsingResult
  1663. {
  1664. int result;
  1665. int scanedElement;
  1666. int year;
  1667. int month;
  1668. int mday;
  1669. int hour;
  1670. int min;
  1671. int sec;
  1672. int tz_hour;
  1673. int tz_min;
  1674. float minSec;
  1675. };
  1676. struct ParsingResult parseStart;
  1677. struct ParsingResult parseStop;
  1678. int result = -1;
  1679. struct tm tmStart;
  1680. struct timeb tbStart;
  1681. struct tm tmStop;
  1682. struct timeb tbStop;
  1683. memset(&parseStart, 0x00, sizeof(struct ParsingResult));
  1684. memset(&parseStop, 0x00, sizeof(struct ParsingResult));
  1685. // Scan start & stop date time
  1686. if(strstr((char*)start, ".") != NULL)
  1687. {
  1688. // Original data with mini second
  1689. if(strstr((char*)start, "Z") != NULL)
  1690. {
  1691. // Original data with Z
  1692. parseStart.scanedElement = sscanf((char*)start, "%d-%d-%dT%d:%d:%d.%fZ",
  1693. &parseStart.year,
  1694. &parseStart.month,
  1695. &parseStart.mday,
  1696. &parseStart.hour,
  1697. &parseStart.min,
  1698. &parseStart.sec,
  1699. &parseStart.minSec);
  1700. }
  1701. else
  1702. {
  1703. // Original data without Z
  1704. parseStart.scanedElement = sscanf((char*)start, "%d-%d-%dT%d:%d:%d.%f%d:%d",
  1705. &parseStart.year,
  1706. &parseStart.month,
  1707. &parseStart.mday,
  1708. &parseStart.hour,
  1709. &parseStart.min,
  1710. &parseStart.sec,
  1711. &parseStart.minSec,
  1712. &parseStart.tz_hour,
  1713. &parseStart.tz_min);
  1714. }
  1715. }
  1716. else
  1717. {
  1718. // Original data without mini second
  1719. if(strstr((char*)start, "Z") != NULL)
  1720. {
  1721. // Original data with Z
  1722. parseStart.scanedElement = sscanf((char*)start, "%d-%d-%dT%d:%d:%dZ",
  1723. &parseStart.year,
  1724. &parseStart.month,
  1725. &parseStart.mday,
  1726. &parseStart.hour,
  1727. &parseStart.min,
  1728. &parseStart.sec);
  1729. }
  1730. else
  1731. {
  1732. // Original data without Z
  1733. parseStart.scanedElement = sscanf((char*)start, "%d-%d-%dT%d:%d:%d%d:%d",
  1734. &parseStart.year,
  1735. &parseStart.month,
  1736. &parseStart.mday,
  1737. &parseStart.hour,
  1738. &parseStart.min,
  1739. &parseStart.sec,
  1740. &parseStart.tz_hour,
  1741. &parseStart.tz_min);
  1742. }
  1743. }
  1744. if(strstr((char*)stop, ".") != NULL)
  1745. {
  1746. // Original data with mini second
  1747. if(strstr((char*)stop, "Z") != NULL)
  1748. {
  1749. // Original data with Z
  1750. parseStop.scanedElement = sscanf((char*)stop, "%d-%d-%dT%d:%d:%d.%fZ",
  1751. &parseStop.year,
  1752. &parseStop.month,
  1753. &parseStop.mday,
  1754. &parseStop.hour,
  1755. &parseStop.min,
  1756. &parseStop.sec,
  1757. &parseStop.minSec);
  1758. }
  1759. else
  1760. {
  1761. // Original data without Z
  1762. parseStop.scanedElement = sscanf((char*)stop, "%d-%d-%dT%d:%d:%d.%f%d:%d",
  1763. &parseStop.year,
  1764. &parseStop.month,
  1765. &parseStop.mday,
  1766. &parseStop.hour,
  1767. &parseStop.min,
  1768. &parseStop.sec,
  1769. &parseStop.minSec,
  1770. &parseStop.tz_hour,
  1771. &parseStop.tz_min);
  1772. }
  1773. }
  1774. else
  1775. {
  1776. // Original data without mini second
  1777. if(strstr((char*)stop, "Z") != NULL)
  1778. {
  1779. // Original data with Z
  1780. parseStop.scanedElement = sscanf((char*)stop, "%d-%d-%dT%d:%d:%dZ",
  1781. &parseStop.year,
  1782. &parseStop.month,
  1783. &parseStop.mday,
  1784. &parseStop.hour,
  1785. &parseStop.min,
  1786. &parseStop.sec);
  1787. }
  1788. else
  1789. {
  1790. // Original data without Z
  1791. parseStop.scanedElement = sscanf((char*)stop, "%d-%d-%dT%d:%d:%d%d:%d",
  1792. &parseStop.year,
  1793. &parseStop.month,
  1794. &parseStop.mday,
  1795. &parseStop.hour,
  1796. &parseStop.min,
  1797. &parseStop.sec,
  1798. &parseStop.tz_hour,
  1799. &parseStop.tz_min);
  1800. }
  1801. }
  1802. // Calculate date time difference
  1803. if((parseStart.scanedElement >=6) &&
  1804. (parseStop.scanedElement >=6))
  1805. {
  1806. //DEBUG_INFO("Start: %04d-%02d-%02d %02d:%02d:%02d(%02d:%02d)\n", parseStart.year, parseStart.month, parseStart.mday, parseStart.hour, parseStart.min, parseStart.sec, parseStart.tz_hour, parseStart.tz_min);
  1807. //DEBUG_INFO("Stop: %04d-%02d-%02d %02d:%02d:%02d(%02d:%02d)\n", parseStop.year, parseStop.month, parseStop.mday, parseStop.hour, parseStop.min, parseStop.sec, parseStop.tz_hour, parseStop.tz_min);
  1808. tmStart.tm_year = parseStart.year - 1900;
  1809. tmStart.tm_mon = parseStart.month - 1;
  1810. tmStart.tm_mday = parseStart.mday;
  1811. tmStart.tm_hour = parseStart.hour;
  1812. tmStart.tm_min = parseStart.min;
  1813. tmStart.tm_sec = parseStart.sec;
  1814. tmStart.tm_gmtoff = 0;
  1815. tbStart.time = mktime(&tmStart);
  1816. tbStart.timezone = 0;
  1817. tbStart.time -= (parseStart.tz_hour*3600) + (parseStart.tz_min*60*(parseStart.tz_hour>=0?1:-1));
  1818. tmStop.tm_year = parseStop.year - 1900;
  1819. tmStop.tm_mon = parseStop.month - 1;
  1820. tmStop.tm_mday = parseStop.mday;
  1821. tmStop.tm_hour = parseStop.hour;
  1822. tmStop.tm_min = parseStop.min;
  1823. tmStop.tm_sec = parseStop.sec;
  1824. tmStop.tm_gmtoff = 0;
  1825. tbStop.time = mktime(&tmStop);
  1826. tbStop.timezone = 0;
  1827. tbStop.time -= (parseStop.tz_hour*3600) + (parseStop.tz_min*60*(parseStop.tz_hour>=0?1:-1));
  1828. result = DiffTimebSec(tbStart, tbStop)%(isDaily?86400:604800);
  1829. //DEBUG_INFO("getStartStop(): %d\n", result);
  1830. }
  1831. else
  1832. {
  1833. DEBUG_WARN("Start or stop date parsing error.\r\n");
  1834. }
  1835. return result;
  1836. }
  1837. void checkChargePointMaxProfile(uint32_t durationReq, struct StructChargingProfile *targetCompositeProfile, uint8_t isUnitA)
  1838. {
  1839. FILE *fp;
  1840. char profileFileName[128];
  1841. char *line = NULL;
  1842. size_t len = 0;
  1843. time_t CurrentTime;
  1844. struct tm *tmComposite;
  1845. struct StructChargingProfile maxProfile;
  1846. struct StructChargingProfile compositeProfile;
  1847. uint8_t limitMax=0;
  1848. int compositePeriodIdx = 0;
  1849. //uint8_t isDurationNull = FALSE;
  1850. CurrentTime = time(NULL);
  1851. tmComposite=localtime(&CurrentTime);
  1852. 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);
  1853. if(isUnitA)
  1854. sprintf((char*)compositeProfile.ChargingSchedule.ChargingRateUnit, "A");
  1855. else
  1856. sprintf((char*)compositeProfile.ChargingSchedule.ChargingRateUnit, "W");
  1857. compositeProfile.ChargingSchedule.Duration = durationReq;
  1858. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(compositeProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  1859. {
  1860. compositeProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = -1;
  1861. compositeProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit = -1;
  1862. compositeProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases = 3;
  1863. }
  1864. compositeProfile.ChargingProfileId = 0;
  1865. compositeProfile.StackLevel = 99 ;
  1866. sprintf((char*)compositeProfile.ChargingProfileKind ,"Absolute");
  1867. maxProfile.ChargingProfileId = -1;
  1868. maxProfile.ChargingSchedule.Duration = -1;
  1869. system("rm -f /tmp/*.json");
  1870. system("cp /Storage/OCPP/*.json /tmp 2>/dev/null");
  1871. // Search max profile
  1872. sprintf(profileFileName, "/tmp/ChargePointMaxProfile.json");
  1873. if((access(profileFileName, F_OK))!=-1)
  1874. {
  1875. fp = fopen(profileFileName, "r");
  1876. while(getline(&line, &len, fp) != -1)
  1877. {
  1878. json_object *obj = NULL;
  1879. obj = json_tokener_parse(line);
  1880. if(is_error(obj))
  1881. {
  1882. DEBUG_ERROR("Parse MaxProfile from file error.\n");
  1883. }
  1884. else
  1885. {
  1886. if((json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileId")) != maxProfile.ChargingProfileId) &&
  1887. (json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "stackLevel")) >= maxProfile.StackLevel)
  1888. )
  1889. {
  1890. if((json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom") != NULL) &&
  1891. (json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo") != NULL)
  1892. )
  1893. {
  1894. struct tm tmFrom, tmTo;
  1895. struct timeb tbFrom, tbTo;
  1896. 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) &&
  1897. (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))
  1898. {
  1899. tmFrom.tm_year -= 1900;
  1900. tmFrom.tm_mon -= 1;
  1901. tbFrom.time = mktime(&tmFrom);
  1902. tmTo.tm_year -= 1900;
  1903. tmTo.tm_mon -= 1;
  1904. tbTo.time = mktime(&tmTo);
  1905. if((DiffTimebWithNowSec(tbFrom)>=0) && (DiffTimebWithNowSec(tbTo)<=0))
  1906. {
  1907. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  1908. {
  1909. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = -1;
  1910. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit = -1;
  1911. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases = 3;
  1912. }
  1913. if(maxProfile.ChargingProfileId == -1)
  1914. DEBUG_INFO("MaxProfile found.\n");
  1915. else
  1916. DEBUG_INFO("MaxProfile updated.\n");
  1917. // Required item
  1918. maxProfile.ChargingProfileId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileId"));
  1919. maxProfile.StackLevel = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "stackLevel"));
  1920. sprintf((char*)maxProfile.ChargingProfileKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileKind")));
  1921. if(isUnitA)
  1922. {
  1923. sprintf((char*)maxProfile.ChargingSchedule.ChargingRateUnit, "A");
  1924. 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++)
  1925. {
  1926. 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"));
  1927. 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?
  1928. 3:
  1929. 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")));
  1930. 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")));
  1931. }
  1932. }
  1933. else
  1934. {
  1935. sprintf((char*)maxProfile.ChargingSchedule.ChargingRateUnit, "W");
  1936. 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++)
  1937. {
  1938. 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"));
  1939. 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?
  1940. 3:
  1941. 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")));
  1942. 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));
  1943. }
  1944. }
  1945. // Optional item
  1946. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom") != NULL)
  1947. {
  1948. sprintf((char*)maxProfile.ValidFrom, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom")));
  1949. }
  1950. else
  1951. {
  1952. sprintf((char*)maxProfile.ValidFrom, " ");
  1953. }
  1954. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo") != NULL)
  1955. {
  1956. sprintf((char*)maxProfile.ValidTo, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo")));
  1957. }
  1958. else
  1959. {
  1960. sprintf((char*)maxProfile.ValidTo, " ");
  1961. }
  1962. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "recurrencyKind") != NULL)
  1963. {
  1964. sprintf((char*)maxProfile.RecurrencyKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "recurrencyKind")));
  1965. }
  1966. else
  1967. {
  1968. sprintf((char*)maxProfile.RecurrencyKind, " ");
  1969. }
  1970. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId") != NULL)
  1971. {
  1972. maxProfile.TransactionId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId"));
  1973. }
  1974. else
  1975. {
  1976. maxProfile.TransactionId = -1;
  1977. }
  1978. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration") != NULL)
  1979. {
  1980. maxProfile.ChargingSchedule.Duration = json_object_get_int(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration"));
  1981. }
  1982. else
  1983. {
  1984. maxProfile.ChargingSchedule.Duration = 86400;
  1985. //isDurationNull = TRUE;
  1986. }
  1987. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "startSchedule") != NULL)
  1988. {
  1989. 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")));
  1990. }
  1991. else
  1992. {
  1993. sprintf((char*)maxProfile.ChargingSchedule.StartSchedule, "%s", compositeProfile.ChargingSchedule.StartSchedule);
  1994. }
  1995. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate") != NULL)
  1996. {
  1997. maxProfile.ChargingSchedule.MinChargingRate = json_object_get_double(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate"));
  1998. }
  1999. else
  2000. {
  2001. maxProfile.ChargingSchedule.MinChargingRate = -1;
  2002. }
  2003. }
  2004. }
  2005. }
  2006. else
  2007. {
  2008. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  2009. {
  2010. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = -1;
  2011. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit = -1;
  2012. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases = 3;
  2013. }
  2014. if(maxProfile.ChargingProfileId == -1)
  2015. DEBUG_INFO("MaxProfile found.\n");
  2016. else
  2017. DEBUG_INFO("MaxProfile updated.\n");
  2018. // Required item
  2019. maxProfile.ChargingProfileId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileId"));
  2020. maxProfile.StackLevel = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "stackLevel"));
  2021. sprintf((char*)maxProfile.ChargingProfileKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileKind")));
  2022. if(isUnitA)
  2023. {
  2024. sprintf((char*)maxProfile.ChargingSchedule.ChargingRateUnit, "A");
  2025. 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++)
  2026. {
  2027. 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"));
  2028. 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?
  2029. 3:
  2030. 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")));
  2031. 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")));
  2032. }
  2033. }
  2034. else
  2035. {
  2036. sprintf((char*)maxProfile.ChargingSchedule.ChargingRateUnit, "W");
  2037. 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++)
  2038. {
  2039. 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"));
  2040. 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?
  2041. 3:
  2042. 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")));
  2043. 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));
  2044. }
  2045. }
  2046. // Optional item
  2047. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom") != NULL)
  2048. {
  2049. sprintf((char*)maxProfile.ValidFrom, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom")));
  2050. }
  2051. else
  2052. {
  2053. sprintf((char*)maxProfile.ValidFrom, " ");
  2054. }
  2055. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo") != NULL)
  2056. {
  2057. sprintf((char*)maxProfile.ValidTo, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo")));
  2058. }
  2059. else
  2060. {
  2061. sprintf((char*)maxProfile.ValidTo, " ");
  2062. }
  2063. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "recurrencyKind") != NULL)
  2064. {
  2065. sprintf((char*)maxProfile.RecurrencyKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "recurrencyKind")));
  2066. }
  2067. else
  2068. {
  2069. sprintf((char*)maxProfile.RecurrencyKind, " ");
  2070. }
  2071. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId") != NULL)
  2072. {
  2073. maxProfile.TransactionId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId"));
  2074. }
  2075. else
  2076. {
  2077. maxProfile.TransactionId = -1;
  2078. }
  2079. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration") != NULL)
  2080. {
  2081. maxProfile.ChargingSchedule.Duration = json_object_get_int(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration"));
  2082. }
  2083. else
  2084. {
  2085. maxProfile.ChargingSchedule.Duration = 86400;
  2086. //isDurationNull = TRUE;
  2087. }
  2088. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "startSchedule") != NULL)
  2089. {
  2090. 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")));
  2091. }
  2092. else
  2093. {
  2094. sprintf((char*)maxProfile.ChargingSchedule.StartSchedule, "%s", compositeProfile.ChargingSchedule.StartSchedule);
  2095. }
  2096. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate") != NULL)
  2097. {
  2098. maxProfile.ChargingSchedule.MinChargingRate = json_object_get_double(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate"));
  2099. }
  2100. else
  2101. {
  2102. maxProfile.ChargingSchedule.MinChargingRate = -1;
  2103. }
  2104. }
  2105. }
  2106. }
  2107. json_object_put(obj);
  2108. }
  2109. fclose(fp);
  2110. /*
  2111. if(maxProfile.ChargingProfileId !=-1)
  2112. {
  2113. DEBUG_INFO("Profile ID: %d\n", maxProfile.ChargingProfileId);
  2114. DEBUG_INFO("Profile stackLevel: %d\n", maxProfile.StackLevel);
  2115. DEBUG_INFO("Profile TransactionId: %d\n", maxProfile.TransactionId);
  2116. DEBUG_INFO("Profile valid from: %s\n", maxProfile.ValidFrom);
  2117. DEBUG_INFO("Profile valid to: %s\n", maxProfile.ValidTo);
  2118. DEBUG_INFO("Profile ChargingProfileKind: %s\n", maxProfile.ChargingProfileKind);
  2119. DEBUG_INFO("Profile recurrencyKind: %s\n", maxProfile.RecurrencyKind);
  2120. DEBUG_INFO("Profile start schedule: %s\n", maxProfile.ChargingSchedule.StartSchedule);
  2121. DEBUG_INFO("Profile schedule duration: %d\n", maxProfile.ChargingSchedule.Duration);
  2122. DEBUG_INFO("Profile charging rate unit: %s\n", maxProfile.ChargingSchedule.ChargingRateUnit);
  2123. DEBUG_INFO("Profile charging min rate: %f\n", maxProfile.ChargingSchedule.MinChargingRate);
  2124. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  2125. {
  2126. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod >= 0)
  2127. {
  2128. DEBUG_INFO("Period-%02d startPeriod: %d\n", idxPeriod, maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod);
  2129. DEBUG_INFO("Period-%02d limit: %f\n", idxPeriod, maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit);
  2130. DEBUG_INFO("Period-%02d NumberPhases: %d\n", idxPeriod, maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases);
  2131. }
  2132. }
  2133. }
  2134. else
  2135. DEBUG_INFO("MaxProfile not found.\n");
  2136. DEBUG_INFO("------------------------------------\n");*/
  2137. }
  2138. if(maxProfile.ChargingProfileId != -1)
  2139. {
  2140. if(strstr((char*)maxProfile.ChargingProfileKind, "Absolute") != NULL)
  2141. {
  2142. if((maxProfile.ChargingSchedule.Duration != -1)/* && (isDurationNull)*/)
  2143. {
  2144. maxProfile.ChargingSchedule.Duration = ((maxProfile.ChargingSchedule.Duration-getStartStop(maxProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule))<0?
  2145. 0:
  2146. (maxProfile.ChargingSchedule.Duration-getStartStop(maxProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule)));
  2147. }
  2148. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  2149. {
  2150. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  2151. {
  2152. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = ((maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartStop(maxProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule))<0?
  2153. 0:
  2154. (maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartStop(maxProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule)));
  2155. if(idxPeriod > 0)
  2156. {
  2157. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
  2158. {
  2159. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit = maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit;
  2160. }
  2161. }
  2162. }
  2163. }
  2164. }
  2165. else if(strstr((char*)maxProfile.ChargingProfileKind, "Relative") != NULL)
  2166. {
  2167. if(maxProfile.ChargingSchedule.Duration != -1)
  2168. {
  2169. maxProfile.ChargingSchedule.Duration = maxProfile.ChargingSchedule.Duration;
  2170. }
  2171. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  2172. {
  2173. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  2174. {
  2175. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod;
  2176. if(idxPeriod > 0)
  2177. {
  2178. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
  2179. {
  2180. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit = maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit;
  2181. }
  2182. }
  2183. }
  2184. }
  2185. }
  2186. else
  2187. {
  2188. if(strstr((char*)maxProfile.RecurrencyKind, "Weekly") != NULL)
  2189. {
  2190. if(maxProfile.ChargingSchedule.Duration != -1)
  2191. {
  2192. maxProfile.ChargingSchedule.Duration = ((maxProfile.ChargingSchedule.Duration-getStartSinceRecurring(maxProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule, FALSE))<0?
  2193. 0:
  2194. (maxProfile.ChargingSchedule.Duration-getStartSinceRecurring(maxProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule, FALSE)));
  2195. }
  2196. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  2197. {
  2198. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  2199. {
  2200. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = ((maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceRecurring(maxProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule, FALSE))<0?
  2201. 0:
  2202. (maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceRecurring(maxProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule, FALSE)));
  2203. if(idxPeriod > 0)
  2204. {
  2205. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
  2206. {
  2207. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit = maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit;
  2208. }
  2209. }
  2210. }
  2211. }
  2212. }
  2213. else
  2214. {
  2215. if(maxProfile.ChargingSchedule.Duration != -1)
  2216. {
  2217. maxProfile.ChargingSchedule.Duration = ((maxProfile.ChargingSchedule.Duration-getStartSinceRecurring(maxProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule, TRUE))<0?
  2218. 0:
  2219. (maxProfile.ChargingSchedule.Duration-getStartSinceRecurring(maxProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule, TRUE)));
  2220. }
  2221. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  2222. {
  2223. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  2224. {
  2225. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = ((maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceRecurring(maxProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule, TRUE))<0?
  2226. 0:
  2227. (maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceRecurring(maxProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule, TRUE)));
  2228. if(idxPeriod > 0)
  2229. {
  2230. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
  2231. {
  2232. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit = maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit;
  2233. }
  2234. }
  2235. }
  2236. }
  2237. }
  2238. }
  2239. /*
  2240. DEBUG_INFO("MaxProfile after align.\n");
  2241. DEBUG_INFO("Profile ID: %d\n", maxProfile.ChargingProfileId);
  2242. DEBUG_INFO("Profile stackLevel: %d\n", maxProfile.StackLevel);
  2243. DEBUG_INFO("Profile TransactionId: %d\n", maxProfile.TransactionId);
  2244. DEBUG_INFO("Profile valid from: %s\n", maxProfile.ValidFrom);
  2245. DEBUG_INFO("Profile valid to: %s\n", maxProfile.ValidTo);
  2246. DEBUG_INFO("Profile ChargingProfileKind: %s\n", maxProfile.ChargingProfileKind);
  2247. DEBUG_INFO("Profile RecurrencyKind: %s\n", maxProfile.RecurrencyKind);
  2248. DEBUG_INFO("Profile start schedule: %s\n", compositeProfile->ChargingSchedule.StartSchedule);
  2249. DEBUG_INFO("Profile schedule duration: %d\n", maxProfile.ChargingSchedule.Duration);
  2250. DEBUG_INFO("Profile charging rate unit: %s\n", maxProfile.ChargingSchedule.ChargingRateUnit);
  2251. DEBUG_INFO("Profile charging min rate: %f\n", maxProfile.ChargingSchedule.MinChargingRate);
  2252. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  2253. {
  2254. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod >= 0)
  2255. {
  2256. DEBUG_INFO("Period-%02d startPeriod: %d\n", idxPeriod, maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod);
  2257. DEBUG_INFO("Period-%02d limit: %f\n", idxPeriod, maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit);
  2258. DEBUG_INFO("Period-%02d NumberPhases: %d\n", idxPeriod, maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases);
  2259. }
  2260. }
  2261. DEBUG_INFO("------------------------------------\n");*/
  2262. }
  2263. // Find each profile period quantity
  2264. for(int idx=0;idx<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idx++)
  2265. {
  2266. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idx].Limit != -1)
  2267. limitMax = idx+1;
  2268. }
  2269. if(maxProfile.ChargingProfileId != -1)
  2270. {
  2271. for(int idxMaxPeriod=0;idxMaxPeriod<limitMax;idxMaxPeriod++)
  2272. {
  2273. if((maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].Limit != -1) &&
  2274. (maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].StartPeriod < durationReq) &&
  2275. (maxProfile.ChargingSchedule.Duration > 0))
  2276. {
  2277. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].StartPeriod != compositeProfile.ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].StartPeriod)
  2278. {
  2279. memcpy(&compositeProfile.ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx], &maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod],sizeof(struct StructChargingSchedulePeriod));
  2280. compositePeriodIdx++;
  2281. }
  2282. else
  2283. {
  2284. memcpy(&compositeProfile.ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)], &maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod],sizeof(struct StructChargingSchedulePeriod));
  2285. }
  2286. }
  2287. }
  2288. }
  2289. DEBUG_INFO("ChargePointMaxProfile ready.\n");
  2290. DEBUG_INFO("Schedule start: %s\n", compositeProfile.ChargingSchedule.StartSchedule);
  2291. DEBUG_INFO("Schedule duration: %d\n", compositeProfile.ChargingSchedule.Duration);
  2292. DEBUG_INFO("Rate unit: %s\n", compositeProfile.ChargingSchedule.ChargingRateUnit);
  2293. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(compositeProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  2294. {
  2295. if(compositeProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod >= 0)
  2296. {
  2297. compositeProfile.ChargingProfileId = 1;
  2298. DEBUG_INFO("Period-%02d startPeriod: %d\n", idxPeriod, compositeProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod);
  2299. DEBUG_INFO("Period-%02d limit: %f\n", idxPeriod, compositeProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit);
  2300. DEBUG_INFO("Period-%02d NumberPhases: %d\n", idxPeriod, compositeProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases);
  2301. }
  2302. if(compositeProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit == -1)
  2303. compositeProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit =0;
  2304. if(compositeProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod == -1)
  2305. compositeProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod =0;
  2306. }
  2307. memcpy(targetCompositeProfile, &compositeProfile, sizeof(struct StructChargingProfile));
  2308. if(line)
  2309. free(line);
  2310. }
  2311. void checkCompositeSchedule(uint8_t connectorId, uint32_t durationReq, struct StructChargingProfile *targetCompositeProfile, uint8_t isUnitA)
  2312. {
  2313. FILE *fp;
  2314. char profileFileName[128];
  2315. char *line = NULL;
  2316. size_t len = 0;
  2317. time_t CurrentTime;
  2318. struct tm *tmComposite;
  2319. struct StructChargingProfile maxProfile;
  2320. struct StructChargingProfile defaultTxProfile;
  2321. struct StructChargingProfile txProfile;
  2322. struct StructChargingProfile compositeProfile;
  2323. struct StructChargingSchedulePeriod tmpPeriod;
  2324. uint8_t limitMax=0;
  2325. uint8_t limitDef=0;
  2326. uint8_t limitTx=0;
  2327. int compositePeriodIdx = 0;
  2328. CurrentTime = time(NULL);
  2329. tmComposite=localtime(&CurrentTime);
  2330. 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);
  2331. if(isUnitA)
  2332. sprintf((char*)compositeProfile.ChargingSchedule.ChargingRateUnit, "A");
  2333. else
  2334. sprintf((char*)compositeProfile.ChargingSchedule.ChargingRateUnit, "W");
  2335. compositeProfile.ChargingSchedule.Duration = durationReq;
  2336. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(compositeProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  2337. {
  2338. compositeProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = -1;
  2339. compositeProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit = -1;
  2340. compositeProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases = 3;
  2341. }
  2342. compositeProfile.ChargingProfileId = 0;
  2343. compositeProfile.StackLevel = 99 ;
  2344. sprintf((char*)compositeProfile.ChargingProfileKind ,"Absolute");
  2345. maxProfile.ChargingProfileId = -1;
  2346. defaultTxProfile.ChargingProfileId = -1;
  2347. txProfile.ChargingProfileId = -1;
  2348. maxProfile.ChargingSchedule.Duration = -1;
  2349. defaultTxProfile.ChargingSchedule.Duration = -1;
  2350. txProfile.ChargingSchedule.Duration = -1;
  2351. system("rm -f /tmp/*.json");
  2352. system("cp /Storage/OCPP/*.json /tmp 2>/dev/null");
  2353. /*
  2354. * Search valid charging profile
  2355. */
  2356. //DEBUG_INFO("====================================\n");
  2357. // Search tx profile
  2358. sprintf(profileFileName, "/tmp/TxProfile_%d.json", connectorId);
  2359. if((access(profileFileName, F_OK))!=-1)
  2360. {
  2361. fp = fopen(profileFileName, "r");
  2362. while(getline(&line, &len, fp) != -1)
  2363. {
  2364. json_object *obj = NULL;
  2365. obj = json_tokener_parse(line);
  2366. if(is_error(obj))
  2367. {
  2368. DEBUG_ERROR("Parse txProfile from file error.\n");
  2369. }
  2370. else
  2371. {
  2372. if((json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileId")) != txProfile.ChargingProfileId) &&
  2373. (json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "stackLevel")) >= txProfile.StackLevel)
  2374. )
  2375. {
  2376. if((json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom") != NULL) &&
  2377. (json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo") != NULL)
  2378. )
  2379. {
  2380. struct tm tmFrom, tmTo;
  2381. struct timeb tbFrom, tbTo;
  2382. 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) &&
  2383. (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))
  2384. {
  2385. tmFrom.tm_year -= 1900;
  2386. tmFrom.tm_mon -= 1;
  2387. tbFrom.time = mktime(&tmFrom);
  2388. tmTo.tm_year -= 1900;
  2389. tmTo.tm_mon -= 1;
  2390. tbTo.time = mktime(&tmTo);
  2391. if((DiffTimebWithNowSec(tbFrom)>=0) && (DiffTimebWithNowSec(tbTo)<=0))
  2392. {
  2393. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(txProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  2394. {
  2395. txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = -1;
  2396. txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit = -1;
  2397. txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases = 3;
  2398. }
  2399. if(txProfile.ChargingProfileId == -1)
  2400. DEBUG_INFO("TxProfile found.\n");
  2401. else
  2402. DEBUG_INFO("TxProfile updated.\n");
  2403. // Required item
  2404. txProfile.ChargingProfileId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileId"));
  2405. txProfile.StackLevel = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "stackLevel"));
  2406. sprintf((char*)txProfile.ChargingProfileKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileKind")));
  2407. if(isUnitA)
  2408. {
  2409. sprintf((char*)txProfile.ChargingSchedule.ChargingRateUnit, "A");
  2410. 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++)
  2411. {
  2412. 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"));
  2413. 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?
  2414. 3:
  2415. 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")));
  2416. 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")));
  2417. }
  2418. }
  2419. else
  2420. {
  2421. sprintf((char*)txProfile.ChargingSchedule.ChargingRateUnit, "W");
  2422. 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++)
  2423. {
  2424. 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"));
  2425. 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?
  2426. 3:
  2427. 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")));
  2428. 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));
  2429. }
  2430. }
  2431. // Optional item
  2432. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom") != NULL)
  2433. {
  2434. sprintf((char*)txProfile.ValidFrom, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom")));
  2435. }
  2436. else
  2437. {
  2438. sprintf((char*)txProfile.ValidFrom, " ");
  2439. }
  2440. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo") != NULL)
  2441. {
  2442. sprintf((char*)txProfile.ValidTo, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo")));
  2443. }
  2444. else
  2445. {
  2446. sprintf((char*)txProfile.ValidTo, " ");
  2447. }
  2448. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "recurrencyKind") != NULL)
  2449. {
  2450. sprintf((char*)txProfile.RecurrencyKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "recurrencyKind")));
  2451. }
  2452. else
  2453. {
  2454. sprintf((char*)txProfile.RecurrencyKind, " ");
  2455. }
  2456. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId") != NULL)
  2457. {
  2458. txProfile.TransactionId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId"));
  2459. }
  2460. else
  2461. {
  2462. txProfile.TransactionId = -1;
  2463. }
  2464. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration") != NULL)
  2465. {
  2466. txProfile.ChargingSchedule.Duration = json_object_get_int(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration"));
  2467. }
  2468. else
  2469. {
  2470. txProfile.ChargingSchedule.Duration = 86400;
  2471. }
  2472. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "startSchedule") != NULL)
  2473. {
  2474. 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")));
  2475. }
  2476. else
  2477. {
  2478. 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));
  2479. }
  2480. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate") != NULL)
  2481. {
  2482. txProfile.ChargingSchedule.MinChargingRate = json_object_get_double(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate"));
  2483. }
  2484. else
  2485. {
  2486. txProfile.ChargingSchedule.MinChargingRate = -1;
  2487. }
  2488. }
  2489. }
  2490. }
  2491. else
  2492. {
  2493. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(txProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  2494. {
  2495. txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = -1;
  2496. txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit = -1;
  2497. txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases = 3;
  2498. }
  2499. if(txProfile.ChargingProfileId == -1)
  2500. DEBUG_INFO("TxProfile found.\n");
  2501. else
  2502. DEBUG_INFO("TxProfile updated.\n");
  2503. // Required item
  2504. txProfile.ChargingProfileId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileId"));
  2505. txProfile.StackLevel = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "stackLevel"));
  2506. sprintf((char*)txProfile.ChargingProfileKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileKind")));
  2507. if(isUnitA)
  2508. {
  2509. sprintf((char*)txProfile.ChargingSchedule.ChargingRateUnit, "A");
  2510. 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++)
  2511. {
  2512. 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"));
  2513. 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?
  2514. 3:
  2515. 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")));
  2516. 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")));
  2517. }
  2518. }
  2519. else
  2520. {
  2521. sprintf((char*)txProfile.ChargingSchedule.ChargingRateUnit, "W");
  2522. 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++)
  2523. {
  2524. 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"));
  2525. 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?
  2526. 3:
  2527. 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")));
  2528. 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));
  2529. }
  2530. }
  2531. // Optional item
  2532. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom") != NULL)
  2533. {
  2534. sprintf((char*)txProfile.ValidFrom, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom")));
  2535. }
  2536. else
  2537. {
  2538. sprintf((char*)txProfile.ValidFrom, " ");
  2539. }
  2540. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo") != NULL)
  2541. {
  2542. sprintf((char*)txProfile.ValidTo, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo")));
  2543. }
  2544. else
  2545. {
  2546. sprintf((char*)txProfile.ValidTo, " ");
  2547. }
  2548. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "recurrencyKind") != NULL)
  2549. {
  2550. sprintf((char*)txProfile.RecurrencyKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "recurrencyKind")));
  2551. }
  2552. else
  2553. {
  2554. sprintf((char*)txProfile.RecurrencyKind, " ");
  2555. }
  2556. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId") != NULL)
  2557. {
  2558. txProfile.TransactionId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId"));
  2559. }
  2560. else
  2561. {
  2562. txProfile.TransactionId = -1;
  2563. }
  2564. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration") != NULL)
  2565. {
  2566. txProfile.ChargingSchedule.Duration = json_object_get_int(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration"));
  2567. }
  2568. else
  2569. {
  2570. txProfile.ChargingSchedule.Duration = 86400;
  2571. }
  2572. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "startSchedule") != NULL)
  2573. {
  2574. 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")));
  2575. }
  2576. else
  2577. {
  2578. 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));
  2579. }
  2580. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate") != NULL)
  2581. {
  2582. txProfile.ChargingSchedule.MinChargingRate = json_object_get_double(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate"));
  2583. }
  2584. else
  2585. {
  2586. txProfile.ChargingSchedule.MinChargingRate = -1;
  2587. }
  2588. }
  2589. }
  2590. }
  2591. json_object_put(obj);
  2592. }
  2593. fclose(fp);
  2594. /*
  2595. if(txProfile.ChargingProfileId != -1)
  2596. {
  2597. DEBUG_INFO("Profile ID: %d\n", txProfile.ChargingProfileId);
  2598. DEBUG_INFO("Profile stackLevel: %d\n", txProfile.StackLevel);
  2599. DEBUG_INFO("Profile TransactionId: %d\n", txProfile.TransactionId);
  2600. DEBUG_INFO("Profile valid from: %s\n", txProfile.ValidFrom);
  2601. DEBUG_INFO("Profile valid to: %s\n", txProfile.ValidTo);
  2602. DEBUG_INFO("Profile ChargingProfileKind: %s\n", txProfile.ChargingProfileKind);
  2603. DEBUG_INFO("Profile recurrencyKind: %s\n", txProfile.RecurrencyKind);
  2604. DEBUG_INFO("Profile start schedule: %s\n", txProfile.ChargingSchedule.StartSchedule);
  2605. DEBUG_INFO("Profile schedule duration: %d\n", txProfile.ChargingSchedule.Duration);
  2606. DEBUG_INFO("Profile charging rate unit: %s\n", txProfile.ChargingSchedule.ChargingRateUnit);
  2607. DEBUG_INFO("Profile charging min rate: %f\n", txProfile.ChargingSchedule.MinChargingRate);
  2608. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(txProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  2609. {
  2610. if(txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod >= 0)
  2611. {
  2612. DEBUG_INFO("Period-%02d startPeriod: %d\n", idxPeriod, txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod);
  2613. DEBUG_INFO("Period-%02d limit: %f\n", idxPeriod, txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit);
  2614. DEBUG_INFO("Period-%02d NumberPhases: %d\n", idxPeriod, txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases);
  2615. }
  2616. }
  2617. }
  2618. else
  2619. DEBUG_INFO("TxProfile not found.\n");*/
  2620. }
  2621. // Search default tx profile
  2622. sprintf(profileFileName, "/tmp/TxDefaultProfile_%d.json", connectorId);
  2623. if((access(profileFileName, F_OK))==-1)
  2624. sprintf(profileFileName, "/tmp/TxDefaultProfile_0.json");
  2625. if((access(profileFileName, F_OK))!=-1)
  2626. {
  2627. fp = fopen(profileFileName, "r");
  2628. while(getline(&line, &len, fp) != -1)
  2629. {
  2630. json_object *obj = NULL;
  2631. obj = json_tokener_parse(line);
  2632. if(is_error(obj))
  2633. {
  2634. DEBUG_ERROR("Parse TxDefaultProfile from file error.\n");
  2635. }
  2636. else
  2637. {
  2638. if((json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileId")) != defaultTxProfile.ChargingProfileId) &&
  2639. (json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "stackLevel")) >= defaultTxProfile.StackLevel)
  2640. )
  2641. {
  2642. if((json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom") != NULL) &&
  2643. (json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo") != NULL)
  2644. )
  2645. {
  2646. struct tm tmFrom, tmTo;
  2647. struct timeb tbFrom, tbTo;
  2648. 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) &&
  2649. (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))
  2650. {
  2651. tmFrom.tm_year -= 1900;
  2652. tmFrom.tm_mon -= 1;
  2653. tbFrom.time = mktime(&tmFrom);
  2654. tmTo.tm_year -= 1900;
  2655. tmTo.tm_mon -= 1;
  2656. tbTo.time = mktime(&tmTo);
  2657. if((DiffTimebWithNowSec(tbFrom)>=0) && (DiffTimebWithNowSec(tbTo)<=0))
  2658. {
  2659. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  2660. {
  2661. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = -1;
  2662. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit = -1;
  2663. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases = 3;
  2664. }
  2665. if(defaultTxProfile.ChargingProfileId == -1)
  2666. DEBUG_INFO("TxDefaultProfile found.\n");
  2667. else
  2668. DEBUG_INFO("TxDefaultProfile updated.\n");
  2669. // Required item
  2670. defaultTxProfile.ChargingProfileId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileId"));
  2671. defaultTxProfile.StackLevel = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "stackLevel"));
  2672. sprintf((char*)defaultTxProfile.ChargingProfileKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileKind")));
  2673. if(isUnitA)
  2674. {
  2675. sprintf((char*)defaultTxProfile.ChargingSchedule.ChargingRateUnit, "A");
  2676. 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++)
  2677. {
  2678. 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"));
  2679. 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?
  2680. 3:
  2681. 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")));
  2682. 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")));
  2683. }
  2684. }
  2685. else
  2686. {
  2687. sprintf((char*)defaultTxProfile.ChargingSchedule.ChargingRateUnit, "W");
  2688. for(int idxPeriod=0;idxPeriod<json_object_array_length(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"));idxPeriod++)
  2689. {
  2690. 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"));
  2691. 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?
  2692. 3:
  2693. json_object_get_int(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "numberPhases")));
  2694. 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));
  2695. }
  2696. }
  2697. // Optional item
  2698. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom") != NULL)
  2699. {
  2700. sprintf((char*)defaultTxProfile.ValidFrom, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom")));
  2701. }
  2702. else
  2703. {
  2704. sprintf((char*)defaultTxProfile.ValidFrom, " ");
  2705. }
  2706. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo") != NULL)
  2707. {
  2708. sprintf((char*)defaultTxProfile.ValidTo, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo")));
  2709. }
  2710. else
  2711. {
  2712. sprintf((char*)defaultTxProfile.ValidTo, " ");
  2713. }
  2714. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "recurrencyKind") != NULL)
  2715. {
  2716. sprintf((char*)defaultTxProfile.RecurrencyKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "recurrencyKind")));
  2717. }
  2718. else
  2719. {
  2720. sprintf((char*)defaultTxProfile.RecurrencyKind, " ");
  2721. }
  2722. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId") != NULL)
  2723. {
  2724. defaultTxProfile.TransactionId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId"));
  2725. }
  2726. else
  2727. {
  2728. defaultTxProfile.TransactionId = -1;
  2729. }
  2730. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration") != NULL)
  2731. {
  2732. defaultTxProfile.ChargingSchedule.Duration = json_object_get_int(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration"));
  2733. }
  2734. else
  2735. {
  2736. defaultTxProfile.ChargingSchedule.Duration = 86400;
  2737. }
  2738. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "startSchedule") != NULL)
  2739. {
  2740. 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")));
  2741. }
  2742. else
  2743. {
  2744. 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));
  2745. }
  2746. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate") != NULL)
  2747. {
  2748. defaultTxProfile.ChargingSchedule.MinChargingRate = json_object_get_double(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate"));
  2749. }
  2750. else
  2751. {
  2752. defaultTxProfile.ChargingSchedule.MinChargingRate = -1;
  2753. }
  2754. }
  2755. }
  2756. }
  2757. else
  2758. {
  2759. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  2760. {
  2761. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = -1;
  2762. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit = -1;
  2763. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases = 3;
  2764. }
  2765. if(defaultTxProfile.ChargingProfileId == -1)
  2766. DEBUG_INFO("TxDefaultProfile found.\n");
  2767. else
  2768. DEBUG_INFO("TxDefaultProfile updated.\n");
  2769. // Required item
  2770. defaultTxProfile.ChargingProfileId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileId"));
  2771. defaultTxProfile.StackLevel = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "stackLevel"));
  2772. sprintf((char*)defaultTxProfile.ChargingProfileKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileKind")));
  2773. if(isUnitA)
  2774. {
  2775. sprintf((char*)defaultTxProfile.ChargingSchedule.ChargingRateUnit, "A");
  2776. 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++)
  2777. {
  2778. 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"));
  2779. 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?
  2780. 3:
  2781. 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")));
  2782. 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")));
  2783. }
  2784. }
  2785. else
  2786. {
  2787. sprintf((char*)defaultTxProfile.ChargingSchedule.ChargingRateUnit, "W");
  2788. 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++)
  2789. {
  2790. 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"));
  2791. 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?
  2792. 3:
  2793. 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")));
  2794. 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));
  2795. }
  2796. }
  2797. // Optional item
  2798. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom") != NULL)
  2799. {
  2800. sprintf((char*)defaultTxProfile.ValidFrom, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom")));
  2801. }
  2802. else
  2803. {
  2804. sprintf((char*)defaultTxProfile.ValidFrom, " ");
  2805. }
  2806. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo") != NULL)
  2807. {
  2808. sprintf((char*)defaultTxProfile.ValidTo, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo")));
  2809. }
  2810. else
  2811. {
  2812. sprintf((char*)defaultTxProfile.ValidTo, " ");
  2813. }
  2814. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "recurrencyKind") != NULL)
  2815. {
  2816. sprintf((char*)defaultTxProfile.RecurrencyKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "recurrencyKind")));
  2817. }
  2818. else
  2819. {
  2820. sprintf((char*)defaultTxProfile.RecurrencyKind, " ");
  2821. }
  2822. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId") != NULL)
  2823. {
  2824. defaultTxProfile.TransactionId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId"));
  2825. }
  2826. else
  2827. {
  2828. defaultTxProfile.TransactionId = -1;
  2829. }
  2830. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration") != NULL)
  2831. {
  2832. defaultTxProfile.ChargingSchedule.Duration = json_object_get_int(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration"));
  2833. }
  2834. else
  2835. {
  2836. defaultTxProfile.ChargingSchedule.Duration = 86400;
  2837. }
  2838. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "startSchedule") != NULL)
  2839. {
  2840. 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")));
  2841. }
  2842. else
  2843. {
  2844. 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));
  2845. }
  2846. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate") != NULL)
  2847. {
  2848. defaultTxProfile.ChargingSchedule.MinChargingRate = json_object_get_double(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate"));
  2849. }
  2850. else
  2851. {
  2852. defaultTxProfile.ChargingSchedule.MinChargingRate = -1;
  2853. }
  2854. }
  2855. }
  2856. }
  2857. json_object_put(obj);
  2858. }
  2859. fclose(fp);
  2860. /*
  2861. if(defaultTxProfile.ChargingProfileId != -1)
  2862. {
  2863. DEBUG_INFO("Profile ID: %d\n", defaultTxProfile.ChargingProfileId);
  2864. DEBUG_INFO("Profile stackLevel: %d\n", defaultTxProfile.StackLevel);
  2865. DEBUG_INFO("Profile TransactionId: %d\n", defaultTxProfile.TransactionId);
  2866. DEBUG_INFO("Profile valid from: %s\n", defaultTxProfile.ValidFrom);
  2867. DEBUG_INFO("Profile valid to: %s\n", defaultTxProfile.ValidTo);
  2868. DEBUG_INFO("Profile ChargingProfileKind: %s\n", defaultTxProfile.ChargingProfileKind);
  2869. DEBUG_INFO("Profile recurrencyKind: %s\n", defaultTxProfile.RecurrencyKind);
  2870. DEBUG_INFO("Profile start schedule: %s\n", defaultTxProfile.ChargingSchedule.StartSchedule);
  2871. DEBUG_INFO("Profile schedule duration: %d\n", defaultTxProfile.ChargingSchedule.Duration);
  2872. DEBUG_INFO("Profile charging rate unit: %s\n", defaultTxProfile.ChargingSchedule.ChargingRateUnit);
  2873. DEBUG_INFO("Profile charging min rate: %f\n", defaultTxProfile.ChargingSchedule.MinChargingRate);
  2874. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  2875. {
  2876. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod >= 0)
  2877. {
  2878. DEBUG_INFO("Period-%02d startPeriod: %d\n", idxPeriod, defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod);
  2879. DEBUG_INFO("Period-%02d limit: %f\n", idxPeriod, defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit);
  2880. DEBUG_INFO("Period-%02d NumberPhases: %d\n", idxPeriod, defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases);
  2881. }
  2882. }
  2883. }
  2884. else
  2885. DEBUG_INFO("TxDefaultProfile not found.\n");
  2886. DEBUG_INFO("------------------------------------\n");*/
  2887. }
  2888. // Search max profile
  2889. sprintf(profileFileName, "/tmp/ChargePointMaxProfile.json");
  2890. if((access(profileFileName, F_OK))!=-1)
  2891. {
  2892. fp = fopen(profileFileName, "r");
  2893. while(getline(&line, &len, fp) != -1)
  2894. {
  2895. json_object *obj = NULL;
  2896. obj = json_tokener_parse(line);
  2897. if(is_error(obj))
  2898. {
  2899. DEBUG_ERROR("Parse MaxProfile from file error.\n");
  2900. }
  2901. else
  2902. {
  2903. if((json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileId")) != maxProfile.ChargingProfileId) &&
  2904. (json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "stackLevel")) >= maxProfile.StackLevel)
  2905. )
  2906. {
  2907. if((json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom") != NULL) &&
  2908. (json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo") != NULL)
  2909. )
  2910. {
  2911. struct tm tmFrom, tmTo;
  2912. struct timeb tbFrom, tbTo;
  2913. 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) &&
  2914. (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))
  2915. {
  2916. tmFrom.tm_year -= 1900;
  2917. tmFrom.tm_mon -= 1;
  2918. tbFrom.time = mktime(&tmFrom);
  2919. tmTo.tm_year -= 1900;
  2920. tmTo.tm_mon -= 1;
  2921. tbTo.time = mktime(&tmTo);
  2922. if((DiffTimebWithNowSec(tbFrom)>=0) && (DiffTimebWithNowSec(tbTo)<=0))
  2923. {
  2924. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  2925. {
  2926. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = -1;
  2927. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit = -1;
  2928. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases = 3;
  2929. }
  2930. if(maxProfile.ChargingProfileId == -1)
  2931. DEBUG_INFO("MaxProfile found.\n");
  2932. else
  2933. DEBUG_INFO("MaxProfile updated.\n");
  2934. // Required item
  2935. maxProfile.ChargingProfileId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileId"));
  2936. maxProfile.StackLevel = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "stackLevel"));
  2937. sprintf((char*)maxProfile.ChargingProfileKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileKind")));
  2938. if(isUnitA)
  2939. {
  2940. sprintf((char*)maxProfile.ChargingSchedule.ChargingRateUnit, "A");
  2941. 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++)
  2942. {
  2943. 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"));
  2944. 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?
  2945. 3:
  2946. 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")));
  2947. 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")));
  2948. }
  2949. }
  2950. else
  2951. {
  2952. sprintf((char*)maxProfile.ChargingSchedule.ChargingRateUnit, "W");
  2953. 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++)
  2954. {
  2955. 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"));
  2956. 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?
  2957. 3:
  2958. 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")));
  2959. 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));
  2960. }
  2961. }
  2962. // Optional item
  2963. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom") != NULL)
  2964. {
  2965. sprintf((char*)maxProfile.ValidFrom, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom")));
  2966. }
  2967. else
  2968. {
  2969. sprintf((char*)maxProfile.ValidFrom, " ");
  2970. }
  2971. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo") != NULL)
  2972. {
  2973. sprintf((char*)maxProfile.ValidTo, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo")));
  2974. }
  2975. else
  2976. {
  2977. sprintf((char*)maxProfile.ValidTo, " ");
  2978. }
  2979. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "recurrencyKind") != NULL)
  2980. {
  2981. sprintf((char*)maxProfile.RecurrencyKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "recurrencyKind")));
  2982. }
  2983. else
  2984. {
  2985. sprintf((char*)maxProfile.RecurrencyKind, " ");
  2986. }
  2987. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId") != NULL)
  2988. {
  2989. maxProfile.TransactionId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId"));
  2990. }
  2991. else
  2992. {
  2993. maxProfile.TransactionId = -1;
  2994. }
  2995. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration") != NULL)
  2996. {
  2997. maxProfile.ChargingSchedule.Duration = json_object_get_int(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration"));
  2998. }
  2999. else
  3000. {
  3001. maxProfile.ChargingSchedule.Duration = 86400;
  3002. }
  3003. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "startSchedule") != NULL)
  3004. {
  3005. 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")));
  3006. }
  3007. else
  3008. {
  3009. 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));
  3010. }
  3011. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate") != NULL)
  3012. {
  3013. maxProfile.ChargingSchedule.MinChargingRate = json_object_get_double(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate"));
  3014. }
  3015. else
  3016. {
  3017. maxProfile.ChargingSchedule.MinChargingRate = -1;
  3018. }
  3019. }
  3020. }
  3021. }
  3022. else
  3023. {
  3024. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  3025. {
  3026. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = -1;
  3027. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit = -1;
  3028. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases = 3;
  3029. }
  3030. if(maxProfile.ChargingProfileId == -1)
  3031. DEBUG_INFO("MaxProfile found.\n");
  3032. else
  3033. DEBUG_INFO("MaxProfile updated.\n");
  3034. // Required item
  3035. maxProfile.ChargingProfileId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileId"));
  3036. maxProfile.StackLevel = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "stackLevel"));
  3037. sprintf((char*)maxProfile.ChargingProfileKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileKind")));
  3038. if(isUnitA)
  3039. {
  3040. sprintf((char*)maxProfile.ChargingSchedule.ChargingRateUnit, "A");
  3041. 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++)
  3042. {
  3043. 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"));
  3044. 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?
  3045. 3:
  3046. 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")));
  3047. 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")));
  3048. }
  3049. }
  3050. else
  3051. {
  3052. sprintf((char*)maxProfile.ChargingSchedule.ChargingRateUnit, "W");
  3053. 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++)
  3054. {
  3055. 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"));
  3056. 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?
  3057. 3:
  3058. 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")));
  3059. 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));
  3060. }
  3061. }
  3062. // Optional item
  3063. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom") != NULL)
  3064. {
  3065. sprintf((char*)maxProfile.ValidFrom, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom")));
  3066. }
  3067. else
  3068. {
  3069. sprintf((char*)maxProfile.ValidFrom, " ");
  3070. }
  3071. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo") != NULL)
  3072. {
  3073. sprintf((char*)maxProfile.ValidTo, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo")));
  3074. }
  3075. else
  3076. {
  3077. sprintf((char*)maxProfile.ValidTo, " ");
  3078. }
  3079. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "recurrencyKind") != NULL)
  3080. {
  3081. sprintf((char*)maxProfile.RecurrencyKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "recurrencyKind")));
  3082. }
  3083. else
  3084. {
  3085. sprintf((char*)maxProfile.RecurrencyKind, " ");
  3086. }
  3087. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId") != NULL)
  3088. {
  3089. maxProfile.TransactionId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId"));
  3090. }
  3091. else
  3092. {
  3093. maxProfile.TransactionId = -1;
  3094. }
  3095. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration") != NULL)
  3096. {
  3097. maxProfile.ChargingSchedule.Duration = json_object_get_int(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration"));
  3098. }
  3099. else
  3100. {
  3101. maxProfile.ChargingSchedule.Duration = 86400;
  3102. }
  3103. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "startSchedule") != NULL)
  3104. {
  3105. 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")));
  3106. }
  3107. else
  3108. {
  3109. 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));
  3110. }
  3111. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate") != NULL)
  3112. {
  3113. maxProfile.ChargingSchedule.MinChargingRate = json_object_get_double(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate"));
  3114. }
  3115. else
  3116. {
  3117. maxProfile.ChargingSchedule.MinChargingRate = -1;
  3118. }
  3119. }
  3120. }
  3121. }
  3122. json_object_put(obj);
  3123. }
  3124. fclose(fp);
  3125. /*
  3126. if(maxProfile.ChargingProfileId !=-1)
  3127. {
  3128. DEBUG_INFO("Profile ID: %d\n", maxProfile.ChargingProfileId);
  3129. DEBUG_INFO("Profile stackLevel: %d\n", maxProfile.StackLevel);
  3130. DEBUG_INFO("Profile TransactionId: %d\n", maxProfile.TransactionId);
  3131. DEBUG_INFO("Profile valid from: %s\n", maxProfile.ValidFrom);
  3132. DEBUG_INFO("Profile valid to: %s\n", maxProfile.ValidTo);
  3133. DEBUG_INFO("Profile ChargingProfileKind: %s\n", maxProfile.ChargingProfileKind);
  3134. DEBUG_INFO("Profile recurrencyKind: %s\n", maxProfile.RecurrencyKind);
  3135. DEBUG_INFO("Profile start schedule: %s\n", maxProfile.ChargingSchedule.StartSchedule);
  3136. DEBUG_INFO("Profile schedule duration: %d\n", maxProfile.ChargingSchedule.Duration);
  3137. DEBUG_INFO("Profile charging rate unit: %s\n", maxProfile.ChargingSchedule.ChargingRateUnit);
  3138. DEBUG_INFO("Profile charging min rate: %f\n", maxProfile.ChargingSchedule.MinChargingRate);
  3139. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  3140. {
  3141. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod >= 0)
  3142. {
  3143. DEBUG_INFO("Period-%02d startPeriod: %d\n", idxPeriod, maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod);
  3144. DEBUG_INFO("Period-%02d limit: %f\n", idxPeriod, maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit);
  3145. DEBUG_INFO("Period-%02d NumberPhases: %d\n", idxPeriod, maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases);
  3146. }
  3147. }
  3148. }
  3149. else
  3150. DEBUG_INFO("MaxProfile not found.\n");
  3151. DEBUG_INFO("------------------------------------\n");*/
  3152. }
  3153. /*
  3154. * Align found profile start schedule & periods
  3155. */
  3156. //DEBUG_INFO("====================================\n");
  3157. /*
  3158. // For local test usage, force modify found profile start schedule info
  3159. 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);
  3160. 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);
  3161. 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);
  3162. */
  3163. if(txProfile.ChargingProfileId != -1)
  3164. {
  3165. if(strstr((char*)txProfile.ChargingProfileKind, "Absolute") != NULL)
  3166. {
  3167. if(txProfile.ChargingSchedule.Duration != -1)
  3168. {
  3169. txProfile.ChargingSchedule.Duration = ((txProfile.ChargingSchedule.Duration-getStartStop(txProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule))<0?
  3170. 0:
  3171. (txProfile.ChargingSchedule.Duration-getStartStop(txProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule)));
  3172. }
  3173. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(txProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  3174. {
  3175. if(txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  3176. {
  3177. txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = ((txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartStop(txProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule))<0?
  3178. 0:
  3179. (txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartStop(txProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule)));
  3180. if(idxPeriod > 0)
  3181. {
  3182. if(txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
  3183. {
  3184. txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit = txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit;
  3185. }
  3186. }
  3187. }
  3188. }
  3189. }
  3190. else if(strstr((char*)txProfile.ChargingProfileKind, "Relative") != NULL)
  3191. {
  3192. if(txProfile.ChargingSchedule.Duration != -1)
  3193. {
  3194. 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?
  3195. 0:
  3196. (txProfile.ChargingSchedule.Duration-getStartStop(ShmOCPP16Data->StartTransaction[(connectorId==0?0:connectorId-1)].Timestamp, compositeProfile.ChargingSchedule.StartSchedule)));
  3197. }
  3198. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(txProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  3199. {
  3200. if(txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  3201. {
  3202. 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?
  3203. 0:
  3204. (txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartStop(ShmOCPP16Data->StartTransaction[(connectorId==0?0:connectorId-1)].Timestamp, compositeProfile.ChargingSchedule.StartSchedule)));
  3205. if(idxPeriod > 0)
  3206. {
  3207. if(txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
  3208. {
  3209. txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit = txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit;
  3210. }
  3211. }
  3212. }
  3213. }
  3214. }
  3215. else
  3216. {
  3217. if(strstr((char*)txProfile.RecurrencyKind, "Weekly") != NULL)
  3218. {
  3219. if(txProfile.ChargingSchedule.Duration != -1)
  3220. {
  3221. txProfile.ChargingSchedule.Duration = ((txProfile.ChargingSchedule.Duration-getStartSinceRecurring(txProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule, FALSE))<0?
  3222. 0:
  3223. (txProfile.ChargingSchedule.Duration-getStartSinceRecurring(txProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule, FALSE)));
  3224. }
  3225. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(txProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  3226. {
  3227. if(txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  3228. {
  3229. txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = ((txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceRecurring(txProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule, FALSE))<0?
  3230. 0:
  3231. (txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceRecurring(txProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule, FALSE)));
  3232. if(idxPeriod > 0)
  3233. {
  3234. if(txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
  3235. {
  3236. txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit = txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit;
  3237. }
  3238. }
  3239. }
  3240. }
  3241. }
  3242. else
  3243. {
  3244. if(txProfile.ChargingSchedule.Duration != -1)
  3245. {
  3246. txProfile.ChargingSchedule.Duration = ((txProfile.ChargingSchedule.Duration-getStartSinceRecurring(txProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule, TRUE))<0?
  3247. 0:
  3248. (txProfile.ChargingSchedule.Duration-getStartSinceRecurring(txProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule, TRUE)));
  3249. }
  3250. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(txProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  3251. {
  3252. if(txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  3253. {
  3254. txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = ((txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceRecurring(txProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule, TRUE))<0?
  3255. 0:
  3256. (txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceRecurring(txProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule, TRUE)));
  3257. if(idxPeriod > 0)
  3258. {
  3259. if(txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
  3260. {
  3261. txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit = txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit;
  3262. }
  3263. }
  3264. }
  3265. }
  3266. }
  3267. }
  3268. /*
  3269. DEBUG_INFO("txProfile after align.\n");
  3270. DEBUG_INFO("Profile ID: %d\n", txProfile.ChargingProfileId);
  3271. DEBUG_INFO("Profile stackLevel: %d\n", txProfile.StackLevel);
  3272. DEBUG_INFO("Profile TransactionId: %d\n", txProfile.TransactionId);
  3273. DEBUG_INFO("Profile valid from: %s\n", txProfile.ValidFrom);
  3274. DEBUG_INFO("Profile valid to: %s\n", txProfile.ValidTo);
  3275. DEBUG_INFO("Profile ChargingProfileKind: %s\n", txProfile.ChargingProfileKind);
  3276. DEBUG_INFO("Profile recurrencyKind: %s\n", txProfile.RecurrencyKind);
  3277. DEBUG_INFO("Profile start schedule: %s\n", compositeProfile.ChargingSchedule.StartSchedule);
  3278. DEBUG_INFO("Profile schedule duration: %d\n", txProfile.ChargingSchedule.Duration);
  3279. DEBUG_INFO("Profile charging rate unit: %s\n", txProfile.ChargingSchedule.ChargingRateUnit);
  3280. DEBUG_INFO("Profile charging min rate: %f\n", txProfile.ChargingSchedule.MinChargingRate);
  3281. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(txProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  3282. {
  3283. if(txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod >= 0)
  3284. {
  3285. DEBUG_INFO("Period-%02d startPeriod: %d\n", idxPeriod, txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod);
  3286. DEBUG_INFO("Period-%02d limit: %f\n", idxPeriod, txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit);
  3287. DEBUG_INFO("Period-%02d NumberPhases: %d\n", idxPeriod, txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases);
  3288. }
  3289. }*/
  3290. }
  3291. if(defaultTxProfile.ChargingProfileId != -1)
  3292. {
  3293. if(strstr((char*)defaultTxProfile.ChargingProfileKind, "Absolute") != NULL)
  3294. {
  3295. if(defaultTxProfile.ChargingSchedule.Duration != -1)
  3296. {
  3297. defaultTxProfile.ChargingSchedule.Duration = ((defaultTxProfile.ChargingSchedule.Duration-getStartStop(defaultTxProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule))<0?
  3298. 0:
  3299. (defaultTxProfile.ChargingSchedule.Duration-getStartStop(defaultTxProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule)));
  3300. }
  3301. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  3302. {
  3303. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  3304. {
  3305. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = ((defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartStop(defaultTxProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule))<0?
  3306. 0:
  3307. (defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartStop(defaultTxProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule)));
  3308. if(idxPeriod > 0)
  3309. {
  3310. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
  3311. {
  3312. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit = defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit;
  3313. }
  3314. }
  3315. }
  3316. }
  3317. }
  3318. else if(strstr((char*)defaultTxProfile.ChargingProfileKind, "Relative") != NULL)
  3319. {
  3320. if(defaultTxProfile.ChargingSchedule.Duration != -1)
  3321. {
  3322. 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?
  3323. 0:
  3324. (defaultTxProfile.ChargingSchedule.Duration-getStartStop(ShmOCPP16Data->StartTransaction[(connectorId==0?0:connectorId-1)].Timestamp, compositeProfile.ChargingSchedule.StartSchedule)));
  3325. }
  3326. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  3327. {
  3328. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  3329. {
  3330. 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?
  3331. 0:
  3332. (defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartStop(ShmOCPP16Data->StartTransaction[(connectorId==0?0:connectorId-1)].Timestamp, compositeProfile.ChargingSchedule.StartSchedule)));
  3333. if(idxPeriod > 0)
  3334. {
  3335. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
  3336. {
  3337. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit = defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit;
  3338. }
  3339. }
  3340. }
  3341. }
  3342. }
  3343. else
  3344. {
  3345. if(strstr((char*)defaultTxProfile.RecurrencyKind, "Weekly") != NULL)
  3346. {
  3347. if(defaultTxProfile.ChargingSchedule.Duration != -1)
  3348. {
  3349. defaultTxProfile.ChargingSchedule.Duration = ((defaultTxProfile.ChargingSchedule.Duration-getStartSinceRecurring(defaultTxProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule, FALSE))<0?
  3350. 0:
  3351. (defaultTxProfile.ChargingSchedule.Duration-getStartSinceRecurring(defaultTxProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule, FALSE)));
  3352. }
  3353. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  3354. {
  3355. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  3356. {
  3357. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = ((defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceRecurring(defaultTxProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule, FALSE))<0?
  3358. 0:
  3359. (defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceRecurring(defaultTxProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule, FALSE)));
  3360. if(idxPeriod > 0)
  3361. {
  3362. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
  3363. {
  3364. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit = defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit;
  3365. }
  3366. }
  3367. }
  3368. }
  3369. }
  3370. else
  3371. {
  3372. if(defaultTxProfile.ChargingSchedule.Duration != -1)
  3373. {
  3374. defaultTxProfile.ChargingSchedule.Duration = ((defaultTxProfile.ChargingSchedule.Duration-getStartSinceRecurring(defaultTxProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule, TRUE))<0?
  3375. 0:
  3376. (defaultTxProfile.ChargingSchedule.Duration-getStartSinceRecurring(defaultTxProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule, TRUE)));
  3377. }
  3378. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  3379. {
  3380. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  3381. {
  3382. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = ((defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceRecurring(defaultTxProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule, TRUE))<0?
  3383. 0:
  3384. (defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceRecurring(defaultTxProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule, TRUE)));
  3385. if(idxPeriod > 0)
  3386. {
  3387. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
  3388. {
  3389. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit = defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit;
  3390. }
  3391. }
  3392. }
  3393. }
  3394. }
  3395. }
  3396. /*
  3397. DEBUG_INFO("defaultTxProfile after align.\n");
  3398. DEBUG_INFO("Profile ID: %d\n", defaultTxProfile.ChargingProfileId);
  3399. DEBUG_INFO("Profile stackLevel: %d\n", defaultTxProfile.StackLevel);
  3400. DEBUG_INFO("Profile TransactionId: %d\n", defaultTxProfile.TransactionId);
  3401. DEBUG_INFO("Profile valid from: %s\n", defaultTxProfile.ValidFrom);
  3402. DEBUG_INFO("Profile valid to: %s\n", defaultTxProfile.ValidTo);
  3403. DEBUG_INFO("Profile ChargingProfileKind: %s\n", defaultTxProfile.ChargingProfileKind);
  3404. DEBUG_INFO("Profile recurrencyKind: %s\n", defaultTxProfile.RecurrencyKind);
  3405. DEBUG_INFO("Profile start schedule: %s\n", compositeProfile.ChargingSchedule.StartSchedule);
  3406. DEBUG_INFO("Profile schedule duration: %d\n", defaultTxProfile.ChargingSchedule.Duration);
  3407. DEBUG_INFO("Profile charging rate unit: %s\n", defaultTxProfile.ChargingSchedule.ChargingRateUnit);
  3408. DEBUG_INFO("Profile charging min rate: %f\n", defaultTxProfile.ChargingSchedule.MinChargingRate);
  3409. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  3410. {
  3411. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod >= 0)
  3412. {
  3413. DEBUG_INFO("Period-%02d startPeriod: %d\n", idxPeriod, defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod);
  3414. DEBUG_INFO("Period-%02d limit: %f\n", idxPeriod, defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit);
  3415. DEBUG_INFO("Period-%02d NumberPhases: %d\n", idxPeriod, defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases);
  3416. }
  3417. }
  3418. DEBUG_INFO("------------------------------------\n");*/
  3419. }
  3420. if(maxProfile.ChargingProfileId != -1)
  3421. {
  3422. if(strstr((char*)maxProfile.ChargingProfileKind, "Absolute") != NULL)
  3423. {
  3424. if(maxProfile.ChargingSchedule.Duration != -1)
  3425. {
  3426. maxProfile.ChargingSchedule.Duration = ((maxProfile.ChargingSchedule.Duration-getStartStop(maxProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule))<0?
  3427. 0:
  3428. (maxProfile.ChargingSchedule.Duration-getStartStop(maxProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule)));
  3429. }
  3430. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  3431. {
  3432. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  3433. {
  3434. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = ((maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartStop(maxProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule))<0?
  3435. 0:
  3436. (maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartStop(maxProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule)));
  3437. if(idxPeriod > 0)
  3438. {
  3439. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
  3440. {
  3441. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit = maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit;
  3442. }
  3443. }
  3444. }
  3445. }
  3446. }
  3447. else if(strstr((char*)maxProfile.ChargingProfileKind, "Relative") != NULL)
  3448. {
  3449. if(maxProfile.ChargingSchedule.Duration != -1)
  3450. {
  3451. 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?
  3452. 0:
  3453. (maxProfile.ChargingSchedule.Duration-getStartStop(ShmOCPP16Data->StartTransaction[(connectorId==0?0:connectorId-1)].Timestamp, compositeProfile.ChargingSchedule.StartSchedule)));
  3454. }
  3455. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  3456. {
  3457. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  3458. {
  3459. 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?
  3460. 0:
  3461. (maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartStop(ShmOCPP16Data->StartTransaction[(connectorId==0?0:connectorId-1)].Timestamp, compositeProfile.ChargingSchedule.StartSchedule)));
  3462. if(idxPeriod > 0)
  3463. {
  3464. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
  3465. {
  3466. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit = maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit;
  3467. }
  3468. }
  3469. }
  3470. }
  3471. }
  3472. else
  3473. {
  3474. if(strstr((char*)maxProfile.RecurrencyKind, "Weekly") != NULL)
  3475. {
  3476. if(maxProfile.ChargingSchedule.Duration != -1)
  3477. {
  3478. maxProfile.ChargingSchedule.Duration = ((maxProfile.ChargingSchedule.Duration-getStartSinceRecurring(maxProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule, FALSE))<0?
  3479. 0:
  3480. (maxProfile.ChargingSchedule.Duration-getStartSinceRecurring(maxProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule, FALSE)));
  3481. }
  3482. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  3483. {
  3484. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  3485. {
  3486. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = ((maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceRecurring(maxProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule, FALSE))<0?
  3487. 0:
  3488. (maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceRecurring(maxProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule, FALSE)));
  3489. if(idxPeriod > 0)
  3490. {
  3491. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
  3492. {
  3493. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit = maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit;
  3494. }
  3495. }
  3496. }
  3497. }
  3498. }
  3499. else
  3500. {
  3501. if(maxProfile.ChargingSchedule.Duration != -1)
  3502. {
  3503. maxProfile.ChargingSchedule.Duration = ((maxProfile.ChargingSchedule.Duration-getStartSinceRecurring(maxProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule, TRUE))<0?
  3504. 0:
  3505. (maxProfile.ChargingSchedule.Duration-getStartSinceRecurring(maxProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule, TRUE)));
  3506. }
  3507. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  3508. {
  3509. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  3510. {
  3511. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = ((maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceRecurring(maxProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule, TRUE))<0?
  3512. 0:
  3513. (maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceRecurring(maxProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule, TRUE)));
  3514. if(idxPeriod > 0)
  3515. {
  3516. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
  3517. {
  3518. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit = maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit;
  3519. }
  3520. }
  3521. }
  3522. }
  3523. }
  3524. }
  3525. /*
  3526. DEBUG_INFO("MaxProfile after align.\n");
  3527. DEBUG_INFO("Profile ID: %d\n", maxProfile.ChargingProfileId);
  3528. DEBUG_INFO("Profile stackLevel: %d\n", maxProfile.StackLevel);
  3529. DEBUG_INFO("Profile TransactionId: %d\n", maxProfile.TransactionId);
  3530. DEBUG_INFO("Profile valid from: %s\n", maxProfile.ValidFrom);
  3531. DEBUG_INFO("Profile valid to: %s\n", maxProfile.ValidTo);
  3532. DEBUG_INFO("Profile ChargingProfileKind: %s\n", maxProfile.ChargingProfileKind);
  3533. DEBUG_INFO("Profile recurrencyKind: %s\n", maxProfile.RecurrencyKind);
  3534. DEBUG_INFO("Profile start schedule: %s\n", compositeProfile.ChargingSchedule.StartSchedule);
  3535. DEBUG_INFO("Profile schedule duration: %d\n", maxProfile.ChargingSchedule.Duration);
  3536. DEBUG_INFO("Profile charging rate unit: %s\n", maxProfile.ChargingSchedule.ChargingRateUnit);
  3537. DEBUG_INFO("Profile charging min rate: %f\n", maxProfile.ChargingSchedule.MinChargingRate);
  3538. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  3539. {
  3540. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod >= 0)
  3541. {
  3542. DEBUG_INFO("Period-%02d startPeriod: %d\n", idxPeriod, maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod);
  3543. DEBUG_INFO("Period-%02d limit: %f\n", idxPeriod, maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit);
  3544. DEBUG_INFO("Period-%02d NumberPhases: %d\n", idxPeriod, maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases);
  3545. }
  3546. }
  3547. DEBUG_INFO("------------------------------------\n");*/
  3548. }
  3549. /*
  3550. * Merge to conposite schedule
  3551. */
  3552. //DEBUG_INFO("====================================\n");
  3553. // Find each profile period quantity
  3554. for(int idx=0;idx<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idx++)
  3555. {
  3556. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idx].Limit != -1)
  3557. limitMax = idx+1;
  3558. }
  3559. for(int idx=0;idx<ARRAY_SIZE(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod);idx++)
  3560. {
  3561. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idx].Limit != -1)
  3562. limitDef = idx+1;
  3563. }
  3564. for(int idx=0;idx<ARRAY_SIZE(txProfile.ChargingSchedule.ChargingSchedulePeriod);idx++)
  3565. {
  3566. if(txProfile.ChargingSchedule.ChargingSchedulePeriod[idx].Limit != -1)
  3567. limitTx = idx+1;
  3568. }
  3569. // TxProfile found, composite schedule based on it
  3570. if(txProfile.ChargingProfileId != -1)
  3571. {
  3572. compositeProfile.ChargingSchedule.Duration = txProfile.ChargingSchedule.Duration;
  3573. for(int idxTxPeriod=0;idxTxPeriod<limitTx;idxTxPeriod++)
  3574. {
  3575. if((txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod].Limit != -1) &&
  3576. (txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod].StartPeriod < durationReq) &&
  3577. (txProfile.ChargingSchedule.Duration > 0))
  3578. {
  3579. if(maxProfile.ChargingProfileId != -1)
  3580. {
  3581. for(int idxMaxPeriod=0;idxMaxPeriod<limitMax;idxMaxPeriod++)
  3582. {
  3583. if((txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod].StartPeriod >= maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].StartPeriod))
  3584. {
  3585. if((maxProfile.ChargingSchedule.Duration > 0))
  3586. {
  3587. tmpPeriod.StartPeriod = txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod].StartPeriod;
  3588. tmpPeriod.NumberPhases = txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod].NumberPhases;
  3589. tmpPeriod.Limit = (txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod].Limit>maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].Limit?maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].Limit:txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod].Limit);
  3590. }
  3591. else
  3592. {
  3593. tmpPeriod.StartPeriod = txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod].StartPeriod;
  3594. tmpPeriod.NumberPhases = txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod].NumberPhases;
  3595. tmpPeriod.Limit = txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod].Limit;
  3596. }
  3597. }
  3598. if(idxMaxPeriod == (limitMax-1))
  3599. {
  3600. if(tmpPeriod.Limit != compositeProfile.ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].Limit)
  3601. {
  3602. if(tmpPeriod.StartPeriod != compositeProfile.ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].StartPeriod)
  3603. {
  3604. memcpy(&compositeProfile.ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx], &tmpPeriod , sizeof(struct StructChargingSchedulePeriod));
  3605. compositePeriodIdx++;
  3606. }
  3607. else
  3608. {
  3609. memcpy(&compositeProfile.ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)], &tmpPeriod , sizeof(struct StructChargingSchedulePeriod));
  3610. }
  3611. }
  3612. }
  3613. }
  3614. }
  3615. else
  3616. {
  3617. if(txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod].StartPeriod != compositeProfile.ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].StartPeriod)
  3618. {
  3619. memcpy(&compositeProfile.ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx], &txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod],sizeof(struct StructChargingSchedulePeriod));
  3620. compositePeriodIdx++;
  3621. }
  3622. else
  3623. {
  3624. memcpy(&compositeProfile.ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)], &txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod],sizeof(struct StructChargingSchedulePeriod));
  3625. }
  3626. }
  3627. }
  3628. if(idxTxPeriod == (limitTx-1))
  3629. {
  3630. if(defaultTxProfile.ChargingProfileId != -1)
  3631. {
  3632. compositeProfile.ChargingSchedule.Duration = (defaultTxProfile.ChargingSchedule.Duration>compositeProfile.ChargingSchedule.Duration)?defaultTxProfile.ChargingSchedule.Duration:compositeProfile.ChargingSchedule.Duration;
  3633. for(int idxDefPeriod=0;idxDefPeriod<limitDef;idxDefPeriod++)
  3634. {
  3635. if((defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].StartPeriod >= (txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod].StartPeriod + (txProfile.ChargingSchedule.Duration-defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].StartPeriod))) &&
  3636. (defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].StartPeriod < durationReq) &&
  3637. (defaultTxProfile.ChargingSchedule.Duration>0))
  3638. {
  3639. if(maxProfile.ChargingProfileId != -1)
  3640. {
  3641. for(int idxMaxPeriod=0;idxMaxPeriod<limitMax;idxMaxPeriod++)
  3642. {
  3643. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].StartPeriod >= maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].StartPeriod)
  3644. {
  3645. if((maxProfile.ChargingSchedule.Duration > 0))
  3646. {
  3647. tmpPeriod.StartPeriod = defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].StartPeriod;
  3648. tmpPeriod.NumberPhases = defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].NumberPhases;
  3649. tmpPeriod.Limit = (defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].Limit>maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].Limit?maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].Limit:defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod].Limit);
  3650. }
  3651. else
  3652. {
  3653. tmpPeriod.StartPeriod = defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].StartPeriod;
  3654. tmpPeriod.NumberPhases = defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].NumberPhases;
  3655. tmpPeriod.Limit = defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].Limit;
  3656. }
  3657. if(tmpPeriod.Limit != compositeProfile.ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].Limit)
  3658. {
  3659. if(tmpPeriod.StartPeriod != compositeProfile.ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].StartPeriod)
  3660. {
  3661. memcpy(&compositeProfile.ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx], &tmpPeriod , sizeof(struct StructChargingSchedulePeriod));
  3662. compositePeriodIdx++;
  3663. }
  3664. else
  3665. {
  3666. memcpy(&compositeProfile.ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)], &tmpPeriod , sizeof(struct StructChargingSchedulePeriod));
  3667. }
  3668. }
  3669. // Delete duplicate period
  3670. if(compositePeriodIdx > 1)
  3671. {
  3672. if(compositeProfile.ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx-1].Limit == compositeProfile.ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx-2].Limit)
  3673. {
  3674. compositeProfile.ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx-1].StartPeriod = -1;
  3675. compositeProfile.ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx-1].Limit = -1;
  3676. compositePeriodIdx -= 1;
  3677. }
  3678. }
  3679. }
  3680. else
  3681. {
  3682. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].StartPeriod != compositeProfile.ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].StartPeriod)
  3683. {
  3684. memcpy(&compositeProfile.ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx], &defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod],sizeof(struct StructChargingSchedulePeriod));
  3685. compositePeriodIdx++;
  3686. }
  3687. else
  3688. {
  3689. memcpy(&compositeProfile.ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)], &defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod],sizeof(struct StructChargingSchedulePeriod));
  3690. }
  3691. break;
  3692. }
  3693. }
  3694. }
  3695. else
  3696. {
  3697. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].StartPeriod != compositeProfile.ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].StartPeriod)
  3698. {
  3699. memcpy(&compositeProfile.ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx], &defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod],sizeof(struct StructChargingSchedulePeriod));
  3700. compositePeriodIdx++;
  3701. }
  3702. else
  3703. {
  3704. memcpy(&compositeProfile.ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)], &defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod],sizeof(struct StructChargingSchedulePeriod));
  3705. }
  3706. }
  3707. }
  3708. }
  3709. }
  3710. }
  3711. }
  3712. }
  3713. // TxProfile not found but defaultTxProfile found, composite schedule based on it
  3714. else if(defaultTxProfile.ChargingProfileId != -1)
  3715. {
  3716. compositeProfile.ChargingSchedule.Duration = defaultTxProfile.ChargingSchedule.Duration;
  3717. for(int idxDefPeriod=0;idxDefPeriod<limitDef;idxDefPeriod++)
  3718. {
  3719. if((defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].Limit != -1) &&
  3720. (defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].StartPeriod < durationReq) &&
  3721. (defaultTxProfile.ChargingSchedule.Duration > 0))
  3722. {
  3723. if(maxProfile.ChargingProfileId != -1)
  3724. {
  3725. for(int idxMaxPeriod=0;idxMaxPeriod<limitMax;idxMaxPeriod++)
  3726. {
  3727. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].StartPeriod >= maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].StartPeriod)
  3728. {
  3729. tmpPeriod.StartPeriod = defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].StartPeriod;
  3730. tmpPeriod.NumberPhases = defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].NumberPhases;
  3731. if((maxProfile.ChargingSchedule.Duration > 0))
  3732. {
  3733. tmpPeriod.Limit = (defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].Limit>maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].Limit?maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].Limit:defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].Limit);
  3734. }
  3735. else
  3736. {
  3737. tmpPeriod.Limit = defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].Limit;
  3738. }
  3739. if(tmpPeriod.Limit != compositeProfile.ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].Limit)
  3740. {
  3741. if(tmpPeriod.StartPeriod != compositeProfile.ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].StartPeriod)
  3742. {
  3743. memcpy(&compositeProfile.ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx], &tmpPeriod , sizeof(struct StructChargingSchedulePeriod));
  3744. compositePeriodIdx++;
  3745. }
  3746. else
  3747. {
  3748. memcpy(&compositeProfile.ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)], &tmpPeriod , sizeof(struct StructChargingSchedulePeriod));
  3749. }
  3750. }
  3751. // Delete duplicate period
  3752. if(compositePeriodIdx > 1)
  3753. {
  3754. if(compositeProfile.ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx-1].Limit == compositeProfile.ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx-2].Limit)
  3755. {
  3756. compositeProfile.ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx-1].StartPeriod = -1;
  3757. compositeProfile.ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx-1].Limit = -1;
  3758. compositePeriodIdx -= 1;
  3759. }
  3760. }
  3761. }
  3762. else
  3763. {
  3764. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].StartPeriod != compositeProfile.ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].StartPeriod)
  3765. {
  3766. memcpy(&compositeProfile.ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx], &defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod],sizeof(struct StructChargingSchedulePeriod));
  3767. compositePeriodIdx++;
  3768. }
  3769. else
  3770. {
  3771. memcpy(&compositeProfile.ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)], &defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod],sizeof(struct StructChargingSchedulePeriod));
  3772. }
  3773. break;
  3774. }
  3775. }
  3776. }
  3777. else
  3778. {
  3779. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].StartPeriod != compositeProfile.ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].StartPeriod)
  3780. {
  3781. memcpy(&compositeProfile.ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx], &defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod],sizeof(struct StructChargingSchedulePeriod));
  3782. compositePeriodIdx++;
  3783. }
  3784. else
  3785. {
  3786. memcpy(&compositeProfile.ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)], &defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod],sizeof(struct StructChargingSchedulePeriod));
  3787. }
  3788. }
  3789. }
  3790. }
  3791. }
  3792. // Fill other period by MaxProfile
  3793. if(maxProfile.ChargingProfileId != -1)
  3794. {
  3795. if(compositePeriodIdx==0)
  3796. {
  3797. compositeProfile.ChargingSchedule.Duration = maxProfile.ChargingSchedule.Duration;
  3798. for(int idxMaxPeriod=0;idxMaxPeriod<limitDef;idxMaxPeriod++)
  3799. {
  3800. if((maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].Limit != -1) &&
  3801. (maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].StartPeriod < durationReq) &&
  3802. (maxProfile.ChargingSchedule.Duration > 0))
  3803. {
  3804. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].StartPeriod != compositeProfile.ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].StartPeriod)
  3805. {
  3806. memcpy(&compositeProfile.ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx], &maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod],sizeof(struct StructChargingSchedulePeriod));
  3807. compositePeriodIdx++;
  3808. }
  3809. else
  3810. {
  3811. memcpy(&compositeProfile.ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)], &maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod],sizeof(struct StructChargingSchedulePeriod));
  3812. }
  3813. }
  3814. }
  3815. }
  3816. else
  3817. {
  3818. int lastCompositePeriodIdx = compositePeriodIdx;
  3819. for(int idxMaxPeriod=0;idxMaxPeriod<limitMax;idxMaxPeriod++)
  3820. {
  3821. if((maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].Limit != -1) &&
  3822. (maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].StartPeriod < durationReq) &&
  3823. (maxProfile.ChargingSchedule.Duration > 0))
  3824. {
  3825. if((maxProfile.ChargingSchedule.Duration >= compositeProfile.ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx-1].StartPeriod))
  3826. {
  3827. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].Limit > compositeProfile.ChargingSchedule.ChargingSchedulePeriod[lastCompositePeriodIdx-1].Limit)
  3828. {
  3829. tmpPeriod.StartPeriod = maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].StartPeriod;
  3830. tmpPeriod.NumberPhases = maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].NumberPhases;
  3831. tmpPeriod.Limit = compositeProfile.ChargingSchedule.ChargingSchedulePeriod[lastCompositePeriodIdx-1].Limit;
  3832. }
  3833. else
  3834. {
  3835. tmpPeriod.StartPeriod = maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].StartPeriod;
  3836. tmpPeriod.NumberPhases = maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].NumberPhases;
  3837. tmpPeriod.Limit = maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].Limit;
  3838. }
  3839. }
  3840. if(tmpPeriod.Limit != -1)
  3841. {
  3842. if(tmpPeriod.Limit != compositeProfile.ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx-1].Limit)
  3843. {
  3844. if(tmpPeriod.StartPeriod != compositeProfile.ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx-1].StartPeriod)
  3845. {
  3846. memcpy(&compositeProfile.ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx], &tmpPeriod , sizeof(struct StructChargingSchedulePeriod));
  3847. compositePeriodIdx++;
  3848. }
  3849. else
  3850. {
  3851. memcpy(&compositeProfile.ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx-1], &tmpPeriod , sizeof(struct StructChargingSchedulePeriod));
  3852. }
  3853. }
  3854. // Delete duplicate period
  3855. if(compositePeriodIdx > 1)
  3856. {
  3857. if(compositeProfile.ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx-1].Limit == compositeProfile.ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx-2].Limit)
  3858. {
  3859. compositeProfile.ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx-1].StartPeriod = -1;
  3860. compositeProfile.ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx-1].Limit = -1;
  3861. compositePeriodIdx -= 1;
  3862. }
  3863. }
  3864. }
  3865. }
  3866. }
  3867. }
  3868. }
  3869. compositeProfile.ChargingSchedule.Duration = durationReq;
  3870. DEBUG_INFO("Connector-%d composite schedule ready.\n", connectorId);
  3871. DEBUG_INFO("Schedule start: %s\n", compositeProfile.ChargingSchedule.StartSchedule);
  3872. DEBUG_INFO("Schedule duration: %d\n", compositeProfile.ChargingSchedule.Duration);
  3873. DEBUG_INFO("Rate unit: %s\n", compositeProfile.ChargingSchedule.ChargingRateUnit);
  3874. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(compositeProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  3875. {
  3876. if(compositeProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod >= 0)
  3877. {
  3878. compositeProfile.ChargingProfileId = 1;
  3879. DEBUG_INFO("Period-%02d startPeriod: %d\n", idxPeriod, compositeProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod);
  3880. DEBUG_INFO("Period-%02d limit: %f\n", idxPeriod, compositeProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit);
  3881. DEBUG_INFO("Period-%02d NumberPhases: %d\n", idxPeriod, compositeProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases);
  3882. }
  3883. if(compositeProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit == -1)
  3884. compositeProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit =0;
  3885. if(compositeProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod == -1)
  3886. compositeProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod =0;
  3887. }
  3888. memcpy(targetCompositeProfile, &compositeProfile, sizeof(struct StructChargingProfile));
  3889. if(line)
  3890. free(line);
  3891. checkChargePointMaxProfile(durationReq, &ShmOCPP16Data->MaxChargingProfile, isUnitA);
  3892. ShmOCPP16Data->CSUMsg.bits[(connectorId==0?0:connectorId-1)].ChargingProfileConf = 1;
  3893. }
  3894. //==========================================
  3895. // Init all share memory
  3896. //==========================================
  3897. int InitShareMemory()
  3898. {
  3899. int result = PASS;
  3900. int MeterSMId;
  3901. //creat ShmSysConfigAndInfo
  3902. if ((MeterSMId = shmget(ShmSysConfigAndInfoKey, sizeof(struct SysConfigAndInfo), 0777)) < 0)
  3903. {
  3904. DEBUG_ERROR("shmget ShmSysConfigAndInfo NG\n");
  3905. result = FAIL;
  3906. }
  3907. else if ((ShmSysConfigAndInfo = shmat(MeterSMId, NULL, 0)) == (void *) -1)
  3908. {
  3909. DEBUG_ERROR("shmat ShmSysConfigAndInfo NG\n");
  3910. result = FAIL;
  3911. }
  3912. else
  3913. {}
  3914. if ((MeterSMId = shmget(ShmStatusCodeKey, sizeof(struct StatusCodeData), 0777)) < 0)
  3915. {
  3916. DEBUG_ERROR("shmget ShmStatusCodeData NG\n");
  3917. result = FAIL;
  3918. }
  3919. else if ((ShmStatusCodeData = shmat(MeterSMId, NULL, 0)) == (void *) -1)
  3920. {
  3921. DEBUG_ERROR("shmat ShmStatusCodeData NG\n");
  3922. result = FAIL;
  3923. }
  3924. else
  3925. {}
  3926. //creat ShmPsuData
  3927. if ((MeterSMId = shmget(ShmPsuKey, sizeof(struct PsuData), 0777)) < 0)
  3928. {
  3929. DEBUG_ERROR("shmget ShmPsuData NG\n");
  3930. result = FAIL;
  3931. }
  3932. else if ((ShmPsuData = shmat(MeterSMId, NULL, 0)) == (void *) -1)
  3933. {
  3934. DEBUG_ERROR("shmat ShmPsuData NG\n");
  3935. result = FAIL;
  3936. }
  3937. else
  3938. {}
  3939. //creat ShmOCPP16Data
  3940. if ((MeterSMId = shmget(ShmOcppModuleKey, sizeof(struct OCPP16Data), 0777)) < 0)
  3941. {
  3942. DEBUG_ERROR("shmget ShmOCPP16Data NG\n");
  3943. result = FAIL;
  3944. }
  3945. else if ((ShmOCPP16Data = shmat(MeterSMId, NULL, 0)) == (void *) -1)
  3946. {
  3947. DEBUG_ERROR("shmat ShmOCPP16Data NG\n");
  3948. result = FAIL;
  3949. }
  3950. else
  3951. {}
  3952. /****************************** For Initial Settings************************************************/
  3953. ShmOCPP16Data->GetConfiguration.ResponseUnknownKey = NULL;
  3954. ShmOCPP16Data->SendLocalList.LocalAuthorizationList = NULL;
  3955. // allocate Configuration memory address
  3956. ShmOCPP16Data->GetConfiguration.Key = staticKeyArray;
  3957. ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey = staticResponseConfigurationKeyArray;
  3958. ShmOCPP16Data->GetConfiguration.ResponseUnknownKey = staticResponseUnknownKey;
  3959. ShmOCPP16Data->SendLocalList.LocalAuthorizationList = staticLocalAuthorizationList;
  3960. sprintf((char*)ShmOCPP16Data->FirmwareStatusNotification.Status, "%s",FirmwareStatusStr[FirmwareStatus_Idle]);
  3961. //offline MeterValue Interval
  3962. TempMeterValueInterval = 0;
  3963. return result;
  3964. }
  3965. int ProcessShareMemory()
  3966. {
  3967. int result = PASS;
  3968. if(InitShareMemory() == FAIL)
  3969. {
  3970. DEBUG_ERROR("InitShareMemory NG\n");
  3971. if(ShmStatusCodeData!=NULL)
  3972. {
  3973. ShmStatusCodeData->AlarmCode.AlarmEvents.bits.FailToCreateShareMemory=1;
  3974. }
  3975. result = FAIL;
  3976. }
  3977. // Model name parsing
  3978. if(RatedCurrentParsing((char*)ShmSysConfigAndInfo->SysConfig.ModelName, &modelnameInfo) != -1)
  3979. {
  3980. DEBUG_INFO("Model name rated power: %d\n", modelnameInfo.ratedPower);
  3981. if((ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D') &&
  3982. ((ShmSysConfigAndInfo->SysConfig.ModelName[1]=='B') ||
  3983. (ShmSysConfigAndInfo->SysConfig.ModelName[1]=='K') ||
  3984. (ShmSysConfigAndInfo->SysConfig.ModelName[1]=='O'))
  3985. ) // 'D' means DC
  3986. {
  3987. // DO series
  3988. for(int gun_index=0; gun_index<GENERAL_GUN_QUANTITY ; gun_index++)
  3989. {
  3990. gunTotalNumber += 1;
  3991. gunType[gun_index] = GUN_TYPE_DO;
  3992. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  3993. {
  3994. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == gun_index)
  3995. {
  3996. periousPeriodicPowerConsumption[gun_index] = ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PowerConsumption;
  3997. periousClockPowerConsumption[gun_index] = ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PowerConsumption;
  3998. DEBUG_INFO("Gun-%02d PowerConsumption: %.3f\n", gun_index, ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PowerConsumption);
  3999. }
  4000. }
  4001. switch(modelnameInfo.ParsingInfo[gun_index].GunType)
  4002. {
  4003. case Gun_Type_Chademo:
  4004. DEBUG_INFO("Gun-%02d type: Cabinet CHAdeMO\n", gun_index);
  4005. break;
  4006. case Gun_Type_CCS_2:
  4007. DEBUG_INFO("Gun-%02d type: Cabinet CCS\n", gun_index);
  4008. break;
  4009. case Gun_Type_GB:
  4010. DEBUG_INFO("Gun-%02d type: Cabinet GBT\n", gun_index);
  4011. break;
  4012. case Gun_Type_AC:
  4013. DEBUG_INFO("Gun-%02d type: Cabinet AC\n", gun_index);
  4014. break;
  4015. default:
  4016. DEBUG_WARN("Gun-%02d type: Cabinet unknown\n", gun_index);
  4017. break;
  4018. }
  4019. }
  4020. }
  4021. else
  4022. {
  4023. for(int gun_index=0;gun_index<modelnameInfo.GetGunCount;gun_index++)
  4024. {
  4025. gunTotalNumber += 1;
  4026. switch(modelnameInfo.ParsingInfo[gun_index].GunType)
  4027. {
  4028. case Gun_Type_Chademo:
  4029. gunType[gun_index] = GUN_TYPE_CHAdeMO;
  4030. DEBUG_INFO("Gun-%02d type: CHAdeMO\n", gun_index);
  4031. for(int index = 0; index < CHAdeMO_QUANTITY; index++)
  4032. {
  4033. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == gun_index)
  4034. {
  4035. periousPeriodicPowerConsumption[gun_index] = ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PowerConsumption;
  4036. periousClockPowerConsumption[gun_index] = ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PowerConsumption;
  4037. DEBUG_INFO("Gun-%02d PowerConsumption: %.3f\n", gun_index, ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PowerConsumption);
  4038. }
  4039. }
  4040. break;
  4041. case Gun_Type_CCS_2:
  4042. gunType[gun_index] = GUN_TYPE_CCS;
  4043. DEBUG_INFO("Gun-%02d type: CCS\n", gun_index);
  4044. for (int index = 0; index < CCS_QUANTITY; index++)
  4045. {
  4046. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == gun_index)
  4047. {
  4048. periousPeriodicPowerConsumption[gun_index] = ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PowerConsumption;
  4049. periousClockPowerConsumption[gun_index] = ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PowerConsumption;
  4050. DEBUG_INFO("Gun-%02d PowerConsumption: %.3f\n", gun_index, ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PowerConsumption);
  4051. }
  4052. }
  4053. break;
  4054. case Gun_Type_GB:
  4055. gunType[gun_index] = GUN_TYPE_GBT;
  4056. DEBUG_INFO("Gun-%02d type: GBT\n", gun_index);
  4057. for (int index = 0; index < GB_QUANTITY; index++)
  4058. {
  4059. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == gun_index)
  4060. {
  4061. periousPeriodicPowerConsumption[gun_index] = ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PowerConsumption;
  4062. periousClockPowerConsumption[gun_index] = ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PowerConsumption;
  4063. DEBUG_INFO("Gun-%02d PowerConsumption: %.3f\n", gun_index, ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PowerConsumption);
  4064. }
  4065. }
  4066. break;
  4067. case Gun_Type_AC:
  4068. gunType[gun_index] = GUN_TYPE_AC;
  4069. DEBUG_INFO("Gun-%02d type: AC\n", gun_index);
  4070. for (int index = 0; index < AC_QUANTITY; index++)
  4071. {
  4072. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == gun_index)
  4073. {
  4074. periousPeriodicPowerConsumption[gun_index] = ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PowerConsumption;
  4075. periousClockPowerConsumption[gun_index] = ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PowerConsumption;
  4076. DEBUG_INFO("Gun-%02d PowerConsumption: %.3f\n", gun_index, ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PowerConsumption);
  4077. }
  4078. }
  4079. break;
  4080. default:
  4081. DEBUG_WARN("Gun-%02d type: Unknown\n", gun_index);
  4082. break;
  4083. }
  4084. }
  4085. }
  4086. }
  4087. else
  4088. {
  4089. DEBUG_ERROR("Model name parsing fail.\n");
  4090. result = FAIL;
  4091. }
  4092. if(result != PASS)sleep(5);
  4093. return result;
  4094. }
  4095. void checkRemoteStart(uint8_t connectorIdInt)
  4096. {
  4097. uint8_t tempIndex;
  4098. int result = PASS;
  4099. char cmdBuf[512];
  4100. //check Transaction active
  4101. if(gunType[connectorIdInt -1] == GUN_TYPE_CHAdeMO)
  4102. {
  4103. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4104. {
  4105. tempIndex = ((connectorIdInt -1) == 2) ? 1: 0;
  4106. }
  4107. else
  4108. {
  4109. tempIndex = connectorIdInt -1;
  4110. }
  4111. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  4112. {
  4113. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  4114. {
  4115. if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ReservationId != -1) &&
  4116. (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ReservationId >= 0) &&
  4117. (strcmp((const char *)ShmOCPP16Data->ReserveNow[index].IdTag, (char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag) == 0))
  4118. {
  4119. //Reserved
  4120. DEBUG_INFO("CHAdeMO connector already reserved and idTag match.\n");
  4121. }
  4122. else if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ReservationId != -1) &&
  4123. (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ReservationId >= 0) &&
  4124. (strcmp((const char *)ShmOCPP16Data->ReserveNow[index].IdTag, (char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag) != 0))
  4125. {
  4126. //Reserved
  4127. DEBUG_INFO("CHAdeMO connector already reserved and idTag does not match.\n");
  4128. result = FAIL;
  4129. goto end;
  4130. }
  4131. else
  4132. {
  4133. if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  4134. && (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_PREPARING ) //S_PRECHARGE
  4135. && (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EV ) //S_PREPARING_FOR_EV
  4136. && (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EVSE )) // S_PREPARING_FOR_EVSE
  4137. {
  4138. DEBUG_WARN("CHAdeMO connector not allow start cause busy.\n");
  4139. result = FAIL;
  4140. goto end;
  4141. }
  4142. }//END FOR ELSE
  4143. }
  4144. }// END FOR CHAdeMO_QUANTITY
  4145. }
  4146. else if(gunType[connectorIdInt -1] == GUN_TYPE_CCS)
  4147. {
  4148. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4149. {
  4150. tempIndex = ((connectorIdInt -1) == 2) ? 1: 0;
  4151. }
  4152. else
  4153. {
  4154. tempIndex = connectorIdInt -1;
  4155. }
  4156. for (int index = 0; index < CCS_QUANTITY; index++)
  4157. {
  4158. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  4159. {
  4160. if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ReservationId != -1) &&
  4161. (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ReservationId >= 0) &&
  4162. (strcmp((const char *)ShmOCPP16Data->ReserveNow[index].IdTag, (char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag) == 0))
  4163. {
  4164. //Reserved
  4165. DEBUG_INFO("CCS connector already reserved and idTag match.\n");
  4166. }
  4167. else if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ReservationId != -1) &&
  4168. (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ReservationId >= 0) &&
  4169. (strcmp((const char *)ShmOCPP16Data->ReserveNow[index].IdTag, (char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag) != 0))
  4170. {
  4171. //Reserved
  4172. DEBUG_INFO("CCS connector already reserved and idTag does not match.\n");
  4173. result = FAIL;
  4174. goto end;
  4175. }
  4176. else
  4177. {
  4178. if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  4179. && (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_PREPARING) //S_PRECHARGE
  4180. && (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EV) //S_PREPARING_FOR_EV
  4181. && (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EVSE)) // S_PREPARING_FOR_EVSE
  4182. {
  4183. DEBUG_WARN("CCS connector not allow start cause busy.\n.");
  4184. result = FAIL;
  4185. goto end;
  4186. }
  4187. }// END FOR ELSE
  4188. }
  4189. }// END FOR CCS_QUANTITY
  4190. }
  4191. else if(gunType[connectorIdInt -1] == GUN_TYPE_GBT)
  4192. {
  4193. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4194. {
  4195. tempIndex = ((connectorIdInt -1) == 2) ? 1: 0;
  4196. }
  4197. else
  4198. {
  4199. tempIndex = connectorIdInt -1;
  4200. }
  4201. for (int index = 0; index < GB_QUANTITY; index++)
  4202. {
  4203. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex )
  4204. {
  4205. if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ReservationId != -1) &&
  4206. (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ReservationId >= 0) &&
  4207. (strcmp((const char *)ShmOCPP16Data->ReserveNow[index].IdTag, (char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag) == 0))
  4208. {
  4209. //Reserved
  4210. DEBUG_INFO("GBT connector already reserved and idTag match.\n");
  4211. }
  4212. else if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ReservationId != -1) &&
  4213. (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ReservationId >= 0) &&
  4214. (strcmp((const char *)ShmOCPP16Data->ReserveNow[index].IdTag, (char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag) != 0))
  4215. {
  4216. //Reserved
  4217. DEBUG_INFO("GBT connector already reserved and idTag does not match.\n");
  4218. result = FAIL;
  4219. goto end;
  4220. }
  4221. else
  4222. {
  4223. if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  4224. && (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_PREPARING) //S_PRECHARGE
  4225. && (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EV) //S_PREPARING_FOR_EV
  4226. && (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EVSE)) // S_PREPARING_FOR_EVSE
  4227. {
  4228. DEBUG_WARN("GBT connector not allow start cause busy.\n");
  4229. result = FAIL;
  4230. goto end;
  4231. }
  4232. }// END FOR ELSE
  4233. }
  4234. } // END FOR GB_QUANTITY
  4235. }
  4236. else if(gunType[connectorIdInt -1] == GUN_TYPE_DO)
  4237. {
  4238. tempIndex = connectorIdInt -1;
  4239. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  4240. {
  4241. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex )
  4242. {
  4243. if((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.ReservationId != -1) &&
  4244. (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.ReservationId >= 0) &&
  4245. (strcmp((const char *)ShmOCPP16Data->ReserveNow[index].IdTag, (char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag) == 0))
  4246. {
  4247. //Reserved
  4248. DEBUG_INFO("Dispenser connector already reserved and idTag match.\n");
  4249. }
  4250. else if((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.ReservationId != -1) &&
  4251. (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.ReservationId >= 0) &&
  4252. (strcmp((const char *)ShmOCPP16Data->ReserveNow[index].IdTag, (char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag) != 0))
  4253. {
  4254. //Reserved
  4255. DEBUG_INFO("Dispenser connector already reserved and idTag does not match.\n");
  4256. result = FAIL;
  4257. goto end;
  4258. }
  4259. else
  4260. {
  4261. if((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus != SYS_MODE_IDLE) //S_IDLE
  4262. && (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus != SYS_MODE_PREPARING) //S_PRECHARGE
  4263. && (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus != SYS_MODE_PREPARE_FOR_EV) //S_PREPARING_FOR_EV
  4264. && (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus != SYS_MODE_PREPARE_FOR_EVSE)) // S_PREPARING_FOR_EVSE
  4265. {
  4266. DEBUG_WARN("Dispenser connector not allow start cause busy.\n");
  4267. result = FAIL;
  4268. goto end;
  4269. }
  4270. }// END FOR ELSE
  4271. }
  4272. } // END FOR GB_QUANTITY
  4273. }
  4274. else
  4275. {
  4276. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D') // 'D' means DC
  4277. {
  4278. tempIndex = 2;
  4279. }
  4280. else
  4281. {
  4282. tempIndex = connectorIdInt -1;
  4283. }
  4284. for (int index = 0; index < AC_QUANTITY; index++)
  4285. {
  4286. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex )
  4287. {
  4288. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].ReservationId != -1) &&
  4289. (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].ReservationId >= 0) &&
  4290. (strcmp((const char *)ShmOCPP16Data->ReserveNow[index].IdTag, (char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag) == 0))
  4291. {
  4292. //Reserved
  4293. DEBUG_INFO("AC connector already reserved and idTag match.\n");
  4294. }
  4295. else if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].ReservationId != -1) &&
  4296. (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].ReservationId >= 0) &&
  4297. (strcmp((const char *)ShmOCPP16Data->ReserveNow[index].IdTag, (char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag) != 0))
  4298. {
  4299. //Reserved
  4300. DEBUG_INFO("AC connector already reserved and idTag does not match.\n");
  4301. result = FAIL;
  4302. goto end;
  4303. }
  4304. else
  4305. {
  4306. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  4307. && (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_PREPARING) //S_PRECHARGE
  4308. && (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EV) //S_PREPARING_FOR_EV
  4309. && (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EVSE)) // S_PREPARING_FOR_EVSE
  4310. {
  4311. DEBUG_WARN("AC connector not allow start cause busy.\n");
  4312. result = FAIL;
  4313. goto end;
  4314. }
  4315. }//END FOR ELSE
  4316. }
  4317. }// END FOR AC_QUANTITY
  4318. }
  4319. if(ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingProfileId > -1)
  4320. {
  4321. if(strcmp((char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingProfilePurpose, ChargingProfilePurposeTypeStr[TxProfile]) == 0)
  4322. {
  4323. if((access("/Storage/OCPP/TxProfile_Tmp.json", F_OK))!=-1)
  4324. {
  4325. sprintf(cmdBuf, "mv /Storage/OCPP/TxProfile_Tmp.json /Storage/OCPP/TxProfile_%d.json", connectorIdInt);
  4326. system(cmdBuf);
  4327. }
  4328. }
  4329. else
  4330. {
  4331. DEBUG_WARN("Profile purpose not TxProfile.\n.");
  4332. result = FAIL;
  4333. }
  4334. }
  4335. end:
  4336. if(result == PASS)
  4337. {
  4338. ShmOCPP16Data->CsMsg.bits[connectorIdInt -1].RemoteStartTransactionReq = 1;
  4339. memset((char *)ShmOCPP16Data->StartTransaction[connectorIdInt -1].IdTag, 0, 20);
  4340. strcpy((char *)ShmOCPP16Data->StartTransaction[connectorIdInt -1].IdTag, (char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag);
  4341. memset((char *)ShmOCPP16Data->StopTransaction[connectorIdInt -1].IdTag, 0, 20);
  4342. strcpy((char *)ShmOCPP16Data->StopTransaction[connectorIdInt -1].IdTag, (char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag);
  4343. }
  4344. }
  4345. void CheckSystemValue(void)
  4346. {
  4347. char filenmae[100]={0};
  4348. char str[100]={0};
  4349. int tempIndex = 0;
  4350. //===============================
  4351. // send Heartbeat
  4352. //===============================
  4353. if((server_sign == TRUE) && (getDiffSecNow(clientTime.Heartbeat) >= (HeartBeatWaitTime + HeartBeatWithNOResponse)))
  4354. {
  4355. //parameter for test
  4356. sendHeartbeatRequest(0);
  4357. //===========================
  4358. // Reset Waiting Time
  4359. //===========================
  4360. HeartBeatWithNOResponse += 1;
  4361. }
  4362. //===============================
  4363. // Credit deduct report
  4364. //===============================
  4365. if(ShmOCPP16Data->TcciCustomData.ReportCreditDeductReq)
  4366. {
  4367. OCPP_insert_deduct_info(ShmOCPP16Data->TcciCustomData.DeductInfo.txId, (char*)ShmOCPP16Data->TcciCustomData.DeductInfo.creditNo,
  4368. ShmOCPP16Data->TcciCustomData.DeductInfo.deductResult, ShmOCPP16Data->TcciCustomData.DeductInfo.isDonateInvoice,
  4369. ShmOCPP16Data->TcciCustomData.DeductInfo.amount, (char*)ShmOCPP16Data->TcciCustomData.DeductInfo.vemData,
  4370. (char*)ShmOCPP16Data->TcciCustomData.DeductInfo.ROC,(char*)ShmOCPP16Data->TcciCustomData.DeductInfo.RRN,
  4371. (char*)ShmOCPP16Data->TcciCustomData.DeductInfo.approvalNo,(char*)ShmOCPP16Data->TcciCustomData.DeductInfo.storeId);
  4372. ShmOCPP16Data->TcciCustomData.ReportCreditDeductReq = FALSE;
  4373. }
  4374. if(getDiffSecNow(clientTime.TcciQueryDeduct) > 5)
  4375. {
  4376. OCPP_query_deduct_info();
  4377. refreshStartTimer(&clientTime.TcciQueryDeduct);
  4378. }
  4379. for(int gun_index=0;gun_index < gunTotalNumber;gun_index++)
  4380. {
  4381. // ClockAlign MeterValue
  4382. if((server_sign == TRUE) && ((atoi((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemData) > 0)?((getTimePassSinceToday(gun_index)%(atoi((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemData)))==0):FALSE))
  4383. {
  4384. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  4385. {
  4386. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4387. {
  4388. tempIndex = ((gun_index==2) ? 1: 0);
  4389. }
  4390. else
  4391. {
  4392. tempIndex = gun_index;
  4393. }
  4394. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  4395. {
  4396. // 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault
  4397. if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  4398. {
  4399. reqClockAlignMeter[gun_index] = 1;
  4400. }
  4401. }// End for CHAdeMO
  4402. }
  4403. else if(gunType[gun_index] == GUN_TYPE_CCS)
  4404. {
  4405. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4406. {
  4407. tempIndex = ((gun_index==2) ? 1: 0);
  4408. }
  4409. else
  4410. {
  4411. tempIndex = gun_index;
  4412. }
  4413. for (int index = 0; index < CCS_QUANTITY; index++)
  4414. {
  4415. // 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault
  4416. if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  4417. {
  4418. reqClockAlignMeter[gun_index] = 1;
  4419. }
  4420. } // End for CCS
  4421. }
  4422. else if(gunType[gun_index] == GUN_TYPE_GBT)
  4423. {
  4424. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4425. {
  4426. tempIndex = ((gun_index==2) ? 1: 0);
  4427. }
  4428. else
  4429. {
  4430. tempIndex = gun_index;
  4431. }
  4432. for (int index = 0; index < GB_QUANTITY; index++)
  4433. {
  4434. // 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault
  4435. if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  4436. {
  4437. reqClockAlignMeter[gun_index] = 1;
  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. reqClockAlignMeter[gun_index] = 1;
  4450. }
  4451. }
  4452. }
  4453. else
  4454. {
  4455. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  4456. {
  4457. tempIndex = 2;
  4458. }
  4459. else
  4460. {
  4461. tempIndex = gun_index;
  4462. }
  4463. for (int index = 0; index < AC_QUANTITY; index++)
  4464. {
  4465. // 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault
  4466. if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  4467. {
  4468. reqClockAlignMeter[gun_index] = 1;
  4469. }
  4470. }//End for AC
  4471. }
  4472. }
  4473. }
  4474. for(int gun_index=0;gun_index < gunTotalNumber ;gun_index++)
  4475. {
  4476. //==========================================
  4477. // Check remote start without connector id
  4478. //==========================================
  4479. if(ShmOCPP16Data->MsMsg.bits.isRemoteStartWaitReq)
  4480. {
  4481. int connectorIdInt = -1;
  4482. for(uint8_t gun_index=0;gun_index<gunTotalNumber;gun_index++)
  4483. {
  4484. if(!cpinitateMsg.bits[gun_index].isOnCharging && (strstr((char*)ShmOCPP16Data->StatusNotification[gun_index].Status, "Preparing") != NULL))
  4485. {
  4486. connectorIdInt = (gun_index+1);
  4487. DEBUG_INFO("Detect connector-%02d connected ready to start.\n", connectorIdInt);
  4488. checkRemoteStart(connectorIdInt);
  4489. ShmOCPP16Data->MsMsg.bits.isRemoteStartWaitReq = 0;
  4490. break;
  4491. }
  4492. }
  4493. if(getDiffSecNow(clientTime.RemoteStartWait) > atoi((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemData))
  4494. {
  4495. DEBUG_WARN("Remote start request without connector id wait link over %s seconds.\n", ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemData);
  4496. ShmOCPP16Data->MsMsg.bits.isRemoteStartWaitReq = 0;
  4497. }
  4498. }
  4499. //==========================================
  4500. // csu trigger DataTransferReq
  4501. //==========================================
  4502. if(isWebsocketSendable && (server_sign == TRUE) && (ShmOCPP16Data->CsMsg.bits[gun_index].DataTransferReq == 1))
  4503. {
  4504. sendDataTransferRequest(gun_index);
  4505. ShmOCPP16Data->CsMsg.bits[gun_index].DataTransferReq = 0;
  4506. }
  4507. //==========================================
  4508. // CSU Trigger Authorize Request
  4509. //==========================================
  4510. if(isWebsocketSendable && (server_sign == TRUE) && (ShmOCPP16Data->SpMsg.bits.AuthorizeReq == 1)&&(authorizeRetryTimes < 3))
  4511. {
  4512. sendAuthorizeRequest(0);
  4513. authorizeRetryTimes = authorizeRetryTimes + 1;
  4514. if(authorizeRetryTimes < 3)
  4515. ShmOCPP16Data->SpMsg.bits.AuthorizeReq = 0;
  4516. }
  4517. else if((server_sign == TRUE) && (ShmOCPP16Data->SpMsg.bits.AuthorizeReq == 1) && (authorizeRetryTimes >= 3))
  4518. {
  4519. authorizeRetryTimes = 0;
  4520. SetOcppConnStatus(FALSE);
  4521. server_sign = FALSE;
  4522. }
  4523. 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))
  4524. {
  4525. sendAuthorizeRequest(0);
  4526. }
  4527. //==========================================
  4528. // Charger start transaction
  4529. //==========================================
  4530. if(/*(server_sign == TRUE) &&*/ (ShmOCPP16Data->CpMsg.bits[gun_index].StartTransactionReq == 1))
  4531. {
  4532. ShmOCPP16Data->CpMsg.bits[gun_index].StartTransactionReq = 0;
  4533. sendStartTransactionRequest(gun_index);
  4534. refreshStartTimer(&clientTime.StartTransaction);
  4535. refreshStartTimer(&clientTime.MeterValues[gun_index]);
  4536. storeTempStopTransaction(gun_index);
  4537. }
  4538. //==========================================
  4539. // Charger stop transaction
  4540. //==========================================
  4541. if(/*(server_sign == TRUE) &&*/ ((ShmOCPP16Data->CpMsg.bits[gun_index].StopTransactionReq == 1)))
  4542. {
  4543. ShmOCPP16Data->CpMsg.bits[gun_index].StopTransactionReq = 0;
  4544. sendStopTransactionRequest(gun_index);
  4545. OCPP_updatePeriodEnergy(gun_index);
  4546. if(ShmSysConfigAndInfo->SysConfig.TTIA_Info.isEnableTTIA && (gunType[gun_index] != GUN_TYPE_AC) )sendTTIAInfo(gun_index);
  4547. refreshStartTimer(&clientTime.StopTransaction);
  4548. memset(&ShmOCPP16Data->SessionTarget[gun_index], 0x00, sizeof(struct StructSessionTarget));
  4549. }
  4550. //==========================================
  4551. // Charger OCMF message
  4552. //==========================================
  4553. if(/*(server_sign == TRUE) &&*/ ((ShmOCPP16Data->OcmfData[gun_index].SendOcmfDataReq == 1)))
  4554. {
  4555. sendOcmfByDataTransferRequest(gun_index);
  4556. ShmOCPP16Data->OcmfData[gun_index].SendOcmfDataReq = 0;
  4557. }
  4558. //==========================================
  4559. // Charger status report
  4560. //==========================================
  4561. //--- Check Mode Change ---//
  4562. // J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DCcc
  4563. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  4564. {
  4565. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4566. {
  4567. tempIndex = ((gun_index==2) ? 1: 0);
  4568. }
  4569. else
  4570. {
  4571. tempIndex = gun_index;
  4572. }
  4573. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  4574. {
  4575. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  4576. {
  4577. if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != ChademoPreviousSystemStatus[index]) || (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ConnectorPlugIn != ChademoPreviousConnectorPlugIn[index]) )
  4578. {
  4579. // Sent unplug message for California pricing logic
  4580. if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_COMPLETE) && (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ConnectorPlugIn == 0) && !interLock.isSentUnplug[gun_index])
  4581. {
  4582. uint8_t ts[36];
  4583. getNowDatetime(ts);
  4584. sprintf((char*)ShmOCPP16Data->DataTransfer[gun_index].VendorId, "org.openchargealliance.costmsg");
  4585. sprintf((char*)ShmOCPP16Data->DataTransfer[gun_index].MessageId, "ConnectorUnplugged");
  4586. if(strcmp((char*)dmsVersion, "2.0")==0)
  4587. sprintf((char*)ShmOCPP16Data->DataTransfer[gun_index].Data, "{\\\"transactionId\\\":%d,\\\"timestamp\\\":\\\"%s\\\"}", ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId, ts);
  4588. else
  4589. sprintf((char*)ShmOCPP16Data->DataTransfer[gun_index].Data, "{\\\"idTx\\\":%d,\\\"timestamp\\\":\\\"%s\\\"}", ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId, ts);
  4590. sendUnplugByDataTransferRequest(gun_index);
  4591. interLock.isSentUnplug[gun_index] = 1;
  4592. }
  4593. else if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_IDLE))
  4594. {
  4595. interLock.isSentUnplug[gun_index] = 0;
  4596. }
  4597. ChademoPreviousSystemStatus[index] = ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus;
  4598. ChademoPreviousConnectorPlugIn[index] = ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ConnectorPlugIn;
  4599. cpinitateMsg.bits[gun_index].StatusNotificationReq = 1;
  4600. if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex) && ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_COMPLETE) || (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus <= SYS_MODE_IDLE))) // complete
  4601. {
  4602. sprintf(filenmae,"/Storage/OCPP/TxProfile_%d.json",(gun_index+1));
  4603. if((access(filenmae,F_OK))!=-1)
  4604. {
  4605. DEBUG_INFO("TxProfile exist. OCPP will delete TX Charging Profile\n");
  4606. sprintf(str,"rm -f %s",filenmae);
  4607. system(str);
  4608. }
  4609. }
  4610. }
  4611. cpinitateMsg.bits[gun_index].isOnCharging = ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_TERMINATING)?1:0);
  4612. #if 1 // for TempStopTransaction
  4613. if(((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_BOOTING) || (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_IDLE)) &&
  4614. (ShmOCPP16Data->CpMsg.bits[gun_index].StopTransactionReq == 0))
  4615. {
  4616. checkTempStopTransaction(gun_index);
  4617. }
  4618. #endif
  4619. }
  4620. }
  4621. }
  4622. else if(gunType[gun_index] == GUN_TYPE_CCS)
  4623. {
  4624. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4625. {
  4626. tempIndex = ((gun_index==2) ? 1: 0);
  4627. }
  4628. else
  4629. {
  4630. tempIndex = gun_index;
  4631. }
  4632. for (int index = 0; index < CCS_QUANTITY; index++)
  4633. {
  4634. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  4635. {
  4636. if((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]*/ )
  4637. {
  4638. // Sent unplug message for California pricing logic
  4639. if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_COMPLETE) && (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ConnectorPlugIn == 0) && !interLock.isSentUnplug[gun_index])
  4640. {
  4641. uint8_t ts[36];
  4642. getNowDatetime(ts);
  4643. sprintf((char*)ShmOCPP16Data->DataTransfer[gun_index].VendorId, "org.openchargealliance.costmsg");
  4644. sprintf((char*)ShmOCPP16Data->DataTransfer[gun_index].MessageId, "ConnectorUnplugged");
  4645. if(strcmp((char*)dmsVersion, "2.0")==0)
  4646. sprintf((char*)ShmOCPP16Data->DataTransfer[gun_index].Data, "{\\\"transactionId\\\":%d,\\\"timestamp\\\":\\\"%s\\\"}", ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId, ts);
  4647. else
  4648. sprintf((char*)ShmOCPP16Data->DataTransfer[gun_index].Data, "{\\\"idTx\\\":%d,\\\"timestamp\\\":\\\"%s\\\"}", ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId, ts);
  4649. sendUnplugByDataTransferRequest(gun_index);
  4650. interLock.isSentUnplug[gun_index] = 1;
  4651. }
  4652. else if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_IDLE))
  4653. {
  4654. interLock.isSentUnplug[gun_index] = 0;
  4655. }
  4656. CcsPreviousSystemStatus[index] = ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus;
  4657. CcsPreviousConnectorPlugIn[index] = ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ConnectorPlugIn;
  4658. cpinitateMsg.bits[gun_index].StatusNotificationReq = 1;
  4659. if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex) && ((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_COMPLETE) || (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus <= SYS_MODE_IDLE))) // complete
  4660. {
  4661. sprintf(filenmae,"/Storage/OCPP/TxProfile_%d.json",(gun_index+1));
  4662. if((access(filenmae,F_OK))!=-1)
  4663. {
  4664. DEBUG_INFO("TxProfile exist. OCPP will delete TX Charging Profile\n");
  4665. sprintf(str,"rm -f %s",filenmae);
  4666. system(str);
  4667. }
  4668. }
  4669. }
  4670. cpinitateMsg.bits[gun_index].isOnCharging = ((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_TERMINATING)?1:0);
  4671. #if 1 // for TempStopTransaction
  4672. if(((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_BOOTING) || (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_IDLE)) &&
  4673. (ShmOCPP16Data->CpMsg.bits[gun_index].StopTransactionReq == 0))
  4674. {
  4675. checkTempStopTransaction(gun_index);
  4676. }
  4677. #endif
  4678. }
  4679. }
  4680. }
  4681. else if(gunType[gun_index] == GUN_TYPE_GBT)
  4682. {
  4683. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4684. {
  4685. tempIndex = ((gun_index==2) ? 1: 0);
  4686. }
  4687. else
  4688. {
  4689. tempIndex = gun_index;
  4690. }
  4691. for (int index = 0; index < GB_QUANTITY; index++)
  4692. {
  4693. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  4694. {
  4695. if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != GbPreviousSystemStatus[index]) || (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ConnectorPlugIn != GbPreviousConnectorPlugIn[index]) )
  4696. {
  4697. // Sent unplug message for California pricing logic
  4698. if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_COMPLETE) && (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ConnectorPlugIn == 0) && !interLock.isSentUnplug[gun_index])
  4699. {
  4700. uint8_t ts[36];
  4701. getNowDatetime(ts);
  4702. sprintf((char*)ShmOCPP16Data->DataTransfer[gun_index].VendorId, "org.openchargealliance.costmsg");
  4703. sprintf((char*)ShmOCPP16Data->DataTransfer[gun_index].MessageId, "ConnectorUnplugged");
  4704. if(strcmp((char*)dmsVersion, "2.0")==0)
  4705. sprintf((char*)ShmOCPP16Data->DataTransfer[gun_index].Data, "{\\\"transactionId\\\":%d,\\\"timestamp\\\":\\\"%s\\\"}", ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId, ts);
  4706. else
  4707. sprintf((char*)ShmOCPP16Data->DataTransfer[gun_index].Data, "{\\\"idTx\\\":%d,\\\"timestamp\\\":\\\"%s\\\"}", ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId, ts);
  4708. sendUnplugByDataTransferRequest(gun_index);
  4709. interLock.isSentUnplug[gun_index] = 1;
  4710. }
  4711. else if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_IDLE))
  4712. {
  4713. interLock.isSentUnplug[gun_index] = 0;
  4714. }
  4715. GbPreviousSystemStatus[index] = ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus;
  4716. GbPreviousConnectorPlugIn[index] = ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ConnectorPlugIn;
  4717. cpinitateMsg.bits[gun_index].StatusNotificationReq = 1;
  4718. if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex) && ((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_COMPLETE) || (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus <= SYS_MODE_IDLE))) // complete
  4719. {
  4720. sprintf(filenmae,"/Storage/OCPP/TxProfile_%d.json",(gun_index+1));
  4721. if((access(filenmae,F_OK))!=-1)
  4722. {
  4723. DEBUG_INFO("TxProfile exist. OCPP will delete TX Charging Profile\n");
  4724. sprintf(str,"rm -f %s",filenmae);
  4725. system(str);
  4726. }
  4727. }
  4728. }
  4729. cpinitateMsg.bits[gun_index].isOnCharging = ((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_TERMINATING)?1:0);
  4730. #if 1 // for TempStopTransaction
  4731. if(((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_BOOTING) || (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_IDLE)) &&
  4732. (ShmOCPP16Data->CpMsg.bits[gun_index].StopTransactionReq == 0))
  4733. {
  4734. checkTempStopTransaction(gun_index);
  4735. }
  4736. #endif
  4737. }
  4738. }
  4739. }
  4740. else if(gunType[gun_index] == GUN_TYPE_DO)
  4741. {
  4742. tempIndex = gun_index;
  4743. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  4744. {
  4745. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  4746. {
  4747. if((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus != DoPreviousSystemStatus[index]) || (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.ConnectorPlugIn != DoPreviousConnectorPlugIn[index]) )
  4748. {
  4749. // Sent unplug message for California pricing logic
  4750. if((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_COMPLETE) && (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.ConnectorPlugIn == 0) && !interLock.isSentUnplug[gun_index])
  4751. {
  4752. uint8_t ts[36];
  4753. getNowDatetime(ts);
  4754. sprintf((char*)ShmOCPP16Data->DataTransfer[gun_index].VendorId, "org.openchargealliance.costmsg");
  4755. sprintf((char*)ShmOCPP16Data->DataTransfer[gun_index].MessageId, "ConnectorUnplugged");
  4756. if(strcmp((char*)dmsVersion, "2.0")==0)
  4757. sprintf((char*)ShmOCPP16Data->DataTransfer[gun_index].Data, "{\\\"transactionId\\\":%d,\\\"timestamp\\\":\\\"%s\\\"}", ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId, ts);
  4758. else
  4759. sprintf((char*)ShmOCPP16Data->DataTransfer[gun_index].Data, "{\\\"idTx\\\":%d,\\\"timestamp\\\":\\\"%s\\\"}", ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId, ts);
  4760. sendUnplugByDataTransferRequest(gun_index);
  4761. interLock.isSentUnplug[gun_index] = 1;
  4762. }
  4763. else if((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_IDLE))
  4764. {
  4765. interLock.isSentUnplug[gun_index] = 0;
  4766. }
  4767. DoPreviousSystemStatus[index] = ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus;
  4768. DoPreviousConnectorPlugIn[index] = ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.ConnectorPlugIn;
  4769. cpinitateMsg.bits[gun_index].StatusNotificationReq = 1;
  4770. 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
  4771. {
  4772. sprintf(filenmae,"/Storage/OCPP/TxProfile_%d.json",(gun_index+1));
  4773. if((access(filenmae,F_OK))!=-1)
  4774. {
  4775. DEBUG_INFO("TxProfile exist. OCPP will delete TX Charging Profile\n");
  4776. sprintf(str,"rm -f %s",filenmae);
  4777. system(str);
  4778. }
  4779. }
  4780. }
  4781. 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);
  4782. #if 1 // for TempStopTransaction
  4783. if(((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_BOOTING) || (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_IDLE)) &&
  4784. (ShmOCPP16Data->CpMsg.bits[gun_index].StopTransactionReq == 0))
  4785. {
  4786. checkTempStopTransaction(gun_index);
  4787. }
  4788. #endif
  4789. }
  4790. }
  4791. }
  4792. else
  4793. {
  4794. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  4795. {
  4796. tempIndex = 2;
  4797. }
  4798. else
  4799. {
  4800. tempIndex = gun_index;
  4801. }
  4802. for (int index = 0; index < AC_QUANTITY; index++)
  4803. {
  4804. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  4805. {
  4806. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != AcPreviousSystemStatus[index]) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PilotState != AcPreviousConnectorPlugIn[index]) )
  4807. {
  4808. // Sent unplug message for California pricing logic
  4809. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_COMPLETE) && (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PilotState == CP_STATE_A) && !interLock.isSentUnplug[gun_index])
  4810. {
  4811. uint8_t ts[36];
  4812. getNowDatetime(ts);
  4813. sprintf((char*)ShmOCPP16Data->DataTransfer[gun_index].VendorId, "org.openchargealliance.costmsg");
  4814. sprintf((char*)ShmOCPP16Data->DataTransfer[gun_index].MessageId, "ConnectorUnplugged");
  4815. if(strcmp((char*)dmsVersion, "2.0")==0)
  4816. sprintf((char*)ShmOCPP16Data->DataTransfer[gun_index].Data, "{\\\"transactionId\\\":%d,\\\"timestamp\\\":\\\"%s\\\"}", ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId, ts);
  4817. else
  4818. sprintf((char*)ShmOCPP16Data->DataTransfer[gun_index].Data, "{\\\"idTx\\\":%d,\\\"timestamp\\\":\\\"%s\\\"}", ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId, ts);
  4819. sendUnplugByDataTransferRequest(gun_index);
  4820. interLock.isSentUnplug[gun_index] = 1;
  4821. }
  4822. else if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_IDLE))
  4823. {
  4824. interLock.isSentUnplug[gun_index] = 0;
  4825. }
  4826. AcPreviousSystemStatus[index] = ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus;
  4827. AcPreviousConnectorPlugIn[index] = ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PilotState;
  4828. cpinitateMsg.bits[gun_index].StatusNotificationReq = 1;
  4829. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex) && ((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_COMPLETE) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus <= SYS_MODE_IDLE))) // complete
  4830. {
  4831. sprintf(filenmae,"/Storage/OCPP/TxProfile_%d.json",(gun_index+1));
  4832. if((access(filenmae,F_OK))!=-1)
  4833. {
  4834. DEBUG_INFO("TxProfile exist. OCPP will delete TX Charging Profile\n");
  4835. sprintf(str,"rm -f %s",filenmae);
  4836. system(str);
  4837. }
  4838. }
  4839. }
  4840. cpinitateMsg.bits[gun_index].isOnCharging = ((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_TERMINATING)?1:0);
  4841. #if 1 // for TempStopTransaction
  4842. if(((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_BOOTING) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_IDLE)) &&
  4843. (ShmOCPP16Data->CpMsg.bits[gun_index].StopTransactionReq == 0))
  4844. {
  4845. checkTempStopTransaction(gun_index);
  4846. }
  4847. #endif
  4848. }
  4849. }// END
  4850. }
  4851. if(isWebsocketSendable && (server_sign == TRUE) && (getDiffSecNow(clientTime.StatusNotification[gun_index]) >= 1) && (ShmOCPP16Data->CsMsg.bits[gun_index].CancelReservationConf != 1) &&
  4852. (
  4853. (cpinitateMsg.bits[gun_index].StatusNotificationReq == 1) || (cpinitateMsg.bits[gun_index].TriggerStatusNotificationReq == 1) ||
  4854. ((strcmp((const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StatusNotificationPeriodically].ItemData, "TRUE") == 0) && (getDiffSecNow(clientTime.StatusNotification[gun_index]) >= atoi((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[StatusNotificationInterval].ItemData)))
  4855. )
  4856. )
  4857. {
  4858. sendStatusNotificationRequest(gun_index);
  4859. refreshStartTimer(&clientTime.StatusNotification[gun_index]);
  4860. }
  4861. //==============================================
  4862. // TCCI reader status report
  4863. //==============================================
  4864. if(isWebsocketSendable && (server_sign == TRUE) && (ShmOCPP16Data->TcciCustomData.ReaderStatus[gun_index].ReportReaderStatusReq == 1))
  4865. {
  4866. reportReaderStatus(gun_index);
  4867. //ShmOCPP16Data->TcciCustomData.ReaderStatus[gun_index].ReportReaderStatusReq = 0;
  4868. }
  4869. //==============================================
  4870. // CSU Trigger or timer timeout refresh Smart Charging Profile
  4871. //==============================================
  4872. if((ShmOCPP16Data->CSUMsg.bits[gun_index].ChargingProfileReq == 1) ||
  4873. ((cpinitateMsg.bits[gun_index].isOnCharging) && (atoi((const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CharingProfileRefreshInterval].ItemData) > 0) && (getDiffSecNow(clientTime.CharingProfileRefresh[gun_index]) > atoi((const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CharingProfileRefreshInterval].ItemData))))
  4874. {
  4875. checkCompositeSchedule(gun_index+1, 86400, &ShmOCPP16Data->SmartChargingProfile[gun_index], TRUE);
  4876. ShmOCPP16Data->CSUMsg.bits[gun_index].ChargingProfileReq = 0;
  4877. refreshStartTimer(&clientTime.CharingProfileRefresh[gun_index]);
  4878. }
  4879. //==============================================
  4880. // Meter report
  4881. //==============================================
  4882. // Trigger MeterValue
  4883. if(isWebsocketSendable && (server_sign == TRUE) && cpinitateMsg.bits[gun_index].TriggerMeterValue)
  4884. {
  4885. sendMeterValuesRequest(gun_index, ReadingContext_Trigger);
  4886. cpinitateMsg.bits[gun_index].TriggerMeterValue = 0;
  4887. }
  4888. // Clock-aligned Meter value
  4889. if(isWebsocketSendable && (reqClockAlignMeter[gun_index] == 1))
  4890. {
  4891. sendMeterValuesRequest(gun_index, ReadingContext_Sample_Clock);
  4892. reqClockAlignMeter[gun_index] = 0;
  4893. }
  4894. // Sample period MeterValue
  4895. if(((getDiffSecNow(clientTime.MeterValues[gun_index]) >= ((atoi((const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemData))>3?(atoi((const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemData)- 1):3))))
  4896. {
  4897. //check Transaction active
  4898. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  4899. {
  4900. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4901. {
  4902. tempIndex = ((gun_index==2) ? 1: 0);
  4903. }
  4904. else
  4905. {
  4906. tempIndex = gun_index;
  4907. }
  4908. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  4909. {
  4910. // 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault
  4911. if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  4912. {
  4913. if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_CHARGING)
  4914. {
  4915. reqSampleMeter[gun_index] = 1;
  4916. }
  4917. }
  4918. }// End for CHAdeMO
  4919. }
  4920. else if(gunType[gun_index] == GUN_TYPE_CCS)
  4921. {
  4922. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4923. {
  4924. tempIndex = ((gun_index==2) ? 1: 0);
  4925. }
  4926. else
  4927. {
  4928. tempIndex = gun_index;
  4929. }
  4930. for (int index = 0; index < CCS_QUANTITY; index++)
  4931. {
  4932. // 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault
  4933. if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  4934. {
  4935. if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_CHARGING)
  4936. {
  4937. reqSampleMeter[gun_index] = 1;
  4938. }
  4939. }
  4940. } // End for CCS
  4941. }
  4942. else if(gunType[gun_index] == GUN_TYPE_GBT)
  4943. {
  4944. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4945. {
  4946. tempIndex = ((gun_index==2) ? 1: 0);
  4947. }
  4948. else
  4949. {
  4950. tempIndex = gun_index;
  4951. }
  4952. for (int index = 0; index < GB_QUANTITY; index++)
  4953. {
  4954. // 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault
  4955. if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  4956. {
  4957. if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_CHARGING)
  4958. {
  4959. reqSampleMeter[gun_index] = 1;
  4960. }
  4961. }
  4962. }// End for GB
  4963. }
  4964. else if(gunType[gun_index] == GUN_TYPE_DO)
  4965. {
  4966. tempIndex = gun_index;
  4967. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  4968. {
  4969. // 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault
  4970. if(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  4971. {
  4972. if(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_CHARGING)
  4973. {
  4974. reqSampleMeter[gun_index] = 1;
  4975. }
  4976. }
  4977. }
  4978. }
  4979. else
  4980. {
  4981. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  4982. {
  4983. tempIndex = 2;
  4984. }
  4985. else
  4986. {
  4987. tempIndex = gun_index;
  4988. }
  4989. for (int index = 0; index < AC_QUANTITY; index++)
  4990. {
  4991. // 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault
  4992. if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  4993. {
  4994. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_TERMINATING))
  4995. {
  4996. reqSampleMeter[gun_index] = 1;
  4997. }
  4998. }
  4999. }//End for AC
  5000. }
  5001. if(reqSampleMeter[gun_index] == 1)
  5002. {
  5003. if(atoi((const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemData)>0)
  5004. sendMeterValuesRequest(gun_index, ReadingContext_Sample_Periodic);
  5005. storeTempStopTransaction(gun_index);
  5006. reqSampleMeter[gun_index] = 0;
  5007. }
  5008. refreshStartTimer(&clientTime.MeterValues[gun_index]);
  5009. }
  5010. //==============================================
  5011. // Check Connector reserved
  5012. //==============================================
  5013. //===============================
  5014. // Check if Reserve is expired
  5015. //===============================
  5016. if((server_sign == TRUE) && (ShmOCPP16Data->ReserveNow[gun_index].ExpiryDate[0] != 0))
  5017. {
  5018. if(isOvertNow(ShmOCPP16Data->ReserveNow[gun_index].ExpiryDate))
  5019. {
  5020. DEBUG_INFO("reserve expired.\n");
  5021. memset(ShmOCPP16Data->ReserveNow[gun_index].ExpiryDate,0,ARRAY_SIZE(ShmOCPP16Data->ReserveNow[gun_index].ExpiryDate));
  5022. }
  5023. }//END OF Check if Reserve is expired
  5024. //==========================================
  5025. // csu trigger FirmwareStatusNotificationReq
  5026. //==========================================
  5027. if(isWebsocketSendable && (server_sign == TRUE) && (ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationReq == 1))
  5028. {
  5029. sendFirmwareStatusNotificationRequest((char *)ShmOCPP16Data->FirmwareStatusNotification.Status);
  5030. }
  5031. if(isWebsocketSendable && (server_sign == TRUE) && (ShmOCPP16Data->SpMsg.bits.SignedFirmwareStatusNotificationReq == 1))
  5032. {
  5033. sendSignedFirmwareStatusNotificationRequest((char *)ShmOCPP16Data->SignedFirmwareStatusNotification.status);
  5034. }
  5035. //==========================================
  5036. // csu trigger DiagnosticsStatusNotificationReq
  5037. //==========================================
  5038. if(isWebsocketSendable && (server_sign == TRUE) && (ShmOCPP16Data->SpMsg.bits.DiagnosticsStatusNotificationReq == 1))
  5039. {
  5040. sendDiagnosticsStatusNotificationRequest((char *)ShmOCPP16Data->DiagnosticsStatusNotification.Status);
  5041. }
  5042. if(isWebsocketSendable && (server_sign == TRUE) && (ShmOCPP16Data->SpMsg.bits.LogStatusNotificationReq == 1))
  5043. {
  5044. sendLogStatusNotificationRequest((char *)ShmOCPP16Data->LogStatusNotification.status);
  5045. }
  5046. //==========================================
  5047. // csu trigger CancelReservationConf
  5048. //==========================================
  5049. if(isWebsocketSendable && (server_sign == TRUE) && (ShmOCPP16Data->CsMsg.bits[gun_index].CancelReservationConf == 1))
  5050. {
  5051. sendCancelReservationConfirmation((char *)ShmOCPP16Data->CancelReservation[gun_index].guid,(char *)ShmOCPP16Data->CancelReservation[gun_index].ResponseStatus);
  5052. ShmOCPP16Data->CsMsg.bits[gun_index].CancelReservationConf = 0;
  5053. }
  5054. //==========================================
  5055. // csu trigger ChangeAvailabilityConf
  5056. //==========================================
  5057. if(isWebsocketSendable && (server_sign == TRUE) && (ShmOCPP16Data->CsMsg.bits[gun_index].ChangeAvailabilityConf == 1))
  5058. {
  5059. //sendChangeAvailabilityConfirmation(,(char *)ShmOCPP16Data->ChangeAvailability[gun_index].ResponseStatus);
  5060. }
  5061. //==========================================
  5062. // csu trigger UnlockConnectorConf
  5063. //==========================================
  5064. if(isWebsocketSendable && (server_sign == TRUE) && (ShmOCPP16Data->CsMsg.bits[gun_index].UnlockConnectorConf == 1))
  5065. {
  5066. sendUnlockConnectorConfirmation((char *)ShmOCPP16Data->UnlockConnector[gun_index].guid, (char *)ShmOCPP16Data->UnlockConnector[gun_index].ResponseStatus);
  5067. ShmOCPP16Data->CsMsg.bits[gun_index].UnlockConnectorConf = 0;
  5068. }
  5069. //==========================================
  5070. // csu trigger ReserveNowConf
  5071. //==========================================
  5072. if(isWebsocketSendable && (server_sign == TRUE) && (ShmOCPP16Data->CsMsg.bits[gun_index].ReserveNowConf == 1))
  5073. {
  5074. sendReserveNowTransactionConfirmation((char *)ShmOCPP16Data->ReserveNow[gun_index].guid, (char *)ShmOCPP16Data->ReserveNow[gun_index].ResponseStatus);
  5075. ShmOCPP16Data->CsMsg.bits[gun_index].ReserveNowConf = 0;
  5076. }
  5077. if(isWebsocketSendable && (server_sign == TRUE) && (ShmOCPP16Data->SpMsg.bits.SignCertificateReq == 1) && (access("/Storage/OCPP/certCP.csr",F_OK) != -1))
  5078. {
  5079. sendSignCertificateRequest();
  5080. }
  5081. if(isWebsocketSendable && (server_sign == TRUE) && (ShmOCPP16Data->SpMsg.bits.SecurityEventNotificationReq == 1))
  5082. {
  5083. sendSecurityEventNotificationRequest();
  5084. ShmOCPP16Data->SpMsg.bits.SecurityEventNotificationReq = 0;
  5085. }
  5086. }
  5087. }
  5088. //==========================================
  5089. // send request routine
  5090. //==========================================
  5091. int sendAuthorizeRequest(int gun_index)
  5092. {
  5093. mtrace();
  5094. int result = FAIL;
  5095. char message[100]={0};
  5096. char guid[37];
  5097. char tempdata[65]={0};
  5098. DEBUG_INFO("sendAuthorizeRequest...\n");
  5099. memset(&(ShmOCPP16Data->Authorize.ResponseIdTagInfo),0,sizeof(struct StructIdTagInfo));
  5100. //Local Authorize
  5101. if((strcmp((const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemData , "TRUE")==0) &&(ShmOCPP16Data->OcppConnStatus == 0))
  5102. {
  5103. DEBUG_INFO("Allow OfflineTx UnknownId Pass.\n");
  5104. strcpy((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.ExpiryDate, "");
  5105. strcpy((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.ParentIdTag, "");
  5106. strcpy((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.Status, "Accepted");
  5107. result = PASS;
  5108. ShmOCPP16Data->SpMsg.bits.AuthorizeReq = 0;
  5109. ShmOCPP16Data->SpMsg.bits.AuthorizeConf = 1; // inform csu
  5110. authorizeRetryTimes = 0;
  5111. return result;
  5112. }
  5113. 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))||
  5114. ((strcmp((const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemData, "TRUE") == 0)&&(strcmp((const char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "TRUE") == 0)))
  5115. {
  5116. // Query from cache
  5117. DEBUG_INFO("Authorize from cache.\n");
  5118. OCPP_getIdTagFromLocalCache((char *)ShmSysConfigAndInfo->SysConfig.UserId);
  5119. // Query from list
  5120. if((strcmp(idTagQuery.idTagstr,"") == 0) || (strcmp(idTagQuery.idTagstatus,"Accepted") != 0) )
  5121. {
  5122. DEBUG_INFO("Authorize from list.\n");
  5123. OCPP_getIdTagFromLocalList((char *)ShmSysConfigAndInfo->SysConfig.UserId);
  5124. }
  5125. if((strcmp(idTagQuery.idTagstr,"") == 0) || (strcmp(idTagQuery.idTagstatus,"Accepted") != 0) )
  5126. {
  5127. if(strcmp(idTagQuery.idTagstr,"") == 0)
  5128. {
  5129. DEBUG_INFO("Local Authorization Fail, Card %s is not in local cache and list.\n", ShmSysConfigAndInfo->SysConfig.UserId);
  5130. }
  5131. else if(strcmp(idTagQuery.idTagstatus,"Accepted") != 0)
  5132. {
  5133. DEBUG_INFO("Local Authorization Fail, Card %s is not Accepted.\n", idTagQuery.idTagstr);
  5134. }
  5135. if(!GetOcppConnStatus())
  5136. {
  5137. DEBUG_INFO("off-line Local Authorization Fail.\n");
  5138. strcpy((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.ExpiryDate, idTagQuery.expiryDate);
  5139. strcpy((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.ParentIdTag, idTagQuery.parentIdTag);
  5140. strcpy((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.Status, "Invalid");
  5141. DEBUG_INFO("ShmOCPP16Data->Authorize.ResponseIdTagInfo.Status: %s \n", ShmOCPP16Data->Authorize.ResponseIdTagInfo.Status);
  5142. ShmOCPP16Data->SpMsg.bits.AuthorizeReq = 0;
  5143. ShmOCPP16Data->SpMsg.bits.AuthorizeConf = 1; // inform csu
  5144. authorizeRetryTimes = 0;
  5145. return result;
  5146. }
  5147. }
  5148. else
  5149. {
  5150. DEBUG_INFO("off-line Local Authorization get result !!!!\n");
  5151. strcpy((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.ExpiryDate, idTagQuery.expiryDate);
  5152. strcpy((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.ParentIdTag, idTagQuery.parentIdTag);
  5153. if(isOvertNow((uint8_t*)&idTagQuery.expiryDate[0]))
  5154. sprintf((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.Status, "Expired");
  5155. else
  5156. strcpy((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.Status, idTagQuery.idTagstatus);
  5157. DEBUG_INFO("ShmOCPP16Data->Authorize.ResponseIdTagInfo.Status: %s \n", ShmOCPP16Data->Authorize.ResponseIdTagInfo.Status);
  5158. result = PASS;
  5159. ShmOCPP16Data->SpMsg.bits.AuthorizeReq = 0;
  5160. ShmOCPP16Data->SpMsg.bits.AuthorizeConf = 1; // inform csu
  5161. authorizeRetryTimes = 0;
  5162. return result;
  5163. }
  5164. }
  5165. //initialize struct Authorize
  5166. memset(&(ShmOCPP16Data->Authorize), 0 , sizeof(struct StructAuthorize));
  5167. //get data from shared memory
  5168. strcpy((char *)ShmOCPP16Data->Authorize.IdTag, (const char *)ShmSysConfigAndInfo->SysConfig.UserId);
  5169. random_uuid(guid);
  5170. sprintf(message,"[%d,\"%s\",\"Authorize\",{\"idTag\":\"%s\"}]",MESSAGE_TYPE_CALL, guid, ShmOCPP16Data->Authorize.IdTag);
  5171. LWS_Send(message);
  5172. sprintf(tempdata, "Authorize,%d", gun_index);
  5173. if(hashmap_operation(HASH_OP_ADD, guid, tempdata) == 1)
  5174. {
  5175. result = PASS;
  5176. DEBUG_INFO("Authorize mapItem pass\n");
  5177. }
  5178. ShmOCPP16Data->SpMsg.bits.AuthorizeReq = 0;
  5179. return result;
  5180. }
  5181. int sendBootNotificationRequest(void)
  5182. {
  5183. mtrace();
  5184. int result = FAIL;
  5185. char message[500]={0}, payload[700]={0};
  5186. char guid[37]={0};
  5187. char tempdata[65]={0};
  5188. // Fill BootNotification fields
  5189. strcpy((char *)ShmOCPP16Data->BootNotification.CbSN,(const char *)ShmOCPP16Data->ChargeBoxId);
  5190. strcpy((char *)ShmOCPP16Data->BootNotification.CpModel,(const char *)ShmSysConfigAndInfo->SysConfig.ModelName);
  5191. strcpy((char *)ShmOCPP16Data->BootNotification.CpSN,(const char *)ShmSysConfigAndInfo->SysConfig.SerialNumber);
  5192. strcpy((char *)ShmOCPP16Data->BootNotification.CpVendor,(const char *)ShmSysConfigAndInfo->SysConfig.chargePointVendor);
  5193. strcpy((char *)ShmOCPP16Data->BootNotification.CpFwVersion,(const char *)ShmSysConfigAndInfo->SysInfo.CsuRootFsFwRev);
  5194. strcpy((char *)ShmOCPP16Data->BootNotification.CpIccid,(const char *)ShmSysConfigAndInfo->SysConfig.TelecomInterface.TelcomSimIccid);
  5195. strcpy((char *)ShmOCPP16Data->BootNotification.CpImsi,(const char *)ShmSysConfigAndInfo->SysConfig.TelecomInterface.TelcomSimImsi);
  5196. sprintf(payload, "{\"chargeBoxSerialNumber\":\"%s\",\"chargePointModel\":\"%s\",\"chargePointSerialNumber\":\"%s\",\"chargePointVendor\":\"%s\",\"firmwareVersion\":\"%s\",\"iccid\":\"%s\",\"imsi\":\"%s\"} ",
  5197. ShmOCPP16Data->ChargeBoxId
  5198. ,ShmSysConfigAndInfo->SysConfig.ModelName
  5199. ,ShmSysConfigAndInfo->SysConfig.SerialNumber
  5200. ,ShmSysConfigAndInfo->SysConfig.chargePointVendor
  5201. ,ShmOCPP16Data->BootNotification.CpFwVersion
  5202. ,ShmOCPP16Data->BootNotification.CpIccid
  5203. ,ShmOCPP16Data->BootNotification.CpImsi);
  5204. random_uuid(guid);
  5205. sprintf(message,"[%d,\"%s\",\"%s\",%s]",MESSAGE_TYPE_CALL, guid, "BootNotification", payload);
  5206. LWS_Send(message);
  5207. sprintf(tempdata, "BootNotification,0");
  5208. 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*/)
  5209. {
  5210. result = PASS;
  5211. }
  5212. memset(queuedata, 0, ARRAY_SIZE(queuedata));
  5213. strcpy(queuedata,message);
  5214. return result;
  5215. }
  5216. int sendDataTransferRequest(int gun_index)
  5217. {
  5218. mtrace();
  5219. char message[1000]={0};
  5220. char guid[37]={0};
  5221. char tempdata[65]={0};
  5222. int result = FAIL;
  5223. random_uuid(guid);
  5224. sprintf(message,"[%d,\"%s\",\"DataTransfer\",{\"vendorId\":\"%s\",\"messageId\":\"%s\",\"data\":\"%s\"}]",
  5225. MESSAGE_TYPE_CALL,
  5226. guid,
  5227. ShmOCPP16Data->DataTransfer[gun_index].VendorId,
  5228. ShmOCPP16Data->DataTransfer[gun_index].MessageId,
  5229. ShmOCPP16Data->DataTransfer[gun_index].Data);
  5230. LWS_Send(message);
  5231. sprintf(tempdata, "DataTransfer,%d", (gun_index + 1));
  5232. if(hashmap_operation(HASH_OP_ADD, guid, tempdata) == 1)
  5233. {
  5234. result = PASS;
  5235. DEBUG_INFO("DataTransfer mapItem pass\n");
  5236. }
  5237. return result;
  5238. }
  5239. int sendUnplugByDataTransferRequest(int gun_index)
  5240. {
  5241. mtrace();
  5242. char message[1000]={0};
  5243. char guid[37]={0};
  5244. char tempdata[65]={0};
  5245. int result = FAIL;
  5246. random_uuid(guid);
  5247. sprintf(message,"%d,[%d,\"%s\",\"DataTransfer\",{\"vendorId\":\"%s\",\"messageId\":\"%s\",\"data\":\"%s\"}]",
  5248. (gun_index+1),
  5249. MESSAGE_TYPE_CALL,
  5250. guid,
  5251. ShmOCPP16Data->DataTransfer[gun_index].VendorId,
  5252. ShmOCPP16Data->DataTransfer[gun_index].MessageId,
  5253. ShmOCPP16Data->DataTransfer[gun_index].Data);
  5254. sprintf(tempdata, "DataTransfer,%d", (gun_index + 1));
  5255. if(hashmap_operation(HASH_OP_ADD, guid, tempdata) == 1)
  5256. {
  5257. result = PASS;
  5258. DEBUG_INFO("DataTransfer mapItem pass\n");
  5259. }
  5260. queue_operation(QUEUE_OPERATION_ADD, guid, message);
  5261. return result;
  5262. }
  5263. int sendOcmfByDataTransferRequest(int gun_index)
  5264. {
  5265. json_object *DataTransfer = json_object_new_object();
  5266. json_object *data = json_object_new_object();
  5267. mtrace();
  5268. sprintf((char*)ShmOCPP16Data->DataTransfer[gun_index].VendorId, (char*)ShmSysConfigAndInfo->SysConfig.chargePointVendor);
  5269. sprintf((char*)ShmOCPP16Data->DataTransfer[gun_index].MessageId, "ID_OCMF");
  5270. json_object_object_add(data, "txId", json_object_new_int(ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId));
  5271. json_object_object_add(data, "dataString", json_object_new_string((char*)ShmOCPP16Data->OcmfData[gun_index].DataString));
  5272. json_object_object_add(data, "publicKey", json_object_new_string((char*)ShmOCPP16Data->OcmfData[gun_index].PublicKey));
  5273. json_object_object_add(DataTransfer, "data", data);
  5274. json_object_object_add(DataTransfer, "vendorId", json_object_new_string((char*)ShmOCPP16Data->DataTransfer[gun_index].VendorId));
  5275. json_object_object_add(DataTransfer, "messageId", json_object_new_string((char*)ShmOCPP16Data->DataTransfer[gun_index].MessageId));
  5276. char message[3000]={0};
  5277. char guid[37]={0};
  5278. char tempdata[65]={0};
  5279. int result = FAIL;
  5280. random_uuid(guid);
  5281. sprintf(message,"%d,[%d,\"%s\",\"DataTransfer\",%s]",
  5282. (gun_index+1),
  5283. MESSAGE_TYPE_CALL,
  5284. guid,
  5285. json_object_to_json_string_ext(DataTransfer, JSON_C_TO_STRING_PLAIN));
  5286. json_object_put(DataTransfer);
  5287. sprintf(tempdata, "DataTransfer,%d", (gun_index + 1));
  5288. if(hashmap_operation(HASH_OP_ADD, guid, tempdata) == 1)
  5289. {
  5290. result = PASS;
  5291. DEBUG_INFO("DataTransfer mapItem pass\n");
  5292. }
  5293. queue_operation(QUEUE_OPERATION_ADD, guid, message);
  5294. return result;
  5295. }
  5296. int sendDiagnosticsStatusNotificationRequest(char *status)
  5297. {
  5298. mtrace();
  5299. int result = FAIL;
  5300. char message[110]={0};
  5301. char guid[37]={0};
  5302. char tempdata[65]={0};
  5303. //[ 2, "9f7bced1-b8b1-40ec-b3bb-2e15630e3cdc", "DiagnosticsStatusNotification", { "status": "Idle" } ]
  5304. DEBUG_INFO("sendDiagnosticsStatusNotificationRequest...\n");
  5305. sprintf((char *)ShmOCPP16Data->DiagnosticsStatusNotification.Status,"%s",(const char *)status);
  5306. random_uuid(guid);
  5307. sprintf(message,"[%d,\"%s\",\"DiagnosticsStatusNotification\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALL, guid,status);
  5308. LWS_SendNow(message);
  5309. sprintf(tempdata, "DiagnosticsStatusNotification,%d", 0);
  5310. if(hashmap_operation(HASH_OP_ADD, guid, tempdata) == 1)
  5311. {
  5312. result = PASS;
  5313. //DEBUG_INFO("DiagnosticsStatusNotification mapItem pass\n");
  5314. }
  5315. //#ifdef SystemLogMessage
  5316. //DEBUG_INFO(">>>>>DiagnosticsStatusNotification request\n");
  5317. //DEBUG_INFO("Message: %s\n", SendBuffer);
  5318. //DEBUG_INFO("After push hash length: %d\n", hashmapForMessageLength()/*hashmap_length(hashMap)*/);
  5319. //#endif
  5320. ShmOCPP16Data->SpMsg.bits.DiagnosticsStatusNotificationReq = 0;
  5321. ShmOCPP16Data->SpMsg.bits.DiagnosticsStatusNotificationConf = 0;
  5322. //record status
  5323. if(strcmp(status,"Idle")==0)
  5324. {
  5325. DiagnosticsStatusNotificationStatus = DIAGNOSTIC_STATUS_IDLE;
  5326. }
  5327. else if(strcmp(status,"Uploaded")==0)
  5328. {
  5329. DiagnosticsStatusNotificationStatus = DIAGNOSTIC_STATUS_UPLOADED;
  5330. }
  5331. else if(strcmp(status,"UploadFailed")==0)
  5332. {
  5333. DiagnosticsStatusNotificationStatus = DIAGNOSTIC_STATUS_UPLOAD_FAIL;
  5334. }
  5335. else if(strcmp(status,"Uploading")==0)
  5336. {
  5337. DiagnosticsStatusNotificationStatus = DIAGNOSTIC_STATUS_UPLOADING;
  5338. }
  5339. return result;
  5340. }
  5341. int sendFirmwareStatusNotificationRequest(char *status)
  5342. {
  5343. mtrace();
  5344. int result = FAIL;
  5345. char message[110]={0};
  5346. char guid[37]={0};
  5347. char tempdata[65]={0};
  5348. // [ 2, "eb841424-ae56-42b0-8c84-d5296018c33c", "FirmwareStatusNotification", { "status": "Downloaded" } ]
  5349. DEBUG_INFO("sendFirmwareStatusNotificationRequest \n");
  5350. sprintf((char *)ShmOCPP16Data->FirmwareStatusNotification.Status, "%s", (const char *)status);
  5351. random_uuid(guid);
  5352. sprintf(message,"[%d,\"%s\",\"FirmwareStatusNotification\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALL, guid, status);
  5353. LWS_SendNow(message);
  5354. sprintf(tempdata, "FirmwareStatusNotification,%d", 0);
  5355. 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*/)
  5356. {
  5357. result = PASS;
  5358. DEBUG_INFO("FirmwareStatusNotification mapItem pass\n");
  5359. }
  5360. //#ifdef SystemLogMessage
  5361. //DEBUG_INFO(">>>>>FirmwareStatusNotification request\n");
  5362. //DEBUG_INFO("Message: %s\n", SendBuffer);
  5363. //#endif
  5364. ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationReq = 0;
  5365. ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationConf = 0;
  5366. //record status
  5367. if(strcmp(status,"Downloaded")==0)
  5368. {
  5369. FirmwareStatusNotificationStatus = FIRMWARE_STATUS_DOWNLOADED;
  5370. }
  5371. else if(strcmp(status,"DownloadFailed")==0)
  5372. {
  5373. FirmwareStatusNotificationStatus = FIRMWARE_STATUS_DOWNLOAD_FAILED;
  5374. }
  5375. else if(strcmp(status,"Downloading")==0)
  5376. {
  5377. FirmwareStatusNotificationStatus = FIRMWARE_STATUS_DOWNLOADING;
  5378. }
  5379. else if(strcmp(status,"Idle")==0)
  5380. {
  5381. FirmwareStatusNotificationStatus = FIRMWARE_STATUS_IDLE;
  5382. }
  5383. else if(strcmp(status,"InstallationFailed")==0)
  5384. {
  5385. FirmwareStatusNotificationStatus = FIRMWARE_STATUS_INSTALLATION_FAILED;
  5386. }
  5387. else if(strcmp(status,"Installing")==0)
  5388. {
  5389. FirmwareStatusNotificationStatus = FIRMWARE_STATUS_INSTALLING;
  5390. }
  5391. else if(strcmp(status,"Installed")==0)
  5392. {
  5393. FirmwareStatusNotificationStatus = FIRMWARE_STATUS_INSTALLED;
  5394. }
  5395. return result;
  5396. }
  5397. int sendHeartbeatRequest(int gun_index)
  5398. {
  5399. mtrace();
  5400. int result = FAIL;
  5401. char message[80]={0};
  5402. char guid[37]={0};
  5403. char tempdata[65]={0};
  5404. random_uuid(guid);
  5405. sprintf(message, "[%d,\"%s\",\"Heartbeat\",{ }]"
  5406. , MESSAGE_TYPE_CALL
  5407. , guid );
  5408. LWS_Send(message);
  5409. sprintf(tempdata, "Heartbeat,%d", 0);
  5410. 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*/)
  5411. {
  5412. result = PASS;
  5413. }
  5414. return result;
  5415. }
  5416. int sendStartTransactionRequest(int gun_index)
  5417. {
  5418. mtrace();
  5419. int result = FAIL;
  5420. char message[250]={0};
  5421. char guid[37]={0};
  5422. struct timeval tmnow;
  5423. struct tm *tm;
  5424. char buf[28];//, usec_buf[6];
  5425. char tempdata[65]={0};
  5426. int tempIndex = 0;
  5427. DEBUG_INFO("sendStartTransactionRequest...\n");
  5428. gettimeofday(&tmnow, NULL);
  5429. time_t t;
  5430. t = time(NULL);
  5431. /*UTC time and date*/
  5432. tm = gmtime(&t);
  5433. strftime(buf,28,"%Y-%m-%dT%H:%M:%SZ", tm);
  5434. #if 0 // remove temporally
  5435. strftime(buf,30,"%Y-%m-%dT%H:%M:%S", tm);
  5436. strcat(buf,".");
  5437. sprintf(usec_buf,"%dZ",(int)tmnow.tv_usec);
  5438. strcat(buf,usec_buf);
  5439. #endif
  5440. ShmOCPP16Data->StartTransaction[gun_index].ConnectorId = gun_index +1 ; // gun start from 1~
  5441. strcpy((char *)ShmOCPP16Data->StartTransaction[gun_index].Timestamp, buf);
  5442. //strcpy((char *)ShmOCPP16Data->StartTransaction[gun_index].IdTag, (const char *)ShmSysConfigAndInfo->SysConfig.UserId);
  5443. // clear StartTransaction Response
  5444. strcpy((char *)ShmOCPP16Data->StartTransaction[gun_index].ResponseIdTagInfo.ExpiryDate, "");
  5445. strcpy((char *)ShmOCPP16Data->StartTransaction[gun_index].ResponseIdTagInfo.ParentIdTag, "");
  5446. strcpy((char *)ShmOCPP16Data->StartTransaction[gun_index].ResponseIdTagInfo.Status, "");
  5447. ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId = 0;
  5448. refreshStartTimer(&clientTime.MeterValues[gun_index]);
  5449. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DCcc
  5450. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  5451. {
  5452. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  5453. {
  5454. tempIndex = ((gun_index==2) ? 1: 0);
  5455. }
  5456. else
  5457. {
  5458. tempIndex = gun_index;
  5459. }
  5460. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  5461. {
  5462. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  5463. {
  5464. ShmOCPP16Data->StartTransaction[gun_index].MeterStart = (int)(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PowerConsumption*1000);
  5465. ShmOCPP16Data->StartTransaction[gun_index].ReservationId = ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ReservationId;
  5466. periousPeriodicPowerConsumption[gun_index] = ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PowerConsumption;
  5467. }
  5468. }
  5469. }
  5470. else if(gunType[gun_index] == GUN_TYPE_CCS)
  5471. {
  5472. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  5473. {
  5474. tempIndex = ((gun_index==2) ? 1: 0);
  5475. }
  5476. else
  5477. {
  5478. tempIndex = gun_index;
  5479. }
  5480. for (int index = 0; index < CCS_QUANTITY; index++)
  5481. {
  5482. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  5483. {
  5484. ShmOCPP16Data->StartTransaction[gun_index].MeterStart = (int)(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PowerConsumption*1000);
  5485. ShmOCPP16Data->StartTransaction[gun_index].ReservationId = ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ReservationId;
  5486. periousPeriodicPowerConsumption[gun_index] = ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PowerConsumption;
  5487. }
  5488. }
  5489. }
  5490. else if(gunType[gun_index] == GUN_TYPE_GBT)
  5491. {
  5492. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  5493. {
  5494. tempIndex = ((gun_index==2) ? 1: 0);
  5495. }
  5496. else
  5497. {
  5498. tempIndex = gun_index;
  5499. }
  5500. for (int index = 0; index < GB_QUANTITY; index++)
  5501. {
  5502. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  5503. {
  5504. ShmOCPP16Data->StartTransaction[gun_index].MeterStart = (int)(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PowerConsumption*1000);
  5505. ShmOCPP16Data->StartTransaction[gun_index].ReservationId = ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ReservationId;
  5506. periousPeriodicPowerConsumption[gun_index] = ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PowerConsumption;
  5507. }
  5508. }
  5509. }
  5510. else if(gunType[gun_index] == GUN_TYPE_DO)
  5511. {
  5512. tempIndex = gun_index;
  5513. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  5514. {
  5515. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  5516. {
  5517. ShmOCPP16Data->StartTransaction[gun_index].MeterStart = (int)(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PowerConsumption*1000);
  5518. ShmOCPP16Data->StartTransaction[gun_index].ReservationId = ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.ReservationId;
  5519. periousPeriodicPowerConsumption[gun_index] = ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PowerConsumption;
  5520. }
  5521. }
  5522. }
  5523. else
  5524. {
  5525. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  5526. {
  5527. tempIndex = 2;
  5528. }
  5529. else
  5530. {
  5531. tempIndex = gun_index;
  5532. }
  5533. for (int index = 0; index < AC_QUANTITY; index++)
  5534. {
  5535. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  5536. {
  5537. ShmOCPP16Data->StartTransaction[gun_index].MeterStart = (int)(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PowerConsumption*1000);
  5538. ShmOCPP16Data->StartTransaction[gun_index].ReservationId = ShmSysConfigAndInfo->SysInfo.AcChargingData[index].ReservationId;
  5539. periousPeriodicPowerConsumption[gun_index] = ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PowerConsumption;
  5540. }
  5541. }
  5542. }
  5543. random_uuid(guid);
  5544. if(ShmOCPP16Data->StartTransaction[gun_index].ReservationId == -1) // No Reservation
  5545. {
  5546. sprintf(message, "%d,[%d,\"%s\",\"StartTransaction\",{\"connectorId\":%d,\"idTag\":\"%s\",\"meterStart\":%d,\"timestamp\":\"%s\"}]"
  5547. , gun_index +1
  5548. , MESSAGE_TYPE_CALL
  5549. , guid
  5550. , ShmOCPP16Data->StartTransaction[gun_index].ConnectorId
  5551. , ShmOCPP16Data->StartTransaction[gun_index].IdTag
  5552. , ShmOCPP16Data->StartTransaction[gun_index].MeterStart
  5553. , ShmOCPP16Data->StartTransaction[gun_index].Timestamp );
  5554. }
  5555. else
  5556. {
  5557. sprintf(message, "%d,[%d,\"%s\",\"StartTransaction\",{\"connectorId\":%d,\"idTag\":\"%s\",\"meterStart\":%d,\"reservationId\":%d,\"timestamp\":\"%s\"}]"
  5558. , gun_index +1
  5559. , MESSAGE_TYPE_CALL
  5560. , guid
  5561. , ShmOCPP16Data->StartTransaction[gun_index].ConnectorId
  5562. , ShmOCPP16Data->StartTransaction[gun_index].IdTag
  5563. , ShmOCPP16Data->StartTransaction[gun_index].MeterStart
  5564. , ShmOCPP16Data->StartTransaction[gun_index].ReservationId
  5565. , ShmOCPP16Data->StartTransaction[gun_index].Timestamp );
  5566. }
  5567. #if 1
  5568. sprintf(tempdata, "StartTransaction,%d", (gun_index));
  5569. 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*/)
  5570. {
  5571. result = PASS;
  5572. }
  5573. #endif
  5574. strcpy(queuedata, message);
  5575. queue_operation(QUEUE_OPERATION_ADD, guid, queuedata );//addq(guid, queuedata); ---> remove temporally
  5576. OCPP_insert_transaction_msg(YES, queuedata);
  5577. return result;
  5578. }
  5579. int sendStatusNotificationRequest(int gun_index)
  5580. {
  5581. mtrace();
  5582. int result = FAIL;
  5583. char message[600]={0};
  5584. char guid[37];
  5585. int currentStatus = 0;
  5586. struct timeval tmnow;
  5587. struct tm *tm;
  5588. char buf[28];//, usec_buf[6];
  5589. char tempdata[65]={0};
  5590. int tempIndex = 0;
  5591. uint8_t isStateChanged = TRUE;
  5592. uint8_t isContentIllegal = TRUE;
  5593. DEBUG_INFO("sendStatusNotificationRequest...\n");
  5594. gettimeofday(&tmnow, NULL);
  5595. time_t t;
  5596. t = time(NULL);
  5597. /*UTC time and date*/
  5598. tm = gmtime(&t);
  5599. strftime(buf,28,"%Y-%m-%dT%H:%M:%SZ", tm);
  5600. #if 0 // remove temporally
  5601. strftime(buf,30,"%Y-%m-%dT%H:%M:%S", tm);
  5602. strcat(buf,".");
  5603. sprintf(usec_buf,"%dZ",(int)tmnow.tv_usec);
  5604. strcat(buf,usec_buf);
  5605. #endif
  5606. //printf("%s",buf);
  5607. ShmOCPP16Data->StatusNotification[gun_index].ConnectorId = (gun_index + 1);
  5608. //strcpy(ShmOCPP16Data->StatusNotification[gun_index].ErrorCode, "NoError"); --- CSU Setting
  5609. // it's option
  5610. //strcpy((char *)ShmOCPP16Data->StatusNotification[gun_index].Info, "");
  5611. /*
  5612. enum _SYSTEM_STATUS
  5613. {
  5614. S_BOOTING = 0,
  5615. S_IDLE, = 1
  5616. S_AUTHORIZING, =2
  5617. S_REASSIGN_CHECK, =3
  5618. S_REASSIGN, =4
  5619. S_PRECHARGE, =5
  5620. S_PREPARING_FOR_EV, =6
  5621. S_PREPARING_FOR_EVSE, =7
  5622. S_CHARGING, =8
  5623. S_TERMINATING, =9
  5624. S_COMPLETE, =10
  5625. S_ALARM, =11
  5626. S_FAULT =12
  5627. }
  5628. */
  5629. //check Transaction active
  5630. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DCcc
  5631. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  5632. {
  5633. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  5634. {
  5635. tempIndex = ((gun_index==2) ? 1: 0);
  5636. }
  5637. else
  5638. {
  5639. tempIndex = gun_index;
  5640. }
  5641. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  5642. {
  5643. if ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex))
  5644. {
  5645. if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_IDLE)//S_IDLE
  5646. {
  5647. if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ConnectorPlugIn == 1) // //0: unplug, 1: Plug-in
  5648. {
  5649. currentStatus = Preparing; //OCPP Status: Preparing
  5650. }
  5651. else
  5652. {
  5653. currentStatus = Available; //OCPP Status: Available
  5654. }
  5655. }
  5656. else if ( ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus >= SYS_MODE_AUTHORIZING)&&( ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus <= SYS_MODE_PREPARE_FOR_EVSE)) ||
  5657. ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus >= SYS_MODE_CCS_PRECHARGE_STEP0) && ( ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus <= SYS_MODE_CCS_PRECHARGE_STEP1) )
  5658. ) //S_PRECHARGE
  5659. {
  5660. currentStatus = Preparing; //OCPP Status: Preparing
  5661. }
  5662. else if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_CHARGING) //S_CHARGING
  5663. {
  5664. currentStatus = Charging; //OCPP Status: Charging
  5665. }
  5666. else if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_COMPLETE) //S_COMPLETE
  5667. {
  5668. currentStatus = Finishing; //OCPP Status: Finishing
  5669. }
  5670. else if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_TERMINATING) // S_TERMINATING ---> SuspendedEV
  5671. {
  5672. currentStatus = SuspendedEV; //OCPP Status: SuspendedEV
  5673. }
  5674. 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
  5675. {
  5676. currentStatus = Unavailable; //OCPP Status: Unavailable
  5677. }
  5678. else if ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_FAULT) || (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_ALARM)) //S_ALARM,S_FAULT ---> Faulted
  5679. {
  5680. currentStatus = Faulted; //OCPP Status: Faulted
  5681. }
  5682. else if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_RESERVATION) // ---> Reserved
  5683. {
  5684. currentStatus = Reserved; //OCPP Status: Reserved
  5685. }
  5686. } //end of the same index
  5687. }//end of for CHAdeMO_QUANTITY
  5688. }
  5689. else if(gunType[gun_index] == GUN_TYPE_CCS)
  5690. {
  5691. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  5692. {
  5693. tempIndex = ((gun_index==2) ? 1: 0);
  5694. }
  5695. else
  5696. {
  5697. tempIndex = gun_index;
  5698. }
  5699. for (int index = 0; index < CCS_QUANTITY; index++)
  5700. {
  5701. if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  5702. {
  5703. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_IDLE) //S_IDLE
  5704. {
  5705. if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ConnectorPlugIn == 1) //0: unplug, 1: Plug-in
  5706. {
  5707. currentStatus = Preparing; //OCPP Status: Preparing
  5708. }
  5709. else
  5710. {
  5711. currentStatus = Available; //OCPP Status: Available
  5712. }
  5713. }
  5714. else if ( ((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus >= SYS_MODE_AUTHORIZING)&&( ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus <= SYS_MODE_PREPARE_FOR_EVSE)) ||
  5715. ((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus >= SYS_MODE_CCS_PRECHARGE_STEP0) && ( ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus <= SYS_MODE_CCS_PRECHARGE_STEP1) )
  5716. ) //S_PRECHARGE
  5717. {
  5718. currentStatus = Preparing; //OCPP Status: Preparing
  5719. }
  5720. else if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_CHARGING) //S_CHARGING
  5721. {
  5722. currentStatus = Charging; //OCPP Status: Charging
  5723. }
  5724. else if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_COMPLETE) //S_COMPLETE
  5725. {
  5726. currentStatus = Finishing; //OCPP Status: Finishing
  5727. }
  5728. else if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_TERMINATING) //S_TERMINATING ---> SuspendedEV
  5729. {
  5730. currentStatus = SuspendedEV; //OCPP Status: SuspendedEV
  5731. }
  5732. 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
  5733. {
  5734. currentStatus = Unavailable; //OCPP Status : Unavailable
  5735. }
  5736. else if ((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_FAULT) || (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_ALARM)) //S_ALARM ,S_FAULT ---> Faulted
  5737. {
  5738. currentStatus = Faulted; //OCPP Status: Faulted
  5739. }
  5740. else if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_RESERVATION) // ---> Reserved
  5741. {
  5742. currentStatus = Reserved; //OCPP Status: Reserved
  5743. }
  5744. } //end of the same index
  5745. } // end of for CCS_QUANTITY
  5746. }
  5747. else if(gunType[gun_index] == GUN_TYPE_GBT)
  5748. {
  5749. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  5750. {
  5751. tempIndex = ((gun_index==2) ? 1: 0);
  5752. }
  5753. else
  5754. {
  5755. tempIndex = gun_index;
  5756. }
  5757. for (int index = 0; index < GB_QUANTITY; index++)
  5758. {
  5759. if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  5760. {
  5761. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_IDLE) //S_IDLE
  5762. {
  5763. if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ConnectorPlugIn == 1) // //0: unplug, 1: Plug-in
  5764. {
  5765. currentStatus = Preparing; //OCPP Status: Preparing
  5766. }
  5767. else
  5768. {
  5769. currentStatus = Available; //OCPP Status: Available
  5770. }
  5771. }
  5772. else if ( ((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus >= SYS_MODE_AUTHORIZING)&&( ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus <= SYS_MODE_PREPARE_FOR_EVSE)) ||
  5773. ((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus >= SYS_MODE_CCS_PRECHARGE_STEP0) && ( ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus <= SYS_MODE_CCS_PRECHARGE_STEP1) )
  5774. ) //S_PRECHARGE
  5775. {
  5776. currentStatus = Preparing; //OCPP Status: Preparing
  5777. }
  5778. else if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_CHARGING) //S_CHARGING
  5779. {
  5780. currentStatus = Charging; //OCPP Status: Charging
  5781. }
  5782. else if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_COMPLETE) //S_COMPLETE
  5783. {
  5784. currentStatus = Finishing; //OCPP Status: Finishing
  5785. }
  5786. else if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_TERMINATING) // S_TERMINATING ---> SuspendedEV
  5787. {
  5788. currentStatus = SuspendedEV; //OCPP Status: SuspendedEV
  5789. }
  5790. 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
  5791. {
  5792. currentStatus = Unavailable; //OCPP Status: Unavailable
  5793. }
  5794. else if ((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_FAULT) || (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_ALARM)) //S_ALARM ,S_FAULT ---> Faulted
  5795. {
  5796. currentStatus = Faulted; //OCPP Status: Faulted
  5797. }
  5798. else if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_RESERVATION) // ---> Reserved
  5799. {
  5800. currentStatus = Reserved; //OCPP Status: Reserved
  5801. }
  5802. } //end of the same index
  5803. } // end of for GB_QUANTITY
  5804. }
  5805. else if(gunType[gun_index] == GUN_TYPE_DO)
  5806. {
  5807. tempIndex = gun_index;
  5808. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  5809. {
  5810. if(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  5811. {
  5812. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_IDLE) //S_IDLE
  5813. {
  5814. if(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.ConnectorPlugIn == 1) // //0: unplug, 1: Plug-in
  5815. {
  5816. currentStatus = Preparing; //OCPP Status: Preparing
  5817. }
  5818. else
  5819. {
  5820. currentStatus = Available; //OCPP Status: Available
  5821. }
  5822. }
  5823. else if ( ((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus >= SYS_MODE_AUTHORIZING) && (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus <= SYS_MODE_PREPARE_FOR_EVSE)) ||
  5824. ((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus >= SYS_MODE_CCS_PRECHARGE_STEP0) && (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus <= SYS_MODE_CCS_PRECHARGE_STEP1) )
  5825. ) //S_PRECHARGE
  5826. {
  5827. currentStatus = Preparing; //OCPP Status: Preparing
  5828. }
  5829. else if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_CHARGING) //S_CHARGING
  5830. {
  5831. currentStatus = Charging; //OCPP Status: Charging
  5832. }
  5833. else if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_COMPLETE) //S_COMPLETE
  5834. {
  5835. currentStatus = Finishing; //OCPP Status: Finishing
  5836. }
  5837. else if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_TERMINATING) // S_TERMINATING ---> SuspendedEV
  5838. {
  5839. currentStatus = SuspendedEV; //OCPP Status: SuspendedEV
  5840. }
  5841. 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
  5842. {
  5843. currentStatus = Unavailable; //OCPP Status: Unavailable
  5844. }
  5845. 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
  5846. {
  5847. currentStatus = Faulted; //OCPP Status: Faulted
  5848. }
  5849. else if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_RESERVATION) // ---> Reserved
  5850. {
  5851. currentStatus = Reserved; //OCPP Status: Reserved
  5852. }
  5853. } //end of the same index
  5854. }
  5855. }
  5856. else
  5857. {
  5858. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  5859. {
  5860. tempIndex = 2;
  5861. }
  5862. else
  5863. {
  5864. tempIndex = gun_index;
  5865. }
  5866. for (int index = 0; index < AC_QUANTITY; index++)
  5867. {
  5868. if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  5869. {
  5870. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_IDLE) //SYS_MODE_IDLE
  5871. {
  5872. 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))
  5873. {
  5874. currentStatus = Preparing; //OCPP Status: Preparing
  5875. }
  5876. else
  5877. {
  5878. currentStatus = Available; //OCPP Status: Available
  5879. }
  5880. }
  5881. else if ((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_AUTHORIZING) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_PREPARING)) //SYS_MODE_PREPARING
  5882. {
  5883. currentStatus = Preparing; //OCPP Status: Preparing
  5884. }
  5885. else if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_CHARGING) //SYS_MODE_CHARGING
  5886. {
  5887. currentStatus = Charging; //OCPP Status: Charging
  5888. }
  5889. else if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_COMPLETE) //SYS_MODE_COMPLETE
  5890. {
  5891. currentStatus = Finishing; //OCPP Status: Finishing
  5892. }
  5893. else if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_TERMINATING) // S_TERMINATING ---> SuspendedEV
  5894. {
  5895. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PilotState == CP_STATE_B))
  5896. currentStatus = SuspendedEV; //OCPP Status: SuspendedEV
  5897. else
  5898. currentStatus = SuspendedEVSE; //OCPP Status: SuspendedEVSE
  5899. }
  5900. 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
  5901. {
  5902. currentStatus = Unavailable; //OCPP Status: Unavailable
  5903. }
  5904. else if ((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_FAULT) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_ALARM)) //S_ALARM,S_FAULT ---> Faulted
  5905. {
  5906. currentStatus = Faulted; //OCPP Status: Faulted
  5907. }
  5908. else if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_RESERVATION) // ---> Reserved
  5909. {
  5910. currentStatus = Reserved; //OCPP Status: Reserved
  5911. }
  5912. }//end of the same index
  5913. }//end of for AC_QUANTITY
  5914. }
  5915. //it's option
  5916. if(((strstr((char *)ShmOCPP16Data->StatusNotification[gun_index].Status, ChargePointStatusStr[currentStatus]) != NULL) || (((currentStatus == SuspendedEV) || (currentStatus == SuspendedEVSE)) && ShmOCPP16Data->CsMsg.bits[gun_index].RemoteStopTransactionReq)) &&
  5917. !cpinitateMsg.bits[gun_index].TriggerStatusNotificationReq &&
  5918. (strcmp((const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StatusNotificationPeriodically].ItemData, "TRUE") != 0))
  5919. {
  5920. isStateChanged = FALSE;
  5921. }
  5922. cpinitateMsg.bits[gun_index].TriggerStatusNotificationReq = 0;
  5923. strcpy((char *)ShmOCPP16Data->StatusNotification[gun_index].Timestamp, buf);
  5924. strcpy((char *)ShmOCPP16Data->StatusNotification[gun_index].VendorId, (char*)ShmSysConfigAndInfo->SysConfig.chargePointVendor);
  5925. strcpy((char *)ShmOCPP16Data->StatusNotification[gun_index].Status, ChargePointStatusStr[currentStatus]);
  5926. isContentIllegal = TRUE;
  5927. for(int index = 0; index < ARRAY_SIZE(ChargePointErrorCodeStr); index++)
  5928. {
  5929. if(strcmp((char *)ShmOCPP16Data->StatusNotification[gun_index].ErrorCode, ChargePointErrorCodeStr[index])==0)
  5930. {
  5931. isContentIllegal = FALSE;
  5932. break;
  5933. }
  5934. }
  5935. if(isContentIllegal)
  5936. {
  5937. //DEBUG_WARN("Detect illegal ErrorCode: %s \n",(char *)ShmOCPP16Data->StatusNotification[gun_index].ErrorCode);
  5938. strcpy((char *)ShmOCPP16Data->StatusNotification[gun_index].ErrorCode, ChargePointErrorCodeStr[6]);
  5939. }
  5940. random_uuid(guid);
  5941. sprintf(message, "[%d,\"%s\",\"StatusNotification\",{\"connectorId\":%d,\"errorCode\":\"%s\",\"info\":\"%s\",\"status\":\"%s\",\"timestamp\":\"%s\",\"vendorId\":\"%s\",\"vendorErrorCode\":\"%s\"}]"
  5942. , MESSAGE_TYPE_CALL
  5943. , guid
  5944. , ShmOCPP16Data->StatusNotification[gun_index].ConnectorId
  5945. , ShmOCPP16Data->StatusNotification[gun_index].ErrorCode
  5946. , ShmOCPP16Data->StatusNotification[gun_index].Info
  5947. , ShmOCPP16Data->StatusNotification[gun_index].Status
  5948. , ShmOCPP16Data->StatusNotification[gun_index].Timestamp
  5949. , ShmOCPP16Data->StatusNotification[gun_index].VendorId
  5950. , ShmOCPP16Data->StatusNotification[gun_index].VendorErrorCode);
  5951. if((server_sign == TRUE) && isStateChanged)
  5952. {
  5953. cpinitateMsg.bits[gun_index].StatusNotificationReq = 0;
  5954. cpinitateMsg.bits[gun_index].TriggerStatusNotificationReq = 0;
  5955. LWS_Send(message);
  5956. sprintf(tempdata, "StatusNotification,%d", (gun_index));
  5957. 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*/)
  5958. {
  5959. //DEBUG_ERROR("statusNotification mapitem pass");
  5960. result = PASS;
  5961. }
  5962. }
  5963. else
  5964. {
  5965. cpinitateMsg.bits[gun_index].StatusNotificationReq = 0;
  5966. cpinitateMsg.bits[gun_index].TriggerStatusNotificationReq = 0;
  5967. result = PASS;
  5968. }
  5969. return result;
  5970. }
  5971. int sendStopTransactionRequest(int gun_index)
  5972. {
  5973. mtrace();
  5974. int result = FAIL;
  5975. //char message[1500]={0};
  5976. char guid[37]={0};
  5977. char tempdata[65]={0};
  5978. int tempIndex = 0;
  5979. char TempStopTransaction[256];
  5980. sprintf(TempStopTransaction, "/Storage/OCPP/TempStopTransaction_%d", (gun_index+1));
  5981. //int idx_sample=0;
  5982. DEBUG_INFO("sendStopTransactionRequest \n");
  5983. memset(queuedata, 0, ARRAY_SIZE(queuedata));
  5984. memset(&ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0], 0, ARRAY_SIZE(ShmOCPP16Data->StopTransaction[gun_index].TransactionData));
  5985. //=========================== ENERGY_ACTIVE_IMPORT_REGISTER =======================================
  5986. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DCcc
  5987. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  5988. {
  5989. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  5990. {
  5991. tempIndex = ((gun_index==2) ? 1: 0);
  5992. }
  5993. else
  5994. {
  5995. tempIndex = gun_index;
  5996. }
  5997. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  5998. {
  5999. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  6000. {
  6001. ShmOCPP16Data->StopTransaction[gun_index].MeterStop = (int)(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PowerConsumption*1000);
  6002. }
  6003. }// END OF CHAdeMO_QUANTITY
  6004. }
  6005. else if(gunType[gun_index] == GUN_TYPE_CCS)
  6006. {
  6007. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  6008. {
  6009. tempIndex = ((gun_index==2) ? 1: 0);
  6010. }
  6011. else
  6012. {
  6013. tempIndex = gun_index;
  6014. }
  6015. for (int index = 0; index < CCS_QUANTITY; index++)
  6016. {
  6017. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  6018. {
  6019. ShmOCPP16Data->StopTransaction[gun_index].MeterStop = (int)(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PowerConsumption*1000);
  6020. }
  6021. }// END OF CCS_QUANTITY
  6022. }
  6023. else if(gunType[gun_index] == GUN_TYPE_GBT)
  6024. {
  6025. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  6026. {
  6027. tempIndex = ((gun_index==2) ? 1: 0);
  6028. }
  6029. else
  6030. {
  6031. tempIndex = gun_index;
  6032. }
  6033. for (int index = 0; index < GB_QUANTITY; index++)
  6034. {
  6035. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  6036. {
  6037. ShmOCPP16Data->StopTransaction[gun_index].MeterStop = (int)(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PowerConsumption*1000);
  6038. }
  6039. }// END OF GB_QUANTITY
  6040. }
  6041. else if(gunType[gun_index] == GUN_TYPE_DO)
  6042. {
  6043. tempIndex = gun_index;
  6044. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  6045. {
  6046. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  6047. {
  6048. ShmOCPP16Data->StopTransaction[gun_index].MeterStop = (int)(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PowerConsumption*1000);
  6049. }
  6050. }// END OF GB_QUANTITY
  6051. }
  6052. else
  6053. {
  6054. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  6055. {
  6056. tempIndex = 2;
  6057. }
  6058. else
  6059. {
  6060. tempIndex = gun_index;
  6061. }
  6062. for (int index = 0; index < AC_QUANTITY; index++)
  6063. {
  6064. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  6065. {
  6066. ShmOCPP16Data->StopTransaction[gun_index].MeterStop = (int)(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PowerConsumption*1000);
  6067. }
  6068. }// END OF AC_QUANTITY
  6069. }
  6070. //====================================== Stop Transaction Time =====================================================
  6071. struct timeval tmnow;
  6072. struct tm *tm;
  6073. char buf[28];//, usec_buf[6];
  6074. gettimeofday(&tmnow, NULL);
  6075. time_t t;
  6076. t = time(NULL);
  6077. /*UTC time and date*/
  6078. tm = gmtime(&t);
  6079. strftime(buf,28,"%Y-%m-%dT%H:%M:%SZ", tm);
  6080. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].Timestamp,buf);
  6081. ShmOCPP16Data->StopTransaction[gun_index].TransactionId = ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId;
  6082. random_uuid(guid);
  6083. /***********************************transactionData******************************************************/
  6084. memset(ShmOCPP16Data->StopTransaction[gun_index].TransactionData, 0, sizeof(struct StructMeterValue));
  6085. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].TimeStamp, buf);
  6086. //=================================
  6087. // Transaction_Begin
  6088. //=================================
  6089. //=================================
  6090. // Transaction_End
  6091. //=================================
  6092. // ================================= Current.Import L1 ===============================================
  6093. if(strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Current.Import") != NULL)
  6094. {
  6095. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G : GBT DC
  6096. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  6097. {
  6098. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  6099. {
  6100. tempIndex = ((gun_index==2) ? 1: 0);
  6101. }
  6102. else
  6103. {
  6104. tempIndex = gun_index;
  6105. }
  6106. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  6107. {
  6108. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  6109. {
  6110. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargingCurrent );// PresentChargingCurrent is 0~6553.5 amp
  6111. }
  6112. }// End of for CHAdeMO_QUANTITY
  6113. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase,PhaseStr[L3_N]);
  6114. }
  6115. else if(gunType[gun_index] == GUN_TYPE_CCS)
  6116. {
  6117. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  6118. {
  6119. tempIndex = ((gun_index==2) ? 1: 0);
  6120. }
  6121. else
  6122. {
  6123. tempIndex = gun_index;
  6124. }
  6125. for (int index = 0; index < CCS_QUANTITY; index++)
  6126. {
  6127. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  6128. {
  6129. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargingCurrent );// PresentChargingCurrent is 0~6553.5 amp
  6130. }
  6131. }// End of for CCS_QUANTITY
  6132. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase,PhaseStr[L3_N]);
  6133. }
  6134. else if(gunType[gun_index] == GUN_TYPE_GBT)
  6135. {
  6136. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  6137. {
  6138. tempIndex = ((gun_index==2) ? 1: 0);
  6139. }
  6140. else
  6141. {
  6142. tempIndex = gun_index;
  6143. }
  6144. for (int index = 0; index < GB_QUANTITY; index++)
  6145. {
  6146. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  6147. {
  6148. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingCurrent );// PresentChargingCurrent is 0~6553.5 amp
  6149. }
  6150. }// End of for GB_QUANTITY
  6151. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase,PhaseStr[L3_N]);
  6152. }
  6153. else if(gunType[gun_index] == GUN_TYPE_DO)
  6154. {
  6155. tempIndex = gun_index;
  6156. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  6157. {
  6158. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  6159. {
  6160. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PresentChargingCurrent );// PresentChargingCurrent is 0~6553.5 amp
  6161. }
  6162. }
  6163. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase,PhaseStr[L3_N]);
  6164. }
  6165. else
  6166. {
  6167. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  6168. {
  6169. tempIndex = 2;
  6170. }
  6171. else
  6172. {
  6173. tempIndex = gun_index;
  6174. }
  6175. for (int index = 0; index < AC_QUANTITY; index++)
  6176. {
  6177. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  6178. {
  6179. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingCurrent );// 0~6553.5 amp for EVSE
  6180. }
  6181. }// End of for AC_QUANTITY
  6182. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase,PhaseStr[L1_N]);
  6183. }
  6184. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  6185. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Format,ValueFormatStr[Raw]);
  6186. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Measurand,MeasurandStr[Current_Import]);
  6187. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Location,LocationStr[Location_Outlet]);
  6188. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Unit,UnitOfMeasureStr[UnitOfMeasure_A]);
  6189. }
  6190. // ================================= Energy.Active.Import.Interval ==============================================
  6191. if(strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Energy.Active.Import.Interval") != NULL)
  6192. {
  6193. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  6194. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  6195. {
  6196. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  6197. {
  6198. tempIndex = ((gun_index==2) ? 1: 0);
  6199. }
  6200. else
  6201. {
  6202. tempIndex = gun_index;
  6203. }
  6204. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  6205. {
  6206. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  6207. {
  6208. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Value, "%.3f" ,(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PowerConsumption - periousPeriodicPowerConsumption[gun_index]));// PresentChargedEnergy is 0~6553.5 kWh
  6209. periousPeriodicPowerConsumption[gun_index] = ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PowerConsumption;
  6210. }
  6211. }// END OF CHAdeMO_QUANTITY
  6212. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase,PhaseStr[L3_N]);
  6213. }
  6214. else if(gunType[gun_index] == GUN_TYPE_CCS)
  6215. {
  6216. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  6217. {
  6218. tempIndex = ((gun_index==2) ? 1: 0);
  6219. }
  6220. else
  6221. {
  6222. tempIndex = gun_index;
  6223. }
  6224. for (int index = 0; index < CCS_QUANTITY; index++)
  6225. {
  6226. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  6227. {
  6228. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Value, "%.3f" ,(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PowerConsumption - periousPeriodicPowerConsumption[gun_index]));// PresentChargedEnergy is 0~6553.5 kWh
  6229. periousPeriodicPowerConsumption[gun_index] = ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PowerConsumption;
  6230. }
  6231. }// END OF CCS_QUANTITY
  6232. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase,PhaseStr[L3_N]);
  6233. }
  6234. else if(gunType[gun_index] == GUN_TYPE_GBT)
  6235. {
  6236. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  6237. {
  6238. tempIndex = ((gun_index==2) ? 1: 0);
  6239. }
  6240. else
  6241. {
  6242. tempIndex = gun_index;
  6243. }
  6244. for (int index = 0; index < GB_QUANTITY; index++)
  6245. {
  6246. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  6247. {
  6248. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Value, "%.3f" ,(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PowerConsumption - periousPeriodicPowerConsumption[gun_index]));// PresentChargedEnergy is 0~6553.5 kWh
  6249. periousPeriodicPowerConsumption[gun_index] = ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PowerConsumption;
  6250. }
  6251. }// END OF GB_QUANTITY
  6252. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase,PhaseStr[L3_N]);
  6253. }
  6254. else if(gunType[gun_index] == GUN_TYPE_DO)
  6255. {
  6256. tempIndex = gun_index;
  6257. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  6258. {
  6259. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  6260. {
  6261. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Value, "%.3f" ,(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PowerConsumption - periousPeriodicPowerConsumption[gun_index]));// PresentChargedEnergy is 0~6553.5 kWh
  6262. periousPeriodicPowerConsumption[gun_index] = ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PowerConsumption;
  6263. }
  6264. }
  6265. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase,PhaseStr[L3_N]);
  6266. }
  6267. else
  6268. {
  6269. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  6270. {
  6271. tempIndex = 2;
  6272. }
  6273. else
  6274. {
  6275. tempIndex = gun_index;
  6276. }
  6277. for (int index = 0; index < AC_QUANTITY; index++)
  6278. {
  6279. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  6280. {
  6281. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Value, "%.3f" ,(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PowerConsumption - periousPeriodicPowerConsumption[gun_index]));// PresentChargedEnergy is 0~6553.5 kWh
  6282. periousPeriodicPowerConsumption[gun_index] = ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PowerConsumption;
  6283. }
  6284. }// END OF AC_QUANTITY
  6285. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase,PhaseStr[L1_N]);
  6286. }
  6287. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  6288. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Format,ValueFormatStr[Raw]);
  6289. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Measurand,MeasurandStr[Energy_Active_Import_Interval]);
  6290. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Location,LocationStr[Location_Outlet]);
  6291. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Unit,UnitOfMeasureStr[UnitOfMeasure_kWh]);
  6292. }
  6293. //=================================== Power.Active.Import ==================================================
  6294. if(strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Power.Active.Import") != NULL)
  6295. {
  6296. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  6297. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  6298. {
  6299. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  6300. {
  6301. tempIndex = ((gun_index==2) ? 1: 0);
  6302. }
  6303. else
  6304. {
  6305. tempIndex = gun_index;
  6306. }
  6307. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  6308. {
  6309. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  6310. {
  6311. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargingPower );// PresentChargingPower is 0~6553.5 kW
  6312. }
  6313. } // End for CHAdeMO_QUANTITY
  6314. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase,PhaseStr[L3_N]);
  6315. }
  6316. else if(gunType[gun_index] == GUN_TYPE_CCS)
  6317. {
  6318. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  6319. {
  6320. tempIndex = ((gun_index==2) ? 1: 0);
  6321. }
  6322. else
  6323. {
  6324. tempIndex = gun_index;
  6325. }
  6326. for (int index = 0; index < CCS_QUANTITY; index++)
  6327. {
  6328. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  6329. {
  6330. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargingPower );// PresentChargingPower is 0~6553.5 kW
  6331. }
  6332. } // END for CCS_QUANTITY
  6333. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase,PhaseStr[L3_N]);
  6334. }
  6335. else if(gunType[gun_index] == GUN_TYPE_GBT)
  6336. {
  6337. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  6338. {
  6339. tempIndex = ((gun_index==2) ? 1: 0);
  6340. }
  6341. else
  6342. {
  6343. tempIndex = gun_index;
  6344. }
  6345. for (int index = 0; index < GB_QUANTITY; index++)
  6346. {
  6347. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  6348. {
  6349. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingPower );// PresentChargingPower is 0~6553.5 kW
  6350. }
  6351. }// END for GB_QUANTITY
  6352. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase,PhaseStr[L3_N]);
  6353. }
  6354. else if(gunType[gun_index] == GUN_TYPE_DO)
  6355. {
  6356. tempIndex = gun_index;
  6357. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  6358. {
  6359. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  6360. {
  6361. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PresentChargingPower );// PresentChargingPower is 0~6553.5 kW
  6362. }
  6363. }
  6364. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase,PhaseStr[L3_N]);
  6365. }
  6366. else
  6367. {
  6368. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  6369. {
  6370. tempIndex = 2;
  6371. }
  6372. else
  6373. {
  6374. tempIndex = gun_index;
  6375. }
  6376. for (int index = 0; index < AC_QUANTITY; index++)
  6377. {
  6378. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  6379. {
  6380. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingPower );// PresentChargingPower is 0~6553.5 kW
  6381. }
  6382. } // END for AC_QUANTITY
  6383. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase,PhaseStr[L1_N]);
  6384. }
  6385. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  6386. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Format,ValueFormatStr[Raw]);
  6387. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Measurand,MeasurandStr[Power_Active_Import]);
  6388. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Location,LocationStr[Location_Outlet]);
  6389. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Unit,UnitOfMeasureStr[UnitOfMeasure_kW/*UnitOfMeasure_kWh*/]);
  6390. }
  6391. //============================ Voltage L1 ====================================
  6392. if(strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Voltage") != NULL)
  6393. {
  6394. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  6395. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  6396. {
  6397. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  6398. {
  6399. tempIndex = ((gun_index==2) ? 1: 0);
  6400. }
  6401. else
  6402. {
  6403. tempIndex = gun_index;
  6404. }
  6405. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  6406. {
  6407. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  6408. {
  6409. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargingVoltage );// PresentChargingVoltage is 0~6553.5 volt
  6410. }
  6411. } // END OF FOR CHAdeMO_QUANTITY
  6412. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase,PhaseStr[L3_N]);
  6413. }
  6414. else if(gunType[gun_index] == GUN_TYPE_CCS)
  6415. {
  6416. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  6417. {
  6418. tempIndex = ((gun_index==2) ? 1: 0);
  6419. }
  6420. else
  6421. {
  6422. tempIndex = gun_index;
  6423. }
  6424. for (int index = 0; index < CCS_QUANTITY; index++)
  6425. {
  6426. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  6427. {
  6428. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargingVoltage );// PresentChargingVoltage is 0~6553.5 volt
  6429. }
  6430. } // END OF FOR CCS_QUANTITY
  6431. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase,PhaseStr[L3_N]);
  6432. }
  6433. else if(gunType[gun_index] == GUN_TYPE_GBT)
  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 < GB_QUANTITY; index++)
  6444. {
  6445. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  6446. {
  6447. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingVoltage );// PresentChargingVoltage is 0~6553.5 volt
  6448. }
  6449. } // END OF FOR GB_QUANTITY
  6450. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase,PhaseStr[L3_N]);
  6451. }
  6452. else if(gunType[gun_index] == GUN_TYPE_DO)
  6453. {
  6454. tempIndex = gun_index;
  6455. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  6456. {
  6457. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  6458. {
  6459. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PresentChargingVoltage );// PresentChargingVoltage is 0~6553.5 volt
  6460. }
  6461. }
  6462. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase,PhaseStr[L3_N]);
  6463. }
  6464. else
  6465. {
  6466. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  6467. {
  6468. tempIndex = 2;
  6469. }
  6470. else
  6471. {
  6472. tempIndex = gun_index;
  6473. }
  6474. for (int index = 0; index < AC_QUANTITY; index++)
  6475. {
  6476. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  6477. {
  6478. 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
  6479. }
  6480. } // END OF FOR AC_QUANTITY
  6481. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase,PhaseStr[L1_N]);
  6482. }
  6483. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  6484. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Format,ValueFormatStr[Raw]);
  6485. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Measurand,MeasurandStr[Voltage]);
  6486. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Location,LocationStr[Location_Outlet]);
  6487. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Unit,UnitOfMeasureStr[UnitOfMeasure_V]);
  6488. }
  6489. //====================== End SoC ================================
  6490. if(strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, MeasurandStr[SoC]) != NULL)
  6491. {
  6492. //J : CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  6493. 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))
  6494. {
  6495. if((ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0') && (gunType[gun_index] != GUN_TYPE_DO))
  6496. {
  6497. tempIndex = ((gun_index==2) ? 1: 0);
  6498. }
  6499. else
  6500. {
  6501. tempIndex = gun_index;
  6502. }
  6503. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  6504. {
  6505. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  6506. {
  6507. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  6508. {
  6509. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].EvBatterySoc );// 0~100%
  6510. }
  6511. }
  6512. }
  6513. else if(gunType[gun_index] == GUN_TYPE_CCS)
  6514. {
  6515. for (int index = 0; index < CCS_QUANTITY; index++)
  6516. {
  6517. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  6518. {
  6519. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].EvBatterySoc );// 0~100%
  6520. }
  6521. }
  6522. }
  6523. else if(gunType[gun_index] == GUN_TYPE_GBT)
  6524. {
  6525. for (int index = 0; index < GB_QUANTITY; index++)
  6526. {
  6527. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  6528. {
  6529. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].EvBatterySoc );// 0~100%
  6530. }
  6531. }
  6532. }
  6533. else if(gunType[gun_index] == GUN_TYPE_DO)
  6534. {
  6535. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  6536. {
  6537. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  6538. {
  6539. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.EvBatterySoc );// 0~100%
  6540. }
  6541. }
  6542. }
  6543. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  6544. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Format,ValueFormatStr[Raw]);
  6545. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Measurand,MeasurandStr[SoC/*Energy_Reactive_Export_Register*/]);
  6546. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Phase,PhaseStr[L3_N]);
  6547. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Location,LocationStr[Location_EV]);
  6548. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Unit,UnitOfMeasureStr[UnitOfMeasure_Percent/*UnitOfMeasure_kWh*/]);
  6549. } // END FOR DC CASE
  6550. }
  6551. // ================================= Current.Import L2 ===============================================
  6552. if(strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Current.Import") != NULL)
  6553. {
  6554. // AC 3 phse L2 current
  6555. if((gunType[gun_index] == GUN_TYPE_AC) && ((ShmSysConfigAndInfo->SysConfig.ModelName[2]=='Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='W') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='D')))
  6556. {
  6557. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  6558. {
  6559. tempIndex = 2;
  6560. }
  6561. else
  6562. {
  6563. tempIndex = gun_index;
  6564. }
  6565. for (int index = 0; index < AC_QUANTITY; index++)
  6566. {
  6567. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  6568. {
  6569. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingCurrentL2 );// 0~6553.5 amp for EVSE
  6570. }
  6571. }// End of for AC_QUANTITY
  6572. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Phase,PhaseStr[L2_N]);
  6573. }
  6574. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  6575. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Format,ValueFormatStr[Raw]);
  6576. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Measurand,MeasurandStr[Current_Import]);
  6577. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Location,LocationStr[Location_Outlet]);
  6578. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Unit,UnitOfMeasureStr[UnitOfMeasure_A]);
  6579. }
  6580. // ================================= Current.Import L3 ===============================================
  6581. if(strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Current.Import") != NULL)
  6582. {
  6583. // AC 3 phse L3 current
  6584. if((gunType[gun_index] == GUN_TYPE_AC) && ((ShmSysConfigAndInfo->SysConfig.ModelName[2]=='Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='W') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='D')))
  6585. {
  6586. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  6587. {
  6588. tempIndex = 2;
  6589. }
  6590. else
  6591. {
  6592. tempIndex = gun_index;
  6593. }
  6594. for (int index = 0; index < AC_QUANTITY; index++)
  6595. {
  6596. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  6597. {
  6598. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingCurrentL3 );// 0~6553.5 amp for EVSE
  6599. }
  6600. }// End of for AC_QUANTITY
  6601. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Phase,PhaseStr[L3_N]);
  6602. }
  6603. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  6604. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Format,ValueFormatStr[Raw]);
  6605. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Measurand,MeasurandStr[Current_Import]);
  6606. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Location,LocationStr[Location_Outlet]);
  6607. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Unit,UnitOfMeasureStr[UnitOfMeasure_A]);
  6608. }
  6609. //============================ Voltage L2 ====================================
  6610. if(strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Voltage") != NULL)
  6611. {
  6612. // AC 3 phse L2 voltage
  6613. if((gunType[gun_index] == GUN_TYPE_AC) && ((ShmSysConfigAndInfo->SysConfig.ModelName[2]=='Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='W') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='D')))
  6614. {
  6615. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  6616. {
  6617. tempIndex = 2;
  6618. }
  6619. else
  6620. {
  6621. tempIndex = gun_index;
  6622. }
  6623. for (int index = 0; index < AC_QUANTITY; index++)
  6624. {
  6625. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  6626. {
  6627. 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
  6628. }
  6629. } // END OF FOR AC_QUANTITY
  6630. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Phase,PhaseStr[L2_N]);
  6631. }
  6632. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  6633. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Format,ValueFormatStr[Raw]);
  6634. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Measurand,MeasurandStr[Voltage]);
  6635. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Location,LocationStr[Location_Outlet]);
  6636. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Unit,UnitOfMeasureStr[UnitOfMeasure_V]);
  6637. }
  6638. //============================ Voltage L3 ====================================
  6639. if(strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Voltage") != NULL)
  6640. {
  6641. // AC 3 phse L3 voltage
  6642. if((gunType[gun_index] == GUN_TYPE_AC) && ((ShmSysConfigAndInfo->SysConfig.ModelName[2]=='Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='W') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='D')))
  6643. {
  6644. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  6645. {
  6646. tempIndex = 2;
  6647. }
  6648. else
  6649. {
  6650. tempIndex = gun_index;
  6651. }
  6652. for (int index = 0; index < AC_QUANTITY; index++)
  6653. {
  6654. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  6655. {
  6656. 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
  6657. }
  6658. } // END OF FOR AC_QUANTITY
  6659. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Phase,PhaseStr[L3_N]);
  6660. }
  6661. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  6662. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Format,ValueFormatStr[Raw]);
  6663. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Measurand,MeasurandStr[Voltage]);
  6664. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Location,LocationStr[Location_Outlet]);
  6665. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Unit,UnitOfMeasureStr[UnitOfMeasure_V]);
  6666. }
  6667. //====================== Start SoC ================================
  6668. if(strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, MeasurandStr[SoC]) != NULL)
  6669. {
  6670. //J : CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  6671. 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))
  6672. {
  6673. if((ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0') && (gunType[gun_index] != GUN_TYPE_DO))
  6674. {
  6675. tempIndex = ((gun_index==2) ? 1: 0);
  6676. }
  6677. else
  6678. {
  6679. tempIndex = gun_index;
  6680. }
  6681. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  6682. {
  6683. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  6684. {
  6685. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  6686. {
  6687. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].EvBatteryStartSoc );// 0~100%
  6688. }
  6689. }
  6690. }
  6691. else if(gunType[gun_index] == GUN_TYPE_CCS)
  6692. {
  6693. for (int index = 0; index < CCS_QUANTITY; index++)
  6694. {
  6695. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  6696. {
  6697. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].EvBatteryStartSoc );// 0~100%
  6698. }
  6699. }
  6700. }
  6701. else if(gunType[gun_index] == GUN_TYPE_GBT)
  6702. {
  6703. for (int index = 0; index < GB_QUANTITY; index++)
  6704. {
  6705. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  6706. {
  6707. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].EvBatteryStartSoc );// 0~100%
  6708. }
  6709. }
  6710. }
  6711. else if(gunType[gun_index] == GUN_TYPE_DO)
  6712. {
  6713. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  6714. {
  6715. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  6716. {
  6717. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.EvBatteryStartSoc );// 0~100%
  6718. }
  6719. }
  6720. }
  6721. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Context,ReadingContextStr[ReadingContext_Transaction_Begin]);
  6722. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Format,ValueFormatStr[Raw]);
  6723. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Measurand,MeasurandStr[SoC/*Energy_Reactive_Export_Register*/]);
  6724. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Phase,PhaseStr[L3_N]);
  6725. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Location,LocationStr[Location_EV]);
  6726. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Unit,UnitOfMeasureStr[UnitOfMeasure_Percent/*UnitOfMeasure_kWh*/]);
  6727. } // END FOR DC CASE
  6728. }
  6729. //================================================ Message create ====================================================
  6730. json_object *StopTransaction = json_object_new_object();
  6731. json_object *transactionDatas = json_object_new_array();
  6732. json_object *sampledValues = json_object_new_array();
  6733. if(strlen((char*)ShmOCPP16Data->StopTransaction[gun_index].IdTag) > 0)
  6734. json_object_object_add(StopTransaction, "idTag", json_object_new_string((char*)ShmOCPP16Data->StopTransaction[gun_index].IdTag));
  6735. json_object_object_add(StopTransaction, "meterStop", json_object_new_int(ShmOCPP16Data->StopTransaction[gun_index].MeterStop));
  6736. json_object_object_add(StopTransaction, "transactionId", json_object_new_int(ShmOCPP16Data->StopTransaction[gun_index].TransactionId));
  6737. json_object_object_add(StopTransaction, "timestamp", json_object_new_string((char*)ShmOCPP16Data->StopTransaction[gun_index].Timestamp));
  6738. if(strlen((char*)ShmOCPP16Data->StopTransaction[gun_index].StopReason) > 0)
  6739. json_object_object_add(StopTransaction, "reason", json_object_new_string((char*)ShmOCPP16Data->StopTransaction[gun_index].StopReason));
  6740. for(int idxTrans = 0;idxTrans<ARRAY_SIZE(ShmOCPP16Data->StopTransaction[gun_index].TransactionData);idxTrans++)
  6741. {
  6742. json_object *transactionData = json_object_new_object();
  6743. json_object_object_add(transactionData, "timestamp", json_object_new_string((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].TimeStamp));
  6744. for(int idx=0;idx<ARRAY_SIZE(ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue);idx++)
  6745. {
  6746. if(strlen((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Value) > 0)
  6747. {
  6748. json_object *sampledValue = json_object_new_object();
  6749. json_object_object_add(sampledValue, "value", json_object_new_string((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Value));
  6750. if(strlen((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Context) > 0)
  6751. json_object_object_add(sampledValue, "context", json_object_new_string((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Context));
  6752. if(strlen((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Format) > 0)
  6753. json_object_object_add(sampledValue, "format", json_object_new_string((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Format));
  6754. if(strlen((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Measurand) > 0)
  6755. json_object_object_add(sampledValue, "measurand", json_object_new_string((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Measurand));
  6756. if(strlen((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Phase) > 0)
  6757. json_object_object_add(sampledValue, "phase", json_object_new_string((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Phase));
  6758. if(strlen((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Location) > 0)
  6759. json_object_object_add(sampledValue, "location", json_object_new_string((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Location));
  6760. if(strlen((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Unit) > 0)
  6761. json_object_object_add(sampledValue, "unit", json_object_new_string((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Unit));
  6762. json_object_array_add(sampledValues, sampledValue);
  6763. }
  6764. }
  6765. json_object_object_add(transactionData, "sampledValue", sampledValues);
  6766. json_object_array_add(transactionDatas, transactionData);
  6767. }
  6768. json_object_object_add(StopTransaction, "transactionData", transactionDatas);
  6769. sprintf(queuedata, "%d,[%d,\"%s\",\"StopTransaction\",%s]",(gun_index+1)
  6770. ,MESSAGE_TYPE_CALL
  6771. ,guid
  6772. ,json_object_to_json_string_ext(StopTransaction, JSON_C_TO_STRING_PLAIN));
  6773. json_object_put(StopTransaction);
  6774. #if 1 // for TempStopTransaction
  6775. //Delete TempStopTransaction
  6776. if((access(TempStopTransaction,F_OK))!=-1)
  6777. {
  6778. remove(TempStopTransaction); // remove file "TempStopTransaction"
  6779. }
  6780. #endif
  6781. #if 1
  6782. sprintf(tempdata, "StopTransaction,%d", (gun_index));
  6783. if(hashmap_operation(HASH_OP_ADD, guid, tempdata) == 1)
  6784. {
  6785. result = PASS;
  6786. //DEBUG_INFO("StopTransaction mapitem pass\n");
  6787. }
  6788. #endif
  6789. queue_operation(QUEUE_OPERATION_ADD, guid, queuedata );//addq(guid, queuedata); ---> remove temporally
  6790. OCPP_insert_transaction_msg(NO, queuedata);
  6791. //----------------------------replace queue StopTransaction TransactionId ---------------------------//
  6792. //int gettransactionId = GetTransactionId(gun_index+1, ShmOCPP16Data->StopTransaction[gun_index].IdTag);
  6793. int gettransactionId = GetTransactionId(gun_index+1, ShmOCPP16Data->StartTransaction[gun_index].IdTag, TRUE);
  6794. if((ShmOCPP16Data->StopTransaction[gun_index].TransactionId != 0) && (gettransactionId != 0))
  6795. {
  6796. //SetTransactionIdZero(ShmOCPP16Data->StopTransaction[gun_index].TransactionId);
  6797. }
  6798. //for test
  6799. //ShmOCPP16Data->CpMsg.bits[gun_index].StopTransactionReq = 0;
  6800. return result;
  6801. }
  6802. int sendMeterValuesRequest(int gun_index, ReadingContext dataType)
  6803. {
  6804. mtrace();
  6805. int result = FAIL;
  6806. char guid[37]={0};
  6807. char tempdata[65]={0};
  6808. int tempIndex = 0;
  6809. DEBUG_INFO("sendMeterValuesRequest ...\n");
  6810. memset(queuedata, 0, ARRAY_SIZE(queuedata));
  6811. memset(&ShmOCPP16Data->MeterValues[gun_index], 0, sizeof(struct StructMeterValues));
  6812. //set value
  6813. ShmOCPP16Data->MeterValues[gun_index].ConnectorId = gun_index + 1; // gun start from 1~
  6814. ShmOCPP16Data->MeterValues[gun_index].TransactionId = (cpinitateMsg.bits[gun_index].isOnCharging?
  6815. ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId :
  6816. -1);
  6817. random_uuid(guid);
  6818. //UTC Date time
  6819. struct timeval tmnow;
  6820. struct tm *tm;
  6821. char buf[28];//, usec_buf[6];
  6822. gettimeofday(&tmnow, NULL);
  6823. time_t t;
  6824. t = time(NULL);
  6825. /*UTC time and date*/
  6826. tm = gmtime(&t);
  6827. if(dataType == ReadingContext_Sample_Clock)
  6828. {
  6829. struct tm *tmTarget;
  6830. struct timeb tbTarget;
  6831. tbTarget.time = mktime(tm);
  6832. tbTarget.time -= (atoi((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemData));
  6833. tmTarget = gmtime(&tbTarget.time);
  6834. strftime(buf,28,"%Y-%m-%dT%H:%M:%SZ", tmTarget);
  6835. }
  6836. else
  6837. {
  6838. strftime(buf,28,"%Y-%m-%dT%H:%M:%SZ", tm);
  6839. }
  6840. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].TimeStamp, buf);
  6841. //DEBUG_INFO("ShmSysConfigAndInfo->SysConfig.ModelName[0]=%c\n", ShmSysConfigAndInfo->SysConfig.ModelName[0]);
  6842. //********************************(1)Current.Import L1************************************************/
  6843. if(((dataType == ReadingContext_Sample_Clock) && (strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, MeasurandStr[Current_Import]) != NULL)) ||
  6844. ((dataType == ReadingContext_Sample_Periodic) && (strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, MeasurandStr[Current_Import]) != NULL)) ||
  6845. (dataType == ReadingContext_Trigger))
  6846. {
  6847. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  6848. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  6849. {
  6850. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  6851. {
  6852. tempIndex = ((gun_index==2) ? 1: 0);
  6853. }
  6854. else
  6855. {
  6856. tempIndex = gun_index;
  6857. }
  6858. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  6859. {
  6860. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  6861. {
  6862. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargingCurrent );
  6863. }
  6864. }
  6865. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Phase, PhaseStr[L3_N]);
  6866. }
  6867. else if(gunType[gun_index] == GUN_TYPE_CCS)
  6868. {
  6869. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  6870. {
  6871. tempIndex = ((gun_index==2) ? 1: 0);
  6872. }
  6873. else
  6874. {
  6875. tempIndex = gun_index;
  6876. }
  6877. for (int index = 0; index < CCS_QUANTITY; index++)
  6878. {
  6879. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  6880. {
  6881. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargingCurrent );
  6882. }
  6883. }
  6884. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Phase, PhaseStr[L3_N]);
  6885. }
  6886. else if(gunType[gun_index] == GUN_TYPE_GBT)
  6887. {
  6888. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  6889. {
  6890. tempIndex = ((gun_index==2) ? 1: 0);
  6891. }
  6892. else
  6893. {
  6894. tempIndex = gun_index;
  6895. }
  6896. for (int index = 0; index < GB_QUANTITY; index++)
  6897. {
  6898. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  6899. {
  6900. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingCurrent );
  6901. }
  6902. }
  6903. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Phase, PhaseStr[L3_N]);
  6904. }
  6905. else if(gunType[gun_index] == GUN_TYPE_DO)
  6906. {
  6907. tempIndex = gun_index;
  6908. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  6909. {
  6910. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  6911. {
  6912. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PresentChargingCurrent );
  6913. }
  6914. }
  6915. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Phase, PhaseStr[L3_N]);
  6916. }
  6917. else
  6918. {
  6919. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  6920. {
  6921. tempIndex = 2;
  6922. }
  6923. else
  6924. {
  6925. tempIndex = gun_index;
  6926. }
  6927. for (int index = 0; index < AC_QUANTITY; index++)
  6928. {
  6929. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  6930. {
  6931. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingCurrent );
  6932. }
  6933. }
  6934. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Phase, PhaseStr[L1_N]);
  6935. }
  6936. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Context, ReadingContextStr[dataType]);
  6937. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Format, ValueFormatStr[Raw]);
  6938. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Measurand, MeasurandStr[Current_Import]);
  6939. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Location, LocationStr[Location_Outlet]);
  6940. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Unit,UnitOfMeasureStr[UnitOfMeasure_A]);
  6941. }
  6942. //********************************(2)Energy.Active.Import.Register ************************************************/
  6943. if(((dataType == ReadingContext_Sample_Clock) && (strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, MeasurandStr[Energy_Active_Import_Register]) != NULL)) ||
  6944. ((dataType == ReadingContext_Sample_Periodic) && (strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, MeasurandStr[Energy_Active_Import_Register]) != NULL)) ||
  6945. (dataType == ReadingContext_Trigger))
  6946. {
  6947. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  6948. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  6949. {
  6950. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  6951. {
  6952. tempIndex = ((gun_index==2) ? 1: 0);
  6953. }
  6954. else
  6955. {
  6956. tempIndex = gun_index;
  6957. }
  6958. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  6959. {
  6960. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  6961. {
  6962. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PowerConsumption );
  6963. }
  6964. }
  6965. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Phase, PhaseStr[L3_N]);
  6966. }
  6967. else if(gunType[gun_index] == GUN_TYPE_CCS)
  6968. {
  6969. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  6970. {
  6971. tempIndex = ((gun_index==2) ? 1: 0);
  6972. }
  6973. else
  6974. {
  6975. tempIndex = gun_index;
  6976. }
  6977. for (int index = 0; index < CCS_QUANTITY; index++)
  6978. {
  6979. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  6980. {
  6981. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PowerConsumption );
  6982. }
  6983. }
  6984. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Phase, PhaseStr[L3_N]);
  6985. }
  6986. else if(gunType[gun_index] == GUN_TYPE_GBT)
  6987. {
  6988. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  6989. {
  6990. tempIndex = ((gun_index==2) ? 1: 0);
  6991. }
  6992. else
  6993. {
  6994. tempIndex = gun_index;
  6995. }
  6996. for (int index = 0; index < GB_QUANTITY; index++)
  6997. {
  6998. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  6999. {
  7000. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PowerConsumption );
  7001. }
  7002. }
  7003. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Phase, PhaseStr[L3_N]);
  7004. }
  7005. else if(gunType[gun_index] == GUN_TYPE_DO)
  7006. {
  7007. tempIndex = gun_index;
  7008. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  7009. {
  7010. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  7011. {
  7012. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PowerConsumption );
  7013. }
  7014. }
  7015. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Phase, PhaseStr[L3_N]);
  7016. }
  7017. else
  7018. {
  7019. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  7020. {
  7021. tempIndex = 2;
  7022. }
  7023. else
  7024. {
  7025. tempIndex = gun_index;
  7026. }
  7027. for (int index = 0; index < AC_QUANTITY; index++)
  7028. {
  7029. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  7030. {
  7031. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PowerConsumption );
  7032. }
  7033. }
  7034. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Phase, PhaseStr[L1_N]);
  7035. }
  7036. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Context, ReadingContextStr[dataType]);
  7037. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Format, ValueFormatStr[Raw]);
  7038. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Measurand, MeasurandStr[Energy_Active_Import_Register]);
  7039. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Location, LocationStr[Location_Outlet]);
  7040. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Unit,UnitOfMeasureStr[UnitOfMeasure_kWh]);
  7041. }
  7042. //****************************************************(3)Energy.Active.Import.Interval*********************************************/
  7043. if(((dataType == ReadingContext_Sample_Clock) && (strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, MeasurandStr[Energy_Active_Import_Interval]) != NULL)) ||
  7044. ((dataType == ReadingContext_Sample_Periodic) && (strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, MeasurandStr[Energy_Active_Import_Interval]) != NULL)) ||
  7045. (dataType == ReadingContext_Trigger))
  7046. {
  7047. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  7048. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  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 < CHAdeMO_QUANTITY; index++)
  7059. {
  7060. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  7061. {
  7062. if(dataType == ReadingContext_Sample_Clock)
  7063. {
  7064. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Value, "%.3f" ,(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PowerConsumption - periousClockPowerConsumption[gun_index]));
  7065. periousClockPowerConsumption[gun_index] = ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PowerConsumption;
  7066. }
  7067. else if(dataType == ReadingContext_Sample_Periodic)
  7068. {
  7069. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Value, "%.3f" ,(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PowerConsumption - periousPeriodicPowerConsumption[gun_index]));
  7070. periousPeriodicPowerConsumption[gun_index] = ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PowerConsumption;
  7071. }
  7072. else
  7073. {
  7074. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Value, "0.000");
  7075. }
  7076. }
  7077. } // END OF FOR CHAdeMO_QUANTITY
  7078. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Phase, PhaseStr[L3_N]);
  7079. }
  7080. else if(gunType[gun_index] == GUN_TYPE_CCS)
  7081. {
  7082. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  7083. {
  7084. tempIndex = ((gun_index==2) ? 1: 0);
  7085. }
  7086. else
  7087. {
  7088. tempIndex = gun_index;
  7089. }
  7090. for (int index = 0; index < CCS_QUANTITY; index++)
  7091. {
  7092. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  7093. {
  7094. if(dataType == ReadingContext_Sample_Clock)
  7095. {
  7096. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Value, "%.3f" ,(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PowerConsumption - periousClockPowerConsumption[gun_index]));
  7097. periousClockPowerConsumption[gun_index] = ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PowerConsumption;
  7098. }
  7099. else if(dataType == ReadingContext_Sample_Periodic)
  7100. {
  7101. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Value, "%.3f" ,(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PowerConsumption - periousPeriodicPowerConsumption[gun_index]));
  7102. periousPeriodicPowerConsumption[gun_index] = ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PowerConsumption;
  7103. }
  7104. else
  7105. {
  7106. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Value, "0.000");
  7107. }
  7108. }
  7109. } // END OF CCS_QUANTITY
  7110. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Phase, PhaseStr[L3_N]);
  7111. }
  7112. else if(gunType[gun_index] == GUN_TYPE_GBT)
  7113. {
  7114. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  7115. {
  7116. tempIndex = ((gun_index==2) ? 1: 0);
  7117. }
  7118. else
  7119. {
  7120. tempIndex = gun_index;
  7121. }
  7122. for (int index = 0; index < GB_QUANTITY; index++)
  7123. {
  7124. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  7125. {
  7126. if(dataType == ReadingContext_Sample_Clock)
  7127. {
  7128. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Value, "%.3f" ,(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PowerConsumption - periousClockPowerConsumption[gun_index]));
  7129. periousClockPowerConsumption[gun_index] = ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PowerConsumption;
  7130. }
  7131. else if(dataType == ReadingContext_Sample_Periodic)
  7132. {
  7133. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Value, "%.3f" ,(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PowerConsumption - periousPeriodicPowerConsumption[gun_index]));
  7134. periousPeriodicPowerConsumption[gun_index] = ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PowerConsumption;
  7135. }
  7136. else
  7137. {
  7138. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Value, "0.000");
  7139. }
  7140. }
  7141. } // END OF GB_QUANTITY
  7142. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Phase, PhaseStr[L3_N]);
  7143. }
  7144. else if(gunType[gun_index] == GUN_TYPE_DO)
  7145. {
  7146. tempIndex = gun_index;
  7147. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  7148. {
  7149. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  7150. {
  7151. if(dataType == ReadingContext_Sample_Clock)
  7152. {
  7153. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Value, "%.3f" ,(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PowerConsumption - periousClockPowerConsumption[gun_index]));
  7154. periousClockPowerConsumption[gun_index] = ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PowerConsumption;
  7155. }
  7156. else if(dataType == ReadingContext_Sample_Periodic)
  7157. {
  7158. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Value, "%.3f" ,(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PowerConsumption - periousPeriodicPowerConsumption[gun_index]));
  7159. periousPeriodicPowerConsumption[gun_index] = ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PowerConsumption;
  7160. }
  7161. else
  7162. {
  7163. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Value, "0.000");
  7164. }
  7165. }
  7166. }
  7167. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Phase, PhaseStr[L3_N]);
  7168. }
  7169. else
  7170. {
  7171. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  7172. {
  7173. tempIndex = 2;
  7174. }
  7175. else
  7176. {
  7177. tempIndex = gun_index;
  7178. }
  7179. for (int index = 0; index < AC_QUANTITY; index++)
  7180. {
  7181. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  7182. {
  7183. if(dataType == ReadingContext_Sample_Clock)
  7184. {
  7185. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Value, "%.3f" ,(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PowerConsumption - periousClockPowerConsumption[gun_index]));
  7186. periousClockPowerConsumption[gun_index] = ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PowerConsumption;
  7187. }
  7188. else if(dataType == ReadingContext_Sample_Periodic)
  7189. {
  7190. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Value, "%.3f" ,(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PowerConsumption - periousPeriodicPowerConsumption[gun_index]));
  7191. periousPeriodicPowerConsumption[gun_index] = ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PowerConsumption;
  7192. }
  7193. else
  7194. {
  7195. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Value, "0.000");
  7196. }
  7197. }
  7198. }
  7199. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Phase, PhaseStr[L1_N]);
  7200. }
  7201. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Context, ReadingContextStr[dataType]);
  7202. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Format, ValueFormatStr[Raw]);
  7203. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Measurand, MeasurandStr[Energy_Active_Import_Interval]);
  7204. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Location, LocationStr[Location_Outlet]);
  7205. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Unit,UnitOfMeasureStr[UnitOfMeasure_kWh]);
  7206. }
  7207. //********************************(4)Power.Active.Import************************************************/
  7208. if(((dataType == ReadingContext_Sample_Clock) && (strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, MeasurandStr[Power_Active_Import]) != NULL)) ||
  7209. ((dataType == ReadingContext_Sample_Periodic) && (strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, MeasurandStr[Power_Active_Import]) != NULL)) ||
  7210. (dataType == ReadingContext_Trigger))
  7211. {
  7212. //J : CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  7213. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  7214. {
  7215. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  7216. {
  7217. tempIndex = ((gun_index==2) ? 1: 0);
  7218. }
  7219. else
  7220. {
  7221. tempIndex = gun_index;
  7222. }
  7223. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  7224. {
  7225. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  7226. {
  7227. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Value, "%.1f" , ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargingPower);
  7228. }
  7229. } // END OF FOR
  7230. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Phase, PhaseStr[L3_N]);
  7231. }
  7232. else if(gunType[gun_index] == GUN_TYPE_CCS)
  7233. {
  7234. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  7235. {
  7236. tempIndex = ((gun_index==2) ? 1: 0);
  7237. }
  7238. else
  7239. {
  7240. tempIndex = gun_index;
  7241. }
  7242. for (int index = 0; index < CCS_QUANTITY; index++)
  7243. {
  7244. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  7245. {
  7246. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Value, "%.1f" , ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargingPower);
  7247. }
  7248. }
  7249. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Phase, PhaseStr[L3_N]);
  7250. }
  7251. else if(gunType[gun_index] == GUN_TYPE_GBT)
  7252. {
  7253. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  7254. {
  7255. tempIndex = ((gun_index==2) ? 1: 0);
  7256. }
  7257. else
  7258. {
  7259. tempIndex = gun_index;
  7260. }
  7261. for (int index = 0; index < GB_QUANTITY; index++)
  7262. {
  7263. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  7264. {
  7265. //ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingPower = 100.0;
  7266. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Value, "%.1f" , ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingPower);
  7267. }
  7268. }
  7269. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Phase, PhaseStr[L3_N]);
  7270. }
  7271. else if(gunType[gun_index] == GUN_TYPE_DO)
  7272. {
  7273. tempIndex = gun_index;
  7274. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  7275. {
  7276. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  7277. {
  7278. //ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingPower = 100.0;
  7279. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Value, "%.1f" , ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PresentChargingPower);
  7280. }
  7281. }
  7282. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Phase, PhaseStr[L3_N]);
  7283. }
  7284. else
  7285. {
  7286. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  7287. {
  7288. tempIndex = 2;
  7289. }
  7290. else
  7291. {
  7292. tempIndex = gun_index;
  7293. }
  7294. for (int index = 0; index < AC_QUANTITY; index++)
  7295. {
  7296. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  7297. {
  7298. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Value, "%.1f" , ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingPower);
  7299. }
  7300. }
  7301. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Phase, PhaseStr[L1_N]);
  7302. }
  7303. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Context, ReadingContextStr[dataType]);
  7304. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Format, ValueFormatStr[Raw]);
  7305. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Measurand, MeasurandStr[Power_Active_Import]);
  7306. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Location, LocationStr[Location_Outlet]);
  7307. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Unit,UnitOfMeasureStr[UnitOfMeasure_kW]);
  7308. }
  7309. //***********************************************(5)VOLTAGE L1******************************************************/
  7310. if(((dataType == ReadingContext_Sample_Clock) && (strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, MeasurandStr[Voltage]) != NULL)) ||
  7311. ((dataType == ReadingContext_Sample_Periodic) && (strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, MeasurandStr[Voltage]) != NULL)) ||
  7312. (dataType == ReadingContext_Trigger))
  7313. {
  7314. //J : CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  7315. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  7316. {
  7317. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  7318. {
  7319. tempIndex = ((gun_index==2) ? 1: 0);
  7320. }
  7321. else
  7322. {
  7323. tempIndex = gun_index;
  7324. }
  7325. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  7326. {
  7327. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  7328. {
  7329. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargingVoltage );
  7330. }
  7331. }
  7332. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Phase, PhaseStr[L3_N]);
  7333. }
  7334. else if(gunType[gun_index] == GUN_TYPE_CCS)
  7335. {
  7336. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  7337. {
  7338. tempIndex = ((gun_index==2) ? 1: 0);
  7339. }
  7340. else
  7341. {
  7342. tempIndex = gun_index;
  7343. }
  7344. for (int index = 0; index < CCS_QUANTITY; index++)
  7345. {
  7346. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  7347. {
  7348. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargingVoltage );
  7349. }
  7350. }
  7351. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Phase, PhaseStr[L3_N]);
  7352. }
  7353. else if(gunType[gun_index] == GUN_TYPE_GBT)
  7354. {
  7355. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  7356. {
  7357. tempIndex = ((gun_index==2) ? 1: 0);
  7358. }
  7359. else
  7360. {
  7361. tempIndex = gun_index;
  7362. }
  7363. for (int index = 0; index < GB_QUANTITY; index++)
  7364. {
  7365. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  7366. {
  7367. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingVoltage );
  7368. }
  7369. }
  7370. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Phase, PhaseStr[L3_N]);
  7371. }
  7372. else if(gunType[gun_index] == GUN_TYPE_DO)
  7373. {
  7374. tempIndex = gun_index;
  7375. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  7376. {
  7377. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  7378. {
  7379. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PresentChargingVoltage );
  7380. }
  7381. }
  7382. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Phase, PhaseStr[L3_N]);
  7383. }
  7384. else
  7385. {
  7386. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  7387. {
  7388. tempIndex = 2;
  7389. }
  7390. else
  7391. {
  7392. tempIndex = gun_index;
  7393. }
  7394. for (int index = 0; index < AC_QUANTITY; index++)
  7395. {
  7396. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  7397. {
  7398. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingVoltage );
  7399. }
  7400. }
  7401. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Phase, PhaseStr[L1_N]);
  7402. }
  7403. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Context, ReadingContextStr[dataType]);
  7404. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Format, ValueFormatStr[Raw]);
  7405. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Measurand, MeasurandStr[Voltage]);
  7406. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Location, LocationStr[Location_Outlet]);
  7407. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Unit,UnitOfMeasureStr[UnitOfMeasure_V]);
  7408. }
  7409. //***********************************************(6)SOC******************************************************/
  7410. if(((dataType == ReadingContext_Sample_Clock) && (strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, MeasurandStr[SoC]) != NULL)) ||
  7411. ((dataType == ReadingContext_Sample_Periodic) && (strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, MeasurandStr[SoC]) != NULL)) ||
  7412. (dataType == ReadingContext_Trigger))
  7413. {
  7414. 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))
  7415. {
  7416. //idx_sample=5;
  7417. //sampledValue = NULL;
  7418. if((ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0') && (gunType[gun_index] != GUN_TYPE_DO))
  7419. {
  7420. tempIndex = ((gun_index==2) ? 1: 0);
  7421. }
  7422. else
  7423. {
  7424. tempIndex = gun_index;
  7425. }
  7426. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  7427. {
  7428. //tempIndex = ((gun_index==2) ? 1: 0);
  7429. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  7430. {
  7431. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  7432. {
  7433. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].EvBatterySoc );
  7434. }
  7435. }
  7436. }
  7437. else if(gunType[gun_index] == GUN_TYPE_CCS)
  7438. {
  7439. //tempIndex = ((gun_index==2) ? 1: 0);
  7440. for (int index = 0; index < CCS_QUANTITY; index++)
  7441. {
  7442. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  7443. {
  7444. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].EvBatterySoc );
  7445. }
  7446. }
  7447. }
  7448. else if(gunType[gun_index] == GUN_TYPE_GBT)
  7449. {
  7450. //tempIndex = ((gun_index==2) ? 1: 0);
  7451. for (int index = 0; index < GB_QUANTITY; index++)
  7452. {
  7453. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  7454. {
  7455. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].EvBatterySoc );
  7456. }
  7457. }
  7458. }
  7459. else if(gunType[gun_index] == GUN_TYPE_DO)
  7460. {
  7461. //tempIndex = ((gun_index==2) ? 1: 0);
  7462. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  7463. {
  7464. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  7465. {
  7466. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.EvBatterySoc );
  7467. }
  7468. }
  7469. }
  7470. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[5].Context, ReadingContextStr[dataType]);
  7471. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[5].Format, ValueFormatStr[Raw]);
  7472. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[5].Measurand, MeasurandStr[SoC]);
  7473. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[5].Phase, PhaseStr[L3_N]);
  7474. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[5].Location, LocationStr[Location_EV]);
  7475. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[5].Unit,UnitOfMeasureStr[UnitOfMeasure_Percent]);
  7476. }
  7477. }
  7478. //********************************(7)Current.Import L2************************************************/
  7479. if(((dataType == ReadingContext_Sample_Clock) && (strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, MeasurandStr[Current_Import]) != NULL)) ||
  7480. ((dataType == ReadingContext_Sample_Periodic) && (strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, MeasurandStr[Current_Import]) != NULL)) ||
  7481. (dataType == ReadingContext_Trigger))
  7482. {
  7483. // Only for AC 3 phase
  7484. if((gunType[gun_index] == GUN_TYPE_AC) && ((ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'W') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='D')))
  7485. {
  7486. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  7487. {
  7488. tempIndex = 2;
  7489. }
  7490. else
  7491. {
  7492. tempIndex = gun_index;
  7493. }
  7494. for (int index = 0; index < AC_QUANTITY; index++)
  7495. {
  7496. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  7497. {
  7498. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[6].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingCurrentL2);
  7499. }
  7500. }
  7501. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[6].Phase, PhaseStr[L2_N]);
  7502. }
  7503. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[6].Context, ReadingContextStr[dataType]);
  7504. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[6].Format, ValueFormatStr[Raw]);
  7505. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[6].Measurand, MeasurandStr[Current_Import]);
  7506. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[6].Location, LocationStr[Location_Outlet]);
  7507. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[6].Unit,UnitOfMeasureStr[UnitOfMeasure_A]);
  7508. }
  7509. //********************************(8)Current.Import L3************************************************/
  7510. if(((dataType == ReadingContext_Sample_Clock) && (strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, MeasurandStr[Current_Import]) != NULL)) ||
  7511. ((dataType == ReadingContext_Sample_Periodic) && (strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, MeasurandStr[Current_Import]) != NULL)) ||
  7512. (dataType == ReadingContext_Trigger))
  7513. {
  7514. // Only for AC 3 phase
  7515. if((gunType[gun_index] == GUN_TYPE_AC) && ((ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'W') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='D')))
  7516. {
  7517. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  7518. {
  7519. tempIndex = 2;
  7520. }
  7521. else
  7522. {
  7523. tempIndex = gun_index;
  7524. }
  7525. for (int index = 0; index < AC_QUANTITY; index++)
  7526. {
  7527. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  7528. {
  7529. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[7].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingCurrentL3);
  7530. }
  7531. }
  7532. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[7].Phase, PhaseStr[L3_N]);
  7533. }
  7534. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[7].Context, ReadingContextStr[dataType]);
  7535. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[7].Format, ValueFormatStr[Raw]);
  7536. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[7].Measurand, MeasurandStr[Current_Import]);
  7537. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[7].Location, LocationStr[Location_Outlet]);
  7538. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[7].Unit,UnitOfMeasureStr[UnitOfMeasure_A]);
  7539. }
  7540. //***********************************************(9)VOLTAGE L2******************************************************/
  7541. if(((dataType == ReadingContext_Sample_Clock) && (strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, MeasurandStr[Voltage]) != NULL)) ||
  7542. ((dataType == ReadingContext_Sample_Periodic) && (strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, MeasurandStr[Voltage]) != NULL)) ||
  7543. (dataType == ReadingContext_Trigger))
  7544. {
  7545. if((gunType[gun_index] == GUN_TYPE_AC) && ((ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'W') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='D')))
  7546. {
  7547. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  7548. {
  7549. tempIndex = 2;
  7550. }
  7551. else
  7552. {
  7553. tempIndex = gun_index;
  7554. }
  7555. for (int index = 0; index < AC_QUANTITY; index++)
  7556. {
  7557. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  7558. {
  7559. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[8].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingVoltageL2);
  7560. }
  7561. }
  7562. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[8].Phase, PhaseStr[L2_N]);
  7563. }
  7564. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[8].Context, ReadingContextStr[dataType]);
  7565. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[8].Format, ValueFormatStr[Raw]);
  7566. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[8].Measurand, MeasurandStr[Voltage]);
  7567. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[8].Location, LocationStr[Location_Outlet]);
  7568. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[8].Unit,UnitOfMeasureStr[UnitOfMeasure_V]);
  7569. }
  7570. //***********************************************(10)VOLTAGE L3******************************************************/
  7571. if(((dataType == ReadingContext_Sample_Clock) && (strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, MeasurandStr[Voltage]) != NULL)) ||
  7572. ((dataType == ReadingContext_Sample_Periodic) && (strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, MeasurandStr[Voltage]) != NULL)) ||
  7573. (dataType == ReadingContext_Trigger))
  7574. {
  7575. if((gunType[gun_index] == GUN_TYPE_AC) && ((ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'W') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='D')))
  7576. {
  7577. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  7578. {
  7579. tempIndex = 2;
  7580. }
  7581. else
  7582. {
  7583. tempIndex = gun_index;
  7584. }
  7585. for (int index = 0; index < AC_QUANTITY; index++)
  7586. {
  7587. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  7588. {
  7589. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[9].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingVoltageL3);
  7590. }
  7591. }
  7592. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[9].Phase, PhaseStr[L3_N]);
  7593. }
  7594. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[9].Context, ReadingContextStr[dataType]);
  7595. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[9].Format, ValueFormatStr[Raw]);
  7596. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[9].Measurand, MeasurandStr[Voltage]);
  7597. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[9].Location, LocationStr[Location_Outlet]);
  7598. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[9].Unit,UnitOfMeasureStr[UnitOfMeasure_V]);
  7599. }
  7600. //***********************************************(11)Current.Offered******************************************************/
  7601. if(((dataType == ReadingContext_Sample_Clock) && (strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, MeasurandStr[Current_Offered]) != NULL)) ||
  7602. ((dataType == ReadingContext_Sample_Periodic) && (strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, MeasurandStr[Current_Offered]) != NULL)) ||
  7603. (dataType == ReadingContext_Trigger))
  7604. {
  7605. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  7606. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  7607. {
  7608. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  7609. {
  7610. tempIndex = ((gun_index==2) ? 1: 0);
  7611. }
  7612. else
  7613. {
  7614. tempIndex = gun_index;
  7615. }
  7616. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  7617. {
  7618. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  7619. {
  7620. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[10].Value, "%d", (uint16_t) (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].CurrentOffered/10));
  7621. }
  7622. } // END OF FOR CHAdeMO_QUANTITY
  7623. }
  7624. else if(gunType[gun_index] == GUN_TYPE_CCS)
  7625. {
  7626. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  7627. {
  7628. tempIndex = ((gun_index==2) ? 1: 0);
  7629. }
  7630. else
  7631. {
  7632. tempIndex = gun_index;
  7633. }
  7634. for (int index = 0; index < CCS_QUANTITY; index++)
  7635. {
  7636. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  7637. {
  7638. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[10].Value, "%d", (uint16_t) (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].CurrentOffered/10));
  7639. }
  7640. } // END OF CCS_QUANTITY
  7641. }
  7642. else if(gunType[gun_index] == GUN_TYPE_GBT)
  7643. {
  7644. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  7645. {
  7646. tempIndex = ((gun_index==2) ? 1: 0);
  7647. }
  7648. else
  7649. {
  7650. tempIndex = gun_index;
  7651. }
  7652. for (int index = 0; index < GB_QUANTITY; index++)
  7653. {
  7654. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  7655. {
  7656. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[10].Value, "%d", (uint16_t) (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].CurrentOffered/10));
  7657. }
  7658. } // END OF GB_QUANTITY
  7659. }
  7660. else if(gunType[gun_index] == GUN_TYPE_DO)
  7661. {
  7662. tempIndex = gun_index;
  7663. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  7664. {
  7665. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  7666. {
  7667. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[10].Value, "%d", (uint16_t) (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.CurrentOffered/10));
  7668. }
  7669. }
  7670. }
  7671. else
  7672. {
  7673. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  7674. {
  7675. tempIndex = 2;
  7676. }
  7677. else
  7678. {
  7679. tempIndex = gun_index;
  7680. }
  7681. for (int index = 0; index < AC_QUANTITY; index++)
  7682. {
  7683. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  7684. {
  7685. uint16_t currentOffer;
  7686. if(ShmSysConfigAndInfo->SysConfig.MaxChargingCurrent == 0)
  7687. {
  7688. currentOffer = ShmSysConfigAndInfo->SysConfig.RatingCurrent;
  7689. }
  7690. else
  7691. {
  7692. currentOffer = ((ShmSysConfigAndInfo->SysConfig.MaxChargingCurrent>ShmSysConfigAndInfo->SysConfig.RatingCurrent)?ShmSysConfigAndInfo->SysConfig.RatingCurrent:ShmSysConfigAndInfo->SysConfig.MaxChargingCurrent);
  7693. }
  7694. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[10].Value, "%d", currentOffer);
  7695. }
  7696. }
  7697. }
  7698. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[10].Context, ReadingContextStr[dataType]);
  7699. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[10].Format, ValueFormatStr[Raw]);
  7700. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[10].Measurand, MeasurandStr[Current_Offered]);
  7701. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[10].Location, LocationStr[Location_Outlet]);
  7702. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[10].Unit,UnitOfMeasureStr[UnitOfMeasure_A]);
  7703. }
  7704. //***********************************************(12)Power.Offered******************************************************/
  7705. if(((dataType == ReadingContext_Sample_Clock) && (strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, MeasurandStr[Power_Offered]) != NULL) && (gunType[gun_index] != GUN_TYPE_AC)) ||
  7706. ((dataType == ReadingContext_Sample_Periodic) && (strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, MeasurandStr[Power_Offered]) != NULL) && (gunType[gun_index] != GUN_TYPE_AC)) ||
  7707. ((dataType == ReadingContext_Trigger) && (gunType[gun_index] != GUN_TYPE_AC)))
  7708. {
  7709. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  7710. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  7711. {
  7712. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  7713. {
  7714. tempIndex = ((gun_index==2) ? 1: 0);
  7715. }
  7716. else
  7717. {
  7718. tempIndex = gun_index;
  7719. }
  7720. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  7721. {
  7722. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  7723. {
  7724. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[11].Value, "%d", (uint32_t) (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PowerOffered*100));
  7725. }
  7726. } // END OF FOR CHAdeMO_QUANTITY
  7727. }
  7728. else if(gunType[gun_index] == GUN_TYPE_CCS)
  7729. {
  7730. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  7731. {
  7732. tempIndex = ((gun_index==2) ? 1: 0);
  7733. }
  7734. else
  7735. {
  7736. tempIndex = gun_index;
  7737. }
  7738. for (int index = 0; index < CCS_QUANTITY; index++)
  7739. {
  7740. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  7741. {
  7742. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[11].Value, "%d", (uint32_t) (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PowerOffered*100));
  7743. }
  7744. } // END OF CCS_QUANTITY
  7745. }
  7746. else if(gunType[gun_index] == GUN_TYPE_GBT)
  7747. {
  7748. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  7749. {
  7750. tempIndex = ((gun_index==2) ? 1: 0);
  7751. }
  7752. else
  7753. {
  7754. tempIndex = gun_index;
  7755. }
  7756. for (int index = 0; index < GB_QUANTITY; index++)
  7757. {
  7758. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  7759. {
  7760. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[11].Value, "%d", (uint32_t) (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PowerOffered*100));
  7761. }
  7762. } // END OF GB_QUANTITY
  7763. }
  7764. else if(gunType[gun_index] == GUN_TYPE_DO)
  7765. {
  7766. tempIndex = gun_index;
  7767. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  7768. {
  7769. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  7770. {
  7771. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[11].Value, "%d", (uint32_t) (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PowerOffered*100));
  7772. }
  7773. }
  7774. }
  7775. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[11].Context, ReadingContextStr[dataType]);
  7776. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[11].Format, ValueFormatStr[Raw]);
  7777. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[11].Measurand, MeasurandStr[Power_Offered]);
  7778. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[11].Location, LocationStr[Location_Outlet]);
  7779. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[11].Unit,UnitOfMeasureStr[UnitOfMeasure_W]);
  7780. }
  7781. // Message create ====================================================================================================
  7782. if(TRUE)
  7783. {
  7784. json_object *MeterValueReq = json_object_new_object();
  7785. json_object *MeterValues = json_object_new_array();
  7786. json_object *sampledValues = json_object_new_array();
  7787. json_object_object_add(MeterValueReq, "connectorId", json_object_new_int(ShmOCPP16Data->MeterValues[gun_index].ConnectorId));
  7788. if(ShmOCPP16Data->MeterValues[gun_index].TransactionId != -1)
  7789. json_object_object_add(MeterValueReq, "transactionId", json_object_new_int(ShmOCPP16Data->MeterValues[gun_index].TransactionId));
  7790. for(uint8_t idxMeter=0;idxMeter<ARRAY_SIZE(ShmOCPP16Data->MeterValues[gun_index].MeterValue);idxMeter++)
  7791. {
  7792. json_object *MeterValue = json_object_new_object();
  7793. for(int idxSample=0;idxSample<ARRAY_SIZE(ShmOCPP16Data->MeterValues[gun_index].MeterValue[idxMeter].SampledValue);idxSample++)
  7794. {
  7795. if(strlen((char*)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Value) > 0)
  7796. {
  7797. json_object *sampledValue = json_object_new_object();
  7798. json_object_object_add(sampledValue, "value", json_object_new_string((char*)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Value));
  7799. if(strlen((char*)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Context) > 0)
  7800. json_object_object_add(sampledValue, "context", json_object_new_string((char*)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Context));
  7801. if(strlen((char*)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Format) > 0)
  7802. json_object_object_add(sampledValue, "format", json_object_new_string((char*)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Format));
  7803. if(strlen((char*)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Measurand) > 0)
  7804. json_object_object_add(sampledValue, "measurand", json_object_new_string((char*)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Measurand));
  7805. if(strlen((char*)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Phase) > 0)
  7806. json_object_object_add(sampledValue, "phase", json_object_new_string((char*)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Phase));
  7807. if(strlen((char*)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Location) > 0)
  7808. json_object_object_add(sampledValue, "location", json_object_new_string((char*)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Location));
  7809. if(strlen((char*)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Unit) > 0)
  7810. json_object_object_add(sampledValue, "unit", json_object_new_string((char*)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Unit));
  7811. json_object_array_add(sampledValues, sampledValue);
  7812. }
  7813. }
  7814. json_object_object_add(MeterValue, "timestamp", json_object_new_string((char*)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idxMeter].TimeStamp));
  7815. json_object_object_add(MeterValue, "sampledValue", sampledValues);
  7816. json_object_array_add(MeterValues, MeterValue);
  7817. }
  7818. json_object_object_add(MeterValueReq, "meterValue", MeterValues);
  7819. sprintf(queuedata,"%d,[%d,\"%s\",\"MeterValues\",%s]"
  7820. ,gun_index + 1
  7821. ,MESSAGE_TYPE_CALL
  7822. ,guid
  7823. ,json_object_to_json_string_ext(MeterValueReq, JSON_C_TO_STRING_PLAIN));
  7824. json_object_put(MeterValueReq);
  7825. }
  7826. // Put request guid to hash map
  7827. sprintf(tempdata, "MeterValues,%d", (gun_index));
  7828. 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*/)
  7829. {
  7830. result = PASS;
  7831. //DEBUG_INFO("MeterValues mapitem pass\n");
  7832. }
  7833. if((dataType != ReadingContext_Trigger) &&
  7834. (dataType != ReadingContext_Sample_Clock) &&
  7835. ((ShmOCPP16Data->MeterValues[gun_index].TransactionId > 0) || (strstr((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[QueueOffLineMeterValues].ItemData, "TRUE"))))
  7836. queue_operation(QUEUE_OPERATION_ADD, guid, queuedata );
  7837. else
  7838. {
  7839. if(FirstHeartBeat)
  7840. LWS_Send(queuedata +2);
  7841. }
  7842. return result;
  7843. }
  7844. int sendLogStatusNotificationRequest(char *status)
  7845. {
  7846. mtrace();
  7847. int result = PASS;
  7848. char message[4096]={0};
  7849. char guid[37]={0};
  7850. char tempdata[128]={0};
  7851. json_object *LogStatusNotification = json_object_new_object();
  7852. DEBUG_INFO("sendLogStatusNotificationRequest...\n");
  7853. ShmOCPP16Data->LogStatusNotification.requestId = ShmOCPP16Data->GetLog.requestId;
  7854. sprintf((char *)ShmOCPP16Data->LogStatusNotification.status,"%s",(const char *)status);
  7855. json_object_object_add(LogStatusNotification, "status", json_object_new_string((char*)ShmOCPP16Data->LogStatusNotification.status));
  7856. json_object_object_add(LogStatusNotification, "requestId", json_object_new_int(ShmOCPP16Data->LogStatusNotification.requestId));
  7857. random_uuid(guid);
  7858. sprintf(message,"[%d,\"%s\",\"LogStatusNotification\",%s]",MESSAGE_TYPE_CALL, guid, json_object_to_json_string_ext(LogStatusNotification, JSON_C_TO_STRING_PLAIN));
  7859. json_object_put(LogStatusNotification);
  7860. LWS_Send(message);
  7861. sprintf(tempdata, "LogStatusNotification,%d", 0);
  7862. if(hashmap_operation(HASH_OP_ADD, guid, tempdata) == PASS)
  7863. {
  7864. result = PASS;
  7865. }
  7866. ShmOCPP16Data->SpMsg.bits.LogStatusNotificationReq = 0;
  7867. ShmOCPP16Data->SpMsg.bits.LogStatusNotificationConf = 0;
  7868. return result;
  7869. }
  7870. int sendSecurityEventNotificationRequest()
  7871. {
  7872. mtrace();
  7873. int result = PASS;
  7874. char message[4096]={0};
  7875. char guid[37]={0};
  7876. char tempdata[128]={0};
  7877. json_object *SecurityEventNotification = json_object_new_object();
  7878. DEBUG_INFO("sendSecurityEventNotificationRequest...\n");
  7879. //Stop Transaction Time
  7880. struct timeval tmnow;
  7881. struct tm *tm;
  7882. gettimeofday(&tmnow, NULL);
  7883. time_t t;
  7884. t = time(NULL);
  7885. /*UTC time and date*/
  7886. tm = gmtime(&t);
  7887. strftime((char *)ShmOCPP16Data->SecurityEventNotification.timestamp, ARRAY_SIZE(ShmOCPP16Data->SecurityEventNotification.timestamp), "%Y-%m-%dT%H:%M:%SZ", tm);
  7888. json_object_object_add(SecurityEventNotification, "timestamp", json_object_new_string((char*)ShmOCPP16Data->SecurityEventNotification.timestamp));
  7889. json_object_object_add(SecurityEventNotification, "type", json_object_new_string((char*)ShmOCPP16Data->SecurityEventNotification.type));
  7890. if(strlen((char*)ShmOCPP16Data->SecurityEventNotification.techInfo) > 0)
  7891. json_object_object_add(SecurityEventNotification, "techInfo", json_object_new_string((char*)ShmOCPP16Data->SecurityEventNotification.techInfo));
  7892. random_uuid(guid);
  7893. sprintf(message,"[%d,\"%s\",\"%s\",%s]",MESSAGE_TYPE_CALL, guid, "SecurityEventNotification", json_object_to_json_string_ext(SecurityEventNotification, JSON_C_TO_STRING_PLAIN));
  7894. json_object_put(SecurityEventNotification);
  7895. LWS_Send(message);
  7896. sprintf(tempdata, "SecurityEventNotification,0");
  7897. if(hashmap_operation(HASH_OP_ADD, guid, tempdata) == PASS)
  7898. {
  7899. result = PASS;
  7900. }
  7901. ShmOCPP16Data->SpMsg.bits.SecurityEventNotificationReq = 0;
  7902. ShmOCPP16Data->SpMsg.bits.SecurityEventNotificationConf = 0;
  7903. return result;
  7904. }
  7905. int sendSignCertificateRequest()
  7906. {
  7907. mtrace();
  7908. int result = PASS;
  7909. char message[4096]={0};
  7910. char guid[37]={0};
  7911. char tempdata[128]={0};
  7912. json_object *SignCertificate = json_object_new_object();
  7913. DEBUG_INFO("sendSignCertificateRequest...\n");
  7914. // Read csr file content
  7915. memset(ShmOCPP16Data->SignCertificate.csr, 0x00, ARRAY_SIZE(ShmOCPP16Data->SignCertificate.csr));
  7916. FILE *fp=fopen("/Storage/OCPP/certCP.csr","r");
  7917. char *line = NULL;
  7918. size_t len = 0;
  7919. while(getline(&line, &len, fp) != -1)
  7920. {
  7921. if((strstr(line, "BEGIN CERTIFICATE REQUEST") == NULL) && (strstr(line, "END CERTIFICATE REQUEST") == NULL))
  7922. {
  7923. memcpy(&ShmOCPP16Data->SignCertificate.csr[strlen((char*)ShmOCPP16Data->SignCertificate.csr)], line, (strlen(line)-1));
  7924. }
  7925. }
  7926. fclose(fp);
  7927. json_object_object_add(SignCertificate, "csr", json_object_new_string((char*)ShmOCPP16Data->SignCertificate.csr));
  7928. random_uuid(guid);
  7929. sprintf(message,"[%d,\"%s\",\"%s\",%s]",MESSAGE_TYPE_CALL, guid, "SignCertificate", json_object_to_json_string_ext(SignCertificate, JSON_C_TO_STRING_PLAIN));
  7930. json_object_put(SignCertificate);
  7931. LWS_Send(message);
  7932. sprintf(tempdata, "SignCertificate,0");
  7933. if(hashmap_operation(HASH_OP_ADD, guid, tempdata) == PASS)
  7934. {
  7935. result = PASS;
  7936. }
  7937. ShmOCPP16Data->SpMsg.bits.SignCertificateReq = 0;
  7938. ShmOCPP16Data->SpMsg.bits.SignCertificateConf = 0;
  7939. return result;
  7940. }
  7941. int sendSignedFirmwareStatusNotificationRequest(char *status)
  7942. {
  7943. mtrace();
  7944. int result = PASS;
  7945. char message[4096]={0};
  7946. char guid[37]={0};
  7947. char tempdata[128]={0};
  7948. json_object *SignedFirmwareStatusNotification = json_object_new_object();
  7949. DEBUG_INFO("sendSignedFirmwareStatusNotificationRequest...\n");
  7950. sprintf((char *)ShmOCPP16Data->SignedFirmwareStatusNotification.status , "%s", (const char *)status);
  7951. ShmOCPP16Data->SignedFirmwareStatusNotification.requestId = ShmOCPP16Data->SignedUpdateFirmware.requestId;
  7952. json_object_object_add(SignedFirmwareStatusNotification, "status", json_object_new_string((char*)ShmOCPP16Data->SignedFirmwareStatusNotification.status));
  7953. json_object_object_add(SignedFirmwareStatusNotification, "requestId", json_object_new_int(ShmOCPP16Data->SignedFirmwareStatusNotification.requestId));
  7954. random_uuid(guid);
  7955. sprintf(message,"[%d,\"%s\",\"SignedFirmwareStatusNotification\",%s]",MESSAGE_TYPE_CALL, guid, json_object_to_json_string_ext(SignedFirmwareStatusNotification, JSON_C_TO_STRING_PLAIN));
  7956. json_object_put(SignedFirmwareStatusNotification);
  7957. LWS_Send(message);
  7958. sprintf(tempdata, "SignedFirmwareStatusNotification,%d", 0);
  7959. if(hashmap_operation(HASH_OP_ADD, guid, tempdata) == PASS)
  7960. {
  7961. result = PASS;
  7962. }
  7963. ShmOCPP16Data->SpMsg.bits.SignedFirmwareStatusNotificationReq = 0;
  7964. ShmOCPP16Data->SpMsg.bits.SignedFirmwareStatusNotificationConf = 0;
  7965. return result;
  7966. }
  7967. //==========================================
  7968. // send confirm routine
  7969. //==========================================
  7970. int sendCancelReservationConfirmation(char *uuid,char *payload)
  7971. {
  7972. mtrace();
  7973. int result = FAIL;
  7974. char message[100]={0};
  7975. DEBUG_INFO("sendCancelReservationConfirmation...\n");
  7976. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT,uuid, payload);
  7977. LWS_Send(message);
  7978. result = TRUE;
  7979. return result;
  7980. }
  7981. int sendChangeAvailabilityConfirmation(char *uuid,char *payload)
  7982. {
  7983. mtrace();
  7984. int result = FAIL;
  7985. char message[100]={0};
  7986. DEBUG_INFO("sendChangeAvailabilityConfirmation...\n");
  7987. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT,uuid, payload);
  7988. LWS_Send(message);
  7989. result = TRUE;
  7990. return result;
  7991. }
  7992. int sendChangeConfigurationConfirmation(char *uuid,char *payload)
  7993. {
  7994. mtrace();
  7995. int result = FAIL;
  7996. char message[100]={0};
  7997. DEBUG_INFO("sendChangeConfigurationConfirmation...\n");
  7998. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT,uuid, payload);
  7999. LWS_Send(message);
  8000. result = TRUE;
  8001. return result;
  8002. }
  8003. int sendClearCacheConfirmation(char *uuid,char *payload)
  8004. {
  8005. mtrace();
  8006. int result = FAIL;
  8007. char message[500]={0};
  8008. DEBUG_INFO("sendClearCacheConfirmation...\n");
  8009. sprintf(message,"[%d,\"%s\",{\"%s\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, "status", payload);
  8010. LWS_Send(message);
  8011. return result;
  8012. }
  8013. int sendClearChargingProfileConfirmation(char *uuid,char *payload)
  8014. {
  8015. mtrace();
  8016. int result = FAIL;
  8017. char message[500]={0};
  8018. DEBUG_INFO("sendClearChargingProfileConfirmation...\n");
  8019. sprintf(message,"[%d,\"%s\",{\"%s\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, "status", payload);
  8020. LWS_Send(message);
  8021. return result;
  8022. }
  8023. int sendDataTransferConfirmation(char *uuid,char *payload)
  8024. {
  8025. mtrace();
  8026. char statusStr[20]={0};
  8027. char dataStr[10]={0};
  8028. char sstr[20]={0};
  8029. int c = 0;
  8030. char *loc;
  8031. int result = FAIL;
  8032. DEBUG_INFO("sendDataTransferConfirmation...\n");
  8033. /**********************status**************************/
  8034. loc = strstr(payload, "status");
  8035. memset(sstr ,0, ARRAY_SIZE(sstr) );
  8036. c = 0;
  8037. while (loc[3+strlen("status")+c] != '\"')
  8038. {
  8039. sstr[c] = loc[3+strlen("status")+c];
  8040. c++;
  8041. }
  8042. sstr[c] = '\0';
  8043. strcpy(statusStr, sstr);
  8044. /**********************data**************************/
  8045. loc = strstr(payload, "data");
  8046. memset(sstr ,0, ARRAY_SIZE(sstr) );
  8047. c = 0;
  8048. while (loc[3+strlen("data")+c] != '\"')
  8049. {
  8050. sstr[c] = loc[3+strlen("data")+c];
  8051. c++;
  8052. }
  8053. sstr[c] = '\0';
  8054. strcpy(dataStr, sstr);
  8055. return result;
  8056. }
  8057. int sendGetCompositeScheduleConfirmation(char *uuid, char *payload, int connectorIdInt, int nPeriod)
  8058. {
  8059. mtrace();
  8060. int result = FAIL;
  8061. char message[1000]={0};
  8062. int CompositeScheduleIndex = 0;
  8063. DEBUG_INFO("sendGetCompositeScheduleConfirmation...\n");
  8064. CompositeScheduleIndex = (connectorIdInt > 0) ?(connectorIdInt -1) : 0;
  8065. if(nPeriod == 0)
  8066. {
  8067. if(strcmp((const char *)ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.StartSchedule,"")==0)
  8068. {
  8069. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\",\"connectorId\":%d}]"
  8070. ,MESSAGE_TYPE_CALLRESULT
  8071. ,uuid
  8072. ,payload
  8073. ,connectorIdInt);
  8074. }
  8075. else
  8076. {
  8077. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\",\"connectorId\":%d,\"scheduleStart\":\"%s\",\"chargingSchedule\":{\"duration\":%d,\"startSchedule\":\"%s\",\"chargingRateUnit\":\"%s\",\"chargingSchedulePeriod\":[{\"startPeriod\":0,\"limit\":%d}]}}]"
  8078. ,MESSAGE_TYPE_CALLRESULT
  8079. ,uuid
  8080. ,payload
  8081. ,connectorIdInt
  8082. ,ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.StartSchedule
  8083. ,ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.Duration
  8084. ,ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.StartSchedule
  8085. ,ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.ChargingRateUnit
  8086. ,ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.ChargingRateUnit[0]=='W'?modelnameInfo.ratedPower:(ShmSysConfigAndInfo->SysConfig.MaxChargingCurrent==0?ShmSysConfigAndInfo->SysConfig.RatingCurrent:ShmSysConfigAndInfo->SysConfig.MaxChargingCurrent));
  8087. }
  8088. }
  8089. else
  8090. {
  8091. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\",\"connectorId\":%d,\"scheduleStart\":\"%s\",\"chargingSchedule\":{\"duration\":%d,\"startSchedule\":\"%s\",\"chargingRateUnit\":\"%s\",\"chargingSchedulePeriod\":["
  8092. ,MESSAGE_TYPE_CALLRESULT
  8093. ,uuid
  8094. ,payload
  8095. ,connectorIdInt
  8096. ,ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.StartSchedule
  8097. ,ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.Duration
  8098. ,ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.StartSchedule
  8099. ,ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.ChargingRateUnit);
  8100. for(int idx_sample=0;idx_sample< nPeriod;idx_sample++)
  8101. {
  8102. if (idx_sample == 0)
  8103. {
  8104. sprintf(message + strlen(message), "{\"startPeriod\":%d,\"limit\":%.1f,\"numberPhases\":%d}"
  8105. , ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[idx_sample].StartPeriod
  8106. , ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[idx_sample].Limit
  8107. , ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[idx_sample].NumberPhases );
  8108. }
  8109. else
  8110. {
  8111. sprintf(message + strlen(message), ",{\"startPeriod\":%d,\"limit\":%.1f,\"numberPhases\":%d}"
  8112. , ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[idx_sample].StartPeriod
  8113. , ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[idx_sample].Limit
  8114. , ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[idx_sample].NumberPhases );
  8115. }
  8116. }
  8117. sprintf(message + strlen(message), "]}}]");
  8118. }
  8119. LWS_Send(message);
  8120. result = TRUE;
  8121. return result;
  8122. }
  8123. int sendGetConfigurationConfirmation(char *uuid)
  8124. {
  8125. mtrace();
  8126. int result = FAIL;
  8127. int MaxKeySupported = 0;
  8128. int sentConfigurationNumber= 0;
  8129. int sentunConfigurationNumber= 0;
  8130. char message[1024*10]={0};
  8131. DEBUG_INFO("sendGetConfigurationConfirmation...\n");
  8132. MaxKeySupported = atoi((const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemData);
  8133. sprintf(message,"[%d,\"%s\",{\"configurationKey\":["
  8134. ,MESSAGE_TYPE_CALLRESULT
  8135. ,uuid );
  8136. //configuration key
  8137. for(int idx_sample=0;idx_sample< MaxKeySupported/*43*/;idx_sample++)
  8138. {
  8139. if(strcmp((const char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[idx_sample].Key, "")!= 0)
  8140. {
  8141. if (sentConfigurationNumber == 0)
  8142. {
  8143. sprintf(message + strlen(message), "{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}"
  8144. , ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[idx_sample].Key
  8145. , atoi((const char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[idx_sample].ReadOnly) == 1 ? "true":"false"
  8146. , ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[idx_sample].Value );
  8147. }
  8148. else
  8149. {
  8150. sprintf(message + strlen(message), ", {\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}"
  8151. , ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[idx_sample].Key
  8152. , atoi((const char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[idx_sample].ReadOnly) == 1 ? "true":"false"
  8153. , ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[idx_sample].Value );
  8154. }
  8155. sentConfigurationNumber = sentConfigurationNumber + 1;
  8156. }
  8157. }
  8158. sprintf(message + strlen(message), "]");
  8159. if(UnknownKeynum != 0)
  8160. {
  8161. sprintf(message + strlen(message), ",\"unknownKey\":[");
  8162. //unkown key
  8163. for(int idx_sample=0;idx_sample< UnknownKeynum ;idx_sample++)
  8164. {
  8165. // json_object *jstring1 = json_object_new_string((const char *)((ShmOCPP16Data->GetConfiguration.ResponseUnknownKey + idx_sample)->Item));
  8166. DEBUG_INFO("unkown key:%s\n", ShmOCPP16Data->GetConfiguration.ResponseUnknownKey[idx_sample].Item);
  8167. if(sentunConfigurationNumber == 0)
  8168. {
  8169. sprintf(message + strlen(message), "\"%s\""
  8170. , ShmOCPP16Data->GetConfiguration.ResponseUnknownKey[idx_sample].Item );
  8171. }
  8172. else
  8173. {
  8174. sprintf(message + strlen(message), ",\"%s\""
  8175. , ShmOCPP16Data->GetConfiguration.ResponseUnknownKey[idx_sample].Item );
  8176. }
  8177. sentunConfigurationNumber = sentunConfigurationNumber + 1;
  8178. }
  8179. sprintf(message + strlen(message), "]");
  8180. }
  8181. sprintf(message + strlen(message), "}]");
  8182. LWS_Send(message);
  8183. return result;
  8184. }
  8185. int sendGetDiagnosticsConfirmation(char *uuid,char *payload)
  8186. {
  8187. mtrace();
  8188. int result = FAIL;
  8189. char message[400]={0};
  8190. DEBUG_INFO("sendGetDiagnosticsConfirmation...\n");
  8191. if(strcmp(payload,"")==0)
  8192. {
  8193. sprintf(message,"[%d,\"%s\",{}]",MESSAGE_TYPE_CALLRESULT, uuid);
  8194. }
  8195. else
  8196. {
  8197. sprintf(message,"[%d,\"%s\",{\"fileName\":\"%s\"}]", MESSAGE_TYPE_CALLRESULT, uuid, payload);
  8198. }
  8199. LWS_Send(message);
  8200. result = TRUE;
  8201. return result;
  8202. }
  8203. int sendGetLocalListVersionConfirmation(char *uuid,char *payload)
  8204. {
  8205. mtrace();
  8206. int result = FAIL;
  8207. char message[80]={0};
  8208. DEBUG_INFO("sendGetLocalListVersionConfirmation...\n");
  8209. sprintf(message,"[%d,\"%s\",{\"listVersion\":%d}]",MESSAGE_TYPE_CALLRESULT, uuid, ShmOCPP16Data->GetLocalListVersion.ResponseListVersion);
  8210. LWS_Send(message);
  8211. result = TRUE;
  8212. return result;
  8213. }
  8214. int sendRemoteStartConfirmation(char *uuid,char *payload)
  8215. {
  8216. mtrace();
  8217. int result = FAIL;
  8218. char message[80]={0};
  8219. DEBUG_INFO("sendRemoteStartConfirmation...\n");
  8220. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, payload);
  8221. LWS_Send(message);
  8222. result = TRUE;
  8223. return result;
  8224. }
  8225. int sendRemoteStopTransactionConfirmation(char *uuid,char *payload)
  8226. {
  8227. mtrace();
  8228. int result = FAIL;
  8229. char message[80]={0};
  8230. DEBUG_INFO("sendRemoteStopTransactionConfirmation...\n");
  8231. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, payload);
  8232. LWS_Send(message);
  8233. result = TRUE;
  8234. return result;
  8235. }
  8236. int sendReserveNowTransactionConfirmation(char *uuid,char *payload)
  8237. {
  8238. mtrace();
  8239. int result = FAIL;
  8240. char message[80]={0};
  8241. // [3,"287d837d-809e-41ea-8385-fdab7f72a01c",{"status":"Accepted"}]
  8242. DEBUG_INFO("sendReserveNowTransactionConfirmation...\n");
  8243. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, payload);
  8244. LWS_Send(message);
  8245. result = TRUE;
  8246. return result;
  8247. }
  8248. int sendResetConfirmation(char *uuid,char *payload)
  8249. {
  8250. mtrace();
  8251. int result = FAIL;
  8252. //[ 3, "6f88d461-4d17-462c-a69b-1f7a8c5b12df", { "status": 0 } ]
  8253. char message[80]={0};
  8254. ShmOCPP16Data->MsMsg.bits.ResetConf = 0;
  8255. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, payload);
  8256. LWS_Send(message);
  8257. result = TRUE;
  8258. return result;
  8259. }
  8260. int sendSendLocalListConfirmation(char *uuid,char *payload)
  8261. {
  8262. mtrace();
  8263. int result = FAIL;
  8264. char message[500]={0};
  8265. // [ 3, "1571284266109", { "status": "Accepted" } ]
  8266. sprintf(message,"[%d,\"%s\",{\"%s\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, "status", payload);
  8267. LWS_Send(message);
  8268. result = TRUE;
  8269. return result;
  8270. }
  8271. int sendSetChargingProfileConfirmation(char *uuid,char *payload)
  8272. {
  8273. mtrace();
  8274. int result = FAIL;
  8275. //[3,"5748585f-8524-4fa6-9b4f-4a7eca750b90",{"status":"NotSupported"}]
  8276. char message[80]={0};
  8277. DEBUG_INFO("sendSetChargingProfileConfirmation...\n");
  8278. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, payload);
  8279. LWS_Send(message);
  8280. result = TRUE;
  8281. return result;
  8282. }
  8283. int sendTriggerMessageConfirmation(char *uuid,char *payload)
  8284. {
  8285. mtrace();
  8286. int result = FAIL;
  8287. char message[80]={0};
  8288. DEBUG_INFO("sendTriggerMessageConfirmation...\n");
  8289. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, payload);
  8290. LWS_Send(message);
  8291. result = TRUE;
  8292. return result;
  8293. }
  8294. int sendUnlockConnectorConfirmation(char *uuid,char *payload)
  8295. {
  8296. mtrace();
  8297. int result = FAIL;
  8298. char message[80]={0};
  8299. //[ 3, "ba1cbd49-2a76-493a-8f76-fa23e7606532", { "status": "Unlocked" } ]
  8300. DEBUG_INFO("sendUnlockConnectorConfirmation...\n");
  8301. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, payload);
  8302. LWS_Send(message);
  8303. result = TRUE;
  8304. return result;
  8305. }
  8306. int sendUpdateFirmwareConfirmation(char *uuid)
  8307. {
  8308. mtrace();
  8309. int result = FAIL;
  8310. char message[60]={0};
  8311. //[ 3, "ba1cbd49-2a76-493a-8f76-fa23e7606532", { "status": "Unlocked" } ]
  8312. DEBUG_INFO("sendUpdateFirmwareConfirmation...\n");
  8313. sprintf(message,"[%d,\"%s\",{}]",MESSAGE_TYPE_CALLRESULT, uuid);
  8314. LWS_Send(message);
  8315. result = TRUE;
  8316. return result;
  8317. }
  8318. int sendCertificateSignedConfirmation(char *uuid)
  8319. {
  8320. mtrace();
  8321. int result = PASS;
  8322. char message[4096]={0};
  8323. json_object *CertificateSigned = json_object_new_object();
  8324. DEBUG_INFO("sendCertificateSignedConfirmation...\n");
  8325. json_object_object_add(CertificateSigned, "status", json_object_new_string((char*)ShmOCPP16Data->CertificateSigned.Response_status));
  8326. sprintf(message,"[%d,\"%s\",%s]"
  8327. ,MESSAGE_TYPE_CALLRESULT
  8328. ,uuid
  8329. ,json_object_to_json_string_ext(CertificateSigned, JSON_C_TO_STRING_PLAIN));
  8330. json_object_put(CertificateSigned);
  8331. LWS_Send(message);
  8332. return result;
  8333. }
  8334. int sendDeleteCertificateConfirmation(char *uuid)
  8335. {
  8336. mtrace();
  8337. int result = PASS;
  8338. char message[4096]={0};
  8339. json_object *DeleteCertificate = json_object_new_object();
  8340. DEBUG_INFO("sendDeleteCertificateConfirmation...\n");
  8341. json_object_object_add(DeleteCertificate, "status", json_object_new_string((char*)ShmOCPP16Data->DeleteCertificate.Response_status));
  8342. sprintf(message,"[%d,\"%s\",%s]"
  8343. ,MESSAGE_TYPE_CALLRESULT
  8344. ,uuid
  8345. ,json_object_to_json_string_ext(DeleteCertificate, JSON_C_TO_STRING_PLAIN));
  8346. json_object_put(DeleteCertificate);
  8347. LWS_Send(message);
  8348. return result;
  8349. }
  8350. int sendExtendedTriggerMessageConfirmation(char *uuid)
  8351. {
  8352. mtrace();
  8353. int result = PASS;
  8354. char message[4096]={0};
  8355. json_object *ExtendedTriggerMessage = json_object_new_object();
  8356. DEBUG_INFO("sendExtendedTriggerMessageConfirmation...\n");
  8357. json_object_object_add(ExtendedTriggerMessage, "status", json_object_new_string((char*)ShmOCPP16Data->ExtendedTriggerMessage.Response_status));
  8358. sprintf(message,"[%d,\"%s\",%s]"
  8359. ,MESSAGE_TYPE_CALLRESULT
  8360. ,uuid
  8361. ,json_object_to_json_string_ext(ExtendedTriggerMessage, JSON_C_TO_STRING_PLAIN));
  8362. json_object_put(ExtendedTriggerMessage);
  8363. LWS_Send(message);
  8364. return result;
  8365. }
  8366. int sendGetInstalledCertificateIdsConfirmation(char *uuid)
  8367. {
  8368. mtrace();
  8369. int result = PASS;
  8370. char message[4096]={0};
  8371. json_object *GetInstalledCertificateIds = json_object_new_object();
  8372. json_object *certificateHashDataDatas = json_object_new_array();
  8373. DEBUG_INFO("sendGetInstalledCertificateIdsConfirmation...\n");
  8374. json_object_object_add(GetInstalledCertificateIds, "status", json_object_new_string((char*)ShmOCPP16Data->GetInstalledCertificateIds.Response_status));
  8375. if(strlen((char*)ShmOCPP16Data->GetInstalledCertificateIds.Response_certificateHashData[0].hashAlgorithm) > 0)
  8376. {
  8377. for(int idx=0;idx<ARRAY_SIZE(ShmOCPP16Data->GetInstalledCertificateIds.Response_certificateHashData);idx++)
  8378. {
  8379. json_object *certificateHashData = json_object_new_object();
  8380. json_object_object_add(certificateHashData, "hashAlgorithm", json_object_new_string((char*)ShmOCPP16Data->GetInstalledCertificateIds.Response_certificateHashData[idx].hashAlgorithm));
  8381. json_object_object_add(certificateHashData, "issuerNameHash", json_object_new_string((char*)ShmOCPP16Data->GetInstalledCertificateIds.Response_certificateHashData[idx].issuerNameHash));
  8382. json_object_object_add(certificateHashData, "issuerKeyHash", json_object_new_string((char*)ShmOCPP16Data->GetInstalledCertificateIds.Response_certificateHashData[idx].issuerKeyHash));
  8383. json_object_object_add(certificateHashData, "serialNumber", json_object_new_string((char*)ShmOCPP16Data->GetInstalledCertificateIds.Response_certificateHashData[idx].serialNumber));
  8384. json_object_array_add(certificateHashDataDatas, certificateHashData);
  8385. }
  8386. json_object_object_add(GetInstalledCertificateIds , "certificateHashData", certificateHashDataDatas);
  8387. }
  8388. else
  8389. {
  8390. json_object_put(certificateHashDataDatas);
  8391. }
  8392. sprintf(message,"[%d,\"%s\",%s]"
  8393. ,MESSAGE_TYPE_CALLRESULT
  8394. ,uuid
  8395. ,json_object_to_json_string_ext(GetInstalledCertificateIds, JSON_C_TO_STRING_PLAIN));
  8396. json_object_put(GetInstalledCertificateIds);
  8397. LWS_Send(message);
  8398. return result;
  8399. }
  8400. int sendGetLogConfirmation(char *uuid)
  8401. {
  8402. mtrace();
  8403. int result = PASS;
  8404. char message[4096]={0};
  8405. json_object *GetLog = json_object_new_object();
  8406. DEBUG_INFO("sendGetLogConfirmation...\n");
  8407. json_object_object_add(GetLog, "status", json_object_new_string((char*)ShmOCPP16Data->GetLog.Response_status));
  8408. if(strlen((char*)ShmOCPP16Data->GetLog.Response_filename) > 0)
  8409. json_object_object_add(GetLog, "filename", json_object_new_string((char*)ShmOCPP16Data->GetLog.Response_filename));
  8410. sprintf(message,"[%d,\"%s\",%s]"
  8411. ,MESSAGE_TYPE_CALLRESULT
  8412. ,uuid
  8413. ,json_object_to_json_string_ext(GetLog, JSON_C_TO_STRING_PLAIN));
  8414. json_object_put(GetLog);
  8415. LWS_Send(message);
  8416. return result;
  8417. }
  8418. int sendInstallCertificateConfirmation(char *uuid)
  8419. {
  8420. mtrace();
  8421. int result = PASS;
  8422. char message[4096]={0};
  8423. json_object *InstallCertificate = json_object_new_object();
  8424. DEBUG_INFO("sendInstallCertificateConfirmation...\n");
  8425. json_object_object_add(InstallCertificate, "status", json_object_new_string((char*)ShmOCPP16Data->InstallCertificate.Response_status));
  8426. sprintf(message,"[%d,\"%s\",%s]"
  8427. ,MESSAGE_TYPE_CALLRESULT
  8428. ,uuid
  8429. ,json_object_to_json_string_ext(InstallCertificate, JSON_C_TO_STRING_PLAIN));
  8430. json_object_put(InstallCertificate);
  8431. LWS_Send(message);
  8432. return result;
  8433. }
  8434. int sendSignedUpdateFirmwareConfirmation(char *uuid)
  8435. {
  8436. mtrace();
  8437. int result = PASS;
  8438. char message[4096]={0};
  8439. json_object *SignedUpdateFirmware = json_object_new_object();
  8440. DEBUG_INFO("sendSignedUpdateFirmwareConfirmation...\n");
  8441. json_object_object_add(SignedUpdateFirmware, "status", json_object_new_string((char*)ShmOCPP16Data->SignedUpdateFirmware.Response_status));
  8442. sprintf(message,"[%d,\"%s\",%s]"
  8443. ,MESSAGE_TYPE_CALLRESULT
  8444. ,uuid
  8445. ,json_object_to_json_string_ext(SignedUpdateFirmware, JSON_C_TO_STRING_PLAIN));
  8446. json_object_put(SignedUpdateFirmware);
  8447. LWS_Send(message);
  8448. return result;
  8449. }
  8450. int sendUnknownConfirmation(char *uuid)
  8451. {
  8452. mtrace();
  8453. int result = PASS;
  8454. char message[256]={0};
  8455. DEBUG_INFO("sendUnknownConfirmation...\n");
  8456. sprintf(message,"[%d,\"%s\",\"NotImplemented\",\"Requested Action is not known by receiver\",{}]", MESSAGE_TYPE_CALLERROR, uuid);
  8457. LWS_Send(message);
  8458. return result;
  8459. }
  8460. //==========================================
  8461. // Handle server request routine Start
  8462. //==========================================
  8463. int handleCancelReservationRequest(char *uuid, char *payload)
  8464. {
  8465. mtrace();
  8466. int result = FAIL;
  8467. int gunNO = 0;
  8468. int reservationIdInt = -1;
  8469. char comfirmstr[20];
  8470. DEBUG_INFO("handleCancelReservationRequest...\n");
  8471. json_object *CancelReservation;
  8472. CancelReservation = json_tokener_parse(payload);
  8473. if(!is_error(CancelReservation))
  8474. {
  8475. // Required data
  8476. if(json_object_object_get(CancelReservation, "reservationId") != NULL)
  8477. reservationIdInt = json_object_get_int(json_object_object_get(CancelReservation, "reservationId"));
  8478. }
  8479. json_object_put(CancelReservation);
  8480. DEBUG_INFO("reservationIdInt = %d\n", reservationIdInt);
  8481. memset(comfirmstr, 0, ARRAY_SIZE(comfirmstr));
  8482. sprintf(comfirmstr, "%s", CancelReservationStatusStr[CancelReservationStatus_Rejected]);
  8483. if(reservationIdInt != -1)
  8484. {
  8485. //0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault, 8: Reserved, 9: maintain
  8486. //check Transaction active
  8487. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  8488. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  8489. {
  8490. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ReservationId == reservationIdInt)
  8491. {
  8492. sprintf(comfirmstr, "%s", CancelReservationStatusStr[CancelReservationStatus_Accepted] );
  8493. sprintf((char *)ShmOCPP16Data->CancelReservation[ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index].ResponseStatus, "%s", comfirmstr );
  8494. if(gunType[2] == GUN_TYPE_CHAdeMO)
  8495. {
  8496. gunNO = ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index + 1;
  8497. }
  8498. else
  8499. {
  8500. gunNO = ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index;
  8501. }
  8502. ShmOCPP16Data->CsMsg.bits[gunNO].CancelReservationReq = 1;
  8503. goto end;
  8504. }
  8505. }
  8506. for (int index = 0; index < CCS_QUANTITY; index++)
  8507. {
  8508. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ReservationId == reservationIdInt)
  8509. {
  8510. sprintf(comfirmstr, "%s", CancelReservationStatusStr[CancelReservationStatus_Accepted] );
  8511. sprintf((char *)ShmOCPP16Data->CancelReservation[ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index].ResponseStatus, "%s", comfirmstr );
  8512. if(gunType[2] == GUN_TYPE_CCS)
  8513. {
  8514. gunNO = ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index + 1;
  8515. }
  8516. else
  8517. {
  8518. gunNO = ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index;
  8519. }
  8520. ShmOCPP16Data->CsMsg.bits[gunNO].CancelReservationReq = 1;
  8521. goto end;
  8522. }
  8523. }
  8524. for (int index = 0; index < GB_QUANTITY; index++)
  8525. {
  8526. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ReservationId == reservationIdInt)
  8527. {
  8528. sprintf(comfirmstr, "%s", CancelReservationStatusStr[CancelReservationStatus_Accepted] );
  8529. sprintf((char *)ShmOCPP16Data->CancelReservation[ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index].ResponseStatus, "%s", comfirmstr );
  8530. if(gunType[2] == GUN_TYPE_GBT)
  8531. {
  8532. gunNO = ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index + 1;
  8533. }
  8534. else
  8535. {
  8536. gunNO = ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index;
  8537. }
  8538. ShmOCPP16Data->CsMsg.bits[gunNO].CancelReservationReq = 1;
  8539. goto end;
  8540. }
  8541. }
  8542. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  8543. {
  8544. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.ReservationId == reservationIdInt)
  8545. {
  8546. sprintf(comfirmstr, "%s", CancelReservationStatusStr[CancelReservationStatus_Accepted] );
  8547. sprintf((char *)ShmOCPP16Data->CancelReservation[ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index].ResponseStatus, "%s", comfirmstr );
  8548. gunNO = ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index;
  8549. ShmOCPP16Data->CsMsg.bits[gunNO].CancelReservationReq = 1;
  8550. goto end;
  8551. }
  8552. }
  8553. for (int index = 0; index < AC_QUANTITY; index++)
  8554. {
  8555. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].ReservationId == reservationIdInt)
  8556. {
  8557. sprintf(comfirmstr, "%s", CancelReservationStatusStr[CancelReservationStatus_Accepted] );
  8558. sprintf((char *)ShmOCPP16Data->CancelReservation[ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index].ResponseStatus, "%s", comfirmstr );
  8559. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  8560. {
  8561. gunNO = 1; //ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index ;
  8562. }
  8563. else
  8564. {
  8565. gunNO = ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index;
  8566. }
  8567. ShmOCPP16Data->CsMsg.bits[gunNO].CancelReservationReq = 1;
  8568. goto end;
  8569. }
  8570. }
  8571. }
  8572. //The reservationId does NOT match the reservationId
  8573. sendCancelReservationConfirmation(uuid, comfirmstr);
  8574. end:
  8575. // Fill in ocpp packet uuid
  8576. strcpy((char *)ShmOCPP16Data->CancelReservation[gunNO].guid, uuid);
  8577. return result;
  8578. }
  8579. int handleChangeAvailabilityRequest(char *uuid, char *payload)
  8580. {
  8581. mtrace();
  8582. int result = FAIL;
  8583. int gunIndex = -1;
  8584. char typeStr[16]={0};
  8585. char comfirmstr[20];
  8586. int specificId = FALSE;
  8587. DEBUG_INFO("handleChangeAvailabilityRequest...\n");
  8588. json_object *ChangeAvailability;
  8589. ChangeAvailability = json_tokener_parse(payload);
  8590. if(!is_error(ChangeAvailability))
  8591. {
  8592. // Required data
  8593. if((json_object_object_get(ChangeAvailability, "connectorId") != NULL) && (json_object_get_type(json_object_object_get(ChangeAvailability, "connectorId")) == json_type_int))
  8594. gunIndex = json_object_get_int(json_object_object_get(ChangeAvailability, "connectorId"));
  8595. if(json_object_object_get(ChangeAvailability, "type") != NULL)
  8596. sprintf((char*)typeStr, "%s", json_object_get_string(json_object_object_get(ChangeAvailability, "type")));
  8597. }
  8598. json_object_put(ChangeAvailability);
  8599. if((gunIndex > 0) && (gunIndex <= gunTotalNumber))
  8600. {
  8601. ShmOCPP16Data->ChangeAvailability[gunIndex - 1].ConnectorId= gunIndex;
  8602. sprintf((char *)ShmOCPP16Data->ChangeAvailability[gunIndex - 1].Type, "%s", typeStr);
  8603. }
  8604. else if(gunIndex == 0)
  8605. {
  8606. for(int i=0; i < gunTotalNumber; i++)
  8607. {
  8608. ShmOCPP16Data->ChangeAvailability[i].ConnectorId= gunIndex;
  8609. sprintf((char *)ShmOCPP16Data->ChangeAvailability[i].Type, "%s", typeStr);
  8610. }
  8611. }
  8612. memset(comfirmstr, 0, ARRAY_SIZE(comfirmstr));
  8613. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  8614. if((gunIndex == 0) || ((gunIndex > 0) && (gunIndex <= gunTotalNumber)))
  8615. {
  8616. specificId = TRUE;
  8617. }
  8618. if(specificId == FALSE)
  8619. goto end;
  8620. if(strcmp((const char *)typeStr, AvailabilityTypeStr[Inoperative]) == 0)
  8621. {
  8622. //----------------------gunIndex is 0 ------------------------------------------------//
  8623. if(gunIndex == 0)
  8624. {
  8625. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D') // 'D' means DC
  8626. {
  8627. for(int i=0; i < gunTotalNumber; i++)
  8628. {
  8629. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  8630. {
  8631. if ((gunType[i] == GUN_TYPE_CHAdeMO)&&(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == i))
  8632. {
  8633. if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_RESERVATION) // S_PRECHARGE
  8634. {
  8635. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  8636. goto end;
  8637. }
  8638. else if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_AUTHORIZING) ||
  8639. (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_PREPARING) ||
  8640. (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_CHARGING) ||
  8641. (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_TERMINATING) ||
  8642. (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_COMPLETE)) // S_CHARGING
  8643. {
  8644. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  8645. goto end;
  8646. }
  8647. }
  8648. }//END FOR CHAdeMO_QUANTITY
  8649. for (int index = 0; index < CCS_QUANTITY; index++)
  8650. {
  8651. if ((gunType[i] == GUN_TYPE_CCS)&&(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == i))
  8652. {
  8653. if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_RESERVATION)// S_PRECHARGE
  8654. {
  8655. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  8656. goto end;
  8657. }
  8658. else if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_AUTHORIZING) ||
  8659. (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_PREPARING) ||
  8660. (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_CHARGING) ||
  8661. (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_TERMINATING) ||
  8662. (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_COMPLETE)) // S_CHARGING
  8663. {
  8664. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  8665. goto end;
  8666. }
  8667. }
  8668. }//END FOR CCS_QUANTITY
  8669. for (int index = 0; index < GB_QUANTITY; index++)
  8670. {
  8671. if ((gunType[i] == GUN_TYPE_GBT)&&(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == i))
  8672. {
  8673. if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_RESERVATION) // S_PRECHARGE
  8674. {
  8675. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  8676. goto end;
  8677. }
  8678. else if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_AUTHORIZING) ||
  8679. (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_PREPARING) ||
  8680. (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_CHARGING) ||
  8681. (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_TERMINATING) ||
  8682. (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_COMPLETE)) // S_CHARGING
  8683. {
  8684. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  8685. goto end;
  8686. }
  8687. }
  8688. }// END FOR GB_QUANTITY
  8689. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  8690. {
  8691. if ((gunType[i] == GUN_TYPE_DO)&&(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == i))
  8692. {
  8693. if(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_RESERVATION) // S_PRECHARGE
  8694. {
  8695. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  8696. goto end;
  8697. }
  8698. else if((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_AUTHORIZING) ||
  8699. (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_PREPARING) ||
  8700. (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_CHARGING) ||
  8701. (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_TERMINATING) ||
  8702. (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_COMPLETE)) // S_CHARGING
  8703. {
  8704. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  8705. goto end;
  8706. }
  8707. }
  8708. }// END FOR GENERAL_GUN_QUANTITY
  8709. for (int index = 0; index < AC_QUANTITY; index++)
  8710. {
  8711. if ((gunType[i] == GUN_TYPE_AC)&&(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == i))
  8712. {
  8713. if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_RESERVATION) // S_PRECHARGE
  8714. {
  8715. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  8716. goto end;
  8717. }
  8718. else if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_AUTHORIZING) ||
  8719. (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_PREPARING) ||
  8720. (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_CHARGING) ||
  8721. (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_TERMINATING) ||
  8722. (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_COMPLETE)) // S_CHARGING
  8723. {
  8724. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  8725. goto end;
  8726. }
  8727. }
  8728. }//END FOR AC_QUANTITY
  8729. }// END FOR gunTotalNumber
  8730. }
  8731. else if (ShmSysConfigAndInfo->SysConfig.ModelName[0]=='A') //'A' means AC
  8732. {
  8733. for(int i=0; i < gunTotalNumber; i++)
  8734. {
  8735. if(ShmSysConfigAndInfo->SysInfo.AcChargingData[i].SystemStatus == SYS_MODE_RESERVATION) // S_PRECHARGE
  8736. {
  8737. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  8738. goto end;
  8739. }
  8740. else if((ShmSysConfigAndInfo->SysInfo.AcChargingData[i].SystemStatus == SYS_MODE_AUTHORIZING) ||
  8741. (ShmSysConfigAndInfo->SysInfo.AcChargingData[i].SystemStatus == SYS_MODE_PREPARING) ||
  8742. (ShmSysConfigAndInfo->SysInfo.AcChargingData[i].SystemStatus == SYS_MODE_CHARGING) ||
  8743. (ShmSysConfigAndInfo->SysInfo.AcChargingData[i].SystemStatus == SYS_MODE_TERMINATING) ||
  8744. (ShmSysConfigAndInfo->SysInfo.AcChargingData[i].SystemStatus == SYS_MODE_COMPLETE)) // S_CHARGING
  8745. {
  8746. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  8747. goto end;
  8748. }
  8749. }
  8750. }
  8751. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  8752. goto end;
  8753. }
  8754. //----------------------gunIndex is not 0 ------------------------------------------------//
  8755. //check Transaction active
  8756. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  8757. {
  8758. if ((gunIndex > 0)&&(gunType[gunIndex-1] == GUN_TYPE_CHAdeMO))
  8759. {
  8760. if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_RESERVATION) ) // S_PRECHARGE
  8761. {
  8762. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  8763. goto end;
  8764. }
  8765. else if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_AUTHORIZING) ||
  8766. (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_PREPARING) ||
  8767. (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_CHARGING) ||
  8768. (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_TERMINATING) ||
  8769. (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_COMPLETE)) // S_CHARGING
  8770. {
  8771. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  8772. goto end;
  8773. }
  8774. else
  8775. {
  8776. DEBUG_INFO("ShmSysConfigAndInfo->SysInfo.ChademoChargingData[%d].SystemStatus = %d\n",index, ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus);
  8777. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  8778. goto end;
  8779. }
  8780. }
  8781. }//END FOR CHAdeMO_QUANTITY
  8782. for (int index = 0; index < CCS_QUANTITY; index++)
  8783. {
  8784. if ((gunIndex > 0)&&(gunType[gunIndex - 1] == GUN_TYPE_CCS))
  8785. {
  8786. if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_RESERVATION) )// S_PRECHARGE
  8787. {
  8788. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  8789. goto end;
  8790. }
  8791. else if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_AUTHORIZING) ||
  8792. (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_PREPARING) ||
  8793. (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_CHARGING) ||
  8794. (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_TERMINATING) ||
  8795. (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_COMPLETE)) // S_CHARGING
  8796. {
  8797. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  8798. goto end;
  8799. }
  8800. else
  8801. {
  8802. DEBUG_INFO("ShmSysConfigAndInfo->SysInfo.CcsChargingData[%d].SystemStatus=%d\n",index, ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus);
  8803. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  8804. goto end;
  8805. }
  8806. }
  8807. }//END FOR CCS_QUANTITY
  8808. for (int index = 0; index < GB_QUANTITY; index++)
  8809. {
  8810. if ((gunIndex > 0)&&(gunType[gunIndex-1] == GUN_TYPE_GBT))
  8811. {
  8812. if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_RESERVATION)) // S_PRECHARGE
  8813. {
  8814. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  8815. goto end;
  8816. }
  8817. else if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_AUTHORIZING) ||
  8818. (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_PREPARING) ||
  8819. (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_CHARGING) ||
  8820. (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_TERMINATING) ||
  8821. (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_COMPLETE)) // S_CHARGING
  8822. {
  8823. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  8824. goto end;
  8825. }
  8826. else
  8827. {
  8828. DEBUG_INFO("ShmSysConfigAndInfo->SysInfo.GbChargingData[%d].SystemStatus=%d\n",index,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus);
  8829. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  8830. goto end;
  8831. }
  8832. }
  8833. }// END FOR GB_QUANTITY
  8834. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  8835. {
  8836. if ((gunIndex > 0)&&(gunType[gunIndex-1] == GUN_TYPE_DO))
  8837. {
  8838. if((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_RESERVATION)) // S_PRECHARGE
  8839. {
  8840. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  8841. goto end;
  8842. }
  8843. else if((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_AUTHORIZING) ||
  8844. (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_PREPARING) ||
  8845. (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_CHARGING) ||
  8846. (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_TERMINATING) ||
  8847. (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_COMPLETE)) // S_CHARGING
  8848. {
  8849. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  8850. goto end;
  8851. }
  8852. else
  8853. {
  8854. DEBUG_INFO("ShmSysConfigAndInfo->SysInfo.GbChargingData[%d].SystemStatus=%d\n",index,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus);
  8855. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  8856. goto end;
  8857. }
  8858. }
  8859. }// END FOR GENERAL_GUN_QUANTITY
  8860. for (int index = 0; index < AC_QUANTITY; index++)
  8861. {
  8862. if ((gunIndex > 0)&&(gunType[gunIndex-1] ==GUN_TYPE_AC))
  8863. {
  8864. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_RESERVATION)) // S_PRECHARGE
  8865. {
  8866. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  8867. goto end;
  8868. }
  8869. else if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_AUTHORIZING) ||
  8870. (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_PREPARING) ||
  8871. (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_CHARGING) ||
  8872. (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_TERMINATING) ||
  8873. (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_COMPLETE)) // S_CHARGING
  8874. {
  8875. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  8876. goto end;
  8877. }
  8878. else
  8879. {
  8880. DEBUG_INFO("ShmSysConfigAndInfo->SysInfo.AcChargingData[%d].SystemStatus=%d\n",index, ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus);
  8881. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  8882. goto end;
  8883. }
  8884. }
  8885. }//END FOR AC_QUANTITY
  8886. }//END FOR AvailabilityTypeStr[Inoperative]
  8887. if(strcmp((const char *)typeStr, AvailabilityTypeStr[Operative]) == 0)
  8888. {
  8889. //----------------------gunIndex is 0 ------------------------------------------------//
  8890. if(gunIndex == 0)
  8891. {
  8892. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D') // 'D' means DC
  8893. {
  8894. for(int i=0; i < gunTotalNumber; i++)
  8895. {
  8896. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  8897. {
  8898. 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
  8899. {
  8900. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  8901. goto end;
  8902. }
  8903. }//END FOR CHAdeMO_QUANTITY
  8904. for (int index = 0; index < CCS_QUANTITY; index++)
  8905. {
  8906. 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
  8907. {
  8908. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  8909. goto end;
  8910. }
  8911. }//END FOR CCS_QUANTITY
  8912. for (int index = 0; index < GB_QUANTITY; index++)
  8913. {
  8914. 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
  8915. {
  8916. //ShmOCPP16Data->CsMsg.bits[gunIndex - 1].ChangeAvailabilityReq = 1;
  8917. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  8918. goto end;
  8919. }
  8920. }// END FOR GB_QUANTITY
  8921. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  8922. {
  8923. 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
  8924. {
  8925. //ShmOCPP16Data->CsMsg.bits[gunIndex - 1].ChangeAvailabilityReq = 1;
  8926. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  8927. goto end;
  8928. }
  8929. }// END FOR GENERAL_GUN_QUANTITY
  8930. for (int index = 0; index < AC_QUANTITY; index++)
  8931. {
  8932. 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
  8933. {
  8934. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  8935. goto end;
  8936. }
  8937. }//END FOR CHAdeMO_QUANTITY
  8938. }// END FOR gunTotalNumber
  8939. }
  8940. else if (ShmSysConfigAndInfo->SysConfig.ModelName[0]=='A') //'A' means AC
  8941. {
  8942. for(int i=0; i < gunTotalNumber; i++)
  8943. {
  8944. for (int index = 0; index < AC_QUANTITY; index++)
  8945. {
  8946. 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
  8947. {
  8948. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  8949. goto end;
  8950. }
  8951. }//END FOR CHAdeMO_QUANTITY
  8952. } // END FOR gunTotalNumber
  8953. }
  8954. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  8955. goto end;
  8956. }
  8957. //----------------------gunIndex is not 0 ------------------------------------------------//
  8958. //check Transaction active
  8959. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  8960. {
  8961. if (((gunIndex > 0)&&(gunType[gunIndex-1] == GUN_TYPE_CHAdeMO) ) &&(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_FAULT)) //S_FAULT
  8962. {
  8963. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  8964. goto end;
  8965. }
  8966. }//END FOR CHAdeMO_QUANTITY
  8967. for (int index = 0; index < CCS_QUANTITY; index++)
  8968. {
  8969. if ((((gunIndex > 0)&&(gunType[gunIndex - 1] == GUN_TYPE_CCS)) )&&(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_FAULT)) //S_FAULT
  8970. {
  8971. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  8972. goto end;
  8973. }
  8974. }//END FOR CCS_QUANTITY
  8975. for (int index = 0; index < GB_QUANTITY; index++)
  8976. {
  8977. if (((gunIndex > 0)&&(gunType[gunIndex-1] == GUN_TYPE_GBT))&&(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_FAULT)) //S_FAULT
  8978. {
  8979. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  8980. goto end;
  8981. }
  8982. }// END FOR GB_QUANTITY
  8983. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  8984. {
  8985. if (((gunIndex > 0)&&(gunType[gunIndex-1] == GUN_TYPE_DO))&&(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus != SYS_MODE_FAULT)) //S_FAULT
  8986. {
  8987. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  8988. goto end;
  8989. }
  8990. }// END FOR GENERAL_GUN_QUANTITY
  8991. for (int index = 0; index < AC_QUANTITY; index++)
  8992. {
  8993. if (((gunIndex > 0)&&(gunType[gunIndex-1] == GUN_TYPE_AC)) &&(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_FAULT)) //S_FAULT
  8994. {
  8995. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  8996. goto end;
  8997. }
  8998. }//END FOR AC_QUANTITY
  8999. }//END FOR AvailabilityTypeStr[Operative]
  9000. end:
  9001. if((gunIndex != 0) && (gunIndex <= gunTotalNumber))
  9002. {
  9003. sprintf((char *)ShmOCPP16Data->ChangeAvailability[gunIndex - 1].ResponseStatus, "%s", comfirmstr );
  9004. }
  9005. else
  9006. {
  9007. sprintf((char *)ShmOCPP16Data->ChangeAvailability[0].ResponseStatus, "%s", comfirmstr );
  9008. }
  9009. if((gunIndex != 0) && (gunIndex <= gunTotalNumber))
  9010. {
  9011. if(strstr(comfirmstr, AvailabilityStatusStr[Rejected]) == NULL)
  9012. ShmOCPP16Data->CsMsg.bits[gunIndex - 1].ChangeAvailabilityReq = 1;
  9013. }
  9014. else if(gunIndex == 0)
  9015. {
  9016. if(strstr(comfirmstr, AvailabilityStatusStr[Rejected]) == NULL)
  9017. {
  9018. for(int i=0; i < gunTotalNumber/*(CHAdeMO_QUANTITY+ CCS_QUANTITY + GB_QUANTITY)*/; i++)
  9019. ShmOCPP16Data->CsMsg.bits[i].ChangeAvailabilityReq = 1;
  9020. }
  9021. }
  9022. sendChangeAvailabilityConfirmation(uuid, comfirmstr);
  9023. system("/bin/fsync -d /dev/mtdblock13;/bin/sync &");
  9024. return result;
  9025. }
  9026. int handleChangeConfigurationRequest(char *uuid, char *payload)
  9027. {
  9028. mtrace();
  9029. int valueInvalid = NO;
  9030. int result = FAIL;
  9031. char keystr[40]={0};
  9032. char valuestr[501]={0}; //value should be limited in 500 bytes
  9033. char comfirmstr[20]={0};
  9034. DEBUG_INFO("handleChangeConfigurationRequest...\n");
  9035. json_object *ChangeConfiguration;
  9036. ChangeConfiguration = json_tokener_parse(payload);
  9037. if(!is_error(ChangeConfiguration))
  9038. {
  9039. // Required data
  9040. if(json_object_object_get(ChangeConfiguration, "key") != NULL)
  9041. sprintf((char*)keystr, "%s", json_object_get_string(json_object_object_get(ChangeConfiguration, "key")));
  9042. if((json_object_object_get(ChangeConfiguration, "value") != NULL) && (strlen(json_object_get_string(json_object_object_get(ChangeConfiguration, "value"))) < ARRAY_SIZE(valuestr)))
  9043. {
  9044. sprintf((char*)valuestr, "%s", json_object_get_string(json_object_object_get(ChangeConfiguration, "value")));
  9045. }
  9046. else
  9047. {
  9048. valueInvalid = YES;
  9049. DEBUG_ERROR("The ChangeConfiguration value is NULL or OVER SIZE.\n");
  9050. }
  9051. }
  9052. json_object_put(ChangeConfiguration);
  9053. if((uuid==NULL) || (payload ==NULL) || (valueInvalid==YES))
  9054. {
  9055. DEBUG_ERROR("Payload is null or value is invalid.\n");
  9056. sprintf(comfirmstr, "%s", ConfigurationStatusStr[ConfigurationStatus_Rejected] );
  9057. }
  9058. else
  9059. {
  9060. int status = setKeyValue(keystr, valuestr);
  9061. switch(status)
  9062. {
  9063. case ConfigurationStatus_Accepted:
  9064. sprintf(comfirmstr, "%s", ConfigurationStatusStr[ConfigurationStatus_Accepted]);
  9065. ShmOCPP16Data->MsMsg.bits.ChangeConfigurationReq = 1;
  9066. StoreConfigurationTable();
  9067. break;
  9068. case RebootRequired:
  9069. sprintf(comfirmstr, "%s", ConfigurationStatusStr[RebootRequired]);
  9070. StoreConfigurationTable();
  9071. break;
  9072. case NotSupported:
  9073. sprintf(comfirmstr, "%s", ConfigurationStatusStr[NotSupported] );
  9074. break;
  9075. case ConfigurationStatus_Rejected:
  9076. default:
  9077. sprintf(comfirmstr, "%s", ConfigurationStatusStr[ConfigurationStatus_Rejected] );
  9078. break;
  9079. }
  9080. }
  9081. sendChangeConfigurationConfirmation(uuid, comfirmstr);
  9082. ShmOCPP16Data->MsMsg.bits.ChangeConfigurationConf = 1;
  9083. if(((strcmp(keystr,"AuthorizationKey")==0) || (strcmp(keystr,"SecurityProfile")==0) || (strcmp(keystr,"OcppServer")==0) || (strcmp(keystr,"MaintainServer")==0)) && (strcmp(comfirmstr,"Accepted")==0))
  9084. {
  9085. StoreUsrConfigData(&ShmSysConfigAndInfo->SysConfig);
  9086. SetOcppConnStatus(FALSE);
  9087. }
  9088. if(((strcmp(keystr,"FreeVend")==0) || (strcmp(keystr,"isEnableLocalPowerSharing")==0) || (strcmp(keystr,"PowerSharingServerIP")==0)) && (strcmp(comfirmstr,"Accepted")==0))
  9089. {
  9090. StoreUsrConfigData(&ShmSysConfigAndInfo->SysConfig);
  9091. }
  9092. return result;
  9093. }
  9094. int handleClearCacheRequest(char *uuid, char *payload)
  9095. {
  9096. mtrace();
  9097. int result = FAIL;
  9098. char comfirmstr[20];
  9099. char rmFileCmd[100]={0};
  9100. struct stat stats;
  9101. DEBUG_INFO("handleClearCacheRequest...\n");
  9102. stat("/Storage/OCPP", &stats);
  9103. // Check for directory existence
  9104. if (S_ISDIR(stats.st_mode) == 1)
  9105. {}
  9106. else
  9107. {
  9108. DEBUG_INFO("\n OCPP directory not exist, create dir \n");
  9109. sprintf(rmFileCmd,"mkdir -p %s","/Storage/OCPP");
  9110. system(rmFileCmd);
  9111. }
  9112. if(OCPP_cleanLocalCache())
  9113. {
  9114. sprintf(comfirmstr, "%s", ClearCacheStatusStr[ClearCacheStatus_Accepted] );
  9115. }
  9116. else
  9117. {
  9118. sprintf(comfirmstr, "%s", ClearCacheStatusStr[ClearCacheStatus_Rejected] );
  9119. }
  9120. sendClearCacheConfirmation(uuid, comfirmstr);
  9121. system("/bin/fsync -d /dev/mtdblock13;/bin/sync &");
  9122. return result;
  9123. }
  9124. int handleClearChargingProfileRequest(char *uuid, char *payload)
  9125. {
  9126. mtrace();
  9127. int result = FAIL;
  9128. int resultRename;
  9129. int connectorIdInt, chargingProfileIdInt, stackLevelInt;
  9130. char chargingProfilePurposeStr[26]={0};
  9131. int tempconnectorIdInt, tempchargingProfileIdInt, tempstackLevelInt;
  9132. char tempchargingProfilePurposeStr[26]={0};
  9133. char str[100]={0};
  9134. char fname[200]={0};
  9135. char comfirmstr[20]={0};
  9136. char word[1600]={0};
  9137. int clearflag = FALSE;
  9138. int chargingProfileIdIsNULL = FALSE;
  9139. int connectorIsNULL = FALSE;
  9140. int chargingProfilePurposeIsNULL = FALSE;
  9141. int stackLevelIsNULL = FALSE;
  9142. //int GotoEnd = FALSE;
  9143. FILE *fptr1, *fptr2;
  9144. char temp[] = "/Storage/OCPP/ClearChargingProfiletemp.json"; // Create temp file
  9145. int n_chargingProfile=0;
  9146. int isEmptyFile = FALSE;
  9147. char sLineWord[1600]={0};
  9148. char chargingProfiles[10][100]={0};
  9149. int ChargeProfileCount = 0;
  9150. int ch;
  9151. connectorIdInt = chargingProfileIdInt = stackLevelInt = 0;
  9152. DEBUG_INFO("handleClearChargingProfileRequest...\n");
  9153. json_object *ClearChargingProfile;
  9154. ClearChargingProfile = json_tokener_parse(payload);
  9155. if(!is_error(ClearChargingProfile))
  9156. {
  9157. // Optional data
  9158. if(json_object_object_get(ClearChargingProfile, "id") != NULL)
  9159. chargingProfileIdInt = json_object_get_int(json_object_object_get(ClearChargingProfile, "id"));
  9160. else
  9161. chargingProfileIdIsNULL = TRUE;
  9162. if(json_object_object_get(ClearChargingProfile, "connectorId") != NULL)
  9163. connectorIdInt = json_object_get_int(json_object_object_get(ClearChargingProfile, "connectorId"));
  9164. else
  9165. connectorIsNULL = TRUE;
  9166. if(json_object_object_get(ClearChargingProfile, "chargingProfilePurpose") != NULL)
  9167. sprintf((char*)chargingProfilePurposeStr, "%s", json_object_get_string(json_object_object_get(ClearChargingProfile, "chargingProfilePurpose")));
  9168. else
  9169. chargingProfilePurposeIsNULL = TRUE;
  9170. if(json_object_object_get(ClearChargingProfile, "stackLevel") != NULL)
  9171. stackLevelInt = json_object_get_int(json_object_object_get(ClearChargingProfile, "stackLevel"));
  9172. else
  9173. stackLevelIsNULL = TRUE;
  9174. }
  9175. json_object_put(ClearChargingProfile);
  9176. if(connectorIsNULL == FALSE)
  9177. {
  9178. switch(connectorIdInt)
  9179. {
  9180. case 0:
  9181. if(chargingProfilePurposeIsNULL == TRUE)
  9182. {
  9183. int l = 0;
  9184. strcpy(fname, ChargePointMaxProfile_JSON);
  9185. if((access(fname,F_OK))!=-1)
  9186. {
  9187. strcpy(chargingProfiles[l], fname);
  9188. l = l + 1;
  9189. }
  9190. strcpy(fname, TxDefaultProfile_0_JSON);
  9191. if((access(fname,F_OK))!=-1)
  9192. {
  9193. strcpy(chargingProfiles[l], fname);
  9194. l = l + 1;
  9195. }
  9196. ChargeProfileCount = l;
  9197. }
  9198. else if((chargingProfilePurposeIsNULL == FALSE)&&(strcmp(chargingProfilePurposeStr,"ChargePointMaxProfile")==0))
  9199. {
  9200. strcpy(fname, ChargePointMaxProfile_JSON);
  9201. if((access(fname,F_OK))!=-1)
  9202. {
  9203. strcpy(chargingProfiles[0], fname);
  9204. ChargeProfileCount = 1;
  9205. }
  9206. }
  9207. else if((chargingProfilePurposeIsNULL == FALSE)&&(strcmp(chargingProfilePurposeStr,"TxDefaultProfile")==0))
  9208. {
  9209. strcpy(fname, TxDefaultProfile_0_JSON);
  9210. if((access(fname,F_OK))!=-1)
  9211. {
  9212. strcpy(chargingProfiles[0], fname);
  9213. ChargeProfileCount = 1;
  9214. }
  9215. }
  9216. break;
  9217. default:
  9218. if(chargingProfilePurposeIsNULL == TRUE)
  9219. {
  9220. int m = 0;
  9221. memset(fname, 0, ARRAY_SIZE(fname));
  9222. sprintf(fname, "/Storage/OCPP/TxDefaultProfile_%d.json", connectorIdInt);
  9223. if((access(fname,F_OK))!=-1)
  9224. {
  9225. strcpy(chargingProfiles[m], fname);
  9226. m = m + 1;
  9227. }
  9228. memset(fname, 0, ARRAY_SIZE(fname));
  9229. sprintf(fname, "/Storage/OCPP/TxProfile_%d.json", connectorIdInt);
  9230. if((access(fname,F_OK))!=-1)
  9231. {
  9232. strcpy(chargingProfiles[m], fname);
  9233. m = m + 1;
  9234. }
  9235. ChargeProfileCount = m;
  9236. }
  9237. else if((chargingProfilePurposeIsNULL == FALSE)&&(strcmp(chargingProfilePurposeStr,"TxDefaultProfile")==0))
  9238. {
  9239. //strcpy(fname, TxDefaultProfile_1_JSON);
  9240. sprintf(fname, "/Storage/OCPP/TxDefaultProfile_%d.json", connectorIdInt);
  9241. if((access(fname,F_OK))!=-1)
  9242. {
  9243. strcpy(chargingProfiles[0], fname);
  9244. ChargeProfileCount = 1;
  9245. }
  9246. }
  9247. else if((chargingProfilePurposeIsNULL == FALSE)&&(strcmp(chargingProfilePurposeStr,"TxProfile")==0))
  9248. {
  9249. sprintf(fname, "/Storage/OCPP/TxProfile_%d.json", connectorIdInt);
  9250. if((access(fname,F_OK))!=-1)
  9251. {
  9252. strcpy(chargingProfiles[0], fname);
  9253. ChargeProfileCount = 1;
  9254. }
  9255. //strcpy(fname, TxProfile_1_JSON);
  9256. }
  9257. //strcpy(fname, ChargePointMaxProfile_JSON );
  9258. break;
  9259. }
  9260. }
  9261. else // Check all Charging Profiles
  9262. {
  9263. int i = 0;
  9264. char fnametemp[200]={0};
  9265. ChargeProfileCount = 0;
  9266. //Check ChargePointMaxProfile.json exit
  9267. if((access("/Storage/OCPP/ChargePointMaxProfile.json",F_OK))!=-1)
  9268. {
  9269. strcpy(chargingProfiles[i], "/Storage/OCPP/ChargePointMaxProfile.json");
  9270. i = i + 1;
  9271. }
  9272. //Check TxDefaultProfile_0.json exit
  9273. if((access("/Storage/OCPP/TxDefaultProfile_0.json",F_OK))!=-1)
  9274. {
  9275. strcpy(chargingProfiles[i], "/Storage/OCPP/TxDefaultProfile_0.json");
  9276. i = i + 1;
  9277. }
  9278. //Check TxDefaultProfile_%d.json
  9279. for(int j=1; j <= gunTotalNumber; j++)
  9280. {
  9281. memset(fnametemp, 0, ARRAY_SIZE(fnametemp));
  9282. sprintf(fnametemp, "/Storage/OCPP/TxDefaultProfile_%d.json", j);
  9283. if((access(fnametemp,F_OK))!=-1)
  9284. {
  9285. strcpy(chargingProfiles[i], fnametemp);
  9286. i = i + 1;
  9287. }
  9288. }
  9289. //Check TxProfile_%d.json
  9290. for(int j=1; j <= gunTotalNumber; j++)
  9291. {
  9292. memset(fnametemp, 0, ARRAY_SIZE(fnametemp));
  9293. sprintf(fnametemp, "/Storage/OCPP/TxProfile_%d.json", j);
  9294. if((access(fnametemp,F_OK))!=-1)
  9295. {
  9296. strcpy(chargingProfiles[i], fnametemp);
  9297. i = i + 1;
  9298. }
  9299. }
  9300. ChargeProfileCount = i;
  9301. }// End connectorIsNULL is TRUE
  9302. if(ChargeProfileCount == 0)
  9303. {
  9304. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Unknown] );
  9305. goto end;
  9306. }
  9307. if(connectorIsNULL == FALSE && (connectorIdInt != 0) && ( (connectorIdInt-1) > gunTotalNumber) )
  9308. {
  9309. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Unknown] );
  9310. goto end;
  9311. }
  9312. if((connectorIsNULL == FALSE) && (connectorIdInt == 0) )
  9313. {
  9314. memset(str, 0, ARRAY_SIZE(str));
  9315. // clear temp file
  9316. sprintf(str,"rm -f %s",temp);
  9317. system(str);
  9318. for(int k=0; k < ChargeProfileCount; k++)
  9319. {
  9320. memset(str, 0, ARRAY_SIZE(str));
  9321. //clear file in C
  9322. sprintf(str,"rm -f %s",chargingProfiles[k]);
  9323. system(str);
  9324. }
  9325. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Accepted] );
  9326. goto end;
  9327. }
  9328. else if(connectorIsNULL == TRUE)
  9329. {
  9330. for(int k=0; k < ChargeProfileCount; k++)
  9331. {
  9332. fptr1 = fopen(chargingProfiles[k], "r");
  9333. fptr2 = fopen("/Storage/OCPP/ClearChargingProfiletemp.json", "w+");
  9334. //Check Charging Profile Count
  9335. while(fscanf(fptr1, "%s", word) != EOF)
  9336. {
  9337. //DEBUG_INFO("word=%s\n",word);
  9338. if(strstr(word, "chargingProfileId")!= NULL)
  9339. {
  9340. //DEBUG_INFO("test chargingProfileId \n");
  9341. n_chargingProfile = n_chargingProfile + 1;
  9342. //DEBUG_INFO("chargingProfileId Found\n");
  9343. }
  9344. }
  9345. rewind(fptr1);
  9346. //search Charging Profile Element
  9347. //int i= 0;
  9348. while ( fgets( sLineWord, sizeof sLineWord, fptr1 ) != NULL )
  9349. {
  9350. json_object *tmpProfilee;
  9351. tmpProfilee = json_tokener_parse(sLineWord);
  9352. if(!is_error(tmpProfilee))
  9353. {
  9354. if(json_object_object_get(tmpProfilee, "connectorId") != NULL)
  9355. {
  9356. tempconnectorIdInt = json_object_get_int(json_object_object_get(tmpProfilee, "connectorId"));
  9357. DEBUG_INFO("file's gun number: %d\n", tempconnectorIdInt);
  9358. }
  9359. if(json_object_object_get(json_object_object_get(tmpProfilee, "csChargingProfiles"), "chargingProfileId") != NULL)
  9360. {
  9361. tempchargingProfileIdInt = json_object_get_int(json_object_object_get(json_object_object_get(tmpProfilee, "csChargingProfiles"), "chargingProfileId"));
  9362. DEBUG_INFO("file's chargingProfileId: %d\n", tempchargingProfileIdInt);
  9363. }
  9364. if(json_object_object_get(json_object_object_get(tmpProfilee, "csChargingProfiles"), "stackLevel") != NULL)
  9365. {
  9366. tempstackLevelInt = json_object_get_int(json_object_object_get(json_object_object_get(tmpProfilee, "csChargingProfiles"), "stackLevel"));
  9367. DEBUG_INFO("file's stackLevel: %d\n", tempstackLevelInt);
  9368. }
  9369. if(json_object_object_get(json_object_object_get(tmpProfilee, "csChargingProfiles"), "chargingProfilePurpose") != NULL)
  9370. {
  9371. sprintf((char*)tempchargingProfilePurposeStr, "%s", json_object_get_string(json_object_object_get(json_object_object_get(tmpProfilee, "csChargingProfiles"), "chargingProfilePurpose")));
  9372. DEBUG_INFO("file's chargingProfilePurpose: %s\n", tempchargingProfilePurposeStr);
  9373. }
  9374. }
  9375. json_object_put(tmpProfilee);
  9376. if((chargingProfileIdIsNULL == FALSE)&&(tempchargingProfileIdInt == chargingProfileIdInt))
  9377. {
  9378. //------- not write to fptr2-------//
  9379. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Accepted] );
  9380. //clearflag = TRUE;
  9381. }
  9382. else if((chargingProfilePurposeIsNULL == FALSE)&&(strcmp(tempchargingProfilePurposeStr, chargingProfilePurposeStr) == 0))
  9383. {
  9384. //------- not write to fptr2-------//
  9385. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Accepted] );
  9386. }
  9387. else if((stackLevelIsNULL == FALSE) &&(tempstackLevelInt == stackLevelInt))
  9388. {
  9389. //------- not write to fptr2-------//
  9390. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Accepted] );
  9391. }
  9392. else if(chargingProfileIdIsNULL && chargingProfilePurposeIsNULL && stackLevelIsNULL)
  9393. {
  9394. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Accepted] );
  9395. }
  9396. else
  9397. {
  9398. fprintf(fptr2, sLineWord);//writing data into file
  9399. }
  9400. memset(sLineWord, 0, ARRAY_SIZE(sLineWord));
  9401. } //End of while ( fgets( sLineWord, sizeof sLineWord, fptr1 ) != NULL )
  9402. if(clearflag == TRUE)
  9403. {
  9404. fclose(fptr1);
  9405. fclose(fptr2);
  9406. sprintf(str,"rm -f %s",chargingProfiles[k]);
  9407. system(str);
  9408. // clear temp file
  9409. sprintf(str,"rm -f %s",temp);
  9410. system(str);
  9411. }
  9412. else
  9413. {
  9414. fclose(fptr1);
  9415. fclose(fptr2);
  9416. memset(str, 0, ARRAY_SIZE(str));
  9417. sprintf(str,"rm -f %s",chargingProfiles[k]);
  9418. system(str);
  9419. resultRename = rename(temp, chargingProfiles[k]);
  9420. if(resultRename == 0)
  9421. {
  9422. DEBUG_INFO("File ChargingProfile renamed successfully\n");
  9423. }
  9424. else
  9425. {
  9426. DEBUG_INFO("Error: unable to rename the ChargingProfile file\n");
  9427. }
  9428. if(comfirmstr[0]== 0)
  9429. {
  9430. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Unknown] );
  9431. }
  9432. //Check chargingProfile is empty file
  9433. /*------ Read the file ----------------*/
  9434. fptr1=fopen(chargingProfiles[k],"r");
  9435. ch=fgetc(fptr1);
  9436. rewind(fptr1);
  9437. memset(sLineWord, 0, ARRAY_SIZE(sLineWord));
  9438. if(ch!=EOF)
  9439. {
  9440. while (fgets( sLineWord, sizeof sLineWord, fptr1) != NULL)
  9441. {
  9442. str[strlen(sLineWord) - 1] = '\0'; // eat the newline fgets() stores
  9443. if(sLineWord[0]=='\0')
  9444. {
  9445. isEmptyFile = TRUE;
  9446. break;
  9447. }
  9448. else
  9449. {
  9450. isEmptyFile = FALSE;
  9451. break;
  9452. }
  9453. }
  9454. }
  9455. else
  9456. isEmptyFile = TRUE;
  9457. fclose(fptr1);
  9458. if(isEmptyFile == TRUE)
  9459. {
  9460. memset(str, 0, ARRAY_SIZE(str));
  9461. sprintf(str,"rm -f %s",chargingProfiles[k]);
  9462. system(str);
  9463. }
  9464. }
  9465. }// End of while(int k=0; k < ChargePointCount; k++)
  9466. }
  9467. else if((connectorIsNULL == FALSE) && (connectorIdInt != 0) )
  9468. {
  9469. DEBUG_INFO("ChargeProfileCount = %d\n", ChargeProfileCount);
  9470. for(int k=0; k < ChargeProfileCount; k++)
  9471. {
  9472. fptr1 = fopen(chargingProfiles[k], "r");
  9473. fptr2 = fopen(temp, "w+");
  9474. //Check Charging Profile Count
  9475. while(fscanf(fptr1, "%s", word) != EOF)
  9476. {
  9477. //DEBUG_INFO("word=%s\n",word);
  9478. if(strstr(word, "chargingProfileId")!= NULL)
  9479. {
  9480. n_chargingProfile = n_chargingProfile + 1;
  9481. }
  9482. }
  9483. rewind(fptr1);
  9484. //search Charging Profile Element
  9485. //int i= 0;
  9486. while ( fgets( sLineWord, sizeof sLineWord, fptr1 ) != NULL )
  9487. {
  9488. json_object *tmpProfilee;
  9489. tmpProfilee = json_tokener_parse(sLineWord);
  9490. if(!is_error(tmpProfilee))
  9491. {
  9492. if(json_object_object_get(tmpProfilee, "connectorId") != NULL)
  9493. {
  9494. tempconnectorIdInt = json_object_get_int(json_object_object_get(tmpProfilee, "connectorId"));
  9495. DEBUG_INFO("file's gun number: %d\n", tempconnectorIdInt);
  9496. }
  9497. if(json_object_object_get(json_object_object_get(tmpProfilee, "csChargingProfiles"), "chargingProfileId") != NULL)
  9498. {
  9499. tempchargingProfileIdInt = json_object_get_int(json_object_object_get(json_object_object_get(tmpProfilee, "csChargingProfiles"), "chargingProfileId"));
  9500. DEBUG_INFO("file's chargingProfileId: %d\n", tempchargingProfileIdInt);
  9501. }
  9502. if(json_object_object_get(json_object_object_get(tmpProfilee, "csChargingProfiles"), "stackLevel") != NULL)
  9503. {
  9504. tempstackLevelInt = json_object_get_int(json_object_object_get(json_object_object_get(tmpProfilee, "csChargingProfiles"), "stackLevel"));
  9505. DEBUG_INFO("file's stackLevel: %d\n", tempstackLevelInt);
  9506. }
  9507. if(json_object_object_get(json_object_object_get(tmpProfilee, "csChargingProfiles"), "chargingProfilePurpose") != NULL)
  9508. {
  9509. sprintf((char*)tempchargingProfilePurposeStr, "%s", json_object_get_string(json_object_object_get(json_object_object_get(tmpProfilee, "csChargingProfiles"), "chargingProfilePurpose")));
  9510. DEBUG_INFO("file's chargingProfilePurpose: %s\n", tempchargingProfilePurposeStr);
  9511. }
  9512. }
  9513. json_object_put(tmpProfilee);
  9514. if((chargingProfileIdIsNULL == FALSE)&&(tempchargingProfileIdInt == chargingProfileIdInt))
  9515. {
  9516. //------- not write to fptr2-------//
  9517. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Accepted] );
  9518. //clearflag = TRUE;
  9519. }
  9520. else if((stackLevelIsNULL == FALSE) &&(tempstackLevelInt == stackLevelInt))
  9521. {
  9522. //------- not write to fptr2-------//
  9523. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Accepted] );
  9524. }
  9525. else if(stackLevelIsNULL == TRUE)
  9526. {
  9527. //Clear Whole File
  9528. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Accepted] );
  9529. clearflag = TRUE;
  9530. break;
  9531. }
  9532. else
  9533. {
  9534. fprintf(fptr2, sLineWord);//writing data into file
  9535. }
  9536. memset(sLineWord, 0, ARRAY_SIZE(sLineWord));
  9537. }
  9538. if(clearflag == TRUE)
  9539. {
  9540. fclose(fptr1);
  9541. fclose(fptr2);
  9542. sprintf(str,"rm -f %s",chargingProfiles[k]);
  9543. system(str);
  9544. // clear temp file
  9545. sprintf(str,"rm -f %s",temp);
  9546. system(str);
  9547. }
  9548. else
  9549. {
  9550. fclose(fptr1);
  9551. fclose(fptr2);
  9552. sprintf(str,"rm -f %s",chargingProfiles[k]);
  9553. system(str);
  9554. resultRename = rename(temp, chargingProfiles[k]);
  9555. if(resultRename == 0)
  9556. {
  9557. DEBUG_INFO("File ChargingProfile renamed successfully");
  9558. }
  9559. else
  9560. {
  9561. DEBUG_INFO("Error: unable to rename the ChargingProfile file");
  9562. }
  9563. if(comfirmstr[0]== 0)
  9564. {
  9565. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Unknown] );
  9566. }
  9567. //Check chargingProfile is empty file
  9568. /*------ Read the file ----------------*/
  9569. fptr1=fopen(chargingProfiles[k],"r");
  9570. ch=fgetc(fptr1);
  9571. rewind(fptr1);
  9572. memset(sLineWord, 0, ARRAY_SIZE(sLineWord));
  9573. if(ch!=EOF)
  9574. {
  9575. while (fgets( sLineWord, sizeof sLineWord, fptr1) != NULL)
  9576. {
  9577. str[strlen(sLineWord) - 1] = '\0'; // eat the newline fgets() stores
  9578. if(sLineWord[0]=='\0')
  9579. {
  9580. isEmptyFile = TRUE;
  9581. break;
  9582. }
  9583. else
  9584. {
  9585. isEmptyFile = FALSE;
  9586. break;
  9587. }
  9588. }
  9589. }
  9590. else
  9591. isEmptyFile = TRUE;
  9592. fclose(fptr1);
  9593. if(isEmptyFile == TRUE)
  9594. {
  9595. memset(str, 0, ARRAY_SIZE(str));
  9596. sprintf(str,"rm -f %s",chargingProfiles[k]);
  9597. system(str);
  9598. }
  9599. /*------- End of reading ---------------*/
  9600. }
  9601. } // while(int k=0; k < ChargeProfileCount; k++)
  9602. }// (connectorIsNULL == FALSE) && (connectorIdInt != 0)
  9603. end:
  9604. if(strcmp(comfirmstr, ClearChargingProfileStatusStr[ClearChargingProfileStatus_Accepted]) == 0)
  9605. {
  9606. if(connectorIdInt == 0)
  9607. {
  9608. for(uint8_t idx=0;idx<gunTotalNumber;idx++)
  9609. {
  9610. checkCompositeSchedule((idx+1), 86400, &ShmOCPP16Data->SmartChargingProfile[idx], TRUE);
  9611. }
  9612. }
  9613. else
  9614. checkCompositeSchedule(connectorIdInt, 86400, &ShmOCPP16Data->SmartChargingProfile[connectorIdInt-1], TRUE);
  9615. }
  9616. sendClearChargingProfileConfirmation(uuid, comfirmstr);
  9617. system("/bin/fsync -d /dev/mtdblock13;/bin/sync &");
  9618. return result;
  9619. }
  9620. void createFirmwareVersionByDataTransfer(void)
  9621. {
  9622. json_object *FirmwareDataTransfer = json_object_new_object();
  9623. // AC & DC model
  9624. json_object_object_add(FirmwareDataTransfer, "CsuBootLoadFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.CsuBootLoadFwRev));
  9625. json_object_object_add(FirmwareDataTransfer, "CsuKernelFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.CsuKernelFwRev));
  9626. json_object_object_add(FirmwareDataTransfer, "CsuRootFsFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.CsuRootFsFwRev));
  9627. json_object_object_add(FirmwareDataTransfer, "CsuPrimFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.CsuPrimFwRev));
  9628. // DC model
  9629. if((ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D'))
  9630. {
  9631. if((gunType[1] != GUN_TYPE_UNKNOWN) ||
  9632. (gunType[2] != GUN_TYPE_UNKNOWN) ||
  9633. (gunType[3] != GUN_TYPE_UNKNOWN))
  9634. {
  9635. json_object_object_add(FirmwareDataTransfer, "Connector2FwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.Connector2FwRev));
  9636. }
  9637. if((ShmSysConfigAndInfo->SysConfig.ModelName[1]!='B') && (ShmSysConfigAndInfo->SysConfig.ModelName[1]!='K') && (ShmSysConfigAndInfo->SysConfig.ModelName[1]!='O'))
  9638. {
  9639. // DS DM DW
  9640. json_object_object_add(FirmwareDataTransfer, "FanModuleFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.FanModuleFwRev));
  9641. json_object_object_add(FirmwareDataTransfer, "RelayModuleFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.RelayModuleFwRev));
  9642. json_object_object_add(FirmwareDataTransfer, "LedModuleFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.LedModuleFwRev));
  9643. json_object_object_add(FirmwareDataTransfer, "Connector1FwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.Connector1FwRev));
  9644. json_object_object_add(FirmwareDataTransfer, "PsuPrimFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.PsuPrimFwRev));
  9645. json_object_object_add(FirmwareDataTransfer, "PsuSecFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.PsuSecFwRev));
  9646. }
  9647. else
  9648. {
  9649. json_object_object_add(FirmwareDataTransfer, "FanModuleFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.FanModuleFwRev));
  9650. json_object_object_add(FirmwareDataTransfer, "RelayModuleFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.RelayModuleFwRev));
  9651. json_object_object_add(FirmwareDataTransfer, "PsuPrimFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.PsuPrimFwRev));
  9652. json_object_object_add(FirmwareDataTransfer, "PsuSecFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.PsuSecFwRev));
  9653. json_object_object_add(FirmwareDataTransfer, "DD0_CsuBootLoadFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[0].CsuBootLoadFwRev));
  9654. json_object_object_add(FirmwareDataTransfer, "DD0_CsuKernelFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[0].CsuKernelFwRev));
  9655. json_object_object_add(FirmwareDataTransfer, "DD0_CsuRootFsFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[0].CsuRootFsFwRev));
  9656. json_object_object_add(FirmwareDataTransfer, "DD0_CsuPrimFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[0].CsuPrimFwRev));
  9657. json_object_object_add(FirmwareDataTransfer, "DD0_FanModuleFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[0].FanModuleFwRev));
  9658. json_object_object_add(FirmwareDataTransfer, "DD0_RelayModuleFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[0].RelayModuleFwRev));
  9659. json_object_object_add(FirmwareDataTransfer, "DD0_LedModuleFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[0].LedModuleFwRev));
  9660. json_object_object_add(FirmwareDataTransfer, "DD0_Connector1FwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[0].Connector1FwRev));
  9661. json_object_object_add(FirmwareDataTransfer, "DD0_Connector2FwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[0].Connector2FwRev));
  9662. if(strlen((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].CsuBootLoadFwRev) > 0)
  9663. json_object_object_add(FirmwareDataTransfer, "DD1_CsuBootLoadFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].CsuBootLoadFwRev));
  9664. if(strlen((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].CsuKernelFwRev) > 0)
  9665. json_object_object_add(FirmwareDataTransfer, "DD1_CsuKernelFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].CsuKernelFwRev));
  9666. if(strlen((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].CsuRootFsFwRev) > 0)
  9667. json_object_object_add(FirmwareDataTransfer, "DD1_CsuRootFsFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].CsuRootFsFwRev));
  9668. if(strlen((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].CsuPrimFwRev) > 0)
  9669. json_object_object_add(FirmwareDataTransfer, "DD1_CsuPrimFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].CsuPrimFwRev));
  9670. if(strlen((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].FanModuleFwRev) > 0)
  9671. json_object_object_add(FirmwareDataTransfer, "DD1_FanModuleFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].FanModuleFwRev));
  9672. if(strlen((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].RelayModuleFwRev) > 0)
  9673. json_object_object_add(FirmwareDataTransfer, "DD1_RelayModuleFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].RelayModuleFwRev));
  9674. if(strlen((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].LedModuleFwRev) > 0)
  9675. json_object_object_add(FirmwareDataTransfer, "DD1_LedModuleFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].LedModuleFwRev));
  9676. if(strlen((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].Connector1FwRev) > 0)
  9677. json_object_object_add(FirmwareDataTransfer, "DD1_Connector1FwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].Connector1FwRev));
  9678. if(strlen((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].Connector2FwRev) > 0)
  9679. json_object_object_add(FirmwareDataTransfer, "D11_Connector2FwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].Connector2FwRev));
  9680. }
  9681. }
  9682. // 4G model
  9683. if((ShmSysConfigAndInfo->SysConfig.ModelName[10]=='T')||(ShmSysConfigAndInfo->SysConfig.ModelName[10]=='D'))
  9684. {
  9685. json_object_object_add(FirmwareDataTransfer, "TelcomModemFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysConfig.TelecomInterface.TelcomSoftwareVer));
  9686. }
  9687. sprintf((char*)ShmOCPP16Data->DataTransfer[0].ResponseData, json_object_to_json_string_ext(FirmwareDataTransfer, JSON_C_TO_STRING_PLAIN));
  9688. json_object_put(FirmwareDataTransfer);
  9689. }
  9690. int handleDataTransferRequest(char *uuid, char *payload)
  9691. {
  9692. mtrace();
  9693. json_object *response = json_object_new_object();
  9694. int result = FAIL;
  9695. char tempvendorId[255]={0};
  9696. char tempmessageId[50]={0};
  9697. char tempdata[1024]={0};
  9698. char message[2048]={0};
  9699. DEBUG_INFO("handleDataTransferRequest...\n");
  9700. if((uuid != NULL) && (payload != NULL))
  9701. {
  9702. json_object *DataTransfer;
  9703. DataTransfer = json_tokener_parse(payload);
  9704. if(!is_error(DataTransfer))
  9705. {
  9706. // Required data
  9707. if(json_object_object_get(DataTransfer, "vendorId") != NULL)
  9708. sprintf((char*)tempvendorId, "%s", json_object_get_string(json_object_object_get(DataTransfer, "vendorId")));
  9709. // Optional data
  9710. if(json_object_object_get(DataTransfer, "messageId") != NULL)
  9711. sprintf((char*)tempmessageId, "%s", json_object_get_string(json_object_object_get(DataTransfer, "messageId")));
  9712. if(json_object_object_get(DataTransfer, "data") != NULL)
  9713. sprintf((char*)tempdata, "%s", json_object_get_string(json_object_object_get(DataTransfer, "data")));
  9714. result = PASS;
  9715. }
  9716. json_object_put(DataTransfer);
  9717. if(strstr(tempmessageId, "ID_FirmwareVersion") != NULL)
  9718. {
  9719. // Send all moudle firmware version on EVSE
  9720. createFirmwareVersionByDataTransfer();
  9721. json_object_object_add(response, "status", json_object_new_string("Accepted"));
  9722. json_object_object_add(response, "data", json_object_new_string((char*)ShmOCPP16Data->DataTransfer[0].ResponseData));
  9723. sprintf(message,"[%d,\"%s\",%s]",MESSAGE_TYPE_CALLRESULT, uuid, json_object_to_json_string_ext(response, JSON_C_TO_STRING_PLAIN));
  9724. json_object_put(response);
  9725. }
  9726. else if(strstr(tempmessageId, "ID_Tmate") != NULL)
  9727. {
  9728. system("/usr/bin/run_tmate_restart.sh &");
  9729. json_object_object_add(response, "status", json_object_new_string("Accepted"));
  9730. sprintf(message,"[%d,\"%s\",%s]",MESSAGE_TYPE_CALLRESULT, uuid, json_object_to_json_string_ext(response, JSON_C_TO_STRING_PLAIN));
  9731. json_object_put(response);
  9732. }
  9733. else if(strstr(tempmessageId, "ID_ChargingPreference") != NULL)
  9734. {
  9735. json_object *data;
  9736. data = json_tokener_parse(tempdata);
  9737. if(!is_error(data))
  9738. {
  9739. 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))
  9740. {
  9741. DEBUG_INFO("ChargeingPreference connector id: %d\n", json_object_get_int(json_object_object_get(data, "ConnectorId")));
  9742. memset(&ShmOCPP16Data->SessionTarget[json_object_get_int(json_object_object_get(data, "ConnectorId"))], 0x00, sizeof(struct StructSessionTarget));
  9743. if(json_object_object_get(data, "SOC") != NULL)
  9744. {
  9745. ShmOCPP16Data->SessionTarget[json_object_get_int(json_object_object_get(data, "ConnectorId"))-1].targetSoc = json_object_get_int(json_object_object_get(data, "SOC"));
  9746. DEBUG_INFO("ChargeingPreference target soc: %d\n", json_object_get_int(json_object_object_get(data, "SOC")));
  9747. }
  9748. if(json_object_object_get(data, "Energy") != NULL)
  9749. {
  9750. ShmOCPP16Data->SessionTarget[json_object_get_int(json_object_object_get(data, "ConnectorId"))-1].targetEnergy = json_object_get_int(json_object_object_get(data, "Energy"));
  9751. DEBUG_INFO("ChargeingPreference target energy: %d KWH\n", json_object_get_int(json_object_object_get(data, "Energy")));
  9752. }
  9753. if(json_object_object_get(data, "Duration") != NULL)
  9754. {
  9755. ShmOCPP16Data->SessionTarget[json_object_get_int(json_object_object_get(data, "ConnectorId"))-1].targetDuration = json_object_get_int(json_object_object_get(data, "Duration"));
  9756. DEBUG_INFO("ChargeingPreference target duration: %d minutes\n", json_object_get_int(json_object_object_get(data, "Duration")));
  9757. }
  9758. json_object_object_add(response, "status", json_object_new_string("Accepted"));
  9759. }
  9760. else
  9761. {
  9762. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  9763. json_object_object_add(response, "data", json_object_new_string("Connector id must > 0."));
  9764. }
  9765. }
  9766. else
  9767. {
  9768. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  9769. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  9770. }
  9771. json_object_put(data);
  9772. sprintf(message,"[%d,\"%s\",%s]",MESSAGE_TYPE_CALLRESULT, uuid, json_object_to_json_string_ext(response, JSON_C_TO_STRING_PLAIN));
  9773. json_object_put(response);
  9774. }
  9775. else if(strstr(tempmessageId, "SetLEDBar") != NULL)
  9776. {
  9777. json_object *data;
  9778. data = json_tokener_parse(tempdata);
  9779. if(!is_error(data))
  9780. {
  9781. ShmSysConfigAndInfo->SysConfig.LedInfo.Intensity = json_object_get_int(json_object_object_get(data, "Intensity"));
  9782. ShmSysConfigAndInfo->SysConfig.LedInfo.Red[0] = json_object_get_int(json_object_object_get(json_object_object_get(data, "Idle"), "R"));
  9783. ShmSysConfigAndInfo->SysConfig.LedInfo.Green[0]= json_object_get_int(json_object_object_get(json_object_object_get(data, "Idle"), "G"));
  9784. ShmSysConfigAndInfo->SysConfig.LedInfo.Blue[0] = json_object_get_int(json_object_object_get(json_object_object_get(data, "Idle"), "B"));
  9785. ShmSysConfigAndInfo->SysConfig.LedInfo.Red[1] = json_object_get_int(json_object_object_get(json_object_object_get(data, "Charging"), "R"));
  9786. ShmSysConfigAndInfo->SysConfig.LedInfo.Green[1]= json_object_get_int(json_object_object_get(json_object_object_get(data, "Charging"), "G"));
  9787. ShmSysConfigAndInfo->SysConfig.LedInfo.Blue[1] = json_object_get_int(json_object_object_get(json_object_object_get(data, "Charging"), "B"));
  9788. ShmSysConfigAndInfo->SysConfig.LedInfo.Red[2] = json_object_get_int(json_object_object_get(json_object_object_get(data, "Fault"), "R"));
  9789. ShmSysConfigAndInfo->SysConfig.LedInfo.Green[2]= json_object_get_int(json_object_object_get(json_object_object_get(data, "Fault"), "G"));
  9790. ShmSysConfigAndInfo->SysConfig.LedInfo.Blue[2] = json_object_get_int(json_object_object_get(json_object_object_get(data, "Fault"), "B"));
  9791. json_object_object_add(response, "status", json_object_new_string("Accepted"));
  9792. }
  9793. else
  9794. {
  9795. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  9796. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  9797. }
  9798. json_object_put(data);
  9799. sprintf(message,"[%d,\"%s\",%s]",MESSAGE_TYPE_CALLRESULT, uuid, json_object_to_json_string_ext(response, JSON_C_TO_STRING_PLAIN));
  9800. json_object_put(response);
  9801. }
  9802. else if(strstr(tempmessageId, "SetUserPrice") != NULL)
  9803. {
  9804. json_object *data;
  9805. data = json_tokener_parse(tempdata);
  9806. if(!is_error(data))
  9807. {
  9808. memset(&ShmOCPP16Data->Cost.SetUserPrice, 0x00, sizeof(struct StrcutSetUserPrice));
  9809. json_object_object_add(response, "status", json_object_new_string("Accepted"));
  9810. if(json_object_object_get(data, "idToken") != NULL)
  9811. {
  9812. sprintf((char*)ShmOCPP16Data->Cost.SetUserPrice.idToken, "%s", json_object_get_string(json_object_object_get(data, "idToken")));
  9813. DEBUG_INFO("idToken: %s\n", json_object_get_string(json_object_object_get(data, "idToken")));
  9814. }
  9815. else
  9816. {
  9817. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  9818. json_object_object_add(response, "data", json_object_new_string("idToken not found."));
  9819. }
  9820. if(json_object_object_get(data, "price") != NULL) //v1.0
  9821. {
  9822. sprintf((char*)ShmOCPP16Data->Cost.SetUserPrice.price, "%s", json_object_get_string(json_object_object_get(data, "price")));
  9823. DEBUG_INFO("price: %s\n", json_object_get_string(json_object_object_get(data, "price")));
  9824. }
  9825. else if(json_object_object_get(data, "priceText") != NULL) //v2.0
  9826. {
  9827. sprintf((char*)ShmOCPP16Data->Cost.SetUserPrice.price, "%s", json_object_get_string(json_object_object_get(data, "priceText")));
  9828. DEBUG_INFO("priceText: %s\n", json_object_get_string(json_object_object_get(data, "priceText")));
  9829. }
  9830. else
  9831. {
  9832. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  9833. json_object_object_add(response, "data", json_object_new_string("price or priceText not found."));
  9834. }
  9835. }
  9836. else
  9837. {
  9838. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  9839. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  9840. }
  9841. json_object_put(data);
  9842. sprintf(message,"[%d,\"%s\",%s]",MESSAGE_TYPE_CALLRESULT, uuid, json_object_to_json_string_ext(response, JSON_C_TO_STRING_PLAIN));
  9843. json_object_put(response);
  9844. }
  9845. else if(strstr(tempmessageId, "RunningCost") != NULL)
  9846. {
  9847. json_object *data;
  9848. data = json_tokener_parse(tempdata);
  9849. if(!is_error(data))
  9850. {
  9851. json_object_object_add(response, "status", json_object_new_string("Accepted"));
  9852. if(json_object_object_get(data, "txId") != NULL)
  9853. {
  9854. // California pricing V1.0
  9855. DEBUG_INFO("California pricing V1.0\n");
  9856. DEBUG_INFO("txId: %d\n", json_object_get_int(json_object_object_get(data, "txId")));
  9857. sprintf((char*)dmsVersion, "1.0");
  9858. for(int idx = 0;idx<gunTotalNumber;idx++)
  9859. {
  9860. if(ShmOCPP16Data->StartTransaction[idx].ResponseTransactionId == json_object_get_int(json_object_object_get(data, "txId")))
  9861. {
  9862. memset(&ShmOCPP16Data->Cost.RunningCost[idx], 0x00, sizeof(struct StrcutRunningCost));
  9863. ShmOCPP16Data->Cost.RunningCost[idx].txId = json_object_get_int(json_object_object_get(data, "txId"));
  9864. if(json_object_object_get(data, "description") != NULL)
  9865. {
  9866. DEBUG_INFO("description: %s\n", json_object_get_string(json_object_object_get(data, "description")));
  9867. sprintf((char*)ShmOCPP16Data->Cost.RunningCost[idx].description, "%s", json_object_get_string(json_object_object_get(data, "description")));
  9868. }
  9869. else
  9870. {
  9871. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  9872. json_object_object_add(response, "data", json_object_new_string("description not found."));
  9873. }
  9874. }
  9875. }
  9876. }
  9877. else if(json_object_object_get(data, "transactionId") != NULL)
  9878. {
  9879. // California pricing V2.0
  9880. DEBUG_INFO("California pricing V2.0\n");
  9881. DEBUG_INFO("transactionId: %d\n", json_object_get_int(json_object_object_get(data, "transactionId")));
  9882. sprintf((char*)dmsVersion, "2.0");
  9883. for(int idx=0;idx<gunTotalNumber;idx++)
  9884. {
  9885. if(ShmOCPP16Data->StartTransaction[idx].ResponseTransactionId == json_object_get_int(json_object_object_get(data, "transactionId")))
  9886. {
  9887. ShmOCPP16Data->Cost.RunningCost[idx].txId = json_object_get_int(json_object_object_get(data, "transactionId"));
  9888. if(json_object_object_get(data, "timestamp") != NULL)
  9889. {
  9890. DEBUG_INFO("timestamp: %s\n", json_object_get_string(json_object_object_get(data, "timestamp")));
  9891. sprintf((char*)ShmOCPP16Data->Cost.RunningCost[idx].timestamp, "%s", json_object_get_string(json_object_object_get(data, "timestamp")));
  9892. }
  9893. else
  9894. {
  9895. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  9896. json_object_object_add(response, "data", json_object_new_string("timestamp not found."));
  9897. }
  9898. if(json_object_object_get(data, "meterValue") != NULL)
  9899. {
  9900. DEBUG_INFO("meterValue: %d\n", json_object_get_int(json_object_object_get(data, "meterValue")));
  9901. ShmOCPP16Data->Cost.RunningCost[idx].meterValue = json_object_get_int(json_object_object_get(data, "meterValue"));
  9902. }
  9903. else
  9904. {
  9905. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  9906. json_object_object_add(response, "data", json_object_new_string("meterValue not found."));
  9907. }
  9908. if(json_object_object_get(data, "cost") != NULL)
  9909. {
  9910. DEBUG_INFO("cost: %f\n", json_object_get_double(json_object_object_get(data, "cost")));
  9911. ShmOCPP16Data->Cost.RunningCost[idx].cost = json_object_get_double(json_object_object_get(data, "cost"));
  9912. }
  9913. else
  9914. {
  9915. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  9916. json_object_object_add(response, "data", json_object_new_string("cost not found."));
  9917. }
  9918. if(json_object_object_get(data, "state") != NULL)
  9919. {
  9920. DEBUG_INFO("state: %s\n", json_object_get_string(json_object_object_get(data, "state")));
  9921. sprintf((char*)ShmOCPP16Data->Cost.RunningCost[idx].state, "%s", json_object_get_string(json_object_object_get(data, "state")));
  9922. }
  9923. else
  9924. {
  9925. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  9926. json_object_object_add(response, "data", json_object_new_string("state not found."));
  9927. }
  9928. if(json_object_object_get(data, "chargingPrice") != NULL)
  9929. {
  9930. if(json_object_object_get(json_object_object_get(data, "chargingPrice"), "kWhPrice") != NULL)
  9931. {
  9932. DEBUG_INFO("chargingPrice-kWhPrice: %f\n", json_object_get_double(json_object_object_get(json_object_object_get(data, "chargingPrice"), "kWhPrice")));
  9933. ShmOCPP16Data->Cost.RunningCost[idx].chargingPrice.kWhPrice = json_object_get_double(json_object_object_get(json_object_object_get(data, "chargingPrice"), "kWhPrice"));
  9934. }
  9935. if(json_object_object_get(json_object_object_get(data, "chargingPrice"), "hourPrice") != NULL)
  9936. {
  9937. DEBUG_INFO("chargingPrice-hourPrice: %f\n", json_object_get_double(json_object_object_get(json_object_object_get(data, "chargingPrice"), "hourPrice")));
  9938. ShmOCPP16Data->Cost.RunningCost[idx].chargingPrice.hourPrice = json_object_get_double(json_object_object_get(json_object_object_get(data, "chargingPrice"), "hourPrice"));
  9939. }
  9940. if(json_object_object_get(json_object_object_get(data, "chargingPrice"), "flatFee") != NULL)
  9941. {
  9942. DEBUG_INFO("chargingPrice-flatFee: %f\n", json_object_get_double(json_object_object_get(json_object_object_get(data, "chargingPrice"), "flatFee")));
  9943. ShmOCPP16Data->Cost.RunningCost[idx].chargingPrice.flatFee = json_object_get_double(json_object_object_get(json_object_object_get(data, "chargingPrice"), "flatFee"));
  9944. }
  9945. }
  9946. else
  9947. {
  9948. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  9949. json_object_object_add(response, "data", json_object_new_string("chargingPrice not found."));
  9950. }
  9951. if(json_object_object_get(data, "idlePrice") != NULL)
  9952. {
  9953. if(json_object_object_get(json_object_object_get(data, "idlePrice"), "graceMinutes") != NULL)
  9954. {
  9955. DEBUG_INFO("idlePrice-graceMinutes: %d\n", json_object_get_int(json_object_object_get(json_object_object_get(data, "idlePrice"), "graceMinutes")));
  9956. ShmOCPP16Data->Cost.RunningCost[idx].idlePrice.graceMinutes = json_object_get_int(json_object_object_get(json_object_object_get(data, "idlePrice"), "graceMinutes"));
  9957. }
  9958. if(json_object_object_get(json_object_object_get(data, "idlePrice"), "hourPrice") != NULL)
  9959. {
  9960. DEBUG_INFO("idlePrice-hourPrice: %f\n", json_object_get_double(json_object_object_get(json_object_object_get(data, "idlePrice"), "hourPrice")));
  9961. ShmOCPP16Data->Cost.RunningCost[idx].idlePrice.hourPrice = json_object_get_double(json_object_object_get(json_object_object_get(data, "idlePrice"), "hourPrice"));
  9962. }
  9963. }
  9964. if(json_object_object_get(data, "nextPeriod") != NULL)
  9965. {
  9966. if(json_object_object_get(json_object_object_get(data, "nextPeriod"), "atTime") != NULL)
  9967. {
  9968. DEBUG_INFO("nextPeriod-atTime: %s\n", json_object_get_string(json_object_object_get(json_object_object_get(data, "nextPeriod"), "atTime")));
  9969. sprintf((char*)ShmOCPP16Data->Cost.RunningCost[idx].nextPeriod.atTime, "%s", json_object_get_string(json_object_object_get(json_object_object_get(data, "nextPeriod"), "atTime")));
  9970. }
  9971. else
  9972. {
  9973. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  9974. json_object_object_add(response, "data", json_object_new_string("atTime not found."));
  9975. }
  9976. if(json_object_object_get(json_object_object_get(data, "nextPeriod"), "chargingPrice") != NULL)
  9977. {
  9978. if(json_object_object_get(json_object_object_get(json_object_object_get(data, "nextPeriod"), "chargingPrice"), "kWhPrice") != NULL)
  9979. {
  9980. 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")));
  9981. 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"));
  9982. }
  9983. if(json_object_object_get(json_object_object_get(json_object_object_get(data, "nextPeriod"), "chargingPrice"), "hourPrice") != NULL)
  9984. {
  9985. 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")));
  9986. 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"));
  9987. }
  9988. if(json_object_object_get(json_object_object_get(json_object_object_get(data, "nextPeriod"), "chargingPrice"), "flatFee") != NULL)
  9989. {
  9990. 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")));
  9991. 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"));
  9992. }
  9993. }
  9994. else
  9995. {
  9996. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  9997. json_object_object_add(response, "data", json_object_new_string("chargingPrice not found."));
  9998. }
  9999. if(json_object_object_get(json_object_object_get(data, "nextPeriod"), "idlePrice") != NULL)
  10000. {
  10001. if(json_object_object_get(json_object_object_get(json_object_object_get(data, "nextPeriod"), "idlePrice"), "graceMinutes") != NULL)
  10002. {
  10003. 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")));
  10004. 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"));
  10005. }
  10006. if(json_object_object_get(json_object_object_get(json_object_object_get(data, "nextPeriod"), "idlePrice"), "hourPrice") != NULL)
  10007. {
  10008. 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")));
  10009. 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"));
  10010. }
  10011. }
  10012. }
  10013. if(json_object_object_get(data, "triggerMeterValue") != NULL)
  10014. {
  10015. if(json_object_object_get(json_object_object_get(data, "triggerMeterValue"), "atTime") != NULL)
  10016. {
  10017. DEBUG_INFO("triggerMeterValue-atTime: %s\n", json_object_get_string(json_object_object_get(json_object_object_get(data, "triggerMeterValue"), "atTime")));
  10018. sprintf((char*)ShmOCPP16Data->Cost.RunningCost[idx].triggerMeterValue.atTime, "%s", json_object_get_string(json_object_object_get(json_object_object_get(data, "triggerMeterValue"), "atTime")));
  10019. }
  10020. if(json_object_object_get(json_object_object_get(data, "triggerMeterValue"), "atEnergykWh") != NULL)
  10021. {
  10022. DEBUG_INFO("triggerMeterValue-atEnergykWh: %f\n", json_object_get_double(json_object_object_get(json_object_object_get(data, "triggerMeterValue"), "atEnergykWh")));
  10023. ShmOCPP16Data->Cost.RunningCost[idx].triggerMeterValue.atEnergykWh = json_object_get_double(json_object_object_get(json_object_object_get(data, "triggerMeterValue"), "atEnergykWh"));
  10024. }
  10025. if(json_object_object_get(json_object_object_get(data, "triggerMeterValue"), "atPowerkW") != NULL)
  10026. {
  10027. DEBUG_INFO("triggerMeterValue-atPowerkW: %f\n", json_object_get_double(json_object_object_get(json_object_object_get(data, "triggerMeterValue"), "atPowerkW")));
  10028. ShmOCPP16Data->Cost.RunningCost[idx].triggerMeterValue.atPowerkW = json_object_get_double(json_object_object_get(json_object_object_get(data, "triggerMeterValue"), "atPowerkW"));
  10029. }
  10030. if(json_object_object_get(json_object_object_get(data, "triggerMeterValue"), "atCPStatus") != NULL)
  10031. {
  10032. DEBUG_INFO("triggerMeterValue-atCPStatus: %s\n", json_object_get_string(json_object_object_get(json_object_object_get(data, "triggerMeterValue"), "atCPStatus")));
  10033. sprintf((char*)ShmOCPP16Data->Cost.RunningCost[idx].triggerMeterValue.atCPStatus, "%s", json_object_get_string(json_object_object_get(json_object_object_get(data, "triggerMeterValue"), "atCPStatus")));
  10034. }
  10035. }
  10036. }
  10037. }
  10038. }
  10039. else
  10040. {
  10041. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  10042. json_object_object_add(response, "data", json_object_new_string("txId or transactionId not found."));
  10043. }
  10044. }
  10045. else
  10046. {
  10047. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  10048. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  10049. }
  10050. json_object_put(data);
  10051. sprintf(message,"[%d,\"%s\",%s]",MESSAGE_TYPE_CALLRESULT, uuid, json_object_to_json_string_ext(response, JSON_C_TO_STRING_PLAIN));
  10052. json_object_put(response);
  10053. }
  10054. else if(strstr(tempmessageId, "FinalCost") != NULL)
  10055. {
  10056. json_object *data;
  10057. data = json_tokener_parse(tempdata);
  10058. if(!is_error(data))
  10059. {
  10060. json_object_object_add(response, "status", json_object_new_string("Accepted"));
  10061. if(json_object_object_get(data, "txId") != NULL)
  10062. {
  10063. DEBUG_INFO("v1.0 txId: %d\n", json_object_get_int(json_object_object_get(data, "txId")));
  10064. for(int idx = 0;idx<gunTotalNumber;idx++)
  10065. {
  10066. if(ShmOCPP16Data->StartTransaction[idx].ResponseTransactionId == json_object_get_int(json_object_object_get(data, "txId")))
  10067. {
  10068. memset(&ShmOCPP16Data->Cost.FinalCost[idx], 0x00, sizeof(struct StrcutFinalCost));
  10069. ShmOCPP16Data->Cost.FinalCost[idx].txId = json_object_get_int(json_object_object_get(data, "txId"));
  10070. if(json_object_object_get(data, "description") != NULL)
  10071. {
  10072. DEBUG_INFO("description: %s\n", json_object_get_string(json_object_object_get(data, "description")));
  10073. sprintf((char*)ShmOCPP16Data->Cost.FinalCost[idx].description, "%s", json_object_get_string(json_object_object_get(data, "description")));
  10074. }
  10075. else
  10076. {
  10077. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  10078. json_object_object_add(response, "data", json_object_new_string("description not found."));
  10079. }
  10080. }
  10081. }
  10082. }
  10083. else if(json_object_object_get(data, "transactionId") != NULL)
  10084. {
  10085. DEBUG_INFO("v2.0 transactionId: %d\n", json_object_get_int(json_object_object_get(data, "transactionId")));
  10086. for(int idx = 0;idx<gunTotalNumber;idx++)
  10087. {
  10088. if(ShmOCPP16Data->StartTransaction[idx].ResponseTransactionId == json_object_get_int(json_object_object_get(data, "transactionId")))
  10089. {
  10090. memset(&ShmOCPP16Data->Cost.FinalCost[idx], 0x00, sizeof(struct StrcutFinalCost));
  10091. ShmOCPP16Data->Cost.FinalCost[idx].txId = json_object_get_int(json_object_object_get(data, "transactionId"));
  10092. if(json_object_object_get(data, "cost") != NULL)
  10093. {
  10094. DEBUG_INFO("cost: %s\n", json_object_get_string(json_object_object_get(data, "cost")));
  10095. ShmOCPP16Data->Cost.FinalCost[idx].cost = json_object_get_double(json_object_object_get(data, "cost"));
  10096. }
  10097. else
  10098. {
  10099. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  10100. json_object_object_add(response, "data", json_object_new_string("cost not found."));
  10101. }
  10102. if(json_object_object_get(data, "priceText") != NULL)
  10103. {
  10104. DEBUG_INFO("priceText: %s\n", json_object_get_string(json_object_object_get(data, "priceText")));
  10105. sprintf((char*)ShmOCPP16Data->Cost.FinalCost[idx].priceText, "%s", json_object_get_string(json_object_object_get(data, "priceText")));
  10106. }
  10107. else
  10108. {
  10109. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  10110. json_object_object_add(response, "data", json_object_new_string("priceText not found."));
  10111. }
  10112. if(json_object_object_get(data, "qrCodeText") != NULL)
  10113. {
  10114. DEBUG_INFO(": %s\n", json_object_get_string(json_object_object_get(data, "qrCodeText")));
  10115. sprintf((char*)ShmOCPP16Data->Cost.FinalCost[idx].qrCodeText, "%s", json_object_get_string(json_object_object_get(data, "qrCodeText")));
  10116. }
  10117. }
  10118. }
  10119. }
  10120. else
  10121. {
  10122. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  10123. json_object_object_add(response, "data", json_object_new_string("txId or transactionId not found."));
  10124. }
  10125. }
  10126. else
  10127. {
  10128. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  10129. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  10130. }
  10131. json_object_put(data);
  10132. sprintf(message,"[%d,\"%s\",%s]",MESSAGE_TYPE_CALLRESULT, uuid, json_object_to_json_string_ext(response, JSON_C_TO_STRING_PLAIN));
  10133. json_object_put(response);
  10134. }
  10135. else if(strstr(tempmessageId, "ID_ConfigQR") != NULL)
  10136. {
  10137. json_object *data;
  10138. data = json_tokener_parse(tempdata);
  10139. if(!is_error(data))
  10140. {
  10141. json_object_object_add(response, "status", json_object_new_string("Accepted"));
  10142. if(json_object_object_get(data, "Content_Type") != NULL)
  10143. {
  10144. 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))
  10145. {
  10146. ShmSysConfigAndInfo->SysConfig.QRCodeMadeMode = json_object_get_int(json_object_object_get(data, "Content_Type"));
  10147. if(json_object_object_get(data, "Customization_Conent") != NULL)
  10148. {
  10149. sprintf((char*)ShmSysConfigAndInfo->SysConfig.QRCodeContent, "%s", json_object_get_string(json_object_object_get(data, "Customization_Conent")));
  10150. }
  10151. }
  10152. else
  10153. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  10154. }
  10155. StoreUsrConfigData(&ShmSysConfigAndInfo->SysConfig);
  10156. }
  10157. else
  10158. {
  10159. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  10160. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  10161. }
  10162. json_object_put(data);
  10163. sprintf(message,"[%d,\"%s\",%s]",MESSAGE_TYPE_CALLRESULT, uuid, json_object_to_json_string_ext(response, JSON_C_TO_STRING_PLAIN));
  10164. json_object_put(response);
  10165. }
  10166. else if(strstr(tempmessageId, "ID_LineStatusPage") != NULL)
  10167. {
  10168. json_object *data;
  10169. data = json_tokener_parse(tempdata);
  10170. if(!is_error(data))
  10171. {
  10172. json_object_object_add(response, "status", json_object_new_string("Accepted"));
  10173. if(json_object_object_get(data, "ConnectorId") != NULL)
  10174. {
  10175. ShmSysConfigAndInfo->SysInfo.LcdOveride.connectorId = json_object_get_int(json_object_object_get(data, "ConnectorId"));
  10176. }
  10177. if(json_object_object_get(data, "SerialNo") != NULL)
  10178. {
  10179. sprintf((char *)ShmOCPP16Data->TcciCustomData.SerialNo[(ShmSysConfigAndInfo->SysInfo.LcdOveride.connectorId-1)], "%s", json_object_get_string(json_object_object_get(data,"SerialNo")));
  10180. }
  10181. if(json_object_object_get(data, "Page_Index") != NULL)
  10182. {
  10183. ShmSysConfigAndInfo->SysInfo.LcdOveride.page_index = json_object_get_int(json_object_object_get(data, "Page_Index"));
  10184. }
  10185. if(json_object_object_get(data, "Duration") != NULL)
  10186. {
  10187. ShmSysConfigAndInfo->SysInfo.LcdOveride.duration = json_object_get_int(json_object_object_get(data, "Duration"));
  10188. }
  10189. ShmSysConfigAndInfo->SysInfo.LcdOveride.isOverideReq = 1;
  10190. }
  10191. else
  10192. {
  10193. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  10194. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  10195. }
  10196. json_object_put(data);
  10197. sprintf(message,"[%d,\"%s\",%s]",MESSAGE_TYPE_CALLRESULT, uuid, json_object_to_json_string_ext(response, JSON_C_TO_STRING_PLAIN));
  10198. json_object_put(response);
  10199. }
  10200. else if(strstr(tempmessageId, "ID_CpConfiguration") != NULL)
  10201. {
  10202. json_object *data;
  10203. data = json_tokener_parse(tempdata);
  10204. if(!is_error(data))
  10205. {
  10206. json_object_object_add(response, "status", json_object_new_string("Accepted"));
  10207. if(json_object_object_get(data, "MaxChargingCurrent") != NULL)
  10208. {
  10209. if(json_object_get_int(json_object_object_get(data, "MaxChargingCurrent")) >= 0)
  10210. ShmSysConfigAndInfo->SysConfig.MaxChargingCurrent = json_object_get_int(json_object_object_get(data, "MaxChargingCurrent"));
  10211. else
  10212. {
  10213. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  10214. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  10215. }
  10216. }
  10217. if(json_object_object_get(data, "MaxChargingDuration") != NULL)
  10218. {
  10219. if(json_object_get_int(json_object_object_get(data, "MaxChargingDuration")) >= 0)
  10220. ShmSysConfigAndInfo->SysConfig.MaxChargingDuration = json_object_get_int(json_object_object_get(data, "MaxChargingDuration"));
  10221. else
  10222. {
  10223. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  10224. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  10225. }
  10226. }
  10227. if(json_object_object_get(data, "MaxChargingEnergy") != NULL)
  10228. {
  10229. if(json_object_get_int(json_object_object_get(data, "MaxChargingEnergy")) >= 0)
  10230. ShmSysConfigAndInfo->SysConfig.MaxChargingEnergy = json_object_get_int(json_object_object_get(data, "MaxChargingEnergy"));
  10231. else
  10232. {
  10233. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  10234. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  10235. }
  10236. }
  10237. if(json_object_object_get(data, "MaxChargingPower") != NULL)
  10238. {
  10239. if(json_object_get_int(json_object_object_get(data, "MaxChargingPower")) >= 0)
  10240. ShmSysConfigAndInfo->SysConfig.MaxChargingPower = json_object_get_int(json_object_object_get(data, "MaxChargingPower"));
  10241. else
  10242. {
  10243. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  10244. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  10245. }
  10246. }
  10247. if(json_object_object_get(data, "OfflineMaxChargeEnergy") != NULL)
  10248. {
  10249. if(json_object_get_int(json_object_object_get(data, "OfflineMaxChargeEnergy")) >= 0)
  10250. ShmSysConfigAndInfo->SysConfig.OfflineMaxChargeEnergy = json_object_get_int(json_object_object_get(data, "OfflineMaxChargeEnergy"));
  10251. else
  10252. {
  10253. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  10254. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  10255. }
  10256. }
  10257. if(json_object_object_get(data, "OfflinePolicy") != NULL)
  10258. {
  10259. if((json_object_get_int(json_object_object_get(data, "OfflinePolicy")) == 0) ||
  10260. (json_object_get_int(json_object_object_get(data, "OfflinePolicy")) == 2) ||
  10261. (json_object_get_int(json_object_object_get(data, "OfflinePolicy")) == 3))
  10262. ShmSysConfigAndInfo->SysConfig.OfflinePolicy = json_object_get_int(json_object_object_get(data, "OfflinePolicy"));
  10263. else
  10264. {
  10265. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  10266. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  10267. }
  10268. }
  10269. if(json_object_object_get(data, "isAuthentication") != NULL)
  10270. {
  10271. switch(json_object_get_int(json_object_object_get(data, "isAuthentication")))
  10272. {
  10273. case 0:
  10274. case 1:
  10275. ShmSysConfigAndInfo->SysConfig.AuthorisationMode = json_object_get_int(json_object_object_get(data, "isAuthentication"))^1;
  10276. break;
  10277. default:
  10278. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  10279. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  10280. break;
  10281. }
  10282. }
  10283. if(strstr(json_object_get_string(json_object_object_get(response, "status")), "Accepted") != NULL)
  10284. StoreUsrConfigData(&ShmSysConfigAndInfo->SysConfig);
  10285. }
  10286. else
  10287. {
  10288. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  10289. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  10290. }
  10291. json_object_put(data);
  10292. sprintf(message,"[%d,\"%s\",%s]",MESSAGE_TYPE_CALLRESULT, uuid, json_object_to_json_string_ext(response, JSON_C_TO_STRING_PLAIN));
  10293. json_object_put(response);
  10294. }
  10295. else if(strstr(tempmessageId, "ID_TxEnergy") != NULL)
  10296. {
  10297. json_object *data;
  10298. data = json_tokener_parse(tempdata);
  10299. if(!is_error(data))
  10300. {
  10301. if((json_object_object_get(data, "ConnectorId") != NULL) && (json_object_object_get(data, "txId") != NULL))
  10302. {
  10303. if(OCPP_getPeriodEnergyToDataTransfer(json_object_get_int(json_object_object_get(data, "txId"))) == PASS)
  10304. {
  10305. json_object_object_add(response, "status", json_object_new_string("Accepted"));
  10306. json_object_object_add(response, "data", json_object_new_string((char*)ShmOCPP16Data->DataTransfer[0].ResponseData));
  10307. }
  10308. else
  10309. {
  10310. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  10311. json_object_object_add(response, "data", json_object_new_string("Present charged energy data can not get."));
  10312. }
  10313. }
  10314. else
  10315. {
  10316. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  10317. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  10318. }
  10319. }
  10320. else
  10321. {
  10322. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  10323. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  10324. }
  10325. sprintf(message,"[%d,\"%s\",%s]",MESSAGE_TYPE_CALLRESULT, uuid, json_object_to_json_string_ext(response, JSON_C_TO_STRING_PLAIN));
  10326. json_object_put(response);
  10327. }
  10328. else if(strstr(tempmessageId, "ID_Station_Location") != NULL)
  10329. {
  10330. json_object *data;
  10331. data = json_tokener_parse(tempdata);
  10332. if(!is_error(data))
  10333. {
  10334. json_object_object_add(response, "status", json_object_new_string("Accepted"));
  10335. if(json_object_object_get(data, "stationName") != NULL)
  10336. {
  10337. sprintf((char *)ShmOCPP16Data->TcciCustomData.ChargerInfo.station_name, "%s", json_object_get_string(json_object_object_get(data,"stationName")));
  10338. }
  10339. else
  10340. {
  10341. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  10342. json_object_object_add(response, "data", json_object_new_string("station_name data can not get."));
  10343. }
  10344. if(strcmp(json_object_get_string(json_object_object_get(response,"status")),"Accepted")==0)
  10345. {
  10346. ShmOCPP16Data->TcciCustomData.ChargerInfoReq = 1;
  10347. DEBUG_INFO("<<< ID_Station_Location:{station_name:%s}\n",
  10348. ShmOCPP16Data->TcciCustomData.ChargerInfo.station_name);
  10349. }
  10350. }
  10351. else
  10352. {
  10353. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  10354. json_object_object_add(response, "data", json_object_new_string("charger_info content got something wrong."));
  10355. }
  10356. sprintf(message,"[%d,\"%s\",%s]",MESSAGE_TYPE_CALLRESULT, uuid, json_object_to_json_string_ext(response, JSON_C_TO_STRING_PLAIN));
  10357. json_object_put(response);
  10358. }
  10359. else if(strstr(tempmessageId, "ID_Weather_Info") != NULL)
  10360. {
  10361. json_object *data;
  10362. data = json_tokener_parse(tempdata);
  10363. if(!is_error(data))
  10364. {
  10365. json_object_object_add(response, "status", json_object_new_string("Accepted"));
  10366. if(json_object_object_get(data, "weatherId") != NULL)
  10367. {
  10368. ShmOCPP16Data->TcciCustomData.WeatherInfo.weatherId = json_object_get_int(json_object_object_get(data, "weatherId"));
  10369. }
  10370. else
  10371. {
  10372. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  10373. json_object_object_add(response, "data", json_object_new_string("weather data can not get."));
  10374. }
  10375. if(json_object_object_get(data, "Temperature") != NULL)
  10376. {
  10377. ShmOCPP16Data->TcciCustomData.WeatherInfo.temperature = json_object_get_double(json_object_object_get(data,"Temperature"));
  10378. }
  10379. else
  10380. {
  10381. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  10382. json_object_object_add(response, "data", json_object_new_string("temperature data can not get."));
  10383. }
  10384. if(strcmp(json_object_get_string(json_object_object_get(response,"status")),"Accepted")==0)
  10385. {
  10386. ShmOCPP16Data->TcciCustomData.WeatherInfoReq = 1;
  10387. DEBUG_INFO("<<< ID_Weather_Info:{weather:%d, temperature:%.1f}\n",
  10388. ShmOCPP16Data->TcciCustomData.WeatherInfo.weatherId,
  10389. ShmOCPP16Data->TcciCustomData.WeatherInfo.temperature
  10390. );
  10391. }
  10392. }
  10393. else
  10394. {
  10395. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  10396. json_object_object_add(response, "data", json_object_new_string("weather_info content got something wrong."));
  10397. }
  10398. sprintf(message,"[%d,\"%s\",%s]",MESSAGE_TYPE_CALLRESULT, uuid, json_object_to_json_string_ext(response, JSON_C_TO_STRING_PLAIN));
  10399. json_object_put(response);
  10400. }
  10401. else if(strstr(tempmessageId, "ID_TriggerCreditReader") != NULL)
  10402. {
  10403. json_object *data;
  10404. data = json_tokener_parse(tempdata);
  10405. if(!is_error(data))
  10406. {
  10407. json_object_object_add(response, "status", json_object_new_string("Accepted"));
  10408. if(json_object_get_int(json_object_object_get(data, "ConnectorId")) > 0)
  10409. {
  10410. ShmOCPP16Data->TcciCustomData.TriggerReaderReq[json_object_get_int(json_object_object_get(data, "ConnectorId")) -1] = TRUE;
  10411. DEBUG_INFO("<<< ID_TriggerCreditReader:{ConnectorId: %d}\n", json_object_get_int(json_object_object_get(data, "ConnectorId")));
  10412. }
  10413. else
  10414. {
  10415. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  10416. json_object_object_add(response, "data", json_object_new_string("ConnectorId does not valid."));
  10417. }
  10418. }
  10419. else
  10420. {
  10421. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  10422. json_object_object_add(response, "data", json_object_new_string("charger_info content got something wrong."));
  10423. }
  10424. sprintf(message,"[%d,\"%s\",%s]",MESSAGE_TYPE_CALLRESULT, uuid, json_object_to_json_string_ext(response, JSON_C_TO_STRING_PLAIN));
  10425. json_object_put(response);
  10426. }
  10427. else if(strstr(tempmessageId, "ID_GetTxUserInfo") != NULL)
  10428. {
  10429. json_object *data;
  10430. data = json_tokener_parse(tempdata);
  10431. if(!is_error(data))
  10432. {
  10433. if((json_object_object_get(data, "ConnectorId") != NULL) && (json_object_object_get(data, "txId") != NULL))
  10434. {
  10435. int gun_index = json_object_get_int(json_object_object_get(data, "ConnectorId"))-1;
  10436. json_object_object_add(response, "status", json_object_new_string("Accepted"));
  10437. if(gun_index < gunTotalNumber)
  10438. {
  10439. if(ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId == json_object_get_int(json_object_object_get(data, "txId")))
  10440. {
  10441. json_object *responsedata = json_object_new_object();
  10442. json_object_object_add(responsedata, "txId", json_object_new_int(ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId));
  10443. json_object_object_add(responsedata, "ConnectorId", json_object_new_int(gun_index+1));
  10444. json_object_object_add(responsedata, "SerialNo", json_object_new_string((char*)ShmOCPP16Data->TcciCustomData.SerialNo[gun_index]));
  10445. json_object_object_add(responsedata, "StartTime", json_object_new_string((char*)ShmOCPP16Data->StartTransaction[gun_index].Timestamp));
  10446. json_object_object_add(responsedata, "VEMData", json_object_new_string((char*)ShmOCPP16Data->TcciCustomData.VEMData[gun_index]));
  10447. json_object_object_add(response, "data", json_object_new_string(json_object_to_json_string_ext(responsedata, JSON_C_TO_STRING_PLAIN)));
  10448. }
  10449. else
  10450. {
  10451. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  10452. json_object_object_add(response, "data", json_object_new_string("txId doesn't match the current transactionId."));
  10453. }
  10454. }
  10455. else
  10456. {
  10457. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  10458. json_object_object_add(response, "data", json_object_new_string("ConnectorId is invalid."));
  10459. }
  10460. }
  10461. else
  10462. {
  10463. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  10464. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  10465. }
  10466. }
  10467. else
  10468. {
  10469. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  10470. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  10471. }
  10472. sprintf(message,"[%d,\"%s\",%s]",MESSAGE_TYPE_CALLRESULT, uuid, json_object_to_json_string_ext(response, JSON_C_TO_STRING_PLAIN));
  10473. json_object_put(response);
  10474. }
  10475. else
  10476. {
  10477. // Can not find valid message id
  10478. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\",\"data\":\"vendorId-%s messageId-%s data-%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, "UnknownMessageId", tempvendorId, tempmessageId, tempdata);
  10479. }
  10480. }
  10481. else
  10482. {
  10483. // Payload is null
  10484. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\",\"data\":\"{}\"}]",MESSAGE_TYPE_CALLRESULT, uuid, "UnknownMessageId");
  10485. }
  10486. LWS_Send(message);
  10487. return result;
  10488. }
  10489. int handleGetCompositeScheduleRequest(char *uuid, char *payload)
  10490. {
  10491. mtrace();
  10492. int result = FAIL;
  10493. int connectorIdInt, durationInt;
  10494. char chargingRateUnitStr[4]={0};
  10495. char comfirmstr[20];
  10496. int confirmPeriods = 0;
  10497. DEBUG_INFO("handleGetCompositeScheduleRequest...\n");
  10498. json_object *GetCompositeSchedule;
  10499. GetCompositeSchedule = json_tokener_parse(payload);
  10500. if(!is_error(GetCompositeSchedule))
  10501. {
  10502. // Required data
  10503. if(json_object_object_get(GetCompositeSchedule, "connectorId") != NULL)
  10504. connectorIdInt = json_object_get_int(json_object_object_get(GetCompositeSchedule, "connectorId"));
  10505. else
  10506. connectorIdInt = -1;
  10507. if(json_object_object_get(GetCompositeSchedule, "duration"))
  10508. durationInt = json_object_get_int(json_object_object_get(GetCompositeSchedule, "duration"));
  10509. else
  10510. durationInt = 86400;
  10511. // Optional data
  10512. if(json_object_object_get(GetCompositeSchedule, "chargingRateUnit") != NULL)
  10513. sprintf((char*)chargingRateUnitStr, "%s", json_object_get_string(json_object_object_get(GetCompositeSchedule, "chargingRateUnit")));
  10514. }
  10515. json_object_put(GetCompositeSchedule);
  10516. memset(ShmOCPP16Data->GetCompositeSchedule, 0, sizeof(struct StructChargingSchedulePeriod)*gunTotalNumber);
  10517. if((connectorIdInt == 0) ||
  10518. ((connectorIdInt > 0) && ((connectorIdInt -1) < gunTotalNumber)))
  10519. {
  10520. int gun_index = (connectorIdInt==0?0:connectorIdInt-1);
  10521. struct StructChargingProfile tmpProfile[1];
  10522. if(strstr(chargingRateUnitStr, "W") != NULL)
  10523. checkCompositeSchedule(connectorIdInt, durationInt, &tmpProfile[0], FALSE);
  10524. else
  10525. checkCompositeSchedule(connectorIdInt, durationInt, &tmpProfile[0], TRUE);
  10526. for(int idx=0;idx<ARRAY_SIZE(ShmOCPP16Data->GetCompositeSchedule[gun_index].ResponseChargingSchedule.ChargingSchedulePeriod);idx++)
  10527. {
  10528. DEBUG_INFO("Smart Period-%02d start: %d\n", idx, tmpProfile[0].ChargingSchedule.ChargingSchedulePeriod[idx].StartPeriod);
  10529. DEBUG_INFO("Smart Period-%02d limit: %f\n", idx, tmpProfile[0].ChargingSchedule.ChargingSchedulePeriod[idx].Limit);
  10530. }
  10531. ShmOCPP16Data->GetCompositeSchedule[gun_index].ResponseConnectorId = connectorIdInt;
  10532. memcpy(&ShmOCPP16Data->GetCompositeSchedule[gun_index].ResponseChargingSchedule, &tmpProfile[0].ChargingSchedule, sizeof(struct StructChargingSchedule));
  10533. memcpy(&ShmOCPP16Data->GetCompositeSchedule[gun_index].ResponseScheduleStart ,&tmpProfile[0].ChargingSchedule.StartSchedule, ARRAY_SIZE(tmpProfile[0].ChargingSchedule.StartSchedule));
  10534. for(int idx=0;idx<ARRAY_SIZE(ShmOCPP16Data->GetCompositeSchedule[gun_index].ResponseChargingSchedule.ChargingSchedulePeriod);idx++)
  10535. {
  10536. DEBUG_INFO("Composite Period-%02d start: %d\n", idx, ShmOCPP16Data->GetCompositeSchedule[gun_index].ResponseChargingSchedule.ChargingSchedulePeriod[idx].StartPeriod);
  10537. DEBUG_INFO("Composite Period-%02d limit: %f\n", idx, ShmOCPP16Data->GetCompositeSchedule[gun_index].ResponseChargingSchedule.ChargingSchedulePeriod[idx].Limit);
  10538. if((ShmOCPP16Data->GetCompositeSchedule[gun_index].ResponseChargingSchedule.ChargingSchedulePeriod[idx].StartPeriod==0) &&
  10539. (ShmOCPP16Data->GetCompositeSchedule[gun_index].ResponseChargingSchedule.ChargingSchedulePeriod[idx].Limit==0) &&
  10540. (idx<(ARRAY_SIZE(ShmOCPP16Data->GetCompositeSchedule[gun_index].ResponseChargingSchedule.ChargingSchedulePeriod)-1)?(ShmOCPP16Data->GetCompositeSchedule[gun_index].ResponseChargingSchedule.ChargingSchedulePeriod[idx+1].StartPeriod==0):TRUE))
  10541. {
  10542. confirmPeriods = idx;
  10543. break;
  10544. }
  10545. }
  10546. if((confirmPeriods == 0) && (tmpProfile[0].ChargingProfileId > 0))
  10547. {
  10548. confirmPeriods += 1;
  10549. }
  10550. sprintf(comfirmstr, "%s", GetCompositeScheduleStatusStr[GetCompositeScheduleStatus_Accepted] );
  10551. }
  10552. else
  10553. {
  10554. sprintf(comfirmstr, "%s", GetCompositeScheduleStatusStr[GetCompositeScheduleStatus_Rejected] );
  10555. }
  10556. sendGetCompositeScheduleConfirmation(uuid, comfirmstr, connectorIdInt, confirmPeriods);
  10557. return result;
  10558. }
  10559. int handleGetConfigurationRequest(char *uuid, char *payload)
  10560. {
  10561. mtrace();
  10562. int result = FAIL;
  10563. int MaxKeySupported = 0;
  10564. int n_keys = 0;
  10565. char requestKey[GetConfigurationMaxKeysNUM][50]={0};
  10566. DEBUG_INFO("handleGetConfigurationRequest...\n");
  10567. json_object *GetConfiguration;
  10568. GetConfiguration = json_tokener_parse(payload);
  10569. if(!is_error(GetConfiguration))
  10570. {
  10571. // Optional data
  10572. if(json_object_object_get(GetConfiguration, "key") != NULL)
  10573. {
  10574. for(int idx=0;idx<json_object_array_length(json_object_object_get(GetConfiguration, "key"));idx++)
  10575. {
  10576. sprintf((char*)requestKey[idx], "%s", json_object_get_string(json_object_array_get_idx(json_object_object_get(GetConfiguration, "key"), idx)));
  10577. n_keys = idx + 1;
  10578. }
  10579. }
  10580. }
  10581. json_object_put(GetConfiguration);
  10582. UnknownKeynum = 0;
  10583. memset( (void *)unknownkey, 0, sizeof(unknownkey));
  10584. MaxKeySupported = GetConfigurationMaxKeysNUM;
  10585. memset(ShmOCPP16Data->GetConfiguration.Key, 0 ,sizeof(struct StructConfigurationKeyItems)*MaxKeySupported);
  10586. memset(ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey, 0, sizeof(struct StructConfigurationKey)*MaxKeySupported);
  10587. if(n_keys != 0)
  10588. {
  10589. for(int i=0;i<n_keys;i++)
  10590. {
  10591. getKeyValue(requestKey[i]);
  10592. }
  10593. }
  10594. else
  10595. {
  10596. DEBUG_INFO("There is no key in Message, get all configuration\n");
  10597. getKeyValue("");
  10598. }
  10599. processUnkownKey();
  10600. sendGetConfigurationConfirmation(uuid);
  10601. return result;
  10602. }
  10603. static char fnamePlusPath[100]={0};
  10604. static char fnamePWithNoPath[60]={0};
  10605. void checkUploadLog(void)
  10606. {
  10607. FILE *fp;
  10608. /* Open the command for reading. */
  10609. fp = popen("find /mnt/ -type f -name \"*.zip\" |xargs ls -t", "r");
  10610. if (fp == NULL) {
  10611. DEBUG_WARN("Failed to run command\n" );
  10612. exit(1);
  10613. }
  10614. int ftppathlen = 0;
  10615. memset(fnamePlusPath, 0, ARRAY_SIZE(fnamePlusPath));
  10616. int i = 0;
  10617. /* Read the output a line at a time - output it. */
  10618. while (fgets(fnamePlusPath, sizeof(fnamePlusPath), fp) != NULL) {
  10619. if(i==0)
  10620. {
  10621. ftppathlen = strlen(fnamePlusPath);
  10622. DEBUG_INFO("%s\n", fnamePlusPath);
  10623. fnamePlusPath[ftppathlen]='\0';
  10624. break;
  10625. }
  10626. i= i+1;
  10627. }
  10628. /* close */
  10629. pclose(fp);
  10630. for(int k=0; k< ARRAY_SIZE(fnamePlusPath); k++)
  10631. {
  10632. if((fnamePlusPath[k]=='\n') || (fnamePlusPath[k]=='\r'))
  10633. {
  10634. fnamePlusPath[k]='\0';
  10635. }
  10636. }
  10637. i=1;
  10638. //char fname[60]={0};
  10639. while(i < ftppathlen)
  10640. {
  10641. int len=ftppathlen-i;
  10642. if(fnamePlusPath[len]== 47) // '/' ascll code: 47
  10643. {
  10644. DEBUG_INFO("compare '/' all right\n");
  10645. break;
  10646. }
  10647. i=i+1;
  10648. }
  10649. memset(fnamePWithNoPath, 0, ARRAY_SIZE(fnamePWithNoPath));
  10650. strncpy(fnamePWithNoPath, fnamePlusPath+(ftppathlen-i+1), i+1);
  10651. fnamePWithNoPath[i+1] = '\0';
  10652. for(int j=0; j< ARRAY_SIZE(fnamePWithNoPath); j++)
  10653. {
  10654. if((fnamePWithNoPath[j]=='\n') || (fnamePWithNoPath[j]=='r'))
  10655. {
  10656. fnamePWithNoPath[j]='\0';
  10657. }
  10658. }
  10659. FILE* fp1 = fopen(fnamePlusPath, "r");
  10660. if (fp1)
  10661. {
  10662. DEBUG_INFO("testfuc : fnamePlusPath=%s exist.\n", fnamePlusPath);
  10663. // file exists
  10664. fclose(fp1);
  10665. }
  10666. else
  10667. {
  10668. // file doesn't exist
  10669. DEBUG_WARN("testfuc : fnamePlusPath=%s not exist!\n", fnamePlusPath);
  10670. }
  10671. }
  10672. int handleGetDiagnosticsRequest(char *uuid, char *payload)
  10673. {
  10674. mtrace();
  10675. int result = FAIL;
  10676. time_t CurrentTime;
  10677. struct tm *tm;
  10678. pthread_t th_Status;
  10679. CurrentTime = time(NULL);
  10680. tm = localtime(&CurrentTime);
  10681. memset(ShmOCPP16Data->GetDiagnostics.ResponseFileName, 0x00, ARRAY_SIZE(ShmOCPP16Data->GetDiagnostics.ResponseFileName));
  10682. 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);
  10683. sendGetDiagnosticsConfirmation(uuid, (char*)ShmOCPP16Data->GetDiagnostics.ResponseFileName);
  10684. if(!interLock.isGetDiagnosticGoing)
  10685. {
  10686. interLock.isGetDiagnosticGoing = 1;
  10687. pthread_create(&th_Status, NULL, GetDiagnosticsProcess, payload);
  10688. sleep(1);
  10689. }
  10690. else
  10691. DEBUG_WARN("Other GetDiagnostic request on going.\n");
  10692. return result;
  10693. }
  10694. void* GetDiagnosticsProcess(void* data)
  10695. {
  10696. pthread_detach(pthread_self());
  10697. mtrace();
  10698. int retriesInt=0, retryIntervalInt=0;
  10699. char locationstr[1024]={0}, startTimestr[30]={0}, stopTimestr[30]={0} ;
  10700. 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};
  10701. int port=0;
  10702. int isSuccess = FALSE;
  10703. char cmdBuf[2048];
  10704. struct tm *tmNow;
  10705. time_t CurrentTime;
  10706. struct tm tmStart;
  10707. struct tm tmStop;
  10708. CurrentTime = time(NULL);
  10709. tmNow=localtime(&CurrentTime);
  10710. uint16_t targetYear, targetMonth;
  10711. json_object *GetDiagnostics;
  10712. DEBUG_INFO("GetDiagnosticsProcess...\n");
  10713. GetDiagnostics = json_tokener_parse(data);
  10714. if(!is_error(GetDiagnostics))
  10715. {
  10716. // Required data
  10717. if(json_object_object_get(GetDiagnostics, "location") != NULL)
  10718. sprintf(locationstr, "%s", json_object_get_string(json_object_object_get(GetDiagnostics, "location")));
  10719. // Optional data
  10720. if(json_object_object_get(GetDiagnostics, "retries") != NULL)
  10721. retriesInt = json_object_get_int(json_object_object_get(GetDiagnostics, "retries"));
  10722. else
  10723. retriesInt = 3; // If this field is not present, it is left to Charge Point to decide how many times it wants to retry.
  10724. if(json_object_object_get(GetDiagnostics, "retryInterval") != NULL)
  10725. retryIntervalInt = json_object_get_int(json_object_object_get(GetDiagnostics, "retryInterval"));
  10726. else
  10727. retryIntervalInt = 30;
  10728. if(json_object_object_get(GetDiagnostics, "startTime") != NULL)
  10729. sprintf(startTimestr, "%s", json_object_get_string(json_object_object_get(GetDiagnostics, "startTime")));
  10730. if(json_object_object_get(GetDiagnostics, "stopTime") != NULL)
  10731. sprintf(stopTimestr, "%s", json_object_get_string(json_object_object_get(GetDiagnostics, "stopTime")));
  10732. }
  10733. json_object_put(GetDiagnostics);
  10734. // Pack log to compress file
  10735. 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) &&
  10736. (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))
  10737. {
  10738. // Pack system log
  10739. memset(cmdBuf, 0x00, ARRAY_SIZE(cmdBuf));
  10740. sprintf(cmdBuf, "exec zip -9 --password %04d%02d%s /mnt/system.zip", tmNow->tm_year+1900, tmNow->tm_mon+1, ShmSysConfigAndInfo->SysConfig.SerialNumber);
  10741. targetYear = tmStart.tm_year;
  10742. targetMonth = tmStart.tm_mon;
  10743. do
  10744. {
  10745. sprintf(cmdBuf, "%s /Storage/SystemLog/*%04d*%02d*", cmdBuf, targetYear, targetMonth);
  10746. sprintf(cmdBuf, "%s /Storage/OCPP/*%04d*%02d*SystemLog*", cmdBuf, targetYear, targetMonth);
  10747. if(targetMonth+1>=13)
  10748. {
  10749. targetYear += 1;
  10750. targetMonth = 1;
  10751. }
  10752. else
  10753. {
  10754. targetMonth += 1;
  10755. }
  10756. }while((targetYear < (tmNow->tm_year+1900)) ||
  10757. ((targetYear <= (tmNow->tm_year+1900)) && (targetMonth <= (tmNow->tm_mon+1))));
  10758. sprintf(cmdBuf, "%s /Storage/CCS*.zip", cmdBuf);
  10759. sprintf(cmdBuf, "%s /Storage/OCPP/*.db", cmdBuf);
  10760. system(cmdBuf);
  10761. // Pack charging & event log
  10762. memset(cmdBuf, 0x00, ARRAY_SIZE(cmdBuf));
  10763. sprintf(cmdBuf, "exec zip -9 /mnt/charging_event.zip");
  10764. targetYear = tmStart.tm_year;
  10765. targetMonth = tmStart.tm_mon;
  10766. do
  10767. {
  10768. sprintf(cmdBuf, "%s /Storage/EventLog/*%04d*%02d*", cmdBuf, targetYear, targetMonth);
  10769. sprintf(cmdBuf, "%s /Storage/OCPP/*%04d*%02d*OcppMessageLog*", cmdBuf, targetYear, targetMonth);
  10770. if(targetMonth+1>=13)
  10771. {
  10772. targetYear += 1;
  10773. targetMonth = 1;
  10774. }
  10775. else
  10776. {
  10777. targetMonth += 1;
  10778. }
  10779. }while((targetYear < (tmNow->tm_year+1900)) ||
  10780. ((targetYear <= (tmNow->tm_year+1900)) && (targetMonth <= (tmNow->tm_mon+1))));
  10781. sprintf(cmdBuf, "%s /Storage/ChargeLog/*.db", cmdBuf);
  10782. sprintf(cmdBuf, "%s /Storage/EventLog/*.db", cmdBuf);
  10783. system(cmdBuf);
  10784. // Combine log file
  10785. system("exec zip -9 /mnt/log.zip /mnt/system.zip /mnt/charging_event.zip");
  10786. system("exec rm -f /mnt/system.zip /mnt/charging_event.zip");
  10787. }
  10788. else
  10789. {
  10790. system("exec /root/logPackTools 'log' 6");
  10791. }
  10792. sprintf(cmdBuf, "mv /mnt/log.zip /mnt/%s", ShmOCPP16Data->GetDiagnostics.ResponseFileName);
  10793. system(cmdBuf);
  10794. checkUploadLog();
  10795. //****************location*******************/
  10796. if(strcmp(locationstr,"")==0)
  10797. {
  10798. DEBUG_INFO("location is <Empty>!\n");
  10799. sprintf((char*)ShmOCPP16Data->DiagnosticsStatusNotification.Status, "%s", DiagnosticsStatusStr[DiagnosticsStatus_UploadFailed]);
  10800. ShmOCPP16Data->SpMsg.bits.DiagnosticsStatusNotificationReq = 1;
  10801. goto end;
  10802. }
  10803. memset(protocol, 0, ARRAY_SIZE(protocol));
  10804. memset(user, 0, ARRAY_SIZE(user) );
  10805. memset(password, 0, ARRAY_SIZE(password));
  10806. memset(host, 0, ARRAY_SIZE(host));
  10807. memset(path, 0, ARRAY_SIZE(path));
  10808. memset(ftppath, 0, ARRAY_SIZE(ftppath));
  10809. memset(host1, 0, ARRAY_SIZE(host1));
  10810. memset(path1, 0, ARRAY_SIZE(path1));
  10811. /*location: ftp://user:password@host:port/path*/
  10812. //DEBUG_INFO("fnamePlusPath =%s\n",fnamePlusPath);
  10813. if((access(fnamePlusPath,F_OK))!=-1)
  10814. {
  10815. DEBUG_INFO("fnamePlusPath exist.\n");
  10816. }
  10817. else
  10818. {
  10819. DEBUG_INFO("fnamePlusPath not exist!\n");
  10820. sprintf((char*)ShmOCPP16Data->DiagnosticsStatusNotification.Status, "%s", DiagnosticsStatusStr[DiagnosticsStatus_UploadFailed]);
  10821. ShmOCPP16Data->SpMsg.bits.DiagnosticsStatusNotificationReq = 1;
  10822. goto end;
  10823. }
  10824. if(strchr(locationstr,'@')==NULL)
  10825. {
  10826. sscanf(locationstr,
  10827. "%[^:]:%*2[/]%[^:]:%i/%[a-zA-Z0-9._/-]",
  10828. protocol, host, &port, path);
  10829. strcpy(user,"anonymous");
  10830. strcpy(password,"");
  10831. }
  10832. else
  10833. {
  10834. //DEBUG_INFO("pch=%s\n", pch);
  10835. sscanf(locationstr,"%[^:]:%*2[/]%[^:]:%[^@]@%[^:]:%i/%199[^\n]",
  10836. protocol, user, password, host, &port, path);
  10837. }
  10838. if((strcmp(protocol,"ftp")!=0)&&(strcmp(protocol,"http")!=0)&&(strcmp(protocol,"https")!=0))
  10839. {
  10840. DEBUG_INFO("protocol is not ftp/http ! \n");
  10841. sprintf((char*)ShmOCPP16Data->DiagnosticsStatusNotification.Status, "%s", DiagnosticsStatusStr[DiagnosticsStatus_UploadFailed]);
  10842. ShmOCPP16Data->SpMsg.bits.DiagnosticsStatusNotificationReq = 1;
  10843. goto end;
  10844. }
  10845. if(strncmp(locationstr,"http", 4) == 0)
  10846. {
  10847. sscanf(locationstr,"%[^:]:%*2[/]%[^/]/%199[^\n]", protocol, host, path);
  10848. sprintf(ftppath,"/%s", path);
  10849. do
  10850. {
  10851. sprintf((char*)ShmOCPP16Data->DiagnosticsStatusNotification.Status, "%s", DiagnosticsStatusStr[DiagnosticsStatus_Uploading]);
  10852. ShmOCPP16Data->SpMsg.bits.DiagnosticsStatusNotificationReq = 1;
  10853. sleep(3);
  10854. isSuccess = httpUploadFile(host, ftppath, fnamePlusPath, locationstr);
  10855. if(!isSuccess)
  10856. {
  10857. DEBUG_INFO("Diagnostics fail.\n");
  10858. sprintf((char*)ShmOCPP16Data->DiagnosticsStatusNotification.Status, "%s", DiagnosticsStatusStr[DiagnosticsStatus_UploadFailed]);
  10859. ShmOCPP16Data->SpMsg.bits.DiagnosticsStatusNotificationReq = 1;
  10860. sleep(retryIntervalInt);
  10861. }
  10862. else
  10863. {
  10864. DEBUG_INFO("sendDiagnosticsStatusNotificationRequest Uploaded\n");
  10865. sprintf((char*)ShmOCPP16Data->DiagnosticsStatusNotification.Status, "%s", DiagnosticsStatusStr[DiagnosticsStatus_Uploaded]);
  10866. ShmOCPP16Data->SpMsg.bits.DiagnosticsStatusNotificationReq = 1;
  10867. }
  10868. retriesInt--;
  10869. }while((isSuccess == 0)&&(retriesInt >= 0));
  10870. }
  10871. else
  10872. {
  10873. sscanf(host,"%[^/]%s",host1, path1);
  10874. if(strlen(path) > 0)
  10875. sprintf(ftppath,"/%s", path);
  10876. else
  10877. sprintf(ftppath,"/%s", path1);
  10878. int ftppathlen=strlen(ftppath);
  10879. int i=1;
  10880. char filenametemp[50];
  10881. while(i < ftppathlen)
  10882. {
  10883. int len=ftppathlen-i;
  10884. if(ftppath[len]== 47) // '/' ascll code: 47
  10885. {
  10886. DEBUG_INFO("find '/' all right\n");
  10887. break;
  10888. }
  10889. i=i+1;
  10890. }
  10891. memset(filenametemp, 0, ARRAY_SIZE(filenametemp));
  10892. strncpy(filenametemp, ftppath+(ftppathlen-i+1), i+1);
  10893. filenametemp[i+1] = 0;
  10894. if(port == 0)
  10895. port = 21;
  10896. do
  10897. {
  10898. sprintf((char*)ShmOCPP16Data->DiagnosticsStatusNotification.Status, "%s", DiagnosticsStatusStr[DiagnosticsStatus_Uploading]);
  10899. ShmOCPP16Data->SpMsg.bits.DiagnosticsStatusNotificationReq = 1;
  10900. sleep(3);
  10901. isSuccess = ftpUploadFile(host1, user, password, port, ftppath, fnamePlusPath, fnamePWithNoPath);
  10902. if(!isSuccess)
  10903. {
  10904. DEBUG_INFO("Diagnostics fail.\n");
  10905. sprintf((char*)ShmOCPP16Data->DiagnosticsStatusNotification.Status, "%s", DiagnosticsStatusStr[DiagnosticsStatus_UploadFailed]);
  10906. ShmOCPP16Data->SpMsg.bits.DiagnosticsStatusNotificationReq = 1;
  10907. sleep(retryIntervalInt);
  10908. }
  10909. else
  10910. {
  10911. DEBUG_INFO("sendDiagnosticsStatusNotificationRequest Uploaded\n");
  10912. sprintf((char*)ShmOCPP16Data->DiagnosticsStatusNotification.Status, "%s", DiagnosticsStatusStr[DiagnosticsStatus_Uploaded]);
  10913. ShmOCPP16Data->SpMsg.bits.DiagnosticsStatusNotificationReq = 1;
  10914. }
  10915. retriesInt--;
  10916. }while((!isSuccess)&&(retriesInt >= 0));
  10917. }
  10918. end:
  10919. system("rm -f /mnt/*");
  10920. sleep(5);
  10921. sprintf((char*)ShmOCPP16Data->DiagnosticsStatusNotification.Status, "%s", DiagnosticsStatusStr[DiagnosticsStatus_Idle]);
  10922. ShmOCPP16Data->SpMsg.bits.DiagnosticsStatusNotificationReq = 1;
  10923. interLock.isGetDiagnosticGoing = 0;
  10924. pthread_exit(NULL);
  10925. }
  10926. int handleGetLocalListVersionRequest(char *uuid, char *payload)
  10927. {
  10928. mtrace();
  10929. int result = FAIL;
  10930. DEBUG_INFO("handle GetLocalListVersionRequest\n");
  10931. if(strcmp((const char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "FALSE") == 0)
  10932. {
  10933. DEBUG_INFO("LocalAuthListEnabled is FALSE \n");
  10934. locallistVersion = -1;
  10935. }
  10936. else
  10937. {
  10938. DEBUG_INFO("handle GetLocalListVersionRequest OCPP_getListVerion \n");
  10939. locallistVersion = 0;
  10940. OCPP_getListVerion();
  10941. }
  10942. //from db.OCPP_getListVerion
  10943. ShmOCPP16Data->GetLocalListVersion.ResponseListVersion = locallistVersion;
  10944. //ShmOCPP16Data->MsMsg.bits.GetLocalListVersionReq = 1;
  10945. sendGetLocalListVersionConfirmation(uuid,"");
  10946. //ShmOCPP16Data->MsMsg.bits.GetLocalListVersionConf = 1;
  10947. return result;
  10948. }
  10949. int handleRemoteStartRequest(char *uuid, char *payload)
  10950. {
  10951. mtrace();
  10952. int result = PASS;
  10953. int connectorIdInt=-1;
  10954. int tempIndex = 0;
  10955. char comfirmstr[20]={0};
  10956. char cmdBuf[512];
  10957. json_object *RemoteStartTransaction;
  10958. FILE *fp;
  10959. DEBUG_INFO("handleRemoteStartRequest ...\n");
  10960. if(server_pending == TRUE)
  10961. {
  10962. result = FAIL;
  10963. }
  10964. RemoteStartTransaction = json_tokener_parse(payload);
  10965. if(!is_error(RemoteStartTransaction))
  10966. {
  10967. if(json_object_object_get(RemoteStartTransaction, "connectorId") != NULL)
  10968. {
  10969. connectorIdInt = json_object_get_int(json_object_object_get(RemoteStartTransaction, "connectorId"));
  10970. }
  10971. else
  10972. {
  10973. for(uint8_t gun_index=0;gun_index<gunTotalNumber;gun_index++)
  10974. {
  10975. if(!cpinitateMsg.bits[gun_index].isOnCharging && (strstr((char*)ShmOCPP16Data->StatusNotification[gun_index].Status, "Preparing") != NULL))
  10976. {
  10977. connectorIdInt = (gun_index+1);
  10978. DEBUG_INFO("Remote start without connectorId but detect connector-%02d connected ready to start.\n", connectorIdInt);
  10979. break;
  10980. }
  10981. }
  10982. }
  10983. if(connectorIdInt == 0)
  10984. {
  10985. DEBUG_WARN("Connector id shall not equal 0.\n");
  10986. result = FAIL;
  10987. }
  10988. else if(json_object_object_get(RemoteStartTransaction, "idTag") == NULL)
  10989. {
  10990. DEBUG_WARN("idTag should not be NULL.\n");
  10991. result = FAIL;
  10992. }
  10993. else if(connectorIdInt == -1)
  10994. {
  10995. DEBUG_INFO("Connector id does not specific.\n");
  10996. for(uint8_t gun_index=0;gun_index<gunTotalNumber;gun_index++)
  10997. {
  10998. memset(&ShmOCPP16Data->RemoteStartTransaction[gun_index], 0x00, sizeof(struct StructRemoteStartTransaction));
  10999. // Required data
  11000. sprintf((char*)ShmOCPP16Data->RemoteStartTransaction[gun_index].IdTag, "%s", json_object_get_string(json_object_object_get(RemoteStartTransaction, "idTag")));
  11001. // Optional data
  11002. if(json_object_object_get(RemoteStartTransaction, "chargingProfile") != NULL)
  11003. {
  11004. ShmOCPP16Data->RemoteStartTransaction[gun_index].ChargingProfile.ChargingProfileId = json_object_get_int(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingProfileId"));
  11005. ShmOCPP16Data->RemoteStartTransaction[gun_index].ChargingProfile.StackLevel = json_object_get_int(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "stackLevel"));
  11006. sprintf((char*)ShmOCPP16Data->RemoteStartTransaction[gun_index].ChargingProfile.ChargingProfilePurpose, "%s", json_object_get_string(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingProfilePurpose")));
  11007. sprintf((char*)ShmOCPP16Data->RemoteStartTransaction[gun_index].ChargingProfile.ChargingProfileKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingProfileKind")));
  11008. if(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "transactionId") != NULL)
  11009. ShmOCPP16Data->RemoteStartTransaction[gun_index].ChargingProfile.TransactionId = json_object_get_int(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "transactionId"));
  11010. if(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "recurrencyKind") != NULL)
  11011. sprintf((char*)ShmOCPP16Data->RemoteStartTransaction[gun_index].ChargingProfile.RecurrencyKind , "%s", json_object_get_string(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "recurrencyKind")));
  11012. if(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "validFrom") != NULL)
  11013. sprintf((char*)ShmOCPP16Data->RemoteStartTransaction[gun_index].ChargingProfile.ValidFrom , "%s", json_object_get_string(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "validFrom")));
  11014. if(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "validTo") != NULL)
  11015. sprintf((char*)ShmOCPP16Data->RemoteStartTransaction[gun_index].ChargingProfile.ValidTo , "%s", json_object_get_string(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "validTo")));
  11016. if(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingSchedule") != NULL)
  11017. {
  11018. 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")));
  11019. if(json_object_object_get(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingSchedule"), "duration") != NULL)
  11020. 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"));
  11021. if(json_object_object_get(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingSchedule"), "minChargingRate") != NULL)
  11022. 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"));
  11023. if(json_object_object_get(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingSchedule"), "startSchedule") != NULL)
  11024. 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")));
  11025. if(json_object_object_get(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingSchedule"), "chargingSchedulePeriod") != NULL)
  11026. {
  11027. 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++)
  11028. {
  11029. 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"));
  11030. 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"));
  11031. 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)
  11032. 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"));
  11033. }
  11034. }
  11035. }
  11036. }
  11037. else
  11038. {
  11039. ShmOCPP16Data->RemoteStartTransaction[gun_index].ChargingProfile.ChargingProfileId = -1;
  11040. }
  11041. }
  11042. }
  11043. else if(((0 < connectorIdInt) && (connectorIdInt <= gunTotalNumber)))
  11044. {
  11045. DEBUG_INFO("Connector id: %d\n", connectorIdInt);
  11046. memset(&ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1], 0x00, sizeof(struct StructRemoteStartTransaction));
  11047. // Required data
  11048. sprintf((char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag, "%s", json_object_get_string(json_object_object_get(RemoteStartTransaction, "idTag")));
  11049. // Optional data
  11050. if(json_object_object_get(RemoteStartTransaction, "chargingProfile") != NULL)
  11051. {
  11052. ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingProfileId = json_object_get_int(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingProfileId"));
  11053. ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.StackLevel = json_object_get_int(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "stackLevel"));
  11054. sprintf((char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingProfilePurpose, "%s", json_object_get_string(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingProfilePurpose")));
  11055. sprintf((char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingProfileKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingProfileKind")));
  11056. if(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "transactionId") != NULL)
  11057. ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.TransactionId = json_object_get_int(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "transactionId"));
  11058. if(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "recurrencyKind") != NULL)
  11059. sprintf((char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.RecurrencyKind , "%s", json_object_get_string(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "recurrencyKind")));
  11060. if(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "validFrom") != NULL)
  11061. sprintf((char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ValidFrom , "%s", json_object_get_string(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "validFrom")));
  11062. if(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "validTo") != NULL)
  11063. sprintf((char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ValidTo , "%s", json_object_get_string(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "validTo")));
  11064. if(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingSchedule") != NULL)
  11065. {
  11066. 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")));
  11067. if(json_object_object_get(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingSchedule"), "duration") != NULL)
  11068. 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"));
  11069. if(json_object_object_get(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingSchedule"), "minChargingRate") != NULL)
  11070. 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"));
  11071. if(json_object_object_get(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingSchedule"), "startSchedule") != NULL)
  11072. 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")));
  11073. if(json_object_object_get(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingSchedule"), "chargingSchedulePeriod") != NULL)
  11074. {
  11075. 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++)
  11076. {
  11077. 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"));
  11078. 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"));
  11079. 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)
  11080. 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"));
  11081. }
  11082. }
  11083. }
  11084. }
  11085. else
  11086. {
  11087. ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingProfileId = -1;
  11088. }
  11089. }
  11090. else
  11091. {
  11092. DEBUG_WARN("Connector id is over maximun value.\n");
  11093. result = FAIL;
  11094. }
  11095. }
  11096. if(result == PASS)
  11097. {
  11098. if(connectorIdInt > 0)
  11099. {
  11100. //check Transaction active
  11101. if(gunType[connectorIdInt -1] == GUN_TYPE_CHAdeMO)
  11102. {
  11103. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  11104. {
  11105. tempIndex = ((connectorIdInt -1) == 2) ? 1: 0;
  11106. }
  11107. else
  11108. {
  11109. tempIndex = connectorIdInt -1;
  11110. }
  11111. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  11112. {
  11113. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  11114. {
  11115. if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ReservationId != -1) &&
  11116. (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ReservationId >= 0) &&
  11117. (strcmp((const char *)ShmOCPP16Data->ReserveNow[index].IdTag, (char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag) == 0))
  11118. {
  11119. //Reserved
  11120. DEBUG_INFO("CHAdeMO connector already reserved and idTag match.\n");
  11121. }
  11122. else if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ReservationId != -1) &&
  11123. (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ReservationId >= 0) &&
  11124. (strcmp((const char *)ShmOCPP16Data->ReserveNow[index].IdTag, (char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag) != 0))
  11125. {
  11126. //Reserved
  11127. if(strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemData, "TRUE") == NULL)
  11128. {
  11129. DEBUG_INFO("CHAdeMO connector already reserved and idTag does not match.\n");
  11130. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  11131. goto end;
  11132. }
  11133. }
  11134. else
  11135. {
  11136. if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_IDLE) || ShmOCPP16Data->MsMsg.bits.isRemoteStartWaitReq)
  11137. {
  11138. DEBUG_WARN("CHAdeMO connector not allow start cause busy.\n");
  11139. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  11140. goto end;
  11141. }
  11142. }//END FOR ELSE
  11143. }
  11144. }// END FOR CHAdeMO_QUANTITY
  11145. }
  11146. else if(gunType[connectorIdInt -1] == GUN_TYPE_CCS)
  11147. {
  11148. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  11149. {
  11150. tempIndex = ((connectorIdInt -1) == 2) ? 1: 0;
  11151. }
  11152. else
  11153. {
  11154. tempIndex = connectorIdInt -1;
  11155. }
  11156. for (int index = 0; index < CCS_QUANTITY; index++)
  11157. {
  11158. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  11159. {
  11160. if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ReservationId != -1) &&
  11161. (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ReservationId >= 0) &&
  11162. (strcmp((const char *)ShmOCPP16Data->ReserveNow[index].IdTag, (char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag) == 0))
  11163. {
  11164. //Reserved
  11165. DEBUG_INFO("CCS connector already reserved and idTag match.\n");
  11166. }
  11167. else if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ReservationId != -1) &&
  11168. (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ReservationId >= 0) &&
  11169. (strcmp((const char *)ShmOCPP16Data->ReserveNow[index].IdTag, (char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag) != 0))
  11170. {
  11171. //Reserved
  11172. if(strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemData, "TRUE") == NULL)
  11173. {
  11174. DEBUG_INFO("CCS connector already reserved and idTag does not match.\n");
  11175. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  11176. goto end;
  11177. }
  11178. }
  11179. else
  11180. {
  11181. if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_IDLE) || ShmOCPP16Data->MsMsg.bits.isRemoteStartWaitReq)
  11182. {
  11183. DEBUG_WARN("CCS connector not allow start cause busy.\n");
  11184. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  11185. goto end;
  11186. }
  11187. }// END FOR ELSE
  11188. }
  11189. }// END FOR CCS_QUANTITY
  11190. }
  11191. else if(gunType[connectorIdInt -1] == GUN_TYPE_GBT)
  11192. {
  11193. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  11194. {
  11195. tempIndex = ((connectorIdInt -1) == 2) ? 1: 0;
  11196. }
  11197. else
  11198. {
  11199. tempIndex = connectorIdInt -1;
  11200. }
  11201. for (int index = 0; index < GB_QUANTITY; index++)
  11202. {
  11203. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex )
  11204. {
  11205. if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ReservationId != -1) &&
  11206. (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ReservationId >= 0) &&
  11207. (strcmp((const char *)ShmOCPP16Data->ReserveNow[index].IdTag, (char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag) == 0))
  11208. {
  11209. //Reserved
  11210. DEBUG_INFO("GBT connector already reserved and idTag match.\n");
  11211. }
  11212. else if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ReservationId != -1) &&
  11213. (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ReservationId >= 0) &&
  11214. (strcmp((const char *)ShmOCPP16Data->ReserveNow[index].IdTag, (char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag) != 0))
  11215. {
  11216. //Reserved
  11217. if(strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemData, "TRUE") == NULL)
  11218. {
  11219. DEBUG_INFO("GBT connector already reserved and idTag does not match.\n");
  11220. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  11221. goto end;
  11222. }
  11223. }
  11224. else
  11225. {
  11226. if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_IDLE) || ShmOCPP16Data->MsMsg.bits.isRemoteStartWaitReq)
  11227. {
  11228. DEBUG_WARN("GBT connector not allow start cause busy.\n");
  11229. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  11230. goto end;
  11231. }
  11232. }// END FOR ELSE
  11233. }
  11234. } // END FOR GB_QUANTITY
  11235. }
  11236. else if(gunType[connectorIdInt -1] == GUN_TYPE_DO)
  11237. {
  11238. tempIndex = connectorIdInt -1;
  11239. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  11240. {
  11241. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex )
  11242. {
  11243. if((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.ReservationId != -1) &&
  11244. (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.ReservationId >= 0) &&
  11245. (strcmp((const char *)ShmOCPP16Data->ReserveNow[index].IdTag, (char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag) == 0))
  11246. {
  11247. //Reserved
  11248. DEBUG_INFO("Dispenser connector already reserved and idTag match.\n");
  11249. }
  11250. else if((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.ReservationId != -1) &&
  11251. (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.ReservationId >= 0) &&
  11252. (strcmp((const char *)ShmOCPP16Data->ReserveNow[index].IdTag, (char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag) != 0))
  11253. {
  11254. //Reserved
  11255. if(strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemData, "TRUE") == NULL)
  11256. {
  11257. DEBUG_INFO("Dispenser connector already reserved and idTag does not match.\n");
  11258. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  11259. goto end;
  11260. }
  11261. }
  11262. else
  11263. {
  11264. if((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus != SYS_MODE_IDLE) || ShmOCPP16Data->MsMsg.bits.isRemoteStartWaitReq)
  11265. {
  11266. DEBUG_WARN("Dispenser connector not allow start cause busy.\n");
  11267. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  11268. goto end;
  11269. }
  11270. }// END FOR ELSE
  11271. }
  11272. } // END FOR GB_QUANTITY
  11273. }
  11274. else
  11275. {
  11276. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D') // 'D' means DC
  11277. {
  11278. tempIndex = 2;
  11279. }
  11280. else
  11281. {
  11282. tempIndex = connectorIdInt -1;
  11283. }
  11284. for (int index = 0; index < AC_QUANTITY; index++)
  11285. {
  11286. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex )
  11287. {
  11288. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].ReservationId != -1) &&
  11289. (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].ReservationId >= 0) &&
  11290. (strcmp((const char *)ShmOCPP16Data->ReserveNow[index].IdTag, (char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag) == 0))
  11291. {
  11292. //Reserved
  11293. DEBUG_INFO("AC connector already reserved and idTag match.\n");
  11294. }
  11295. else if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].ReservationId != -1) &&
  11296. (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].ReservationId >= 0) &&
  11297. (strcmp((const char *)ShmOCPP16Data->ReserveNow[index].IdTag, (char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag) != 0))
  11298. {
  11299. //Reserved
  11300. if(strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemData, "TRUE") == NULL)
  11301. {
  11302. DEBUG_INFO("AC connector already reserved and idTag does not match.\n");
  11303. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  11304. goto end;
  11305. }
  11306. }
  11307. else
  11308. {
  11309. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_IDLE) || ShmOCPP16Data->MsMsg.bits.isRemoteStartWaitReq)
  11310. {
  11311. DEBUG_WARN("AC connector not allow start cause busy.\n");
  11312. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  11313. goto end;
  11314. }
  11315. }//END FOR ELSE
  11316. }
  11317. }// END FOR AC_QUANTITY
  11318. }
  11319. if(ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingProfileId > -1)
  11320. {
  11321. if(strcmp((char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingProfilePurpose, ChargingProfilePurposeTypeStr[TxProfile]) == 0)
  11322. {
  11323. // Save profile to file
  11324. sprintf(cmdBuf, "rm -f /Storage/OCPP/TxProfile_%d.json", connectorIdInt);
  11325. system(cmdBuf);
  11326. sprintf(cmdBuf, "/Storage/OCPP/TxProfile_%d.json", connectorIdInt);
  11327. fp = fopen(cmdBuf, "w");
  11328. 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));
  11329. fclose(fp);
  11330. }
  11331. else
  11332. {
  11333. DEBUG_WARN("Profile purpose not TxProfile.\n");
  11334. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  11335. goto end;
  11336. }
  11337. }
  11338. ShmOCPP16Data->CsMsg.bits[connectorIdInt -1].RemoteStartTransactionReq = 1;
  11339. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Accepted]);
  11340. memset((char *)ShmOCPP16Data->StartTransaction[connectorIdInt -1].IdTag,0, 20);
  11341. strcpy((char *)ShmOCPP16Data->StartTransaction[connectorIdInt -1].IdTag, (char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag);
  11342. memset((char *)ShmOCPP16Data->StopTransaction[connectorIdInt -1].IdTag,0, 20);
  11343. strcpy((char *)ShmOCPP16Data->StopTransaction[connectorIdInt -1].IdTag, (char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag);
  11344. }
  11345. else
  11346. {
  11347. uint8_t isHasIdleConnector = FALSE;
  11348. for(uint8_t gun_index=0;gun_index<gunTotalNumber;gun_index++)
  11349. {
  11350. if(!cpinitateMsg.bits[gun_index].isOnCharging)
  11351. {
  11352. isHasIdleConnector = TRUE;
  11353. break;
  11354. }
  11355. }
  11356. if((isHasIdleConnector == TRUE) && !ShmOCPP16Data->MsMsg.bits.isRemoteStartWaitReq)
  11357. {
  11358. DEBUG_INFO("Start wait connector link to EV in %s seconds.\n", ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemData);
  11359. if(ShmOCPP16Data->RemoteStartTransaction[0].ChargingProfile.ChargingProfileId > -1)
  11360. {
  11361. if(strcmp((char*)ShmOCPP16Data->RemoteStartTransaction[0].ChargingProfile.ChargingProfilePurpose, ChargingProfilePurposeTypeStr[TxProfile]) == 0)
  11362. {
  11363. // Save profile to file
  11364. sprintf(cmdBuf, "rm -f /Storage/OCPP/TxProfile_Tmp.json");
  11365. system(cmdBuf);
  11366. sprintf(cmdBuf, "/Storage/OCPP/TxProfile_Tmp.json");
  11367. fp = fopen(cmdBuf, "w");
  11368. fprintf(fp, "{\"connectorId\":0,\"csChargingProfiles\":%s}\n", json_object_to_json_string_ext(json_object_object_get(RemoteStartTransaction, "chargingProfile"), JSON_C_TO_STRING_PLAIN));
  11369. fclose(fp);
  11370. refreshStartTimer(&clientTime.RemoteStartWait);
  11371. ShmOCPP16Data->MsMsg.bits.isRemoteStartWaitReq = 1;
  11372. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Accepted]);
  11373. }
  11374. else
  11375. {
  11376. DEBUG_WARN("Profile purpose not TxProfile.\n");
  11377. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  11378. }
  11379. }
  11380. else
  11381. {
  11382. refreshStartTimer(&clientTime.RemoteStartWait);
  11383. ShmOCPP16Data->MsMsg.bits.isRemoteStartWaitReq = 1;
  11384. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Accepted]);
  11385. }
  11386. }
  11387. else
  11388. {
  11389. DEBUG_INFO("There is not any connector is idle.\n");
  11390. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  11391. }
  11392. }
  11393. }
  11394. else
  11395. {
  11396. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  11397. }
  11398. end:
  11399. json_object_put(RemoteStartTransaction);
  11400. sendRemoteStartConfirmation(uuid, comfirmstr);
  11401. return result;
  11402. }
  11403. int handleRemoteStopTransactionRequest(char *uuid, char *payload)
  11404. {
  11405. mtrace();
  11406. int result = FAIL;
  11407. int match = FALSE;
  11408. int GunNO = 0;
  11409. int tempIndex = 0;
  11410. int transactionIdInt=0;
  11411. int transactionIdIsNULL= TRUE;
  11412. char comfirmstr[20];
  11413. json_object *RemoteStopTransaction;
  11414. //[2,"ff522854-0dea-436e-87ba-23a229269994","RemoteStopTransaction",{"transactionId":1373618380}]
  11415. DEBUG_INFO("handleRemoteStopTransactionRequest...\n");
  11416. if(server_pending == TRUE)
  11417. {
  11418. return 0;
  11419. }
  11420. RemoteStopTransaction = json_tokener_parse(payload);
  11421. if(!is_error(RemoteStopTransaction))
  11422. {
  11423. if(json_object_object_get(RemoteStopTransaction, "transactionId") != NULL)
  11424. {
  11425. transactionIdInt = json_object_get_int(json_object_object_get(RemoteStopTransaction, "transactionId"));
  11426. transactionIdIsNULL = FALSE;
  11427. }
  11428. }
  11429. json_object_put(RemoteStopTransaction);
  11430. if(transactionIdIsNULL == FALSE)
  11431. {
  11432. for(int gun_index=0;gun_index < gunTotalNumber;gun_index++)
  11433. {
  11434. if(ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId == transactionIdInt)
  11435. {
  11436. //check Transaction active
  11437. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  11438. {
  11439. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  11440. {
  11441. tempIndex = ((gun_index==2) ? 1: 0);
  11442. }
  11443. else
  11444. {
  11445. tempIndex = gun_index;
  11446. }
  11447. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  11448. {
  11449. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  11450. {
  11451. if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_TERMINATING)) // SYS_MODE_CHARGING, SYS_MODE_TERMINATING
  11452. {
  11453. match = TRUE;
  11454. GunNO = gun_index;
  11455. }
  11456. }
  11457. }// END FOR CHAdeMO_QUANTITY
  11458. }
  11459. else if(gunType[gun_index] == GUN_TYPE_CCS)
  11460. {
  11461. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  11462. {
  11463. tempIndex = ((gun_index==2) ? 1: 0);
  11464. }
  11465. else
  11466. {
  11467. tempIndex = gun_index;
  11468. }
  11469. for (int index = 0; index < CCS_QUANTITY; index++)
  11470. {
  11471. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  11472. {
  11473. if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_TERMINATING) ) // SYS_MODE_CHARGING, SYS_MODE_TERMINATING
  11474. {
  11475. match = TRUE;
  11476. GunNO = gun_index;
  11477. }
  11478. }
  11479. }// END FOR CCS_QUANTITY
  11480. }
  11481. else if(gunType[gun_index] == GUN_TYPE_GBT)
  11482. {
  11483. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  11484. {
  11485. tempIndex = ((gun_index==2) ? 1: 0);
  11486. }
  11487. else
  11488. {
  11489. tempIndex = gun_index;
  11490. }
  11491. for (int index = 0; index < GB_QUANTITY; index++)
  11492. {
  11493. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  11494. {
  11495. if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_TERMINATING)) // SYS_MODE_CHARGING, SYS_MODE_TERMINATING
  11496. {
  11497. match = TRUE;
  11498. GunNO = gun_index;
  11499. }
  11500. }
  11501. }// END FOR GB_QUANTITY
  11502. }
  11503. else if(gunType[gun_index] == GUN_TYPE_DO)
  11504. {
  11505. tempIndex = gun_index;
  11506. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  11507. {
  11508. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  11509. {
  11510. 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
  11511. {
  11512. match = TRUE;
  11513. GunNO = gun_index;
  11514. }
  11515. }
  11516. }// END FOR GB_QUANTITY
  11517. }
  11518. else
  11519. {
  11520. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D') // 'D' means DC
  11521. {
  11522. tempIndex = 2;
  11523. }
  11524. else
  11525. {
  11526. tempIndex = gun_index;
  11527. }
  11528. for (int index = 0; index < AC_QUANTITY; index++)
  11529. {
  11530. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  11531. {
  11532. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_TERMINATING)) // SYS_MODE_CHARGING, SYS_MODE_TERMINATING
  11533. {
  11534. match = TRUE;
  11535. GunNO = gun_index;
  11536. }
  11537. }
  11538. }// END FOR CHAdeMO_QUANTITY
  11539. } // END FOR AC ELSE
  11540. }// CHECK IF ResponseTransactionId == transactionIdInt
  11541. }//END FOR
  11542. if( match == TRUE)
  11543. {
  11544. ShmOCPP16Data->CsMsg.bits[GunNO].RemoteStopTransactionReq = 1; // inform csu of StopTransaction
  11545. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Accepted]);
  11546. sprintf((char *)ShmOCPP16Data->RemoteStopTransaction[GunNO].ResponseStatus, "%s" ,comfirmstr);
  11547. }
  11548. else
  11549. {
  11550. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  11551. }
  11552. }
  11553. else
  11554. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  11555. sendRemoteStopTransactionConfirmation(uuid, comfirmstr);
  11556. return result;
  11557. }
  11558. int handleReserveNowTransactionRequest(char *uuid, char *payload)
  11559. {
  11560. mtrace();
  11561. int result = FAIL;
  11562. int connectorIdInt=0, reservationIdInt=0;
  11563. int tempIndex = 0;
  11564. char expiryDatestr[30]={0}, idTagstr[21]={0},parentIdTagstr[21]={0};
  11565. char comfirmstr[20]={0};
  11566. char sstr[180]={ 0 },sstrtemp[200]={ 0 };
  11567. int c = 0;
  11568. char *loc;
  11569. //char *ptr;
  11570. DEBUG_INFO("handleReserveNowTransactionRequest ...\n");
  11571. strcpy(sstrtemp, stringtrimspace(payload));
  11572. //***(1)connectorId ****/
  11573. c=0;
  11574. loc = strstr(sstrtemp, "connectorId");
  11575. memset(sstr ,0, ARRAY_SIZE(sstr) );
  11576. while ((loc != NULL) &&(loc[strlen("connectorId")+2+c] != ',') && (loc[strlen("connectorId")+2+c] != '}'))
  11577. {
  11578. sstr[c] = loc[strlen("connectorId")+2+c];
  11579. //printf("i=%d sstr=%c\n",c, sstr[c]);
  11580. c++;
  11581. }
  11582. sstr[c] = '\0';
  11583. connectorIdInt = atoi(sstr);
  11584. //***(2)expiryDate ****/
  11585. loc = strstr(sstrtemp, "expiryDate");
  11586. memset(sstr ,0, ARRAY_SIZE(sstr) );
  11587. c = 0;
  11588. while ((loc != NULL) &&(loc[3+strlen("expiryDate")+c] != '\"'))
  11589. {
  11590. sstr[c] = loc[3+strlen("expiryDate")+c];
  11591. c++;
  11592. }
  11593. sstr[c] = '\0';
  11594. strcpy(expiryDatestr, sstr);
  11595. //***(3)idTag ****/
  11596. loc = strstr(sstrtemp, "idTag");
  11597. memset(sstr ,0, ARRAY_SIZE(sstr) );
  11598. c = 0;
  11599. while ((loc != NULL) &&(loc[3+strlen("idTag")+c] != '\"'))
  11600. {
  11601. sstr[c] = loc[3+strlen("idTag")+c];
  11602. c++;
  11603. }
  11604. sstr[c] = '\0';
  11605. strcpy(idTagstr, sstr);
  11606. //***(4)parentIdTag ****/
  11607. loc = strstr(sstrtemp, "parentIdTag");
  11608. memset(sstr ,0, ARRAY_SIZE(sstr) );
  11609. c = 0;
  11610. if(loc == NULL)
  11611. {
  11612. strcpy(parentIdTagstr, "");
  11613. }
  11614. else
  11615. {
  11616. while ((loc != NULL) &&(loc[3+strlen("parentIdTag")+c] != '\"'))
  11617. {
  11618. sstr[c] = loc[3+strlen("parentIdTag")+c];
  11619. c++;
  11620. }
  11621. sstr[c] = '\0';
  11622. strcpy(parentIdTagstr, sstr);
  11623. }
  11624. //***(5)reservationId ****/
  11625. c=0;
  11626. loc = strstr(sstrtemp, "reservationId");
  11627. memset(sstr ,0, ARRAY_SIZE(sstr) );
  11628. while ((loc != NULL) &&((loc[strlen("reservationId")+2+c] != '}') && (loc[strlen("reservationId")+2+c] != ',')))
  11629. {
  11630. sstr[c] = loc[strlen("reservationId")+2+c];
  11631. //printf("i=%d sstr=%c\n",c, sstr[c]);
  11632. c++;
  11633. }
  11634. sstr[c] = '\0';
  11635. reservationIdInt = atoi(sstr);
  11636. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  11637. /*
  11638. enum SYSTEM_STATUS
  11639. {
  11640. SYS_MODE_BOOTING = 0,
  11641. SYS_MODE_IDLE = 1,
  11642. SYS_MODE_AUTHORIZING = 2,
  11643. SYS_MODE_MODE_REASSIGN_CHECK = 3,
  11644. SYS_MODE_REASSIGN = 4,
  11645. SYS_MODE_PREPARING = 5,
  11646. SYS_MODE_PREPARE_FOR_EV = 6,
  11647. SYS_MODE_PREPARE_FOR_EVSE = 7,
  11648. SYS_MODE_CHARGING = 8,
  11649. SYS_MODE_TERMINATING = 9,
  11650. SYS_MODE_COMPLETE = 10,
  11651. SYS_MODE_ALARM = 11,
  11652. SYS_MODE_FAULT = 12,
  11653. SYS_MODE_RESERVATION = 13,
  11654. SYS_MODE_BOOKING = 14,
  11655. SYS_MODE_MAINTAIN = 15,
  11656. SYS_MODE_DEBUG = 16,
  11657. SYS_MODE_CCS_PRECHARGE_STEP0 = 17,
  11658. SYS_MODE_CCS_PRECHARGE_STEP1 = 18,
  11659. SYS_MODE_UPDATE = 19
  11660. };
  11661. */
  11662. if((connectorIdInt == 0) &&(strcmp((const char *)ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemData, "FALSE") == 0)) //For OCTT Test case
  11663. {
  11664. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  11665. goto end;
  11666. }
  11667. if((connectorIdInt > 0) && ((connectorIdInt -1) <= gunTotalNumber))
  11668. {
  11669. //check Transaction active
  11670. if(gunType[connectorIdInt -1] == GUN_TYPE_CHAdeMO)
  11671. {
  11672. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  11673. {
  11674. tempIndex = (((connectorIdInt -1)==2) ? 1: 0);
  11675. }
  11676. else
  11677. {
  11678. tempIndex = connectorIdInt -1;
  11679. }
  11680. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  11681. {
  11682. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  11683. {
  11684. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ReservationId)
  11685. {
  11686. if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_FAULT)&&(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_ALARM)) //S_FAULT
  11687. {
  11688. if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_IDLE) //S_IDLE
  11689. {
  11690. if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ConnectorPlugIn == 1) || (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].InProgress == 1))
  11691. {
  11692. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  11693. }
  11694. else
  11695. {
  11696. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  11697. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  11698. }
  11699. }
  11700. 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'))
  11701. {
  11702. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  11703. }
  11704. else if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_PREPARING) || (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_RESERVATION) ) //S_PRECHARGE
  11705. {
  11706. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  11707. }
  11708. else
  11709. {
  11710. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  11711. }
  11712. }
  11713. 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
  11714. {
  11715. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  11716. }
  11717. }
  11718. else
  11719. {
  11720. //replace reservation
  11721. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  11722. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  11723. }
  11724. }
  11725. } // END FOR CHAdeMO_QUANTITY
  11726. }
  11727. else if(gunType[connectorIdInt -1] == GUN_TYPE_CCS)
  11728. {
  11729. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  11730. {
  11731. tempIndex = (((connectorIdInt -1)==2) ? 1: 0);
  11732. }
  11733. else
  11734. {
  11735. tempIndex = connectorIdInt -1;
  11736. }
  11737. for (int index = 0; index < CCS_QUANTITY; index++)
  11738. {
  11739. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  11740. {
  11741. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ReservationId)
  11742. {
  11743. //SystemStatus: 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault, 8: Reserved, 9: maintain
  11744. if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_FAULT)&&(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_ALARM)) //S_FAULT
  11745. {
  11746. if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_IDLE) //S_IDLE
  11747. {
  11748. if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ConnectorPlugIn == 1) || (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].InProgress == 1))
  11749. {
  11750. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  11751. }
  11752. else
  11753. {
  11754. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  11755. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  11756. }
  11757. }
  11758. 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'))
  11759. {
  11760. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  11761. }
  11762. else if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_PREPARING) || (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_RESERVATION)) //S_PRECHARGE
  11763. {
  11764. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  11765. }
  11766. else
  11767. {
  11768. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  11769. }
  11770. }
  11771. 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
  11772. {
  11773. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  11774. }
  11775. }
  11776. else
  11777. {
  11778. //replace reservation
  11779. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  11780. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  11781. }
  11782. }
  11783. } // END FOR CCS_QUANTITY
  11784. }
  11785. else if(gunType[connectorIdInt -1] == GUN_TYPE_GBT)
  11786. {
  11787. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  11788. {
  11789. tempIndex = (((connectorIdInt -1)==2) ? 1: 0);
  11790. }
  11791. else
  11792. {
  11793. tempIndex = connectorIdInt -1;
  11794. }
  11795. for (int index = 0; index < GB_QUANTITY; index++)
  11796. {
  11797. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  11798. {
  11799. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ReservationId)
  11800. {
  11801. //SystemStatus: 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault, 8: Reserved, 9: maintain
  11802. if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_FAULT)&&(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_ALARM)) //SYS_MODE_FAULT, SYS_MODE_ALARM
  11803. {
  11804. if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_IDLE) //S_IDLE
  11805. {
  11806. if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ConnectorPlugIn == 1) || (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].InProgress == 1))
  11807. {
  11808. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  11809. }
  11810. else
  11811. {
  11812. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  11813. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  11814. }
  11815. }
  11816. 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'))
  11817. {
  11818. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  11819. }
  11820. else if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_PREPARING) || (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_RESERVATION) ) //S_PRECHARGE
  11821. {
  11822. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  11823. }
  11824. else
  11825. {
  11826. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  11827. }
  11828. }
  11829. 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
  11830. {
  11831. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  11832. }
  11833. }
  11834. else
  11835. {
  11836. //replace reservation
  11837. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  11838. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  11839. }
  11840. }
  11841. }// END FOR GB_QUANTITY
  11842. }
  11843. else if(gunType[connectorIdInt -1] == GUN_TYPE_DO)
  11844. {
  11845. tempIndex = connectorIdInt -1;
  11846. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  11847. {
  11848. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  11849. {
  11850. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.ReservationId)
  11851. {
  11852. //SystemStatus: 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault, 8: Reserved, 9: maintain
  11853. 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
  11854. {
  11855. if(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_IDLE) //S_IDLE
  11856. {
  11857. if((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.ConnectorPlugIn == 1) || (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.InProgress == 1))
  11858. {
  11859. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  11860. }
  11861. else
  11862. {
  11863. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  11864. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  11865. }
  11866. }
  11867. 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'))
  11868. {
  11869. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  11870. }
  11871. else if((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_PREPARING) || (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_RESERVATION) ) //S_PRECHARGE
  11872. {
  11873. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  11874. }
  11875. else
  11876. {
  11877. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  11878. }
  11879. }
  11880. 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
  11881. {
  11882. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  11883. }
  11884. }
  11885. else
  11886. {
  11887. //replace reservation
  11888. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  11889. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  11890. }
  11891. }
  11892. }// END FOR GB_QUANTITY
  11893. }
  11894. else
  11895. {
  11896. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D') // 'D' means DC
  11897. {
  11898. tempIndex = 2;
  11899. }
  11900. else
  11901. {
  11902. tempIndex = (connectorIdInt -1);
  11903. }
  11904. for (int index = 0; index < AC_QUANTITY; index++)
  11905. {
  11906. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  11907. {
  11908. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.AcChargingData[index].ReservationId)
  11909. {
  11910. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_FAULT)&&(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_ALARM)) //SYS_MODE_FAULT, SYS_MODE_ALARM
  11911. {
  11912. if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_IDLE) //S_IDLE
  11913. {
  11914. 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))
  11915. {
  11916. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  11917. }
  11918. else
  11919. {
  11920. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  11921. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  11922. }
  11923. }
  11924. 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'))
  11925. {
  11926. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  11927. }
  11928. else if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_PREPARING) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_RESERVATION) ) //S_PRECHARGE
  11929. {
  11930. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  11931. }
  11932. else
  11933. {
  11934. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  11935. }
  11936. }
  11937. 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
  11938. {
  11939. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  11940. }
  11941. }
  11942. else
  11943. {
  11944. //replace reservation
  11945. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  11946. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  11947. }
  11948. }
  11949. } // END FOR AC_QUANTITY
  11950. }
  11951. sprintf((char *)ShmOCPP16Data->ReserveNow[connectorIdInt-1].ResponseStatus, "%s" ,comfirmstr);
  11952. }
  11953. else if(connectorIdInt == 0)
  11954. {
  11955. //check Transaction active
  11956. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  11957. {
  11958. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ReservationId)
  11959. {
  11960. 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'))
  11961. {
  11962. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  11963. goto end;
  11964. }
  11965. else if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_PREPARING) //S_PRECHARGE
  11966. {
  11967. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  11968. goto end;
  11969. }
  11970. 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
  11971. {
  11972. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  11973. goto end;
  11974. }
  11975. else if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  11976. {
  11977. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  11978. goto end;
  11979. }
  11980. }
  11981. }// END FOR CHAdeMO_QUANTITY
  11982. for (int index = 0; index < CCS_QUANTITY; index++)
  11983. {
  11984. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ReservationId)
  11985. {
  11986. 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'))
  11987. {
  11988. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  11989. goto end;
  11990. }
  11991. else if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_PREPARING) //SYS_MODE_PREPARING
  11992. {
  11993. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  11994. goto end;
  11995. }
  11996. 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
  11997. {
  11998. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  11999. goto end;
  12000. }
  12001. else if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  12002. {
  12003. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  12004. goto end;
  12005. }
  12006. }
  12007. } // END FOR CCS_QUANTITY
  12008. for (int index = 0; index < GB_QUANTITY; index++)
  12009. {
  12010. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ReservationId)
  12011. {
  12012. 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'))
  12013. {
  12014. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  12015. goto end;
  12016. }
  12017. else if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_PREPARING) //S_PRECHARGE
  12018. {
  12019. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  12020. goto end;
  12021. }
  12022. 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
  12023. {
  12024. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  12025. goto end;
  12026. }
  12027. else if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  12028. {
  12029. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  12030. goto end;
  12031. }
  12032. }
  12033. } // END FOR GB_QUANTITY
  12034. for (int index = 0; index < AC_QUANTITY; index++)
  12035. {
  12036. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.AcChargingData[index].ReservationId)
  12037. {
  12038. 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'))
  12039. {
  12040. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  12041. goto end;
  12042. }
  12043. else if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_PREPARING) //S_PRECHARGE
  12044. {
  12045. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  12046. goto end;
  12047. }
  12048. 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
  12049. {
  12050. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  12051. goto end;
  12052. }
  12053. if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_IDLE) //S_IDLE
  12054. {
  12055. 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))
  12056. {
  12057. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  12058. goto end;
  12059. }
  12060. }
  12061. else if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  12062. {
  12063. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  12064. goto end;
  12065. }
  12066. }
  12067. }// END FOR AC_QUANTITY
  12068. //The connectorId is 0
  12069. ShmOCPP16Data->CsMsg.bits[0].ReserveNowReq = 1;
  12070. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  12071. sprintf((char *)ShmOCPP16Data->ReserveNow[0].ResponseStatus, "%s" ,comfirmstr);
  12072. ShmOCPP16Data->ReserveNow[0].ConnectorId = connectorIdInt;
  12073. sprintf((char *)ShmOCPP16Data->ReserveNow[0].ExpiryDate, "%s" , expiryDatestr);
  12074. sprintf((char *)ShmOCPP16Data->ReserveNow[0].IdTag, "%s" , idTagstr);
  12075. sprintf((char *)ShmOCPP16Data->ReserveNow[0].ParentIdTag, "%s" , parentIdTagstr);
  12076. ShmOCPP16Data->ReserveNow[0].ReservationId = reservationIdInt;
  12077. strcpy((char *)ShmOCPP16Data->ReserveNow[0].guid, uuid);
  12078. result = TRUE;
  12079. return result;
  12080. }
  12081. else
  12082. {
  12083. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  12084. sprintf((char *)ShmOCPP16Data->ReserveNow[connectorIdInt-1].ResponseStatus, "%s" ,comfirmstr);
  12085. }
  12086. if(strcmp(comfirmstr,"Accepted") == 0)
  12087. {
  12088. ShmOCPP16Data->ReserveNow[connectorIdInt-1].ConnectorId = connectorIdInt;
  12089. sprintf((char *)ShmOCPP16Data->ReserveNow[connectorIdInt-1].ExpiryDate, "%s" , expiryDatestr);
  12090. sprintf((char *)ShmOCPP16Data->ReserveNow[connectorIdInt-1].IdTag, "%s" , idTagstr);
  12091. sprintf((char *)ShmOCPP16Data->ReserveNow[connectorIdInt-1].ParentIdTag, "%s" , parentIdTagstr);
  12092. ShmOCPP16Data->ReserveNow[connectorIdInt-1].ReservationId = reservationIdInt;
  12093. strcpy((char *)ShmOCPP16Data->ReserveNow[connectorIdInt-1].guid, uuid);
  12094. result = TRUE;
  12095. return result;
  12096. }
  12097. end:
  12098. sendReserveNowTransactionConfirmation(uuid,comfirmstr);
  12099. //ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].ReserveNowConf = 1;
  12100. return result;
  12101. }
  12102. int handleResetRequest(char *uuid, char *payload)
  12103. {
  12104. mtrace();
  12105. int result = FAIL;
  12106. char sstr[10]={0},sstrtemp[30]={ 0 };
  12107. char typestr[10]={0};
  12108. char comfirmstr[20]={0};
  12109. int c = 0;
  12110. char *loc;
  12111. DEBUG_INFO("handleResetRequest...\n");
  12112. strcpy(sstrtemp, stringtrimspace(payload));
  12113. loc = strstr(sstrtemp, "type");
  12114. memset(sstr ,0, ARRAY_SIZE(sstr) );
  12115. c = 0;
  12116. while (loc[3+strlen("type")+c] != '\"')
  12117. {
  12118. sstr[c] = loc[3+strlen("type")+c];
  12119. c++;
  12120. }
  12121. sstr[c] = '\0';
  12122. strcpy(typestr,sstr);
  12123. sprintf((char *)ShmOCPP16Data->Reset.Type, "%s" ,typestr);
  12124. if((strcmp(typestr, ResetTypeStr[Hard])==0) || (strcmp(typestr, ResetTypeStr[Soft])==0))
  12125. {
  12126. ShmOCPP16Data->MsMsg.bits.ResetReq = 1;
  12127. strcpy((char *)ShmOCPP16Data->Reset.guid, uuid);
  12128. strcpy(comfirmstr, ResetStatusStr[ResetStatus_Accepted]);
  12129. sprintf((char *)ShmOCPP16Data->Reset.ResponseStatus, "%s" ,comfirmstr);
  12130. }
  12131. else
  12132. {
  12133. strcpy(comfirmstr, ResetStatusStr[ResetStatus_Rejected]);
  12134. sprintf((char *)ShmOCPP16Data->Reset.ResponseStatus, "%s" ,comfirmstr);
  12135. result = PASS;
  12136. }
  12137. sendResetConfirmation(uuid, comfirmstr);
  12138. return result;
  12139. }
  12140. int handleSendLocalListRequest(char *uuid, char *payload)
  12141. {
  12142. mtrace();
  12143. int result = FAIL;
  12144. char comfirmstr[20];
  12145. int checkState_Faulted = FALSE;
  12146. json_object *SendLocalList;
  12147. DEBUG_INFO("handleSendLocalListRequest...\n");
  12148. if(strcmp((const char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "FALSE") == 0) //For OCTT Test case
  12149. {
  12150. strcpy(comfirmstr, UpdateStatusStr[UpdateStatus_NotSupported]);
  12151. goto end;
  12152. }
  12153. //check Charge Point state
  12154. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  12155. {
  12156. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_FAULT) //S_FAULT ---> Faulted
  12157. {
  12158. checkState_Faulted = TRUE; //OCPP Status: Faulted
  12159. }
  12160. }
  12161. for (int index = 0; index < CCS_QUANTITY; index++)
  12162. {
  12163. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_FAULT) //S_FAULT ---> Faulted
  12164. {
  12165. checkState_Faulted = TRUE; //OCPP Status
  12166. }
  12167. }
  12168. for (int index = 0; index < GB_QUANTITY; index++)
  12169. {
  12170. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_FAULT) //S_FAULT ---> Faulted
  12171. {
  12172. checkState_Faulted = TRUE; //OCPP Status: Faulted
  12173. }
  12174. }
  12175. //check Charge Point state
  12176. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  12177. {
  12178. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_FAULT) //S_FAULT ---> Faulted
  12179. {
  12180. checkState_Faulted = TRUE; //OCPP Status: Faulted
  12181. }
  12182. }
  12183. //check Charge Point state
  12184. for (int index = 0; index < AC_QUANTITY; index++)
  12185. {
  12186. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_FAULT) //S_FAULT ---> Faulted
  12187. {
  12188. checkState_Faulted = TRUE; //OCPP Status: Faulted
  12189. }
  12190. }
  12191. if(checkState_Faulted == TRUE)
  12192. {
  12193. strcpy(comfirmstr, UpdateStatusStr[UpdateStatus_Failed]);
  12194. goto end;
  12195. }
  12196. // Parsing payload
  12197. SendLocalList = json_tokener_parse(payload);
  12198. if(!is_error(SendLocalList))
  12199. {
  12200. // Required data
  12201. ShmOCPP16Data->SendLocalList.ListVersion = json_object_get_int(json_object_object_get(SendLocalList, "listVersion"));
  12202. sprintf((char*)ShmOCPP16Data->SendLocalList.UpdateType, "%s", json_object_get_string(json_object_object_get(SendLocalList, "updateType")));
  12203. // Optional data
  12204. if(json_object_object_get(SendLocalList, "localAuthorizationList") != NULL)
  12205. {
  12206. //Check UpdateType
  12207. if(strcmp((char*)ShmOCPP16Data->SendLocalList.UpdateType, UpdateTypeStr[Full]) == 0)
  12208. {
  12209. //Local list full update
  12210. DEBUG_INFO("Local list full update.\n");
  12211. locallistVersion = 0;
  12212. OCPP_getListVerion();
  12213. if((ShmOCPP16Data->SendLocalList.ListVersion > 0) && (ShmOCPP16Data->SendLocalList.ListVersion < locallistVersion))
  12214. {
  12215. strcpy(comfirmstr, UpdateStatusStr[UpdateStatus_Failed]);
  12216. goto end;
  12217. }
  12218. OCPP_cleanLocalList();
  12219. }
  12220. else if(strcmp((char*)ShmOCPP16Data->SendLocalList.UpdateType, UpdateTypeStr[Differential]) == 0)
  12221. {
  12222. //Local list different update
  12223. DEBUG_INFO("Local list different update.\n");
  12224. locallistVersion = 0;
  12225. OCPP_getListVerion();
  12226. if(ShmOCPP16Data->SendLocalList.ListVersion < locallistVersion)
  12227. {
  12228. strcpy(comfirmstr, UpdateStatusStr[UpdateStatus_VersionMismatch]);
  12229. goto end;
  12230. }
  12231. }
  12232. else
  12233. {
  12234. strcpy(comfirmstr, UpdateStatusStr[UpdateStatus_NotSupported]);
  12235. goto end;
  12236. }
  12237. if(json_object_array_length(json_object_object_get(SendLocalList, "localAuthorizationList")) > atoi((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemData))
  12238. {
  12239. DEBUG_WARN("Local list length is over SendLocalListMaxLength.\n");
  12240. strcpy(comfirmstr, UpdateStatusStr[UpdateStatus_Failed]);
  12241. goto end;
  12242. }
  12243. memset(ShmOCPP16Data->SendLocalList.LocalAuthorizationList, 0 , sizeof(struct StructLocalAuthorizationList)*1);
  12244. for(int idx=0;idx<json_object_array_length(json_object_object_get(SendLocalList, "localAuthorizationList"));idx++)
  12245. {
  12246. 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")));
  12247. if(json_object_object_get(json_object_array_get_idx(json_object_object_get(SendLocalList, "localAuthorizationList"), idx), "idTagInfo") != NULL)
  12248. {
  12249. 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")));
  12250. if(json_object_object_get(json_object_object_get(json_object_array_get_idx(json_object_object_get(SendLocalList, "localAuthorizationList"), idx), "idTagInfo"), "expiryDate") != NULL)
  12251. 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")));
  12252. if(json_object_object_get(json_object_object_get(json_object_array_get_idx(json_object_object_get(SendLocalList, "localAuthorizationList"), idx), "idTagInfo"), "parentIdTag") != NULL)
  12253. 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")));
  12254. }
  12255. // Add to db
  12256. if(strcmp((char*)ShmOCPP16Data->SendLocalList.UpdateType, UpdateTypeStr[Full]) == 0)
  12257. {
  12258. //Local list full update
  12259. DEBUG_INFO("Local list full update item: %d, listVer: %d, %s, %s, %s, %s.\n",
  12260. idx,
  12261. ShmOCPP16Data->SendLocalList.ListVersion,
  12262. ShmOCPP16Data->SendLocalList.LocalAuthorizationList[0].IdTag,
  12263. ShmOCPP16Data->SendLocalList.LocalAuthorizationList[0].IdTagInfo.ParentIdTag,
  12264. ShmOCPP16Data->SendLocalList.LocalAuthorizationList[0].IdTagInfo.ExpiryDate,
  12265. ShmOCPP16Data->SendLocalList.LocalAuthorizationList[0].IdTagInfo.Status);
  12266. // update list
  12267. OCPP_addLocalList(ShmOCPP16Data->SendLocalList.ListVersion,
  12268. (char*)ShmOCPP16Data->SendLocalList.LocalAuthorizationList[0].IdTag,
  12269. (char*)ShmOCPP16Data->SendLocalList.LocalAuthorizationList[0].IdTagInfo.ParentIdTag,
  12270. (char*)ShmOCPP16Data->SendLocalList.LocalAuthorizationList[0].IdTagInfo.ExpiryDate,
  12271. (char*)ShmOCPP16Data->SendLocalList.LocalAuthorizationList[0].IdTagInfo.Status);
  12272. }
  12273. else if(strcmp((char*)ShmOCPP16Data->SendLocalList.UpdateType, UpdateTypeStr[Differential]) == 0)
  12274. {
  12275. DEBUG_INFO("Local list diff update item: %d,listVer: %d, %s, %s, %s, %s.\n",
  12276. idx,
  12277. ShmOCPP16Data->SendLocalList.ListVersion,
  12278. ShmOCPP16Data->SendLocalList.LocalAuthorizationList[0].IdTag,
  12279. ShmOCPP16Data->SendLocalList.LocalAuthorizationList[0].IdTagInfo.ParentIdTag,
  12280. ShmOCPP16Data->SendLocalList.LocalAuthorizationList[0].IdTagInfo.ExpiryDate,
  12281. ShmOCPP16Data->SendLocalList.LocalAuthorizationList[0].IdTagInfo.Status);
  12282. OCPP_addLocalList(ShmOCPP16Data->SendLocalList.ListVersion,
  12283. (char*)ShmOCPP16Data->SendLocalList.LocalAuthorizationList[0].IdTag,
  12284. (char*)ShmOCPP16Data->SendLocalList.LocalAuthorizationList[0].IdTagInfo.ParentIdTag,
  12285. (char*)ShmOCPP16Data->SendLocalList.LocalAuthorizationList[0].IdTagInfo.ExpiryDate,
  12286. (char*)ShmOCPP16Data->SendLocalList.LocalAuthorizationList[0].IdTagInfo.Status);
  12287. }
  12288. }
  12289. }
  12290. else
  12291. {
  12292. //Check UpdateType
  12293. if(strcmp((char*)ShmOCPP16Data->SendLocalList.UpdateType, UpdateTypeStr[Full]) == 0)
  12294. {
  12295. //Local list full update
  12296. DEBUG_INFO("If no (empty) localAuthorizationList is given and the updateType is Full, all identifications are removed from the list. \n");
  12297. OCPP_cleanLocalList();
  12298. strcpy(comfirmstr, UpdateStatusStr[UpdateStatus_Accepted]);
  12299. goto end;
  12300. }
  12301. if(strcmp((char*)ShmOCPP16Data->SendLocalList.UpdateType, UpdateTypeStr[Differential]) == 0)
  12302. {
  12303. //Local list different update
  12304. DEBUG_INFO("Requesting a Differential update without (empty) localAuthorizationList will have no effect on the list\n");
  12305. strcpy(comfirmstr, UpdateStatusStr[UpdateStatus_Accepted]);
  12306. goto end;
  12307. }
  12308. }
  12309. result = PASS;
  12310. }
  12311. strcpy(comfirmstr, UpdateStatusStr[UpdateStatus_Accepted]);
  12312. end:
  12313. json_object_put(SendLocalList);
  12314. sendSendLocalListConfirmation(uuid, comfirmstr);
  12315. return result;
  12316. }
  12317. int handleSetChargingProfileRequest(char *uuid, char *payload)
  12318. {
  12319. mtrace();
  12320. int result = FAIL;
  12321. struct StructSetChargingProfile SetProfileReq = {0};
  12322. int tempchargingProfileIdInt;
  12323. int tempstackLevelInt;
  12324. int chargingSchedulePeriodCount = 0;
  12325. char comfirmstr[20]={0};
  12326. char tempfile[] = "/Storage/OCPP/SetChargingProfiletemp.json";
  12327. char rmFileCmd[128]={0};
  12328. int profileQuantity = 0;
  12329. int replaceableProfileCnt = 0;
  12330. json_object *SetChargingProfile;
  12331. DEBUG_INFO("handleSetChargingProfileRequest\n");
  12332. SetChargingProfile = json_tokener_parse(payload);
  12333. if(!is_error(SetChargingProfile))
  12334. {
  12335. if(json_object_object_get(SetChargingProfile, "connectorId") != NULL)
  12336. {
  12337. SetProfileReq.ConnectorId = json_object_get_int(json_object_object_get(SetChargingProfile, "connectorId"));
  12338. }
  12339. if(json_object_object_get(SetChargingProfile, "csChargingProfiles") != NULL)
  12340. {
  12341. if(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingProfileId") != NULL)
  12342. {
  12343. SetProfileReq.ChargingProfile.ChargingProfileId = json_object_get_int(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingProfileId"));
  12344. }
  12345. else
  12346. {
  12347. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  12348. DEBUG_WARN("Cannot find chargingProfileId field.");
  12349. goto end;
  12350. }
  12351. if(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "stackLevel") != NULL)
  12352. {
  12353. SetProfileReq.ChargingProfile.StackLevel = json_object_get_int(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "stackLevel"));
  12354. }
  12355. else
  12356. {
  12357. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  12358. DEBUG_WARN("Cannot find stackLevel field.");
  12359. goto end;
  12360. }
  12361. if(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingProfilePurpose") != NULL)
  12362. {
  12363. strcpy((char*)SetProfileReq.ChargingProfile.ChargingProfilePurpose, json_object_get_string(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingProfilePurpose")));
  12364. }
  12365. else
  12366. {
  12367. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  12368. DEBUG_WARN("Cannot find chargingProfilePurpose field.");
  12369. goto end;
  12370. }
  12371. if(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingProfileKind") != NULL)
  12372. {
  12373. strcpy((char*)SetProfileReq.ChargingProfile.ChargingProfileKind, json_object_get_string(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingProfileKind")));
  12374. }
  12375. else
  12376. {
  12377. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  12378. DEBUG_WARN("Cannot find chargingProfileKind field.");
  12379. goto end;
  12380. }
  12381. if(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "transactionId") != NULL)
  12382. {
  12383. SetProfileReq.ChargingProfile.TransactionId = json_object_get_int(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "transactionId"));
  12384. }
  12385. if(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "recurrencyKind") != NULL)
  12386. {
  12387. strcpy((char*)SetProfileReq.ChargingProfile.RecurrencyKind, json_object_get_string(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "recurrencyKind")));
  12388. }
  12389. if(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "validFrom") != NULL)
  12390. {
  12391. strcpy((char*)SetProfileReq.ChargingProfile.ValidFrom, json_object_get_string(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "validFrom")));
  12392. }
  12393. if(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "validTo") != NULL)
  12394. {
  12395. strcpy((char*)SetProfileReq.ChargingProfile.ValidTo, json_object_get_string(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "validTo")));
  12396. }
  12397. if(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingSchedule") != NULL)
  12398. {
  12399. if(json_object_object_get(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingSchedule"), "chargingRateUnit") != NULL)
  12400. {
  12401. 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")));
  12402. }
  12403. else
  12404. {
  12405. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  12406. DEBUG_WARN("Cannot find chargingRateUnit field.");
  12407. goto end;
  12408. }
  12409. if(json_object_object_get(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingSchedule"), "duration") != NULL)
  12410. {
  12411. SetProfileReq.ChargingProfile.ChargingSchedule.Duration = json_object_get_int(json_object_object_get(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingSchedule"), "duration"));
  12412. }
  12413. if(json_object_object_get(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingSchedule"), "minChargingRate") != NULL)
  12414. {
  12415. SetProfileReq.ChargingProfile.ChargingSchedule.MinChargingRate = json_object_get_double(json_object_object_get(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingSchedule"), "minChargingRate"));
  12416. }
  12417. if(json_object_object_get(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingSchedule"), "startSchedule") != NULL)
  12418. {
  12419. 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")));
  12420. }
  12421. if(json_object_object_get(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod") != NULL)
  12422. {
  12423. chargingSchedulePeriodCount = json_object_array_length(json_object_object_get(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"));
  12424. if(chargingSchedulePeriodCount <= 10)
  12425. {
  12426. 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++)
  12427. {
  12428. 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)
  12429. {
  12430. 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"));
  12431. }
  12432. else
  12433. {
  12434. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  12435. DEBUG_WARN("Cannot find startPeriod field.");
  12436. goto end;
  12437. }
  12438. 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)
  12439. {
  12440. 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"));
  12441. }
  12442. else
  12443. {
  12444. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  12445. DEBUG_WARN("Cannot find limit field.");
  12446. goto end;
  12447. }
  12448. 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)
  12449. {
  12450. 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"));
  12451. }
  12452. }
  12453. }
  12454. }
  12455. else
  12456. {
  12457. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  12458. DEBUG_WARN("Cannot find chargingSchedulePeriod field.");
  12459. goto end;
  12460. }
  12461. }
  12462. else
  12463. {
  12464. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  12465. DEBUG_WARN("Cannot find chargingSchedule field.");
  12466. goto end;
  12467. }
  12468. }
  12469. }
  12470. // Profile periods quantity check
  12471. if( chargingSchedulePeriodCount > atoi((const char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemData))
  12472. {
  12473. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  12474. DEBUG_WARN("Profile period is over limit %s. \n", ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemData);
  12475. goto end;
  12476. }
  12477. // Check invalid limit
  12478. if((strcmp((char*)SetProfileReq.ChargingProfile.ChargingProfilePurpose, ChargingProfilePurposeTypeStr[ChargePointMaxProfile]) != 0) ||
  12479. ((strcmp((char*)SetProfileReq.ChargingProfile.ChargingProfilePurpose, ChargingProfilePurposeTypeStr[ChargePointMaxProfile]) == 0) && (ShmSysConfigAndInfo->SysConfig.isEnableLocalPowerSharing != 1)))
  12480. {
  12481. if(ShmSysConfigAndInfo->SysConfig.ModelName[0] == 'A')
  12482. {
  12483. for(uint8_t idxPeriod=0;idxPeriod<chargingSchedulePeriodCount;idxPeriod++)
  12484. {
  12485. 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)))) ||
  12486. (SetProfileReq.ChargingProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit > (SetProfileReq.ChargingProfile.ChargingSchedule.ChargingRateUnit[0]=='W'?modelnameInfo.ratedPower:ShmSysConfigAndInfo->SysConfig.RatingCurrent)))
  12487. {
  12488. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  12489. DEBUG_WARN("Profile period-%02d is invalid limit: %.2f %s with phase %d.\n", idxPeriod,
  12490. SetProfileReq.ChargingProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit,
  12491. SetProfileReq.ChargingProfile.ChargingSchedule.ChargingRateUnit,
  12492. (SetProfileReq.ChargingProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases==0?3:SetProfileReq.ChargingProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases));
  12493. goto end;
  12494. }
  12495. }
  12496. }
  12497. else
  12498. {
  12499. for(uint8_t idxPeriod=0;idxPeriod<chargingSchedulePeriodCount;idxPeriod++)
  12500. {
  12501. if((SetProfileReq.ChargingProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit*(SetProfileReq.ChargingProfile.ChargingSchedule.ChargingRateUnit[0]=='W'?1:220*(SetProfileReq.ChargingProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases==0?3:SetProfileReq.ChargingProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases)) > modelnameInfo.ratedPower) ||
  12502. (SetProfileReq.ChargingProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit*(SetProfileReq.ChargingProfile.ChargingSchedule.ChargingRateUnit[0]=='W'?1:220*(SetProfileReq.ChargingProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases==0?3:SetProfileReq.ChargingProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases)) < (modelnameInfo.ratedPower*0.01)))
  12503. {
  12504. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  12505. DEBUG_WARN("Profile period-%02d is invalid limit: %.2f %s with phase %d.\n", idxPeriod,
  12506. SetProfileReq.ChargingProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit,
  12507. SetProfileReq.ChargingProfile.ChargingSchedule.ChargingRateUnit,
  12508. (SetProfileReq.ChargingProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases==0?3:SetProfileReq.ChargingProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases));
  12509. goto end;
  12510. }
  12511. }
  12512. }
  12513. }
  12514. // Profile purpose info check
  12515. if(strcmp((char*)SetProfileReq.ChargingProfile.ChargingProfilePurpose, ChargingProfilePurposeTypeStr[ChargePointMaxProfile]) == 0)
  12516. {
  12517. FILE *fp;
  12518. DEBUG_INFO("Profile purpose is ChargePointMaxProfile.\n");
  12519. if(SetProfileReq.ConnectorId != 0)
  12520. {
  12521. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  12522. DEBUG_WARN("Profile connector id is not 0.\n");
  12523. goto end;
  12524. }
  12525. fp = fopen(ChargePointMaxProfile_JSON, "r");
  12526. if (!fp)
  12527. {
  12528. DEBUG_INFO("%s does not create.\n", ChargePointMaxProfile_JSON);
  12529. fp = fopen(ChargePointMaxProfile_JSON, "w+");
  12530. }
  12531. else
  12532. {
  12533. char *line = NULL;
  12534. size_t len = 0;
  12535. while(getline(&line, &len, fp) != -1)
  12536. {
  12537. json_object *obj = NULL;
  12538. obj = json_tokener_parse(line);
  12539. if(is_error(obj))
  12540. {
  12541. DEBUG_ERROR("Parse txProfile from file error.\n");
  12542. }
  12543. else
  12544. {
  12545. if((json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileId")) != SetProfileReq.ChargingProfile.ChargingProfileId) &&
  12546. (json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "stackLevel")) != SetProfileReq.ChargingProfile.StackLevel))
  12547. {
  12548. profileQuantity += 1;
  12549. }
  12550. else
  12551. replaceableProfileCnt += 1;
  12552. }
  12553. }
  12554. }
  12555. fclose(fp);
  12556. }
  12557. else if(strcmp((char*)SetProfileReq.ChargingProfile.ChargingProfilePurpose, ChargingProfilePurposeTypeStr[TxDefaultProfile]) == 0)
  12558. {
  12559. FILE *fp;
  12560. char filename[128]={0};
  12561. int tmpProfileQuantity;
  12562. DEBUG_INFO("Profile purpose is TxDefaultProfile.\n");
  12563. if((SetProfileReq.ConnectorId != 0) && (SetProfileReq.ConnectorId > gunTotalNumber))
  12564. {
  12565. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  12566. DEBUG_WARN("Profile connector id is over max gun number.\n");
  12567. goto end;
  12568. }
  12569. if(SetProfileReq.ConnectorId == 0)
  12570. {
  12571. for(int idxCon=1;idxCon<=gunTotalNumber;idxCon++)
  12572. {
  12573. tmpProfileQuantity = 0;
  12574. memset(filename, 0, ARRAY_SIZE(filename));
  12575. sprintf(filename, "/Storage/OCPP/TxDefaultProfile_%d.json", idxCon);
  12576. fp = fopen(filename, "r");
  12577. if (!fp)
  12578. {
  12579. DEBUG_INFO("%s does not create.\n", filename);
  12580. fp = fopen(filename, "w+");
  12581. }
  12582. else
  12583. {
  12584. char *line = NULL;
  12585. size_t len = 0;
  12586. while(getline(&line, &len, fp) != -1)
  12587. {
  12588. json_object *obj = NULL;
  12589. obj = json_tokener_parse(line);
  12590. if(is_error(obj))
  12591. {
  12592. DEBUG_ERROR("Parse txProfile from file error.\n");
  12593. }
  12594. else
  12595. {
  12596. if((json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileId")) != SetProfileReq.ChargingProfile.ChargingProfileId) &&
  12597. (json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "stackLevel")) != SetProfileReq.ChargingProfile.StackLevel))
  12598. {
  12599. tmpProfileQuantity += 1;
  12600. }
  12601. else
  12602. replaceableProfileCnt += 1;
  12603. }
  12604. }
  12605. }
  12606. fclose(fp);
  12607. profileQuantity = (profileQuantity < tmpProfileQuantity) ? tmpProfileQuantity : profileQuantity;
  12608. }
  12609. }
  12610. else
  12611. {
  12612. memset(filename, 0, ARRAY_SIZE(filename));
  12613. sprintf(filename, "/Storage/OCPP/TxDefaultProfile_%d.json", SetProfileReq.ConnectorId);
  12614. fp = fopen(filename, "r");
  12615. if (!fp)
  12616. {
  12617. DEBUG_INFO("%s does not create.\n", filename);
  12618. fp = fopen(filename, "w+");
  12619. }
  12620. else
  12621. {
  12622. char *line = NULL;
  12623. size_t len = 0;
  12624. while(getline(&line, &len, fp) != -1)
  12625. {
  12626. json_object *obj = NULL;
  12627. obj = json_tokener_parse(line);
  12628. if(is_error(obj))
  12629. {
  12630. DEBUG_ERROR("Parse txProfile from file error.\n");
  12631. }
  12632. else
  12633. {
  12634. if((json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileId")) != SetProfileReq.ChargingProfile.ChargingProfileId) &&
  12635. (json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "stackLevel")) != SetProfileReq.ChargingProfile.StackLevel))
  12636. {
  12637. profileQuantity += 1;
  12638. }
  12639. else
  12640. replaceableProfileCnt += 1;
  12641. }
  12642. }
  12643. }
  12644. fclose(fp);
  12645. }
  12646. }
  12647. else if(strcmp((char*)SetProfileReq.ChargingProfile.ChargingProfilePurpose, ChargingProfilePurposeTypeStr[TxProfile]) == 0)
  12648. {
  12649. int isMatchTransactiodId= FALSE;
  12650. FILE *fp;
  12651. char filename[128]={0};
  12652. DEBUG_INFO("Profile purposeStr is TxProfile.\n");
  12653. //---TxProfile SHALL only be set at Charge Point ConnectorId > 0. ---//
  12654. if(SetProfileReq.ConnectorId == 0)
  12655. {
  12656. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  12657. DEBUG_WARN("Profile connector id is 0.\n");
  12658. goto end;
  12659. }
  12660. int tempIndex = 0;
  12661. //check Transaction active
  12662. if(gunType[SetProfileReq.ConnectorId -1] == GUN_TYPE_CHAdeMO)
  12663. {
  12664. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  12665. {
  12666. tempIndex = (((SetProfileReq.ConnectorId -1)==2) ? 1: 0);
  12667. }
  12668. else
  12669. {
  12670. tempIndex = SetProfileReq.ConnectorId -1;
  12671. }
  12672. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  12673. {
  12674. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  12675. {
  12676. if((SYS_MODE_PREPARING <= ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus) && (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus <= SYS_MODE_TERMINATING)) // S_CHARGING
  12677. {
  12678. if(SetProfileReq.ChargingProfile.TransactionId == ShmOCPP16Data->StartTransaction[SetProfileReq.ConnectorId -1].ResponseTransactionId)
  12679. {
  12680. isMatchTransactiodId = TRUE;
  12681. break;
  12682. }
  12683. }
  12684. }
  12685. }
  12686. }
  12687. else if(gunType[SetProfileReq.ConnectorId -1] == GUN_TYPE_CCS)
  12688. {
  12689. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  12690. {
  12691. tempIndex = (((SetProfileReq.ConnectorId -1)==2) ? 1: 0);
  12692. }
  12693. else
  12694. {
  12695. tempIndex = SetProfileReq.ConnectorId -1;
  12696. }
  12697. for (int index = 0; index < CCS_QUANTITY; index++)
  12698. {
  12699. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  12700. {
  12701. if(((SYS_MODE_PREPARING <= ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus) && (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus <= SYS_MODE_TERMINATING)) ||
  12702. ((SYS_MODE_CCS_PRECHARGE_STEP0 <= ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus) && (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus <= SYS_MODE_CCS_PRECHARGE_STEP1))) // S_CHARGING
  12703. {
  12704. if(SetProfileReq.ChargingProfile.TransactionId == ShmOCPP16Data->StartTransaction[SetProfileReq.ConnectorId -1].ResponseTransactionId)
  12705. {
  12706. isMatchTransactiodId = TRUE;
  12707. break;
  12708. }
  12709. }
  12710. }
  12711. }
  12712. }
  12713. else if(gunType[SetProfileReq.ConnectorId -1] == GUN_TYPE_GBT)
  12714. {
  12715. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  12716. {
  12717. tempIndex = (((SetProfileReq.ConnectorId -1)==2) ? 1: 0);
  12718. }
  12719. else
  12720. {
  12721. tempIndex = SetProfileReq.ConnectorId -1;
  12722. }
  12723. for (int index = 0; index < GB_QUANTITY; index++)
  12724. {
  12725. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  12726. {
  12727. if((SYS_MODE_PREPARING <= ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus) && (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus <= SYS_MODE_TERMINATING)) // S_CHARGING
  12728. {
  12729. if(SetProfileReq.ChargingProfile.TransactionId == ShmOCPP16Data->StartTransaction[SetProfileReq.ConnectorId -1].ResponseTransactionId)
  12730. {
  12731. isMatchTransactiodId = TRUE;
  12732. break;
  12733. }
  12734. }
  12735. }
  12736. }
  12737. }
  12738. else if(gunType[SetProfileReq.ConnectorId -1] == GUN_TYPE_DO)
  12739. {
  12740. tempIndex = SetProfileReq.ConnectorId -1;
  12741. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  12742. {
  12743. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  12744. {
  12745. if(((SYS_MODE_PREPARING <= ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus) && (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus <= SYS_MODE_TERMINATING)) ||
  12746. ((SYS_MODE_CCS_PRECHARGE_STEP0 <= ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus) && (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus <= SYS_MODE_CCS_PRECHARGE_STEP1))) // S_CHARGING
  12747. {
  12748. if(SetProfileReq.ChargingProfile.TransactionId == ShmOCPP16Data->StartTransaction[SetProfileReq.ConnectorId -1].ResponseTransactionId)
  12749. {
  12750. isMatchTransactiodId = TRUE;
  12751. break;
  12752. }
  12753. }
  12754. }
  12755. }
  12756. }
  12757. else
  12758. {
  12759. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D') // 'D' means DC
  12760. {
  12761. tempIndex = 2;
  12762. }
  12763. else
  12764. {
  12765. tempIndex = (SetProfileReq.ConnectorId -1);
  12766. }
  12767. for (int index = 0; index < AC_QUANTITY; index++)
  12768. {
  12769. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  12770. {
  12771. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_TERMINATING)) // S_CHARGING
  12772. {
  12773. if(SetProfileReq.ChargingProfile.TransactionId == ShmOCPP16Data->StartTransaction[SetProfileReq.ConnectorId -1].ResponseTransactionId)
  12774. {
  12775. isMatchTransactiodId = TRUE;
  12776. break;
  12777. }
  12778. }
  12779. }
  12780. }
  12781. }
  12782. //check Transaction active
  12783. if(isMatchTransactiodId == FALSE)
  12784. {
  12785. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  12786. DEBUG_WARN("Tx profile transaction id is not match.\n");
  12787. goto end;
  12788. }
  12789. if((SetProfileReq.ConnectorId != 0) && (SetProfileReq.ConnectorId > gunTotalNumber))
  12790. {
  12791. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  12792. DEBUG_WARN("Connector id is over max gun number.\n");
  12793. goto end;
  12794. }
  12795. sprintf(filename, "/Storage/OCPP/TxProfile_%d.json", SetProfileReq.ConnectorId);
  12796. fp = fopen(filename, "r");
  12797. if (!fp)
  12798. {
  12799. DEBUG_INFO("%s does not create.\n", filename);
  12800. fp = fopen(filename, "w+");
  12801. }
  12802. else
  12803. {
  12804. char *line = NULL;
  12805. size_t len = 0;
  12806. while(getline(&line, &len, fp) != -1)
  12807. {
  12808. json_object *obj = NULL;
  12809. obj = json_tokener_parse(line);
  12810. if(is_error(obj))
  12811. {
  12812. DEBUG_ERROR("Parse txProfile from file error.\n");
  12813. }
  12814. else
  12815. {
  12816. if((json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileId")) != SetProfileReq.ChargingProfile.ChargingProfileId) &&
  12817. (json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "stackLevel")) != SetProfileReq.ChargingProfile.StackLevel))
  12818. {
  12819. profileQuantity += 1;
  12820. }
  12821. else
  12822. replaceableProfileCnt += 1;
  12823. }
  12824. }
  12825. }
  12826. fclose(fp);
  12827. }
  12828. // Check ChargeProfileMaxStackLevel
  12829. DEBUG_INFO("%s profile quantity: %d\n", SetProfileReq.ChargingProfile.ChargingProfilePurpose, profileQuantity);
  12830. if(profileQuantity >= atoi((const char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemData))
  12831. {
  12832. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  12833. DEBUG_WARN("Purpose profile quantify is over stack limit %s.\n", ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemData);
  12834. goto end;
  12835. }
  12836. //------------------------------Start: Check Configuration Key "MaxChargingProfilesInstalled" Logic---------------------------------------//
  12837. {
  12838. FILE *fp;
  12839. char dataLine[4096]={0};
  12840. char fnametemp[128]={0};
  12841. int tmpProfileQuantity;
  12842. //Check ChargePointMaxProfile.json exit
  12843. profileQuantity = 0;
  12844. if((access("/Storage/OCPP/ChargePointMaxProfile.json",F_OK))!=-1)
  12845. {
  12846. fp = fopen("/Storage/OCPP/ChargePointMaxProfile.json", "r");
  12847. //Check Charging Profile Count
  12848. tmpProfileQuantity = 0;
  12849. while(fscanf(fp, "%s", dataLine) != EOF)
  12850. {
  12851. if(strstr(dataLine, "chargingProfileId")!= NULL)
  12852. {
  12853. profileQuantity += 1;
  12854. tmpProfileQuantity += 1;
  12855. }
  12856. memset(dataLine, 0, ARRAY_SIZE(dataLine));
  12857. }
  12858. fclose(fp);
  12859. DEBUG_INFO("ChargePointMaxProfile.json has %d charging Profile\n", tmpProfileQuantity);
  12860. }
  12861. //Check TxDefaultProfile_%d.json
  12862. for(int idxCon=1; idxCon <= gunTotalNumber; idxCon++)
  12863. {
  12864. memset(fnametemp, 0, ARRAY_SIZE(fnametemp));
  12865. sprintf(fnametemp, "/Storage/OCPP/TxDefaultProfile_%d.json", idxCon);
  12866. if((access(fnametemp,F_OK))!=-1)
  12867. {
  12868. fp = fopen(fnametemp, "r");
  12869. //Check Charging Profile Count
  12870. tmpProfileQuantity = 0;
  12871. while(fscanf(fp, "%s", dataLine) != EOF)
  12872. {
  12873. //DEBUG_INFO("word=%s\n",word);
  12874. if(strstr(dataLine, "chargingProfileId")!= NULL)
  12875. {
  12876. profileQuantity += 1;
  12877. tmpProfileQuantity += 1;
  12878. }
  12879. memset(dataLine, 0, ARRAY_SIZE(dataLine));
  12880. }
  12881. fclose(fp);
  12882. DEBUG_INFO("%s has %d charging Profile\n",fnametemp, tmpProfileQuantity);
  12883. }
  12884. }
  12885. //Check TxProfile_%d.json
  12886. for(int idxCon=1; idxCon <= gunTotalNumber; idxCon++)
  12887. {
  12888. memset(fnametemp, 0, ARRAY_SIZE(fnametemp));
  12889. sprintf(fnametemp, "/Storage/OCPP/TxProfile_%d.json", idxCon);
  12890. if((access(fnametemp,F_OK))!=-1)
  12891. {
  12892. fp = fopen(fnametemp, "r");
  12893. //Check Charging Profile Count
  12894. tmpProfileQuantity = 0;
  12895. while(fscanf(fp, "%s", dataLine) != EOF)
  12896. {
  12897. if(strstr(dataLine, "chargingProfileId")!= NULL)
  12898. {
  12899. profileQuantity += 1;
  12900. tmpProfileQuantity += 1;
  12901. }
  12902. memset(dataLine, 0, ARRAY_SIZE(dataLine));
  12903. }
  12904. fclose(fp);
  12905. DEBUG_INFO("%s has %d charging Profile\n",fnametemp, tmpProfileQuantity);
  12906. }
  12907. }
  12908. DEBUG_INFO("All purpose profile quantity: %d\n", profileQuantity);
  12909. DEBUG_INFO("Replaceable profile quantity: %d\n", replaceableProfileCnt);
  12910. // To check total Profile quantity
  12911. if((SetProfileReq.ConnectorId > 0) || (strcmp((char*)SetProfileReq.ChargingProfile.ChargingProfilePurpose, ChargingProfilePurposeTypeStr[ChargePointMaxProfile]) == 0))
  12912. {
  12913. if((profileQuantity-replaceableProfileCnt) >= atoi((const char*)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemData))
  12914. {
  12915. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected]);
  12916. DEBUG_WARN("Total profile quantify is over installed limit %s.\n", ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemData);
  12917. goto end;
  12918. }
  12919. }
  12920. else
  12921. {
  12922. if((profileQuantity+gunTotalNumber-replaceableProfileCnt) > atoi((const char*)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemData))
  12923. {
  12924. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected]);
  12925. DEBUG_WARN("Total profile quantify is over installed limit %s.\n", ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemData);
  12926. goto end;
  12927. }
  12928. }
  12929. }
  12930. //------------------------------End: Check Configuration Key "MaxChargingProfilesInstalled" Logic---------------------------------------//
  12931. //**********************************Write to File********************************************************/
  12932. {
  12933. FILE *infile;
  12934. FILE *outfile;
  12935. char dataLine[4096]={0};
  12936. char filename[128]={0};
  12937. int chkChar=0;
  12938. for(int idxCon=1; idxCon <= (SetProfileReq.ConnectorId==0?gunTotalNumber:1); idxCon++)
  12939. {
  12940. if(strcmp((char*)SetProfileReq.ChargingProfile.ChargingProfilePurpose, ChargingProfilePurposeTypeStr[ChargePointMaxProfile]) == 0)
  12941. {
  12942. sprintf(filename, "%s", ChargePointMaxProfile_JSON);
  12943. }
  12944. else if(strcmp((char*)SetProfileReq.ChargingProfile.ChargingProfilePurpose, ChargingProfilePurposeTypeStr[TxDefaultProfile]) == 0)
  12945. {
  12946. if(SetProfileReq.ConnectorId==0)
  12947. sprintf(filename, "/Storage/OCPP/TxDefaultProfile_%d.json", idxCon);
  12948. else
  12949. sprintf(filename, "/Storage/OCPP/TxDefaultProfile_%d.json", SetProfileReq.ConnectorId);
  12950. }
  12951. else
  12952. {
  12953. sprintf(filename, "/Storage/OCPP/TxProfile_%d.json", SetProfileReq.ConnectorId);
  12954. }
  12955. infile = fopen (filename, "r");
  12956. outfile = fopen (tempfile, "w");
  12957. chkChar = fgetc(infile);
  12958. rewind(infile);
  12959. if(chkChar == EOF)
  12960. {
  12961. // Profile is empty
  12962. if((strcmp((char*)SetProfileReq.ChargingProfile.ChargingProfilePurpose, ChargingProfilePurposeTypeStr[TxDefaultProfile]) == 0) && (SetProfileReq.ConnectorId==0))
  12963. json_object_object_add(SetChargingProfile, "connectorId", json_object_new_int(idxCon));
  12964. fprintf(outfile,"%s\n",json_object_to_json_string_ext(SetChargingProfile, JSON_C_TO_STRING_PLAIN));
  12965. fclose(infile);
  12966. fclose(outfile);
  12967. sprintf(rmFileCmd,"rm -f %s",filename);
  12968. system(rmFileCmd);
  12969. rename(tempfile, filename);
  12970. }
  12971. else
  12972. {
  12973. // Profile is not empty
  12974. int ChargingProfileAdded = FALSE;
  12975. while (fgets(dataLine, ARRAY_SIZE(dataLine), infile) != NULL)
  12976. {
  12977. dataLine[strlen(dataLine) - 1] = '\0'; // eat the newline fgets() stores
  12978. json_object *tmpChargingProfile;
  12979. tmpChargingProfile = json_tokener_parse(dataLine);
  12980. if(!is_error(SetChargingProfile))
  12981. {
  12982. if(json_object_object_get(tmpChargingProfile, "csChargingProfiles") != NULL)
  12983. {
  12984. if(json_object_object_get(json_object_object_get(tmpChargingProfile, "csChargingProfiles"), "chargingProfileId") != NULL)
  12985. {
  12986. tempchargingProfileIdInt = json_object_get_int(json_object_object_get(json_object_object_get(tmpChargingProfile, "csChargingProfiles"), "chargingProfileId"));
  12987. }
  12988. if(json_object_object_get(json_object_object_get(tmpChargingProfile, "csChargingProfiles"), "stackLevel") != NULL)
  12989. {
  12990. tempstackLevelInt = json_object_get_int(json_object_object_get(json_object_object_get(tmpChargingProfile, "csChargingProfiles"), "stackLevel"));
  12991. }
  12992. }
  12993. }
  12994. json_object_put(tmpChargingProfile);
  12995. if((tempchargingProfileIdInt == SetProfileReq.ChargingProfile.ChargingProfileId))
  12996. {
  12997. if(ChargingProfileAdded == FALSE)
  12998. {
  12999. if((strcmp((char*)SetProfileReq.ChargingProfile.ChargingProfilePurpose, ChargingProfilePurposeTypeStr[TxDefaultProfile]) == 0) && (SetProfileReq.ConnectorId==0))
  13000. json_object_object_add(SetChargingProfile, "connectorId", json_object_new_int(idxCon));
  13001. fprintf(outfile,"%s\n",json_object_to_json_string_ext(SetChargingProfile, JSON_C_TO_STRING_PLAIN));
  13002. ChargingProfileAdded = TRUE;
  13003. }
  13004. }
  13005. else if(tempstackLevelInt == SetProfileReq.ChargingProfile.StackLevel)
  13006. {
  13007. if(ChargingProfileAdded == FALSE)
  13008. {
  13009. if((strcmp((char*)SetProfileReq.ChargingProfile.ChargingProfilePurpose, ChargingProfilePurposeTypeStr[TxDefaultProfile]) == 0) && (SetProfileReq.ConnectorId==0))
  13010. json_object_object_add(SetChargingProfile, "connectorId", json_object_new_int(idxCon));
  13011. fprintf(outfile,"%s\n",json_object_to_json_string_ext(SetChargingProfile, JSON_C_TO_STRING_PLAIN));
  13012. ChargingProfileAdded = TRUE;
  13013. }
  13014. }
  13015. else
  13016. {
  13017. fprintf(outfile,"%s\n",dataLine);
  13018. if(ChargingProfileAdded == FALSE)
  13019. {
  13020. if((strcmp((char*)SetProfileReq.ChargingProfile.ChargingProfilePurpose, ChargingProfilePurposeTypeStr[TxDefaultProfile]) == 0) && (SetProfileReq.ConnectorId==0))
  13021. json_object_object_add(SetChargingProfile, "connectorId", json_object_new_int(idxCon));
  13022. fprintf(outfile,"%s\n",json_object_to_json_string_ext(SetChargingProfile, JSON_C_TO_STRING_PLAIN));
  13023. ChargingProfileAdded = TRUE;
  13024. }
  13025. }
  13026. } // end of while loop
  13027. fclose(infile);
  13028. fclose(outfile);
  13029. sprintf(rmFileCmd,"rm -f %s",filename);
  13030. system(rmFileCmd);
  13031. rename(tempfile, filename);
  13032. }
  13033. }
  13034. sleep(1);
  13035. result = TRUE;
  13036. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Accepted] );
  13037. }
  13038. end:
  13039. json_object_put(SetChargingProfile);
  13040. if(strcmp(comfirmstr, ChargingProfileStatusStr[ChargingProfileStatus_Accepted]) == 0)
  13041. {
  13042. if(SetProfileReq.ConnectorId == 0)
  13043. {
  13044. for(uint8_t idx=0;idx<gunTotalNumber;idx++)
  13045. {
  13046. checkCompositeSchedule((idx+1), 86400, &ShmOCPP16Data->SmartChargingProfile[idx], TRUE);
  13047. }
  13048. }
  13049. else
  13050. checkCompositeSchedule(SetProfileReq.ConnectorId, 86400, &ShmOCPP16Data->SmartChargingProfile[SetProfileReq.ConnectorId-1], TRUE);
  13051. }
  13052. sendSetChargingProfileConfirmation(uuid, comfirmstr);
  13053. system("/bin/fsync -d /dev/mtdblock13;/bin/sync &");
  13054. return result;
  13055. }
  13056. int handleTriggerMessageRequest(char *uuid, char *payload)
  13057. {
  13058. mtrace();
  13059. int result = FAIL;
  13060. int connectorIdIsNULL = FALSE;
  13061. int connectorIdInt =0;
  13062. char sstr[40]={0},sstrtemp[100]={ 0 };
  13063. char requestedMessagestr[40]={0};
  13064. char comfirmstr[20]={0};
  13065. int c = 0;
  13066. char *loc;
  13067. DEBUG_INFO("handleTriggerMessageRequest\n");
  13068. //[2,"266e23f4-27a4-41cf-84cb-aadf56b9523f","TriggerMessage",{"requestedMessage":"DiagnosticsStatusNotification","connectorId":1}]
  13069. strcpy(sstrtemp, stringtrimspace(payload));
  13070. c = 0;
  13071. loc = strstr(sstrtemp, "requestedMessage");
  13072. while (loc[3+strlen("requestedMessage")+c] != '\"')
  13073. {
  13074. sstr[c] = loc[3+strlen("requestedMessage")+c];
  13075. c++;
  13076. }
  13077. sstr[c] = '\0';
  13078. strcpy(requestedMessagestr, sstr);
  13079. c = 0;
  13080. loc = strstr(sstrtemp, "connectorId");
  13081. if(loc == NULL)
  13082. {
  13083. connectorIdIsNULL = TRUE;
  13084. }
  13085. else
  13086. {
  13087. memset(sstr ,0, ARRAY_SIZE(sstr) );
  13088. while ((loc[strlen("connectorId")+2+c] != ',')&&(loc[strlen("connectorId")+2+c] != '}'))
  13089. {
  13090. sstr[c] = loc[strlen("connectorId")+2+c];
  13091. //printf("i=%d sstr=%c\n",c, sstr[c]);
  13092. c++;
  13093. }
  13094. sstr[c] = '\0';
  13095. connectorIdInt = atoi(sstr);
  13096. }
  13097. if((connectorIdIsNULL == TRUE) || ((connectorIdIsNULL == FALSE) && ((connectorIdInt > 0) && (connectorIdInt <= gunTotalNumber /*(CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY)*/ ))) )
  13098. {
  13099. sprintf((char *)ShmOCPP16Data->TriggerMessage[connectorIdInt -1].RequestedMessage, "%s" ,requestedMessagestr);
  13100. ShmOCPP16Data->TriggerMessage[connectorIdInt -1].ConnectorId = connectorIdInt;
  13101. if((strcmp(requestedMessagestr, MessageTriggerStr[FirmwareStatusNotification]) != 0) &&
  13102. (strcmp(requestedMessagestr, MessageTriggerStr[DiagnosticsStatusNotification]) != 0) &&
  13103. (strcmp(requestedMessagestr, MessageTriggerStr[BootNotification]) != 0 ) &&
  13104. (strcmp(requestedMessagestr, MessageTriggerStr[Heartbeat]) != 0) &&
  13105. (strcmp(requestedMessagestr, MessageTriggerStr[MeterValues]) != 0) &&
  13106. (strcmp(requestedMessagestr, MessageTriggerStr[StatusNotification]) != 0 ))
  13107. {
  13108. sprintf(comfirmstr, "%s",TriggerMessageStatusStr[TriggerMessageStatus_NotImplemented] );
  13109. sendTriggerMessageConfirmation(uuid,comfirmstr);
  13110. return TRUE;
  13111. }
  13112. else
  13113. {
  13114. sprintf(comfirmstr, "%s",TriggerMessageStatusStr[TriggerMessageStatus_Accepted] );
  13115. sendTriggerMessageConfirmation(uuid,comfirmstr);
  13116. }
  13117. }
  13118. else if(connectorIdIsNULL == FALSE && ((connectorIdInt <= 0) || (connectorIdInt > gunTotalNumber /*(CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY)*/) ))
  13119. {
  13120. sprintf(comfirmstr, "%s",TriggerMessageStatusStr[TriggerMessageStatus_Rejected] );
  13121. sendTriggerMessageConfirmation(uuid,comfirmstr);
  13122. return TRUE;
  13123. }
  13124. //==========================
  13125. // Trigger message
  13126. //==========================
  13127. if( strcmp(requestedMessagestr, MessageTriggerStr[FirmwareStatusNotification]) == 0)
  13128. {
  13129. if((strlen((char*)ShmOCPP16Data->FirmwareStatusNotification.Status) == 0) ||
  13130. ((FirmwareStatusNotificationStatus != FIRMWARE_STATUS_DOWNLOADING) && (FirmwareStatusNotificationStatus != FIRMWARE_STATUS_DOWNLOADED) && (FirmwareStatusNotificationStatus != FIRMWARE_STATUS_IDLE) && (FirmwareStatusNotificationStatus != FIRMWARE_STATUS_INSTALLING)))
  13131. {
  13132. FirmwareStatusNotificationStatus = FIRMWARE_STATUS_IDLE;
  13133. sprintf((char*)ShmOCPP16Data->FirmwareStatusNotification.Status, "%s", FirmwareStatusStr[FirmwareStatus_Idle]);
  13134. }
  13135. ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationReq = 1;
  13136. }
  13137. else if(strcmp(requestedMessagestr, MessageTriggerStr[DiagnosticsStatusNotification]) == 0 )
  13138. {
  13139. if(strlen((char*)ShmOCPP16Data->DiagnosticsStatusNotification.Status) == 0)
  13140. sprintf((char*)ShmOCPP16Data->DiagnosticsStatusNotification.Status, "%s", DiagnosticsStatusStr[DiagnosticsStatus_Idle]);
  13141. ShmOCPP16Data->SpMsg.bits.DiagnosticsStatusNotificationReq = 1;
  13142. }
  13143. else if(strcmp(requestedMessagestr, MessageTriggerStr[BootNotification]) == 0 )
  13144. {
  13145. //sendBootNotificationRequest();
  13146. server_sign = FALSE;
  13147. }
  13148. else if(strcmp(requestedMessagestr, MessageTriggerStr[Heartbeat]) == 0 )
  13149. {
  13150. refreshStartTimer(&clientTime.Heartbeat);
  13151. clientTime.Heartbeat.tv_sec -= ShmOCPP16Data->BootNotification.ResponseHeartbeatInterval;
  13152. }
  13153. else if (strcmp(requestedMessagestr, MessageTriggerStr[MeterValues]) == 0 )
  13154. {
  13155. if(connectorIdIsNULL == FALSE)
  13156. {
  13157. if((connectorIdInt > 0) && ((connectorIdInt -1) < gunTotalNumber))
  13158. {
  13159. //sendMeterValuesRequest((connectorIdInt -1), ReadingContext_Trigger);
  13160. cpinitateMsg.bits[connectorIdInt -1].TriggerMeterValue = 1;
  13161. }
  13162. }
  13163. else
  13164. {
  13165. for(int idx=0;idx< gunTotalNumber;idx++)
  13166. {
  13167. //sendMeterValuesRequest(idx, ReadingContext_Trigger);
  13168. cpinitateMsg.bits[idx].TriggerMeterValue = 1;
  13169. }
  13170. }
  13171. }
  13172. else if(strcmp(requestedMessagestr, MessageTriggerStr[StatusNotification]) == 0 )
  13173. {
  13174. if(connectorIdIsNULL == FALSE)
  13175. {
  13176. if((connectorIdInt > 0) && ((connectorIdInt-1) < gunTotalNumber))
  13177. {
  13178. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].TriggerMessageReq = 1;
  13179. cpinitateMsg.bits[connectorIdInt-1].TriggerStatusNotificationReq = 1;
  13180. //clientTime.StatusNotification[connectorIdInt-1] = time((time_t*)NULL);
  13181. }
  13182. }
  13183. else
  13184. {
  13185. for(int idx=0;idx< gunTotalNumber;idx++)
  13186. {
  13187. ShmOCPP16Data->CsMsg.bits[idx].TriggerMessageReq = 1;
  13188. cpinitateMsg.bits[idx].TriggerStatusNotificationReq = 1;
  13189. //clientTime.StatusNotification[idx] = time((time_t*)NULL);
  13190. }
  13191. }
  13192. }
  13193. return result;
  13194. }
  13195. int handleUnlockConnectorRequest(char *uuid, char *payload)
  13196. {
  13197. mtrace();
  13198. int result = FAIL;
  13199. int connectorIdInt =0;
  13200. char comfirmstr[20]={0};
  13201. int tempIndex = 0;
  13202. json_object *UnlockConnector;
  13203. //[2,"ba1cbd49-2a76-493a-8f76-fa23e7606532","UnlockConnector",{"connectorId":1}]
  13204. DEBUG_INFO("handleUnlockConnectorRequest ...\n");
  13205. UnlockConnector = json_tokener_parse(payload);
  13206. if(!is_error(UnlockConnector))
  13207. {
  13208. if(json_object_object_get(UnlockConnector, "connectorId") != NULL)
  13209. {
  13210. connectorIdInt = json_object_get_int(json_object_object_get(UnlockConnector, "connectorId"));
  13211. }
  13212. }
  13213. json_object_put(UnlockConnector);
  13214. DEBUG_INFO("Unlock connectorIdInt = %d\n",connectorIdInt);
  13215. if(gunTotalNumber == 0)
  13216. {
  13217. sprintf(comfirmstr, "%s", UnlockStatusStr[UnlockStatus_NotSupported] );
  13218. goto end;
  13219. }
  13220. else if((connectorIdInt > gunTotalNumber/*CHAdeMO_QUANTITY+ CCS_QUANTITY + GB_QUANTITY*/) || (connectorIdInt <= 0))
  13221. {
  13222. //sprintf(comfirmstr, "%s", UnlockStatusStr[UnlockStatus_NotSupported] );
  13223. sprintf(comfirmstr, "%s", UnlockStatusStr[UnlockStatus_NotSupported] );
  13224. goto end;
  13225. }
  13226. else
  13227. {
  13228. //check Transaction active
  13229. if(gunType[connectorIdInt-1] == GUN_TYPE_CHAdeMO)
  13230. {
  13231. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  13232. {
  13233. tempIndex = (((connectorIdInt -1)==2) ? 1: 0);
  13234. }
  13235. else
  13236. {
  13237. tempIndex = connectorIdInt -1;
  13238. }
  13239. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  13240. {
  13241. if ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex ))
  13242. {
  13243. //stop Transaction
  13244. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].UnlockConnectorReq = 1;
  13245. }
  13246. }
  13247. }
  13248. else if(gunType[connectorIdInt-1] == GUN_TYPE_CCS)
  13249. {
  13250. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  13251. {
  13252. tempIndex = (((connectorIdInt -1)==2) ? 1: 0);
  13253. }
  13254. else
  13255. {
  13256. tempIndex = connectorIdInt -1;
  13257. }
  13258. for (int index = 0; index < CCS_QUANTITY; index++)
  13259. {
  13260. if ((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex ))
  13261. {
  13262. //stop Transaction
  13263. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].UnlockConnectorReq = 1;
  13264. }
  13265. }
  13266. }
  13267. else if(gunType[connectorIdInt-1] == GUN_TYPE_GBT)
  13268. {
  13269. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  13270. {
  13271. tempIndex = (((connectorIdInt -1)==2) ? 1: 0);
  13272. }
  13273. else
  13274. {
  13275. tempIndex = connectorIdInt -1;
  13276. }
  13277. for (int index = 0; index < GB_QUANTITY; index++)
  13278. {
  13279. if ((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex ))
  13280. {
  13281. //stop Transaction
  13282. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].UnlockConnectorReq = 1;
  13283. }
  13284. }
  13285. }
  13286. else if(gunType[connectorIdInt-1] == GUN_TYPE_DO)
  13287. {
  13288. tempIndex = connectorIdInt -1;
  13289. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  13290. {
  13291. if ((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex ))
  13292. {
  13293. //stop Transaction
  13294. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].UnlockConnectorReq = 1;
  13295. }
  13296. }
  13297. }
  13298. else
  13299. {
  13300. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  13301. {
  13302. tempIndex = 2;
  13303. }
  13304. else
  13305. {
  13306. tempIndex = connectorIdInt-1;
  13307. }
  13308. for (int index = 0; index < AC_QUANTITY; index++)
  13309. {
  13310. if ((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex ))
  13311. {
  13312. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].UnlockConnectorReq = 1;
  13313. }
  13314. }
  13315. }
  13316. ShmOCPP16Data->UnlockConnector[connectorIdInt-1].ConnectorId = connectorIdInt;
  13317. strcpy((char *)ShmOCPP16Data->UnlockConnector[connectorIdInt-1].guid, uuid);
  13318. result = TRUE;
  13319. return result;
  13320. }
  13321. end:
  13322. //json_object_put(obj); --- remove temporally
  13323. sendUnlockConnectorConfirmation(uuid, comfirmstr);
  13324. return result;
  13325. }
  13326. int handleUpdateFirmwareRequest(char *uuid, char *payload)
  13327. {
  13328. mtrace();
  13329. int result = FAIL;
  13330. pthread_t t;
  13331. DEBUG_INFO("handleUpdateFirmwareRequest ...\n");
  13332. sendUpdateFirmwareConfirmation(uuid);
  13333. if(!interLock.isUpdateFirmwareGoing)
  13334. {
  13335. interLock.isUpdateFirmwareGoing = 1;
  13336. pthread_create(&t, NULL, UpdateFirmwareProcess, payload);
  13337. sleep(1);
  13338. }
  13339. else
  13340. DEBUG_WARN("Other UpdateFirmware request on going.\n");
  13341. ShmOCPP16Data->MsMsg.bits.UpdateFirmwareConf =1;
  13342. return result;
  13343. }
  13344. void *UpdateFirmwareProcess(void *data)
  13345. {
  13346. pthread_detach(pthread_self());
  13347. mtrace();
  13348. int retriesInt =0, retryIntervalInt=0;
  13349. char protocol[10], user[64],password[64],host[128], path[512], ftppath[512],host1[128],path1[512];
  13350. int port=0;
  13351. char locationstr[1024]={0}, retrieveDatestr[36]={0};
  13352. int isSuccess = 0;
  13353. char ftpbuf[1024];
  13354. char temp[1024];
  13355. char * pch;
  13356. json_object *UpdateFirmware;
  13357. UpdateFirmware = json_tokener_parse(data);
  13358. if(!is_error(UpdateFirmware))
  13359. {
  13360. // Required data
  13361. if(json_object_object_get(UpdateFirmware, "location") != NULL)
  13362. sprintf((char*)locationstr, "%s", json_object_get_string(json_object_object_get(UpdateFirmware, "location")));
  13363. if(json_object_object_get(UpdateFirmware, "retrieveDate") != NULL)
  13364. sprintf((char*)retrieveDatestr, "%s", json_object_get_string(json_object_object_get(UpdateFirmware, "retrieveDate")));
  13365. // Optional data
  13366. if(json_object_object_get(UpdateFirmware, "retries"))
  13367. {
  13368. retriesInt = json_object_get_int(json_object_object_get(UpdateFirmware, "retries"));
  13369. }
  13370. if(json_object_object_get(UpdateFirmware, "retryInterval"))
  13371. {
  13372. retryIntervalInt = json_object_get_int(json_object_object_get(UpdateFirmware, "retryInterval"));
  13373. }
  13374. }
  13375. json_object_put(UpdateFirmware);
  13376. memset(ftppath, 0, ARRAY_SIZE(ftppath));
  13377. memset(path, 0, ARRAY_SIZE(path));
  13378. // Wait retrieveData
  13379. if(strlen(retrieveDatestr) > 10)
  13380. {
  13381. do
  13382. {
  13383. sleep(1);
  13384. }while(!isOvertNow((uint8_t*)retrieveDatestr));
  13385. }
  13386. // Ready to download
  13387. system("rm -f /mnt/*");
  13388. if(strncmp(locationstr,"http", 4) == 0)
  13389. {
  13390. sscanf(locationstr,"%[^:]:%*2[/]%[^/]/%199[^\n]", protocol, host, path);
  13391. sprintf(ftppath,"/%s", path);
  13392. DEBUG_INFO("locationstr: %s\n", locationstr);
  13393. DEBUG_INFO("protocol: %s\n",protocol);
  13394. DEBUG_INFO("host: %s\n",host);
  13395. DEBUG_INFO("path: %s\n",path);
  13396. DEBUG_INFO("ftppath: %s\n",ftppath);
  13397. int ftppathlen=strlen(ftppath);
  13398. int i=1;
  13399. char filenametemp[50];
  13400. while(i < ftppathlen)
  13401. {
  13402. int len=ftppathlen-i;
  13403. if(ftppath[len]== 47) // '/' ascll code: 47
  13404. {
  13405. DEBUG_INFO("compare '/' all right\n");
  13406. break;
  13407. }
  13408. i=i+1;
  13409. }
  13410. memset(filenametemp, 0, ARRAY_SIZE(filenametemp));
  13411. strncpy(filenametemp, ftppath+(ftppathlen-i+1), i+1);
  13412. filenametemp[i+1] = 0;
  13413. do
  13414. {
  13415. sleep(1);
  13416. sprintf((char*)ShmOCPP16Data->FirmwareStatusNotification.Status, "%s",FirmwareStatusStr[FirmwareStatus_Downloading]);
  13417. ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationReq = 1;
  13418. sleep(1);
  13419. isSuccess = httpDownLoadFile(host, ftppath, filenametemp, locationstr);
  13420. if(!isSuccess)
  13421. {
  13422. sleep(1);
  13423. sprintf((char*)ShmOCPP16Data->FirmwareStatusNotification.Status, "%s",FirmwareStatusStr[FirmwareStatus_DownloadFailed]);
  13424. ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationReq = 1;
  13425. if(retriesInt>0)sleep(retryIntervalInt);else sleep(3);
  13426. sprintf((char*)ShmOCPP16Data->FirmwareStatusNotification.Status, "%s",FirmwareStatusStr[FirmwareStatus_Idle]);
  13427. ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationReq = 1;
  13428. }
  13429. else
  13430. {
  13431. sprintf((char*)ShmOCPP16Data->FirmwareStatusNotification.Status, "%s",FirmwareStatusStr[FirmwareStatus_Downloaded]);
  13432. ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationReq = 1;
  13433. }
  13434. retriesInt--;
  13435. }while((isSuccess == 0)&&(retriesInt >= 0));
  13436. }
  13437. else if(strncmp(locationstr,"sftp", 4) == 0) // sftp
  13438. {
  13439. memset(ftpbuf, 0, ARRAY_SIZE(ftpbuf));
  13440. memset(temp, 0, ARRAY_SIZE(temp));
  13441. //DEBUG_INFO("locationstr=%s\n",locationstr);
  13442. strcpy(ftpbuf, locationstr);
  13443. int ftppathlen=strlen(ftpbuf);
  13444. int i=1;
  13445. char filenametemp[50];
  13446. while(i < ftppathlen)
  13447. {
  13448. int len=ftppathlen-i;
  13449. if(ftpbuf[len]== 47) // '/' ascii code: 47
  13450. {
  13451. DEBUG_INFO(" compare '/' all right\n");
  13452. break;
  13453. }
  13454. i=i+1;
  13455. }
  13456. memset(filenametemp, 0, ARRAY_SIZE(filenametemp));
  13457. strncpy(filenametemp, ftpbuf+(ftppathlen-i+1), i+1);
  13458. filenametemp[i+1] = 0;
  13459. strncpy(temp, ftpbuf, ftppathlen-i+1);
  13460. pch=strchr(temp,'@');
  13461. if(pch==NULL)
  13462. {
  13463. sscanf(temp,"%[^:]:%*2[/]%[^:]:%i/%[a-zA-Z0-9._/-]",
  13464. protocol, host, &port, path);
  13465. strcpy(user,"anonymous");
  13466. strcpy(password,"");
  13467. }
  13468. else
  13469. {
  13470. sscanf(temp,"%[^:]:%*2[/]%[^@]@%[^:]:%i/%199[^\n]",
  13471. protocol, user, host, &port, path);
  13472. }
  13473. sscanf(host,"%[^/]%s",host1, path1);
  13474. sprintf(ftppath,"%s:/%s", host,path);
  13475. if(port == 0)
  13476. {
  13477. port = 21;
  13478. }
  13479. do
  13480. {
  13481. sleep(1);
  13482. sprintf((char*)ShmOCPP16Data->FirmwareStatusNotification.Status, "%s",FirmwareStatusStr[FirmwareStatus_Downloading]);
  13483. ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationReq = 1;
  13484. sleep(1);
  13485. isSuccess = sftpDownLoadFile(host1, user, port, ftppath, filenametemp, locationstr);
  13486. if(!isSuccess)
  13487. {
  13488. //BulldogUtil.sleepMs(interval*1000);
  13489. DEBUG_INFO("Update firmware request and download file fail.\n");
  13490. sprintf((char*)ShmOCPP16Data->FirmwareStatusNotification.Status, "%s",FirmwareStatusStr[FirmwareStatus_DownloadFailed]);
  13491. ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationReq = 1;
  13492. if(retriesInt>0)sleep(retryIntervalInt);else sleep(3);
  13493. sprintf((char*)ShmOCPP16Data->FirmwareStatusNotification.Status, "%s",FirmwareStatusStr[FirmwareStatus_Idle]);
  13494. ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationReq = 1;
  13495. }
  13496. else
  13497. {
  13498. sprintf((char*)ShmOCPP16Data->FirmwareStatusNotification.Status, "%s",FirmwareStatusStr[FirmwareStatus_Downloaded]);
  13499. ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationReq = 1;
  13500. }
  13501. retriesInt--;
  13502. }while((!isSuccess)&&(retriesInt >= 0));
  13503. }
  13504. else if(strncmp(locationstr,"ftp", 3) == 0) // ftp
  13505. {
  13506. memset(ftpbuf, 0, ARRAY_SIZE(ftpbuf));
  13507. memset(temp, 0, ARRAY_SIZE(temp));
  13508. //DEBUG_INFO("locationstr=%s\n",locationstr);
  13509. strcpy(ftpbuf, locationstr/*"ftp://ipc_ui:pht2016@ftp.phihong.com.tw/DC/log/DemoDC1_2018-07-13_185011_PSULog.zip"*/ );
  13510. int ftppathlen=strlen(ftpbuf);
  13511. int i=1;
  13512. char filenametemp[50];
  13513. while(i < ftppathlen)
  13514. {
  13515. int len=ftppathlen-i;
  13516. if(ftpbuf[len]== 47) // '/' ascll code: 47
  13517. {
  13518. DEBUG_INFO(" compare '/' all right\n");
  13519. break;
  13520. }
  13521. i=i+1;
  13522. }
  13523. memset(filenametemp, 0, ARRAY_SIZE(filenametemp));
  13524. strncpy(filenametemp, ftpbuf+(ftppathlen-i+1), i+1);
  13525. filenametemp[i+1] = 0;
  13526. strncpy(temp, ftpbuf, ftppathlen-i+1);
  13527. pch=strchr(temp,'@');
  13528. if(pch==NULL)
  13529. {
  13530. sscanf(temp,"%[^:]:%*2[/]%[^:]:%i/%[a-zA-Z0-9._/-]",
  13531. protocol, host, &port, path);
  13532. strcpy(user,"anonymous");
  13533. strcpy(password,"");
  13534. }
  13535. else
  13536. {
  13537. sscanf(temp,"%[^:]:%*2[/]%[^:]:%[^@]@%[^:]:%i/%199[^\n]",
  13538. protocol, user, password, host, &port, path);
  13539. }
  13540. sscanf(host,"%[^/]%s",host1, path1);
  13541. sprintf(ftppath,"%s", path1);
  13542. //DEBUG_INFO("protocol =%s\n",protocol);
  13543. //DEBUG_INFO("user =%s\n",user);
  13544. //DEBUG_INFO("password =%s\n",password);
  13545. //DEBUG_INFO("host1 =%s\n",host1);
  13546. //DEBUG_INFO("port =%d\n",port);
  13547. //DEBUG_INFO("path1 =%s\n",path1);
  13548. //DEBUG_INFO("ftppath=%s\n",ftppath);
  13549. //ftpFile(host, user, password, port, ftppath, fname);
  13550. //download firmware pthred
  13551. if(port == 0)
  13552. {
  13553. port = 21;
  13554. }
  13555. do
  13556. {
  13557. sleep(1);
  13558. sprintf((char*)ShmOCPP16Data->FirmwareStatusNotification.Status, "%s",FirmwareStatusStr[FirmwareStatus_Downloading]);
  13559. ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationReq = 1;
  13560. sleep(1);
  13561. isSuccess = ftpDownLoadFile(host1, user, password, port, ftppath, filenametemp, locationstr);
  13562. if(!isSuccess)
  13563. {
  13564. //BulldogUtil.sleepMs(interval*1000);
  13565. DEBUG_INFO("Update firmware request and download file fail.\n");
  13566. sprintf((char*)ShmOCPP16Data->FirmwareStatusNotification.Status, "%s",FirmwareStatusStr[FirmwareStatus_DownloadFailed]);
  13567. ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationReq = 1;
  13568. if(retriesInt>0)sleep(retryIntervalInt);else sleep(3);
  13569. sprintf((char*)ShmOCPP16Data->FirmwareStatusNotification.Status, "%s",FirmwareStatusStr[FirmwareStatus_Idle]);
  13570. ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationReq = 1;
  13571. }
  13572. else
  13573. {
  13574. sprintf((char*)ShmOCPP16Data->FirmwareStatusNotification.Status, "%s",FirmwareStatusStr[FirmwareStatus_Downloaded]);
  13575. ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationReq = 1;
  13576. }
  13577. retriesInt--;
  13578. }while((!isSuccess)&&(retriesInt >= 0));
  13579. }
  13580. else
  13581. {
  13582. sprintf((char*)ShmOCPP16Data->FirmwareStatusNotification.Status, "%s",FirmwareStatusStr[FirmwareStatus_DownloadFailed]);
  13583. ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationReq = 1;
  13584. sleep(1);
  13585. sprintf((char*)ShmOCPP16Data->FirmwareStatusNotification.Status, "%s",FirmwareStatusStr[FirmwareStatus_Idle]);
  13586. ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationReq = 1;
  13587. }
  13588. if(strstr((char*)ShmOCPP16Data->FirmwareStatusNotification.Status, FirmwareStatusStr[FirmwareStatus_Downloaded]) != NULL)
  13589. {
  13590. sleep(3);
  13591. ShmOCPP16Data->MsMsg.bits.UpdateFirmwareReq = 1;
  13592. }
  13593. interLock.isUpdateFirmwareGoing = 0;
  13594. pthread_exit(NULL);
  13595. }
  13596. int handleCertificateSignedRequest(char *uuid, char *payload)
  13597. {
  13598. mtrace();
  13599. int result = PASS;
  13600. json_object *CertificateSigned;
  13601. DEBUG_INFO("handleCertificateSignedRequest...\n");
  13602. CertificateSigned = json_tokener_parse(payload);
  13603. if(!is_error(CertificateSigned))
  13604. {
  13605. sprintf((char*)ShmOCPP16Data->CertificateSigned.certificateChain, "%s", json_object_get_string(json_object_object_get(CertificateSigned, "certificateChain")));
  13606. }
  13607. json_object_put(CertificateSigned);
  13608. FILE *fp = fopen("/Storage/OCPP/certCP.crt", "w");
  13609. fprintf(fp, "%s", ShmOCPP16Data->CertificateSigned.certificateChain);
  13610. fclose(fp);
  13611. system("/bin/fsync -d /dev/mtdblock13;/bin/sync &");
  13612. ShmOCPP16Data->MsMsg.bits.CertificateSignedReq = 1;
  13613. if(certVerify("/Storage/OCPP/certCP.key", "/Storage/OCPP/certCP.crt") == PASS)
  13614. sprintf((char*)ShmOCPP16Data->CertificateSigned.Response_status, "Accepted");
  13615. else
  13616. {
  13617. sprintf((char*)ShmOCPP16Data->CertificateSigned.Response_status, "Rejected");
  13618. sprintf((char*)ShmOCPP16Data->SecurityEventNotification.type, "InvalidChargePointCertificate");
  13619. memset(ShmOCPP16Data->SecurityEventNotification.techInfo, 0x00, ARRAY_SIZE(ShmOCPP16Data->SecurityEventNotification.techInfo));
  13620. ShmOCPP16Data->SpMsg.bits.SecurityEventNotificationReq = 1;
  13621. }
  13622. sendCertificateSignedConfirmation(uuid);
  13623. return result;
  13624. }
  13625. int handleDeleteCertificateRequest(char *uuid, char *payload)
  13626. {
  13627. mtrace();
  13628. int result = PASS;
  13629. json_object *DeleteCertificate;
  13630. DEBUG_INFO("handleDeleteCertificateRequest...\n");
  13631. DeleteCertificate = json_tokener_parse(payload);
  13632. if(!is_error(DeleteCertificate))
  13633. {
  13634. sprintf((char*)ShmOCPP16Data->DeleteCertificate.certificateHashData.hashAlgorithm, "%s", json_object_get_string(json_object_object_get(json_object_object_get(DeleteCertificate, "certificateHashData"), "hashAlgorithm")));
  13635. sprintf((char*)ShmOCPP16Data->DeleteCertificate.certificateHashData.issuerNameHash, "%s", json_object_get_string(json_object_object_get(json_object_object_get(DeleteCertificate, "certificateHashData"), "issuerNameHash")));
  13636. sprintf((char*)ShmOCPP16Data->DeleteCertificate.certificateHashData.issuerKeyHash, "%s", json_object_get_string(json_object_object_get(json_object_object_get(DeleteCertificate, "certificateHashData"), "issuerKeyHash")));
  13637. sprintf((char*)ShmOCPP16Data->DeleteCertificate.certificateHashData.serialNumber, "%s", json_object_get_string(json_object_object_get(json_object_object_get(DeleteCertificate, "certificateHashData"), "serialNumber")));
  13638. }
  13639. json_object_put(DeleteCertificate);
  13640. /*
  13641. * TODO: Delete certificateSigned process
  13642. */
  13643. ShmOCPP16Data->MsMsg.bits.DeleteCertificateReq = 1;
  13644. DEBUG_INFO("hashAlgorithm: %s\n", ShmOCPP16Data->DeleteCertificate.certificateHashData.hashAlgorithm);
  13645. DEBUG_INFO("issuerNameHash: %s\n", ShmOCPP16Data->DeleteCertificate.certificateHashData.issuerNameHash);
  13646. DEBUG_INFO("issuerKeyHash: %s\n", ShmOCPP16Data->DeleteCertificate.certificateHashData.issuerKeyHash);
  13647. DEBUG_INFO("serialNumber: %s\n", ShmOCPP16Data->DeleteCertificate.certificateHashData.serialNumber);
  13648. sprintf((char*)ShmOCPP16Data->DeleteCertificate.Response_status, "NotFound");
  13649. sendDeleteCertificateConfirmation(uuid);
  13650. return result;
  13651. }
  13652. int handleExtendedTriggerMessageRequest(char *uuid, char *payload)
  13653. {
  13654. mtrace();
  13655. int result = PASS;
  13656. json_object *ExtendedTriggerMessage;
  13657. DEBUG_INFO("handleExtendedTriggerMessageRequest...\n");
  13658. ExtendedTriggerMessage = json_tokener_parse(payload);
  13659. if(!is_error(ExtendedTriggerMessage))
  13660. {
  13661. sprintf((char*)ShmOCPP16Data->ExtendedTriggerMessage.requestedMessage, "%s", json_object_get_string(json_object_object_get(ExtendedTriggerMessage, "requestedMessage")));
  13662. if(json_object_object_get(ExtendedTriggerMessage, "connectorId") != NULL)
  13663. {
  13664. ShmOCPP16Data->ExtendedTriggerMessage.connectorId = json_object_get_int(json_object_object_get(ExtendedTriggerMessage, "connectorId"));
  13665. }
  13666. else
  13667. {
  13668. ShmOCPP16Data->ExtendedTriggerMessage.connectorId = -1;
  13669. }
  13670. }
  13671. json_object_put(ExtendedTriggerMessage);
  13672. DEBUG_INFO("requestedMessage: %s\n", ShmOCPP16Data->ExtendedTriggerMessage.requestedMessage);
  13673. DEBUG_INFO("connectorIdInt: %d\n", ShmOCPP16Data->ExtendedTriggerMessage.connectorId);
  13674. if((ShmOCPP16Data->ExtendedTriggerMessage.connectorId == 0) || (ShmOCPP16Data->ExtendedTriggerMessage.connectorId > gunTotalNumber))
  13675. {
  13676. sprintf((char*)ShmOCPP16Data->ExtendedTriggerMessage.Response_status, TriggerMessageStatusStr[TriggerMessageStatus_Rejected]);
  13677. }
  13678. else
  13679. {
  13680. if((strcmp((char*)ShmOCPP16Data->ExtendedTriggerMessage.requestedMessage, MessageTriggerStr[BootNotification]) != 0 ) &&
  13681. (strcmp((char*)ShmOCPP16Data->ExtendedTriggerMessage.requestedMessage, "LogStatusNotification") != 0) &&
  13682. (strcmp((char*)ShmOCPP16Data->ExtendedTriggerMessage.requestedMessage, MessageTriggerStr[FirmwareStatusNotification]) != 0) &&
  13683. (strcmp((char*)ShmOCPP16Data->ExtendedTriggerMessage.requestedMessage, MessageTriggerStr[Heartbeat]) != 0) &&
  13684. (strcmp((char*)ShmOCPP16Data->ExtendedTriggerMessage.requestedMessage, MessageTriggerStr[MeterValues]) != 0) &&
  13685. (strcmp((char*)ShmOCPP16Data->ExtendedTriggerMessage.requestedMessage, "SignChargePointCertificate") != 0 ) &&
  13686. (strcmp((char*)ShmOCPP16Data->ExtendedTriggerMessage.requestedMessage, MessageTriggerStr[StatusNotification]) != 0 ))
  13687. {
  13688. sprintf((char*)ShmOCPP16Data->ExtendedTriggerMessage.Response_status, "%s",TriggerMessageStatusStr[TriggerMessageStatus_NotImplemented] );
  13689. }
  13690. else
  13691. {
  13692. sprintf((char*)ShmOCPP16Data->ExtendedTriggerMessage.Response_status, "%s",TriggerMessageStatusStr[TriggerMessageStatus_Accepted] );
  13693. }
  13694. }
  13695. sendExtendedTriggerMessageConfirmation(uuid);
  13696. //==========================
  13697. // Trigger message
  13698. //==========================
  13699. if(strcmp((char*)ShmOCPP16Data->ExtendedTriggerMessage.requestedMessage, MessageTriggerStr[BootNotification]) == 0 )
  13700. {
  13701. //sendBootNotificationRequest();
  13702. server_sign = FALSE;
  13703. }
  13704. else if( strcmp((char*)ShmOCPP16Data->ExtendedTriggerMessage.requestedMessage, "LogStatusNotification") == 0)
  13705. {
  13706. ShmOCPP16Data->SpMsg.bits.LogStatusNotificationReq = 1;
  13707. }
  13708. else if( strcmp((char*)ShmOCPP16Data->ExtendedTriggerMessage.requestedMessage, MessageTriggerStr[FirmwareStatusNotification]) == 0)
  13709. {
  13710. if((strlen((char*)ShmOCPP16Data->FirmwareStatusNotification.Status) == 0) ||
  13711. ((FirmwareStatusNotificationStatus != FIRMWARE_STATUS_DOWNLOADING) && (FirmwareStatusNotificationStatus != FIRMWARE_STATUS_DOWNLOADED) && (FirmwareStatusNotificationStatus != FIRMWARE_STATUS_IDLE) && (FirmwareStatusNotificationStatus != FIRMWARE_STATUS_INSTALLING)))
  13712. {
  13713. FirmwareStatusNotificationStatus = FIRMWARE_STATUS_IDLE;
  13714. sprintf((char*)ShmOCPP16Data->FirmwareStatusNotification.Status, "%s", FirmwareStatusStr[FirmwareStatus_Idle]);
  13715. }
  13716. ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationReq = 1;
  13717. }
  13718. else if(strcmp((char*)ShmOCPP16Data->ExtendedTriggerMessage.requestedMessage, MessageTriggerStr[Heartbeat]) == 0 )
  13719. {
  13720. refreshStartTimer(&clientTime.Heartbeat);
  13721. clientTime.Heartbeat.tv_sec -= ShmOCPP16Data->BootNotification.ResponseHeartbeatInterval;
  13722. }
  13723. else if (strcmp((char*)ShmOCPP16Data->ExtendedTriggerMessage.requestedMessage, MessageTriggerStr[MeterValues]) == 0 )
  13724. {
  13725. if((ShmOCPP16Data->ExtendedTriggerMessage.connectorId > 0) && (ShmOCPP16Data->ExtendedTriggerMessage.connectorId <= gunTotalNumber))
  13726. {
  13727. cpinitateMsg.bits[ShmOCPP16Data->ExtendedTriggerMessage.connectorId-1].TriggerMeterValue = 1;
  13728. }
  13729. else
  13730. {
  13731. for(int idx=0;idx< gunTotalNumber;idx++)
  13732. {
  13733. //sendMeterValuesRequest(idx, ReadingContext_Trigger);
  13734. cpinitateMsg.bits[idx].TriggerMeterValue = 1;
  13735. }
  13736. }
  13737. }
  13738. else if(strcmp((char*)ShmOCPP16Data->ExtendedTriggerMessage.requestedMessage, "SignChargePointCertificate") == 0 )
  13739. {
  13740. ShmOCPP16Data->SpMsg.bits.SignCertificateReq = 1;
  13741. if(access("/Storage/OCPP/certCP.csr",F_OK) == -1)
  13742. {
  13743. 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\" &");
  13744. }
  13745. }
  13746. else if(strcmp((char*)ShmOCPP16Data->ExtendedTriggerMessage.requestedMessage, MessageTriggerStr[StatusNotification]) == 0 )
  13747. {
  13748. if((ShmOCPP16Data->ExtendedTriggerMessage.connectorId > 0) && (ShmOCPP16Data->ExtendedTriggerMessage.connectorId <= gunTotalNumber))
  13749. {
  13750. cpinitateMsg.bits[ShmOCPP16Data->ExtendedTriggerMessage.connectorId -1].StatusNotificationReq = 1;
  13751. }
  13752. else
  13753. {
  13754. for(int idx=0;idx< gunTotalNumber;idx++)
  13755. cpinitateMsg.bits[idx].StatusNotificationReq = 1;
  13756. }
  13757. }
  13758. return result;
  13759. }
  13760. int handleGetInstalledCertificateIdsRequest(char *uuid, char *payload)
  13761. {
  13762. mtrace();
  13763. int result = PASS;
  13764. json_object *GetInstalledCertificateIds;
  13765. DEBUG_INFO("handleGetInstalledCertificateIdsRequest...\n");
  13766. GetInstalledCertificateIds = json_tokener_parse(payload);
  13767. if(!is_error(GetInstalledCertificateIds))
  13768. {
  13769. sprintf((char*)ShmOCPP16Data->GetInstalledCertificateIds.certificateType, "%s", json_object_get_string(json_object_object_get(GetInstalledCertificateIds, "certificateType")));
  13770. }
  13771. json_object_put(GetInstalledCertificateIds);
  13772. /*
  13773. * TODO: Return installed certificate process
  13774. */
  13775. ShmOCPP16Data->MsMsg.bits.GetInstalledCertificateIdsReq = 1;
  13776. DEBUG_INFO("requestedMessage: %s\n", (char*)ShmOCPP16Data->GetInstalledCertificateIds.certificateType);
  13777. memset(ShmOCPP16Data->GetInstalledCertificateIds.Response_certificateHashData, 0x00, ARRAY_SIZE(ShmOCPP16Data->GetInstalledCertificateIds.Response_certificateHashData)*sizeof(struct CertificateHashDataType));
  13778. sprintf((char*)ShmOCPP16Data->GetInstalledCertificateIds.Response_status, "NotFound");
  13779. sendGetInstalledCertificateIdsConfirmation(uuid);
  13780. return result;
  13781. }
  13782. void* GetLogProcess(void* data)
  13783. {
  13784. pthread_detach(pthread_self());
  13785. mtrace();
  13786. 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};
  13787. int port=0;
  13788. int isSuccess = FALSE;
  13789. char cmdBuf[2048];
  13790. struct tm *tmNow;
  13791. time_t CurrentTime;
  13792. struct tm tmStart;
  13793. struct tm tmStop;
  13794. CurrentTime = time(NULL);
  13795. tmNow=localtime(&CurrentTime);
  13796. uint16_t targetYear, targetMonth;
  13797. json_object *GetLog;
  13798. DEBUG_INFO("GetLogProcess...\n");
  13799. GetLog = json_tokener_parse(data);
  13800. if(!is_error(GetLog))
  13801. {
  13802. sprintf((char*)ShmOCPP16Data->GetLog.logType, "%s", json_object_get_string(json_object_object_get(GetLog, "logType")));
  13803. ShmOCPP16Data->GetLog.requestId = json_object_get_int(json_object_object_get(GetLog, "requestId"));
  13804. if(json_object_object_get(GetLog, "retries") != NULL)
  13805. {
  13806. ShmOCPP16Data->GetLog.retries = json_object_get_int(json_object_object_get(GetLog, "retries"));
  13807. }
  13808. if(json_object_object_get(GetLog, "retryInterval") != NULL)
  13809. {
  13810. ShmOCPP16Data->GetLog.retryInterval = json_object_get_int(json_object_object_get(GetLog, "retryInterval"));
  13811. }
  13812. sprintf((char*)ShmOCPP16Data->GetLog.log.remoteLocation, "%s", json_object_get_string(json_object_object_get(json_object_object_get(GetLog, "log"), "remoteLocation")));
  13813. if(json_object_object_get(json_object_object_get(GetLog, "log"), "oldestTimestamp") != NULL)
  13814. {
  13815. sprintf((char*)ShmOCPP16Data->GetLog.log.oldestTimestamp, "%s", json_object_get_string(json_object_object_get(json_object_object_get(GetLog, "log"), "oldestTimestamp")));
  13816. }
  13817. if(json_object_object_get(json_object_object_get(GetLog, "log"), "latestTimestamp") != NULL)
  13818. {
  13819. sprintf((char*)ShmOCPP16Data->GetLog.log.latestTimestamp, "%s", json_object_get_string(json_object_object_get(json_object_object_get(GetLog, "log"), "latestTimestamp")));
  13820. }
  13821. }
  13822. json_object_put(GetLog);
  13823. // Pack log to compress file
  13824. if((sscanf((char*)ShmOCPP16Data->GetLog.log.oldestTimestamp, "%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) &&
  13825. (sscanf((char*)ShmOCPP16Data->GetLog.log.latestTimestamp, "%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))
  13826. {
  13827. // Pack system log
  13828. memset(cmdBuf, 0x00, ARRAY_SIZE(cmdBuf));
  13829. sprintf(cmdBuf, "exec zip -9 --password %04d%02d%s /mnt/system.zip", tmNow->tm_year+1900, tmNow->tm_mon+1, ShmSysConfigAndInfo->SysConfig.SerialNumber);
  13830. targetYear = tmStart.tm_year;
  13831. targetMonth = tmStart.tm_mon;
  13832. do
  13833. {
  13834. sprintf(cmdBuf, "%s /Storage/SystemLog/*%04d*%02d*", cmdBuf, targetYear, targetMonth);
  13835. sprintf(cmdBuf, "%s /Storage/OCPP/*%04d*%02d*SystemLog*", cmdBuf, targetYear, targetMonth);
  13836. if(targetMonth+1>=13)
  13837. {
  13838. targetYear += 1;
  13839. targetMonth = 1;
  13840. }
  13841. else
  13842. {
  13843. targetMonth += 1;
  13844. }
  13845. }while((targetYear < (tmNow->tm_year+1900)) ||
  13846. ((targetYear <= (tmNow->tm_year+1900)) && (targetMonth <= (tmNow->tm_mon+1))));
  13847. sprintf(cmdBuf, "%s /Storage/CCS*.zip", cmdBuf);
  13848. sprintf(cmdBuf, "%s /Storage/OCPP/*.db", cmdBuf);
  13849. system(cmdBuf);
  13850. // Pack charging & event log
  13851. memset(cmdBuf, 0x00, ARRAY_SIZE(cmdBuf));
  13852. sprintf(cmdBuf, "exec zip -9 /mnt/charging_event.zip");
  13853. targetYear = tmStart.tm_year;
  13854. targetMonth = tmStart.tm_mon;
  13855. do
  13856. {
  13857. sprintf(cmdBuf, "%s /Storage/EventLog/*%04d*%02d*", cmdBuf, targetYear, targetMonth);
  13858. sprintf(cmdBuf, "%s /Storage/OCPP/*%04d*%02d*OcppMessageLog*", cmdBuf, targetYear, targetMonth);
  13859. if(targetMonth+1>=13)
  13860. {
  13861. targetYear += 1;
  13862. targetMonth = 1;
  13863. }
  13864. else
  13865. {
  13866. targetMonth += 1;
  13867. }
  13868. }while((targetYear < (tmNow->tm_year+1900)) ||
  13869. ((targetYear <= (tmNow->tm_year+1900)) && (targetMonth <= (tmNow->tm_mon+1))));
  13870. sprintf(cmdBuf, "%s /Storage/ChargeLog/*.db", cmdBuf);
  13871. sprintf(cmdBuf, "%s /Storage/EventLog/*.db", cmdBuf);
  13872. system(cmdBuf);
  13873. // Combine log file
  13874. system("exec zip -9 /mnt/log.zip /mnt/system.zip /mnt/charging_event.zip");
  13875. system("exec rm -f /mnt/system.zip /mnt/charging_event.zip");
  13876. }
  13877. else
  13878. {
  13879. system("exec /root/logPackTools 'log' 6");
  13880. }
  13881. sprintf(cmdBuf, "mv /mnt/log.zip /mnt/%s", ShmOCPP16Data->GetLog.Response_filename);
  13882. system(cmdBuf);
  13883. checkUploadLog();
  13884. //****************location*******************/
  13885. if(strcmp((char*)ShmOCPP16Data->GetLog.log.remoteLocation,"")==0)
  13886. {
  13887. DEBUG_INFO("location is <Empty>!\n");
  13888. ShmOCPP16Data->LogStatusNotification.requestId = ShmOCPP16Data->GetLog.requestId;
  13889. sprintf((char*)ShmOCPP16Data->LogStatusNotification.status, "%s", "UploadFailure");
  13890. ShmOCPP16Data->SpMsg.bits.LogStatusNotificationReq = 1;
  13891. goto end;
  13892. }
  13893. memset(protocol, 0, ARRAY_SIZE(protocol));
  13894. memset(user, 0, ARRAY_SIZE(user) );
  13895. memset(password, 0, ARRAY_SIZE(password));
  13896. memset(host, 0, ARRAY_SIZE(host));
  13897. memset(path, 0, ARRAY_SIZE(path));
  13898. memset(ftppath, 0, ARRAY_SIZE(ftppath));
  13899. memset(host1, 0, ARRAY_SIZE(host1));
  13900. memset(path1, 0, ARRAY_SIZE(path1));
  13901. /*location: ftp://user:password@host:port/path*/
  13902. //DEBUG_INFO("fnamePlusPath =%s\n",fnamePlusPath);
  13903. if((access(fnamePlusPath,F_OK))!=-1)
  13904. {
  13905. DEBUG_INFO("fnamePlusPath exist.\n");
  13906. }
  13907. else
  13908. {
  13909. DEBUG_INFO("fnamePlusPath not exist!\n");
  13910. ShmOCPP16Data->LogStatusNotification.requestId = ShmOCPP16Data->GetLog.requestId;
  13911. sprintf((char*)ShmOCPP16Data->LogStatusNotification.status, "%s", "UploadFailure");
  13912. ShmOCPP16Data->SpMsg.bits.LogStatusNotificationReq = 1;
  13913. goto end;
  13914. }
  13915. if(strchr((char*)ShmOCPP16Data->GetLog.log.remoteLocation,'@')==NULL)
  13916. {
  13917. sscanf((char*)ShmOCPP16Data->GetLog.log.remoteLocation,
  13918. "%[^:]:%*2[/]%[^:]:%i/%[a-zA-Z0-9._/-]",
  13919. protocol, host, &port, path);
  13920. strcpy(user,"anonymous");
  13921. strcpy(password,"");
  13922. }
  13923. else
  13924. {
  13925. //DEBUG_INFO("pch=%s\n", pch);
  13926. sscanf((char*)ShmOCPP16Data->GetLog.log.remoteLocation,"%[^:]:%*2[/]%[^:]:%[^@]@%[^:]:%i/%199[^\n]",
  13927. protocol, user, password, host, &port, path);
  13928. }
  13929. if((strcmp(protocol,"ftp")!=0)&&(strcmp(protocol,"http")!=0)&&(strcmp(protocol,"https")!=0))
  13930. {
  13931. DEBUG_INFO("protocol is not ftp/http ! \n");
  13932. ShmOCPP16Data->LogStatusNotification.requestId = ShmOCPP16Data->GetLog.requestId;
  13933. sprintf((char*)ShmOCPP16Data->LogStatusNotification.status, "%s", "UploadFailure");
  13934. ShmOCPP16Data->SpMsg.bits.LogStatusNotificationReq = 1;
  13935. goto end;
  13936. }
  13937. if(strncmp((char*)ShmOCPP16Data->GetLog.log.remoteLocation,"http", 4) == 0)
  13938. {
  13939. sscanf((char*)ShmOCPP16Data->GetLog.log.remoteLocation,"%[^:]:%*2[/]%[^/]/%199[^\n]", protocol, host, path);
  13940. sprintf(ftppath,"/%s", path);
  13941. do
  13942. {
  13943. ShmOCPP16Data->LogStatusNotification.requestId = ShmOCPP16Data->GetLog.requestId;
  13944. sprintf((char*)ShmOCPP16Data->LogStatusNotification.status, "%s", "Uploading");
  13945. ShmOCPP16Data->SpMsg.bits.LogStatusNotificationReq = 1;
  13946. sleep(3);
  13947. isSuccess = httpUploadFile(host, ftppath, fnamePlusPath, (char*)ShmOCPP16Data->GetLog.log.remoteLocation);
  13948. if(!isSuccess)
  13949. {
  13950. DEBUG_INFO("Diagnostics fail.\n");
  13951. ShmOCPP16Data->LogStatusNotification.requestId = ShmOCPP16Data->GetLog.requestId;
  13952. sprintf((char*)ShmOCPP16Data->LogStatusNotification.status, "%s", "UploadFailure");
  13953. ShmOCPP16Data->SpMsg.bits.LogStatusNotificationReq = 1;
  13954. sleep(ShmOCPP16Data->GetLog.retryInterval);
  13955. }
  13956. else
  13957. {
  13958. DEBUG_INFO("sendDiagnosticsStatusNotificationRequest Uploaded\n");
  13959. ShmOCPP16Data->LogStatusNotification.requestId = ShmOCPP16Data->GetLog.requestId;
  13960. sprintf((char*)ShmOCPP16Data->LogStatusNotification.status, "%s", "Uploaded");
  13961. ShmOCPP16Data->SpMsg.bits.LogStatusNotificationReq = 1;
  13962. }
  13963. ShmOCPP16Data->GetLog.retries--;
  13964. }while((isSuccess == 0)&&(ShmOCPP16Data->GetLog.retries >= 0));
  13965. }
  13966. else
  13967. {
  13968. sscanf(host,"%[^/]%s",host1, path1);
  13969. if(strlen(path) > 0)
  13970. sprintf(ftppath,"/%s", path);
  13971. else
  13972. sprintf(ftppath,"/%s", path1);
  13973. int ftppathlen=strlen(ftppath);
  13974. int i=1;
  13975. char filenametemp[50];
  13976. while(i < ftppathlen)
  13977. {
  13978. int len=ftppathlen-i;
  13979. if(ftppath[len]== 47) // '/' ascll code: 47
  13980. {
  13981. DEBUG_INFO("find '/' all right\n");
  13982. break;
  13983. }
  13984. i=i+1;
  13985. }
  13986. memset(filenametemp, 0, ARRAY_SIZE(filenametemp));
  13987. strncpy(filenametemp, ftppath+(ftppathlen-i+1), i+1);
  13988. filenametemp[i+1] = 0;
  13989. if(port == 0)
  13990. port = 21;
  13991. do
  13992. {
  13993. ShmOCPP16Data->LogStatusNotification.requestId = ShmOCPP16Data->GetLog.requestId;
  13994. sprintf((char*)ShmOCPP16Data->LogStatusNotification.status, "%s", "Uploading");
  13995. ShmOCPP16Data->SpMsg.bits.LogStatusNotificationReq = 1;
  13996. sleep(3);
  13997. isSuccess = ftpUploadFile(host1, user, password, port, ftppath, fnamePlusPath, fnamePWithNoPath);
  13998. if(!isSuccess)
  13999. {
  14000. DEBUG_INFO("Diagnostics fail.\n");
  14001. ShmOCPP16Data->LogStatusNotification.requestId = ShmOCPP16Data->GetLog.requestId;
  14002. sprintf((char*)ShmOCPP16Data->LogStatusNotification.status, "%s", "UploadFailure");
  14003. ShmOCPP16Data->SpMsg.bits.LogStatusNotificationReq = 1;
  14004. sleep(ShmOCPP16Data->GetLog.retryInterval);
  14005. }
  14006. else
  14007. {
  14008. DEBUG_INFO("sendDiagnosticsStatusNotificationRequest Uploaded\n");
  14009. ShmOCPP16Data->LogStatusNotification.requestId = ShmOCPP16Data->GetLog.requestId;
  14010. sprintf((char*)ShmOCPP16Data->LogStatusNotification.status, "%s", "Uploaded");
  14011. ShmOCPP16Data->SpMsg.bits.LogStatusNotificationReq = 1;
  14012. }
  14013. ShmOCPP16Data->GetLog.retries--;
  14014. }while((!isSuccess)&&(ShmOCPP16Data->GetLog.retries >= 0));
  14015. }
  14016. end:
  14017. system("rm -f /mnt/*");
  14018. sleep(5);
  14019. ShmOCPP16Data->LogStatusNotification.requestId = ShmOCPP16Data->GetLog.requestId;
  14020. sprintf((char*)ShmOCPP16Data->LogStatusNotification.status, "%s", "Idle");
  14021. ShmOCPP16Data->SpMsg.bits.LogStatusNotificationReq = 1;
  14022. interLock.isGetDiagnosticGoing = 0;
  14023. pthread_exit(NULL);
  14024. }
  14025. int handleGetLogRequest(char *uuid, char *payload)
  14026. {
  14027. mtrace();
  14028. int result = PASS;
  14029. time_t CurrentTime;
  14030. struct tm *tm;
  14031. DEBUG_INFO("handleGetLogRequest...\n");
  14032. pthread_t th_Status;
  14033. CurrentTime = time(NULL);
  14034. tm = localtime(&CurrentTime);
  14035. memset(ShmOCPP16Data->GetLog.Response_filename, 0x00, ARRAY_SIZE(ShmOCPP16Data->GetLog.Response_filename));
  14036. sprintf((char*)ShmOCPP16Data->GetLog.Response_filename, "%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);
  14037. if(!interLock.isGetDiagnosticGoing)
  14038. {
  14039. sprintf((char*)ShmOCPP16Data->GetLog.Response_status, "Accepted");
  14040. interLock.isGetDiagnosticGoing = 1;
  14041. pthread_create(&th_Status, NULL, GetLogProcess, stringtrimspace(payload));
  14042. sleep(1);
  14043. }
  14044. else
  14045. {
  14046. sprintf((char*)ShmOCPP16Data->GetLog.Response_status, "Rejected");
  14047. DEBUG_WARN("Other GetDiagnostic request on going.\n");
  14048. }
  14049. sendGetLogConfirmation(uuid);
  14050. return result;
  14051. }
  14052. int handleInstallCertificateRequest(char *uuid, char *payload)
  14053. {
  14054. mtrace();
  14055. int result = PASS;
  14056. json_object *InstallCertificate;
  14057. DEBUG_INFO("handleInstallCertificateRequest...\n");
  14058. InstallCertificate = json_tokener_parse(payload);
  14059. if(!is_error(InstallCertificate))
  14060. {
  14061. sprintf((char*)ShmOCPP16Data->InstallCertificate.certificateType, "%s", json_object_get_string(json_object_object_get(InstallCertificate, "certificateType")));
  14062. sprintf((char*)ShmOCPP16Data->InstallCertificate.certificate, "%s", json_object_get_string(json_object_object_get(InstallCertificate, "certificate")));
  14063. /*
  14064. * TODO: Install certificate process
  14065. */
  14066. ShmOCPP16Data->MsMsg.bits.InstallCertificateReq = 1;
  14067. DEBUG_INFO("certificateType: %s\n", (char*)ShmOCPP16Data->InstallCertificate.certificateType);
  14068. DEBUG_INFO("certificate: %s\n", (char*)ShmOCPP16Data->InstallCertificate.certificate);
  14069. sprintf((char*)ShmOCPP16Data->InstallCertificate.Response_status, "Rejected");
  14070. sendInstallCertificateConfirmation(uuid);
  14071. }
  14072. json_object_put(InstallCertificate);
  14073. return result;
  14074. }
  14075. void *SignedUpdateFirmwareProcess(void *data)
  14076. {
  14077. pthread_detach(pthread_self());
  14078. mtrace();
  14079. char protocol[10], user[64],password[64],host[128], path[512], ftppath[512],host1[128],path1[512];
  14080. int port=0;
  14081. int isSuccess = 0;
  14082. char ftpbuf[1024];
  14083. char temp[1024];
  14084. char * pch;
  14085. char firmwareFileName[50];
  14086. DEBUG_INFO("SignedUpdateFirmwareProcess ...\n");
  14087. json_object *SignedUpdateFirmware;
  14088. SignedUpdateFirmware = json_tokener_parse(data);
  14089. if(!is_error(SignedUpdateFirmware))
  14090. {
  14091. if(json_object_object_get(SignedUpdateFirmware, "retries") != NULL)
  14092. {
  14093. ShmOCPP16Data->SignedUpdateFirmware.retries = json_object_get_int(json_object_object_get(SignedUpdateFirmware, "retries"));
  14094. }
  14095. if(json_object_object_get(SignedUpdateFirmware, "retryInterval") != NULL)
  14096. {
  14097. ShmOCPP16Data->SignedUpdateFirmware.retryInterval = json_object_get_int(json_object_object_get(SignedUpdateFirmware, "retryInterval"));
  14098. }
  14099. ShmOCPP16Data->SignedUpdateFirmware.requestId = json_object_get_int(json_object_object_get(SignedUpdateFirmware, "requestId"));
  14100. sprintf((char*)ShmOCPP16Data->SignedUpdateFirmware.firmware.location, "%s", json_object_get_string(json_object_object_get(json_object_object_get(SignedUpdateFirmware, "firmware"), "location")));
  14101. sprintf((char*)ShmOCPP16Data->SignedUpdateFirmware.firmware.retrieveDateTime, "%s", json_object_get_string(json_object_object_get(json_object_object_get(SignedUpdateFirmware, "firmware"), "retrieveDateTime")));
  14102. if(json_object_object_get(json_object_object_get(SignedUpdateFirmware, "firmware"), "installDateTime") != NULL)
  14103. {
  14104. sprintf((char*)ShmOCPP16Data->SignedUpdateFirmware.firmware.installDateTime, "%s", json_object_get_string(json_object_object_get(json_object_object_get(SignedUpdateFirmware, "firmware"), "installDateTime")));
  14105. }
  14106. sprintf((char*)ShmOCPP16Data->SignedUpdateFirmware.firmware.signingCertificate, "%s", json_object_get_string(json_object_object_get(json_object_object_get(SignedUpdateFirmware, "firmware"), "signingCertificate")));
  14107. sprintf((char*)ShmOCPP16Data->SignedUpdateFirmware.firmware.signature, "%s", json_object_get_string(json_object_object_get(json_object_object_get(SignedUpdateFirmware, "firmware"), "signature")));
  14108. }
  14109. json_object_put(SignedUpdateFirmware);
  14110. memset(ftppath, 0, ARRAY_SIZE(ftppath));
  14111. memset(path, 0, ARRAY_SIZE(path));
  14112. // Wait retrieveData
  14113. if(strlen((char*)ShmOCPP16Data->SignedUpdateFirmware.firmware.location) > 10)
  14114. {
  14115. do
  14116. {
  14117. sleep(1);
  14118. }while(!isOvertNow((uint8_t*)ShmOCPP16Data->SignedUpdateFirmware.firmware.retrieveDateTime));
  14119. }
  14120. // Ready to download
  14121. system("rm -f /mnt/*");
  14122. if(strncmp((char*)ShmOCPP16Data->SignedUpdateFirmware.firmware.location,"http", 4) == 0)
  14123. {
  14124. sscanf((char*)ShmOCPP16Data->SignedUpdateFirmware.firmware.location,"%[^:]:%*2[/]%[^/]/%199[^\n]", protocol, host, path);
  14125. sprintf(ftppath,"/%s", path);
  14126. DEBUG_INFO("locationstr: %s\n", (char*)ShmOCPP16Data->SignedUpdateFirmware.firmware.location);
  14127. DEBUG_INFO("protocol: %s\n",protocol);
  14128. DEBUG_INFO("host: %s\n",host);
  14129. DEBUG_INFO("path: %s\n",path);
  14130. DEBUG_INFO("ftppath: %s\n",ftppath);
  14131. int ftppathlen=strlen(ftppath);
  14132. int i=1;
  14133. while(i < ftppathlen)
  14134. {
  14135. int len=ftppathlen-i;
  14136. if(ftppath[len]== 47) // '/' ascll code: 47
  14137. {
  14138. DEBUG_INFO("compare '/' all right\n");
  14139. break;
  14140. }
  14141. i=i+1;
  14142. }
  14143. memset(firmwareFileName, 0, ARRAY_SIZE(firmwareFileName));
  14144. strncpy(firmwareFileName, ftppath+(ftppathlen-i+1), i+1);
  14145. firmwareFileName[i+1] = 0;
  14146. do
  14147. {
  14148. ShmOCPP16Data->SignedFirmwareStatusNotification.requestId = ShmOCPP16Data->SignedUpdateFirmware.requestId;
  14149. sprintf((char*)ShmOCPP16Data->SignedFirmwareStatusNotification.status, "%s", "Downloading");
  14150. ShmOCPP16Data->SpMsg.bits.SignedFirmwareStatusNotificationReq = 1;
  14151. sleep(1);
  14152. isSuccess = httpDownLoadFile(host, ftppath, firmwareFileName, (char*)ShmOCPP16Data->SignedUpdateFirmware.firmware.location);
  14153. if(!isSuccess)
  14154. {
  14155. ShmOCPP16Data->SignedFirmwareStatusNotification.requestId = ShmOCPP16Data->SignedUpdateFirmware.requestId;
  14156. sprintf((char*)ShmOCPP16Data->SignedFirmwareStatusNotification.status, "%s", "DownloadFailed");
  14157. ShmOCPP16Data->SpMsg.bits.SignedFirmwareStatusNotificationReq = 1;
  14158. if(ShmOCPP16Data->SignedUpdateFirmware.retries>0)sleep(ShmOCPP16Data->SignedUpdateFirmware.retryInterval);else sleep(1);
  14159. ShmOCPP16Data->SignedFirmwareStatusNotification.requestId = ShmOCPP16Data->SignedUpdateFirmware.requestId;
  14160. sprintf((char*)ShmOCPP16Data->SignedFirmwareStatusNotification.status, "%s", "Idle");
  14161. ShmOCPP16Data->SpMsg.bits.SignedFirmwareStatusNotificationReq = 1;
  14162. }
  14163. else
  14164. {
  14165. ShmOCPP16Data->SignedFirmwareStatusNotification.requestId = ShmOCPP16Data->SignedUpdateFirmware.requestId;
  14166. sprintf((char*)ShmOCPP16Data->SignedFirmwareStatusNotification.status, "%s", "Downloaded");
  14167. ShmOCPP16Data->SpMsg.bits.SignedFirmwareStatusNotificationReq = 1;
  14168. }
  14169. ShmOCPP16Data->SignedUpdateFirmware.retries--;
  14170. }while((isSuccess == 0)&&(ShmOCPP16Data->SignedUpdateFirmware.retries >= 0));
  14171. }
  14172. else if(strncmp((char*)ShmOCPP16Data->SignedUpdateFirmware.firmware.location,"sftp", 4) == 0) // sftp
  14173. {
  14174. memset(ftpbuf, 0, ARRAY_SIZE(ftpbuf));
  14175. memset(temp, 0, ARRAY_SIZE(temp));
  14176. //DEBUG_INFO("locationstr=%s\n",locationstr);
  14177. strcpy(ftpbuf, (char*)ShmOCPP16Data->SignedUpdateFirmware.firmware.location);
  14178. int ftppathlen=strlen(ftpbuf);
  14179. int i=1;
  14180. while(i < ftppathlen)
  14181. {
  14182. int len=ftppathlen-i;
  14183. if(ftpbuf[len]== 47) // '/' ascii code: 47
  14184. {
  14185. DEBUG_INFO(" compare '/' all right\n");
  14186. break;
  14187. }
  14188. i=i+1;
  14189. }
  14190. memset(firmwareFileName, 0, ARRAY_SIZE(firmwareFileName));
  14191. strncpy(firmwareFileName, ftpbuf+(ftppathlen-i+1), i+1);
  14192. firmwareFileName[i+1] = 0;
  14193. strncpy(temp, ftpbuf, ftppathlen-i+1);
  14194. pch=strchr(temp,'@');
  14195. if(pch==NULL)
  14196. {
  14197. sscanf(temp,"%[^:]:%*2[/]%[^:]:%i/%[a-zA-Z0-9._/-]",
  14198. protocol, host, &port, path);
  14199. strcpy(user,"anonymous");
  14200. strcpy(password,"");
  14201. }
  14202. else
  14203. {
  14204. sscanf(temp,"%[^:]:%*2[/]%[^@]@%[^:]:%i/%199[^\n]",
  14205. protocol, user, host, &port, path);
  14206. }
  14207. sscanf(host,"%[^/]%s",host1, path1);
  14208. sprintf(ftppath,"%s:/%s", host,path);
  14209. if(port == 0)
  14210. {
  14211. port = 21;
  14212. }
  14213. do
  14214. {
  14215. ShmOCPP16Data->SignedFirmwareStatusNotification.requestId = ShmOCPP16Data->SignedUpdateFirmware.requestId;
  14216. sprintf((char*)ShmOCPP16Data->SignedFirmwareStatusNotification.status, "%s", "Downloading");
  14217. ShmOCPP16Data->SpMsg.bits.SignedFirmwareStatusNotificationReq = 1;
  14218. sleep(1);
  14219. isSuccess = sftpDownLoadFile(host1, user, port, ftppath, firmwareFileName, (char*)ShmOCPP16Data->SignedUpdateFirmware.firmware.location);
  14220. if(!isSuccess)
  14221. {
  14222. //BulldogUtil.sleepMs(interval*1000);
  14223. DEBUG_INFO("Update firmware request and download file fail.\n");
  14224. ShmOCPP16Data->SignedFirmwareStatusNotification.requestId = ShmOCPP16Data->SignedUpdateFirmware.requestId;
  14225. sprintf((char*)ShmOCPP16Data->SignedFirmwareStatusNotification.status, "%s", "DownloadFailed");
  14226. ShmOCPP16Data->SpMsg.bits.SignedFirmwareStatusNotificationReq = 1;
  14227. if(ShmOCPP16Data->SignedUpdateFirmware.retries>0)sleep(ShmOCPP16Data->SignedUpdateFirmware.retryInterval);else sleep(1);
  14228. ShmOCPP16Data->SignedFirmwareStatusNotification.requestId = ShmOCPP16Data->SignedUpdateFirmware.requestId;
  14229. sprintf((char*)ShmOCPP16Data->SignedFirmwareStatusNotification.status, "%s", "Idle");
  14230. ShmOCPP16Data->SpMsg.bits.SignedFirmwareStatusNotificationReq = 1;
  14231. }
  14232. else
  14233. {
  14234. ShmOCPP16Data->SignedFirmwareStatusNotification.requestId = ShmOCPP16Data->SignedUpdateFirmware.requestId;
  14235. sprintf((char*)ShmOCPP16Data->SignedFirmwareStatusNotification.status, "%s", "Downloaded");
  14236. ShmOCPP16Data->SpMsg.bits.SignedFirmwareStatusNotificationReq = 1;
  14237. }
  14238. ShmOCPP16Data->SignedUpdateFirmware.retries--;
  14239. }while((!isSuccess)&&(ShmOCPP16Data->SignedUpdateFirmware.retries >= 0));
  14240. }
  14241. else if(strncmp((char*)ShmOCPP16Data->SignedUpdateFirmware.firmware.location,"ftp", 3) == 0) // ftp
  14242. {
  14243. memset(ftpbuf, 0, ARRAY_SIZE(ftpbuf));
  14244. memset(temp, 0, ARRAY_SIZE(temp));
  14245. //DEBUG_INFO("locationstr=%s\n",locationstr);
  14246. strcpy(ftpbuf, (char*)ShmOCPP16Data->SignedUpdateFirmware.firmware.location);
  14247. int ftppathlen=strlen(ftpbuf);
  14248. int i=1;
  14249. while(i < ftppathlen)
  14250. {
  14251. int len=ftppathlen-i;
  14252. if(ftpbuf[len]== 47) // '/' ascll code: 47
  14253. {
  14254. DEBUG_INFO(" compare '/' all right\n");
  14255. break;
  14256. }
  14257. i=i+1;
  14258. }
  14259. memset(firmwareFileName, 0, ARRAY_SIZE(firmwareFileName));
  14260. strncpy(firmwareFileName, ftpbuf+(ftppathlen-i+1), i+1);
  14261. firmwareFileName[i+1] = 0;
  14262. strncpy(temp, ftpbuf, ftppathlen-i+1);
  14263. pch=strchr(temp,'@');
  14264. if(pch==NULL)
  14265. {
  14266. sscanf(temp,"%[^:]:%*2[/]%[^:]:%i/%[a-zA-Z0-9._/-]",
  14267. protocol, host, &port, path);
  14268. strcpy(user,"anonymous");
  14269. strcpy(password,"");
  14270. }
  14271. else
  14272. {
  14273. sscanf(temp,"%[^:]:%*2[/]%[^:]:%[^@]@%[^:]:%i/%199[^\n]",
  14274. protocol, user, password, host, &port, path);
  14275. }
  14276. sscanf(host,"%[^/]%s",host1, path1);
  14277. sprintf(ftppath,"%s", path1);
  14278. //DEBUG_INFO("protocol =%s\n",protocol);
  14279. //DEBUG_INFO("user =%s\n",user);
  14280. //DEBUG_INFO("password =%s\n",password);
  14281. //DEBUG_INFO("host1 =%s\n",host1);
  14282. //DEBUG_INFO("port =%d\n",port);
  14283. //DEBUG_INFO("path1 =%s\n",path1);
  14284. //DEBUG_INFO("ftppath=%s\n",ftppath);
  14285. //ftpFile(host, user, password, port, ftppath, fname);
  14286. //download firmware pthred
  14287. if(port == 0)
  14288. {
  14289. port = 21;
  14290. }
  14291. do
  14292. {
  14293. ShmOCPP16Data->SignedFirmwareStatusNotification.requestId = ShmOCPP16Data->SignedUpdateFirmware.requestId;
  14294. sprintf((char*)ShmOCPP16Data->SignedFirmwareStatusNotification.status, "%s", "Downloading");
  14295. ShmOCPP16Data->SpMsg.bits.SignedFirmwareStatusNotificationReq = 1;
  14296. sleep(1);
  14297. isSuccess = ftpDownLoadFile(host1, user, password, port, ftppath, firmwareFileName, (char*)ShmOCPP16Data->SignedUpdateFirmware.firmware.location);
  14298. if(!isSuccess)
  14299. {
  14300. //BulldogUtil.sleepMs(interval*1000);
  14301. DEBUG_INFO("Update firmware request and download file fail.\n");
  14302. ShmOCPP16Data->SignedFirmwareStatusNotification.requestId = ShmOCPP16Data->SignedUpdateFirmware.requestId;
  14303. sprintf((char*)ShmOCPP16Data->SignedFirmwareStatusNotification.status, "%s", "DownloadFailed");
  14304. ShmOCPP16Data->SpMsg.bits.SignedFirmwareStatusNotificationReq = 1;
  14305. if(ShmOCPP16Data->SignedUpdateFirmware.retries>0)sleep(ShmOCPP16Data->SignedUpdateFirmware.retryInterval);else sleep(1);
  14306. ShmOCPP16Data->SignedFirmwareStatusNotification.requestId = ShmOCPP16Data->SignedUpdateFirmware.requestId;
  14307. sprintf((char*)ShmOCPP16Data->SignedFirmwareStatusNotification.status, "%s", "Idle");
  14308. ShmOCPP16Data->SpMsg.bits.SignedFirmwareStatusNotificationReq = 1;
  14309. }
  14310. else
  14311. {
  14312. ShmOCPP16Data->SignedFirmwareStatusNotification.requestId = ShmOCPP16Data->SignedUpdateFirmware.requestId;
  14313. sprintf((char*)ShmOCPP16Data->SignedFirmwareStatusNotification.status, "%s", "Downloaded");
  14314. ShmOCPP16Data->SpMsg.bits.SignedFirmwareStatusNotificationReq = 1;
  14315. }
  14316. ShmOCPP16Data->SignedUpdateFirmware.retries--;
  14317. }while((!isSuccess)&&(ShmOCPP16Data->SignedUpdateFirmware.retries >= 0));
  14318. }
  14319. else
  14320. {
  14321. ShmOCPP16Data->SignedFirmwareStatusNotification.requestId = ShmOCPP16Data->SignedUpdateFirmware.requestId;
  14322. sprintf((char*)ShmOCPP16Data->SignedFirmwareStatusNotification.status, "%s", "DownloadFailed");
  14323. ShmOCPP16Data->SpMsg.bits.SignedFirmwareStatusNotificationReq = 1;
  14324. sleep(1);
  14325. ShmOCPP16Data->SignedFirmwareStatusNotification.requestId = ShmOCPP16Data->SignedUpdateFirmware.requestId;
  14326. sprintf((char*)ShmOCPP16Data->SignedFirmwareStatusNotification.status, "%s", "Idle");
  14327. ShmOCPP16Data->SpMsg.bits.SignedFirmwareStatusNotificationReq = 1;
  14328. }
  14329. // Verify firmware image signature
  14330. struct stat st;
  14331. FILE *fp = fopen("/tmp/signingFirmwareUpdate.crt", "w");
  14332. fprintf(fp, "%s", ShmOCPP16Data->SignedUpdateFirmware.firmware.signingCertificate);
  14333. fclose(fp);
  14334. system("openssl x509 -pubkey -noout -in /tmp/signingFirmwareUpdate.crt > /tmp/signingFirmwareUpdate.key");
  14335. fp = fopen("/tmp/signingFirmwareUpdate.sign", "w");
  14336. fprintf(fp, "%s", ShmOCPP16Data->SignedUpdateFirmware.firmware.signature);
  14337. fclose(fp);
  14338. system("openssl base64 -d -in /tmp/signingFirmwareUpdate.sign -out /tmp/signingFirmwareUpdate.sign.256");
  14339. stat("/tmp/signingFirmwareUpdate.sign.256", &st);
  14340. if(st.st_size == 0)
  14341. system("openssl base64 -d -A -in /tmp/signingFirmwareUpdate.sign -out /tmp/signingFirmwareUpdate.sign.256");
  14342. if(strstr((char*)ShmOCPP16Data->SignedFirmwareStatusNotification.status, "Downloaded") != NULL)
  14343. {
  14344. sprintf(temp ,"openssl dgst -verify /tmp/signingFirmwareUpdate.key -signature /tmp/signingFirmwareUpdate.sign.256 /mnt/%s", firmwareFileName);
  14345. fp = popen(temp, "r");
  14346. if(fp)
  14347. {
  14348. while(fgets(temp, sizeof(temp), fp) != NULL)
  14349. {
  14350. if(strstr(temp, "Verified OK") != NULL)
  14351. {
  14352. ShmOCPP16Data->SignedFirmwareStatusNotification.requestId = ShmOCPP16Data->SignedUpdateFirmware.requestId;
  14353. sprintf((char*)ShmOCPP16Data->SignedFirmwareStatusNotification.status, "%s", "SignatureVerified");
  14354. ShmOCPP16Data->SpMsg.bits.SignedFirmwareStatusNotificationReq = 1;
  14355. }
  14356. else
  14357. {
  14358. ShmOCPP16Data->SignedFirmwareStatusNotification.requestId = ShmOCPP16Data->SignedUpdateFirmware.requestId;
  14359. sprintf((char*)ShmOCPP16Data->SignedFirmwareStatusNotification.status, "%s", "InvalidSignature");
  14360. ShmOCPP16Data->SpMsg.bits.SignedFirmwareStatusNotificationReq = 1;
  14361. sleep(1);
  14362. ShmOCPP16Data->SignedFirmwareStatusNotification.requestId = ShmOCPP16Data->SignedUpdateFirmware.requestId;
  14363. sprintf((char*)ShmOCPP16Data->SignedFirmwareStatusNotification.status, "%s", "InstallationFailed");
  14364. ShmOCPP16Data->SpMsg.bits.SignedFirmwareStatusNotificationReq = 1;
  14365. sleep(1);
  14366. ShmOCPP16Data->SignedFirmwareStatusNotification.requestId = ShmOCPP16Data->SignedUpdateFirmware.requestId;
  14367. sprintf((char*)ShmOCPP16Data->SignedFirmwareStatusNotification.status, "%s", "Idle");
  14368. ShmOCPP16Data->SpMsg.bits.SignedFirmwareStatusNotificationReq = 1;
  14369. }
  14370. break;
  14371. }
  14372. }
  14373. pclose(fp);
  14374. if(strstr((char*)ShmOCPP16Data->SignedFirmwareStatusNotification.status, "SignatureVerified") != NULL)ShmOCPP16Data->MsMsg.bits.SignedUpdateFirmwareReq = 1;
  14375. }
  14376. interLock.isUpdateFirmwareGoing = 0;
  14377. pthread_exit(NULL);
  14378. }
  14379. int handleSignedUpdateFirmwareRequest(char *uuid, char *payload)
  14380. {
  14381. mtrace();
  14382. int result = PASS;
  14383. pthread_t t;
  14384. DEBUG_INFO("handleSignedUpdateFirmwareRequest...\n");
  14385. sprintf((char*)ShmOCPP16Data->SignedUpdateFirmware.Response_status, "Accepted");
  14386. sendSignedUpdateFirmwareConfirmation(uuid);
  14387. if(!interLock.isUpdateFirmwareGoing)
  14388. {
  14389. interLock.isUpdateFirmwareGoing = 1;
  14390. pthread_create(&t, NULL, SignedUpdateFirmwareProcess, payload);
  14391. sleep(1);
  14392. }
  14393. else
  14394. DEBUG_WARN("Other UpdateFirmware request on going.\n");
  14395. ShmOCPP16Data->MsMsg.bits.SignedUpdateFirmwareConf = 1;
  14396. return result;
  14397. }
  14398. int handleUnknownRequest(char *uuid, char *payload)
  14399. {
  14400. mtrace();
  14401. int result = PASS;
  14402. DEBUG_INFO("handleUnknownRequest...\n");
  14403. sendUnknownConfirmation(uuid);
  14404. return result;
  14405. }
  14406. //==========================================
  14407. // Handle server response routine
  14408. //==========================================
  14409. void handleAuthorizeResponse(char *payload, int gun_index)
  14410. {
  14411. mtrace();
  14412. char expiryDatestr[36]={0};
  14413. char parentIdTagstr[21]={0};
  14414. char statusstr[20]={0};
  14415. int expiryDateISNULL=FALSE;
  14416. int parentIdTagISNULL=FALSE;
  14417. DEBUG_INFO("handleAuthorizeResponse...\n");
  14418. json_object *Authorize;
  14419. Authorize = json_tokener_parse(payload);
  14420. if(!is_error(Authorize))
  14421. {
  14422. if(json_object_object_get(Authorize, "idTagInfo") != NULL)
  14423. {
  14424. // Required data
  14425. sprintf((char *)statusstr, "%s", json_object_get_string(json_object_object_get(json_object_object_get(Authorize,"idTagInfo"), "status")));
  14426. // Optional data
  14427. if(json_object_object_get(json_object_object_get(Authorize,"idTagInfo"), "expiryDate") != NULL)
  14428. sprintf((char *)expiryDatestr, "%s", json_object_get_string(json_object_object_get(json_object_object_get(Authorize,"idTagInfo"), "expiryDate")));
  14429. if(json_object_object_get(json_object_object_get(Authorize,"idTagInfo"), "parentIdTag") != NULL)
  14430. sprintf((char *)parentIdTagstr, "%s", json_object_get_string(json_object_object_get(json_object_object_get(Authorize,"idTagInfo"), "parentIdTag")));
  14431. }
  14432. }
  14433. json_object_put(Authorize);
  14434. if(expiryDateISNULL == FALSE)
  14435. strcpy((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.ExpiryDate, expiryDatestr);
  14436. if(parentIdTagISNULL == FALSE)
  14437. strcpy((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.ParentIdTag, parentIdTagstr);
  14438. strcpy((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.Status, statusstr);
  14439. //Update idTag information to authorization cache if supproted
  14440. if((strcmp((const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemData, "TRUE") == 0) && (ShmOCPP16Data->Authorize.ResponseIdTagInfo.ParentIdTag != NULL) && (ShmOCPP16Data->Authorize.ResponseIdTagInfo.ExpiryDate != NULL) )
  14441. {
  14442. OCPP_addLocalCache((char*)ShmOCPP16Data->Authorize.IdTag, parentIdTagstr, expiryDatestr, statusstr);
  14443. }
  14444. ShmOCPP16Data->SpMsg.bits.AuthorizeReq = 0;
  14445. ShmOCPP16Data->SpMsg.bits.AuthorizeConf = 1; // inform csu
  14446. authorizeRetryTimes = 0;
  14447. }
  14448. void handleBootNotificationResponse(char *payload, int gun_index)
  14449. {
  14450. mtrace();
  14451. char statusStr[12]={0};
  14452. char currentTimeStr[30]={0};
  14453. int intervalInt = 0;
  14454. DEBUG_INFO("handleBootNotificationResponse...\n");
  14455. json_object *BootNotification;
  14456. BootNotification = json_tokener_parse(payload);
  14457. if(!is_error(BootNotification))
  14458. {
  14459. // Required data
  14460. sprintf((char *)currentTimeStr, "%s", json_object_get_string(json_object_object_get(BootNotification,"currentTime")));
  14461. intervalInt = json_object_get_int(json_object_object_get(BootNotification,"interval"));
  14462. sprintf((char *)statusStr, "%s", json_object_get_string(json_object_object_get(BootNotification,"status")));
  14463. }
  14464. json_object_put(BootNotification);
  14465. ShmOCPP16Data->BootNotification.ResponseHeartbeatInterval = intervalInt;
  14466. BootNotificationInterval = intervalInt;
  14467. //write back to ShmOCPP16Data->BootNotification
  14468. strcpy((char *)ShmOCPP16Data->BootNotification.ResponseCurrentTime, currentTimeStr);
  14469. ShmOCPP16Data->BootNotification.ResponseHeartbeatInterval = intervalInt;
  14470. strcpy((char *)ShmOCPP16Data->BootNotification.ResponseStatus, statusStr);
  14471. if((strcmp(statusStr, RegistrationStatusStr[RegistrationStatus_Accepted]) == 0 ))
  14472. {
  14473. BootNotificationInterval = 0;
  14474. if((intervalInt == 0) || (intervalInt >= 10))
  14475. {
  14476. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemData, "%d", intervalInt);
  14477. HeartBeatWaitTime = intervalInt;
  14478. DEBUG_INFO("BootNotificationResponse setting interval to %d...\n",intervalInt);
  14479. }
  14480. server_sign = TRUE;
  14481. server_pending =FALSE;
  14482. }
  14483. else if(strcmp(statusStr, RegistrationStatusStr[RegistrationStatus_Pending]) == 0)
  14484. {
  14485. server_pending = TRUE;
  14486. }
  14487. syncDateTimeRTC(ShmOCPP16Data->BootNotification.ResponseCurrentTime);
  14488. srand(time(NULL));
  14489. refreshStartTimer(&clientTime.Heartbeat);
  14490. clientTime.Heartbeat.tv_sec -= (ShmOCPP16Data->BootNotification.ResponseHeartbeatInterval-((rand()%8)+3));
  14491. SetOcppConnStatus(TRUE);
  14492. ShmOCPP16Data->SpMsg.bits.BootNotificationConf = 1;
  14493. }
  14494. void handleDataTransferResponse(char *payload, int gun_index)
  14495. {
  14496. json_object *DataTransfer = json_tokener_parse(payload);
  14497. if(!is_error(DataTransfer))
  14498. {
  14499. // Required data
  14500. DEBUG_INFO("Status: %s.\n", json_object_get_string(json_object_object_get(DataTransfer, "status")));
  14501. // Optional data
  14502. if(json_object_object_get(DataTransfer, "data") != NULL)
  14503. {
  14504. DEBUG_INFO("Data: %s\n", json_object_get_string(json_object_object_get(DataTransfer, "data")));
  14505. json_object *Data = json_tokener_parse(json_object_get_string(json_object_object_get(DataTransfer, "data")));
  14506. if(!is_error(Data))
  14507. {
  14508. if(json_object_object_get(Data, "msgId") != NULL)
  14509. {
  14510. if(strstr(json_object_get_string(json_object_object_get(Data, "msgId")), "ID_CreditDeductResult") != NULL)
  14511. {
  14512. OCPP_update_deduct_info(json_object_get_int(json_object_object_get(Data, "txId")), (char*)json_object_get_string(json_object_object_get(Data, "creditNo")));
  14513. }
  14514. if(strstr(json_object_get_string(json_object_object_get(Data, "msgId")), "ID_ReaderStatus") != NULL)
  14515. {
  14516. if(json_object_object_get(Data, "ConnectorId") != NULL)
  14517. ShmOCPP16Data->TcciCustomData.ReaderStatus[json_object_get_int(json_object_object_get(Data, "ConnectorId"))-1].ReportReaderStatusReq = 0;
  14518. }
  14519. }
  14520. }
  14521. json_object_put(Data);
  14522. }
  14523. }
  14524. json_object_put(DataTransfer);
  14525. }
  14526. void handleDiagnosticsStatusNotificationResponse(char *payload, int gun_index)
  14527. {
  14528. DEBUG_INFO("handleDiagnosticsStatusNotificationResponse ...\n");
  14529. //struct json_object *obj;
  14530. // obj = json_tokener_parse(payload);
  14531. ShmOCPP16Data->SpMsg.bits.DiagnosticsStatusNotificationReq = 0;
  14532. ShmOCPP16Data->SpMsg.bits.DiagnosticsStatusNotificationConf = 1;
  14533. //No fields are defined.
  14534. }
  14535. void handleFirmwareStatusNotificationResponse(char *payload, int gun_index)
  14536. {
  14537. DEBUG_INFO("handleFirmwareStatusNotificationResponse ...\n");
  14538. //struct json_object *obj;
  14539. // obj = json_tokener_parse(payload);
  14540. ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationReq = 0;
  14541. ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationConf = 1;
  14542. //No fields are defined.
  14543. }
  14544. void handleHeartbeatResponse(char *payload, int gun_index)
  14545. {
  14546. mtrace();
  14547. DEBUG_INFO("handleHeartbeatResponse...\n");
  14548. json_object *Heartbeat;
  14549. Heartbeat = json_tokener_parse(payload);
  14550. if(!is_error(Heartbeat))
  14551. {
  14552. // Required data
  14553. sprintf((char *)ShmOCPP16Data->Heartbeat.ResponseCurrentTime, "%s", json_object_get_string(json_object_object_get(Heartbeat,"currentTime")));
  14554. }
  14555. json_object_put(Heartbeat);
  14556. if(FirstHeartBeat == 0)
  14557. {
  14558. FirstHeartBeat = 1;
  14559. DEBUG_INFO("FirstHeartBeat \n");
  14560. }
  14561. HeartBeatWithNOResponse = 0;
  14562. refreshStartTimer(&clientTime.Heartbeat);
  14563. syncDateTimeRTC(ShmOCPP16Data->Heartbeat.ResponseCurrentTime);
  14564. }
  14565. void handleMeterValuesResponse(char *payload, int gun_index)
  14566. {
  14567. mtrace();
  14568. DEBUG_INFO("handleMeterValuesResponse...\n");
  14569. isQueueSendable = 1;
  14570. }
  14571. void handleStartTransactionResponse(char *payload, int gun_index)
  14572. {
  14573. mtrace();
  14574. //int transactionIdInt = 0;
  14575. FILE *outfile;
  14576. char data[100]={0};
  14577. DEBUG_INFO("handleStartTransactionResponse...\n");
  14578. json_object *StartTransaction;
  14579. StartTransaction = json_tokener_parse(payload);
  14580. if(!is_error(StartTransaction))
  14581. {
  14582. // Required data
  14583. sprintf((char *)ShmOCPP16Data->StartTransaction[gun_index].ResponseIdTagInfo.Status, "%s", json_object_get_string(json_object_object_get(json_object_object_get(StartTransaction,"idTagInfo"), "status")));
  14584. ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId = json_object_get_int(json_object_object_get(StartTransaction,"transactionId"));
  14585. // Optional data
  14586. if(json_object_object_get(json_object_object_get(StartTransaction,"idTagInfo"), "expiryDate") != NULL)
  14587. sprintf((char *)ShmOCPP16Data->StartTransaction[gun_index].ResponseIdTagInfo.ExpiryDate, "%s", json_object_get_string(json_object_object_get(json_object_object_get(StartTransaction,"idTagInfo"), "expiryDate")));
  14588. if(json_object_object_get(json_object_object_get(StartTransaction,"idTagInfo"), "parentIdTag") != NULL)
  14589. sprintf((char *)ShmOCPP16Data->StartTransaction[gun_index].ResponseIdTagInfo.ParentIdTag, "%s", json_object_get_string(json_object_object_get(json_object_object_get(StartTransaction,"idTagInfo"), "parentIdTag")));
  14590. }
  14591. json_object_put(StartTransaction);
  14592. OCPP_updatePeriodEnergy(gun_index);
  14593. //-----------Start : write to the Queue TransactionId file -----------------//
  14594. if((access("/Storage/OCPP/QueueTransactionId",F_OK))!=-1)
  14595. {}
  14596. else
  14597. {
  14598. FILE *log = fopen("/Storage/OCPP/QueueTransactionId", "w+");
  14599. if(log == NULL)
  14600. {
  14601. DEBUG_INFO("Can't Create File QueueTransactionId \n");
  14602. return ;
  14603. }
  14604. else
  14605. {
  14606. fclose(log);
  14607. }
  14608. }
  14609. // open file for writing
  14610. //-------------Start: write to the Queue TransactionId file------------------------------------------//
  14611. if((ShmOCPP16Data->StartTransaction[gun_index].ConnectorId !=0)&&(strcmp((const char *)ShmOCPP16Data->StartTransaction[gun_index].IdTag,"")!=0)&&(ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId !=0))
  14612. {
  14613. outfile = fopen ("/Storage/OCPP/QueueTransactionId", "a");
  14614. sprintf(data,"%d,%s,%d\n", ShmOCPP16Data->StartTransaction[gun_index].ConnectorId , ShmOCPP16Data->StartTransaction[gun_index].IdTag, ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId); // GunIndex, idtag, TransactionId
  14615. fputs(data, outfile);
  14616. fclose (outfile);
  14617. }
  14618. DEBUG_INFO("idTagInfo-expiryDate: %s\n", ShmOCPP16Data->StartTransaction[gun_index].ResponseIdTagInfo.ExpiryDate);
  14619. DEBUG_INFO("idTagInfo-parentIdTag: %s\n", ShmOCPP16Data->StartTransaction[gun_index].ResponseIdTagInfo.ParentIdTag);
  14620. DEBUG_INFO("idTagInfo-status: %s\n", ShmOCPP16Data->StartTransaction[gun_index].ResponseIdTagInfo.Status);
  14621. DEBUG_INFO("transactionId: %d\n", ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId);
  14622. system("/bin/fsync -d /dev/mtdblock13;/bin/sync &");
  14623. isQueueSendable = 1;
  14624. ShmOCPP16Data->CpMsg.bits[gun_index].StartTransactionConf = 1;
  14625. ShmOCPP16Data->CpMsg.bits[gun_index].StartTransactionReq = 0;
  14626. }
  14627. void handleStatusNotificationResponse(char *payload, int gun_index)
  14628. {
  14629. mtrace();
  14630. DEBUG_INFO("handleStatusNotificationResponse...\n");
  14631. //cpinitateMsg.bits[gun_index].TriggerStatusNotificationReq = 0;
  14632. //cpinitateMsg.bits[gun_index].StatusNotificationReq = 0;
  14633. cpinitateMsg.bits[gun_index].StatusNotificationConf = 1;
  14634. }
  14635. void handleStopTransactionnResponse(char *payload, int gun_index)
  14636. {
  14637. mtrace();
  14638. DEBUG_INFO("handleStopTransactionnResponse...\n");
  14639. json_object *StopTransaction;
  14640. StopTransaction = json_tokener_parse(payload);
  14641. if(!is_error(StopTransaction))
  14642. {
  14643. // Optional data
  14644. if(json_object_object_get(StopTransaction, "idTagInfo") != NULL)
  14645. {
  14646. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].ResponseIdTagInfo.Status, "%s", json_object_get_string(json_object_object_get(json_object_object_get(StopTransaction,"idTagInfo"), "status")));
  14647. if(json_object_object_get(json_object_object_get(StopTransaction,"idTagInfo"), "expiryDate") != NULL)
  14648. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].ResponseIdTagInfo.ExpiryDate, "%s", json_object_get_string(json_object_object_get(json_object_object_get(StopTransaction,"idTagInfo"), "expiryDate")));
  14649. if(json_object_object_get(json_object_object_get(StopTransaction,"idTagInfo"), "parentIdTag") != NULL)
  14650. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].ResponseIdTagInfo.ParentIdTag, "%s", json_object_get_string(json_object_object_get(json_object_object_get(StopTransaction,"idTagInfo"), "parentIdTag")));
  14651. }
  14652. }
  14653. json_object_put(StopTransaction);
  14654. isQueueSendable = 1;
  14655. ShmOCPP16Data->CpMsg.bits[gun_index].StopTransactionConf = 1;
  14656. ShmOCPP16Data->CpMsg.bits[gun_index].StopTransactionReq = 0;
  14657. DEBUG_INFO("idTagInfo-expiryDate: %s\n", ShmOCPP16Data->StopTransaction[gun_index].ResponseIdTagInfo.ExpiryDate);
  14658. DEBUG_INFO("idTagInfo-parentIdTag: %s\n", ShmOCPP16Data->StopTransaction[gun_index].ResponseIdTagInfo.ParentIdTag);
  14659. DEBUG_INFO("idTagInfo-status: %s\n", ShmOCPP16Data->StopTransaction[gun_index].ResponseIdTagInfo.Status);
  14660. SetTransactionIdZero(queueOpInfo.stopTransactionId);
  14661. }
  14662. void handleLogStatusNotificationResponse(char *payload, int gun_index)
  14663. {
  14664. mtrace();
  14665. DEBUG_INFO("handleLogStatusNotificationResponse...\n");
  14666. ShmOCPP16Data->SpMsg.bits.LogStatusNotificationConf = 1;
  14667. }
  14668. void handleSecurityEventNotificationResponse(char *payload, int gun_index)
  14669. {
  14670. mtrace();
  14671. DEBUG_INFO("handleSecurityEventNotificationResponse...\n");
  14672. ShmOCPP16Data->SpMsg.bits.SecurityEventNotificationConf = 1;
  14673. }
  14674. void handleSignCertificateResponse(char *payload, int gun_index)
  14675. {
  14676. mtrace();
  14677. DEBUG_INFO("handleSignCertificateResponse...\n");
  14678. json_object *SignCertificate;
  14679. SignCertificate = json_tokener_parse(payload);
  14680. if(!is_error(SignCertificate))
  14681. {
  14682. sprintf((char*)ShmOCPP16Data->SignCertificate.Response_status, "%s", json_object_get_string(json_object_object_get(SignCertificate, "status")));
  14683. DEBUG_INFO("status: %s\n", ShmOCPP16Data->SignCertificate.Response_status);
  14684. }
  14685. json_object_put(SignCertificate);
  14686. ShmOCPP16Data->SpMsg.bits.SignCertificateConf = 1;
  14687. }
  14688. void handleSignedFirmwareStatusNotificationResponse(char *payload, int gun_index)
  14689. {
  14690. mtrace();
  14691. DEBUG_INFO("handleSignedFirmwareStatusNotificationResponse...\n");
  14692. ShmOCPP16Data->SpMsg.bits.SignedFirmwareStatusNotificationConf = 1;
  14693. }
  14694. //==========================================
  14695. // Handle Error routine
  14696. //==========================================
  14697. void handleError(char *id, char *errorCode, char *errorDescription,char *payload)
  14698. {
  14699. mtrace();
  14700. #ifdef SystemLogMessage
  14701. DEBUG_INFO("errorCode: %s\n", errorCode);
  14702. DEBUG_INFO("errorDescription: %s\n", errorDescription);
  14703. DEBUG_INFO("errorDetails: %s\n", payload);
  14704. #endif
  14705. }
  14706. //===============================================
  14707. // Common routine
  14708. //===============================================
  14709. int initialConfigurationTable(void)
  14710. {
  14711. //clock_t start_t, end_t, total_t;
  14712. FILE *fp;
  14713. FILE *outfile;
  14714. char str[512]={0};
  14715. char sstr[256]={0};
  14716. int c = 0;
  14717. char *loc;
  14718. int confVersion = 19;
  14719. DEBUG_INFO("initialConfigurationTable...version: %d\n", confVersion);
  14720. //start_t = clock();
  14721. //printf("Starting of the program, start_t = %ld\n", start_t);
  14722. memset(&(ShmOCPP16Data->ConfigurationTable), 0, sizeof(struct OCPP16ConfigurationTable) );
  14723. // Check configuration file size is correct
  14724. if((access("/Storage/OCPP/OCPPConfiguration",F_OK))!=-1)
  14725. {
  14726. struct stat st;
  14727. stat("/Storage/OCPP/OCPPConfiguration", &st);
  14728. if(st.st_size < 3100)
  14729. {
  14730. system("rm -f /Storage/OCPP/OCPPConfiguration");
  14731. DEBUG_INFO("OCPPConfiguration file size: %d is smaller than 3100 bytes, restore to default value.\n", st.st_size);
  14732. }
  14733. }
  14734. if((access("/Storage/OCPP/OCPPConfiguration",F_OK))==-1)
  14735. {
  14736. outfile = fopen("/Storage/OCPP/OCPPConfiguration" , "w+");
  14737. if(outfile == NULL)
  14738. {
  14739. DEBUG_INFO("Error opening file\n");
  14740. return FALSE;
  14741. }
  14742. /*Core Profile*/
  14743. //AllowOfflineTxForUnknownId
  14744. ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemAccessibility = 1;
  14745. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemName, "AllowOfflineTxForUnknownId");
  14746. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemData, "FALSE" );
  14747. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","AllowOfflineTxForUnknownId", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemData);
  14748. //AuthorizationCacheEnabled
  14749. ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemAccessibility = 1;
  14750. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemName, "AuthorizationCacheEnabled");
  14751. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemData, "FALSE" );
  14752. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","AuthorizationCacheEnabled", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemData);
  14753. //AuthorizeRemoteTxRequests
  14754. ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemAccessibility = 0;
  14755. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemName, "AuthorizeRemoteTxRequests");
  14756. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemData, "FALSE" );
  14757. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","AuthorizeRemoteTxRequests", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemData);
  14758. //BlinkRepeat
  14759. ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemAccessibility = 1;
  14760. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemName, "BlinkRepeat");
  14761. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemData, "0" );
  14762. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","BlinkRepeat", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemData);
  14763. //ClockAlignedDataInterval
  14764. ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemAccessibility = 1;
  14765. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemName, "ClockAlignedDataInterval");
  14766. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemData, "0" );
  14767. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ClockAlignedDataInterval", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemData);
  14768. //ConnectionTimeOut
  14769. ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemAccessibility = 1;
  14770. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemName, "ConnectionTimeOut");
  14771. if(ShmSysConfigAndInfo->SysConfig.ModelName[3]=='J')
  14772. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemData, "55" );
  14773. else
  14774. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemData, "180" );
  14775. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ConnectionTimeOut", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemData);
  14776. //GetConfigurationMaxKeys
  14777. ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemAccessibility =0;
  14778. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemName, "GetConfigurationMaxKeys");
  14779. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemData, "%d", _GetConfiguration_CNT);
  14780. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","GetConfigurationMaxKeys", "true", ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemData);
  14781. // HeartbeatInterval
  14782. ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemAccessibility = 1;
  14783. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemName, "HeartbeatInterval");
  14784. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemData, "20" );
  14785. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","HeartbeatInterval", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemData);
  14786. // LightIntensity
  14787. ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemAccessibility = 1;
  14788. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemName, "LightIntensity");
  14789. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemData, "0" );
  14790. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LightIntensity", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemData);
  14791. // LocalAuthorizeOffline
  14792. ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemAccessibility = 1;
  14793. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemName, "LocalAuthorizeOffline");
  14794. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemData, "TRUE" );
  14795. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LocalAuthorizeOffline", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemData);
  14796. // LocalPreAuthorize
  14797. ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemAccessibility = 1;
  14798. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemName, "LocalPreAuthorize");
  14799. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemData, "FALSE" );
  14800. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LocalPreAuthorize", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemData);
  14801. // MaxEnergyOnInvalidId
  14802. ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemAccessibility = 1;
  14803. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemName, "MaxEnergyOnInvalidId");
  14804. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemData, "0" );
  14805. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MaxEnergyOnInvalidId", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemData);
  14806. // MeterValuesAlignedData
  14807. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemAccessibility = 1;
  14808. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemName, "MeterValuesAlignedData");
  14809. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  14810. 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" );
  14811. else
  14812. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, "Current.Import,Energy.Active.Import.Register,Energy.Active.Import.Interval,Power.Active.Import,Voltage,Current.Offered" );
  14813. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValuesAlignedData", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData);
  14814. // MeterValuesAlignedDataMaxLength
  14815. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemAccessibility = 0;
  14816. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemName, "MeterValuesAlignedDataMaxLength");
  14817. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  14818. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemData, "8" );
  14819. else
  14820. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemData, "10" );
  14821. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValuesAlignedDataMaxLength", "true", ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemData);
  14822. // MeterValuesSampledData
  14823. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemAccessibility = 1;
  14824. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemName, "MeterValuesSampledData");
  14825. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  14826. 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" );
  14827. else
  14828. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, "Current.Import,Energy.Active.Import.Register,Energy.Active.Import.Interval,Power.Active.Import,Voltage,Current.Offered" );
  14829. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValuesSampledData", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData);
  14830. // MeterValuesSampledDataMaxLength
  14831. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemAccessibility = 0;
  14832. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemName, "MeterValuesSampledDataMaxLength");
  14833. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  14834. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemData, "8" );
  14835. else
  14836. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemData, "10" );
  14837. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValuesSampledDataMaxLength", "true", ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemData);
  14838. // MeterValueSampleInterval
  14839. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemAccessibility = 1;
  14840. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemName, "MeterValueSampleInterval");
  14841. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemData, "30" );
  14842. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValueSampleInterval", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemData);
  14843. // MinimumStatusDuration
  14844. ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemAccessibility = 1;
  14845. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemName, "MinimumStatusDuration");
  14846. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemData, "120" );
  14847. server_cycle_Status = atoi((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemData); //StatusNotification cycle
  14848. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MinimumStatusDuration", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemData);
  14849. // NumberOfConnectors
  14850. ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemAccessibility = 0;
  14851. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemName, "NumberOfConnectors");
  14852. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  14853. {
  14854. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData, "%d", (CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY));
  14855. }
  14856. else
  14857. {
  14858. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData, "%d", AC_QUANTITY);
  14859. }
  14860. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","NumberOfConnectors", "true", ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData);
  14861. // ResetRetries
  14862. ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemAccessibility = 1;
  14863. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemName, "ResetRetries");
  14864. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemData, "3" );
  14865. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ResetRetries", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemData);
  14866. // ConnectorPhaseRotation
  14867. ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemAccessibility = 1;
  14868. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemName, "ConnectorPhaseRotation");
  14869. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "NotApplicable" );
  14870. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ConnectorPhaseRotation", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData);
  14871. // ConnectorPhaseRotationMaxLength
  14872. ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemAccessibility = 0;
  14873. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemName, "ConnectorPhaseRotationMaxLength");
  14874. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemData, "1" );
  14875. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ConnectorPhaseRotationMaxLength", "true", ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemData);
  14876. // StopTransactionOnEVSideDisconnect
  14877. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemAccessibility = 0;
  14878. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemName, "StopTransactionOnEVSideDisconnect");
  14879. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemData, "TRUE" );
  14880. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTransactionOnEVSideDisconnect", "true", ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemData);
  14881. // StopTransactionOnInvalidId
  14882. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemAccessibility = 1; //1;
  14883. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemName, "StopTransactionOnInvalidId");
  14884. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemData, "FALSE" );
  14885. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTransactionOnInvalidId", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemData);
  14886. // StopTxnAlignedData
  14887. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemAccessibility = 1;
  14888. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemName, "StopTxnAlignedData");
  14889. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemData, "" );
  14890. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTxnAlignedData", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemData);
  14891. // StopTxnAlignedDataMaxLength
  14892. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemAccessibility = 0;
  14893. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemName, "StopTxnAlignedDataMaxLength");
  14894. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemData, "0" );
  14895. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTxnAlignedDataMaxLength", "true", ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemData);
  14896. // StopTxnSampledData
  14897. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemAccessibility = 1;
  14898. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemName, "StopTxnSampledData");
  14899. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  14900. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Current.Import,Energy.Active.Import.Interval,Power.Active.Import,Voltage,SoC" );
  14901. else
  14902. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Current.Import,Energy.Active.Import.Interval,Power.Active.Import,Voltage" );
  14903. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTxnSampledData", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData);
  14904. // StopTxnSampledDataMaxLength
  14905. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemAccessibility = 0;
  14906. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemName, "StopTxnSampledDataMaxLength");
  14907. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  14908. {
  14909. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemData, "%d", 7);
  14910. }
  14911. else
  14912. {
  14913. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemData, "%d", 9);
  14914. }
  14915. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTxnSampledDataMaxLength", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemData);
  14916. // SupportedFeatureProfiles
  14917. ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemAccessibility = 0;
  14918. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemName, "SupportedFeatureProfiles");
  14919. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemData, "Core,FirmwareManagement,LocalAuthListManagement,Reservation,SmartCharging,RemoteTrigger" );
  14920. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","SupportedFeatureProfiles", "true", ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemData);
  14921. // SupportedFeatureProfilesMaxLength
  14922. ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemAccessibility = 0;
  14923. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemName, "SupportedFeatureProfilesMaxLength");
  14924. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemData, "6" );
  14925. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","SupportedFeatureProfilesMaxLength", "true", ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemData);
  14926. // TransactionMessageAttempts
  14927. ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemAccessibility = 1;
  14928. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemName, "TransactionMessageAttempts");
  14929. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData, "3" );
  14930. TransactionMessageAttemptsValue = atoi((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData);
  14931. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","TransactionMessageAttempts", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData);
  14932. // TransactionMessageRetryInterval
  14933. ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemAccessibility = 1;
  14934. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemName, "TransactionMessageRetryInterval");
  14935. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData, "60" );
  14936. TransactionMessageRetryIntervalValue = atoi((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData);
  14937. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","TransactionMessageRetryInterval", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData);
  14938. // UnlockConnectorOnEVSideDisconnect
  14939. ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemAccessibility = 0;
  14940. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemName, "UnlockConnectorOnEVSideDisconnect");
  14941. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemData, "TRUE" );
  14942. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","UnlockConnectorOnEVSideDisconnect", "true", ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemData);
  14943. // WebSocketPingInterval
  14944. ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemAccessibility = 1;
  14945. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemName, "WebSocketPingInterval");
  14946. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemData, "30" );
  14947. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","WebSocketPingInterval", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemData);
  14948. // QueueOffLineMeterValues
  14949. ShmOCPP16Data->ConfigurationTable.CoreProfile[QueueOffLineMeterValues].ItemAccessibility = 1;
  14950. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[QueueOffLineMeterValues].ItemName, "QueueOffLineMeterValues");
  14951. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[QueueOffLineMeterValues].ItemData, "FALSE" );
  14952. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","QueueOffLineMeterValues", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[QueueOffLineMeterValues].ItemData);
  14953. // AuthorizationKey
  14954. ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationKey].ItemAccessibility = 1;
  14955. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationKey].ItemName, "AuthorizationKey");
  14956. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationKey].ItemData, (char*)ShmSysConfigAndInfo->SysConfig.OcppSecurityPassword);
  14957. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","AuthorizationKey", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationKey].ItemData);
  14958. // SecurityProfile
  14959. ShmOCPP16Data->ConfigurationTable.CoreProfile[SecurityProfile].ItemAccessibility = 1;
  14960. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SecurityProfile].ItemName, "SecurityProfile");
  14961. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SecurityProfile].ItemData, "%d", ShmSysConfigAndInfo->SysConfig.OcppSecurityProfile);
  14962. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","SecurityProfile", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[SecurityProfile].ItemData);
  14963. // DefaultPrice
  14964. ShmOCPP16Data->ConfigurationTable.CoreProfile[DefaultPrice].ItemAccessibility = 1;
  14965. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[DefaultPrice].ItemName, "DefaultPrice");
  14966. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[DefaultPrice].ItemData, "" );
  14967. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","DefaultPrice", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[DefaultPrice].ItemData);
  14968. // CustomDisplayCostAndPrice
  14969. ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemAccessibility = 1;
  14970. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemName, "CustomDisplayCostAndPrice");
  14971. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemData, "FALSE" );
  14972. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","CustomDisplayCostAndPrice", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemData);
  14973. // CustomIdleFeeAfterStop
  14974. ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemAccessibility = 1;
  14975. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemName, "CustomIdleFeeAfterStop");
  14976. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemData, "FALSE" );
  14977. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","CustomIdleFeeAfterStop", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemData);
  14978. // TimeOffset
  14979. ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffset].ItemAccessibility = 1;
  14980. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffset].ItemName, "TimeOffset");
  14981. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffset].ItemData, "+00:00" );
  14982. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","TimeOffset", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffset].ItemData);
  14983. // NextTimeOffsetTransitionDateTime
  14984. ShmOCPP16Data->ConfigurationTable.CoreProfile[NextTimeOffsetTransitionDateTime].ItemAccessibility = 1;
  14985. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NextTimeOffsetTransitionDateTime].ItemName, "NextTimeOffsetTransitionDateTime");
  14986. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NextTimeOffsetTransitionDateTime].ItemData, " " );
  14987. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","NextTimeOffsetTransitionDateTime", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[NextTimeOffsetTransitionDateTime].ItemData);
  14988. // TimeOffsetNextTransition
  14989. ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffsetNextTransition].ItemAccessibility = 1;
  14990. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffsetNextTransition].ItemName, "TimeOffsetNextTransition");
  14991. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffsetNextTransition].ItemData, "+00:00" );
  14992. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","TimeOffsetNextTransition", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffsetNextTransition].ItemData);
  14993. // SystemUptimeSec
  14994. ShmOCPP16Data->ConfigurationTable.CoreProfile[SystemUptimeSec].ItemAccessibility = 1;
  14995. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SystemUptimeSec].ItemName, "SystemUptimeSec");
  14996. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SystemUptimeSec].ItemData, "0" );
  14997. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","SystemUptimeSec", "true", ShmOCPP16Data->ConfigurationTable.CoreProfile[SystemUptimeSec].ItemData);
  14998. // FreeVend
  14999. ShmOCPP16Data->ConfigurationTable.CoreProfile[FreeVend].ItemAccessibility = 1;
  15000. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[FreeVend].ItemName, "FreeVend");
  15001. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[FreeVend].ItemData, (ShmSysConfigAndInfo->SysConfig.AuthorisationMode?"TRUE":"FALSE") );
  15002. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","FreeVend", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[FreeVend].ItemData);
  15003. // FreeVendIdtag
  15004. ShmOCPP16Data->ConfigurationTable.CoreProfile[FreeVendIdtag].ItemAccessibility = 1;
  15005. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[FreeVendIdtag].ItemName, "FreeVendIdtag");
  15006. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[FreeVendIdtag].ItemData, "FreeVendIdtag" );
  15007. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","FreeVendIdtag", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[FreeVendIdtag].ItemData);
  15008. // OcppServer
  15009. ShmOCPP16Data->ConfigurationTable.CoreProfile[OcppServer].ItemAccessibility = 1;
  15010. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[OcppServer].ItemName, "OcppServer");
  15011. memcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[OcppServer].ItemData, (char*)ShmSysConfigAndInfo->SysConfig.OcppServerURL, 500);
  15012. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","OcppServer", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[OcppServer].ItemData);
  15013. // MaintainServer
  15014. ShmOCPP16Data->ConfigurationTable.CoreProfile[MaintainServer].ItemAccessibility = 1;
  15015. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MaintainServer].ItemName, "MaintainServer");
  15016. memcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MaintainServer].ItemData, (char*)ShmSysConfigAndInfo->SysConfig.MaintainServerURL, 500);
  15017. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MaintainServer", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[MaintainServer].ItemData);
  15018. // StatusNotificationPeriodically
  15019. ShmOCPP16Data->ConfigurationTable.CoreProfile[StatusNotificationPeriodically].ItemAccessibility = 1;
  15020. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StatusNotificationPeriodically].ItemName, "StatusNotificationPeriodically");
  15021. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StatusNotificationPeriodically].ItemData, "FALSE" );
  15022. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StatusNotificationPeriodically", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[StatusNotificationPeriodically].ItemData);
  15023. // StatusNotificationInterval
  15024. ShmOCPP16Data->ConfigurationTable.CoreProfile[StatusNotificationInterval].ItemAccessibility = 1;
  15025. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StatusNotificationInterval].ItemName, "StatusNotificationInterval");
  15026. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StatusNotificationInterval].ItemData, "120" );
  15027. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StatusNotificationInterval", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[StatusNotificationInterval].ItemData);
  15028. // PreAuthAmount
  15029. ShmOCPP16Data->ConfigurationTable.CoreProfile[PreAuthAmount].ItemAccessibility = 1;
  15030. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[PreAuthAmount].ItemName, "PreAuthAmount");
  15031. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[PreAuthAmount].ItemData, "888" );
  15032. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","PreAuthAmount", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[PreAuthAmount].ItemData);
  15033. // isEnableLocalPowerSharing
  15034. ShmOCPP16Data->ConfigurationTable.CoreProfile[isEnableLocalPowerSharing].ItemAccessibility = 1;
  15035. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[isEnableLocalPowerSharing].ItemName, "isEnableLocalPowerSharing");
  15036. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[isEnableLocalPowerSharing].ItemData, "%d", ShmSysConfigAndInfo->SysConfig.isEnableLocalPowerSharing);
  15037. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","isEnableLocalPowerSharing", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[isEnableLocalPowerSharing].ItemData);
  15038. // PowerSharingServerIP
  15039. ShmOCPP16Data->ConfigurationTable.CoreProfile[PowerSharingServerIP].ItemAccessibility = 1;
  15040. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[PowerSharingServerIP].ItemName, "PowerSharingServerIP");
  15041. memcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[PowerSharingServerIP].ItemData, (char*)ShmSysConfigAndInfo->SysConfig.PowerSharingServerIP, 500);
  15042. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","PowerSharingServerIP", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[PowerSharingServerIP].ItemData);
  15043. // EVCCID_PREFIX
  15044. ShmOCPP16Data->ConfigurationTable.CoreProfile[EVCCID_PREFIX].ItemAccessibility = 1;
  15045. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[EVCCID_PREFIX].ItemName, "EVCCID_PREFIX");
  15046. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[EVCCID_PREFIX].ItemData, "" );
  15047. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","EVCCID_PREFIX", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[EVCCID_PREFIX].ItemData);
  15048. // OffLineMaxChargingPower
  15049. ShmOCPP16Data->ConfigurationTable.CoreProfile[OffLineMaxChargingPower].ItemAccessibility = 1;
  15050. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[OffLineMaxChargingPower].ItemName, "OffLineMaxChargingPower");
  15051. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[OffLineMaxChargingPower].ItemData, "0" );
  15052. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","OffLineMaxChargingPower", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[OffLineMaxChargingPower].ItemData);
  15053. // Configuration Version
  15054. ShmOCPP16Data->ConfigurationTable.CoreProfile[ConfigurationVersion].ItemAccessibility = 0;
  15055. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConfigurationVersion].ItemName, "ConfigurationVersion");
  15056. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConfigurationVersion].ItemData, "%d", confVersion);
  15057. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ConfigurationVersion", "true", ShmOCPP16Data->ConfigurationTable.CoreProfile[ConfigurationVersion].ItemData);
  15058. // Charging profile refresh interval
  15059. ShmOCPP16Data->ConfigurationTable.CoreProfile[CharingProfileRefreshInterval].ItemAccessibility = 1;
  15060. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CharingProfileRefreshInterval].ItemName, "CharingProfileRefreshInterval");
  15061. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CharingProfileRefreshInterval].ItemData, "30");
  15062. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","CharingProfileRefreshInterval", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[CharingProfileRefreshInterval].ItemData);
  15063. // Ocpp Software certificated version
  15064. ShmOCPP16Data->ConfigurationTable.CoreProfile[OcppSoftwareVersion].ItemAccessibility = 0;
  15065. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[OcppSoftwareVersion].ItemName, "OcppSoftwareVersion");
  15066. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[OcppSoftwareVersion].ItemData, "%s", "V1.00");
  15067. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","OcppSoftwareVersion", "true", ShmOCPP16Data->ConfigurationTable.CoreProfile[OcppSoftwareVersion].ItemData);
  15068. //* Local Auth List Management Profile*/
  15069. #if 0
  15070. //For OCTT Test Case
  15071. ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemAccessibility = 1;
  15072. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemName, "LocalAuthorizationListEnabled");
  15073. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "TRUE" );
  15074. #endif
  15075. #if 1
  15076. //LocalAuthListEnabled
  15077. ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemAccessibility = 1;
  15078. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemName, "LocalAuthListEnabled");
  15079. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "TRUE" );
  15080. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LocalAuthListEnabled", "false", ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData);
  15081. #endif
  15082. //LocalAuthListMaxLength
  15083. ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemAccessibility = 0;
  15084. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemName, "LocalAuthListMaxLength");
  15085. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemData, "100000" );
  15086. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LocalAuthListMaxLength", "true", ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemData);
  15087. //SendLocalListMaxLength
  15088. ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemAccessibility = 0;
  15089. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemName, "SendLocalListMaxLength");
  15090. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemData, "1000" );
  15091. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","SendLocalListMaxLength", "true", ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemData);
  15092. //ReserveConnectorZeroSupported
  15093. ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemAccessibility = 0;
  15094. strcpy((char *)ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemName, "ReserveConnectorZeroSupported");
  15095. strcpy((char *)ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemData, "FALSE" );
  15096. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ReserveConnectorZeroSupported", "true", ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemData);
  15097. //* Smart Charging Profile */
  15098. //ChargeProfileMaxStackLevel
  15099. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemAccessibility = 0;
  15100. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemName, "ChargeProfileMaxStackLevel");
  15101. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemData, "8" );
  15102. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ChargeProfileMaxStackLevel", "true", ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemData);
  15103. // ChargingScheduleAllowedChargingRateUnit
  15104. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemAccessibility = 0;
  15105. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemName, "ChargingScheduleAllowedChargingRateUnit");
  15106. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemData, "Current,Power" );
  15107. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ChargingScheduleAllowedChargingRateUnit", "true", ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemData);
  15108. // ChargingScheduleMaxPeriods
  15109. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemAccessibility = 0;
  15110. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemName, "ChargingScheduleMaxPeriods");
  15111. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemData, "10" );
  15112. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ChargingScheduleMaxPeriods", "true", ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemData);
  15113. // ConnectorSwitch3to1PhaseSupported
  15114. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemAccessibility = 0;
  15115. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemName, "ConnectorSwitch3to1PhaseSupported");
  15116. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemData, "FALSE" );
  15117. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ConnectorSwitch3to1PhaseSupported", "true", ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemData);
  15118. // MaxChargingProfilesInstalled
  15119. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemAccessibility = 0;
  15120. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemName, "MaxChargingProfilesInstalled");
  15121. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemData, "50" );
  15122. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MaxChargingProfilesInstalled", "true", ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemData);
  15123. fclose(outfile);
  15124. }
  15125. else
  15126. {
  15127. //DEBUG_INFO("../Storage/OCPP/OCPPConfiguration EXit\n");
  15128. char keystr[60]={0};
  15129. char readonlystr[10]={0};
  15130. char valuestr[256]={0};
  15131. fp = fopen("/Storage/OCPP/OCPPConfiguration" , "r");
  15132. if(fp == NULL) {
  15133. DEBUG_INFO("Error opening file");
  15134. return FALSE;
  15135. }
  15136. while( fgets (str, ARRAY_SIZE(str), fp)!=NULL )
  15137. {
  15138. //DEBUG_INFO("Get Configuration \n");
  15139. if(strlen(str) > 0)
  15140. {
  15141. str[strlen(str) - 1] = '\0'; // eat the newline fgets() stores
  15142. //*************************key*********************************/
  15143. if(strstr(str, "key") != NULL)
  15144. {
  15145. loc = strstr(str, "key");
  15146. c = 0;
  15147. memset(sstr ,0, ARRAY_SIZE(sstr) );
  15148. while ((loc[strlen("key")+3+c] != '\"') && (c < (ARRAY_SIZE(sstr)-1)))
  15149. {
  15150. sstr[c] = loc[strlen("key")+3+c];
  15151. c++;
  15152. }
  15153. sstr[c] = '\0';
  15154. strcpy(keystr,sstr);
  15155. }
  15156. //*************************readonly*********************************/
  15157. if(strstr(str, "readonly") != NULL)
  15158. {
  15159. loc = strstr(str, "readonly");
  15160. c = 0;
  15161. memset(sstr ,0, ARRAY_SIZE(sstr) );
  15162. while ((loc[strlen("readonly")+2+c] != ',') && (c < (ARRAY_SIZE(sstr)-1)))
  15163. {
  15164. sstr[c] = loc[strlen("readonly")+2+c];
  15165. c++;
  15166. }
  15167. sstr[c] = '\0';
  15168. strcpy(readonlystr,sstr);
  15169. }
  15170. //*************************value*********************************/
  15171. if(strstr(str, "value") != NULL)
  15172. {
  15173. loc = strstr(str, "value");
  15174. c = 0;
  15175. memset(sstr ,0, ARRAY_SIZE(sstr) );
  15176. while ((loc[strlen("value")+3+c] != '\"') && (c < (ARRAY_SIZE(sstr)-1)))
  15177. {
  15178. sstr[c] = loc[strlen("value")+3+c];
  15179. c++;
  15180. }
  15181. sstr[c] = '\0';
  15182. strcpy(valuestr,sstr);
  15183. }
  15184. // DEBUG_INFO("keystr=%s\n",keystr);
  15185. // DEBUG_INFO("readonlystr=%s\n",readonlystr);
  15186. // DEBUG_INFO("valuestr=%s\n",valuestr);
  15187. if(strcmp(keystr, "AllowOfflineTxForUnknownId") == 0)
  15188. {
  15189. //Charger.AllowOfflineTxForUnknownId = (value.toLowerCase().equals("true")?true:false);
  15190. ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  15191. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemData, "%s", valuestr );
  15192. // DEBUG_INFO("AllowOfflineTxForUnknownId setting\n");
  15193. // DEBUG_INFO("AllowOfflineTxForUnknownId setting\n");
  15194. }
  15195. if(strcmp(keystr, "AuthorizationCacheEnabled") == 0)
  15196. {
  15197. //Charger.AuthorizationCacheEnabled = (value.toLowerCase().equals("true")?true:false);
  15198. ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  15199. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemData, "%s", valuestr );
  15200. }
  15201. if(strcmp(keystr, "AuthorizeRemoteTxRequests") == 0)
  15202. {
  15203. ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  15204. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemData, "%s", valuestr );
  15205. }
  15206. if(strcmp(keystr, "BlinkRepeat") == 0)
  15207. {
  15208. //Charger.BlinkRepeat = Integer.parseInt(value);
  15209. ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  15210. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemData, "%d", atoi(valuestr) );
  15211. }
  15212. if(strcmp(keystr, "ClockAlignedDataInterval") == 0)
  15213. {
  15214. ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  15215. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemData, "%d", atoi(valuestr) );
  15216. }
  15217. if(strcmp(keystr, "ConnectionTimeOut") == 0 )
  15218. {
  15219. ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  15220. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemData, "%d", atoi(valuestr));
  15221. }
  15222. if(strcmp(keystr, "GetConfigurationMaxKeys") == 0)
  15223. {
  15224. ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  15225. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemData, "%d", (atoi(valuestr)!=GetConfigurationMaxKeysNUM?GetConfigurationMaxKeysNUM:atoi(valuestr)));
  15226. }
  15227. if(strcmp(keystr, "HeartbeatInterval") == 0)
  15228. {
  15229. ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  15230. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemData, "%d", atoi(valuestr));
  15231. HeartBeatWaitTime = atoi(valuestr);
  15232. }
  15233. if(strcmp(keystr, "LightIntensity") == 0)
  15234. {
  15235. ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  15236. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemData, "%d", atoi(valuestr));
  15237. }
  15238. if(strcmp(keystr, "LocalAuthorizeOffline") == 0)
  15239. {
  15240. ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  15241. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemData, "%s", valuestr );
  15242. }
  15243. if(strcmp(keystr, "LocalPreAuthorize") == 0)
  15244. {
  15245. ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  15246. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemData, "%s", valuestr );
  15247. }
  15248. if(strcmp(keystr, "MaxEnergyOnInvalidId") == 0)
  15249. {
  15250. ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  15251. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemData, "%d", atoi(valuestr) );
  15252. }
  15253. if(strcmp(keystr, "MeterValuesAlignedData") == 0)
  15254. {
  15255. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  15256. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, "%s", valuestr );
  15257. }
  15258. if(strcmp(keystr, "MeterValuesAlignedDataMaxLength") == 0)
  15259. {
  15260. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  15261. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemData, "%d", atoi(valuestr));
  15262. }
  15263. if(strcmp(keystr, "MeterValuesSampledData") == 0 )
  15264. {
  15265. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  15266. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, "%s", valuestr );
  15267. }
  15268. if(strcmp(keystr, "MeterValuesSampledDataMaxLength") == 0)
  15269. {
  15270. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  15271. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemData, "%d", atoi(valuestr));
  15272. }
  15273. if(strcmp(keystr, "MeterValueSampleInterval") == 0)
  15274. {
  15275. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  15276. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemData, "%d", atoi(valuestr));
  15277. }
  15278. if(strcmp(keystr, "MinimumStatusDuration") == 0)
  15279. {
  15280. ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  15281. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemData, "%d", atoi(valuestr) );
  15282. server_cycle_Status = atoi(valuestr); //StatusNotification cycle
  15283. }
  15284. if(strcmp(keystr, "NumberOfConnectors") == 0)
  15285. {
  15286. ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  15287. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData, "%d", atoi(valuestr) );
  15288. }
  15289. if(strcmp(keystr, "ResetRetries") == 0)
  15290. {
  15291. ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  15292. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemData, "%d", atoi(valuestr) );
  15293. }
  15294. if(strcmp(keystr, "ConnectorPhaseRotation") == 0)
  15295. {
  15296. ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  15297. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "%s", valuestr );
  15298. }
  15299. if(strcmp(keystr, "ConnectorPhaseRotationMaxLength") == 0)
  15300. {
  15301. ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  15302. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemData, "%d", atoi(valuestr) );
  15303. }
  15304. if(strcmp(keystr, "StopTransactionOnEVSideDisconnect") == 0)
  15305. {
  15306. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  15307. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemData, "%s", valuestr );
  15308. }
  15309. if(strcmp(keystr, "StopTransactionOnInvalidId") == 0)
  15310. {
  15311. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  15312. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemData, "%s", valuestr );
  15313. }
  15314. if(strcmp(keystr, "StopTxnAlignedData") == 0)
  15315. {
  15316. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  15317. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemData, "%s", valuestr );
  15318. }
  15319. if(strcmp(keystr, "StopTxnAlignedDataMaxLength") == 0)
  15320. {
  15321. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  15322. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemData, "%d", atoi(valuestr) );
  15323. }
  15324. if(strcmp(keystr, "StopTxnSampledData") == 0)
  15325. {
  15326. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  15327. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "%s", valuestr );
  15328. }
  15329. if(strcmp(keystr, "StopTxnSampledDataMaxLength") == 0)
  15330. {
  15331. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  15332. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemData, "%d", atoi(valuestr) );
  15333. }
  15334. if(strcmp(keystr, "SupportedFeatureProfiles") == 0)
  15335. {
  15336. ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  15337. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemData, "%s", valuestr );
  15338. }
  15339. if(strcmp(keystr, "SupportedFeatureProfilesMaxLength") == 0)
  15340. {
  15341. ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  15342. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemData, "%d", atoi(valuestr) );
  15343. }
  15344. if(strcmp(keystr, "TransactionMessageAttempts") == 0)
  15345. {
  15346. ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  15347. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData, "%d", atoi(valuestr) );
  15348. TransactionMessageAttemptsValue = atoi(valuestr);
  15349. }
  15350. if(strcmp(keystr, "TransactionMessageRetryInterval") == 0)
  15351. {
  15352. ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemAccessibility= (strcmp(readonlystr, "true")==0) ? 0 : 1;
  15353. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData, "%d", atoi(valuestr) );
  15354. TransactionMessageRetryIntervalValue = atoi(valuestr);
  15355. }
  15356. if(strcmp(keystr, "UnlockConnectorOnEVSideDisconnect") == 0)
  15357. {
  15358. ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  15359. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemData, "%s", valuestr );
  15360. }
  15361. if(strcmp(keystr, "WebSocketPingInterval") == 0)
  15362. {
  15363. ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  15364. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemData, "%d", atoi(valuestr) );
  15365. }
  15366. if(strcmp(keystr, "QueueOffLineMeterValues") == 0)
  15367. {
  15368. ShmOCPP16Data->ConfigurationTable.CoreProfile[QueueOffLineMeterValues].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  15369. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[QueueOffLineMeterValues].ItemData, "%s", valuestr);
  15370. }
  15371. if(strcmp(keystr, "AuthorizationKey") == 0)
  15372. {
  15373. ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationKey].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  15374. //sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationKey].ItemData, "%s", valuestr);
  15375. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationKey].ItemData, "%s", ShmSysConfigAndInfo->SysConfig.OcppSecurityPassword);
  15376. }
  15377. if(strcmp(keystr, "SecurityProfile") == 0)
  15378. {
  15379. ShmOCPP16Data->ConfigurationTable.CoreProfile[SecurityProfile].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  15380. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SecurityProfile].ItemData, "%d", ShmSysConfigAndInfo->SysConfig.OcppSecurityProfile);
  15381. }
  15382. if(strcmp(keystr, "DefaultPrice") == 0)
  15383. {
  15384. ShmOCPP16Data->ConfigurationTable.CoreProfile[DefaultPrice].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  15385. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[DefaultPrice].ItemData, "%s", valuestr);
  15386. }
  15387. if(strcmp(keystr, "CustomDisplayCostAndPrice") == 0)
  15388. {
  15389. ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  15390. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemData, "%s", valuestr);
  15391. }
  15392. if(strcmp(keystr, "CustomIdleFeeAfterStop") == 0)
  15393. {
  15394. ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  15395. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemData, "%s", valuestr);
  15396. }
  15397. if(strcmp(keystr, "TimeOffset") == 0)
  15398. {
  15399. ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffset].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  15400. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffset].ItemData, "%s", valuestr);
  15401. }
  15402. if(strcmp(keystr, "NextTimeOffsetTransitionDateTime") == 0)
  15403. {
  15404. ShmOCPP16Data->ConfigurationTable.CoreProfile[NextTimeOffsetTransitionDateTime].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  15405. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NextTimeOffsetTransitionDateTime].ItemData, "%s", valuestr);
  15406. }
  15407. if(strcmp(keystr, "TimeOffsetNextTransition") == 0)
  15408. {
  15409. ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffsetNextTransition].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  15410. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffsetNextTransition].ItemData, "%s", valuestr);
  15411. }
  15412. if(strcmp(keystr, "SystemUptimeSec") == 0)
  15413. {
  15414. ShmOCPP16Data->ConfigurationTable.CoreProfile[SystemUptimeSec].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  15415. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SystemUptimeSec].ItemData, "%s", valuestr);
  15416. }
  15417. if(strcmp(keystr, "FreeVend") == 0)
  15418. {
  15419. ShmOCPP16Data->ConfigurationTable.CoreProfile[FreeVend].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  15420. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[FreeVend].ItemData, "%s", (ShmSysConfigAndInfo->SysConfig.AuthorisationMode ? "TRUE" : "FALSE"));
  15421. }
  15422. if(strcmp(keystr, "FreeVendIdtag") == 0)
  15423. {
  15424. ShmOCPP16Data->ConfigurationTable.CoreProfile[FreeVendIdtag].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  15425. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[FreeVendIdtag].ItemData, "%s", valuestr);
  15426. }
  15427. if(strcmp(keystr, "OcppServer") == 0)
  15428. {
  15429. ShmOCPP16Data->ConfigurationTable.CoreProfile[OcppServer].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  15430. memcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[OcppServer].ItemData, (char *)ShmSysConfigAndInfo->SysConfig.OcppServerURL, 500);
  15431. }
  15432. if(strcmp(keystr, "MaintainServer") == 0)
  15433. {
  15434. ShmOCPP16Data->ConfigurationTable.CoreProfile[MaintainServer].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  15435. memcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MaintainServer].ItemData, (char *)ShmSysConfigAndInfo->SysConfig.MaintainServerURL,500);
  15436. }
  15437. if(strcmp(keystr, "StatusNotificationPeriodically") == 0)
  15438. {
  15439. ShmOCPP16Data->ConfigurationTable.CoreProfile[StatusNotificationPeriodically].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  15440. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StatusNotificationPeriodically].ItemData, "%s", valuestr);
  15441. }
  15442. if(strcmp(keystr, "StatusNotificationInterval") == 0)
  15443. {
  15444. ShmOCPP16Data->ConfigurationTable.CoreProfile[StatusNotificationInterval].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  15445. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StatusNotificationInterval].ItemData, "%d", atoi(valuestr));
  15446. }
  15447. if(strcmp(keystr, "PreAuthAmount") == 0)
  15448. {
  15449. ShmOCPP16Data->ConfigurationTable.CoreProfile[PreAuthAmount].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  15450. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[PreAuthAmount].ItemData, "%.2f", atof(valuestr));
  15451. }
  15452. if(strcmp(keystr, "isEnableLocalPowerSharing") == 0)
  15453. {
  15454. ShmOCPP16Data->ConfigurationTable.CoreProfile[isEnableLocalPowerSharing].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  15455. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[isEnableLocalPowerSharing].ItemData, "%d", ShmSysConfigAndInfo->SysConfig.isEnableLocalPowerSharing);
  15456. }
  15457. if(strcmp(keystr, "PowerSharingServerIP") == 0)
  15458. {
  15459. ShmOCPP16Data->ConfigurationTable.CoreProfile[PowerSharingServerIP].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  15460. memcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[PowerSharingServerIP].ItemData, (char *)ShmSysConfigAndInfo->SysConfig.PowerSharingServerIP,500);
  15461. }
  15462. if(strcmp(keystr, "EVCCID_PREFIX") == 0)
  15463. {
  15464. ShmOCPP16Data->ConfigurationTable.CoreProfile[EVCCID_PREFIX].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  15465. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[EVCCID_PREFIX].ItemData, "%s", valuestr);
  15466. }
  15467. if(strcmp(keystr, "OffLineMaxChargingPower") == 0)
  15468. {
  15469. ShmOCPP16Data->ConfigurationTable.CoreProfile[OffLineMaxChargingPower].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  15470. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[OffLineMaxChargingPower].ItemData, "%s", valuestr);
  15471. }
  15472. if(strcmp(keystr, "ConfigurationVersion") == 0)
  15473. {
  15474. ShmOCPP16Data->ConfigurationTable.CoreProfile[ConfigurationVersion].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  15475. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConfigurationVersion].ItemData, "%d", atoi(valuestr));
  15476. }
  15477. if(strcmp(keystr, "CharingProfileRefreshInterval") == 0)
  15478. {
  15479. ShmOCPP16Data->ConfigurationTable.CoreProfile[CharingProfileRefreshInterval].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  15480. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CharingProfileRefreshInterval].ItemData, "%s", valuestr);
  15481. }
  15482. if(strcmp(keystr, "OcppSoftwareVersion") == 0)
  15483. {
  15484. ShmOCPP16Data->ConfigurationTable.CoreProfile[OcppSoftwareVersion].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  15485. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[OcppSoftwareVersion].ItemData, "%s", valuestr);
  15486. }
  15487. if(strcmp(keystr, "LocalAuthListEnabled") == 0)
  15488. {
  15489. ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  15490. sprintf((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "%s", valuestr );
  15491. }
  15492. if(strcmp(keystr, "LocalAuthListMaxLength") == 0)
  15493. {
  15494. ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  15495. sprintf((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemData, "%d", atoi(valuestr) );
  15496. }
  15497. if(strcmp(keystr, "SendLocalListMaxLength") == 0)
  15498. {
  15499. ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  15500. sprintf((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemData, "%d", atoi(valuestr) );
  15501. }
  15502. if(strcmp(keystr, "ReserveConnectorZeroSupported") == 0)
  15503. {
  15504. ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  15505. sprintf((char *)ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemData, "%s", valuestr );
  15506. }
  15507. if(strcmp(keystr, "ChargeProfileMaxStackLevel") == 0)
  15508. {
  15509. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  15510. sprintf((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemData, "%d", atoi(valuestr) );
  15511. }
  15512. if(strcmp(keystr, "ChargingScheduleAllowedChargingRateUnit") == 0)
  15513. {
  15514. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  15515. sprintf((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemData, "%s", valuestr );
  15516. }
  15517. if(strcmp(keystr, "ChargingScheduleMaxPeriods") == 0)
  15518. {
  15519. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  15520. sprintf((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemData, "%d", atoi(valuestr) );
  15521. }
  15522. if(strcmp(keystr, "ConnectorSwitch3to1PhaseSupported") == 0)
  15523. {
  15524. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  15525. sprintf((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemData, "%s", valuestr);
  15526. }
  15527. if(strcmp(keystr, "MaxChargingProfilesInstalled") == 0)
  15528. {
  15529. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  15530. sprintf((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemData, "%d", atoi(valuestr) );
  15531. }
  15532. }
  15533. }
  15534. fclose(fp);
  15535. }
  15536. if(atoi((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConfigurationVersion].ItemData) == confVersion)
  15537. {
  15538. return PASS;
  15539. }
  15540. else
  15541. {
  15542. return FAIL;
  15543. }
  15544. }
  15545. void StoreConfigurationTable(void)
  15546. {
  15547. FILE *outfile;
  15548. outfile = fopen("/Storage/OCPP/OCPPConfiguration" , "w+");
  15549. if(outfile == NULL)
  15550. {
  15551. DEBUG_INFO("Error opening file");
  15552. return ;
  15553. }
  15554. /*Core Profile*/
  15555. //AllowOfflineTxForUnknownId
  15556. /*
  15557. ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemAccessibility = 1;
  15558. printf("AllowoddlineTXForUnknownId type: %d \n", ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemAccessibility);
  15559. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemName, "AllowOfflineTxForUnknownId");
  15560. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemData, "TRUE" );
  15561. */
  15562. //DEBUG_INFO("data=%s\n",data);
  15563. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","AllowOfflineTxForUnknownId", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemData);
  15564. //AuthorizationCacheEnabled
  15565. /*
  15566. ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemAccessibility = 1;
  15567. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemName, "AuthorizationCacheEnabled");
  15568. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemData, "FALSE" );
  15569. */
  15570. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","AuthorizationCacheEnabled", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemData);
  15571. //AuthorizeRemoteTxRequests
  15572. /*
  15573. ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemAccessibility = 0;
  15574. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemName, "AuthorizeRemoteTxRequests");
  15575. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemData, "TRUE" );
  15576. */
  15577. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","AuthorizeRemoteTxRequests", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemData);
  15578. //BlinkRepeat
  15579. /*
  15580. ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemAccessibility = 1;
  15581. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemName, "BlinkRepeat");
  15582. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemData, "0" );
  15583. */
  15584. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","BlinkRepeat", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemData);
  15585. //ClockAlignedDataInterval
  15586. /*
  15587. ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemAccessibility = 1;
  15588. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemName, "ClockAlignedDataInterval");
  15589. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemData, "0" );
  15590. */
  15591. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ClockAlignedDataInterval", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemData);
  15592. //ConnectionTimeOut
  15593. /*
  15594. ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemAccessibility = 1;
  15595. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemName, "ConnectionTimeOut");
  15596. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemData, "180" );
  15597. */
  15598. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ConnectionTimeOut", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemData);
  15599. //GetConfigurationMaxKeys
  15600. /*
  15601. ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemAccessibility =0;
  15602. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemName, "GetConfigurationMaxKeys");
  15603. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemData, "43" );
  15604. */
  15605. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","GetConfigurationMaxKeys", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemData);
  15606. // HeartbeatInterval
  15607. /*
  15608. ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemAccessibility = 1;
  15609. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemName, "HeartbeatInterval");
  15610. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemData, "10" );
  15611. */
  15612. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","HeartbeatInterval", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemData);
  15613. // LightIntensity
  15614. /*
  15615. ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemAccessibility = 1;
  15616. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemName, "LightIntensity");
  15617. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemData, "0" );
  15618. */
  15619. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LightIntensity", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemData);
  15620. // LocalAuthorizeOffline
  15621. /*
  15622. ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemAccessibility = 0;
  15623. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemName, "LocalAuthorizeOffline");
  15624. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemData, "TRUE" );
  15625. */
  15626. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LocalAuthorizeOffline", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemData);
  15627. // LocalPreAuthorize
  15628. /*
  15629. ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemAccessibility = 0;
  15630. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemName, "LocalPreAuthorize");
  15631. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemData, "FALSE" );
  15632. */
  15633. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LocalPreAuthorize", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemData);
  15634. // MaxEnergyOnInvalidId
  15635. /*
  15636. ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemAccessibility = 1;
  15637. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemName, "MaxEnergyOnInvalidId");
  15638. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemData, "0" );
  15639. */
  15640. //ShmSysConfigAndInfo->SysConfig.OfflineMaxChargeEnergy = 0;
  15641. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MaxEnergyOnInvalidId", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemData);
  15642. // MeterValuesAlignedData
  15643. /*
  15644. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemAccessibility = 1;
  15645. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemName, "MeterValuesAlignedData");
  15646. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, "Current.Export,Energy.Active.Export.Interval,Power.Active.Export,Voltage,SOC" );
  15647. */
  15648. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValuesAlignedData", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData);
  15649. // MeterValuesAlignedDataMaxLength
  15650. /*
  15651. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemAccessibility = 0;
  15652. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemName, "MeterValuesAlignedDataMaxLength");
  15653. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemData, "5" );
  15654. */
  15655. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValuesAlignedDataMaxLength", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemData);
  15656. // MeterValuesSampledData
  15657. /*
  15658. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemAccessibility = 1;
  15659. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemName, "MeterValuesSampledData");
  15660. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, "Current.Export,Energy.Active.Export.Interval,Power.Active.Export,Voltage,SOC" );
  15661. */
  15662. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValuesSampledData", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData);
  15663. // MeterValuesSampledDataMaxLength
  15664. /*
  15665. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemAccessibility = 0;
  15666. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemName, "MeterValuesSampledDataMaxLength");
  15667. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemData, "5" );
  15668. */
  15669. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValuesSampledDataMaxLength", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemData);
  15670. // MeterValueSampleInterval
  15671. /*
  15672. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemAccessibility = 1;
  15673. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemName, "MeterValueSampleInterval");
  15674. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemData, "10" );
  15675. */
  15676. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValueSampleInterval", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemData);
  15677. // MinimumStatusDuration
  15678. /*
  15679. ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemAccessibility = 1;
  15680. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemName, "MinimumStatusDuration");
  15681. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemData, "0" );
  15682. */
  15683. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MinimumStatusDuration", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemData);
  15684. // NumberOfConnectors
  15685. /*
  15686. ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemAccessibility = 0;
  15687. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemName, "NumberOfConnectors");
  15688. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  15689. {
  15690. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData, "%d", (CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY));
  15691. }
  15692. else
  15693. {
  15694. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData, "%d", AC_QUANTITY);
  15695. }
  15696. */
  15697. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","NumberOfConnectors", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData);
  15698. // ResetRetries
  15699. /*
  15700. ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemAccessibility = 1;
  15701. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemName, "ResetRetries");
  15702. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemData, "3" );
  15703. */
  15704. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ResetRetries", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemData);
  15705. // ConnectorPhaseRotation
  15706. /*
  15707. ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemAccessibility = 1;
  15708. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemName, "ConnectorPhaseRotation");
  15709. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "NotApplicable" );
  15710. */
  15711. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ConnectorPhaseRotation", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData);
  15712. // ConnectorPhaseRotationMaxLength
  15713. /*
  15714. ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemAccessibility = 0;
  15715. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemName, "ConnectorPhaseRotationMaxLength");
  15716. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemData, "1" );
  15717. */
  15718. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ConnectorPhaseRotationMaxLength", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemData);
  15719. // StopTransactionOnEVSideDisconnect
  15720. /*
  15721. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemAccessibility = 0;
  15722. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemName, "StopTransactionOnEVSideDisconnect");
  15723. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemData, "TRUE" );
  15724. */
  15725. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTransactionOnEVSideDisconnect", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemData);
  15726. // StopTransactionOnInvalidId
  15727. /*
  15728. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemAccessibility = 0;
  15729. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemName, "StopTransactionOnInvalidId");
  15730. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemData, "FALSE" );
  15731. */
  15732. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTransactionOnInvalidId", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemData);
  15733. // StopTxnAlignedData
  15734. /*
  15735. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemAccessibility = 1;
  15736. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemName, "StopTxnAlignedData");
  15737. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemData, "Energy.Active.Import.Register" );
  15738. */
  15739. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTxnAlignedData", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemData);
  15740. // StopTxnAlignedDataMaxLength
  15741. /*
  15742. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemAccessibility = 0;
  15743. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemName, "StopTxnAlignedDataMaxLength");
  15744. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemData, "0" );
  15745. */
  15746. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTxnAlignedDataMaxLength", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemData);
  15747. // StopTxnSampledData
  15748. /*
  15749. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemAccessibility = 1;
  15750. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemName, "StopTxnSampledData");
  15751. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Energy.Active.Import.Register" );
  15752. */
  15753. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTxnSampledData", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData);
  15754. // StopTxnSampledDataMaxLength
  15755. /*
  15756. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemAccessibility = 0;
  15757. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemName, "StopTxnSampledDataMaxLength");
  15758. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemData, "0" );
  15759. */
  15760. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTxnSampledDataMaxLength", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemData);
  15761. // SupportedFeatureProfiles
  15762. /*
  15763. ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemAccessibility = 0;
  15764. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemName, "SupportedFeatureProfiles");
  15765. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemData, "Core,FirmwareManagement,LocalAuthListManagement,Reservation,SmartCharging,RemoteTrigger" );
  15766. */
  15767. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","SupportedFeatureProfiles", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemData);
  15768. // SupportedFeatureProfilesMaxLength
  15769. /*
  15770. ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemAccessibility = 0;
  15771. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemName, "SupportedFeatureProfilesMaxLength");
  15772. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemData, "6" );
  15773. */
  15774. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","SupportedFeatureProfilesMaxLength", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemData);
  15775. // TransactionMessageAttempts
  15776. /*
  15777. ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemAccessibility = 1;
  15778. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemName, "TransactionMessageAttempts");
  15779. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData, "3" );
  15780. */
  15781. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","TransactionMessageAttempts", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData);
  15782. // TransactionMessageRetryInterval
  15783. /*
  15784. ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemAccessibility = 1;
  15785. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemName, "TransactionMessageRetryInterval");
  15786. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData, "60" );
  15787. */
  15788. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","TransactionMessageRetryInterval", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData);
  15789. // UnlockConnectorOnEVSideDisconnect
  15790. /*
  15791. ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemAccessibility = 0;
  15792. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemName, "UnlockConnectorOnEVSideDisconnect");
  15793. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemData, "TRUE" );
  15794. */
  15795. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","UnlockConnectorOnEVSideDisconnect", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemData);
  15796. // WebSocketPingInterval
  15797. /*
  15798. ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemAccessibility = 1;
  15799. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemName, "WebSocketPingInterval");
  15800. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemData, "30" );
  15801. */
  15802. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","WebSocketPingInterval", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemData);
  15803. // QueueOffLineMeterValues
  15804. /*
  15805. ShmOCPP16Data->ConfigurationTable.CoreProfile[QueueOffLineMeterValues].ItemAccessibility = 0;
  15806. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[QueueOffLineMeterValues].ItemName, "QueueOffLineMeterValues");
  15807. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[QueueOffLineMeterValues].ItemData, "TRUE" );
  15808. */
  15809. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","QueueOffLineMeterValues", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[QueueOffLineMeterValues].ItemData);
  15810. // AuthorizationKey
  15811. /*
  15812. ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationKey].ItemAccessibility = 1;
  15813. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationKey].ItemName, "AuthorizationKey");
  15814. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationKey].ItemData, "0" );
  15815. */
  15816. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","AuthorizationKey", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationKey].ItemData);
  15817. // SecurityProfile
  15818. /*
  15819. ShmOCPP16Data->ConfigurationTable.CoreProfile[SecurityProfile].ItemAccessibility = 1;
  15820. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SecurityProfile].ItemName, "SecurityProfile");
  15821. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SecurityProfile].ItemData, "30" );
  15822. */
  15823. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","SecurityProfile", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SecurityProfile].ItemData);
  15824. // DefaultPrice
  15825. /*
  15826. ShmOCPP16Data->ConfigurationTable.CoreProfile[DefaultPrice].ItemAccessibility = 1;
  15827. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[DefaultPrice].ItemName, "DefaultPrice");
  15828. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[DefaultPrice].ItemData, "" );
  15829. */
  15830. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","DefaultPrice", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[DefaultPrice].ItemData);
  15831. // CustomDisplayCostAndPrice
  15832. /*
  15833. ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemAccessibility = 1;
  15834. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemName, "CustomDisplayCostAndPrice");
  15835. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemData, "FALSE" );
  15836. */
  15837. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","CustomDisplayCostAndPrice", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemData);
  15838. // CustomIdleFeeAfterStop
  15839. /*
  15840. ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemAccessibility = 1;
  15841. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemName, "CustomIdleFeeAfterStop");
  15842. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemData, "FALSE" );
  15843. */
  15844. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","CustomIdleFeeAfterStop", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemData);
  15845. // TimeOffset
  15846. /*
  15847. ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffset].ItemAccessibility = 1;
  15848. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffset].ItemName, "TimeOffset");
  15849. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffset].ItemData, "FALSE" );
  15850. */
  15851. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","TimeOffset", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffset].ItemData);
  15852. // NextTimeOffsetTransitionDateTime
  15853. /*
  15854. ShmOCPP16Data->ConfigurationTable.CoreProfile[NextTimeOffsetTransitionDateTime].ItemAccessibility = 1;
  15855. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NextTimeOffsetTransitionDateTime].ItemName, "NextTimeOffsetTransitionDateTime");
  15856. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NextTimeOffsetTransitionDateTime].ItemData, "FALSE" );
  15857. */
  15858. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","NextTimeOffsetTransitionDateTime", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NextTimeOffsetTransitionDateTime].ItemData);
  15859. // TimeOffsetNextTransition
  15860. /*
  15861. ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffsetNextTransition].ItemAccessibility = 1;
  15862. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffsetNextTransition].ItemName, "TimeOffsetNextTransition");
  15863. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffsetNextTransition].ItemData, "FALSE" );
  15864. */
  15865. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","TimeOffsetNextTransition", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffsetNextTransition].ItemData);
  15866. // SystemUptimeSec
  15867. /*
  15868. ShmOCPP16Data->ConfigurationTable.CoreProfile[SystemUptimeSec].ItemAccessibility = 1;
  15869. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SystemUptimeSec].ItemName, "SystemUptimeSec");
  15870. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SystemUptimeSec].ItemData, "0" );
  15871. */
  15872. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","SystemUptimeSec", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SystemUptimeSec].ItemData);
  15873. // FreeVend
  15874. /*
  15875. ShmOCPP16Data->ConfigurationTable.CoreProfile[FreeVend].ItemAccessibility = 1;
  15876. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[FreeVend].ItemName, "FreeVend");
  15877. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[FreeVend].ItemData, "FALSE" );
  15878. */
  15879. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","FreeVend", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[FreeVend].ItemData);
  15880. // FreeVendIdtag
  15881. /*
  15882. ShmOCPP16Data->ConfigurationTable.CoreProfile[FreeVendIdtag].ItemAccessibility = 1;
  15883. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[FreeVendIdtag].ItemName, "FreeVendIdtag");
  15884. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[FreeVendIdtag].ItemData, "FreeVendIdtag" );
  15885. */
  15886. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","FreeVendIdtag", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[FreeVendIdtag].ItemData);
  15887. // OcppServer
  15888. /*
  15889. ShmOCPP16Data->ConfigurationTable.CoreProfile[OcppServer].ItemAccessibility = 1;
  15890. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[OcppServer].ItemName, "OcppServer");
  15891. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[OcppServer].ItemData, "FALSE" );
  15892. */
  15893. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","OcppServer", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[OcppServer].ItemData);
  15894. // MaintainServer
  15895. /*
  15896. ShmOCPP16Data->ConfigurationTable.CoreProfile[MaintainServer].ItemAccessibility = 1;
  15897. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MaintainServer].ItemName, "MaintainServer");
  15898. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MaintainServer].ItemData, "FALSE" );
  15899. */
  15900. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MaintainServer", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MaintainServer].ItemData);
  15901. // StatusNotificationPeriodically
  15902. /*
  15903. ShmOCPP16Data->ConfigurationTable.CoreProfile[StatusNotificationPeriodically].ItemAccessibility =0;
  15904. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StatusNotificationPeriodically].ItemName, "StatusNotificationPeriodically");
  15905. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StatusNotificationPeriodically].ItemData, "FALSE" );
  15906. */
  15907. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StatusNotificationPeriodically", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StatusNotificationPeriodically].ItemData);
  15908. // StatusNotificationInterval
  15909. /*
  15910. ShmOCPP16Data->ConfigurationTable.CoreProfile[StatusNotificationInterval].ItemAccessibility = 1;
  15911. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StatusNotificationInterval].ItemName, "StatusNotificationInterval");
  15912. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StatusNotificationInterval].ItemData, "120" );
  15913. */
  15914. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StatusNotificationInterval", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StatusNotificationInterval].ItemData);
  15915. // PreAuthAmount
  15916. /*
  15917. ShmOCPP16Data->ConfigurationTable.CoreProfile[PreAuthAmount].ItemAccessibility = 1;
  15918. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[PreAuthAmount].ItemName, "PreAuthAmount");
  15919. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[PreAuthAmount].ItemData, "120" );
  15920. */
  15921. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","PreAuthAmount", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[PreAuthAmount].ItemData);
  15922. // isEnableLocalPowerSharing
  15923. /*
  15924. ShmOCPP16Data->ConfigurationTable.CoreProfile[isEnableLocalPowerSharing].ItemAccessibility = 1;
  15925. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[isEnableLocalPowerSharing].ItemName, "isEnableLocalPowerSharing");
  15926. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[isEnableLocalPowerSharing].ItemData, "0" );
  15927. */
  15928. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","isEnableLocalPowerSharing", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[isEnableLocalPowerSharing].ItemData);
  15929. // PowerSharingServerIP
  15930. /*
  15931. ShmOCPP16Data->ConfigurationTable.CoreProfile[PowerSharingServerIP].ItemAccessibility = 1;
  15932. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[PowerSharingServerIP].ItemName, "PowerSharingServerIP");
  15933. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[PowerSharingServerIP].ItemData, "" );
  15934. */
  15935. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","PowerSharingServerIP", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[PowerSharingServerIP].ItemData);
  15936. // EVCCID_PREFIX
  15937. /*
  15938. ShmOCPP16Data->ConfigurationTable.CoreProfile[EVCCID_PREFIX].ItemAccessibility = 1;
  15939. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[EVCCID_PREFIX].ItemName, "EVCCID_PREFIX");
  15940. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[EVCCID_PREFIX].ItemData, "" );
  15941. */
  15942. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","EVCCID_PREFIX", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[EVCCID_PREFIX].ItemData);
  15943. // OffLineMaxChargingPower
  15944. /*
  15945. ShmOCPP16Data->ConfigurationTable.CoreProfile[OffLineMaxChargingPower].ItemAccessibility = 1;
  15946. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[OffLineMaxChargingPower].ItemName, "OffLineMaxChargingPower");
  15947. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[OffLineMaxChargingPower].ItemData, "" );
  15948. */
  15949. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","OffLineMaxChargingPower", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[OffLineMaxChargingPower].ItemData);
  15950. // ConfigurationVersion
  15951. /*
  15952. ShmOCPP16Data->ConfigurationTable.CoreProfile[ConfigurationVersion].ItemAccessibility = 1;
  15953. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConfigurationVersion].ItemName, "ConfigurationVersion");
  15954. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConfigurationVersion].ItemData, "1" );
  15955. */
  15956. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ConfigurationVersion", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConfigurationVersion].ItemData);
  15957. // CharingProfileRefreshInterval
  15958. /*
  15959. ShmOCPP16Data->ConfigurationTable.CoreProfile[CharingProfileRefreshInterval].ItemAccessibility = 1;
  15960. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CharingProfileRefreshInterval].ItemName, "CharingProfileRefreshInterval");
  15961. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CharingProfileRefreshInterval].ItemData, "" );
  15962. */
  15963. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","CharingProfileRefreshInterval", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CharingProfileRefreshInterval].ItemData);
  15964. // OcppSoftwareVersion
  15965. /*
  15966. ShmOCPP16Data->ConfigurationTable.CoreProfile[OcppSoftwareVersion].ItemAccessibility = 1;
  15967. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[OcppSoftwareVersion].ItemName, "OcppSoftwareVersion");
  15968. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[OcppSoftwareVersion].ItemData, "" );
  15969. */
  15970. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","OcppSoftwareVersion", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[OcppSoftwareVersion].ItemData);
  15971. //* Local Auth List Management Profile*/
  15972. //LocalAuthListEnabled
  15973. /*
  15974. ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemAccessibility = 1;
  15975. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemName, "LocalAuthListEnabled");
  15976. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "TRUE" );
  15977. */
  15978. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LocalAuthListEnabled", "false", (char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData);
  15979. //LocalAuthListMaxLength
  15980. /*
  15981. ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemAccessibility = 0;
  15982. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemName, "LocalAuthListMaxLength");
  15983. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemData, "500" );
  15984. */
  15985. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LocalAuthListMaxLength", "true", (char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemData);
  15986. //SendLocalListMaxLength
  15987. /*
  15988. ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemAccessibility = 0;
  15989. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemName, "SendLocalListMaxLength");
  15990. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemData, "500" );
  15991. */
  15992. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","SendLocalListMaxLength", "true", (char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemData);
  15993. //ReserveConnectorZeroSupported
  15994. /*
  15995. ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemAccessibility = 0;
  15996. strcpy((char *)ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemName, "ReserveConnectorZeroSupported");
  15997. strcpy((char *)ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemData, "FALSE" );
  15998. */
  15999. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ReserveConnectorZeroSupported", "true", (char *)ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemData);
  16000. //* Smart Charging Profile */
  16001. //ChargeProfileMaxStackLevel
  16002. /*
  16003. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemAccessibility = 0;
  16004. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemName, "ChargeProfileMaxStackLevel");
  16005. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemData, "3" );
  16006. */
  16007. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ChargeProfileMaxStackLevel", "true", (char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemData);
  16008. // ChargingScheduleAllowedChargingRateUnit
  16009. /*
  16010. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemAccessibility = 0;
  16011. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemName, "ChargingScheduleAllowedChargingRateUnit");
  16012. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemData, "Current" );
  16013. */
  16014. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ChargingScheduleAllowedChargingRateUnit", "true", (char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemData);
  16015. // ChargingScheduleMaxPeriods
  16016. /*
  16017. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemAccessibility = 0;
  16018. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemName, "ChargingScheduleMaxPeriods");
  16019. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemData, "10" );
  16020. */
  16021. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ChargingScheduleMaxPeriods", "true", (char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemData);
  16022. // ConnectorSwitch3to1PhaseSupported
  16023. /*
  16024. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemAccessibility = 0;
  16025. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemName, "ConnectorSwitch3to1PhaseSupported");
  16026. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemData, "TRUE" );
  16027. */
  16028. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ConnectorSwitch3to1PhaseSupported", "true", (char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemData);
  16029. // MaxChargingProfilesInstalled
  16030. /*
  16031. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemAccessibility = 0;
  16032. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemName, "MaxChargingProfilesInstalled");
  16033. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemData, "10" );
  16034. */
  16035. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MaxChargingProfilesInstalled", "true", (char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemData);
  16036. fclose(outfile);
  16037. system("/bin/fsync -d /dev/mtdblock13;/bin/sync &");
  16038. }
  16039. void getKeyValue(char *keyReq)
  16040. {
  16041. int isEmpty = FALSE;
  16042. int isKnowKey = FALSE;
  16043. DEBUG_INFO("keyReq = %s\n", keyReq);
  16044. if((keyReq == NULL) || (strlen(keyReq) == 0))
  16045. isEmpty = TRUE;
  16046. if(isEmpty || strcmp(keyReq, "AllowOfflineTxForUnknownId") == 0)
  16047. {
  16048. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_AllowOfflineTxForUnknownId].Item, "AllowOfflineTxForUnknownId");
  16049. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AllowOfflineTxForUnknownId].Key, "AllowOfflineTxForUnknownId");
  16050. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemAccessibility == 1)
  16051. {
  16052. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AllowOfflineTxForUnknownId].ReadOnly, "0"/*"FALSE"*/);
  16053. }
  16054. else
  16055. {
  16056. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AllowOfflineTxForUnknownId].ReadOnly, "1"/*"TRUE"*/);
  16057. }
  16058. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AllowOfflineTxForUnknownId].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemData );
  16059. isKnowKey = TRUE;
  16060. }
  16061. if(isEmpty || strcmp(keyReq, "AuthorizationCacheEnabled") == 0 )
  16062. {
  16063. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_AuthorizationCacheEnabled].Item, "AuthorizationCacheEnabled");
  16064. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizationCacheEnabled].Key, "AuthorizationCacheEnabled");
  16065. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemAccessibility == 1)
  16066. {
  16067. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizationCacheEnabled].ReadOnly, "0"/*"FALSE"*/);
  16068. }
  16069. else
  16070. {
  16071. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizationCacheEnabled].ReadOnly, "1"/*"TRUE"*/);
  16072. }
  16073. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizationCacheEnabled].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemData );
  16074. isKnowKey = TRUE;
  16075. }
  16076. if(isEmpty || strcmp(keyReq, "AuthorizeRemoteTxRequests") == 0 )
  16077. {
  16078. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_AuthorizeRemoteTxRequests].Item, "AuthorizeRemoteTxRequests");
  16079. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizeRemoteTxRequests].Key, "AuthorizeRemoteTxRequests");
  16080. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemAccessibility == 1)
  16081. {
  16082. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizeRemoteTxRequests].ReadOnly, "0"/*"FALSE"*/);
  16083. }
  16084. else
  16085. {
  16086. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizeRemoteTxRequests].ReadOnly, "1"/*"TRUE"*/);
  16087. }
  16088. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizeRemoteTxRequests].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemData );
  16089. isKnowKey = TRUE;
  16090. }
  16091. if(isEmpty || strcmp(keyReq, "BlinkRepeat") == 0 )
  16092. {
  16093. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_BlinkRepeat].Item, "BlinkRepeat");
  16094. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_BlinkRepeat].Key, "BlinkRepeat");
  16095. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemAccessibility == 1)
  16096. {
  16097. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_BlinkRepeat].ReadOnly, "0"/*"FALSE"*/);
  16098. }
  16099. else
  16100. {
  16101. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_BlinkRepeat].ReadOnly, "1"/*"TRUE"*/);
  16102. }
  16103. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_BlinkRepeat].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemData );
  16104. isKnowKey = TRUE;
  16105. }
  16106. if(isEmpty || strcmp(keyReq, "ClockAlignedDataInterval") == 0 )
  16107. {
  16108. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_ClockAlignedDataInterval].Item, "ClockAlignedDataInterval");
  16109. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ClockAlignedDataInterval].Key, "ClockAlignedDataInterval");
  16110. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemAccessibility == 1)
  16111. {
  16112. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ClockAlignedDataInterval].ReadOnly, "0"/*"FALSE"*/);
  16113. }
  16114. else
  16115. {
  16116. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ClockAlignedDataInterval].ReadOnly, "1"/*"TRUE"*/);
  16117. }
  16118. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ClockAlignedDataInterval].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemData );
  16119. isKnowKey = TRUE;
  16120. }
  16121. if(isEmpty || strcmp(keyReq, "ConnectionTimeOut") == 0 )
  16122. {
  16123. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_ConnectionTimeOut].Item, "ConnectionTimeOut");
  16124. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectionTimeOut].Key, "ConnectionTimeOut");
  16125. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemAccessibility == 1)
  16126. {
  16127. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectionTimeOut].ReadOnly, "0"/*"FALSE"*/);
  16128. }
  16129. else
  16130. {
  16131. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectionTimeOut].ReadOnly, "1"/*"TRUE"*/);
  16132. }
  16133. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectionTimeOut].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemData );
  16134. isKnowKey = TRUE;
  16135. }
  16136. if(isEmpty || strcmp(keyReq, "GetConfigurationMaxKeys") == 0 )
  16137. {
  16138. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_GetConfigurationMaxKeys].Item, "GetConfigurationMaxKeys");
  16139. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_GetConfigurationMaxKeys].Key, "GetConfigurationMaxKeys");
  16140. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemAccessibility == 1)
  16141. {
  16142. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_GetConfigurationMaxKeys].ReadOnly, "0"/*"FALSE"*/);
  16143. }
  16144. else
  16145. {
  16146. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_GetConfigurationMaxKeys].ReadOnly, "1"/*"TRUE"*/);
  16147. }
  16148. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_GetConfigurationMaxKeys].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemData );
  16149. isKnowKey = TRUE;
  16150. }
  16151. if(isEmpty || strcmp(keyReq, "HeartbeatInterval") == 0 )
  16152. {
  16153. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_HeartbeatInterval].Item, "HeartbeatInterval");
  16154. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_HeartbeatInterval].Key, "HeartbeatInterval");
  16155. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemAccessibility == 1)
  16156. {
  16157. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_HeartbeatInterval].ReadOnly, "0"/*"FALSE"*/);
  16158. }
  16159. else
  16160. {
  16161. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_HeartbeatInterval].ReadOnly, "1"/*"TRUE"*/);
  16162. }
  16163. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_HeartbeatInterval].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemData );
  16164. isKnowKey = TRUE;
  16165. }
  16166. if(isEmpty || strcmp(keyReq, "LightIntensity") == 0 )
  16167. {
  16168. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_LightIntensity].Item, "LightIntensity");
  16169. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LightIntensity].Key, "LightIntensity");
  16170. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemAccessibility == 1)
  16171. {
  16172. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LightIntensity].ReadOnly, "0"/*"FALSE"*/);
  16173. }
  16174. else
  16175. {
  16176. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LightIntensity].ReadOnly, "1"/*"TRUE"*/);
  16177. }
  16178. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LightIntensity].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemData );
  16179. isKnowKey = TRUE;
  16180. }
  16181. if(isEmpty || strcmp(keyReq, "LocalAuthorizeOffline") == 0 )
  16182. {
  16183. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_LocalAuthorizeOffline].Item, "LocalAuthorizeOffline");
  16184. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthorizeOffline].Key, "LocalAuthorizeOffline");
  16185. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemAccessibility == 1)
  16186. {
  16187. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthorizeOffline].ReadOnly, "0"/*"FALSE"*/);
  16188. }
  16189. else
  16190. {
  16191. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthorizeOffline].ReadOnly, "1"/*"TRUE"*/);
  16192. }
  16193. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthorizeOffline].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemData );
  16194. isKnowKey = TRUE;
  16195. }
  16196. if(isEmpty || strcmp(keyReq, "LocalPreAuthorize") == 0 )
  16197. {
  16198. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_LocalPreAuthorize].Item, "LocalPreAuthorize");
  16199. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalPreAuthorize].Key, "LocalPreAuthorize");
  16200. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemAccessibility == 1)
  16201. {
  16202. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalPreAuthorize].ReadOnly, "0"/*"FALSE"*/);
  16203. }
  16204. else
  16205. {
  16206. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalPreAuthorize].ReadOnly, "1"/*"TRUE"*/);
  16207. }
  16208. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalPreAuthorize].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemData );
  16209. isKnowKey = TRUE;
  16210. }
  16211. if(isEmpty || strcmp(keyReq, "MaxEnergyOnInvalidId") == 0 )
  16212. {
  16213. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_MaxEnergyOnInvalidId].Item, "MaxEnergyOnInvalidId");
  16214. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaxEnergyOnInvalidId].Key, "MaxEnergyOnInvalidId");
  16215. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemAccessibility == 1)
  16216. {
  16217. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaxEnergyOnInvalidId].ReadOnly, "0"/*"FALSE"*/);
  16218. }
  16219. else
  16220. {
  16221. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaxEnergyOnInvalidId].ReadOnly, "1"/*"TRUE"*/);
  16222. }
  16223. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaxEnergyOnInvalidId].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemData );
  16224. isKnowKey = TRUE;
  16225. }
  16226. if(isEmpty || strcmp(keyReq, "MeterValuesAlignedData") == 0 )
  16227. {
  16228. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_MeterValuesAlignedData].Item, "MeterValuesAlignedData");
  16229. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesAlignedData].Key, "MeterValuesAlignedData");
  16230. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemAccessibility == 1)
  16231. {
  16232. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesAlignedData].ReadOnly, "0"/*"FALSE"*/);
  16233. }
  16234. else
  16235. {
  16236. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesAlignedData].ReadOnly, "1"/*"TRUE"*/);
  16237. }
  16238. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesAlignedData].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData );
  16239. isKnowKey = TRUE;
  16240. }
  16241. if(isEmpty || strcmp(keyReq, "MeterValuesAlignedDataMaxLength") == 0 )
  16242. {
  16243. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_MeterValuesAlignedDataMaxLength].Item, "MeterValuesAlignedDataMaxLength");
  16244. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesAlignedDataMaxLength].Key, "MeterValuesAlignedDataMaxLength");
  16245. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemAccessibility == 1)
  16246. {
  16247. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesAlignedDataMaxLength].ReadOnly, "0"/*"FALSE"*/);
  16248. }
  16249. else
  16250. {
  16251. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesAlignedDataMaxLength].ReadOnly, "1"/*"TRUE"*/);
  16252. }
  16253. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesAlignedDataMaxLength].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemData );
  16254. isKnowKey = TRUE;
  16255. }
  16256. if(isEmpty || strcmp(keyReq, "MeterValuesSampledData") == 0 )
  16257. {
  16258. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_MeterValuesSampledData].Item, "MeterValuesSampledData");
  16259. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesSampledData].Key, "MeterValuesSampledData");
  16260. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemAccessibility == 1)
  16261. {
  16262. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesSampledData].ReadOnly, "0"/*"FALSE"*/);
  16263. }
  16264. else
  16265. {
  16266. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesSampledData].ReadOnly, "1"/*"TRUE"*/);
  16267. }
  16268. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesSampledData].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData );
  16269. isKnowKey = TRUE;
  16270. }
  16271. if(isEmpty || strcmp(keyReq, "MeterValuesSampledDataMaxLength") == 0 )
  16272. {
  16273. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_MeterValuesSampledDataMaxLength].Item, "MeterValuesSampledDataMaxLength");
  16274. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesSampledDataMaxLength].Key, "MeterValuesSampledDataMaxLength");
  16275. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemAccessibility == 1)
  16276. {
  16277. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesSampledDataMaxLength].ReadOnly, "0"/*"FALSE"*/);
  16278. }
  16279. else
  16280. {
  16281. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesSampledDataMaxLength].ReadOnly, "1"/*"TRUE"*/);
  16282. }
  16283. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesSampledDataMaxLength].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemData );
  16284. isKnowKey = TRUE;
  16285. }
  16286. if(isEmpty || strcmp(keyReq, "MeterValueSampleInterval") == 0 )
  16287. {
  16288. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_MeterValueSampleInterval].Item, "MeterValueSampleInterval");
  16289. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValueSampleInterval].Key, "MeterValueSampleInterval");
  16290. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemAccessibility == 1)
  16291. {
  16292. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValueSampleInterval].ReadOnly, "0"/*"FALSE"*/);
  16293. }
  16294. else
  16295. {
  16296. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValueSampleInterval].ReadOnly, "1"/*"TRUE"*/);
  16297. }
  16298. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValueSampleInterval].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemData );
  16299. isKnowKey = TRUE;
  16300. }
  16301. if(isEmpty || strcmp(keyReq, "MinimumStatusDuration") == 0 )
  16302. {
  16303. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_MinimumStatusDuration].Item, "MinimumStatusDuration");
  16304. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MinimumStatusDuration].Key, "MinimumStatusDuration");
  16305. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemAccessibility == 1)
  16306. {
  16307. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MinimumStatusDuration].ReadOnly, "0"/*"FALSE"*/);
  16308. }
  16309. else
  16310. {
  16311. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MinimumStatusDuration].ReadOnly, "1"/*"TRUE"*/);
  16312. }
  16313. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MinimumStatusDuration].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[17].ItemData );
  16314. isKnowKey = TRUE;
  16315. }
  16316. if(isEmpty || strcmp(keyReq, "NumberOfConnectors") == 0 )
  16317. {
  16318. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_NumberOfConnectors].Item, "NumberOfConnectors");
  16319. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_NumberOfConnectors].Key, "NumberOfConnectors");
  16320. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemAccessibility == 1)
  16321. {
  16322. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_NumberOfConnectors].ReadOnly, "0"/*"FALSE"*/);
  16323. }
  16324. else
  16325. {
  16326. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_NumberOfConnectors].ReadOnly, "1"/*"TRUE"*/);
  16327. }
  16328. sprintf((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData, "%d", gunTotalNumber);
  16329. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_NumberOfConnectors].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData );
  16330. isKnowKey = TRUE;
  16331. }
  16332. if(isEmpty || strcmp(keyReq, "ResetRetries") == 0 )
  16333. {
  16334. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_ResetRetries].Item, "ResetRetries");
  16335. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ResetRetries].Key, "ResetRetries");
  16336. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemAccessibility == 1)
  16337. {
  16338. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ResetRetries].ReadOnly, "0"/*"FALSE"*/);
  16339. }
  16340. else
  16341. {
  16342. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ResetRetries].ReadOnly, "1"/*"TRUE"*/);
  16343. }
  16344. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ResetRetries].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemData );
  16345. isKnowKey = TRUE;
  16346. }
  16347. if(isEmpty || strcmp(keyReq, "ConnectorPhaseRotation") == 0 )
  16348. {
  16349. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_ConnectorPhaseRotation].Item, "ConnectorPhaseRotation");
  16350. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorPhaseRotation].Key, "ConnectorPhaseRotation");
  16351. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemAccessibility == 1)
  16352. {
  16353. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorPhaseRotation].ReadOnly, "0"/*"FALSE"*/);
  16354. }
  16355. else
  16356. {
  16357. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorPhaseRotation].ReadOnly, "1"/*"TRUE"*/);
  16358. }
  16359. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorPhaseRotation].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData );
  16360. isKnowKey = TRUE;
  16361. }
  16362. if(isEmpty || strcmp(keyReq, "ConnectorPhaseRotationMaxLength") == 0 )
  16363. {
  16364. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_ConnectorPhaseRotationMaxLength].Item, "ConnectorPhaseRotationMaxLength");
  16365. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorPhaseRotationMaxLength].Key, "ConnectorPhaseRotationMaxLength");
  16366. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemAccessibility == 1)
  16367. {
  16368. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorPhaseRotationMaxLength].ReadOnly, "0"/*"FALSE"*/);
  16369. }
  16370. else
  16371. {
  16372. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorPhaseRotationMaxLength].ReadOnly, "1"/*"TRUE"*/);
  16373. }
  16374. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorPhaseRotationMaxLength].Value,(const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemData );
  16375. isKnowKey = TRUE;
  16376. }
  16377. if(isEmpty || strcmp(keyReq, "StopTransactionOnEVSideDisconnect") == 0 )
  16378. {
  16379. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_StopTransactionOnEVSideDisconnect].Item, "StopTransactionOnEVSideDisconnect");
  16380. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTransactionOnEVSideDisconnect].Key, "StopTransactionOnEVSideDisconnect");
  16381. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemAccessibility == 1)
  16382. {
  16383. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTransactionOnEVSideDisconnect].ReadOnly, "0"/*"FALSE"*/);
  16384. }
  16385. else
  16386. {
  16387. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTransactionOnEVSideDisconnect].ReadOnly, "1"/*"TRUE"*/);
  16388. }
  16389. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTransactionOnEVSideDisconnect].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemData );
  16390. isKnowKey = TRUE;
  16391. }
  16392. if(isEmpty || strcmp(keyReq, "StopTransactionOnInvalidId") == 0 )
  16393. {
  16394. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_StopTransactionOnInvalidId].Item, "StopTransactionOnInvalidId");
  16395. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTransactionOnInvalidId].Key, "StopTransactionOnInvalidId");
  16396. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemAccessibility == 1)
  16397. {
  16398. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTransactionOnInvalidId].ReadOnly, "0"/*"FALSE"*/);
  16399. }
  16400. else
  16401. {
  16402. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTransactionOnInvalidId].ReadOnly, "1"/*"TRUE"*/);
  16403. }
  16404. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTransactionOnInvalidId].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemData );
  16405. isKnowKey = TRUE;
  16406. }
  16407. if(isEmpty || strcmp(keyReq, "StopTxnAlignedData") == 0 )
  16408. {
  16409. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_StopTxnAlignedData].Item, "StopTxnAlignedData");
  16410. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnAlignedData].Key, "StopTxnAlignedData");
  16411. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemAccessibility == 1)
  16412. {
  16413. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnAlignedData].ReadOnly, "0"/*"FALSE"*/);
  16414. }
  16415. else
  16416. {
  16417. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnAlignedData].ReadOnly, "1"/*"TRUE"*/);
  16418. }
  16419. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnAlignedData].Value,(const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemData );
  16420. isKnowKey = TRUE;
  16421. }
  16422. if(isEmpty || strcmp(keyReq, "StopTxnAlignedDataMaxLength") == 0 )
  16423. {
  16424. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_StopTxnAlignedDataMaxLength].Item, "StopTxnAlignedDataMaxLength");
  16425. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnAlignedDataMaxLength].Key, "StopTxnAlignedDataMaxLength");
  16426. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemAccessibility == 1)
  16427. {
  16428. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnAlignedDataMaxLength].ReadOnly, "0"/*"FALSE"*/);
  16429. }
  16430. else
  16431. {
  16432. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnAlignedDataMaxLength].ReadOnly, "1"/*"TRUE"*/);
  16433. }
  16434. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnAlignedDataMaxLength].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemData );
  16435. isKnowKey = TRUE;
  16436. }
  16437. if(isEmpty || strcmp(keyReq, "StopTxnSampledData") == 0 )
  16438. {
  16439. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_StopTxnSampledData].Item, "StopTxnSampledData");
  16440. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnSampledData].Key, "StopTxnSampledData");
  16441. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemAccessibility == 1)
  16442. {
  16443. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnSampledData].ReadOnly, "0"/*"FALSE"*/);
  16444. }
  16445. else
  16446. {
  16447. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnSampledData].ReadOnly, "1"/*"TRUE"*/);
  16448. }
  16449. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnSampledData].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData );
  16450. isKnowKey = TRUE;
  16451. }
  16452. if(isEmpty || strcmp(keyReq, "StopTxnSampledDataMaxLength") == 0 )
  16453. {
  16454. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_StopTxnSampledDataMaxLength].Item, "StopTxnSampledDataMaxLength");
  16455. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnSampledDataMaxLength].Key, "StopTxnSampledDataMaxLength");
  16456. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemAccessibility == 1)
  16457. {
  16458. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnSampledDataMaxLength].ReadOnly, "0"/*"FALSE"*/);
  16459. }
  16460. else
  16461. {
  16462. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnSampledDataMaxLength].ReadOnly, "1"/*"TRUE"*/);
  16463. }
  16464. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnSampledDataMaxLength].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemData );
  16465. isKnowKey = TRUE;
  16466. }
  16467. if(isEmpty || strcmp(keyReq, "SupportedFeatureProfiles") == 0 )
  16468. {
  16469. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_SupportedFeatureProfiles].Item, "SupportedFeatureProfiles");
  16470. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SupportedFeatureProfiles].Key, "SupportedFeatureProfiles");
  16471. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemAccessibility == 1)
  16472. {
  16473. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SupportedFeatureProfiles].ReadOnly, "0"/*"FALSE"*/);
  16474. }
  16475. else
  16476. {
  16477. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SupportedFeatureProfiles].ReadOnly, "1"/*"TRUE"*/);
  16478. }
  16479. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SupportedFeatureProfiles].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemData );
  16480. isKnowKey = TRUE;
  16481. }
  16482. if(isEmpty || strcmp(keyReq, "SupportedFeatureProfilesMaxLength") == 0 )
  16483. {
  16484. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_SupportedFeatureProfilesMaxLength].Item, "SupportedFeatureProfilesMaxLength");
  16485. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SupportedFeatureProfilesMaxLength].Key, "SupportedFeatureProfilesMaxLength");
  16486. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemAccessibility == 1)
  16487. {
  16488. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SupportedFeatureProfilesMaxLength].ReadOnly, "0"/*"FALSE"*/);
  16489. }
  16490. else
  16491. {
  16492. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SupportedFeatureProfilesMaxLength].ReadOnly, "1"/*"TRUE"*/);
  16493. }
  16494. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SupportedFeatureProfilesMaxLength].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemData );
  16495. isKnowKey = TRUE;
  16496. }
  16497. if(isEmpty || strcmp(keyReq, "TransactionMessageAttempts") == 0 )
  16498. {
  16499. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_TransactionMessageAttempts].Item, "TransactionMessageAttempts");
  16500. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TransactionMessageAttempts].Key, "TransactionMessageAttempts");
  16501. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemAccessibility == 1)
  16502. {
  16503. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TransactionMessageAttempts].ReadOnly, "0"/*"FALSE"*/);
  16504. }
  16505. else
  16506. {
  16507. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TransactionMessageAttempts].ReadOnly, "1"/*"TRUE"*/);
  16508. }
  16509. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TransactionMessageAttempts].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData );
  16510. isKnowKey = TRUE;
  16511. }
  16512. if(isEmpty || strcmp(keyReq, "TransactionMessageRetryInterval") == 0 )
  16513. {
  16514. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_TransactionMessageRetryInterval].Item, "TransactionMessageRetryInterval");
  16515. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TransactionMessageRetryInterval].Key, "TransactionMessageRetryInterval");
  16516. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemAccessibility == 1)
  16517. {
  16518. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TransactionMessageRetryInterval].ReadOnly, "0"/*"FALSE"*/);
  16519. }
  16520. else
  16521. {
  16522. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TransactionMessageRetryInterval].ReadOnly, "1"/*"TRUE"*/);
  16523. }
  16524. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TransactionMessageRetryInterval].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData );
  16525. isKnowKey = TRUE;
  16526. }
  16527. if(isEmpty || strcmp(keyReq, "UnlockConnectorOnEVSideDisconnect") == 0 )
  16528. {
  16529. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_UnlockConnectorOnEVSideDisconnect].Item, "UnlockConnectorOnEVSideDisconnect");
  16530. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_UnlockConnectorOnEVSideDisconnect].Key, "UnlockConnectorOnEVSideDisconnect");
  16531. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemAccessibility == 1)
  16532. {
  16533. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_UnlockConnectorOnEVSideDisconnect].ReadOnly, "0"/*"FALSE"*/);
  16534. }
  16535. else
  16536. {
  16537. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_UnlockConnectorOnEVSideDisconnect].ReadOnly, "1"/*"TRUE"*/);
  16538. }
  16539. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_UnlockConnectorOnEVSideDisconnect].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemData );
  16540. isKnowKey = TRUE;
  16541. }
  16542. if(isEmpty || strcmp(keyReq, "WebSocketPingInterval") == 0 )
  16543. {
  16544. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_WebSocketPingInterval].Item, "WebSocketPingInterval");
  16545. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_WebSocketPingInterval].Key, "WebSocketPingInterval");
  16546. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemAccessibility == 1)
  16547. {
  16548. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_WebSocketPingInterval].ReadOnly, "0"/*"FALSE"*/);
  16549. }
  16550. else
  16551. {
  16552. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_WebSocketPingInterval].ReadOnly, "1"/*"TRUE"*/);
  16553. }
  16554. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_WebSocketPingInterval].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemData );
  16555. isKnowKey = TRUE;
  16556. }
  16557. if(isEmpty || strcmp(keyReq, "QueueOffLineMeterValues") == 0 )
  16558. {
  16559. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_QueueOffLineMeterValues].Item, "QueueOffLineMeterValues");
  16560. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_QueueOffLineMeterValues].Key, "QueueOffLineMeterValues");
  16561. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[QueueOffLineMeterValues].ItemAccessibility == 1)
  16562. {
  16563. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_QueueOffLineMeterValues].ReadOnly, "0"/*"FALSE"*/);
  16564. }
  16565. else
  16566. {
  16567. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_QueueOffLineMeterValues].ReadOnly, "1"/*"TRUE"*/);
  16568. }
  16569. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_QueueOffLineMeterValues].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[QueueOffLineMeterValues].ItemData );
  16570. isKnowKey = TRUE;
  16571. }
  16572. /*
  16573. if(isEmpty || strcmp(keyReq, "AuthorizationKey") == 0 )
  16574. {
  16575. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_AuthorizationKey].Item, "AuthorizationKey");
  16576. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizationKey].Key, "AuthorizationKey");
  16577. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationKey].ItemAccessibility == 1)
  16578. {
  16579. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizationKey].ReadOnly, "0");
  16580. }
  16581. else
  16582. {
  16583. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizationKey].ReadOnly, "1");
  16584. }
  16585. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizationKey].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationKey].ItemData );
  16586. isKnowKey = TRUE;
  16587. }*/
  16588. if(isEmpty || strcmp(keyReq, "SecurityProfile") == 0 )
  16589. {
  16590. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_SecurityProfile].Item, "SecurityProfile");
  16591. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SecurityProfile].Key, "SecurityProfile");
  16592. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[SecurityProfile].ItemAccessibility == 1)
  16593. {
  16594. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SecurityProfile].ReadOnly, "0"/*"FALSE"*/);
  16595. }
  16596. else
  16597. {
  16598. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SecurityProfile].ReadOnly, "1"/*"TRUE"*/);
  16599. }
  16600. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SecurityProfile].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SecurityProfile].ItemData );
  16601. isKnowKey = TRUE;
  16602. }
  16603. if(isEmpty || strcmp(keyReq, "DefaultPrice") == 0 )
  16604. {
  16605. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_DefaultPrice].Item, "DefaultPrice");
  16606. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_DefaultPrice].Key, "DefaultPrice");
  16607. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[DefaultPrice].ItemAccessibility == 1)
  16608. {
  16609. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_DefaultPrice].ReadOnly, "0"/*"FALSE"*/);
  16610. }
  16611. else
  16612. {
  16613. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_DefaultPrice].ReadOnly, "1"/*"TRUE"*/);
  16614. }
  16615. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_DefaultPrice].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[DefaultPrice].ItemData );
  16616. isKnowKey = TRUE;
  16617. }
  16618. if(isEmpty || strcmp(keyReq, "CustomDisplayCostAndPrice") == 0 )
  16619. {
  16620. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_CustomDisplayCostAndPrice].Item, "CustomDisplayCostAndPrice");
  16621. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_CustomDisplayCostAndPrice].Key, "CustomDisplayCostAndPrice");
  16622. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemAccessibility == 1)
  16623. {
  16624. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_CustomDisplayCostAndPrice].ReadOnly, "0"/*"FALSE"*/);
  16625. }
  16626. else
  16627. {
  16628. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_CustomDisplayCostAndPrice].ReadOnly, "1"/*"TRUE"*/);
  16629. }
  16630. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_CustomDisplayCostAndPrice].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemData );
  16631. isKnowKey = TRUE;
  16632. }
  16633. if(isEmpty || strcmp(keyReq, "CustomIdleFeeAfterStop") == 0 )
  16634. {
  16635. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_CustomIdleFeeAfterStop].Item, "CustomIdleFeeAfterStop");
  16636. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_CustomIdleFeeAfterStop].Key, "CustomIdleFeeAfterStop");
  16637. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemAccessibility == 1)
  16638. {
  16639. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_CustomIdleFeeAfterStop].ReadOnly, "0"/*"FALSE"*/);
  16640. }
  16641. else
  16642. {
  16643. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_CustomIdleFeeAfterStop].ReadOnly, "1"/*"TRUE"*/);
  16644. }
  16645. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_CustomIdleFeeAfterStop].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemData );
  16646. isKnowKey = TRUE;
  16647. }
  16648. if(isEmpty || strcmp(keyReq, "TimeOffset") == 0 )
  16649. {
  16650. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_TimeOffset].Item, "TimeOffset");
  16651. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TimeOffset].Key, "TimeOffset");
  16652. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffset].ItemAccessibility == 1)
  16653. {
  16654. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TimeOffset].ReadOnly, "0"/*"FALSE"*/);
  16655. }
  16656. else
  16657. {
  16658. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TimeOffset].ReadOnly, "1"/*"TRUE"*/);
  16659. }
  16660. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TimeOffset].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffset].ItemData );
  16661. isKnowKey = TRUE;
  16662. }
  16663. if(isEmpty || strcmp(keyReq, "NextTimeOffsetTransitionDateTime") == 0 )
  16664. {
  16665. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_NextTimeOffsetTransitionDateTime].Item, "NextTimeOffsetTransitionDateTime");
  16666. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_NextTimeOffsetTransitionDateTime].Key, "NextTimeOffsetTransitionDateTime");
  16667. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[NextTimeOffsetTransitionDateTime].ItemAccessibility == 1)
  16668. {
  16669. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_NextTimeOffsetTransitionDateTime].ReadOnly, "0"/*"FALSE"*/);
  16670. }
  16671. else
  16672. {
  16673. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_NextTimeOffsetTransitionDateTime].ReadOnly, "1"/*"TRUE"*/);
  16674. }
  16675. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_NextTimeOffsetTransitionDateTime].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NextTimeOffsetTransitionDateTime].ItemData );
  16676. isKnowKey = TRUE;
  16677. }
  16678. if(isEmpty || strcmp(keyReq, "TimeOffsetNextTransition") == 0 )
  16679. {
  16680. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_TimeOffsetNextTransition].Item, "TimeOffsetNextTransition");
  16681. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TimeOffsetNextTransition].Key, "TimeOffsetNextTransition");
  16682. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffsetNextTransition].ItemAccessibility == 1)
  16683. {
  16684. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TimeOffsetNextTransition].ReadOnly, "0"/*"FALSE"*/);
  16685. }
  16686. else
  16687. {
  16688. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TimeOffsetNextTransition].ReadOnly, "1"/*"TRUE"*/);
  16689. }
  16690. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TimeOffsetNextTransition].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffsetNextTransition].ItemData );
  16691. isKnowKey = TRUE;
  16692. }
  16693. if(isEmpty || strcmp(keyReq, "SystemUptimeSec") == 0 )
  16694. {
  16695. struct sysinfo s_info;
  16696. int error = sysinfo(&s_info);
  16697. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_SystemUptimeSec].Item, "SystemUptimeSec");
  16698. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SystemUptimeSec].Key, "SystemUptimeSec");
  16699. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[SystemUptimeSec].ItemAccessibility == 1)
  16700. {
  16701. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SystemUptimeSec].ReadOnly, "0"/*"FALSE"*/);
  16702. }
  16703. else
  16704. {
  16705. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SystemUptimeSec].ReadOnly, "1"/*"TRUE"*/);
  16706. }
  16707. if(error != 0)
  16708. {
  16709. DEBUG_WARN("System uptime get error: %d\n", error);
  16710. }
  16711. else
  16712. {
  16713. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SystemUptimeSec].ItemData, "%ld", s_info.uptime);
  16714. sprintf((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SystemUptimeSec].Value, "%ld", s_info.uptime);
  16715. }
  16716. isKnowKey = TRUE;
  16717. }
  16718. if(isEmpty || strcmp(keyReq, "FreeVend") == 0 )
  16719. {
  16720. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_FreeVend].Item, "FreeVend");
  16721. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_FreeVend].Key, "FreeVend");
  16722. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[FreeVend].ItemAccessibility == 1)
  16723. {
  16724. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_FreeVend].ReadOnly, "0"/*"FALSE"*/);
  16725. }
  16726. else
  16727. {
  16728. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_FreeVend].ReadOnly, "1"/*"TRUE"*/);
  16729. }
  16730. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_FreeVend].Value, (ShmSysConfigAndInfo->SysConfig.AuthorisationMode?"TRUE":"FALSE"));
  16731. isKnowKey = TRUE;
  16732. }
  16733. if(isEmpty || strcmp(keyReq, "FreeVendIdtag") == 0 )
  16734. {
  16735. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_FreeVendIdtag].Item, "FreeVendIdtag");
  16736. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_FreeVendIdtag].Key, "FreeVendIdtag");
  16737. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[FreeVendIdtag].ItemAccessibility == 1)
  16738. {
  16739. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_FreeVendIdtag].ReadOnly, "0"/*"FALSE"*/);
  16740. }
  16741. else
  16742. {
  16743. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_FreeVendIdtag].ReadOnly, "1"/*"TRUE"*/);
  16744. }
  16745. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_FreeVendIdtag].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[FreeVendIdtag].ItemData);
  16746. isKnowKey = TRUE;
  16747. }
  16748. if(isEmpty || strcmp(keyReq, "OcppServer") == 0 )
  16749. {
  16750. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_OcppServer].Item, "OcppServer");
  16751. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_OcppServer].Key, "OcppServer");
  16752. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[OcppServer].ItemAccessibility == 1)
  16753. {
  16754. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_OcppServer].ReadOnly, "0"/*"FALSE"*/);
  16755. }
  16756. else
  16757. {
  16758. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_OcppServer].ReadOnly, "1"/*"TRUE"*/);
  16759. }
  16760. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_OcppServer].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[OcppServer].ItemData);
  16761. isKnowKey = TRUE;
  16762. }
  16763. if(isEmpty || strcmp(keyReq, "MaintainServer") == 0 )
  16764. {
  16765. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_MaintainServer].Item, "MaintainServer");
  16766. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaintainServer].Key, "MaintainServer");
  16767. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MaintainServer].ItemAccessibility == 1)
  16768. {
  16769. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaintainServer].ReadOnly, "0"/*"FALSE"*/);
  16770. }
  16771. else
  16772. {
  16773. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaintainServer].ReadOnly, "1"/*"TRUE"*/);
  16774. }
  16775. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaintainServer].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MaintainServer].ItemData);
  16776. isKnowKey = TRUE;
  16777. }
  16778. if(isEmpty || strcmp(keyReq, "StatusNotificationPeriodically") == 0 )
  16779. {
  16780. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_StatusNotificationPeriodically].Item, "StatusNotificationPeriodically");
  16781. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StatusNotificationPeriodically].Key, "StatusNotificationPeriodically");
  16782. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StatusNotificationPeriodically].ItemAccessibility == 1)
  16783. {
  16784. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StatusNotificationPeriodically].ReadOnly, "0"/*"FALSE"*/);
  16785. }
  16786. else
  16787. {
  16788. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StatusNotificationPeriodically].ReadOnly, "1"/*"TRUE"*/);
  16789. }
  16790. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StatusNotificationPeriodically].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StatusNotificationPeriodically].ItemData );
  16791. isKnowKey = TRUE;
  16792. }
  16793. if(isEmpty || strcmp(keyReq, "StatusNotificationInterval") == 0 )
  16794. {
  16795. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_StatusNotificationInterval].Item, "StatusNotificationInterval");
  16796. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StatusNotificationInterval].Key, "StatusNotificationInterval");
  16797. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StatusNotificationInterval].ItemAccessibility == 1)
  16798. {
  16799. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StatusNotificationInterval].ReadOnly, "0"/*"FALSE"*/);
  16800. }
  16801. else
  16802. {
  16803. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StatusNotificationInterval].ReadOnly, "1"/*"TRUE"*/);
  16804. }
  16805. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StatusNotificationInterval].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StatusNotificationInterval].ItemData );
  16806. isKnowKey = TRUE;
  16807. }
  16808. if(isEmpty || strcmp(keyReq, "PreAuthAmount") == 0 )
  16809. {
  16810. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_PreAuthAmount].Item, "PreAuthAmount");
  16811. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_PreAuthAmount].Key, "PreAuthAmount");
  16812. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[PreAuthAmount].ItemAccessibility == 1)
  16813. {
  16814. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_PreAuthAmount].ReadOnly, "0"/*"FALSE"*/);
  16815. }
  16816. else
  16817. {
  16818. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_PreAuthAmount].ReadOnly, "1"/*"TRUE"*/);
  16819. }
  16820. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_PreAuthAmount].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[PreAuthAmount].ItemData );
  16821. isKnowKey = TRUE;
  16822. }
  16823. if(isEmpty || strcmp(keyReq, "isEnableLocalPowerSharing") == 0 )
  16824. {
  16825. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_isEnableLocalPowerSharing].Item, "isEnableLocalPowerSharing");
  16826. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_isEnableLocalPowerSharing].Key, "isEnableLocalPowerSharing");
  16827. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[isEnableLocalPowerSharing].ItemAccessibility == 1)
  16828. {
  16829. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_isEnableLocalPowerSharing].ReadOnly, "0"/*"FALSE"*/);
  16830. }
  16831. else
  16832. {
  16833. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_isEnableLocalPowerSharing].ReadOnly, "1"/*"TRUE"*/);
  16834. }
  16835. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_isEnableLocalPowerSharing].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[isEnableLocalPowerSharing].ItemData );
  16836. isKnowKey = TRUE;
  16837. }
  16838. if(isEmpty || strcmp(keyReq, "PowerSharingServerIP") == 0 )
  16839. {
  16840. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_PowerSharingServerIP].Item, "PowerSharingServerIP");
  16841. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_PowerSharingServerIP].Key, "PowerSharingServerIP");
  16842. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[PowerSharingServerIP].ItemAccessibility == 1)
  16843. {
  16844. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_PowerSharingServerIP].ReadOnly, "0"/*"FALSE"*/);
  16845. }
  16846. else
  16847. {
  16848. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_PowerSharingServerIP].ReadOnly, "1"/*"TRUE"*/);
  16849. }
  16850. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_PowerSharingServerIP].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[PowerSharingServerIP].ItemData );
  16851. isKnowKey = TRUE;
  16852. }
  16853. if(isEmpty || strcmp(keyReq, "EVCCID_PREFIX") == 0 )
  16854. {
  16855. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_EVCCID_PREFIX].Item, "EVCCID_PREFIX");
  16856. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_EVCCID_PREFIX].Key, "EVCCID_PREFIX");
  16857. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[EVCCID_PREFIX].ItemAccessibility == 1)
  16858. {
  16859. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_EVCCID_PREFIX].ReadOnly, "0"/*"FALSE"*/);
  16860. }
  16861. else
  16862. {
  16863. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_EVCCID_PREFIX].ReadOnly, "1"/*"TRUE"*/);
  16864. }
  16865. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_EVCCID_PREFIX].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[EVCCID_PREFIX].ItemData );
  16866. isKnowKey = TRUE;
  16867. }
  16868. if(isEmpty || strcmp(keyReq, "OffLineMaxChargingPower") == 0 )
  16869. {
  16870. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_OffLineMaxChargingPower].Item, "OffLineMaxChargingPower");
  16871. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_OffLineMaxChargingPower].Key, "OffLineMaxChargingPower");
  16872. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[OffLineMaxChargingPower].ItemAccessibility == 1)
  16873. {
  16874. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_OffLineMaxChargingPower].ReadOnly, "0"/*"FALSE"*/);
  16875. }
  16876. else
  16877. {
  16878. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_OffLineMaxChargingPower].ReadOnly, "1"/*"TRUE"*/);
  16879. }
  16880. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_OffLineMaxChargingPower].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[OffLineMaxChargingPower].ItemData );
  16881. isKnowKey = TRUE;
  16882. }
  16883. if(isEmpty || strcmp(keyReq, "ConfigurationVersion") == 0 )
  16884. {
  16885. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_ConfigurationVersion].Item, "ConfigurationVersion");
  16886. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConfigurationVersion].Key, "ConfigurationVersion");
  16887. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[ConfigurationVersion].ItemAccessibility == 1)
  16888. {
  16889. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConfigurationVersion].ReadOnly, "0"/*"FALSE"*/);
  16890. }
  16891. else
  16892. {
  16893. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConfigurationVersion].ReadOnly, "1"/*"TRUE"*/);
  16894. }
  16895. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConfigurationVersion].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConfigurationVersion].ItemData );
  16896. isKnowKey = TRUE;
  16897. }
  16898. if(isEmpty || strcmp(keyReq, "CharingProfileRefreshInterval") == 0 )
  16899. {
  16900. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_CharingProfileRefreshInterval].Item, "CharingProfileRefreshInterval");
  16901. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_CharingProfileRefreshInterval].Key, "CharingProfileRefreshInterval");
  16902. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[CharingProfileRefreshInterval].ItemAccessibility == 1)
  16903. {
  16904. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_CharingProfileRefreshInterval].ReadOnly, "0"/*"FALSE"*/);
  16905. }
  16906. else
  16907. {
  16908. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_CharingProfileRefreshInterval].ReadOnly, "1"/*"TRUE"*/);
  16909. }
  16910. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_CharingProfileRefreshInterval].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CharingProfileRefreshInterval].ItemData );
  16911. isKnowKey = TRUE;
  16912. }
  16913. if(isEmpty || strcmp(keyReq, "OcppSoftwareVersion") == 0 )
  16914. {
  16915. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_OcppSoftwareVersion].Item, "OcppSoftwareVersion");
  16916. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_OcppSoftwareVersion].Key, "OcppSoftwareVersion");
  16917. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[OcppSoftwareVersion].ItemAccessibility == 1)
  16918. {
  16919. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_OcppSoftwareVersion].ReadOnly, "0"/*"FALSE"*/);
  16920. }
  16921. else
  16922. {
  16923. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_OcppSoftwareVersion].ReadOnly, "1"/*"TRUE"*/);
  16924. }
  16925. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_OcppSoftwareVersion].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[OcppSoftwareVersion].ItemData );
  16926. isKnowKey = TRUE;
  16927. }
  16928. #if 1
  16929. if(isEmpty || strcmp(keyReq, "LocalAuthListEnabled") == 0 )
  16930. {
  16931. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_LocalAuthListEnabled].Item, "LocalAuthListEnabled");
  16932. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListEnabled].Key, "LocalAuthListEnabled");
  16933. if(ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemAccessibility == 1)
  16934. {
  16935. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListEnabled].ReadOnly, "0"/*"FALSE"*/);
  16936. }
  16937. else
  16938. {
  16939. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListEnabled].ReadOnly, "1"/*"TRUE"*/);
  16940. }
  16941. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListEnabled].Value, (const char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData );
  16942. isKnowKey = TRUE;
  16943. }
  16944. #endif
  16945. if(isEmpty || strcmp(keyReq, "LocalAuthListMaxLength") == 0 )
  16946. {
  16947. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_LocalAuthListMaxLength].Item, "LocalAuthListMaxLength");
  16948. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListMaxLength].Key, "LocalAuthListMaxLength");
  16949. if(ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemAccessibility == 1)
  16950. {
  16951. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListMaxLength].ReadOnly, "0"/*"FALSE"*/);
  16952. }
  16953. else
  16954. {
  16955. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListMaxLength].ReadOnly, "1"/*"TRUE"*/);
  16956. }
  16957. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListMaxLength].Value, (const char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemData );
  16958. isKnowKey = TRUE;
  16959. }
  16960. if(isEmpty || strcmp(keyReq, "SendLocalListMaxLength") == 0 )
  16961. {
  16962. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_SendLocalListMaxLength].Item, "SendLocalListMaxLength");
  16963. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SendLocalListMaxLength].Key, "SendLocalListMaxLength");
  16964. if(ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemAccessibility == 1)
  16965. {
  16966. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SendLocalListMaxLength].ReadOnly, "0"/*"FALSE"*/);
  16967. }
  16968. else
  16969. {
  16970. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SendLocalListMaxLength].ReadOnly, "1"/*"TRUE"*/);
  16971. }
  16972. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SendLocalListMaxLength].Value, (const char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemData );
  16973. isKnowKey = TRUE;
  16974. }
  16975. if(isEmpty || strcmp(keyReq, "ReserveConnectorZeroSupported") == 0 )
  16976. {
  16977. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_ReserveConnectorZeroSupported].Item, "ReserveConnectorZeroSupported");
  16978. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ReserveConnectorZeroSupported].Key, "ReserveConnectorZeroSupported");
  16979. if(ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemAccessibility == 1)
  16980. {
  16981. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ReserveConnectorZeroSupported].ReadOnly, "0"/*"FALSE"*/);
  16982. }
  16983. else
  16984. {
  16985. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ReserveConnectorZeroSupported].ReadOnly, "1"/*"TRUE"*/);
  16986. }
  16987. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ReserveConnectorZeroSupported].Value,(const char *)ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemData);
  16988. isKnowKey = TRUE;
  16989. }
  16990. if(isEmpty || strcmp(keyReq, "ChargeProfileMaxStackLevel") == 0 )
  16991. {
  16992. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_ChargeProfileMaxStackLevel].Item, "ChargeProfileMaxStackLevel");
  16993. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargeProfileMaxStackLevel].Key, "ChargeProfileMaxStackLevel");
  16994. if(ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemAccessibility == 1)
  16995. {
  16996. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargeProfileMaxStackLevel].ReadOnly, "0"/*"FALSE"*/);
  16997. }
  16998. else
  16999. {
  17000. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargeProfileMaxStackLevel].ReadOnly, "1"/*"TRUE"*/);
  17001. }
  17002. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargeProfileMaxStackLevel].Value, (const char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemData);
  17003. isKnowKey = TRUE;
  17004. }
  17005. if(isEmpty || strcmp(keyReq, "ChargingScheduleAllowedChargingRateUnit") == 0 )
  17006. {
  17007. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_ChargingScheduleAllowedChargingRateUnit].Item, "ChargingScheduleAllowedChargingRateUnit");
  17008. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargingScheduleAllowedChargingRateUnit].Key, "ChargingScheduleAllowedChargingRateUnit");
  17009. if(ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemAccessibility == 1)
  17010. {
  17011. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargingScheduleAllowedChargingRateUnit].ReadOnly, "0"/*"FALSE"*/);
  17012. }
  17013. else
  17014. {
  17015. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargingScheduleAllowedChargingRateUnit].ReadOnly, "1"/*"TRUE"*/);
  17016. }
  17017. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargingScheduleAllowedChargingRateUnit].Value, (const char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemData);
  17018. isKnowKey = TRUE;
  17019. }
  17020. if(isEmpty || strcmp(keyReq, "ChargingScheduleMaxPeriods") == 0 )
  17021. {
  17022. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_ChargingScheduleMaxPeriods].Item, "ChargingScheduleMaxPeriods");
  17023. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargingScheduleMaxPeriods].Key, "ChargingScheduleMaxPeriods");
  17024. if(ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemAccessibility == 1)
  17025. {
  17026. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargingScheduleMaxPeriods].ReadOnly, "0"/*"FALSE"*/);
  17027. }
  17028. else
  17029. {
  17030. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargingScheduleMaxPeriods].ReadOnly, "1"/*"TRUE"*/);
  17031. }
  17032. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargingScheduleMaxPeriods].Value, (const char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemData);
  17033. isKnowKey = TRUE;
  17034. }
  17035. if(isEmpty || strcmp(keyReq, "ConnectorSwitch3to1PhaseSupported") == 0 )
  17036. {
  17037. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_ConnectorSwitch3to1PhaseSupported].Item, "ConnectorSwitch3to1PhaseSupported");
  17038. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorSwitch3to1PhaseSupported].Key, "ConnectorSwitch3to1PhaseSupported");
  17039. if(ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemAccessibility == 1)
  17040. {
  17041. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorSwitch3to1PhaseSupported].ReadOnly, "0"/*"FALSE"*/);
  17042. }
  17043. else
  17044. {
  17045. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorSwitch3to1PhaseSupported].ReadOnly, "1"/*"TRUE"*/);
  17046. }
  17047. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorSwitch3to1PhaseSupported].Value, (const char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemData);
  17048. isKnowKey = TRUE;
  17049. }
  17050. if(isEmpty || strcmp(keyReq, "MaxChargingProfilesInstalled") == 0 )
  17051. {
  17052. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_MaxChargingProfilesInstalled].Item, "MaxChargingProfilesInstalled");
  17053. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaxChargingProfilesInstalled].Key, "MaxChargingProfilesInstalled");
  17054. if(ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemAccessibility == 1)
  17055. {
  17056. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaxChargingProfilesInstalled].ReadOnly, "0"/*"FLASE"*/);
  17057. }
  17058. else
  17059. {
  17060. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaxChargingProfilesInstalled].ReadOnly, "1"/*"TRUE"*/);
  17061. }
  17062. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaxChargingProfilesInstalled].Value, (const char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemData);
  17063. isKnowKey = TRUE;
  17064. }
  17065. //=========================================================
  17066. if(!isEmpty && !isKnowKey)
  17067. {
  17068. DEBUG_INFO("unKnowIndex =%d\n", UnknownKeynum);
  17069. strcpy(unknownkey[UnknownKeynum], keyReq);
  17070. UnknownKeynum = UnknownKeynum + 1;
  17071. }
  17072. }
  17073. void processUnkownKey(void)
  17074. {
  17075. DEBUG_INFO("processUnkownKey...\n");
  17076. memset(ShmOCPP16Data->GetConfiguration.ResponseUnknownKey, 0 , sizeof(struct StructConfigurationKeyItems)* 10);
  17077. for(int index=0; index < UnknownKeynum; index++)
  17078. {
  17079. if(ShmOCPP16Data->GetConfiguration.ResponseUnknownKey[index].Item[0] == 0)
  17080. {
  17081. strcpy((char *)(ShmOCPP16Data->GetConfiguration.ResponseUnknownKey[index].Item), unknownkey[index]);
  17082. }
  17083. }
  17084. }
  17085. int setKeyValue(char *key, char *value)
  17086. {
  17087. int isSuccess = NotSupported;
  17088. int check_ascii=0;
  17089. char str[501]={0};
  17090. DEBUG_INFO(" setKeyValue %s = %s\n", key, value);
  17091. if(strcmp(key, "AllowOfflineTxForUnknownId") == 0)
  17092. {
  17093. //Charger.AllowOfflineTxForUnknownId = (value.toLowerCase().equals("true")?true:false);
  17094. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemAccessibility == 1)
  17095. {
  17096. strcpy(str, (const char*)value);
  17097. for(int i = 0; str[i]; i++){
  17098. str[i] = tolower(str[i]);
  17099. }
  17100. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  17101. isSuccess = ConfigurationStatus_Accepted;
  17102. }
  17103. else
  17104. {
  17105. isSuccess = ConfigurationStatus_Rejected;
  17106. }
  17107. }
  17108. if(strcmp(key, "AuthorizationCacheEnabled") == 0)
  17109. {
  17110. //Charger.AuthorizationCacheEnabled = (value.toLowerCase().equals("true")?true:false);
  17111. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemAccessibility == 1)
  17112. {
  17113. strcpy(str, (const char*)value);
  17114. for(int i = 0; str[i]; i++){
  17115. str[i] = tolower(str[i]);
  17116. }
  17117. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  17118. isSuccess = ConfigurationStatus_Accepted;
  17119. //updateSetting("AuthorizationCacheEnabled",(char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[1].ItemData);
  17120. }
  17121. else
  17122. {
  17123. isSuccess = ConfigurationStatus_Rejected;
  17124. }
  17125. }
  17126. if(strcmp(key, "AuthorizeRemoteTxRequests") == 0)
  17127. {
  17128. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemAccessibility == 1)
  17129. {
  17130. strcpy(str, (const char*)value);
  17131. for(int i = 0; str[i]; i++)
  17132. {
  17133. str[i] = tolower(str[i]);
  17134. }
  17135. //Charger.AuthorizeRemoteTxRequests = (value.toLowerCase().equals("true")?true:false);
  17136. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  17137. isSuccess = ConfigurationStatus_Accepted;
  17138. }
  17139. else
  17140. {
  17141. isSuccess = ConfigurationStatus_Rejected;
  17142. }
  17143. }
  17144. if(strcmp(key, "BlinkRepeat") == 0)
  17145. {
  17146. //Charger.BlinkRepeat = Integer.parseInt(value);
  17147. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemAccessibility == 1)
  17148. {
  17149. check_ascii = value[0];
  17150. if( (check_ascii < 48) || (check_ascii > 57) )
  17151. {
  17152. isSuccess = ConfigurationStatus_Rejected;
  17153. }
  17154. else
  17155. {
  17156. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemData, "%d", atoi(value) );
  17157. isSuccess = ConfigurationStatus_Accepted;
  17158. }
  17159. }
  17160. else
  17161. {
  17162. isSuccess = ConfigurationStatus_Rejected;
  17163. }
  17164. }
  17165. if(strcmp(key, "ClockAlignedDataInterval") == 0)
  17166. {
  17167. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemAccessibility == 1)
  17168. {
  17169. check_ascii = value[0];
  17170. if( (check_ascii < 48) || (check_ascii > 57) )
  17171. {
  17172. isSuccess = ConfigurationStatus_Rejected;
  17173. }
  17174. else
  17175. {
  17176. if((atoi(value) == 0) || (atoi(value) >= 5))
  17177. {
  17178. //Charger.ClockAlignedDataInterval = Integer.parseInt(value)*1000;
  17179. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemData, "%d", atoi(value) );
  17180. isSuccess = ConfigurationStatus_Accepted;
  17181. }
  17182. else
  17183. isSuccess = ConfigurationStatus_Rejected;
  17184. }
  17185. }
  17186. else
  17187. {
  17188. isSuccess = ConfigurationStatus_Rejected;
  17189. }
  17190. }
  17191. if(strcmp(key, "ConnectionTimeOut") == 0 )
  17192. {
  17193. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemAccessibility == 1)
  17194. {
  17195. check_ascii = value[0];
  17196. if( (check_ascii < 48) || (check_ascii > 57) )
  17197. {
  17198. isSuccess = ConfigurationStatus_Rejected;
  17199. }
  17200. else
  17201. {
  17202. //Charger.ConnectionTimeOut = Integer.parseInt(value)*1000;
  17203. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemData, "%d", atoi(value));
  17204. isSuccess = ConfigurationStatus_Accepted;
  17205. }
  17206. }
  17207. else
  17208. {
  17209. isSuccess = ConfigurationStatus_Rejected;
  17210. }
  17211. }
  17212. if(strcmp(key, "GetConfigurationMaxKeys") == 0)
  17213. {
  17214. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemAccessibility == 1)
  17215. {
  17216. check_ascii = value[0];
  17217. if( (check_ascii < 48) || (check_ascii > 57) )
  17218. {
  17219. isSuccess = ConfigurationStatus_Rejected;
  17220. }
  17221. else
  17222. {
  17223. //Charger.HeartbeatInterval = Integer.parseInt(value)*1000;
  17224. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemData, "%d", atoi(value) );
  17225. isSuccess = ConfigurationStatus_Accepted;
  17226. }
  17227. }
  17228. else
  17229. {
  17230. isSuccess = ConfigurationStatus_Rejected;
  17231. }
  17232. }
  17233. if(strcmp(key, "HeartbeatInterval") == 0)
  17234. {
  17235. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemAccessibility == 1)
  17236. {
  17237. check_ascii = value[0];
  17238. if( (check_ascii < 48) || (check_ascii > 57) )
  17239. {
  17240. isSuccess = ConfigurationStatus_Rejected;
  17241. }
  17242. else
  17243. {
  17244. if((atoi(value) == 0) || (atoi(value) >= 10))
  17245. {
  17246. //Charger.HeartbeatInterval = Integer.parseInt(value)*1000;
  17247. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemData, "%d", atoi(value));
  17248. HeartBeatWaitTime = atoi(value);
  17249. isSuccess = ConfigurationStatus_Accepted;
  17250. }
  17251. else
  17252. {
  17253. isSuccess = ConfigurationStatus_Rejected;
  17254. }
  17255. }
  17256. }
  17257. else
  17258. {
  17259. isSuccess = ConfigurationStatus_Rejected;
  17260. }
  17261. }
  17262. if(strcmp(key, "LightIntensity") == 0)
  17263. {
  17264. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemAccessibility == 1)
  17265. {
  17266. check_ascii = value[0];
  17267. if( (check_ascii < 48) || (check_ascii > 57) )
  17268. {
  17269. isSuccess = ConfigurationStatus_Rejected;
  17270. }
  17271. else
  17272. {
  17273. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemData, "%d", atoi(value) );
  17274. isSuccess = ConfigurationStatus_Accepted;
  17275. }
  17276. }
  17277. else
  17278. {
  17279. isSuccess = ConfigurationStatus_Rejected;
  17280. }
  17281. }
  17282. if(strcmp(key, "LocalAuthorizeOffline") == 0)
  17283. {
  17284. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemAccessibility == 1)
  17285. {
  17286. strcpy(str, (const char*)value);
  17287. for(int i = 0; str[i]; i++)
  17288. {
  17289. str[i] = tolower(str[i]);
  17290. }
  17291. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  17292. isSuccess = ConfigurationStatus_Accepted;
  17293. //updateSetting("LocalAuthorizeOffline", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemData);
  17294. }
  17295. else
  17296. {
  17297. isSuccess = ConfigurationStatus_Rejected;
  17298. }
  17299. }
  17300. if(strcmp(key, "LocalPreAuthorize") == 0)
  17301. {
  17302. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemAccessibility == 1)
  17303. {
  17304. strcpy(str, (const char*)value);
  17305. for(int i = 0; str[i]; i++)
  17306. {
  17307. str[i] = tolower(str[i]);
  17308. }
  17309. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  17310. isSuccess = ConfigurationStatus_Accepted;
  17311. }
  17312. else
  17313. {
  17314. isSuccess = ConfigurationStatus_Rejected;
  17315. }
  17316. }
  17317. if(strcmp(key, "MaxEnergyOnInvalidId") == 0)
  17318. {
  17319. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemAccessibility == 1)
  17320. {
  17321. check_ascii = value[0];
  17322. if( (check_ascii < 48) || (check_ascii > 57) )
  17323. {
  17324. isSuccess = ConfigurationStatus_Rejected;
  17325. }
  17326. else
  17327. {
  17328. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemData, "%d", atoi(value) );
  17329. isSuccess = ConfigurationStatus_Accepted;
  17330. }
  17331. }
  17332. else
  17333. {
  17334. isSuccess = ConfigurationStatus_Rejected;
  17335. }
  17336. }
  17337. if(strcmp(key, "MeterValuesAlignedData") == 0)
  17338. {
  17339. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemAccessibility == 1)
  17340. {
  17341. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, "%s", value );
  17342. isSuccess = ConfigurationStatus_Accepted;
  17343. }
  17344. else
  17345. {
  17346. isSuccess = ConfigurationStatus_Rejected;
  17347. }
  17348. }
  17349. if(strcmp(key, "MeterValuesAlignedDataMaxLength") == 0)
  17350. {
  17351. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemAccessibility == 1)
  17352. {
  17353. check_ascii = value[0];
  17354. if( (check_ascii < 48) || (check_ascii > 57) )
  17355. {
  17356. isSuccess = ConfigurationStatus_Rejected;
  17357. }
  17358. else
  17359. {
  17360. //Charger.MeterValueSampleInterval = Integer.parseInt(value)*1000;
  17361. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemData, "%d", atoi(value));
  17362. isSuccess = ConfigurationStatus_Accepted;
  17363. }
  17364. }
  17365. else
  17366. {
  17367. isSuccess = ConfigurationStatus_Rejected;
  17368. }
  17369. }
  17370. if(strcmp(key, "MeterValuesSampledData") == 0 )
  17371. {
  17372. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemAccessibility == 1)
  17373. {
  17374. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, "%s", value );
  17375. isSuccess = ConfigurationStatus_Accepted;
  17376. }
  17377. else
  17378. {
  17379. isSuccess = ConfigurationStatus_Rejected;
  17380. }
  17381. }
  17382. if(strcmp(key, "MeterValuesSampledDataMaxLength") == 0)
  17383. {
  17384. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemAccessibility == 1)
  17385. {
  17386. check_ascii = value[0];
  17387. if( (check_ascii < 48) || (check_ascii > 57) )
  17388. {
  17389. isSuccess = ConfigurationStatus_Rejected;
  17390. }
  17391. else
  17392. {
  17393. //Charger.MeterValueSampleInterval = Integer.parseInt(value)*1000;
  17394. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemData, "%d", atoi(value));
  17395. isSuccess = ConfigurationStatus_Accepted;
  17396. }
  17397. }
  17398. else
  17399. {
  17400. isSuccess = ConfigurationStatus_Rejected;
  17401. }
  17402. }
  17403. if(strcmp(key, "MeterValueSampleInterval") == 0)
  17404. {
  17405. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemAccessibility == 1)
  17406. {
  17407. check_ascii = value[0];
  17408. if( (check_ascii < 48) || (check_ascii > 57) )
  17409. {
  17410. isSuccess = ConfigurationStatus_Rejected;
  17411. }
  17412. else
  17413. {
  17414. if((atoi(value) == 0) || (atoi(value) >= 3))
  17415. {
  17416. //Charger.MeterValueSampleInterval = Integer.parseInt(value)*1000;
  17417. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemData, "%d", atoi(value));
  17418. isSuccess = ConfigurationStatus_Accepted;
  17419. }
  17420. else
  17421. {
  17422. isSuccess = ConfigurationStatus_Rejected;
  17423. }
  17424. }
  17425. }
  17426. else
  17427. {
  17428. isSuccess = ConfigurationStatus_Rejected;
  17429. }
  17430. }
  17431. if(strcmp(key, "MinimumStatusDuration") == 0)
  17432. {
  17433. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemAccessibility == 1)
  17434. {
  17435. check_ascii = value[0];
  17436. if( (check_ascii < 48) || (check_ascii > 57) )
  17437. {
  17438. isSuccess = ConfigurationStatus_Rejected;
  17439. }
  17440. else
  17441. {
  17442. if(atoi(value) == 0) // MinimumStatusDuration's value can not be 0
  17443. {
  17444. isSuccess = ConfigurationStatus_Rejected;
  17445. }
  17446. else
  17447. {
  17448. //Charger.MinimumStatusDuration = Integer.parseInt(value);
  17449. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemData, "%d", atoi(value) );
  17450. server_cycle_Status = atoi(value); //StatusNotification Cycle
  17451. isSuccess = ConfigurationStatus_Accepted;
  17452. }
  17453. }
  17454. }
  17455. else
  17456. {
  17457. isSuccess = ConfigurationStatus_Rejected;
  17458. }
  17459. }
  17460. if(strcmp(key, "NumberOfConnectors") == 0)
  17461. {
  17462. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemAccessibility == 1)
  17463. {
  17464. check_ascii = value[0];
  17465. if( (check_ascii < 48) || (check_ascii > 57) )
  17466. {
  17467. isSuccess = ConfigurationStatus_Rejected;
  17468. }
  17469. else
  17470. {
  17471. //Charger.ResetRetries = Integer.parseInt(value);
  17472. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData, "%d", atoi(value) );
  17473. isSuccess = ConfigurationStatus_Accepted;
  17474. }
  17475. }
  17476. else
  17477. {
  17478. isSuccess = ConfigurationStatus_Rejected;
  17479. }
  17480. }
  17481. if(strcmp(key, "ResetRetries") == 0)
  17482. {
  17483. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemAccessibility == 1)
  17484. {
  17485. check_ascii = value[0];
  17486. if( (check_ascii < 48) || (check_ascii > 57) )
  17487. {
  17488. isSuccess = ConfigurationStatus_Rejected;
  17489. }
  17490. else
  17491. {
  17492. //Charger.ResetRetries = Integer.parseInt(value);
  17493. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemData, "%d", atoi(value) );
  17494. isSuccess = ConfigurationStatus_Accepted;
  17495. }
  17496. }
  17497. else
  17498. {
  17499. isSuccess = ConfigurationStatus_Rejected;
  17500. }
  17501. }
  17502. if(strcmp(key, "ConnectorPhaseRotation") == 0)
  17503. {
  17504. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemAccessibility == 1)
  17505. {
  17506. strcpy(str, (const char*)value);
  17507. for(int i = 0; str[i]; i++)
  17508. {
  17509. str[i] = tolower(str[i]);
  17510. }
  17511. if(strcmp(str, "notapplicable")== 0)
  17512. {
  17513. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "%s", "NotApplicable" );
  17514. isSuccess = ConfigurationStatus_Accepted;
  17515. }
  17516. else if(strcmp(str, "unknown")== 0)
  17517. {
  17518. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "%s", "Unknown" );
  17519. isSuccess = ConfigurationStatus_Accepted;
  17520. }
  17521. else if(strcmp(str, "rst")== 0)
  17522. {
  17523. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "%s", "RST" );
  17524. isSuccess = ConfigurationStatus_Accepted;
  17525. }
  17526. else if(strcmp(str, "rts")== 0)
  17527. {
  17528. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "%s", "RTS" );
  17529. isSuccess = ConfigurationStatus_Accepted;
  17530. }
  17531. else if(strcmp(str, "srt")== 0)
  17532. {
  17533. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "%s", "SRT" );
  17534. isSuccess = ConfigurationStatus_Accepted;
  17535. }
  17536. else if(strcmp(str, "str")== 0)
  17537. {
  17538. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "%s", "STR" );
  17539. isSuccess = ConfigurationStatus_Accepted;
  17540. }
  17541. else if(strcmp(str, "trs")== 0)
  17542. {
  17543. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "%s", "TRS" );
  17544. isSuccess = ConfigurationStatus_Accepted;
  17545. }
  17546. else if(strcmp(str, "tsr")== 0)
  17547. {
  17548. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "%s", "TSR" );
  17549. isSuccess = ConfigurationStatus_Accepted;
  17550. }
  17551. else
  17552. {
  17553. isSuccess = ConfigurationStatus_Rejected;
  17554. }
  17555. }
  17556. else
  17557. {
  17558. isSuccess = ConfigurationStatus_Rejected;
  17559. }
  17560. }
  17561. if(strcmp(key, "ConnectorPhaseRotationMaxLength") == 0)
  17562. {
  17563. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemAccessibility == 1)
  17564. {
  17565. check_ascii = value[0];
  17566. if( (check_ascii < 48) || (check_ascii > 57) )
  17567. {
  17568. isSuccess = ConfigurationStatus_Rejected;
  17569. }
  17570. else
  17571. {
  17572. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemData, "%d", atoi(value) );
  17573. isSuccess = ConfigurationStatus_Accepted;
  17574. }
  17575. }
  17576. else
  17577. {
  17578. isSuccess = ConfigurationStatus_Rejected;
  17579. }
  17580. }
  17581. if(strcmp(key, "StopTransactionOnEVSideDisconnect") == 0)
  17582. {
  17583. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemAccessibility == 1)
  17584. {
  17585. strcpy(str, (const char*)value);
  17586. for(int i = 0; str[i]; i++)
  17587. {
  17588. str[i] = tolower(str[i]);
  17589. }
  17590. //Charger.StopTransactionOnEVSideDisconnect = (value.toLowerCase().equals("true")?true:false);
  17591. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  17592. isSuccess = ConfigurationStatus_Accepted;
  17593. }
  17594. else
  17595. {
  17596. isSuccess = ConfigurationStatus_Rejected;
  17597. }
  17598. }
  17599. if(strcmp(key, "StopTransactionOnInvalidId") == 0)
  17600. {
  17601. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemAccessibility == 1)
  17602. {
  17603. strcpy(str, (const char*)value);
  17604. for(int i = 0; str[i]; i++)
  17605. {
  17606. str[i] = tolower(str[i]);
  17607. }
  17608. //Charger.StopTransactionOnInvalidId = (value.toLowerCase().equals("true")?true:false);
  17609. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  17610. isSuccess = ConfigurationStatus_Accepted;
  17611. }
  17612. else
  17613. {
  17614. isSuccess = ConfigurationStatus_Rejected;
  17615. }
  17616. }
  17617. if(strcmp(key, "StopTxnAlignedData") == 0)
  17618. {
  17619. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemAccessibility == 1)
  17620. {
  17621. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemData, "%s", value );
  17622. isSuccess = ConfigurationStatus_Accepted;
  17623. }
  17624. else
  17625. {
  17626. isSuccess = ConfigurationStatus_Rejected;
  17627. }
  17628. }
  17629. if(strcmp(key, "StopTxnAlignedDataMaxLength") == 0)
  17630. {
  17631. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemAccessibility == 1)
  17632. {
  17633. check_ascii = value[0];
  17634. if( (check_ascii < 48) || (check_ascii > 57) )
  17635. {
  17636. isSuccess = ConfigurationStatus_Rejected;
  17637. }
  17638. else
  17639. {
  17640. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemData, "%d", atoi(value) );
  17641. isSuccess = ConfigurationStatus_Accepted;
  17642. }
  17643. }
  17644. else
  17645. {
  17646. isSuccess = ConfigurationStatus_Rejected;
  17647. }
  17648. }
  17649. if(strcmp(key, "StopTxnSampledData") == 0)
  17650. {
  17651. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemAccessibility == 1)
  17652. {
  17653. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "%s", value );
  17654. isSuccess = ConfigurationStatus_Accepted;
  17655. }
  17656. else
  17657. {
  17658. isSuccess = ConfigurationStatus_Rejected;
  17659. }
  17660. }
  17661. if(strcmp(key, "StopTxnSampledDataMaxLength") == 0)
  17662. {
  17663. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemAccessibility == 1)
  17664. {
  17665. check_ascii = value[0];
  17666. if( (check_ascii < 48) || (check_ascii > 57) )
  17667. {
  17668. isSuccess = ConfigurationStatus_Rejected;
  17669. }
  17670. else
  17671. {
  17672. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemData, "%d", atoi(value) );
  17673. isSuccess = ConfigurationStatus_Accepted;
  17674. }
  17675. }
  17676. else
  17677. {
  17678. isSuccess = ConfigurationStatus_Rejected;
  17679. }
  17680. }
  17681. if(strcmp(key, "SupportedFeatureProfiles") == 0)
  17682. {
  17683. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemAccessibility == 1)
  17684. {
  17685. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemData, "%s", value );
  17686. isSuccess = ConfigurationStatus_Accepted;
  17687. }
  17688. else
  17689. {
  17690. isSuccess = ConfigurationStatus_Rejected;
  17691. }
  17692. }
  17693. if(strcmp(key, "SupportedFeatureProfilesMaxLength") == 0)
  17694. {
  17695. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemAccessibility == 1)
  17696. {
  17697. check_ascii = value[0];
  17698. if( (check_ascii < 48) || (check_ascii > 57) )
  17699. {
  17700. isSuccess = ConfigurationStatus_Rejected;
  17701. }
  17702. else
  17703. {
  17704. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemData, "%d", atoi(value) );
  17705. isSuccess = ConfigurationStatus_Accepted;
  17706. }
  17707. }
  17708. else
  17709. {
  17710. isSuccess = ConfigurationStatus_Rejected;
  17711. }
  17712. }
  17713. if(strcmp(key, "TransactionMessageAttempts") == 0)
  17714. {
  17715. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemAccessibility == 1)
  17716. {
  17717. check_ascii = value[0];
  17718. if( (check_ascii < 48) || (check_ascii > 57) )
  17719. {
  17720. isSuccess = ConfigurationStatus_Rejected;
  17721. }
  17722. else
  17723. {
  17724. //Charger.TransactionMessageAttempts = Integer.parseInt(value);
  17725. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData, "%d", atoi(value) );
  17726. TransactionMessageAttemptsValue = atoi(value);
  17727. isSuccess = ConfigurationStatus_Accepted;
  17728. }
  17729. }
  17730. else
  17731. {
  17732. isSuccess = ConfigurationStatus_Rejected;
  17733. }
  17734. }
  17735. if(strcmp(key, "TransactionMessageRetryInterval") == 0)
  17736. {
  17737. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemAccessibility == 1)
  17738. {
  17739. check_ascii = value[0];
  17740. if( (check_ascii < 48) || (check_ascii > 57) )
  17741. {
  17742. isSuccess = ConfigurationStatus_Rejected;
  17743. }
  17744. else
  17745. {
  17746. //Charger.TransactionMessageRetryInterval = Integer.parseInt(value)*1000;
  17747. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData, "%d", atoi(value) );
  17748. TransactionMessageRetryIntervalValue = atoi(value);
  17749. isSuccess = ConfigurationStatus_Accepted;
  17750. }
  17751. }
  17752. else
  17753. {
  17754. isSuccess = ConfigurationStatus_Rejected;
  17755. }
  17756. }
  17757. if(strcmp(key, "UnlockConnectorOnEVSideDisconnect") == 0)
  17758. {
  17759. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemAccessibility == 1)
  17760. {
  17761. strcpy(str, (const char*)value);
  17762. for(int i = 0; str[i]; i++)
  17763. {
  17764. str[i] = tolower(str[i]);
  17765. }
  17766. //Charger.UnlockConnectorOnEVSideDisconnect = (value.toLowerCase().equals("true")?true:false);
  17767. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  17768. isSuccess = ConfigurationStatus_Accepted;
  17769. }
  17770. else
  17771. {
  17772. isSuccess = ConfigurationStatus_Rejected;
  17773. }
  17774. }
  17775. if(strcmp(key, "WebSocketPingInterval") == 0)
  17776. {
  17777. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemAccessibility == 1)
  17778. {
  17779. check_ascii = value[0];
  17780. if( (check_ascii < 48) || (check_ascii > 57) )
  17781. {
  17782. isSuccess = ConfigurationStatus_Rejected;
  17783. }
  17784. else
  17785. {
  17786. if((atoi(value) == 0) || (atoi(value) >= 10))
  17787. {
  17788. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemData, "%d", atoi(value) );
  17789. isSuccess = ConfigurationStatus_Accepted;
  17790. }
  17791. else
  17792. isSuccess = ConfigurationStatus_Rejected;
  17793. }
  17794. }
  17795. else
  17796. {
  17797. isSuccess = ConfigurationStatus_Rejected;
  17798. }
  17799. }
  17800. if(strcmp(key, "QueueOffLineMeterValues") == 0)
  17801. {
  17802. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[QueueOffLineMeterValues].ItemAccessibility == 1)
  17803. {
  17804. strcpy(str, (const char*)value);
  17805. for(int i = 0; str[i]; i++)
  17806. {
  17807. str[i] = tolower(str[i]);
  17808. }
  17809. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[QueueOffLineMeterValues].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  17810. isSuccess = ConfigurationStatus_Accepted;
  17811. }
  17812. else
  17813. {
  17814. isSuccess = ConfigurationStatus_Rejected;
  17815. }
  17816. }
  17817. if(strcmp(key, "AuthorizationKey") == 0)
  17818. {
  17819. if((ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationKey].ItemAccessibility == 1) && (strlen(value) <= 40))
  17820. {
  17821. strcpy(str, (const char*)value);
  17822. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationKey].ItemData, "%s", str);
  17823. strcpy((char*)ShmSysConfigAndInfo->SysConfig.OcppSecurityPassword, (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationKey].ItemData);
  17824. isSuccess = ConfigurationStatus_Accepted;
  17825. }
  17826. else
  17827. {
  17828. isSuccess = ConfigurationStatus_Rejected;
  17829. }
  17830. }
  17831. if(strcmp(key, "SecurityProfile") == 0)
  17832. {
  17833. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[SecurityProfile].ItemAccessibility == 1)
  17834. {
  17835. check_ascii = value[0];
  17836. if( (check_ascii < 0x30) || (check_ascii > 0x33) )
  17837. {
  17838. isSuccess = ConfigurationStatus_Rejected;
  17839. }
  17840. else if(check_ascii == 0x33)
  17841. {
  17842. isSuccess = NotSupported;
  17843. }
  17844. else
  17845. {
  17846. if(atoi((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SecurityProfile].ItemData) <= (check_ascii - 0x30))
  17847. {
  17848. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SecurityProfile].ItemData, "%d", atoi(value) );
  17849. ShmSysConfigAndInfo->SysConfig.OcppSecurityProfile = atoi(value);
  17850. isSuccess = ConfigurationStatus_Accepted;
  17851. }
  17852. else
  17853. isSuccess = ConfigurationStatus_Rejected;
  17854. }
  17855. }
  17856. else
  17857. {
  17858. isSuccess = ConfigurationStatus_Rejected;
  17859. }
  17860. }
  17861. if(strcmp(key, "DefaultPrice") == 0)
  17862. {
  17863. if((ShmOCPP16Data->ConfigurationTable.CoreProfile[DefaultPrice].ItemAccessibility == 1))
  17864. {
  17865. strcpy(str, (const char*)value);
  17866. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[DefaultPrice].ItemData, "%s", str);
  17867. isSuccess = ConfigurationStatus_Accepted;
  17868. }
  17869. else
  17870. {
  17871. isSuccess = ConfigurationStatus_Rejected;
  17872. }
  17873. }
  17874. if(strcmp(key, "CustomDisplayCostAndPrice") == 0)
  17875. {
  17876. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemAccessibility == 1)
  17877. {
  17878. strcpy(str, (const char*)value);
  17879. for(int i = 0; str[i]; i++)
  17880. {
  17881. str[i] = tolower(str[i]);
  17882. }
  17883. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  17884. isSuccess = ConfigurationStatus_Accepted;
  17885. }
  17886. else
  17887. {
  17888. isSuccess = ConfigurationStatus_Rejected;
  17889. }
  17890. }
  17891. if(strcmp(key, "CustomIdleFeeAfterStop") == 0)
  17892. {
  17893. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemAccessibility == 1)
  17894. {
  17895. strcpy(str, (const char*)value);
  17896. for(int i = 0; str[i]; i++)
  17897. {
  17898. str[i] = tolower(str[i]);
  17899. }
  17900. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  17901. isSuccess = ConfigurationStatus_Accepted;
  17902. }
  17903. else
  17904. {
  17905. isSuccess = ConfigurationStatus_Rejected;
  17906. }
  17907. }
  17908. if(strcmp(key, "TimeOffset") == 0)
  17909. {
  17910. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffset].ItemAccessibility == 1)
  17911. {
  17912. strcpy(str, (const char*)value);
  17913. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffset].ItemData, "%s", str);
  17914. isSuccess = ConfigurationStatus_Accepted;
  17915. }
  17916. else
  17917. {
  17918. isSuccess = ConfigurationStatus_Rejected;
  17919. }
  17920. }
  17921. if(strcmp(key, "NextTimeOffsetTransitionDateTime") == 0)
  17922. {
  17923. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[NextTimeOffsetTransitionDateTime].ItemAccessibility == 1)
  17924. {
  17925. strcpy(str, (const char*)value);
  17926. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NextTimeOffsetTransitionDateTime].ItemData, "%s", str);
  17927. isSuccess = ConfigurationStatus_Accepted;
  17928. }
  17929. else
  17930. {
  17931. isSuccess = ConfigurationStatus_Rejected;
  17932. }
  17933. }
  17934. if(strcmp(key, "TimeOffsetNextTransition") == 0)
  17935. {
  17936. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffsetNextTransition].ItemAccessibility == 1)
  17937. {
  17938. strcpy(str, (const char*)value);
  17939. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffsetNextTransition].ItemData, "%s", str);
  17940. isSuccess = ConfigurationStatus_Accepted;
  17941. }
  17942. else
  17943. {
  17944. isSuccess = ConfigurationStatus_Rejected;
  17945. }
  17946. }
  17947. if(strcmp(key, "SystemUptimeSec") == 0)
  17948. {
  17949. isSuccess = NotSupported;
  17950. }
  17951. if(strcmp(key, "FreeVend") == 0)
  17952. {
  17953. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[FreeVend].ItemAccessibility == 1)
  17954. {
  17955. strcpy(str, (const char*)value);
  17956. for(int i = 0; str[i]; i++)
  17957. {
  17958. str[i] = tolower(str[i]);
  17959. }
  17960. ShmSysConfigAndInfo->SysConfig.AuthorisationMode = ((strcmp(str, "true")==0) ? 1 : 0 );
  17961. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[FreeVend].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  17962. isSuccess = ConfigurationStatus_Accepted;
  17963. }
  17964. else
  17965. {
  17966. isSuccess = ConfigurationStatus_Rejected;
  17967. }
  17968. }
  17969. if(strcmp(key, "FreeVendIdtag") == 0)
  17970. {
  17971. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[FreeVendIdtag].ItemAccessibility == 1)
  17972. {
  17973. strcpy(str, (const char*)value);
  17974. if(strlen(str) <= 20)
  17975. {
  17976. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[FreeVendIdtag].ItemData, "%s", str );
  17977. isSuccess = ConfigurationStatus_Accepted;
  17978. }
  17979. else
  17980. {
  17981. DEBUG_WARN("FreeVendIdtag(%s) length over 20 bytes.\n", str);
  17982. isSuccess = ConfigurationStatus_Rejected;
  17983. }
  17984. }
  17985. else
  17986. {
  17987. isSuccess = ConfigurationStatus_Rejected;
  17988. }
  17989. }
  17990. if(strcmp(key, "OcppServer") == 0)
  17991. {
  17992. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[OcppServer].ItemAccessibility == 1)
  17993. {
  17994. strcpy(str, (const char*)value);
  17995. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[OcppServer].ItemData, "%s", str );
  17996. sprintf((char *)ShmSysConfigAndInfo->SysConfig.OcppServerURL, "%s", str );
  17997. isSuccess = ConfigurationStatus_Accepted;
  17998. }
  17999. else
  18000. {
  18001. isSuccess = ConfigurationStatus_Rejected;
  18002. }
  18003. }
  18004. if(strcmp(key, "MaintainServer") == 0)
  18005. {
  18006. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MaintainServer].ItemAccessibility == 1)
  18007. {
  18008. strcpy(str, (const char*)value);
  18009. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MaintainServer].ItemData, "%s", str );
  18010. sprintf((char *)ShmSysConfigAndInfo->SysConfig.MaintainServerURL, "%s", str );
  18011. isSuccess = ConfigurationStatus_Accepted;
  18012. }
  18013. else
  18014. {
  18015. isSuccess = ConfigurationStatus_Rejected;
  18016. }
  18017. }
  18018. if(strcmp(key, "StatusNotificationPeriodically") == 0)
  18019. {
  18020. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StatusNotificationPeriodically].ItemAccessibility == 1)
  18021. {
  18022. strcpy(str, (const char*)value);
  18023. for(int i = 0; str[i]; i++)
  18024. {
  18025. str[i] = tolower(str[i]);
  18026. }
  18027. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StatusNotificationPeriodically].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE");
  18028. isSuccess = ConfigurationStatus_Accepted;
  18029. }
  18030. else
  18031. {
  18032. isSuccess = ConfigurationStatus_Rejected;
  18033. }
  18034. }
  18035. if(strcmp(key, "StatusNotificationInterval") == 0)
  18036. {
  18037. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StatusNotificationInterval].ItemAccessibility == 1)
  18038. {
  18039. check_ascii = value[0];
  18040. if( (check_ascii < 48) || (check_ascii > 57) )
  18041. {
  18042. isSuccess = ConfigurationStatus_Rejected;
  18043. }
  18044. else
  18045. {
  18046. if((atoi(value) == 0) || (atoi(value) >= 10))
  18047. {
  18048. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StatusNotificationInterval].ItemData, "%d", atoi(value) );
  18049. isSuccess = ConfigurationStatus_Accepted;
  18050. }
  18051. else
  18052. isSuccess = ConfigurationStatus_Rejected;
  18053. }
  18054. }
  18055. else
  18056. {
  18057. isSuccess = ConfigurationStatus_Rejected;
  18058. }
  18059. }
  18060. if(strcmp(key, "PreAuthAmount") == 0)
  18061. {
  18062. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[PreAuthAmount].ItemAccessibility == 1)
  18063. {
  18064. check_ascii = value[0];
  18065. if( (check_ascii < 48) || (check_ascii > 57) )
  18066. {
  18067. isSuccess = ConfigurationStatus_Rejected;
  18068. }
  18069. else
  18070. {
  18071. if(atof(value) >= 0)
  18072. {
  18073. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[PreAuthAmount].ItemData, "%.2f", atof(value) );
  18074. isSuccess = ConfigurationStatus_Accepted;
  18075. }
  18076. else
  18077. isSuccess = ConfigurationStatus_Rejected;
  18078. }
  18079. }
  18080. else
  18081. {
  18082. isSuccess = ConfigurationStatus_Rejected;
  18083. }
  18084. }
  18085. if(strcmp(key, "isEnableLocalPowerSharing") == 0)
  18086. {
  18087. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[isEnableLocalPowerSharing].ItemAccessibility == 1)
  18088. {
  18089. check_ascii = value[0];
  18090. if( (check_ascii < 48) || (check_ascii > 57) )
  18091. {
  18092. isSuccess = ConfigurationStatus_Rejected;
  18093. }
  18094. else
  18095. {
  18096. if(atoi(value) >= 0)
  18097. {
  18098. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[isEnableLocalPowerSharing].ItemData, "%d", atoi(value));
  18099. ShmSysConfigAndInfo->SysConfig.isEnableLocalPowerSharing = (unsigned char)atoi(value);
  18100. isSuccess = ConfigurationStatus_Accepted;
  18101. }
  18102. else
  18103. isSuccess = ConfigurationStatus_Rejected;
  18104. }
  18105. }
  18106. else
  18107. {
  18108. isSuccess = ConfigurationStatus_Rejected;
  18109. }
  18110. }
  18111. if(strcmp(key, "PowerSharingServerIP") == 0)
  18112. {
  18113. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[PowerSharingServerIP].ItemAccessibility == 1)
  18114. {
  18115. strcpy(str, (const char*)value);
  18116. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[PowerSharingServerIP].ItemData, "%s", str );
  18117. sprintf((char *)ShmSysConfigAndInfo->SysConfig.PowerSharingServerIP, "%s", str );
  18118. isSuccess = ConfigurationStatus_Accepted;
  18119. }
  18120. else
  18121. {
  18122. isSuccess = ConfigurationStatus_Rejected;
  18123. }
  18124. }
  18125. if(strcmp(key, "EVCCID_PREFIX") == 0)
  18126. {
  18127. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[EVCCID_PREFIX].ItemAccessibility == 1)
  18128. {
  18129. strcpy(str, (const char*)value);
  18130. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[EVCCID_PREFIX].ItemData, "%s", str );
  18131. isSuccess = ConfigurationStatus_Accepted;
  18132. }
  18133. else
  18134. {
  18135. isSuccess = ConfigurationStatus_Rejected;
  18136. }
  18137. }
  18138. if(strcmp(key, "OffLineMaxChargingPower") == 0)
  18139. {
  18140. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[OffLineMaxChargingPower].ItemAccessibility == 1)
  18141. {
  18142. if(atoi(value) > modelnameInfo.ratedPower)
  18143. {
  18144. isSuccess = ConfigurationStatus_Rejected;
  18145. }
  18146. else{
  18147. strcpy(str, (const char*)value);
  18148. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[OffLineMaxChargingPower].ItemData, "%s", str );
  18149. isSuccess = ConfigurationStatus_Accepted;
  18150. }
  18151. }
  18152. else
  18153. {
  18154. isSuccess = ConfigurationStatus_Rejected;
  18155. }
  18156. }
  18157. if(strcmp(key, "CharingProfileRefreshInterval") == 0)
  18158. {
  18159. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[CharingProfileRefreshInterval].ItemAccessibility == 1)
  18160. {
  18161. if((atoi(value) != 0) && (atoi(value) < 5))
  18162. {
  18163. isSuccess = ConfigurationStatus_Rejected;
  18164. }
  18165. else{
  18166. strcpy(str, (const char*)value);
  18167. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CharingProfileRefreshInterval].ItemData, "%s", str );
  18168. isSuccess = ConfigurationStatus_Accepted;
  18169. }
  18170. }
  18171. else
  18172. {
  18173. isSuccess = ConfigurationStatus_Rejected;
  18174. }
  18175. }
  18176. #if 0
  18177. //For OCPP Test Case
  18178. if(strcmp(key, "LocalAuthorizationListEnabled") == 0)
  18179. {
  18180. if(ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemAccessibility == 1)
  18181. {
  18182. strcpy(str, (const char*)value);
  18183. for(int i = 0; str[i]; i++)
  18184. {
  18185. str[i] = tolower(str[i]);
  18186. }
  18187. sprintf((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  18188. isSuccess = ConfigurationStatus_Accepted;
  18189. //updateSetting("LocalAuthorizationListEnabled", (char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData);
  18190. }
  18191. else
  18192. {
  18193. isSuccess = ConfigurationStatus_Rejected;
  18194. }
  18195. }
  18196. #endif
  18197. #if 1
  18198. if(strcmp(key, "LocalAuthListEnabled") == 0)
  18199. {
  18200. if(ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemAccessibility == 1)
  18201. {
  18202. strcpy(str, (const char*)value);
  18203. for(int i = 0; str[i]; i++)
  18204. {
  18205. str[i] = tolower(str[i]);
  18206. }
  18207. sprintf((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  18208. isSuccess = ConfigurationStatus_Accepted;
  18209. //updateSetting("LocalAuthListEnabled", (char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData);
  18210. }
  18211. else
  18212. {
  18213. isSuccess = ConfigurationStatus_Rejected;
  18214. }
  18215. }
  18216. #endif
  18217. if(strcmp(key, "LocalAuthListMaxLength") == 0)
  18218. {
  18219. if(ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemAccessibility == 1)
  18220. {
  18221. check_ascii = value[0];
  18222. if( (check_ascii < 48) || (check_ascii > 57) )
  18223. {
  18224. isSuccess = ConfigurationStatus_Rejected;
  18225. }
  18226. else
  18227. {
  18228. sprintf((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemData, "%d", atoi(value) );
  18229. isSuccess = ConfigurationStatus_Accepted;
  18230. }
  18231. }
  18232. else
  18233. {
  18234. isSuccess = ConfigurationStatus_Rejected;
  18235. }
  18236. }
  18237. if(strcmp(key, "SendLocalListMaxLength") == 0)
  18238. {
  18239. if(ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemAccessibility == 1)
  18240. {
  18241. check_ascii = value[0];
  18242. if( (check_ascii < 48) || (check_ascii > 57) )
  18243. {
  18244. isSuccess = ConfigurationStatus_Rejected;
  18245. }
  18246. else
  18247. {
  18248. sprintf((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemData, "%d", atoi(value) );
  18249. isSuccess = ConfigurationStatus_Accepted;
  18250. }
  18251. }
  18252. else
  18253. {
  18254. isSuccess = ConfigurationStatus_Rejected;
  18255. }
  18256. }
  18257. if(strcmp(key, "ReserveConnectorZeroSupported") == 0)
  18258. {
  18259. if(ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemAccessibility == 1)
  18260. {
  18261. strcpy(str, (const char*)value);
  18262. for(int i = 0; str[i]; i++)
  18263. {
  18264. str[i] = tolower(str[i]);
  18265. }
  18266. sprintf((char *)ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  18267. isSuccess = ConfigurationStatus_Accepted;
  18268. }
  18269. else
  18270. {
  18271. isSuccess = ConfigurationStatus_Rejected;
  18272. }
  18273. }
  18274. if(strcmp(key, "ChargeProfileMaxStackLevel") == 0)
  18275. {
  18276. if(ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemAccessibility == 1)
  18277. {
  18278. check_ascii = value[0];
  18279. if( (check_ascii < 48) || (check_ascii > 57) )
  18280. {
  18281. isSuccess = ConfigurationStatus_Rejected;
  18282. }
  18283. else
  18284. {
  18285. sprintf((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemData, "%d", atoi(value) );
  18286. isSuccess = ConfigurationStatus_Accepted;
  18287. }
  18288. }
  18289. else
  18290. {
  18291. isSuccess = ConfigurationStatus_Rejected;
  18292. }
  18293. }
  18294. if(strcmp(key, "ChargingScheduleAllowedChargingRateUnit") == 0)
  18295. {
  18296. if(ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemAccessibility == 1)
  18297. {
  18298. sprintf((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemData, "%s", value );
  18299. isSuccess = ConfigurationStatus_Accepted;
  18300. }
  18301. else
  18302. {
  18303. isSuccess = ConfigurationStatus_Rejected;
  18304. }
  18305. }
  18306. if(strcmp(key, "ChargingScheduleMaxPeriods") == 0)
  18307. {
  18308. if(ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemAccessibility == 1)
  18309. {
  18310. check_ascii = value[0];
  18311. if( (check_ascii < 48) || (check_ascii > 57) )
  18312. {
  18313. isSuccess = ConfigurationStatus_Rejected;
  18314. }
  18315. else
  18316. {
  18317. sprintf((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemData, "%d", atoi(value) );
  18318. isSuccess = ConfigurationStatus_Accepted;
  18319. }
  18320. }
  18321. else
  18322. {
  18323. isSuccess = ConfigurationStatus_Rejected;
  18324. }
  18325. }
  18326. if(strcmp(key, "ConnectorSwitch3to1PhaseSupported") == 0)
  18327. {
  18328. if(ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemAccessibility == 1)
  18329. {
  18330. strcpy(str, (const char*)value);
  18331. for(int i = 0; str[i]; i++)
  18332. {
  18333. str[i] = tolower(str[i]);
  18334. }
  18335. sprintf((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  18336. isSuccess = ConfigurationStatus_Accepted;
  18337. }
  18338. else
  18339. {
  18340. isSuccess = ConfigurationStatus_Rejected;
  18341. }
  18342. }
  18343. if(strcmp(key, "MaxChargingProfilesInstalled") == 0)
  18344. {
  18345. if(ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemAccessibility == 1)
  18346. {
  18347. check_ascii = value[0];
  18348. if( (check_ascii < 48) || (check_ascii > 57) )
  18349. {
  18350. isSuccess = ConfigurationStatus_Rejected;
  18351. }
  18352. else
  18353. {
  18354. sprintf((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemData, "%d", atoi(value) );
  18355. isSuccess = ConfigurationStatus_Accepted;
  18356. }
  18357. }
  18358. else
  18359. {
  18360. isSuccess = ConfigurationStatus_Rejected;
  18361. }
  18362. }
  18363. system("/bin/fsync -d /dev/mtdblock13;/bin/sync &");
  18364. return isSuccess;
  18365. }
  18366. int TransactionMessageAttemptsGet(void)
  18367. {
  18368. return TransactionMessageAttemptsValue;
  18369. }
  18370. int FirstHeartBeatResponse(void)
  18371. {
  18372. return FirstHeartBeat;
  18373. }
  18374. int TransactionMessageRetryIntervalGet(void)
  18375. {
  18376. return TransactionMessageRetryIntervalValue;//atoi((const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData);
  18377. }
  18378. int ReadHttpStatus(int sock)
  18379. {
  18380. //char c;
  18381. char buff[1024]="",*ptr=buff+1;
  18382. int bytes_received, status;
  18383. DEBUG_INFO("Begin Response ..\n");
  18384. while((bytes_received = recv(sock, ptr, 1, 0))){
  18385. if(bytes_received==-1){
  18386. perror("ReadHttpStatus");
  18387. exit(1);
  18388. }
  18389. if((ptr[-1]=='\r') && (*ptr=='\n' )) break;
  18390. ptr++;
  18391. }
  18392. *ptr=0;
  18393. ptr=buff+1;
  18394. sscanf(ptr,"%*s %d ", &status);
  18395. DEBUG_INFO("%s\n",ptr);
  18396. DEBUG_INFO("status=%d\n",status);
  18397. DEBUG_INFO("End Response ..\n");
  18398. return (bytes_received>0)?status:0;
  18399. }
  18400. //the only filed that it parsed is 'Content-Length'
  18401. int ParseHeader(int sock)
  18402. {
  18403. //char c;
  18404. char buff[1024]="",*ptr=buff+4;
  18405. int bytes_received;
  18406. DEBUG_INFO("Begin HEADER ..\n");
  18407. while((bytes_received = recv(sock, ptr, 1, 0))){
  18408. if(bytes_received==-1){
  18409. perror("Parse Header");
  18410. exit(1);
  18411. }
  18412. if(
  18413. (ptr[-3]=='\r') && (ptr[-2]=='\n' ) &&
  18414. (ptr[-1]=='\r') && (*ptr=='\n' )
  18415. ) break;
  18416. ptr++;
  18417. }
  18418. *ptr=0;
  18419. ptr=buff+4;
  18420. //printf("%s",ptr);
  18421. if(bytes_received){
  18422. ptr=strstr(ptr,"Content-Length:");
  18423. if(ptr){
  18424. sscanf(ptr,"%*s %d",&bytes_received);
  18425. }else
  18426. bytes_received=-1; //unknown size
  18427. DEBUG_INFO("Content-Length: %d\n",bytes_received);
  18428. }
  18429. DEBUG_INFO("End HEADER ..\n");
  18430. return bytes_received ;
  18431. }
  18432. int httpDownLoadFile(char *location, char *path, char *filename,char *url)
  18433. {
  18434. int result = TRUE;
  18435. char rmFileCmd[100]={0};
  18436. char FilePath[100]={0};
  18437. char ftpbuf[200];
  18438. int systemresult;
  18439. sprintf(FilePath,"/mnt/%s",filename);
  18440. system("ping 8.8.8.8 &");
  18441. if((access(FilePath,F_OK))!=-1)
  18442. {
  18443. DEBUG_INFO("filename=%s exist.\n",FilePath);
  18444. sprintf(rmFileCmd,"rm -f %s",FilePath);
  18445. system(rmFileCmd);
  18446. }
  18447. memset(ftpbuf, 0, ARRAY_SIZE(ftpbuf));
  18448. sprintf(ftpbuf, "wget --tries=1 -O /mnt/%s -c %s -T 120 --no-check-certificate",filename, url);
  18449. DEBUG_INFO("Download command: %s\n",ftpbuf);
  18450. systemresult = system(ftpbuf);
  18451. if(systemresult != 0)
  18452. {
  18453. DEBUG_INFO("HTTP/HTTPS downLoad fail!\n");
  18454. result = FALSE;
  18455. }
  18456. system("pkill ping");
  18457. return result;
  18458. }
  18459. int sftpDownLoadFile(char *location, char *user, int port, char *path, char *filename,char *url)
  18460. {
  18461. int result = TRUE;
  18462. char rmFileCmd[100]={0};
  18463. char FilePath[100]={0};
  18464. char ftpbuf[200];
  18465. int systemresult;
  18466. sprintf(FilePath,"/mnt/%s",filename);
  18467. system("ping 8.8.8.8 &");
  18468. if((access(FilePath,F_OK))!=-1)
  18469. {
  18470. DEBUG_INFO("filename=%s exist.\n",FilePath);
  18471. sprintf(rmFileCmd,"rm -f %s",FilePath);
  18472. system(rmFileCmd);
  18473. }
  18474. memset(ftpbuf, 0, ARRAY_SIZE(ftpbuf));
  18475. sprintf(ftpbuf,"timeout -t 360 scp -i /root/.ssh/id_rsa_bear -P %d %s@%s%s /mnt/%s", port, user, path, filename, filename);
  18476. DEBUG_INFO("Download command: %s\n",ftpbuf);
  18477. systemresult = system(ftpbuf);
  18478. if(systemresult != 0)
  18479. {
  18480. DEBUG_WARN("scp error!\n");
  18481. result = FALSE;
  18482. }
  18483. system("pkill ping");
  18484. return result;
  18485. }
  18486. int ftpDownLoadFile(char *location, char *user, char *password, int port, char *path, char *filename,char *url)
  18487. {
  18488. int result = TRUE;
  18489. char rmFileCmd[100]={0};
  18490. char FilePath[100]={0};
  18491. char ftpbuf[200];
  18492. int systemresult;
  18493. sprintf(FilePath,"/mnt/%s",filename);
  18494. system("ping 8.8.8.8 &");
  18495. if((access(FilePath,F_OK))!=-1)
  18496. {
  18497. DEBUG_INFO("filename=%s exist.\n",FilePath);
  18498. sprintf(rmFileCmd,"rm -f %s",FilePath);
  18499. system(rmFileCmd);
  18500. }
  18501. memset(ftpbuf, 0, ARRAY_SIZE(ftpbuf));
  18502. sprintf(ftpbuf, "wget --tries=1 -O /mnt/%s -c %s -T 120",filename, url);
  18503. DEBUG_INFO("Download command: %s\n",ftpbuf);
  18504. systemresult = system(ftpbuf);
  18505. if(systemresult != 0)
  18506. {
  18507. sprintf(ftpbuf, "wget --tries=1 -O /mnt/%s -c %s -T 120 --no-passive-ftp",filename, url);
  18508. DEBUG_INFO("Download command: %s\n",ftpbuf);
  18509. systemresult = system(ftpbuf);
  18510. if(systemresult != 0)
  18511. {
  18512. DEBUG_WARN("FTP download fail!\n");
  18513. result = FALSE;
  18514. }
  18515. }
  18516. system("pkill ping");
  18517. return result;
  18518. }
  18519. int httpUploadFile(char *location, char *path, char *filename,char *url)
  18520. {
  18521. char rmFileCmd[100]={0};
  18522. char FilePath[100]={0};
  18523. char buf[512];
  18524. int systemresult = 0;
  18525. //DEBUG_INFO("filename=%s\n",filename);
  18526. //DEBUG_INFO("url=%s\n",url);
  18527. sprintf(FilePath,"%s","/mnt/upload_file.txt");
  18528. if((access(FilePath,F_OK))!=-1)
  18529. {
  18530. DEBUG_INFO("filename=%s exist.\n",FilePath);
  18531. sprintf(rmFileCmd,"rm -f %s",FilePath);
  18532. system(rmFileCmd);
  18533. }
  18534. FILE *fp = fopen("/mnt/upload_file.txt", "w+");
  18535. if(fp == NULL)
  18536. {
  18537. DEBUG_INFO("log is NULL\n");
  18538. return FALSE;
  18539. }
  18540. else
  18541. {
  18542. fprintf(fp, "%s\n", url);
  18543. fprintf(fp, "%s\n", filename);
  18544. fclose(fp);
  18545. }
  18546. FILE *phpFP = popen("/bin/php-cgi /var/www/ocpp_upload.php", "r");
  18547. if(phpFP == NULL)
  18548. {
  18549. DEBUG_INFO("PHP upload fail.\n");
  18550. return FALSE;
  18551. }
  18552. else
  18553. {
  18554. while(fgets(buf, sizeof(buf), phpFP) != NULL)
  18555. {
  18556. if(strstr(buf, "result") != NULL)
  18557. {
  18558. sscanf(buf, "result: %d", &systemresult);
  18559. DEBUG_INFO("PHP HTTP upload result: %d\n", systemresult);
  18560. }
  18561. }
  18562. pclose(phpFP);
  18563. }
  18564. if(systemresult != 1)
  18565. {
  18566. DEBUG_WARN("HTTP POST upload error, change to PUT method\n");
  18567. FILE *phpFP = popen("/bin/php-cgi /var/www/ocpp_upload_put.php", "r");
  18568. if(phpFP == NULL)
  18569. {
  18570. DEBUG_WARN("PHP PUT upload fail.\n");
  18571. return FALSE;
  18572. }
  18573. else
  18574. {
  18575. while(fgets(buf, sizeof(buf), phpFP) != NULL)
  18576. {
  18577. if(strstr(buf, "result") != NULL)
  18578. {
  18579. sscanf(buf, "result: %d", &systemresult);
  18580. DEBUG_INFO("PHP HTTP PUT upload result: %d\n", systemresult);
  18581. }
  18582. }
  18583. pclose(phpFP);
  18584. }
  18585. }
  18586. if(systemresult != 1)
  18587. {
  18588. DEBUG_WARN("PHP PUT upload fail.\n");
  18589. return FALSE;
  18590. }
  18591. return TRUE;
  18592. }
  18593. int ftpUploadFile(char *location, char *user, char *password, int port, char *path, char *fnamePlusPath,char *filename)
  18594. {
  18595. int result = FALSE;
  18596. char ftpbuf[200];
  18597. int systemresult;
  18598. /*
  18599. // Domaind name transfer to IP address
  18600. struct hostent* server;
  18601. char *IPbuffer;
  18602. server = gethostbyname(location);
  18603. IPbuffer = inet_ntoa(*((struct in_addr*)server->h_addr_list[0]));*/
  18604. memset(ftpbuf, 0, ARRAY_SIZE(ftpbuf));
  18605. sprintf(ftpbuf, "ftpput -u %s -p %s %s -P %d %s%s %s", user, password, location, port/*21*/, path, filename, fnamePlusPath);
  18606. DEBUG_INFO("ftp command: %s\n",ftpbuf);
  18607. systemresult = system(ftpbuf);
  18608. if(systemresult != 0)
  18609. {
  18610. DEBUG_INFO("ftpput error!\n");
  18611. }
  18612. else
  18613. {
  18614. result = TRUE;
  18615. DEBUG_INFO("ftpput OK!\n");
  18616. }
  18617. return result;
  18618. }
  18619. int GetOcppServerURL()
  18620. {
  18621. int result = FALSE;
  18622. memset(OcppProtocol, 0, ARRAY_SIZE(OcppProtocol));
  18623. memset(OcppHost, 0, ARRAY_SIZE(OcppHost));
  18624. memset(OcppTempPath, 0, ARRAY_SIZE(OcppTempPath));
  18625. struct yuarel url;
  18626. char urlStr[512];
  18627. if((ShmSysConfigAndInfo->SysConfig.OcppServerURL != NULL) && (strcmp((const char *)ShmSysConfigAndInfo->SysConfig.OcppServerURL,"") != 0) )
  18628. {
  18629. /*sscanf((const char *)ShmSysConfigAndInfo->SysConfig.OcppServerURL,
  18630. "%[^:]:%*2[/]%[^:]:%i/%[a-zA-Z0-9._/-]",
  18631. OcppProtocol, OcppHost, &OcppPort, OcppTempPath);*/
  18632. memcpy(urlStr, ShmSysConfigAndInfo->SysConfig.OcppServerURL, ARRAY_SIZE(ShmSysConfigAndInfo->SysConfig.OcppServerURL));
  18633. if(yuarel_parse(&url, urlStr) != -1)
  18634. {
  18635. sprintf(OcppProtocol, "%s", url.scheme);
  18636. sprintf(OcppHost, "%s", url.host);
  18637. if(url.path == NULL)
  18638. OcppTempPath[0] = '\0';
  18639. else
  18640. {
  18641. if((url.path[strlen(url.path)-1] != '/') && (strlen(url.path) > 0))
  18642. {
  18643. sprintf(OcppTempPath, "%s/", url.path);
  18644. }
  18645. else
  18646. {
  18647. sprintf(OcppTempPath, "%s", url.path);
  18648. }
  18649. }
  18650. if(url.port == 0)
  18651. {
  18652. if(strcmp(OcppProtocol, "wss") == 0)
  18653. OcppPort = 443;
  18654. else
  18655. OcppPort = 80;
  18656. }
  18657. else
  18658. OcppPort = url.port;
  18659. result = TRUE;
  18660. }
  18661. }
  18662. else if((ShmOCPP16Data->OcppServerURL != NULL) && (strcmp((const char *)ShmOCPP16Data->OcppServerURL,"") != 0))
  18663. {
  18664. /*sscanf((const char *)ShmOCPP16Data->OcppServerURL,
  18665. "%[^:]:%*2[/]%[^:]:%i/%[a-zA-Z0-9._/-]",
  18666. OcppProtocol, OcppHost, &OcppPort, OcppTempPath);*/
  18667. memcpy(urlStr, ShmOCPP16Data->OcppServerURL, ARRAY_SIZE(ShmOCPP16Data->OcppServerURL));
  18668. if(yuarel_parse(&url, urlStr) != -1)
  18669. {
  18670. sprintf(OcppProtocol, "%s", url.scheme);
  18671. sprintf(OcppHost, "%s", url.host);
  18672. if(url.path == NULL)
  18673. OcppTempPath[0] = '\0';
  18674. else
  18675. sprintf(OcppTempPath, "%s", url.path);
  18676. if(url.port == 0)
  18677. {
  18678. if(strcmp(OcppProtocol, "wss") == 0)
  18679. OcppPort = 443;
  18680. else
  18681. OcppPort = 80;
  18682. }
  18683. else
  18684. OcppPort = url.port;
  18685. result = TRUE;
  18686. }
  18687. }
  18688. else
  18689. {
  18690. strcpy(OcppHost,"");
  18691. }
  18692. return result;
  18693. }
  18694. int GetOcppPath()
  18695. {
  18696. int result = FALSE;
  18697. if((ShmSysConfigAndInfo->SysConfig.ChargeBoxId != NULL) && (strcmp((const char *)ShmSysConfigAndInfo->SysConfig.ChargeBoxId,"") != 0) )
  18698. {
  18699. if(OcppTempPath == NULL)
  18700. {
  18701. sprintf(OcppPath,"/%s",ShmSysConfigAndInfo->SysConfig.ChargeBoxId);
  18702. }
  18703. else
  18704. {
  18705. sprintf(OcppPath,"/%s%s",OcppTempPath,ShmSysConfigAndInfo->SysConfig.ChargeBoxId);
  18706. }
  18707. result = TRUE;
  18708. goto End;
  18709. }
  18710. else if((ShmOCPP16Data->ChargeBoxId != NULL) && (strcmp((const char *)ShmOCPP16Data->ChargeBoxId,"") != 0))
  18711. {
  18712. if(OcppTempPath == NULL)
  18713. {
  18714. sprintf(OcppPath,"/%s",ShmOCPP16Data->ChargeBoxId);
  18715. }
  18716. else
  18717. {
  18718. sprintf(OcppPath,"/%s%s",OcppTempPath,ShmOCPP16Data->ChargeBoxId);
  18719. }
  18720. result = TRUE;
  18721. goto End;
  18722. }
  18723. else
  18724. {
  18725. strcpy(OcppPath,"");
  18726. }
  18727. End:
  18728. return result;
  18729. }
  18730. int GetOcppPort()
  18731. {
  18732. return OcppPort;
  18733. }
  18734. int GetOcppConnStatus(void)
  18735. {
  18736. return ShmOCPP16Data->OcppConnStatus;
  18737. }
  18738. void SetOcppConnStatus(uint8_t status)
  18739. {
  18740. ShmOCPP16Data->OcppConnStatus = status;
  18741. ShmSysConfigAndInfo->SysInfo.OcppConnStatus = status;
  18742. }
  18743. int GetHeartBeatWithNOResponse(void)
  18744. {
  18745. return HeartBeatWithNOResponse;
  18746. }
  18747. void SetHeartBeatWithNOResponse(void)
  18748. {
  18749. HeartBeatWithNOResponse = 0;
  18750. }
  18751. void GetStartTransactionIdTag(int gun_index)
  18752. {
  18753. memset(StartTransactionIdTagTemp, 0 ,ARRAY_SIZE(StartTransactionIdTagTemp));
  18754. strcpy((char *)StartTransactionIdTagTemp, (const char *)ShmOCPP16Data->StartTransaction[gun_index].IdTag);
  18755. }
  18756. int GetStartTransactionId(int gun_index)
  18757. {
  18758. return ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId;
  18759. }
  18760. int GetTransactionId(int gunindex, unsigned char idTag[], uint8_t isStopTransaction)
  18761. {
  18762. char ch;
  18763. FILE *fptr1;
  18764. int temptransactionId;
  18765. char str[100]={0};
  18766. temptransactionId = 0;
  18767. if(((strcmp((const char*)idTag, "")==0)||(idTag[0]=='\0')) && isStopTransaction)
  18768. {
  18769. DEBUG_INFO("IdTag is empty.\n");
  18770. return temptransactionId;
  18771. }
  18772. /*------ Read the file ----------------*/
  18773. fptr1=fopen("/Storage/OCPP/QueueTransactionId","r");
  18774. if (!fptr1)
  18775. {
  18776. DEBUG_INFO("QueueTransactionId file open error.\n");
  18777. //printf(" File not found or unable to open the input file!!\n");
  18778. return temptransactionId;
  18779. }
  18780. ch=fgetc(fptr1);
  18781. //printf(" Now the content of the file %s is : \n","/Storage/OCPP/QueueTransactionId");
  18782. rewind(fptr1);
  18783. if(ch!=EOF)
  18784. {
  18785. // printf("%c",ch);
  18786. while (fgets(str, 100, fptr1) != NULL)
  18787. {
  18788. str[strlen(str) - 1] = '\0'; // eat the newline fgets() stores
  18789. if(str[0]=='\0')
  18790. {
  18791. break;
  18792. }
  18793. char *revbuf[8] = {0}; // Variable store string split
  18794. int num = 0;// Quantity after string split
  18795. DEBUG_INFO("Transaction queue data= %s\n", str);
  18796. splitstring(str,",",revbuf,&num); // String split
  18797. DEBUG_INFO(" revbuf[0]= %s\n", revbuf[0]);
  18798. DEBUG_INFO(" revbuf[1]= %s\n", revbuf[1]);
  18799. DEBUG_INFO(" revbuf[2]= %s\n", revbuf[2]);
  18800. DEBUG_INFO("------------------------------\n");
  18801. if((revbuf[1][0] != '\0')&&(revbuf[2][0] != '\0'))
  18802. {
  18803. if(isStopTransaction)
  18804. {
  18805. if((atoi(revbuf[0])==gunindex) && (strcmp(revbuf[1],(const char *)idTag)==0))
  18806. {
  18807. temptransactionId = atoi(revbuf[2]);
  18808. //break;
  18809. }
  18810. }
  18811. else
  18812. {
  18813. if((atoi(revbuf[0])==gunindex) || (strcmp(revbuf[1],(const char *)idTag)==0))
  18814. {
  18815. temptransactionId = atoi(revbuf[2]);
  18816. //break;
  18817. }
  18818. }
  18819. }
  18820. }
  18821. }
  18822. else
  18823. DEBUG_INFO("EOF\n");
  18824. fclose(fptr1);
  18825. /*------- End of reading ---------------*/
  18826. return temptransactionId;
  18827. }
  18828. void SetTransactionIdZero(int transactionId)
  18829. {
  18830. char ch;
  18831. FILE *fptr1, *fptr2;
  18832. int temptransactionId = 0;
  18833. char str[100]={0}, strtemp[100]={0}, temp[] = "/Storage/OCPP/QueueTransactionIdtemp.json";
  18834. fptr1 = fopen("/Storage/OCPP/QueueTransactionId", "r");
  18835. if (!fptr1)
  18836. {
  18837. //printf(" File not found or unable to open the input file!!\n");
  18838. return ;
  18839. }
  18840. fptr2 = fopen(temp, "w"); // open the temporary file in write mode
  18841. if (!fptr2)
  18842. {
  18843. DEBUG_INFO("Unable to open a temporary file to write!!\n");
  18844. fclose(fptr1);
  18845. return ;
  18846. }
  18847. ch=fgetc(fptr1);
  18848. rewind(fptr1);
  18849. if(ch!=EOF)
  18850. {
  18851. // copy all contents to the temporary file except the specific line
  18852. while (fgets(str, 100, fptr1) != NULL)
  18853. {
  18854. str[strlen(str) - 1] = '\0'; // eat the newline fgets() stores
  18855. if(str[0]=='\0')
  18856. {
  18857. break;
  18858. }
  18859. char *revbuf[8] = {0};
  18860. int num = 0;
  18861. strcpy(strtemp, str);
  18862. splitstring(str,",",revbuf,&num);
  18863. if(revbuf[2][0] != '\0')
  18864. {
  18865. temptransactionId = atoi(revbuf[2]);
  18866. if(transactionId != temptransactionId)
  18867. {
  18868. fprintf(fptr2, "%s\n", strtemp);
  18869. }
  18870. }
  18871. }
  18872. }
  18873. fclose(fptr1);
  18874. fclose(fptr2);
  18875. remove("/Storage/OCPP/QueueTransactionId"); // remove the original file
  18876. rename(temp, "/Storage/OCPP/QueueTransactionId"); // rename the temporary file to original name
  18877. /*------ Read the file ----------------*/
  18878. }
  18879. int InternetDisconnect(void)
  18880. {
  18881. return (ShmStatusCodeData->InfoCode.InfoEvents.bits.InternetDisconnectVia4Gi && ShmStatusCodeData->InfoCode.InfoEvents.bits.InternetDisconnectViaEthernet && ShmStatusCodeData->InfoCode.InfoEvents.bits.InternetDisconnectViaWiFi );
  18882. }
  18883. //Note: It is not real StopTransaction. It is temporary StopTransaction.
  18884. void storeTempStopTransaction(int gun_index)
  18885. {
  18886. char guid[37]={0};
  18887. int tempIndex = 0;
  18888. char TempStopTransaction[256];
  18889. sprintf(TempStopTransaction, "/Storage/OCPP/TempStopTransaction_%d", (gun_index+1));
  18890. DEBUG_INFO("storeTempStopTransaction...\n");
  18891. memset(queuedata, 0, ARRAY_SIZE(queuedata));
  18892. memset(&ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0], 0, ARRAY_SIZE(ShmOCPP16Data->StopTransaction[gun_index].TransactionData));
  18893. //======================== ENERGY_ACTIVE_IMPORT_REGISTER =======================================
  18894. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DCcc
  18895. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  18896. {
  18897. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  18898. {
  18899. tempIndex = ((gun_index==2) ? 1: 0);
  18900. }
  18901. else
  18902. {
  18903. tempIndex = gun_index;
  18904. }
  18905. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  18906. {
  18907. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  18908. {
  18909. ShmOCPP16Data->StopTransaction[gun_index].MeterStop = (int)(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PowerConsumption*1000);
  18910. }
  18911. }// END OF CHAdeMO_QUANTITY
  18912. }
  18913. else if(gunType[gun_index] == GUN_TYPE_CCS)
  18914. {
  18915. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  18916. {
  18917. tempIndex = ((gun_index==2) ? 1: 0);
  18918. }
  18919. else
  18920. {
  18921. tempIndex = gun_index;
  18922. }
  18923. for (int index = 0; index < CCS_QUANTITY; index++)
  18924. {
  18925. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  18926. {
  18927. ShmOCPP16Data->StopTransaction[gun_index].MeterStop = (int)(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PowerConsumption*1000);
  18928. }
  18929. }// END OF CCS_QUANTITY
  18930. }
  18931. else if(gunType[gun_index] == GUN_TYPE_GBT)
  18932. {
  18933. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  18934. {
  18935. tempIndex = ((gun_index==2) ? 1: 0);
  18936. }
  18937. else
  18938. {
  18939. tempIndex = gun_index;
  18940. }
  18941. for (int index = 0; index < GB_QUANTITY; index++)
  18942. {
  18943. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  18944. {
  18945. ShmOCPP16Data->StopTransaction[gun_index].MeterStop = (int)(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PowerConsumption*1000);
  18946. }
  18947. }// END OF GB_QUANTITY
  18948. }
  18949. else if(gunType[gun_index] == GUN_TYPE_DO)
  18950. {
  18951. tempIndex = gun_index;
  18952. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  18953. {
  18954. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  18955. {
  18956. ShmOCPP16Data->StopTransaction[gun_index].MeterStop = (int)(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PowerConsumption*1000);
  18957. }
  18958. }
  18959. }
  18960. else
  18961. {
  18962. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  18963. {
  18964. tempIndex = 2;
  18965. }
  18966. else
  18967. {
  18968. tempIndex = gun_index;
  18969. }
  18970. for (int index = 0; index < AC_QUANTITY; index++)
  18971. {
  18972. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  18973. {
  18974. ShmOCPP16Data->StopTransaction[gun_index].MeterStop = (int)(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PowerConsumption*1000);
  18975. }
  18976. }// END OF AC_QUANTITY
  18977. }
  18978. //Stop Transaction Time
  18979. struct timeval tmnow;
  18980. struct tm *tm;
  18981. char buf[28];//, usec_buf[6];
  18982. gettimeofday(&tmnow, NULL);
  18983. time_t t;
  18984. t = time(NULL);
  18985. /*UTC time and date*/
  18986. tm = gmtime(&t);
  18987. strftime(buf,28,"%Y-%m-%dT%H:%M:%SZ", tm);
  18988. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].Timestamp,buf);
  18989. ShmOCPP16Data->StopTransaction[gun_index].TransactionId = ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId;
  18990. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].IdTag, (const char*)ShmOCPP16Data->StartTransaction[gun_index].IdTag);
  18991. random_uuid(guid);
  18992. /***********************************transactionData******************************************************/
  18993. memset(ShmOCPP16Data->StopTransaction[gun_index].TransactionData, 0, sizeof(struct StructMeterValue));
  18994. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].TimeStamp, buf);
  18995. //=================================
  18996. //1. Transaction_Begin
  18997. //=================================
  18998. //============================== Energy.Active.Import.Interval ===========================================
  18999. //=================================
  19000. //2. Transaction_End
  19001. //=================================
  19002. //2.1====================================== Current.Import L1 ==============================================
  19003. if(strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Current.Import") != NULL)
  19004. {
  19005. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G : GBT DC
  19006. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  19007. {
  19008. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  19009. {
  19010. tempIndex = ((gun_index==2) ? 1: 0);
  19011. }
  19012. else
  19013. {
  19014. tempIndex = gun_index;
  19015. }
  19016. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  19017. {
  19018. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  19019. {
  19020. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargingCurrent );// PresentChargingCurrent is 0~6553.5 amp
  19021. }
  19022. }// End of for CHAdeMO_QUANTITY
  19023. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase,PhaseStr[L3_N]);
  19024. }
  19025. else if(gunType[gun_index] == GUN_TYPE_CCS)
  19026. {
  19027. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  19028. {
  19029. tempIndex = ((gun_index==2) ? 1: 0);
  19030. }
  19031. else
  19032. {
  19033. tempIndex = gun_index;
  19034. }
  19035. for (int index = 0; index < CCS_QUANTITY; index++)
  19036. {
  19037. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  19038. {
  19039. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargingCurrent );// PresentChargingCurrent is 0~6553.5 amp
  19040. }
  19041. }// End of for CCS_QUANTITY
  19042. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase,PhaseStr[L3_N]);
  19043. }
  19044. else if(gunType[gun_index] == GUN_TYPE_GBT)
  19045. {
  19046. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  19047. {
  19048. tempIndex = ((gun_index==2) ? 1: 0);
  19049. }
  19050. else
  19051. {
  19052. tempIndex = gun_index;
  19053. }
  19054. for (int index = 0; index < GB_QUANTITY; index++)
  19055. {
  19056. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  19057. {
  19058. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingCurrent );// PresentChargingCurrent is 0~6553.5 amp
  19059. }
  19060. }// End of for GB_QUANTITY
  19061. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase,PhaseStr[L3_N]);
  19062. }
  19063. else if(gunType[gun_index] == GUN_TYPE_DO)
  19064. {
  19065. tempIndex = gun_index;
  19066. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  19067. {
  19068. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  19069. {
  19070. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PresentChargingCurrent );// PresentChargingCurrent is 0~6553.5 amp
  19071. }
  19072. }
  19073. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase,PhaseStr[L3_N]);
  19074. }
  19075. else
  19076. {
  19077. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  19078. {
  19079. tempIndex = 2;
  19080. }
  19081. else
  19082. {
  19083. tempIndex = gun_index;
  19084. }
  19085. for (int index = 0; index < AC_QUANTITY; index++)
  19086. {
  19087. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  19088. {
  19089. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingCurrent );// 0~6553.5 amp for EVSE
  19090. }
  19091. }// End of for AC_QUANTITY
  19092. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase,PhaseStr[L1_N]);
  19093. }
  19094. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  19095. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Format,ValueFormatStr[Raw]);
  19096. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Measurand,MeasurandStr[Current_Import]);
  19097. //strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase,PhaseStr[L1_N]);
  19098. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Location,LocationStr[Location_Outlet]);
  19099. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Unit,UnitOfMeasureStr[UnitOfMeasure_A]);
  19100. }
  19101. //2.2===================================== Energy.Active.Import.Interval ==========================================
  19102. if(strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Energy.Active.Import.Interval") != NULL)
  19103. {
  19104. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  19105. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  19106. {
  19107. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  19108. {
  19109. tempIndex = ((gun_index==2) ? 1: 0);
  19110. }
  19111. else
  19112. {
  19113. tempIndex = gun_index;
  19114. }
  19115. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  19116. {
  19117. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  19118. {
  19119. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Value, "%.3f" ,(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PowerConsumption - periousPeriodicPowerConsumption[gun_index]));// PresentChargedEnergy is 0~6553.5 kWh
  19120. }
  19121. }// END OF CHAdeMO_QUANTITY
  19122. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase,PhaseStr[L3_N]);
  19123. }
  19124. else if(gunType[gun_index] == GUN_TYPE_CCS)
  19125. {
  19126. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  19127. {
  19128. tempIndex = ((gun_index==2) ? 1: 0);
  19129. }
  19130. else
  19131. {
  19132. tempIndex = gun_index;
  19133. }
  19134. for (int index = 0; index < CCS_QUANTITY; index++)
  19135. {
  19136. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  19137. {
  19138. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Value, "%.3f" ,(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PowerConsumption - periousPeriodicPowerConsumption[gun_index]));// PresentChargedEnergy is 0~6553.5 kWh
  19139. }
  19140. }// END OF CCS_QUANTITY
  19141. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase,PhaseStr[L3_N]);
  19142. }
  19143. else if(gunType[gun_index] == GUN_TYPE_GBT)
  19144. {
  19145. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  19146. {
  19147. tempIndex = ((gun_index==2) ? 1: 0);
  19148. }
  19149. else
  19150. {
  19151. tempIndex = gun_index;
  19152. }
  19153. for (int index = 0; index < GB_QUANTITY; index++)
  19154. {
  19155. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  19156. {
  19157. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Value, "%.3f" ,(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PowerConsumption - periousPeriodicPowerConsumption[gun_index]));// PresentChargedEnergy is 0~6553.5 kWh
  19158. }
  19159. }// END OF GB_QUANTITY
  19160. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase,PhaseStr[L3_N]);
  19161. }
  19162. else if(gunType[gun_index] == GUN_TYPE_DO)
  19163. {
  19164. tempIndex = gun_index;
  19165. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  19166. {
  19167. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  19168. {
  19169. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Value, "%.3f" ,(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PowerConsumption - periousPeriodicPowerConsumption[gun_index]));// PresentChargedEnergy is 0~6553.5 kWh
  19170. }
  19171. }
  19172. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase,PhaseStr[L3_N]);
  19173. }
  19174. else
  19175. {
  19176. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  19177. {
  19178. tempIndex = 2;
  19179. }
  19180. else
  19181. {
  19182. tempIndex = gun_index;
  19183. }
  19184. for (int index = 0; index < AC_QUANTITY; index++)
  19185. {
  19186. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  19187. {
  19188. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Value, "%.3f" ,(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PowerConsumption - periousPeriodicPowerConsumption[gun_index]));// PresentChargedEnergy is 0~6553.5 kWh
  19189. }
  19190. }// END OF AC_QUANTITY
  19191. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase,PhaseStr[L1_N]);
  19192. }
  19193. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  19194. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Format,ValueFormatStr[Raw]);
  19195. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Measurand,MeasurandStr[Energy_Active_Import_Interval]);
  19196. //strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase,PhaseStr[L1_N]);
  19197. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Location,LocationStr[Location_Outlet]);
  19198. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Unit,UnitOfMeasureStr[UnitOfMeasure_kWh]);
  19199. }
  19200. //2.3====================================== Power.Active.Import =========================================
  19201. if(strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Power.Active.Import") != NULL)
  19202. {
  19203. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  19204. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  19205. {
  19206. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  19207. {
  19208. tempIndex = ((gun_index==2) ? 1: 0);
  19209. }
  19210. else
  19211. {
  19212. tempIndex = gun_index;
  19213. }
  19214. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  19215. {
  19216. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  19217. {
  19218. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargingPower );// PresentChargingPower is 0~6553.5 kW
  19219. }
  19220. } // End for CHAdeMO_QUANTITY
  19221. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase,PhaseStr[L3_N]);
  19222. }
  19223. else if(gunType[gun_index] == GUN_TYPE_CCS)
  19224. {
  19225. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  19226. {
  19227. tempIndex = ((gun_index==2) ? 1: 0);
  19228. }
  19229. else
  19230. {
  19231. tempIndex = gun_index;
  19232. }
  19233. for (int index = 0; index < CCS_QUANTITY; index++)
  19234. {
  19235. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  19236. {
  19237. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargingPower );// PresentChargingPower is 0~6553.5 kW
  19238. }
  19239. } // END for CCS_QUANTITY
  19240. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase,PhaseStr[L3_N]);
  19241. }
  19242. else if(gunType[gun_index] == GUN_TYPE_GBT)
  19243. {
  19244. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  19245. {
  19246. tempIndex = ((gun_index==2) ? 1: 0);
  19247. }
  19248. else
  19249. {
  19250. tempIndex = gun_index;
  19251. }
  19252. for (int index = 0; index < GB_QUANTITY; index++)
  19253. {
  19254. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  19255. {
  19256. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingPower );// PresentChargingPower is 0~6553.5 kW
  19257. }
  19258. }// END for GB_QUANTITY
  19259. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase,PhaseStr[L3_N]);
  19260. }
  19261. else if(gunType[gun_index] == GUN_TYPE_DO)
  19262. {
  19263. tempIndex = gun_index;
  19264. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  19265. {
  19266. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  19267. {
  19268. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PresentChargingPower );// PresentChargingPower is 0~6553.5 kW
  19269. }
  19270. }
  19271. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase,PhaseStr[L3_N]);
  19272. }
  19273. else
  19274. {
  19275. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  19276. {
  19277. tempIndex = 2;
  19278. }
  19279. else
  19280. {
  19281. tempIndex = gun_index;
  19282. }
  19283. for (int index = 0; index < AC_QUANTITY; index++)
  19284. {
  19285. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  19286. {
  19287. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingPower );// PresentChargingPower is 0~6553.5 kW
  19288. }
  19289. } // END for AC_QUANTITY
  19290. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase,PhaseStr[L1_N]);
  19291. }
  19292. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  19293. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Format,ValueFormatStr[Raw]);
  19294. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Measurand,MeasurandStr[Power_Active_Import]);
  19295. //strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase,PhaseStr[L1_N]);
  19296. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Location,LocationStr[Location_Outlet]);
  19297. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Unit,UnitOfMeasureStr[UnitOfMeasure_kW/*UnitOfMeasure_kWh*/]);
  19298. }
  19299. //2.4====================================== Voltage L1 ====================================================
  19300. if(strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Voltage") != NULL)
  19301. {
  19302. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  19303. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  19304. {
  19305. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  19306. {
  19307. tempIndex = ((gun_index==2) ? 1: 0);
  19308. }
  19309. else
  19310. {
  19311. tempIndex = gun_index;
  19312. }
  19313. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  19314. {
  19315. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  19316. {
  19317. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargingVoltage );// PresentChargingVoltage is 0~6553.5 volt
  19318. }
  19319. } // END OF FOR CHAdeMO_QUANTITY
  19320. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase,PhaseStr[L3_N]);
  19321. }
  19322. else if(gunType[gun_index] == GUN_TYPE_CCS)
  19323. {
  19324. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  19325. {
  19326. tempIndex = ((gun_index==2) ? 1: 0);
  19327. }
  19328. else
  19329. {
  19330. tempIndex = gun_index;
  19331. }
  19332. for (int index = 0; index < CCS_QUANTITY; index++)
  19333. {
  19334. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  19335. {
  19336. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargingVoltage );// PresentChargingVoltage is 0~6553.5 volt
  19337. }
  19338. } // END OF FOR CCS_QUANTITY
  19339. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase,PhaseStr[L3_N]);
  19340. }
  19341. else if(gunType[gun_index] == GUN_TYPE_GBT)
  19342. {
  19343. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  19344. {
  19345. tempIndex = ((gun_index==2) ? 1: 0);
  19346. }
  19347. else
  19348. {
  19349. tempIndex = gun_index;
  19350. }
  19351. for (int index = 0; index < GB_QUANTITY; index++)
  19352. {
  19353. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  19354. {
  19355. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingVoltage );// PresentChargingVoltage is 0~6553.5 volt
  19356. }
  19357. } // END OF FOR GB_QUANTITY
  19358. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase,PhaseStr[L3_N]);
  19359. }
  19360. else if(gunType[gun_index] == GUN_TYPE_DO)
  19361. {
  19362. tempIndex = gun_index;
  19363. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  19364. {
  19365. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  19366. {
  19367. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PresentChargingVoltage );// PresentChargingVoltage is 0~6553.5 volt
  19368. }
  19369. }
  19370. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase,PhaseStr[L3_N]);
  19371. }
  19372. else
  19373. {
  19374. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  19375. {
  19376. tempIndex = 2;
  19377. }
  19378. else
  19379. {
  19380. tempIndex = gun_index;
  19381. }
  19382. for (int index = 0; index < AC_QUANTITY; index++)
  19383. {
  19384. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  19385. {
  19386. 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
  19387. }
  19388. } // END OF FOR AC_QUANTITY
  19389. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase,PhaseStr[L1_N]);
  19390. }
  19391. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  19392. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Format,ValueFormatStr[Raw]);
  19393. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Measurand,MeasurandStr[Voltage]);
  19394. //strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase,PhaseStr[L1_N]);
  19395. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Location,LocationStr[Location_Outlet]);
  19396. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Unit,UnitOfMeasureStr[UnitOfMeasure_V]);
  19397. }
  19398. //2.5============================================== End SoC =========================================================
  19399. if(strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, MeasurandStr[SoC]) != NULL)
  19400. {
  19401. //J : CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  19402. 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))
  19403. {
  19404. if((ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0') && (gunType[gun_index] != GUN_TYPE_DO))
  19405. {
  19406. tempIndex = ((gun_index==2) ? 1: 0);
  19407. }
  19408. else
  19409. {
  19410. tempIndex = gun_index;
  19411. }
  19412. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  19413. {
  19414. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  19415. {
  19416. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  19417. {
  19418. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].EvBatterySoc );// 0~100%
  19419. }
  19420. }
  19421. }
  19422. else if(gunType[gun_index] == GUN_TYPE_CCS)
  19423. {
  19424. for (int index = 0; index < CCS_QUANTITY; index++)
  19425. {
  19426. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  19427. {
  19428. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].EvBatterySoc );// 0~100%
  19429. }
  19430. }
  19431. }
  19432. else if(gunType[gun_index] == GUN_TYPE_GBT)
  19433. {
  19434. for (int index = 0; index < GB_QUANTITY; index++)
  19435. {
  19436. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  19437. {
  19438. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].EvBatterySoc );// 0~100%
  19439. }
  19440. }
  19441. }
  19442. else if(gunType[gun_index] == GUN_TYPE_DO)
  19443. {
  19444. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  19445. {
  19446. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  19447. {
  19448. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.EvBatterySoc );// 0~100%
  19449. }
  19450. }
  19451. }
  19452. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  19453. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Format,ValueFormatStr[Raw]);
  19454. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Measurand,MeasurandStr[SoC/*Energy_Reactive_Export_Register*/]);
  19455. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Phase,PhaseStr[L3_N]);
  19456. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Location,LocationStr[Location_EV]);
  19457. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Unit,UnitOfMeasureStr[UnitOfMeasure_Percent/*UnitOfMeasure_kWh*/]);
  19458. } // END FOR DC CASE
  19459. }
  19460. //2.6====================================== Current.Import L2 ==============================================
  19461. if(strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Current.Import") != NULL)
  19462. {
  19463. // AC 3 phase L2 current
  19464. if((gunType[gun_index] == GUN_TYPE_AC) && ((ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'W') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='D')))
  19465. {
  19466. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  19467. {
  19468. tempIndex = 2;
  19469. }
  19470. else
  19471. {
  19472. tempIndex = gun_index;
  19473. }
  19474. for (int index = 0; index < AC_QUANTITY; index++)
  19475. {
  19476. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  19477. {
  19478. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingCurrentL2);// 0~6553.5 amp for EVSE
  19479. }
  19480. }// End of for AC_QUANTITY
  19481. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Phase,PhaseStr[L2_N]);
  19482. }
  19483. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  19484. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Format,ValueFormatStr[Raw]);
  19485. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Measurand,MeasurandStr[Current_Import]);
  19486. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Location,LocationStr[Location_Outlet]);
  19487. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Unit,UnitOfMeasureStr[UnitOfMeasure_A]);
  19488. }
  19489. //2.7====================================== Current.Import L3 ==============================================
  19490. if(strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Current.Import") != NULL)
  19491. {
  19492. // AC 3 phase L3 current
  19493. if((gunType[gun_index] == GUN_TYPE_AC) && ((ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'W') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='D')))
  19494. {
  19495. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  19496. {
  19497. tempIndex = 2;
  19498. }
  19499. else
  19500. {
  19501. tempIndex = gun_index;
  19502. }
  19503. for (int index = 0; index < AC_QUANTITY; index++)
  19504. {
  19505. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  19506. {
  19507. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingCurrentL3);// 0~6553.5 amp for EVSE
  19508. }
  19509. }// End of for AC_QUANTITY
  19510. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Phase,PhaseStr[L3_N]);
  19511. }
  19512. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  19513. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Format,ValueFormatStr[Raw]);
  19514. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Measurand,MeasurandStr[Current_Import]);
  19515. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Location,LocationStr[Location_Outlet]);
  19516. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Unit,UnitOfMeasureStr[UnitOfMeasure_A]);
  19517. }
  19518. //2.9====================================== Voltage L2 ====================================================
  19519. if(strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Voltage") != NULL)
  19520. {
  19521. // AC 3 phase L2 volatge
  19522. if((gunType[gun_index] == GUN_TYPE_AC) && ((ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'W') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='D')))
  19523. {
  19524. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  19525. {
  19526. tempIndex = 2;
  19527. }
  19528. else
  19529. {
  19530. tempIndex = gun_index;
  19531. }
  19532. for (int index = 0; index < AC_QUANTITY; index++)
  19533. {
  19534. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  19535. {
  19536. 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
  19537. }
  19538. } // END OF FOR AC_QUANTITY
  19539. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Phase,PhaseStr[L2_N]);
  19540. }
  19541. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  19542. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Format,ValueFormatStr[Raw]);
  19543. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Measurand,MeasurandStr[Voltage]);
  19544. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Location,LocationStr[Location_Outlet]);
  19545. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Unit,UnitOfMeasureStr[UnitOfMeasure_V]);
  19546. }
  19547. //2.10====================================== Voltage L3 ====================================================
  19548. if(strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Voltage") != NULL)
  19549. {
  19550. // AC 3 phase L3 volatge
  19551. if((gunType[gun_index] == GUN_TYPE_AC) && ((ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'W') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='D')))
  19552. {
  19553. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  19554. {
  19555. tempIndex = 2;
  19556. }
  19557. else
  19558. {
  19559. tempIndex = gun_index;
  19560. }
  19561. for (int index = 0; index < AC_QUANTITY; index++)
  19562. {
  19563. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  19564. {
  19565. 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
  19566. }
  19567. } // END OF FOR AC_QUANTITY
  19568. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Phase,PhaseStr[L3_N]);
  19569. }
  19570. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  19571. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Format,ValueFormatStr[Raw]);
  19572. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Measurand,MeasurandStr[Voltage]);
  19573. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Location,LocationStr[Location_Outlet]);
  19574. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Unit,UnitOfMeasureStr[UnitOfMeasure_V]);
  19575. }
  19576. //====================== Start SoC ================================
  19577. if(strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, MeasurandStr[SoC]) != NULL)
  19578. {
  19579. //J : CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  19580. 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))
  19581. {
  19582. if((ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0') && (gunType[gun_index] != GUN_TYPE_DO))
  19583. {
  19584. tempIndex = ((gun_index==2) ? 1: 0);
  19585. }
  19586. else
  19587. {
  19588. tempIndex = gun_index;
  19589. }
  19590. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  19591. {
  19592. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  19593. {
  19594. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  19595. {
  19596. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].EvBatteryStartSoc );// 0~100%
  19597. }
  19598. }
  19599. }
  19600. else if(gunType[gun_index] == GUN_TYPE_CCS)
  19601. {
  19602. for (int index = 0; index < CCS_QUANTITY; index++)
  19603. {
  19604. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  19605. {
  19606. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].EvBatteryStartSoc );// 0~100%
  19607. }
  19608. }
  19609. }
  19610. else if(gunType[gun_index] == GUN_TYPE_GBT)
  19611. {
  19612. for (int index = 0; index < GB_QUANTITY; index++)
  19613. {
  19614. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  19615. {
  19616. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].EvBatteryStartSoc );// 0~100%
  19617. }
  19618. }
  19619. }
  19620. else if(gunType[gun_index] == GUN_TYPE_DO)
  19621. {
  19622. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  19623. {
  19624. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  19625. {
  19626. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.EvBatteryStartSoc );// 0~100%
  19627. }
  19628. }
  19629. }
  19630. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Context,ReadingContextStr[ReadingContext_Transaction_Begin]);
  19631. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Format,ValueFormatStr[Raw]);
  19632. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Measurand,MeasurandStr[SoC/*Energy_Reactive_Export_Register*/]);
  19633. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Phase,PhaseStr[L3_N]);
  19634. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Location,LocationStr[Location_EV]);
  19635. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Unit,UnitOfMeasureStr[UnitOfMeasure_Percent/*UnitOfMeasure_kWh*/]);
  19636. } // END FOR DC CASE
  19637. }
  19638. //======================================== Message create ==============================================
  19639. json_object *StopTransaction = json_object_new_object();
  19640. json_object *transactionDatas = json_object_new_array();
  19641. json_object *sampledValues = json_object_new_array();
  19642. if(strlen((char*)ShmOCPP16Data->StopTransaction[gun_index].IdTag) > 0)
  19643. json_object_object_add(StopTransaction, "idTag", json_object_new_string((char*)ShmOCPP16Data->StopTransaction[gun_index].IdTag));
  19644. json_object_object_add(StopTransaction, "meterStop", json_object_new_int(ShmOCPP16Data->StopTransaction[gun_index].MeterStop));
  19645. json_object_object_add(StopTransaction, "transactionId", json_object_new_int(ShmOCPP16Data->StopTransaction[gun_index].TransactionId));
  19646. json_object_object_add(StopTransaction, "timestamp", json_object_new_string((char*)ShmOCPP16Data->StopTransaction[gun_index].Timestamp));
  19647. json_object_object_add(StopTransaction, "reason", json_object_new_string("PowerLoss"));
  19648. for(int idxTrans = 0;idxTrans<ARRAY_SIZE(ShmOCPP16Data->StopTransaction[gun_index].TransactionData);idxTrans++)
  19649. {
  19650. json_object *transactionData = json_object_new_object();
  19651. json_object_object_add(transactionData, "timestamp", json_object_new_string((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].TimeStamp));
  19652. for(int idx=0;idx<ARRAY_SIZE(ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue);idx++)
  19653. {
  19654. if(strlen((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Value) > 0)
  19655. {
  19656. json_object *sampledValue = json_object_new_object();
  19657. json_object_object_add(sampledValue, "value", json_object_new_string((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Value));
  19658. if(strlen((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Context) > 0)
  19659. json_object_object_add(sampledValue, "context", json_object_new_string((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Context));
  19660. if(strlen((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Format) > 0)
  19661. json_object_object_add(sampledValue, "format", json_object_new_string((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Format));
  19662. if(strlen((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Measurand) > 0)
  19663. json_object_object_add(sampledValue, "measurand", json_object_new_string((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Measurand));
  19664. if(strlen((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Phase) > 0)
  19665. json_object_object_add(sampledValue, "phase", json_object_new_string((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Phase));
  19666. if(strlen((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Location) > 0)
  19667. json_object_object_add(sampledValue, "location", json_object_new_string((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Location));
  19668. if(strlen((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Unit) > 0)
  19669. json_object_object_add(sampledValue, "unit", json_object_new_string((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Unit));
  19670. json_object_array_add(sampledValues, sampledValue);
  19671. }
  19672. }
  19673. json_object_object_add(transactionData, "sampledValue", sampledValues);
  19674. json_object_array_add(transactionDatas, transactionData);
  19675. }
  19676. json_object_object_add(StopTransaction, "transactionData", transactionDatas);
  19677. sprintf(queuedata, "%d,[%d,\"%s\",\"StopTransaction\",%s]",(gun_index+1)
  19678. ,MESSAGE_TYPE_CALL
  19679. ,guid
  19680. ,json_object_to_json_string_ext(StopTransaction, JSON_C_TO_STRING_PLAIN));
  19681. json_object_put(StopTransaction);
  19682. // Check File "TempStopTransaction" Exist
  19683. if((access(TempStopTransaction,F_OK))!=-1)
  19684. {
  19685. //DEBUG_INFO("TransactionRelatedQueue exist.\n");
  19686. fclose(fopen(TempStopTransaction, "w"));
  19687. }
  19688. else
  19689. {
  19690. //DEBUG_INFO("TransactionRelatedQueue not exist\n");
  19691. FILE *log = fopen(TempStopTransaction, "w+");
  19692. if(log == NULL)
  19693. {
  19694. //DEBUG_INFO("Can't Create File TransactionRelatedQueue \n");
  19695. return ;
  19696. }
  19697. else
  19698. {
  19699. fclose(log);
  19700. }
  19701. }
  19702. //Add TempStopTransaction | Update TempStopTransaction
  19703. // open file for writing
  19704. FILE *outfile;
  19705. outfile = fopen (TempStopTransaction, "a");
  19706. //DEBUG_INFO("data = %s\n", queuedata);
  19707. fputs(queuedata, outfile);
  19708. fputs("\n", outfile);
  19709. fclose (outfile);
  19710. system("/bin/fsync -d /dev/mtdblock13;/bin/sync &");
  19711. OCPP_updatePeriodEnergy(gun_index);
  19712. }
  19713. void checkTempStopTransaction(int gun_index)
  19714. {
  19715. FILE *fptr1;
  19716. char ch;
  19717. char str[QUEUE_MESSAGE_LENGTH]={0};
  19718. char guid[37]={0};
  19719. char tempdata[65]={0};
  19720. char connectorStr[2]={0};
  19721. char TempStopTransaction[256];
  19722. sprintf(TempStopTransaction, "/Storage/OCPP/TempStopTransaction_%d", (gun_index+1));
  19723. fptr1 = fopen(TempStopTransaction, "r");
  19724. //TempStopTransaction格式: 槍號,StopTransaction封包
  19725. if (!fptr1)
  19726. {
  19727. //printf(" File not found or unable to open the input file!!\n");
  19728. return ;
  19729. }
  19730. ch=fgetc(fptr1);
  19731. //printf(" Now the content of the file %s is : \n",fname);
  19732. rewind(fptr1);
  19733. if(ch!=EOF)
  19734. {
  19735. // copy all contents to the temporary file except the specific line
  19736. while (fgets(str, QUEUE_MESSAGE_LENGTH, fptr1) != NULL)
  19737. {
  19738. str[strlen(str) - 1] = '\0'; // eat the newline fgets() stores
  19739. if(str[0]=='\0')
  19740. {
  19741. break;
  19742. }
  19743. //TempStopTransaction格式: 槍號,StopTransaction封包
  19744. strncpy(connectorStr, str, 1);
  19745. if(atoi(connectorStr) != (gun_index+1))
  19746. {
  19747. DEBUG_INFO("atoi(connectorStr) = %d, gun_index = %d\n", atoi(connectorStr), gun_index);
  19748. fclose(fptr1);
  19749. return ;
  19750. }
  19751. //random_uuid(guid);
  19752. strncpy(guid, str+6, 36); //copy guid
  19753. sprintf(tempdata, "StopTransaction,%d", (gun_index));
  19754. if(hashmap_operation(HASH_OP_ADD, guid, tempdata) == 1)
  19755. {
  19756. //DEBUG_INFO("StopTransaction mapitem pass\n");
  19757. }
  19758. queue_operation(QUEUE_OPERATION_ADD, guid, str);//addq(guid, queuedata); ---> remove temporally
  19759. OCPP_insert_transaction_msg(NO, str);
  19760. memset(str,0,ARRAY_SIZE(str));
  19761. }
  19762. }
  19763. // fptr1=freopen(NULL,"w",fptr1); // reset the fptr1 again
  19764. fclose(fptr1);
  19765. remove(TempStopTransaction); // remove the original file
  19766. system("/bin/fsync -d /dev/mtdblock13;/bin/sync &");
  19767. }
  19768. void FillStartTransaction(int ConnectorId, unsigned char IdTag[], int MeterStart,int ReservationId,unsigned char Timestamp[])
  19769. {
  19770. ShmOCPP16Data->StartTransaction[ConnectorId-1].ConnectorId = ConnectorId;
  19771. ShmOCPP16Data->StartTransaction[ConnectorId-1].ReservationId = ReservationId;
  19772. ShmOCPP16Data->StartTransaction[ConnectorId-1].MeterStart = MeterStart;
  19773. strcpy((char *)ShmOCPP16Data->StartTransaction[ConnectorId-1].IdTag, (char *)IdTag);
  19774. strcpy((char *)ShmOCPP16Data->StartTransaction[ConnectorId-1].Timestamp,(char *) Timestamp);
  19775. }
  19776. int GetWebSocketPingInterval(void)
  19777. {
  19778. return atoi((const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemData);
  19779. }
  19780. int GetServerSign(void)
  19781. {
  19782. return server_sign;
  19783. }
  19784. uint8_t GetOcppSecurityProfile()
  19785. {
  19786. return atoi((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[SecurityProfile].ItemData);
  19787. }
  19788. void GetOcppChargerBoxId(uint8_t *data)
  19789. {
  19790. sprintf((char*)data, "%s", ShmSysConfigAndInfo->SysConfig.ChargeBoxId);
  19791. }
  19792. void GetOcppSecurityPassword(uint8_t *data)
  19793. {
  19794. sprintf((char*)data, "%s", ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationKey].ItemData);
  19795. }
  19796. void SetOcppVersion(uint8_t *version)
  19797. {
  19798. for (uint8_t idx=0; idx<strlen((char*)version); idx++) version[idx] = tolower(version[idx]);
  19799. DEBUG_INFO("ocpp version: %s\n", version);
  19800. if(strstr((char*)version, "ocpp1.6") != NULL)
  19801. {
  19802. ShmSysConfigAndInfo->SysInfo.OcppRunningVer = OCPP_RUNNING_VERSION_16;
  19803. }
  19804. else if(strstr((char*)version, "ocpp2.0") != NULL)
  19805. {
  19806. ShmSysConfigAndInfo->SysInfo.OcppRunningVer = OCPP_RUNNING_VERSION_20;
  19807. system("pkill OcppBackend");
  19808. }
  19809. }
  19810. void SetServerSign(int value)
  19811. {
  19812. server_sign = value;
  19813. }
  19814. int GetBootNotificationInterval(void)
  19815. {
  19816. return BootNotificationInterval;
  19817. }
  19818. int GetInternetConn(void)
  19819. {
  19820. return ShmSysConfigAndInfo->SysInfo.InternetConn;
  19821. }
  19822. int GetBackendConnectionTimeout(void)
  19823. {
  19824. return ShmSysConfigAndInfo->SysConfig.BackendConnTimeout>=0?ShmSysConfigAndInfo->SysConfig.BackendConnTimeout:300;
  19825. }
  19826. int isConnectorInitMode(int gun_index)
  19827. {
  19828. int tempIndex = 0;
  19829. int result = TRUE;
  19830. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DCcc
  19831. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  19832. {
  19833. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  19834. {
  19835. tempIndex = ((gun_index==2) ? 1: 0);
  19836. }
  19837. else
  19838. {
  19839. tempIndex = gun_index;
  19840. }
  19841. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  19842. {
  19843. if ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex))
  19844. {
  19845. result = (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus==SYS_MODE_BOOTING)?TRUE:FALSE;
  19846. } //end of the same index
  19847. }//end of for CHAdeMO_QUANTITY
  19848. }
  19849. else if(gunType[gun_index] == GUN_TYPE_CCS)
  19850. {
  19851. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  19852. {
  19853. tempIndex = ((gun_index==2) ? 1: 0);
  19854. }
  19855. else
  19856. {
  19857. tempIndex = gun_index;
  19858. }
  19859. for (int index = 0; index < CCS_QUANTITY; index++)
  19860. {
  19861. if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  19862. {
  19863. result = (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus==SYS_MODE_BOOTING)?TRUE:FALSE;
  19864. } //end of the same index
  19865. } // end of for CCS_QUANTITY
  19866. }
  19867. else if(gunType[gun_index] == GUN_TYPE_GBT)
  19868. {
  19869. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  19870. {
  19871. tempIndex = ((gun_index==2) ? 1: 0);
  19872. }
  19873. else
  19874. {
  19875. tempIndex = gun_index;
  19876. }
  19877. for (int index = 0; index < GB_QUANTITY; index++)
  19878. {
  19879. if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  19880. {
  19881. result = (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus==SYS_MODE_BOOTING)?TRUE:FALSE;
  19882. } //end of the same index
  19883. } // end of for GB_QUANTITY
  19884. }
  19885. else if(gunType[gun_index] == GUN_TYPE_DO)
  19886. {
  19887. tempIndex = gun_index;
  19888. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  19889. {
  19890. if(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  19891. {
  19892. result = (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus==SYS_MODE_BOOTING)?TRUE:FALSE;
  19893. } //end of the same index
  19894. }
  19895. }
  19896. else
  19897. {
  19898. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  19899. {
  19900. tempIndex = 2;
  19901. }
  19902. else
  19903. {
  19904. tempIndex = gun_index;
  19905. }
  19906. for (int index = 0; index < AC_QUANTITY; index++)
  19907. {
  19908. if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  19909. {
  19910. result = (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus==SYS_MODE_BOOTING)?TRUE:FALSE;
  19911. }//end of the same index
  19912. }//end of for AC_QUANTITY
  19913. }
  19914. return result;
  19915. }
  19916. void refreshProcDogTimer()
  19917. {
  19918. ShmOCPP16Data->procDogTime = time((time_t*)NULL);
  19919. }
  19920. void InitialSystemValue(void)
  19921. {
  19922. server_cycle_Status = atoi((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemData);
  19923. locallistVersion=0;
  19924. BootNotificationInterval = 0;
  19925. authorizeRetryTimes = 0;
  19926. GunStatusInterval = 10;
  19927. TransactionMessageAttemptsValue = atoi((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData);
  19928. TransactionMessageRetryIntervalValue = atoi((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData);
  19929. //Hear Beat
  19930. HeartBeatWithNOResponse = 0;
  19931. HeartBeatWaitTime = atoi((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemData);;
  19932. FirstHeartBeat = 0;
  19933. FirmwareStatusNotificationStatus = FIRMWARE_STATUS_IDLE; // Idle
  19934. DiagnosticsStatusNotificationStatus = DIAGNOSTIC_STATUS_IDLE; // Idle
  19935. memset(CurrentChargingProfileScheduleStr, 0, ARRAY_SIZE(CurrentChargingProfileScheduleStr));
  19936. memset(ChademoPreviousSystemStatus, 0, ARRAY_SIZE(ChademoPreviousSystemStatus));
  19937. memset(CcsPreviousSystemStatus, 0, ARRAY_SIZE(CcsPreviousSystemStatus));
  19938. memset(GbPreviousSystemStatus, 0, ARRAY_SIZE(GbPreviousSystemStatus));
  19939. memset(AcPreviousSystemStatus, 0, ARRAY_SIZE(AcPreviousSystemStatus));
  19940. memset(ChademoPreviousConnectorPlugIn, 0, ARRAY_SIZE(ChademoPreviousConnectorPlugIn));
  19941. memset(CcsPreviousConnectorPlugIn, 0, ARRAY_SIZE(CcsPreviousConnectorPlugIn));
  19942. memset(GbPreviousConnectorPlugIn, 0, ARRAY_SIZE(GbPreviousConnectorPlugIn));
  19943. memset(AcPreviousConnectorPlugIn, 0, ARRAY_SIZE(AcPreviousConnectorPlugIn));
  19944. //Status && ConnectorPlugIn Setting
  19945. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  19946. {
  19947. ChademoPreviousSystemStatus[index] = 99; //ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PreviousSystemStatus;
  19948. ChademoPreviousConnectorPlugIn[index] = ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ConnectorPlugIn;
  19949. }
  19950. for (int index = 0; index < CCS_QUANTITY; index++)
  19951. {
  19952. CcsPreviousSystemStatus[index] = 99; //ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PreviousSystemStatus;
  19953. CcsPreviousConnectorPlugIn[index] = ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ConnectorPlugIn;
  19954. }
  19955. for (int index = 0; index < GB_QUANTITY; index++)
  19956. {
  19957. GbPreviousSystemStatus[index] = 99; //ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PreviousSystemStatus;
  19958. GbPreviousConnectorPlugIn[index] = ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ConnectorPlugIn;
  19959. }
  19960. for (int index = 0; index < AC_QUANTITY; index++)
  19961. {
  19962. AcPreviousSystemStatus[index] = 99; //ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PreviousSystemStatus;
  19963. AcPreviousConnectorPlugIn[index] = ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PilotState;
  19964. }
  19965. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  19966. {
  19967. DoPreviousSystemStatus[index] = 99; //ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PreviousSystemStatus;
  19968. DoPreviousConnectorPlugIn[index] = ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PilotState;
  19969. }
  19970. for(int gun_index=0; gun_index < gunTotalNumber; gun_index++ )
  19971. {
  19972. cpinitateMsg.bits[gun_index].TriggerStatusNotificationReq = 0;
  19973. cpinitateMsg.bits[gun_index].StatusNotificationReq = 0;
  19974. cpinitateMsg.bits[gun_index].StatusNotificationConf = 0;
  19975. //clientTime.MeterValues[gun_index] = time((time_t*)NULL);
  19976. //memset(&ShmOCPP16Data->StatusNotification[gun_index], 0x00, sizeof(struct StructStatusNotification));
  19977. memset(&ShmOCPP16Data->StatusNotification[gun_index].Status, 0x00, sizeof(ShmOCPP16Data->StatusNotification[gun_index].Status));
  19978. }
  19979. memset( (void *)unknownkey, 0, sizeof(unknownkey));
  19980. refreshStartTimer(&clientTime.Heartbeat);
  19981. sleep(1);
  19982. }
  19983. void LWS_Send(char *str)
  19984. {
  19985. //=====================================================
  19986. // Check InternetConn 0: disconnected, 1: connected
  19987. //====================================================
  19988. if(GetOcppConnStatus() == 0)
  19989. {
  19990. DEBUG_INFO("offline now !!!\n");
  19991. return;
  19992. }
  19993. // Only disable isWebsocketSendable operation initiated by charger
  19994. if((strstr((char*)str, "\"Authorize\"") != NULL)
  19995. || (strstr((char*)str, "\"BootNotification\"") != NULL)
  19996. || (strstr((char*)str, "\"DataTransfer\"") != NULL)
  19997. || (strstr((char*)str, "\"DiagnosticsStatusNotification\"") != NULL)
  19998. || (strstr((char*)str, "\"FirmwareStatusNotification\"") != NULL)
  19999. || (strstr((char*)str, "\"Heartbeat\"") != NULL)
  20000. || (strstr((char*)str, "\"MeterValues\"") != NULL)
  20001. || (strstr((char*)str, "\"StartTransaction\"") != NULL)
  20002. || (strstr((char*)str, "\"StatusNotification\"") != NULL)
  20003. || (strstr((char*)str, "\"StopTransaction\"") != NULL)
  20004. || (strstr((char*)str, "\"LogStatusNotification\"") != NULL)
  20005. || (strstr((char*)str, "\"SecurityEventNotification\"") != NULL)
  20006. || (strstr((char*)str, "\"SignCertificate\"") != NULL)
  20007. || (strstr((char*)str, "\"SignedFirmwareStatusNotification\"") != NULL))
  20008. {
  20009. isWebsocketSendable = 0;
  20010. }
  20011. pthread_mutex_lock(&lock_send);
  20012. memset(SendBuffer, 0, ARRAY_SIZE(SendBuffer));
  20013. sprintf((char *)SendBuffer, "%s", str);
  20014. SendBufLen = strlen(str);
  20015. pthread_mutex_unlock(&lock_send);
  20016. lws_callback_on_writable(wsi_client);
  20017. //lws_service(context, 0);
  20018. //sleep(1);
  20019. }
  20020. void LWS_SendNow(char *str)
  20021. {
  20022. //=====================================================
  20023. // Check InternetConn 0: disconnected, 1: connected
  20024. //====================================================
  20025. if(GetOcppConnStatus() == 0)
  20026. {
  20027. DEBUG_INFO("offline now !!!\n");
  20028. return;
  20029. }
  20030. // Only disable isWebsocketSendable operation initiated by charger
  20031. if((strstr((char*)str, "\"Authorize\"") != NULL)
  20032. || (strstr((char*)str, "\"BootNotification\"") != NULL)
  20033. || (strstr((char*)str, "\"DataTransfer\"") != NULL)
  20034. || (strstr((char*)str, "\"DiagnosticsStatusNotification\"") != NULL)
  20035. || (strstr((char*)str, "\"FirmwareStatusNotification\"") != NULL)
  20036. || (strstr((char*)str, "\"Heartbeat\"") != NULL)
  20037. || (strstr((char*)str, "\"MeterValues\"") != NULL)
  20038. || (strstr((char*)str, "\"StartTransaction\"") != NULL)
  20039. || (strstr((char*)str, "\"StatusNotification\"") != NULL)
  20040. || (strstr((char*)str, "\"StopTransaction\"") != NULL)
  20041. || (strstr((char*)str, "\"LogStatusNotification\"") != NULL)
  20042. || (strstr((char*)str, "\"SecurityEventNotification\"") != NULL)
  20043. || (strstr((char*)str, "\"SignCertificate\"") != NULL)
  20044. || (strstr((char*)str, "\"SignedFirmwareStatusNotification\"") != NULL))
  20045. {
  20046. isWebsocketSendable = 0;
  20047. }
  20048. pthread_mutex_lock(&lock_send);
  20049. memset(SendBuffer, 0, ARRAY_SIZE(SendBuffer));
  20050. sprintf((char *)SendBuffer, "%s", str);
  20051. SendBufLen = strlen(str);
  20052. pthread_mutex_unlock(&lock_send);
  20053. lws_callback_on_writable(wsi_client);
  20054. lws_service(context, 0);
  20055. //sleep(1);
  20056. }