MessageHandler.c 967 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086308730883089309030913092309330943095309630973098309931003101310231033104310531063107310831093110311131123113311431153116311731183119312031213122312331243125312631273128312931303131313231333134313531363137313831393140314131423143314431453146314731483149315031513152315331543155315631573158315931603161316231633164316531663167316831693170317131723173317431753176317731783179318031813182318331843185318631873188318931903191319231933194319531963197319831993200320132023203320432053206320732083209321032113212321332143215321632173218321932203221322232233224322532263227322832293230323132323233323432353236323732383239324032413242324332443245324632473248324932503251325232533254325532563257325832593260326132623263326432653266326732683269327032713272327332743275327632773278327932803281328232833284328532863287328832893290329132923293329432953296329732983299330033013302330333043305330633073308330933103311331233133314331533163317331833193320332133223323332433253326332733283329333033313332333333343335333633373338333933403341334233433344334533463347334833493350335133523353335433553356335733583359336033613362336333643365336633673368336933703371337233733374337533763377337833793380338133823383338433853386338733883389339033913392339333943395339633973398339934003401340234033404340534063407340834093410341134123413341434153416341734183419342034213422342334243425342634273428342934303431343234333434343534363437343834393440344134423443344434453446344734483449345034513452345334543455345634573458345934603461346234633464346534663467346834693470347134723473347434753476347734783479348034813482348334843485348634873488348934903491349234933494349534963497349834993500350135023503350435053506350735083509351035113512351335143515351635173518351935203521352235233524352535263527352835293530353135323533353435353536353735383539354035413542354335443545354635473548354935503551355235533554355535563557355835593560356135623563356435653566356735683569357035713572357335743575357635773578357935803581358235833584358535863587358835893590359135923593359435953596359735983599360036013602360336043605360636073608360936103611361236133614361536163617361836193620362136223623362436253626362736283629363036313632363336343635363636373638363936403641364236433644364536463647364836493650365136523653365436553656365736583659366036613662366336643665366636673668366936703671367236733674367536763677367836793680368136823683368436853686368736883689369036913692369336943695369636973698369937003701370237033704370537063707370837093710371137123713371437153716371737183719372037213722372337243725372637273728372937303731373237333734373537363737373837393740374137423743374437453746374737483749375037513752375337543755375637573758375937603761376237633764376537663767376837693770377137723773377437753776377737783779378037813782378337843785378637873788378937903791379237933794379537963797379837993800380138023803380438053806380738083809381038113812381338143815381638173818381938203821382238233824382538263827382838293830383138323833383438353836383738383839384038413842384338443845384638473848384938503851385238533854385538563857385838593860386138623863386438653866386738683869387038713872387338743875387638773878387938803881388238833884388538863887388838893890389138923893389438953896389738983899390039013902390339043905390639073908390939103911391239133914391539163917391839193920392139223923392439253926392739283929393039313932393339343935393639373938393939403941394239433944394539463947394839493950395139523953395439553956395739583959396039613962396339643965396639673968396939703971397239733974397539763977397839793980398139823983398439853986398739883989399039913992399339943995399639973998399940004001400240034004400540064007400840094010401140124013401440154016401740184019402040214022402340244025402640274028402940304031403240334034403540364037403840394040404140424043404440454046404740484049405040514052405340544055405640574058405940604061406240634064406540664067406840694070407140724073407440754076407740784079408040814082408340844085408640874088408940904091409240934094409540964097409840994100410141024103410441054106410741084109411041114112411341144115411641174118411941204121412241234124412541264127412841294130413141324133413441354136413741384139414041414142414341444145414641474148414941504151415241534154415541564157415841594160416141624163416441654166416741684169417041714172417341744175417641774178417941804181418241834184418541864187418841894190419141924193419441954196419741984199420042014202420342044205420642074208420942104211421242134214421542164217421842194220422142224223422442254226422742284229423042314232423342344235423642374238423942404241424242434244424542464247424842494250425142524253425442554256425742584259426042614262426342644265426642674268426942704271427242734274427542764277427842794280428142824283428442854286428742884289429042914292429342944295429642974298429943004301430243034304430543064307430843094310431143124313431443154316431743184319432043214322432343244325432643274328432943304331433243334334433543364337433843394340434143424343434443454346434743484349435043514352435343544355435643574358435943604361436243634364436543664367436843694370437143724373437443754376437743784379438043814382438343844385438643874388438943904391439243934394439543964397439843994400440144024403440444054406440744084409441044114412441344144415441644174418441944204421442244234424442544264427442844294430443144324433443444354436443744384439444044414442444344444445444644474448444944504451445244534454445544564457445844594460446144624463446444654466446744684469447044714472447344744475447644774478447944804481448244834484448544864487448844894490449144924493449444954496449744984499450045014502450345044505450645074508450945104511451245134514451545164517451845194520452145224523452445254526452745284529453045314532453345344535453645374538453945404541454245434544454545464547454845494550455145524553455445554556455745584559456045614562456345644565456645674568456945704571457245734574457545764577457845794580458145824583458445854586458745884589459045914592459345944595459645974598459946004601460246034604460546064607460846094610461146124613461446154616461746184619462046214622462346244625462646274628462946304631463246334634463546364637463846394640464146424643464446454646464746484649465046514652465346544655465646574658465946604661466246634664466546664667466846694670467146724673467446754676467746784679468046814682468346844685468646874688468946904691469246934694469546964697469846994700470147024703470447054706470747084709471047114712471347144715471647174718471947204721472247234724472547264727472847294730473147324733473447354736473747384739474047414742474347444745474647474748474947504751475247534754475547564757475847594760476147624763476447654766476747684769477047714772477347744775477647774778477947804781478247834784478547864787478847894790479147924793479447954796479747984799480048014802480348044805480648074808480948104811481248134814481548164817481848194820482148224823482448254826482748284829483048314832483348344835483648374838483948404841484248434844484548464847484848494850485148524853485448554856485748584859486048614862486348644865486648674868486948704871487248734874487548764877487848794880488148824883488448854886488748884889489048914892489348944895489648974898489949004901490249034904490549064907490849094910491149124913491449154916491749184919492049214922492349244925492649274928492949304931493249334934493549364937493849394940494149424943494449454946494749484949495049514952495349544955495649574958495949604961496249634964496549664967496849694970497149724973497449754976497749784979498049814982498349844985498649874988498949904991499249934994499549964997499849995000500150025003500450055006500750085009501050115012501350145015501650175018501950205021502250235024502550265027502850295030503150325033503450355036503750385039504050415042504350445045504650475048504950505051505250535054505550565057505850595060506150625063506450655066506750685069507050715072507350745075507650775078507950805081508250835084508550865087508850895090509150925093509450955096509750985099510051015102510351045105510651075108510951105111511251135114511551165117511851195120512151225123512451255126512751285129513051315132513351345135513651375138513951405141514251435144514551465147514851495150515151525153515451555156515751585159516051615162516351645165516651675168516951705171517251735174517551765177517851795180518151825183518451855186518751885189519051915192519351945195519651975198519952005201520252035204520552065207520852095210521152125213521452155216521752185219522052215222522352245225522652275228522952305231523252335234523552365237523852395240524152425243524452455246524752485249525052515252525352545255525652575258525952605261526252635264526552665267526852695270527152725273527452755276527752785279528052815282528352845285528652875288528952905291529252935294529552965297529852995300530153025303530453055306530753085309531053115312531353145315531653175318531953205321532253235324532553265327532853295330533153325333533453355336533753385339534053415342534353445345534653475348534953505351535253535354535553565357535853595360536153625363536453655366536753685369537053715372537353745375537653775378537953805381538253835384538553865387538853895390539153925393539453955396539753985399540054015402540354045405540654075408540954105411541254135414541554165417541854195420542154225423542454255426542754285429543054315432543354345435543654375438543954405441544254435444544554465447544854495450545154525453545454555456545754585459546054615462546354645465546654675468546954705471547254735474547554765477547854795480548154825483548454855486548754885489549054915492549354945495549654975498549955005501550255035504550555065507550855095510551155125513551455155516551755185519552055215522552355245525552655275528552955305531553255335534553555365537553855395540554155425543554455455546554755485549555055515552555355545555555655575558555955605561556255635564556555665567556855695570557155725573557455755576557755785579558055815582558355845585558655875588558955905591559255935594559555965597559855995600560156025603560456055606560756085609561056115612561356145615561656175618561956205621562256235624562556265627562856295630563156325633563456355636563756385639564056415642564356445645564656475648564956505651565256535654565556565657565856595660566156625663566456655666566756685669567056715672567356745675567656775678567956805681568256835684568556865687568856895690569156925693569456955696569756985699570057015702570357045705570657075708570957105711571257135714571557165717571857195720572157225723572457255726572757285729573057315732573357345735573657375738573957405741574257435744574557465747574857495750575157525753575457555756575757585759576057615762576357645765576657675768576957705771577257735774577557765777577857795780578157825783578457855786578757885789579057915792579357945795579657975798579958005801580258035804580558065807580858095810581158125813581458155816581758185819582058215822582358245825582658275828582958305831583258335834583558365837583858395840584158425843584458455846584758485849585058515852585358545855585658575858585958605861586258635864586558665867586858695870587158725873587458755876587758785879588058815882588358845885588658875888588958905891589258935894589558965897589858995900590159025903590459055906590759085909591059115912591359145915591659175918591959205921592259235924592559265927592859295930593159325933593459355936593759385939594059415942594359445945594659475948594959505951595259535954595559565957595859595960596159625963596459655966596759685969597059715972597359745975597659775978597959805981598259835984598559865987598859895990599159925993599459955996599759985999600060016002600360046005600660076008600960106011601260136014601560166017601860196020602160226023602460256026602760286029603060316032603360346035603660376038603960406041604260436044604560466047604860496050605160526053605460556056605760586059606060616062606360646065606660676068606960706071607260736074607560766077607860796080608160826083608460856086608760886089609060916092609360946095609660976098609961006101610261036104610561066107610861096110611161126113611461156116611761186119612061216122612361246125612661276128612961306131613261336134613561366137613861396140614161426143614461456146614761486149615061516152615361546155615661576158615961606161616261636164616561666167616861696170617161726173617461756176617761786179618061816182618361846185618661876188618961906191619261936194619561966197619861996200620162026203620462056206620762086209621062116212621362146215621662176218621962206221622262236224622562266227622862296230623162326233623462356236623762386239624062416242624362446245624662476248624962506251625262536254625562566257625862596260626162626263626462656266626762686269627062716272627362746275627662776278627962806281628262836284628562866287628862896290629162926293629462956296629762986299630063016302630363046305630663076308630963106311631263136314631563166317631863196320632163226323632463256326632763286329633063316332633363346335633663376338633963406341634263436344634563466347634863496350635163526353635463556356635763586359636063616362636363646365636663676368636963706371637263736374637563766377637863796380638163826383638463856386638763886389639063916392639363946395639663976398639964006401640264036404640564066407640864096410641164126413641464156416641764186419642064216422642364246425642664276428642964306431643264336434643564366437643864396440644164426443644464456446644764486449645064516452645364546455645664576458645964606461646264636464646564666467646864696470647164726473647464756476647764786479648064816482648364846485648664876488648964906491649264936494649564966497649864996500650165026503650465056506650765086509651065116512651365146515651665176518651965206521652265236524652565266527652865296530653165326533653465356536653765386539654065416542654365446545654665476548654965506551655265536554655565566557655865596560656165626563656465656566656765686569657065716572657365746575657665776578657965806581658265836584658565866587658865896590659165926593659465956596659765986599660066016602660366046605660666076608660966106611661266136614661566166617661866196620662166226623662466256626662766286629663066316632663366346635663666376638663966406641664266436644664566466647664866496650665166526653665466556656665766586659666066616662666366646665666666676668666966706671667266736674667566766677667866796680668166826683668466856686668766886689669066916692669366946695669666976698669967006701670267036704670567066707670867096710671167126713671467156716671767186719672067216722672367246725672667276728672967306731673267336734673567366737673867396740674167426743674467456746674767486749675067516752675367546755675667576758675967606761676267636764676567666767676867696770677167726773677467756776677767786779678067816782678367846785678667876788678967906791679267936794679567966797679867996800680168026803680468056806680768086809681068116812681368146815681668176818681968206821682268236824682568266827682868296830683168326833683468356836683768386839684068416842684368446845684668476848684968506851685268536854685568566857685868596860686168626863686468656866686768686869687068716872687368746875687668776878687968806881688268836884688568866887688868896890689168926893689468956896689768986899690069016902690369046905690669076908690969106911691269136914691569166917691869196920692169226923692469256926692769286929693069316932693369346935693669376938693969406941694269436944694569466947694869496950695169526953695469556956695769586959696069616962696369646965696669676968696969706971697269736974697569766977697869796980698169826983698469856986698769886989699069916992699369946995699669976998699970007001700270037004700570067007700870097010701170127013701470157016701770187019702070217022702370247025702670277028702970307031703270337034703570367037703870397040704170427043704470457046704770487049705070517052705370547055705670577058705970607061706270637064706570667067706870697070707170727073707470757076707770787079708070817082708370847085708670877088708970907091709270937094709570967097709870997100710171027103710471057106710771087109711071117112711371147115711671177118711971207121712271237124712571267127712871297130713171327133713471357136713771387139714071417142714371447145714671477148714971507151715271537154715571567157715871597160716171627163716471657166716771687169717071717172717371747175717671777178717971807181718271837184718571867187718871897190719171927193719471957196719771987199720072017202720372047205720672077208720972107211721272137214721572167217721872197220722172227223722472257226722772287229723072317232723372347235723672377238723972407241724272437244724572467247724872497250725172527253725472557256725772587259726072617262726372647265726672677268726972707271727272737274727572767277727872797280728172827283728472857286728772887289729072917292729372947295729672977298729973007301730273037304730573067307730873097310731173127313731473157316731773187319732073217322732373247325732673277328732973307331733273337334733573367337733873397340734173427343734473457346734773487349735073517352735373547355735673577358735973607361736273637364736573667367736873697370737173727373737473757376737773787379738073817382738373847385738673877388738973907391739273937394739573967397739873997400740174027403740474057406740774087409741074117412741374147415741674177418741974207421742274237424742574267427742874297430743174327433743474357436743774387439744074417442744374447445744674477448744974507451745274537454745574567457745874597460746174627463746474657466746774687469747074717472747374747475747674777478747974807481748274837484748574867487748874897490749174927493749474957496749774987499750075017502750375047505750675077508750975107511751275137514751575167517751875197520752175227523752475257526752775287529753075317532753375347535753675377538753975407541754275437544754575467547754875497550755175527553755475557556755775587559756075617562756375647565756675677568756975707571757275737574757575767577757875797580758175827583758475857586758775887589759075917592759375947595759675977598759976007601760276037604760576067607760876097610761176127613761476157616761776187619762076217622762376247625762676277628762976307631763276337634763576367637763876397640764176427643764476457646764776487649765076517652765376547655765676577658765976607661766276637664766576667667766876697670767176727673767476757676767776787679768076817682768376847685768676877688768976907691769276937694769576967697769876997700770177027703770477057706770777087709771077117712771377147715771677177718771977207721772277237724772577267727772877297730773177327733773477357736773777387739774077417742774377447745774677477748774977507751775277537754775577567757775877597760776177627763776477657766776777687769777077717772777377747775777677777778777977807781778277837784778577867787778877897790779177927793779477957796779777987799780078017802780378047805780678077808780978107811781278137814781578167817781878197820782178227823782478257826782778287829783078317832783378347835783678377838783978407841784278437844784578467847784878497850785178527853785478557856785778587859786078617862786378647865786678677868786978707871787278737874787578767877787878797880788178827883788478857886788778887889789078917892789378947895789678977898789979007901790279037904790579067907790879097910791179127913791479157916791779187919792079217922792379247925792679277928792979307931793279337934793579367937793879397940794179427943794479457946794779487949795079517952795379547955795679577958795979607961796279637964796579667967796879697970797179727973797479757976797779787979798079817982798379847985798679877988798979907991799279937994799579967997799879998000800180028003800480058006800780088009801080118012801380148015801680178018801980208021802280238024802580268027802880298030803180328033803480358036803780388039804080418042804380448045804680478048804980508051805280538054805580568057805880598060806180628063806480658066806780688069807080718072807380748075807680778078807980808081808280838084808580868087808880898090809180928093809480958096809780988099810081018102810381048105810681078108810981108111811281138114811581168117811881198120812181228123812481258126812781288129813081318132813381348135813681378138813981408141814281438144814581468147814881498150815181528153815481558156815781588159816081618162816381648165816681678168816981708171817281738174817581768177817881798180818181828183818481858186818781888189819081918192819381948195819681978198819982008201820282038204820582068207820882098210821182128213821482158216821782188219822082218222822382248225822682278228822982308231823282338234823582368237823882398240824182428243824482458246824782488249825082518252825382548255825682578258825982608261826282638264826582668267826882698270827182728273827482758276827782788279828082818282828382848285828682878288828982908291829282938294829582968297829882998300830183028303830483058306830783088309831083118312831383148315831683178318831983208321832283238324832583268327832883298330833183328333833483358336833783388339834083418342834383448345834683478348834983508351835283538354835583568357835883598360836183628363836483658366836783688369837083718372837383748375837683778378837983808381838283838384838583868387838883898390839183928393839483958396839783988399840084018402840384048405840684078408840984108411841284138414841584168417841884198420842184228423842484258426842784288429843084318432843384348435843684378438843984408441844284438444844584468447844884498450845184528453845484558456845784588459846084618462846384648465846684678468846984708471847284738474847584768477847884798480848184828483848484858486848784888489849084918492849384948495849684978498849985008501850285038504850585068507850885098510851185128513851485158516851785188519852085218522852385248525852685278528852985308531853285338534853585368537853885398540854185428543854485458546854785488549855085518552855385548555855685578558855985608561856285638564856585668567856885698570857185728573857485758576857785788579858085818582858385848585858685878588858985908591859285938594859585968597859885998600860186028603860486058606860786088609861086118612861386148615861686178618861986208621862286238624862586268627862886298630863186328633863486358636863786388639864086418642864386448645864686478648864986508651865286538654865586568657865886598660866186628663866486658666866786688669867086718672867386748675867686778678867986808681868286838684868586868687868886898690869186928693869486958696869786988699870087018702870387048705870687078708870987108711871287138714871587168717871887198720872187228723872487258726872787288729873087318732873387348735873687378738873987408741874287438744874587468747874887498750875187528753875487558756875787588759876087618762876387648765876687678768876987708771877287738774877587768777877887798780878187828783878487858786878787888789879087918792879387948795879687978798879988008801880288038804880588068807880888098810881188128813881488158816881788188819882088218822882388248825882688278828882988308831883288338834883588368837883888398840884188428843884488458846884788488849885088518852885388548855885688578858885988608861886288638864886588668867886888698870887188728873887488758876887788788879888088818882888388848885888688878888888988908891889288938894889588968897889888998900890189028903890489058906890789088909891089118912891389148915891689178918891989208921892289238924892589268927892889298930893189328933893489358936893789388939894089418942894389448945894689478948894989508951895289538954895589568957895889598960896189628963896489658966896789688969897089718972897389748975897689778978897989808981898289838984898589868987898889898990899189928993899489958996899789988999900090019002900390049005900690079008900990109011901290139014901590169017901890199020902190229023902490259026902790289029903090319032903390349035903690379038903990409041904290439044904590469047904890499050905190529053905490559056905790589059906090619062906390649065906690679068906990709071907290739074907590769077907890799080908190829083908490859086908790889089909090919092909390949095909690979098909991009101910291039104910591069107910891099110911191129113911491159116911791189119912091219122912391249125912691279128912991309131913291339134913591369137913891399140914191429143914491459146914791489149915091519152915391549155915691579158915991609161916291639164916591669167916891699170917191729173917491759176917791789179918091819182918391849185918691879188918991909191919291939194919591969197919891999200920192029203920492059206920792089209921092119212921392149215921692179218921992209221922292239224922592269227922892299230923192329233923492359236923792389239924092419242924392449245924692479248924992509251925292539254925592569257925892599260926192629263926492659266926792689269927092719272927392749275927692779278927992809281928292839284928592869287928892899290929192929293929492959296929792989299930093019302930393049305930693079308930993109311931293139314931593169317931893199320932193229323932493259326932793289329933093319332933393349335933693379338933993409341934293439344934593469347934893499350935193529353935493559356935793589359936093619362936393649365936693679368936993709371937293739374937593769377937893799380938193829383938493859386938793889389939093919392939393949395939693979398939994009401940294039404940594069407940894099410941194129413941494159416941794189419942094219422942394249425942694279428942994309431943294339434943594369437943894399440944194429443944494459446944794489449945094519452945394549455945694579458945994609461946294639464946594669467946894699470947194729473947494759476947794789479948094819482948394849485948694879488948994909491949294939494949594969497949894999500950195029503950495059506950795089509951095119512951395149515951695179518951995209521952295239524952595269527952895299530953195329533953495359536953795389539954095419542954395449545954695479548954995509551955295539554955595569557955895599560956195629563956495659566956795689569957095719572957395749575957695779578957995809581958295839584958595869587958895899590959195929593959495959596959795989599960096019602960396049605960696079608960996109611961296139614961596169617961896199620962196229623962496259626962796289629963096319632963396349635963696379638963996409641964296439644964596469647964896499650965196529653965496559656965796589659966096619662966396649665966696679668966996709671967296739674967596769677967896799680968196829683968496859686968796889689969096919692969396949695969696979698969997009701970297039704970597069707970897099710971197129713971497159716971797189719972097219722972397249725972697279728972997309731973297339734973597369737973897399740974197429743974497459746974797489749975097519752975397549755975697579758975997609761976297639764976597669767976897699770977197729773977497759776977797789779978097819782978397849785978697879788978997909791979297939794979597969797979897999800980198029803980498059806980798089809981098119812981398149815981698179818981998209821982298239824982598269827982898299830983198329833983498359836983798389839984098419842984398449845984698479848984998509851985298539854985598569857985898599860986198629863986498659866986798689869987098719872987398749875987698779878987998809881988298839884988598869887988898899890989198929893989498959896989798989899990099019902990399049905990699079908990999109911991299139914991599169917991899199920992199229923992499259926992799289929993099319932993399349935993699379938993999409941994299439944994599469947994899499950995199529953995499559956995799589959996099619962996399649965996699679968996999709971997299739974997599769977997899799980998199829983998499859986998799889989999099919992999399949995999699979998999910000100011000210003100041000510006100071000810009100101001110012100131001410015100161001710018100191002010021100221002310024100251002610027100281002910030100311003210033100341003510036100371003810039100401004110042100431004410045100461004710048100491005010051100521005310054100551005610057100581005910060100611006210063100641006510066100671006810069100701007110072100731007410075100761007710078100791008010081100821008310084100851008610087100881008910090100911009210093100941009510096100971009810099101001010110102101031010410105101061010710108101091011010111101121011310114101151011610117101181011910120101211012210123101241012510126101271012810129101301013110132101331013410135101361013710138101391014010141101421014310144101451014610147101481014910150101511015210153101541015510156101571015810159101601016110162101631016410165101661016710168101691017010171101721017310174101751017610177101781017910180101811018210183101841018510186101871018810189101901019110192101931019410195101961019710198101991020010201102021020310204102051020610207102081020910210102111021210213102141021510216102171021810219102201022110222102231022410225102261022710228102291023010231102321023310234102351023610237102381023910240102411024210243102441024510246102471024810249102501025110252102531025410255102561025710258102591026010261102621026310264102651026610267102681026910270102711027210273102741027510276102771027810279102801028110282102831028410285102861028710288102891029010291102921029310294102951029610297102981029910300103011030210303103041030510306103071030810309103101031110312103131031410315103161031710318103191032010321103221032310324103251032610327103281032910330103311033210333103341033510336103371033810339103401034110342103431034410345103461034710348103491035010351103521035310354103551035610357103581035910360103611036210363103641036510366103671036810369103701037110372103731037410375103761037710378103791038010381103821038310384103851038610387103881038910390103911039210393103941039510396103971039810399104001040110402104031040410405104061040710408104091041010411104121041310414104151041610417104181041910420104211042210423104241042510426104271042810429104301043110432104331043410435104361043710438104391044010441104421044310444104451044610447104481044910450104511045210453104541045510456104571045810459104601046110462104631046410465104661046710468104691047010471104721047310474104751047610477104781047910480104811048210483104841048510486104871048810489104901049110492104931049410495104961049710498104991050010501105021050310504105051050610507105081050910510105111051210513105141051510516105171051810519105201052110522105231052410525105261052710528105291053010531105321053310534105351053610537105381053910540105411054210543105441054510546105471054810549105501055110552105531055410555105561055710558105591056010561105621056310564105651056610567105681056910570105711057210573105741057510576105771057810579105801058110582105831058410585105861058710588105891059010591105921059310594105951059610597105981059910600106011060210603106041060510606106071060810609106101061110612106131061410615106161061710618106191062010621106221062310624106251062610627106281062910630106311063210633106341063510636106371063810639106401064110642106431064410645106461064710648106491065010651106521065310654106551065610657106581065910660106611066210663106641066510666106671066810669106701067110672106731067410675106761067710678106791068010681106821068310684106851068610687106881068910690106911069210693106941069510696106971069810699107001070110702107031070410705107061070710708107091071010711107121071310714107151071610717107181071910720107211072210723107241072510726107271072810729107301073110732107331073410735107361073710738107391074010741107421074310744107451074610747107481074910750107511075210753107541075510756107571075810759107601076110762107631076410765107661076710768107691077010771107721077310774107751077610777107781077910780107811078210783107841078510786107871078810789107901079110792107931079410795107961079710798107991080010801108021080310804108051080610807108081080910810108111081210813108141081510816108171081810819108201082110822108231082410825108261082710828108291083010831108321083310834108351083610837108381083910840108411084210843108441084510846108471084810849108501085110852108531085410855108561085710858108591086010861108621086310864108651086610867108681086910870108711087210873108741087510876108771087810879108801088110882108831088410885108861088710888108891089010891108921089310894108951089610897108981089910900109011090210903109041090510906109071090810909109101091110912109131091410915109161091710918109191092010921109221092310924109251092610927109281092910930109311093210933109341093510936109371093810939109401094110942109431094410945109461094710948109491095010951109521095310954109551095610957109581095910960109611096210963109641096510966109671096810969109701097110972109731097410975109761097710978109791098010981109821098310984109851098610987109881098910990109911099210993109941099510996109971099810999110001100111002110031100411005110061100711008110091101011011110121101311014110151101611017110181101911020110211102211023110241102511026110271102811029110301103111032110331103411035110361103711038110391104011041110421104311044110451104611047110481104911050110511105211053110541105511056110571105811059110601106111062110631106411065110661106711068110691107011071110721107311074110751107611077110781107911080110811108211083110841108511086110871108811089110901109111092110931109411095110961109711098110991110011101111021110311104111051110611107111081110911110111111111211113111141111511116111171111811119111201112111122111231112411125111261112711128111291113011131111321113311134111351113611137111381113911140111411114211143111441114511146111471114811149111501115111152111531115411155111561115711158111591116011161111621116311164111651116611167111681116911170111711117211173111741117511176111771117811179111801118111182111831118411185111861118711188111891119011191111921119311194111951119611197111981119911200112011120211203112041120511206112071120811209112101121111212112131121411215112161121711218112191122011221112221122311224112251122611227112281122911230112311123211233112341123511236112371123811239112401124111242112431124411245112461124711248112491125011251112521125311254112551125611257112581125911260112611126211263112641126511266112671126811269112701127111272112731127411275112761127711278112791128011281112821128311284112851128611287112881128911290112911129211293112941129511296112971129811299113001130111302113031130411305113061130711308113091131011311113121131311314113151131611317113181131911320113211132211323113241132511326113271132811329113301133111332113331133411335113361133711338113391134011341113421134311344113451134611347113481134911350113511135211353113541135511356113571135811359113601136111362113631136411365113661136711368113691137011371113721137311374113751137611377113781137911380113811138211383113841138511386113871138811389113901139111392113931139411395113961139711398113991140011401114021140311404114051140611407114081140911410114111141211413114141141511416114171141811419114201142111422114231142411425114261142711428114291143011431114321143311434114351143611437114381143911440114411144211443114441144511446114471144811449114501145111452114531145411455114561145711458114591146011461114621146311464114651146611467114681146911470114711147211473114741147511476114771147811479114801148111482114831148411485114861148711488114891149011491114921149311494114951149611497114981149911500115011150211503115041150511506115071150811509115101151111512115131151411515115161151711518115191152011521115221152311524115251152611527115281152911530115311153211533115341153511536115371153811539115401154111542115431154411545115461154711548115491155011551115521155311554115551155611557115581155911560115611156211563115641156511566115671156811569115701157111572115731157411575115761157711578115791158011581115821158311584115851158611587115881158911590115911159211593115941159511596115971159811599116001160111602116031160411605116061160711608116091161011611116121161311614116151161611617116181161911620116211162211623116241162511626116271162811629116301163111632116331163411635116361163711638116391164011641116421164311644116451164611647116481164911650116511165211653116541165511656116571165811659116601166111662116631166411665116661166711668116691167011671116721167311674116751167611677116781167911680116811168211683116841168511686116871168811689116901169111692116931169411695116961169711698116991170011701117021170311704117051170611707117081170911710117111171211713117141171511716117171171811719117201172111722117231172411725117261172711728117291173011731117321173311734117351173611737117381173911740117411174211743117441174511746117471174811749117501175111752117531175411755117561175711758117591176011761117621176311764117651176611767117681176911770117711177211773117741177511776117771177811779117801178111782117831178411785117861178711788117891179011791117921179311794117951179611797117981179911800118011180211803118041180511806118071180811809118101181111812118131181411815118161181711818118191182011821118221182311824118251182611827118281182911830118311183211833118341183511836118371183811839118401184111842118431184411845118461184711848118491185011851118521185311854118551185611857118581185911860118611186211863118641186511866118671186811869118701187111872118731187411875118761187711878118791188011881118821188311884118851188611887118881188911890118911189211893118941189511896118971189811899119001190111902119031190411905119061190711908119091191011911119121191311914119151191611917119181191911920119211192211923119241192511926119271192811929119301193111932119331193411935119361193711938119391194011941119421194311944119451194611947119481194911950119511195211953119541195511956119571195811959119601196111962119631196411965119661196711968119691197011971119721197311974119751197611977119781197911980119811198211983119841198511986119871198811989119901199111992119931199411995119961199711998119991200012001120021200312004120051200612007120081200912010120111201212013120141201512016120171201812019120201202112022120231202412025120261202712028120291203012031120321203312034120351203612037120381203912040120411204212043120441204512046120471204812049120501205112052120531205412055120561205712058120591206012061120621206312064120651206612067120681206912070120711207212073120741207512076120771207812079120801208112082120831208412085120861208712088120891209012091120921209312094120951209612097120981209912100121011210212103121041210512106121071210812109121101211112112121131211412115121161211712118121191212012121121221212312124121251212612127121281212912130121311213212133121341213512136121371213812139121401214112142121431214412145121461214712148121491215012151121521215312154121551215612157121581215912160121611216212163121641216512166121671216812169121701217112172121731217412175121761217712178121791218012181121821218312184121851218612187121881218912190121911219212193121941219512196121971219812199122001220112202122031220412205122061220712208122091221012211122121221312214122151221612217122181221912220122211222212223122241222512226122271222812229122301223112232122331223412235122361223712238122391224012241122421224312244122451224612247122481224912250122511225212253122541225512256122571225812259122601226112262122631226412265122661226712268122691227012271122721227312274122751227612277122781227912280122811228212283122841228512286122871228812289122901229112292122931229412295122961229712298122991230012301123021230312304123051230612307123081230912310123111231212313123141231512316123171231812319123201232112322123231232412325123261232712328123291233012331123321233312334123351233612337123381233912340123411234212343123441234512346123471234812349123501235112352123531235412355123561235712358123591236012361123621236312364123651236612367123681236912370123711237212373123741237512376123771237812379123801238112382123831238412385123861238712388123891239012391123921239312394123951239612397123981239912400124011240212403124041240512406124071240812409124101241112412124131241412415124161241712418124191242012421124221242312424124251242612427124281242912430124311243212433124341243512436124371243812439124401244112442124431244412445124461244712448124491245012451124521245312454124551245612457124581245912460124611246212463124641246512466124671246812469124701247112472124731247412475124761247712478124791248012481124821248312484124851248612487124881248912490124911249212493124941249512496124971249812499125001250112502125031250412505125061250712508125091251012511125121251312514125151251612517125181251912520125211252212523125241252512526125271252812529125301253112532125331253412535125361253712538125391254012541125421254312544125451254612547125481254912550125511255212553125541255512556125571255812559125601256112562125631256412565125661256712568125691257012571125721257312574125751257612577125781257912580125811258212583125841258512586125871258812589125901259112592125931259412595125961259712598125991260012601126021260312604126051260612607126081260912610126111261212613126141261512616126171261812619126201262112622126231262412625126261262712628126291263012631126321263312634126351263612637126381263912640126411264212643126441264512646126471264812649126501265112652126531265412655126561265712658126591266012661126621266312664126651266612667126681266912670126711267212673126741267512676126771267812679126801268112682126831268412685126861268712688126891269012691126921269312694126951269612697126981269912700127011270212703127041270512706127071270812709127101271112712127131271412715127161271712718127191272012721127221272312724127251272612727127281272912730127311273212733127341273512736127371273812739127401274112742127431274412745127461274712748127491275012751127521275312754127551275612757127581275912760127611276212763127641276512766127671276812769127701277112772127731277412775127761277712778127791278012781127821278312784127851278612787127881278912790127911279212793127941279512796127971279812799128001280112802128031280412805128061280712808128091281012811128121281312814128151281612817128181281912820128211282212823128241282512826128271282812829128301283112832128331283412835128361283712838128391284012841128421284312844128451284612847128481284912850128511285212853128541285512856128571285812859128601286112862128631286412865128661286712868128691287012871128721287312874128751287612877128781287912880128811288212883128841288512886128871288812889128901289112892128931289412895128961289712898128991290012901129021290312904129051290612907129081290912910129111291212913129141291512916129171291812919129201292112922129231292412925129261292712928129291293012931129321293312934129351293612937129381293912940129411294212943129441294512946129471294812949129501295112952129531295412955129561295712958129591296012961129621296312964129651296612967129681296912970129711297212973129741297512976129771297812979129801298112982129831298412985129861298712988129891299012991129921299312994129951299612997129981299913000130011300213003130041300513006130071300813009130101301113012130131301413015130161301713018130191302013021130221302313024130251302613027130281302913030130311303213033130341303513036130371303813039130401304113042130431304413045130461304713048130491305013051130521305313054130551305613057130581305913060130611306213063130641306513066130671306813069130701307113072130731307413075130761307713078130791308013081130821308313084130851308613087130881308913090130911309213093130941309513096130971309813099131001310113102131031310413105131061310713108131091311013111131121311313114131151311613117131181311913120131211312213123131241312513126131271312813129131301313113132131331313413135131361313713138131391314013141131421314313144131451314613147131481314913150131511315213153131541315513156131571315813159131601316113162131631316413165131661316713168131691317013171131721317313174131751317613177131781317913180131811318213183131841318513186131871318813189131901319113192131931319413195131961319713198131991320013201132021320313204132051320613207132081320913210132111321213213132141321513216132171321813219132201322113222132231322413225132261322713228132291323013231132321323313234132351323613237132381323913240132411324213243132441324513246132471324813249132501325113252132531325413255132561325713258132591326013261132621326313264132651326613267132681326913270132711327213273132741327513276132771327813279132801328113282132831328413285132861328713288132891329013291132921329313294132951329613297132981329913300133011330213303133041330513306133071330813309133101331113312133131331413315133161331713318133191332013321133221332313324133251332613327133281332913330133311333213333133341333513336133371333813339133401334113342133431334413345133461334713348133491335013351133521335313354133551335613357133581335913360133611336213363133641336513366133671336813369133701337113372133731337413375133761337713378133791338013381133821338313384133851338613387133881338913390133911339213393133941339513396133971339813399134001340113402134031340413405134061340713408134091341013411134121341313414134151341613417134181341913420134211342213423134241342513426134271342813429134301343113432134331343413435134361343713438134391344013441134421344313444134451344613447134481344913450134511345213453134541345513456134571345813459134601346113462134631346413465134661346713468134691347013471134721347313474134751347613477134781347913480134811348213483134841348513486134871348813489134901349113492134931349413495134961349713498134991350013501135021350313504135051350613507135081350913510135111351213513135141351513516135171351813519135201352113522135231352413525135261352713528135291353013531135321353313534135351353613537135381353913540135411354213543135441354513546135471354813549135501355113552135531355413555135561355713558135591356013561135621356313564135651356613567135681356913570135711357213573135741357513576135771357813579135801358113582135831358413585135861358713588135891359013591135921359313594135951359613597135981359913600136011360213603136041360513606136071360813609136101361113612136131361413615136161361713618136191362013621136221362313624136251362613627136281362913630136311363213633136341363513636136371363813639136401364113642136431364413645136461364713648136491365013651136521365313654136551365613657136581365913660136611366213663136641366513666136671366813669136701367113672136731367413675136761367713678136791368013681136821368313684136851368613687136881368913690136911369213693136941369513696136971369813699137001370113702137031370413705137061370713708137091371013711137121371313714137151371613717137181371913720137211372213723137241372513726137271372813729137301373113732137331373413735137361373713738137391374013741137421374313744137451374613747137481374913750137511375213753137541375513756137571375813759137601376113762137631376413765137661376713768137691377013771137721377313774137751377613777137781377913780137811378213783137841378513786137871378813789137901379113792137931379413795137961379713798137991380013801138021380313804138051380613807138081380913810138111381213813138141381513816138171381813819138201382113822138231382413825138261382713828138291383013831138321383313834138351383613837138381383913840138411384213843138441384513846138471384813849138501385113852138531385413855138561385713858138591386013861138621386313864138651386613867138681386913870138711387213873138741387513876138771387813879138801388113882138831388413885138861388713888138891389013891138921389313894138951389613897138981389913900139011390213903139041390513906139071390813909139101391113912139131391413915139161391713918139191392013921139221392313924139251392613927139281392913930139311393213933139341393513936139371393813939139401394113942139431394413945139461394713948139491395013951139521395313954139551395613957139581395913960139611396213963139641396513966139671396813969139701397113972139731397413975139761397713978139791398013981139821398313984139851398613987139881398913990139911399213993139941399513996139971399813999140001400114002140031400414005140061400714008140091401014011140121401314014140151401614017140181401914020140211402214023140241402514026140271402814029140301403114032140331403414035140361403714038140391404014041140421404314044140451404614047140481404914050140511405214053140541405514056140571405814059140601406114062140631406414065140661406714068140691407014071140721407314074140751407614077140781407914080140811408214083140841408514086140871408814089140901409114092140931409414095140961409714098140991410014101141021410314104141051410614107141081410914110141111411214113141141411514116141171411814119141201412114122141231412414125141261412714128141291413014131141321413314134141351413614137141381413914140141411414214143141441414514146141471414814149141501415114152141531415414155141561415714158141591416014161141621416314164141651416614167141681416914170141711417214173141741417514176141771417814179141801418114182141831418414185141861418714188141891419014191141921419314194141951419614197141981419914200142011420214203142041420514206142071420814209142101421114212142131421414215142161421714218142191422014221142221422314224142251422614227142281422914230142311423214233142341423514236142371423814239142401424114242142431424414245142461424714248142491425014251142521425314254142551425614257142581425914260142611426214263142641426514266142671426814269142701427114272142731427414275142761427714278142791428014281142821428314284142851428614287142881428914290142911429214293142941429514296142971429814299143001430114302143031430414305143061430714308143091431014311143121431314314143151431614317143181431914320143211432214323143241432514326143271432814329143301433114332143331433414335143361433714338143391434014341143421434314344143451434614347143481434914350143511435214353143541435514356143571435814359143601436114362143631436414365143661436714368143691437014371143721437314374143751437614377143781437914380143811438214383143841438514386143871438814389143901439114392143931439414395143961439714398143991440014401144021440314404144051440614407144081440914410144111441214413144141441514416144171441814419144201442114422144231442414425144261442714428144291443014431144321443314434144351443614437144381443914440144411444214443144441444514446144471444814449144501445114452144531445414455144561445714458144591446014461144621446314464144651446614467144681446914470144711447214473144741447514476144771447814479144801448114482144831448414485144861448714488144891449014491144921449314494144951449614497144981449914500145011450214503145041450514506145071450814509145101451114512145131451414515145161451714518145191452014521145221452314524145251452614527145281452914530145311453214533145341453514536145371453814539145401454114542145431454414545145461454714548145491455014551145521455314554145551455614557145581455914560145611456214563145641456514566145671456814569145701457114572145731457414575145761457714578145791458014581145821458314584145851458614587145881458914590145911459214593145941459514596145971459814599146001460114602146031460414605146061460714608146091461014611146121461314614146151461614617146181461914620146211462214623146241462514626146271462814629146301463114632146331463414635146361463714638146391464014641146421464314644146451464614647146481464914650146511465214653146541465514656146571465814659146601466114662146631466414665146661466714668146691467014671146721467314674146751467614677146781467914680146811468214683146841468514686146871468814689146901469114692146931469414695146961469714698146991470014701147021470314704147051470614707147081470914710147111471214713147141471514716147171471814719147201472114722147231472414725147261472714728147291473014731147321473314734147351473614737147381473914740147411474214743147441474514746147471474814749147501475114752147531475414755147561475714758147591476014761147621476314764147651476614767147681476914770147711477214773147741477514776147771477814779147801478114782147831478414785147861478714788147891479014791147921479314794147951479614797147981479914800148011480214803148041480514806148071480814809148101481114812148131481414815148161481714818148191482014821148221482314824148251482614827148281482914830148311483214833148341483514836148371483814839148401484114842148431484414845148461484714848148491485014851148521485314854148551485614857148581485914860148611486214863148641486514866148671486814869148701487114872148731487414875148761487714878148791488014881148821488314884148851488614887148881488914890148911489214893148941489514896148971489814899149001490114902149031490414905149061490714908149091491014911149121491314914149151491614917149181491914920149211492214923149241492514926149271492814929149301493114932149331493414935149361493714938149391494014941149421494314944149451494614947149481494914950149511495214953149541495514956149571495814959149601496114962149631496414965149661496714968149691497014971149721497314974149751497614977149781497914980149811498214983149841498514986149871498814989149901499114992149931499414995149961499714998149991500015001150021500315004150051500615007150081500915010150111501215013150141501515016150171501815019150201502115022150231502415025150261502715028150291503015031150321503315034150351503615037150381503915040150411504215043150441504515046150471504815049150501505115052150531505415055150561505715058150591506015061150621506315064150651506615067150681506915070150711507215073150741507515076150771507815079150801508115082150831508415085150861508715088150891509015091150921509315094150951509615097150981509915100151011510215103151041510515106151071510815109151101511115112151131511415115151161511715118151191512015121151221512315124151251512615127151281512915130151311513215133151341513515136151371513815139151401514115142151431514415145151461514715148151491515015151151521515315154151551515615157151581515915160151611516215163151641516515166151671516815169151701517115172151731517415175151761517715178151791518015181151821518315184151851518615187151881518915190151911519215193151941519515196151971519815199152001520115202152031520415205152061520715208152091521015211152121521315214152151521615217152181521915220152211522215223152241522515226152271522815229152301523115232152331523415235152361523715238152391524015241152421524315244152451524615247152481524915250152511525215253152541525515256152571525815259152601526115262152631526415265152661526715268152691527015271152721527315274152751527615277152781527915280152811528215283152841528515286152871528815289152901529115292152931529415295152961529715298152991530015301153021530315304153051530615307153081530915310153111531215313153141531515316153171531815319153201532115322153231532415325153261532715328153291533015331153321533315334153351533615337153381533915340153411534215343153441534515346153471534815349153501535115352153531535415355153561535715358153591536015361153621536315364153651536615367153681536915370153711537215373153741537515376153771537815379153801538115382153831538415385153861538715388153891539015391153921539315394153951539615397153981539915400154011540215403154041540515406154071540815409154101541115412154131541415415154161541715418154191542015421154221542315424154251542615427154281542915430154311543215433154341543515436154371543815439154401544115442154431544415445154461544715448154491545015451154521545315454154551545615457154581545915460154611546215463154641546515466154671546815469154701547115472154731547415475154761547715478154791548015481154821548315484154851548615487154881548915490154911549215493154941549515496154971549815499155001550115502155031550415505155061550715508155091551015511155121551315514155151551615517155181551915520155211552215523155241552515526155271552815529155301553115532155331553415535155361553715538155391554015541155421554315544155451554615547155481554915550155511555215553155541555515556155571555815559155601556115562155631556415565155661556715568155691557015571155721557315574155751557615577155781557915580155811558215583155841558515586155871558815589155901559115592155931559415595155961559715598155991560015601156021560315604156051560615607156081560915610156111561215613156141561515616156171561815619156201562115622156231562415625156261562715628156291563015631156321563315634156351563615637156381563915640156411564215643156441564515646156471564815649156501565115652156531565415655156561565715658156591566015661156621566315664156651566615667156681566915670156711567215673156741567515676156771567815679156801568115682156831568415685156861568715688156891569015691156921569315694156951569615697156981569915700157011570215703157041570515706157071570815709157101571115712157131571415715157161571715718157191572015721157221572315724157251572615727157281572915730157311573215733157341573515736157371573815739157401574115742157431574415745157461574715748157491575015751157521575315754157551575615757157581575915760157611576215763157641576515766157671576815769157701577115772157731577415775157761577715778157791578015781157821578315784157851578615787157881578915790157911579215793157941579515796157971579815799158001580115802158031580415805158061580715808158091581015811158121581315814158151581615817158181581915820158211582215823158241582515826158271582815829158301583115832158331583415835158361583715838158391584015841158421584315844158451584615847158481584915850158511585215853158541585515856158571585815859158601586115862158631586415865158661586715868158691587015871158721587315874158751587615877158781587915880158811588215883158841588515886158871588815889158901589115892158931589415895158961589715898158991590015901159021590315904159051590615907159081590915910159111591215913159141591515916159171591815919159201592115922159231592415925159261592715928159291593015931159321593315934159351593615937159381593915940159411594215943159441594515946159471594815949159501595115952159531595415955159561595715958159591596015961159621596315964159651596615967159681596915970159711597215973159741597515976159771597815979159801598115982159831598415985159861598715988159891599015991159921599315994159951599615997159981599916000160011600216003160041600516006160071600816009160101601116012160131601416015160161601716018160191602016021160221602316024160251602616027160281602916030160311603216033160341603516036160371603816039160401604116042160431604416045160461604716048160491605016051160521605316054160551605616057160581605916060160611606216063160641606516066160671606816069160701607116072160731607416075160761607716078160791608016081160821608316084160851608616087160881608916090160911609216093160941609516096160971609816099161001610116102161031610416105161061610716108161091611016111161121611316114161151611616117161181611916120161211612216123161241612516126161271612816129161301613116132161331613416135161361613716138161391614016141161421614316144161451614616147161481614916150161511615216153161541615516156161571615816159161601616116162161631616416165161661616716168161691617016171161721617316174161751617616177161781617916180161811618216183161841618516186161871618816189161901619116192161931619416195161961619716198161991620016201162021620316204162051620616207162081620916210162111621216213162141621516216162171621816219162201622116222162231622416225162261622716228162291623016231162321623316234162351623616237162381623916240162411624216243162441624516246162471624816249162501625116252162531625416255162561625716258162591626016261162621626316264162651626616267162681626916270162711627216273162741627516276162771627816279162801628116282162831628416285162861628716288162891629016291162921629316294162951629616297162981629916300163011630216303163041630516306163071630816309163101631116312163131631416315163161631716318163191632016321163221632316324163251632616327163281632916330163311633216333163341633516336163371633816339163401634116342163431634416345163461634716348163491635016351163521635316354163551635616357163581635916360163611636216363163641636516366163671636816369163701637116372163731637416375163761637716378163791638016381163821638316384163851638616387163881638916390163911639216393163941639516396163971639816399164001640116402164031640416405164061640716408164091641016411164121641316414164151641616417164181641916420164211642216423164241642516426164271642816429164301643116432164331643416435164361643716438164391644016441164421644316444164451644616447164481644916450164511645216453164541645516456164571645816459164601646116462164631646416465164661646716468164691647016471164721647316474164751647616477164781647916480164811648216483164841648516486164871648816489164901649116492164931649416495164961649716498164991650016501165021650316504165051650616507165081650916510165111651216513165141651516516165171651816519165201652116522165231652416525165261652716528165291653016531165321653316534165351653616537165381653916540165411654216543165441654516546165471654816549165501655116552165531655416555165561655716558165591656016561165621656316564165651656616567165681656916570165711657216573165741657516576165771657816579165801658116582165831658416585165861658716588165891659016591165921659316594165951659616597165981659916600166011660216603166041660516606166071660816609166101661116612166131661416615166161661716618166191662016621166221662316624166251662616627166281662916630166311663216633166341663516636166371663816639166401664116642166431664416645166461664716648166491665016651166521665316654166551665616657166581665916660166611666216663166641666516666166671666816669166701667116672166731667416675166761667716678166791668016681166821668316684166851668616687166881668916690166911669216693166941669516696166971669816699167001670116702167031670416705167061670716708167091671016711167121671316714167151671616717167181671916720167211672216723167241672516726167271672816729167301673116732167331673416735167361673716738167391674016741167421674316744167451674616747167481674916750167511675216753167541675516756167571675816759167601676116762167631676416765167661676716768167691677016771167721677316774167751677616777167781677916780167811678216783167841678516786167871678816789167901679116792167931679416795167961679716798167991680016801168021680316804168051680616807168081680916810168111681216813168141681516816168171681816819168201682116822168231682416825168261682716828168291683016831168321683316834168351683616837168381683916840168411684216843168441684516846168471684816849168501685116852168531685416855168561685716858168591686016861168621686316864168651686616867168681686916870168711687216873168741687516876168771687816879168801688116882168831688416885168861688716888168891689016891168921689316894168951689616897168981689916900169011690216903169041690516906169071690816909169101691116912169131691416915169161691716918169191692016921169221692316924169251692616927169281692916930169311693216933169341693516936169371693816939169401694116942169431694416945169461694716948169491695016951169521695316954169551695616957169581695916960169611696216963169641696516966169671696816969169701697116972169731697416975169761697716978169791698016981169821698316984169851698616987169881698916990169911699216993169941699516996169971699816999170001700117002170031700417005170061700717008170091701017011170121701317014170151701617017170181701917020170211702217023170241702517026170271702817029170301703117032170331703417035170361703717038170391704017041170421704317044170451704617047170481704917050170511705217053170541705517056170571705817059170601706117062170631706417065170661706717068170691707017071170721707317074170751707617077170781707917080170811708217083170841708517086170871708817089170901709117092170931709417095170961709717098170991710017101171021710317104171051710617107171081710917110171111711217113171141711517116171171711817119171201712117122171231712417125171261712717128171291713017131171321713317134171351713617137171381713917140171411714217143171441714517146171471714817149171501715117152171531715417155171561715717158171591716017161171621716317164171651716617167171681716917170171711717217173171741717517176171771717817179171801718117182171831718417185171861718717188171891719017191171921719317194171951719617197171981719917200172011720217203172041720517206172071720817209172101721117212172131721417215172161721717218172191722017221172221722317224172251722617227172281722917230172311723217233172341723517236172371723817239172401724117242172431724417245172461724717248172491725017251172521725317254172551725617257172581725917260172611726217263172641726517266172671726817269172701727117272172731727417275172761727717278172791728017281172821728317284172851728617287172881728917290172911729217293172941729517296172971729817299173001730117302173031730417305173061730717308173091731017311173121731317314173151731617317173181731917320173211732217323173241732517326173271732817329173301733117332173331733417335173361733717338173391734017341173421734317344173451734617347173481734917350173511735217353173541735517356173571735817359173601736117362173631736417365173661736717368173691737017371173721737317374173751737617377173781737917380173811738217383173841738517386173871738817389173901739117392173931739417395173961739717398173991740017401174021740317404174051740617407174081740917410174111741217413174141741517416174171741817419174201742117422174231742417425174261742717428174291743017431174321743317434174351743617437174381743917440174411744217443174441744517446174471744817449174501745117452174531745417455174561745717458174591746017461174621746317464174651746617467174681746917470174711747217473174741747517476174771747817479174801748117482174831748417485174861748717488174891749017491174921749317494174951749617497174981749917500175011750217503175041750517506175071750817509175101751117512175131751417515175161751717518175191752017521175221752317524175251752617527175281752917530175311753217533175341753517536175371753817539175401754117542175431754417545175461754717548175491755017551175521755317554175551755617557175581755917560175611756217563175641756517566175671756817569175701757117572175731757417575175761757717578175791758017581175821758317584175851758617587175881758917590175911759217593175941759517596175971759817599176001760117602176031760417605176061760717608176091761017611176121761317614176151761617617176181761917620176211762217623176241762517626176271762817629176301763117632176331763417635176361763717638176391764017641176421764317644176451764617647176481764917650176511765217653176541765517656176571765817659176601766117662176631766417665176661766717668176691767017671176721767317674176751767617677176781767917680176811768217683176841768517686176871768817689176901769117692176931769417695176961769717698176991770017701177021770317704177051770617707177081770917710177111771217713177141771517716177171771817719177201772117722177231772417725177261772717728177291773017731177321773317734177351773617737177381773917740177411774217743177441774517746177471774817749177501775117752177531775417755177561775717758177591776017761177621776317764177651776617767177681776917770177711777217773177741777517776177771777817779177801778117782177831778417785177861778717788177891779017791177921779317794177951779617797177981779917800178011780217803178041780517806178071780817809178101781117812178131781417815178161781717818178191782017821178221782317824178251782617827178281782917830178311783217833178341783517836178371783817839178401784117842178431784417845178461784717848178491785017851178521785317854178551785617857178581785917860178611786217863178641786517866178671786817869178701787117872178731787417875178761787717878178791788017881178821788317884178851788617887178881788917890178911789217893178941789517896178971789817899179001790117902179031790417905179061790717908179091791017911179121791317914179151791617917179181791917920179211792217923179241792517926179271792817929179301793117932179331793417935179361793717938179391794017941179421794317944179451794617947179481794917950179511795217953179541795517956179571795817959179601796117962179631796417965179661796717968179691797017971179721797317974179751797617977179781797917980179811798217983179841798517986179871798817989179901799117992179931799417995179961799717998179991800018001180021800318004180051800618007180081800918010180111801218013180141801518016180171801818019180201802118022180231802418025180261802718028180291803018031180321803318034180351803618037180381803918040180411804218043180441804518046180471804818049180501805118052180531805418055180561805718058180591806018061180621806318064180651806618067180681806918070180711807218073180741807518076180771807818079180801808118082180831808418085180861808718088180891809018091180921809318094180951809618097180981809918100181011810218103181041810518106181071810818109181101811118112181131811418115181161811718118181191812018121181221812318124181251812618127181281812918130181311813218133181341813518136181371813818139181401814118142181431814418145181461814718148181491815018151181521815318154181551815618157181581815918160181611816218163181641816518166181671816818169181701817118172181731817418175181761817718178181791818018181181821818318184181851818618187181881818918190181911819218193181941819518196181971819818199182001820118202182031820418205182061820718208182091821018211182121821318214182151821618217182181821918220182211822218223182241822518226182271822818229182301823118232182331823418235182361823718238182391824018241182421824318244182451824618247182481824918250182511825218253182541825518256182571825818259182601826118262182631826418265182661826718268182691827018271182721827318274182751827618277182781827918280182811828218283182841828518286182871828818289182901829118292182931829418295182961829718298182991830018301183021830318304183051830618307183081830918310183111831218313183141831518316183171831818319183201832118322183231832418325183261832718328183291833018331183321833318334183351833618337183381833918340183411834218343183441834518346183471834818349183501835118352183531835418355183561835718358183591836018361183621836318364183651836618367183681836918370183711837218373183741837518376183771837818379183801838118382183831838418385183861838718388183891839018391183921839318394183951839618397183981839918400184011840218403184041840518406184071840818409184101841118412184131841418415184161841718418184191842018421184221842318424184251842618427184281842918430184311843218433184341843518436184371843818439184401844118442184431844418445184461844718448184491845018451184521845318454184551845618457184581845918460184611846218463184641846518466184671846818469184701847118472184731847418475184761847718478184791848018481184821848318484184851848618487184881848918490184911849218493184941849518496184971849818499185001850118502185031850418505185061850718508185091851018511185121851318514185151851618517185181851918520185211852218523185241852518526185271852818529185301853118532185331853418535185361853718538185391854018541185421854318544185451854618547185481854918550185511855218553185541855518556185571855818559185601856118562185631856418565185661856718568185691857018571185721857318574185751857618577185781857918580185811858218583185841858518586185871858818589185901859118592185931859418595185961859718598185991860018601186021860318604186051860618607186081860918610186111861218613186141861518616186171861818619186201862118622186231862418625186261862718628186291863018631186321863318634186351863618637186381863918640186411864218643186441864518646186471864818649186501865118652186531865418655186561865718658186591866018661186621866318664186651866618667186681866918670186711867218673186741867518676186771867818679186801868118682186831868418685186861868718688186891869018691186921869318694186951869618697186981869918700187011870218703187041870518706187071870818709187101871118712187131871418715187161871718718187191872018721187221872318724187251872618727187281872918730187311873218733187341873518736187371873818739187401874118742187431874418745187461874718748187491875018751187521875318754187551875618757187581875918760187611876218763187641876518766187671876818769187701877118772187731877418775187761877718778187791878018781187821878318784187851878618787187881878918790187911879218793187941879518796187971879818799188001880118802188031880418805188061880718808188091881018811188121881318814188151881618817188181881918820188211882218823188241882518826188271882818829188301883118832188331883418835188361883718838188391884018841188421884318844188451884618847188481884918850188511885218853188541885518856188571885818859188601886118862188631886418865188661886718868188691887018871188721887318874188751887618877188781887918880188811888218883188841888518886188871888818889188901889118892188931889418895188961889718898188991890018901189021890318904189051890618907189081890918910189111891218913189141891518916189171891818919189201892118922189231892418925189261892718928189291893018931189321893318934189351893618937189381893918940189411894218943189441894518946189471894818949189501895118952189531895418955189561895718958189591896018961189621896318964189651896618967189681896918970189711897218973189741897518976189771897818979189801898118982189831898418985189861898718988189891899018991189921899318994189951899618997189981899919000190011900219003190041900519006190071900819009190101901119012190131901419015190161901719018190191902019021190221902319024190251902619027190281902919030190311903219033190341903519036190371903819039190401904119042190431904419045190461904719048190491905019051190521905319054190551905619057190581905919060190611906219063190641906519066190671906819069190701907119072190731907419075190761907719078190791908019081190821908319084190851908619087190881908919090190911909219093190941909519096190971909819099191001910119102191031910419105191061910719108191091911019111191121911319114191151911619117191181911919120191211912219123191241912519126191271912819129191301913119132191331913419135191361913719138191391914019141191421914319144191451914619147191481914919150191511915219153191541915519156191571915819159191601916119162191631916419165191661916719168191691917019171191721917319174191751917619177191781917919180191811918219183191841918519186191871918819189191901919119192191931919419195191961919719198191991920019201192021920319204192051920619207192081920919210192111921219213192141921519216192171921819219192201922119222192231922419225192261922719228192291923019231192321923319234192351923619237192381923919240192411924219243192441924519246192471924819249192501925119252192531925419255192561925719258192591926019261192621926319264192651926619267192681926919270192711927219273192741927519276192771927819279192801928119282192831928419285192861928719288192891929019291192921929319294192951929619297192981929919300193011930219303193041930519306193071930819309193101931119312193131931419315193161931719318193191932019321193221932319324193251932619327193281932919330193311933219333193341933519336193371933819339193401934119342193431934419345193461934719348193491935019351193521935319354193551935619357193581935919360193611936219363193641936519366193671936819369193701937119372193731937419375193761937719378193791938019381193821938319384193851938619387193881938919390193911939219393193941939519396193971939819399194001940119402194031940419405194061940719408194091941019411194121941319414194151941619417194181941919420194211942219423194241942519426194271942819429194301943119432194331943419435194361943719438194391944019441194421944319444194451944619447194481944919450194511945219453194541945519456194571945819459194601946119462194631946419465194661946719468194691947019471194721947319474194751947619477194781947919480194811948219483194841948519486194871948819489194901949119492194931949419495194961949719498194991950019501195021950319504195051950619507195081950919510195111951219513195141951519516195171951819519195201952119522195231952419525195261952719528195291953019531195321953319534195351953619537195381953919540195411954219543195441954519546195471954819549195501955119552195531955419555195561955719558195591956019561195621956319564195651956619567195681956919570195711957219573195741957519576195771957819579195801958119582195831958419585195861958719588195891959019591195921959319594195951959619597195981959919600196011960219603196041960519606196071960819609196101961119612196131961419615196161961719618196191962019621196221962319624196251962619627196281962919630196311963219633196341963519636196371963819639196401964119642196431964419645196461964719648196491965019651196521965319654196551965619657196581965919660196611966219663196641966519666196671966819669196701967119672196731967419675196761967719678196791968019681196821968319684196851968619687196881968919690196911969219693196941969519696196971969819699197001970119702197031970419705197061970719708197091971019711197121971319714197151971619717197181971919720197211972219723197241972519726197271972819729197301973119732197331973419735197361973719738197391974019741197421974319744197451974619747197481974919750197511975219753197541975519756197571975819759197601976119762197631976419765197661976719768197691977019771197721977319774197751977619777197781977919780197811978219783197841978519786197871978819789197901979119792197931979419795197961979719798197991980019801198021980319804198051980619807198081980919810198111981219813198141981519816198171981819819198201982119822198231982419825198261982719828198291983019831198321983319834198351983619837198381983919840198411984219843198441984519846198471984819849198501985119852198531985419855198561985719858198591986019861198621986319864198651986619867198681986919870198711987219873198741987519876198771987819879198801988119882198831988419885198861988719888198891989019891198921989319894198951989619897198981989919900199011990219903199041990519906199071990819909199101991119912199131991419915199161991719918199191992019921199221992319924199251992619927199281992919930199311993219933199341993519936199371993819939199401994119942199431994419945199461994719948199491995019951199521995319954199551995619957199581995919960199611996219963199641996519966199671996819969199701997119972199731997419975199761997719978199791998019981199821998319984199851998619987199881998919990199911999219993199941999519996199971999819999200002000120002200032000420005200062000720008200092001020011200122001320014200152001620017200182001920020200212002220023200242002520026200272002820029200302003120032200332003420035200362003720038200392004020041200422004320044200452004620047200482004920050200512005220053200542005520056200572005820059200602006120062200632006420065200662006720068200692007020071200722007320074200752007620077200782007920080200812008220083200842008520086200872008820089200902009120092200932009420095200962009720098200992010020101201022010320104201052010620107201082010920110201112011220113201142011520116201172011820119201202012120122201232012420125201262012720128201292013020131201322013320134201352013620137201382013920140201412014220143201442014520146201472014820149201502015120152201532015420155201562015720158201592016020161201622016320164201652016620167201682016920170201712017220173201742017520176201772017820179201802018120182201832018420185201862018720188201892019020191201922019320194201952019620197201982019920200202012020220203202042020520206202072020820209202102021120212202132021420215202162021720218202192022020221202222022320224202252022620227202282022920230202312023220233202342023520236202372023820239202402024120242202432024420245202462024720248202492025020251202522025320254202552025620257202582025920260202612026220263202642026520266202672026820269202702027120272202732027420275202762027720278202792028020281202822028320284202852028620287202882028920290202912029220293202942029520296202972029820299203002030120302203032030420305203062030720308203092031020311203122031320314203152031620317203182031920320203212032220323203242032520326203272032820329203302033120332203332033420335203362033720338203392034020341203422034320344203452034620347203482034920350203512035220353203542035520356203572035820359203602036120362203632036420365203662036720368203692037020371203722037320374203752037620377203782037920380203812038220383203842038520386203872038820389203902039120392203932039420395203962039720398203992040020401204022040320404204052040620407204082040920410204112041220413204142041520416204172041820419204202042120422204232042420425204262042720428204292043020431204322043320434204352043620437204382043920440204412044220443204442044520446204472044820449204502045120452204532045420455204562045720458204592046020461204622046320464204652046620467204682046920470204712047220473204742047520476204772047820479204802048120482204832048420485204862048720488204892049020491204922049320494204952049620497204982049920500205012050220503205042050520506205072050820509205102051120512205132051420515205162051720518205192052020521205222052320524205252052620527205282052920530205312053220533205342053520536205372053820539205402054120542205432054420545205462054720548205492055020551205522055320554205552055620557205582055920560205612056220563205642056520566205672056820569205702057120572205732057420575205762057720578205792058020581205822058320584205852058620587205882058920590205912059220593205942059520596205972059820599206002060120602206032060420605206062060720608206092061020611206122061320614206152061620617206182061920620206212062220623206242062520626206272062820629206302063120632206332063420635206362063720638206392064020641206422064320644206452064620647206482064920650206512065220653206542065520656206572065820659206602066120662206632066420665206662066720668206692067020671206722067320674206752067620677206782067920680206812068220683206842068520686206872068820689206902069120692206932069420695206962069720698206992070020701207022070320704207052070620707207082070920710207112071220713207142071520716207172071820719207202072120722207232072420725207262072720728207292073020731207322073320734207352073620737207382073920740207412074220743207442074520746207472074820749207502075120752207532075420755207562075720758207592076020761207622076320764207652076620767207682076920770207712077220773207742077520776207772077820779207802078120782207832078420785207862078720788207892079020791207922079320794207952079620797207982079920800208012080220803208042080520806208072080820809208102081120812208132081420815208162081720818208192082020821208222082320824208252082620827208282082920830208312083220833208342083520836208372083820839208402084120842208432084420845208462084720848208492085020851208522085320854208552085620857208582085920860208612086220863208642086520866208672086820869208702087120872208732087420875208762087720878208792088020881208822088320884208852088620887208882088920890208912089220893208942089520896208972089820899209002090120902209032090420905209062090720908209092091020911209122091320914209152091620917209182091920920209212092220923209242092520926209272092820929209302093120932209332093420935209362093720938209392094020941209422094320944209452094620947209482094920950209512095220953209542095520956209572095820959209602096120962209632096420965209662096720968209692097020971209722097320974209752097620977209782097920980209812098220983209842098520986209872098820989209902099120992209932099420995209962099720998209992100021001210022100321004210052100621007210082100921010210112101221013210142101521016210172101821019210202102121022210232102421025210262102721028210292103021031210322103321034210352103621037210382103921040210412104221043210442104521046210472104821049210502105121052210532105421055210562105721058210592106021061210622106321064210652106621067210682106921070210712107221073210742107521076210772107821079210802108121082210832108421085210862108721088210892109021091210922109321094210952109621097210982109921100211012110221103211042110521106211072110821109211102111121112211132111421115211162111721118211192112021121211222112321124211252112621127211282112921130211312113221133211342113521136211372113821139211402114121142211432114421145211462114721148211492115021151211522115321154211552115621157211582115921160211612116221163211642116521166211672116821169211702117121172211732117421175211762117721178211792118021181211822118321184211852118621187211882118921190211912119221193211942119521196211972119821199212002120121202212032120421205212062120721208212092121021211212122121321214212152121621217212182121921220212212122221223212242122521226212272122821229212302123121232212332123421235212362123721238212392124021241212422124321244212452124621247212482124921250212512125221253212542125521256212572125821259212602126121262212632126421265212662126721268212692127021271212722127321274212752127621277212782127921280212812128221283212842128521286212872128821289212902129121292212932129421295212962129721298212992130021301213022130321304213052130621307213082130921310213112131221313213142131521316213172131821319213202132121322213232132421325213262132721328213292133021331213322133321334213352133621337213382133921340213412134221343213442134521346213472134821349213502135121352213532135421355213562135721358213592136021361213622136321364213652136621367213682136921370213712137221373213742137521376213772137821379213802138121382213832138421385213862138721388213892139021391213922139321394213952139621397213982139921400214012140221403214042140521406214072140821409214102141121412214132141421415214162141721418214192142021421214222142321424214252142621427214282142921430214312143221433214342143521436214372143821439214402144121442214432144421445214462144721448214492145021451214522145321454214552145621457214582145921460214612146221463214642146521466214672146821469214702147121472214732147421475214762147721478214792148021481214822148321484214852148621487214882148921490214912149221493214942149521496214972149821499215002150121502215032150421505215062150721508215092151021511215122151321514215152151621517215182151921520215212152221523215242152521526215272152821529215302153121532215332153421535215362153721538215392154021541215422154321544215452154621547215482154921550215512155221553215542155521556215572155821559215602156121562215632156421565215662156721568215692157021571215722157321574215752157621577215782157921580215812158221583215842158521586215872158821589215902159121592215932159421595215962159721598215992160021601216022160321604216052160621607216082160921610216112161221613216142161521616216172161821619216202162121622216232162421625216262162721628216292163021631216322163321634216352163621637216382163921640216412164221643216442164521646216472164821649216502165121652216532165421655216562165721658216592166021661216622166321664216652166621667216682166921670216712167221673216742167521676216772167821679216802168121682216832168421685216862168721688216892169021691216922169321694216952169621697216982169921700217012170221703217042170521706217072170821709217102171121712217132171421715217162171721718217192172021721217222172321724217252172621727217282172921730217312173221733217342173521736217372173821739217402174121742217432174421745217462174721748217492175021751217522175321754217552175621757217582175921760217612176221763217642176521766217672176821769217702177121772217732177421775217762177721778217792178021781217822178321784217852178621787217882178921790217912179221793217942179521796217972179821799218002180121802218032180421805218062180721808218092181021811218122181321814218152181621817218182181921820218212182221823218242182521826218272182821829218302183121832218332183421835218362183721838218392184021841218422184321844218452184621847218482184921850218512185221853218542185521856218572185821859218602186121862218632186421865218662186721868218692187021871218722187321874218752187621877218782187921880218812188221883218842188521886218872188821889218902189121892218932189421895218962189721898218992190021901219022190321904219052190621907219082190921910219112191221913219142191521916219172191821919219202192121922219232192421925219262192721928219292193021931219322193321934219352193621937219382193921940219412194221943219442194521946219472194821949219502195121952219532195421955219562195721958219592196021961219622196321964219652196621967219682196921970219712197221973219742197521976219772197821979219802198121982219832198421985219862198721988219892199021991219922199321994219952199621997219982199922000220012200222003220042200522006220072200822009220102201122012220132201422015220162201722018220192202022021220222202322024220252202622027220282202922030220312203222033220342203522036220372203822039220402204122042220432204422045220462204722048220492205022051220522205322054220552205622057220582205922060220612206222063220642206522066220672206822069220702207122072220732207422075220762207722078220792208022081220822208322084220852208622087220882208922090220912209222093220942209522096220972209822099221002210122102221032210422105221062210722108221092211022111221122211322114221152211622117221182211922120221212212222123221242212522126221272212822129221302213122132221332213422135221362213722138221392214022141221422214322144221452214622147221482214922150221512215222153221542215522156221572215822159221602216122162221632216422165221662216722168221692217022171221722217322174221752217622177221782217922180221812218222183221842218522186221872218822189221902219122192221932219422195221962219722198221992220022201222022220322204222052220622207222082220922210222112221222213222142221522216222172221822219222202222122222222232222422225222262222722228222292223022231222322223322234222352223622237222382223922240
  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. // TTIA routine
  368. //=========================================
  369. int sendTTIAInfo(uint8_t gun_index)
  370. {
  371. static int sn = 0;
  372. int result = FAIL;
  373. struct hostent *server;
  374. int udp_socket_fd;
  375. struct sockaddr_in dest_addr = {0};
  376. uint8_t tx_buf[80] = {0};
  377. uint8_t logBuf[256]= {0};
  378. uint8_t tx_len, tempIndex, socStart, socEnd;
  379. uint16_t PresentChargedEnergy;
  380. struct tm tmStart, tmEnd;
  381. DEBUG_INFO("sendTTIAInfo...\n");
  382. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  383. {
  384. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  385. {
  386. tempIndex = ((gun_index==2) ? 1: 0);
  387. }
  388. else
  389. {
  390. tempIndex = gun_index;
  391. }
  392. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  393. {
  394. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  395. {
  396. socStart = ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].EvBatteryStartSoc;
  397. socEnd = ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].EvBatterySoc;
  398. PresentChargedEnergy = (uint16_t)(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargedEnergy*10);
  399. }
  400. }
  401. }
  402. else if(gunType[gun_index] == GUN_TYPE_CCS)
  403. {
  404. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  405. {
  406. tempIndex = ((gun_index==2) ? 1: 0);
  407. }
  408. else
  409. {
  410. tempIndex = gun_index;
  411. }
  412. for (int index = 0; index < CCS_QUANTITY; index++)
  413. {
  414. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  415. {
  416. socStart = ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].EvBatteryStartSoc;
  417. socEnd = ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].EvBatterySoc;
  418. PresentChargedEnergy = (uint16_t)(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargedEnergy*10);
  419. }
  420. }
  421. }
  422. else if(gunType[gun_index] == GUN_TYPE_GBT)
  423. {
  424. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  425. {
  426. tempIndex = ((gun_index==2) ? 1: 0);
  427. }
  428. else
  429. {
  430. tempIndex = gun_index;
  431. }
  432. for (int index = 0; index < GB_QUANTITY; index++)
  433. {
  434. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  435. {
  436. socStart = ShmSysConfigAndInfo->SysInfo.GbChargingData[index].EvBatteryStartSoc;
  437. socEnd = ShmSysConfigAndInfo->SysInfo.GbChargingData[index].EvBatterySoc;
  438. PresentChargedEnergy = (uint16_t)(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargedEnergy*10);
  439. }
  440. }
  441. }
  442. else if(gunType[gun_index] == GUN_TYPE_DO)
  443. {
  444. tempIndex = gun_index;
  445. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  446. {
  447. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  448. {
  449. socStart = ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.EvBatteryStartSoc;
  450. socEnd = ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.EvBatterySoc;
  451. PresentChargedEnergy = (uint16_t)(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PresentChargedEnergy*10);
  452. }
  453. }
  454. }
  455. else
  456. {
  457. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  458. {
  459. tempIndex = 2;
  460. }
  461. else
  462. {
  463. tempIndex = gun_index;
  464. }
  465. for (int index = 0; index < AC_QUANTITY; index++)
  466. {
  467. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  468. {
  469. socStart = ShmSysConfigAndInfo->SysInfo.AcChargingData[index].EvBatteryStartSoc;
  470. socEnd = ShmSysConfigAndInfo->SysInfo.AcChargingData[index].EvBatterySoc;
  471. PresentChargedEnergy = (uint16_t)(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargedEnergy*10);
  472. }
  473. }// END
  474. }
  475. // Message assembly
  476. sprintf((char*)&tx_buf[0], "APTS"); // Protocol ID
  477. tx_buf[4] = 0x02; // Protocol Version
  478. tx_buf[5] = 0xb0; // Message ID
  479. tx_buf[6] = ShmSysConfigAndInfo->SysConfig.TTIA_Info.busVenderId & 0xff; // CustomerID low byte
  480. tx_buf[7] = (ShmSysConfigAndInfo->SysConfig.TTIA_Info.busVenderId>>8) & 0xff; // CustomerID high byte
  481. tx_buf[8] = 0x00; // CarID low byte
  482. tx_buf[9] = 0x00; // CarID high byte
  483. tx_buf[10] = 0x00; // ID Storage
  484. tx_buf[11] = 0x00; // Driver lowest byte
  485. tx_buf[12] = 0x00; // Driver 2nd byte
  486. tx_buf[13] = 0x00; // Driver 3rd byte
  487. tx_buf[14] = 0x00; // Driver highest byte
  488. tx_buf[15] = sn & 0xff; // Sequence SN low byte
  489. tx_buf[16] = (sn>>8) & 0xff; // Sequence SN high byte
  490. tx_buf[17] = 0x00; // Reserve
  491. tx_buf[18] = 60 & 0xff; // Payload length low byte
  492. tx_buf[19] = (60>>8) & 0xff; // Payload length high byte
  493. // EVSE provider
  494. memcpy((char*)&tx_buf[20], ShmSysConfigAndInfo->SysConfig.TTIA_Info.EquipmentProvider, 15);
  495. // EVSE provider
  496. tx_buf[35] = ShmSysConfigAndInfo->SysConfig.TTIA_Info.TransportationCompanyNo;
  497. // EVSE id
  498. tx_buf[36] = ShmSysConfigAndInfo->SysConfig.TTIA_Info.ChargeBoxId;
  499. // Connector id
  500. tx_buf[37] = gun_index;
  501. // EVSE station
  502. memcpy((char*)&tx_buf[38], ShmSysConfigAndInfo->SysConfig.TTIA_Info.evseStation, 15);
  503. // Vehicle SN
  504. memcpy(&tx_buf[53], &ShmOCPP16Data->StartTransaction[gun_index].IdTag, 8);
  505. // Mileage
  506. tx_buf[61] = 0x00; // lowest byte
  507. tx_buf[62] = 0x00; // 2nd byte
  508. tx_buf[63] = 0x00; // highest byte
  509. // Start date time 6 bytes
  510. 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))
  511. {
  512. struct tm *tmTarget;
  513. struct timeb tbTarget;
  514. tmStart.tm_year -= 1900;
  515. tmStart.tm_mon -= 1;
  516. tmStart.tm_gmtoff = 0;
  517. tbTarget.time = mktime(&tmStart);
  518. tbTarget.timezone = 0;
  519. tbTarget.time += (8*3600);
  520. tmTarget = gmtime(&tbTarget.time);
  521. tx_buf[64] = ((tmTarget->tm_year+1900)-2000);
  522. tx_buf[65] = (tmTarget->tm_mon+1);
  523. tx_buf[66] = tmTarget->tm_mday;
  524. tx_buf[67] = tmTarget->tm_hour;
  525. tx_buf[68] = tmTarget->tm_min;
  526. tx_buf[69] = tmTarget->tm_sec;
  527. }
  528. // Stop date time 6 bytes
  529. 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))
  530. {
  531. struct tm *tmTarget;
  532. struct timeb tbTarget;
  533. tmEnd.tm_year -= 1900;
  534. tmEnd.tm_mon -= 1;
  535. tmEnd.tm_gmtoff = 0;
  536. tbTarget.time = mktime(&tmEnd);
  537. tbTarget.timezone = 0;
  538. tbTarget.time += (8*3600);
  539. tmTarget = gmtime(&tbTarget.time);
  540. tx_buf[70] = ((tmTarget->tm_year+1900)-2000);
  541. tx_buf[71] = (tmTarget->tm_mon+1);
  542. tx_buf[72] = tmTarget->tm_mday;
  543. tx_buf[73] = tmTarget->tm_hour;
  544. tx_buf[74] = tmTarget->tm_min;
  545. tx_buf[75] = tmTarget->tm_sec;
  546. }
  547. // Session energy 2 bytes
  548. tx_buf[76] = PresentChargedEnergy & 0xff;
  549. tx_buf[77] = (PresentChargedEnergy>>8) & 0xff;
  550. // Start SOC 1 byte
  551. tx_buf[78] = socStart;
  552. // Stop SOC 1 byte
  553. tx_buf[79] = socEnd;
  554. // Open socket
  555. udp_socket_fd = socket(AF_INET, SOCK_DGRAM, 0);
  556. if(udp_socket_fd == -1)
  557. {
  558. DEBUG_ERROR("UDP socket create failed!\n");
  559. }
  560. else
  561. {
  562. // Get server DNS entry
  563. server = gethostbyname((char*)ShmSysConfigAndInfo->SysConfig.TTIA_Info.server_addr);
  564. if (server == NULL)
  565. {
  566. DEBUG_ERROR("ERROR, no such host as %s\n", ShmSysConfigAndInfo->SysConfig.TTIA_Info.server_addr);
  567. }
  568. else
  569. {
  570. // Build the server's Internet address
  571. bzero((char *) &dest_addr, sizeof(dest_addr));
  572. dest_addr.sin_family = AF_INET;
  573. bcopy((char *)server->h_addr, (char *)&dest_addr.sin_addr.s_addr, server->h_length);
  574. dest_addr.sin_port = htons(ShmSysConfigAndInfo->SysConfig.TTIA_Info.server_port);
  575. if((tx_len = sendto(udp_socket_fd, tx_buf, ARRAY_SIZE(tx_buf), 0, &dest_addr, sizeof(dest_addr))) >= 0)
  576. {
  577. for(uint8_t idx=0;idx<ARRAY_SIZE(tx_buf);idx++)
  578. {
  579. sprintf((char*)logBuf, "%s %02X", logBuf, tx_buf[idx]);
  580. }
  581. DEBUG_TTIA_INFO("TX raw data length: %d\n", tx_len);
  582. DEBUG_TTIA_INFO("Message raw: %s\n", logBuf);
  583. DEBUG_TTIA_INFO("OCPP Transaction ID: %d\n", ShmOCPP16Data->StopTransaction[gun_index].TransactionId);
  584. DEBUG_TTIA_INFO("TTIA server address: %s\n", ShmSysConfigAndInfo->SysConfig.TTIA_Info.server_addr);
  585. DEBUG_TTIA_INFO("TTIA server port: %d\n", ShmSysConfigAndInfo->SysConfig.TTIA_Info.server_port);
  586. DEBUG_TTIA_INFO("---------- Header ----------\n");
  587. DEBUG_TTIA_INFO("ProtocolID: APTS\n");
  588. DEBUG_TTIA_INFO("ProtocolVer: 0x02\n");
  589. DEBUG_TTIA_INFO("MessageID: 0xB0\n");
  590. DEBUG_TTIA_INFO("CustomerID: 0x%04X\n", ShmSysConfigAndInfo->SysConfig.TTIA_Info.busVenderId);
  591. DEBUG_TTIA_INFO("CarID: 0x0000\n");
  592. DEBUG_TTIA_INFO("IDStorage: 0x00\n");
  593. DEBUG_TTIA_INFO("DriverID: 0x00000000\n");
  594. DEBUG_TTIA_INFO("Sequence: %d\n", sn);
  595. DEBUG_TTIA_INFO("Reserved: 0x00\n");
  596. DEBUG_TTIA_INFO("Len: 0x3C\n");
  597. DEBUG_TTIA_INFO("--------- Payload ---------\n");
  598. DEBUG_TTIA_INFO("EquipmentProvider: %s\n", ShmSysConfigAndInfo->SysConfig.TTIA_Info.EquipmentProvider);
  599. DEBUG_TTIA_INFO("TransportationCompanyNo: %d\n", ShmSysConfigAndInfo->SysConfig.TTIA_Info.TransportationCompanyNo);
  600. DEBUG_TTIA_INFO("ChargeBoxId: %d\n", ShmSysConfigAndInfo->SysConfig.TTIA_Info.ChargeBoxId);
  601. DEBUG_TTIA_INFO("Gun index: %d\n", gun_index);
  602. DEBUG_TTIA_INFO("evseStation: %s\n", ShmSysConfigAndInfo->SysConfig.TTIA_Info.evseStation);
  603. DEBUG_TTIA_INFO("EV vehicle: %s\n", ShmOCPP16Data->StartTransaction[gun_index].IdTag);
  604. DEBUG_TTIA_INFO("EV mileage: 000000\n");
  605. DEBUG_TTIA_INFO("Session start data time: %s\n", ShmOCPP16Data->StartTransaction[gun_index].Timestamp);
  606. DEBUG_TTIA_INFO("Session stop data time: %s\n", ShmOCPP16Data->StopTransaction[gun_index].Timestamp);
  607. DEBUG_TTIA_INFO("Session charged energy (kwh): %f\n", (PresentChargedEnergy/10.0));
  608. DEBUG_TTIA_INFO("Session start SOC: %d\n", socStart);
  609. DEBUG_TTIA_INFO("Session end SOC: %d\n", socEnd);
  610. DEBUG_TTIA_INFO("=========================================\n");
  611. sn++;
  612. result = PASS;
  613. }
  614. else
  615. {
  616. DEBUG_ERROR("UDP sent out fail.\n");
  617. }
  618. }
  619. }
  620. return result;
  621. }
  622. //=========================================
  623. // Save configuration
  624. //=========================================
  625. int runShellCmd(const char*cmd)
  626. {
  627. int result = FAIL;
  628. char buf[256];
  629. FILE *fp;
  630. fp = popen(cmd, "r");
  631. if(fp != NULL)
  632. {
  633. while(fgets(buf, sizeof(buf), fp) != NULL)
  634. {
  635. DEBUG_INFO("%s\n", buf);
  636. }
  637. result = PASS;
  638. }
  639. pclose(fp);
  640. return result;
  641. }
  642. int StoreUsrConfigData(struct SysConfigData *UsrData)
  643. {
  644. int result = PASS;
  645. int fd,wrd;
  646. unsigned int i,Chk;
  647. unsigned char *ptr, *BufTmp;
  648. int MtdBlockSize = 0x300000;
  649. Chk=0;
  650. ptr=(unsigned char *)UsrData;
  651. if((BufTmp=malloc(MtdBlockSize))!=NULL)
  652. {
  653. memset(BufTmp,0,MtdBlockSize);
  654. memcpy(BufTmp,ptr,sizeof(struct SysConfigData));
  655. for(i=ARRAY_SIZE(UsrData->CsuBootLoadFwRev);i<MtdBlockSize-4;i++)
  656. Chk+=*(BufTmp+i);
  657. memcpy(BufTmp+MtdBlockSize-4, &Chk, 4);
  658. // Output configuration to file.
  659. fd = open("/mnt/EvseConfig.bin", O_RDWR|O_CREAT);
  660. if (fd < 0)
  661. {
  662. DEBUG_ERROR("open /mnt/EvseConfig.bin NG\n");
  663. free(BufTmp);
  664. return 0;
  665. }
  666. wrd=write(fd, BufTmp, MtdBlockSize);
  667. close(fd);
  668. if(wrd<MtdBlockSize)
  669. {
  670. DEBUG_ERROR("write /mnt/EvseConfig.bin NG\n");
  671. free(BufTmp);
  672. return 0;
  673. }
  674. DEBUG_INFO("EvseConfig write to file in /mnt OK.\n");
  675. DEBUG_INFO("Erase /dev/mtd10.\n");
  676. runShellCmd("flash_erase /dev/mtd10 0 0");
  677. DEBUG_INFO("Write /dev/mtd10.\n");
  678. runShellCmd("nandwrite -p /dev/mtd10 /mnt/EvseConfig.bin");
  679. DEBUG_INFO("Erase /dev/mtd11.\n");
  680. runShellCmd("flash_erase /dev/mtd11 0 0");
  681. DEBUG_INFO("Write /dev/mtd11.\n");
  682. runShellCmd("nandwrite -p /dev/mtd11 /mnt/EvseConfig.bin");
  683. system("rm -f /mnt/EvseConfig.bin");
  684. DEBUG_INFO("EvseConfig write to flash OK\n");
  685. }
  686. else
  687. {
  688. DEBUG_ERROR("alloc BlockSize NG\r\n");
  689. result = FAIL;
  690. }
  691. if(BufTmp!=NULL)
  692. free(BufTmp);
  693. return result;
  694. }
  695. //=========================================
  696. // Sqlite3 related function
  697. //=========================================
  698. static int selectSqlCount = 0;
  699. static int callback(void *data, int argc, char **argv, char **azColName){
  700. int i;
  701. //printf("%s: ", (const char*)data);
  702. selectSqlCount = argc;
  703. for(i = 0; i<argc; i++){
  704. // printf("%s = %s\n", azColName[i], argv[i] ? argv[i] : "NULL");
  705. }
  706. //printf("\n");
  707. return 0;
  708. }
  709. static int versioncallback(void *data, int argc, char **argv, char **azColName){
  710. //int i;
  711. //printf("%s:\n", (const char*)data);
  712. locallistVersion = (argv[5] ? atoi(argv[5]) : 0);
  713. DEBUG_INFO("Callback query locallistVersion : %d\n", locallistVersion);
  714. return 0;
  715. }
  716. static int IdTagcallback(void *data, int columenCount, char **columnValue, char **columnName){
  717. //printf("%s:\n", (const char*)data);
  718. //idTag
  719. sprintf(idTagAuthorization,"%s", columnValue[1] ? columnValue[1] : "NULL");
  720. sprintf(idTagQuery.idTagstr,"%s", columnValue[1] ? columnValue[1] : "NULL");
  721. //parentIdTag
  722. sprintf(idTagQuery.parentIdTag,"%s", columnValue[2] ? columnValue[2] : "NULL");
  723. //expir_date
  724. sprintf(idTagQuery.expiryDate,"%s", columnValue[3] ? columnValue[3] : "NULL");
  725. //status
  726. sprintf(idTagQuery.idTagstatus,"%s", columnValue[4] ? columnValue[4] : "NULL");
  727. //version
  728. if(columenCount > 5)
  729. idTagQuery.listVersionInt = atoi(columnValue[5]);
  730. //DEBUG_INFO("IdTag=%s\n", idTagAuthorization);
  731. return 0;
  732. }
  733. static int deleteIdTagcallback(void *data, int argc, char **argv, char **azColName)
  734. {
  735. // localversion = argv[5] ? atoi(argv[5]) : 0;
  736. // printf("localversion=%d\n", localversion);
  737. return 0;
  738. }
  739. int sqlite3_exec_callback(void *data, int n_columns, char **col_values, char **col_names)
  740. {
  741. for (int i = 0; i < n_columns; i++)
  742. {
  743. DEBUG_INFO("%s\t", col_values[i]);
  744. }
  745. DEBUG_INFO("\n");
  746. return 0;
  747. }
  748. int OCPP_cleanLocalCache()
  749. {
  750. char * sqlcleanLocalList = "delete from ocpp_auth_cache";
  751. char *errMsg = 0;
  752. int rc =sqlite3_exec(db, sqlcleanLocalList, 0, 0, &errMsg);
  753. if (SQLITE_OK != rc)
  754. {
  755. DEBUG_INFO("SQL error: %s\n",errMsg);
  756. return FALSE;
  757. }
  758. return TRUE;
  759. }
  760. int OCPP_addLocalCache(char *idTag, char *parentTage, char *expiryDate, char *status)
  761. {
  762. int isSuccess = TRUE;
  763. int ret = 0;
  764. //const char* data = "Callback function called";
  765. char sql[300];
  766. char zErrMsg[200];
  767. memset(sql, 0, 300);
  768. memset(zErrMsg, 0, 200);
  769. 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);
  770. //* Execute SQL statement */
  771. ret = sqlite3_exec(db, sql, callback, 0, (char **)&zErrMsg);
  772. if( ret != SQLITE_OK )
  773. {
  774. DEBUG_INFO("SQL error: %s\n", zErrMsg);
  775. isSuccess = FALSE;
  776. }
  777. return isSuccess;
  778. }
  779. void OCPP_getIdTagFromLocalCache(char idTag[])
  780. {
  781. int rc = 0;
  782. char sql[100];
  783. char zErrMsg[100];
  784. memset(sql, 0, 100);
  785. memset(zErrMsg, 0, 100);
  786. memset(idTagAuthorization, 0, ARRAY_SIZE(idTagAuthorization));
  787. memset(&idTagQuery, 0, sizeof(idTagQuery));
  788. sprintf(sql,"select * from ocpp_auth_cache where idtag='%s'", idTag);
  789. /* Execute SQL statement */
  790. rc = sqlite3_exec(db, sql, IdTagcallback, 0, (char **)&zErrMsg);
  791. if( rc != SQLITE_OK )
  792. {
  793. DEBUG_INFO("SQL error: %s\n", zErrMsg);
  794. }
  795. }
  796. void OCPP_getListVerion()
  797. {
  798. int rc = 0;
  799. // const char* data = "Callback function called";
  800. char sql[100];
  801. char zErrMsg[100];
  802. memset(sql, 0, 100);
  803. memset(zErrMsg, 0, 100);
  804. strcpy(sql, "select * from ocpp_auth_local order by version desc, idx desc limit 1");
  805. /* Execute SQL statement */
  806. rc = sqlite3_exec(db, sql, versioncallback, 0, (char **)&zErrMsg);
  807. if( rc != SQLITE_OK )
  808. {
  809. DEBUG_INFO("SQL error: %s\n", zErrMsg);
  810. }
  811. }
  812. void OCPP_get_TableAuthlocalAllData(void)
  813. {
  814. int rc = 0;
  815. char sql[100];
  816. char zErrMsg[100];
  817. memset(sql, 0, 100);
  818. memset(zErrMsg, 0, 100);
  819. sprintf(sql,"select * from ocpp_auth_local ");
  820. /* Execute SQL statement */
  821. rc = sqlite3_exec(db, sql, &sqlite3_exec_callback, 0,(char **)&zErrMsg);
  822. if( rc != SQLITE_OK )
  823. {
  824. DEBUG_INFO("SQL error: %s\n", zErrMsg);
  825. }
  826. //return ver;
  827. }
  828. int OCPP_cleanLocalList()
  829. {
  830. char * sqlcleanLocalList = "delete from ocpp_auth_local";
  831. char *errMsg = 0;
  832. int rc =sqlite3_exec(db, sqlcleanLocalList, 0, 0, &errMsg);
  833. if (SQLITE_OK != rc)
  834. {
  835. DEBUG_INFO("%s\n",errMsg);
  836. return FALSE;
  837. }
  838. return TRUE;
  839. }
  840. int OCPP_addLocalList(int version, char *idTag, char *parentTage, char *expiryDate, char *status)
  841. {
  842. int isSuccess = FALSE;
  843. int ret = 0;
  844. //const char* data = "Callback function called";
  845. char sql[300];
  846. char zErrMsg[200];
  847. memset(sql, 0, 300);
  848. memset(zErrMsg, 0, 200);
  849. 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);
  850. //* Execute SQL statement */
  851. ret = sqlite3_exec(db, sql, callback, 0, (char **)&zErrMsg);
  852. if( ret != SQLITE_OK )
  853. {
  854. DEBUG_INFO("SQL error: %s\n", zErrMsg);
  855. return isSuccess;
  856. }
  857. memset(sql, 0, 300);
  858. sprintf(sql, "UPDATE ocpp_auth_local SET version=%d",version);
  859. ret = sqlite3_exec(db, sql, NULL, NULL, (char **)&zErrMsg);
  860. if( ret != SQLITE_OK )
  861. {
  862. DEBUG_INFO("SQL error: %s\n", zErrMsg);
  863. return isSuccess;
  864. }
  865. isSuccess = TRUE;
  866. return isSuccess;
  867. }
  868. void OCPP_getIdTagFromLocalList(char idTag[])
  869. {
  870. int rc = 0;
  871. // const char* data = "Callback function called";
  872. char sql[100];
  873. char zErrMsg[100];
  874. memset(sql, 0, 100);
  875. memset(zErrMsg, 0, 100);
  876. memset(idTagAuthorization, 0, ARRAY_SIZE(idTagAuthorization));
  877. memset(&idTagQuery, 0, sizeof(idTagQuery));
  878. //DEBUG_INFO("look up card: %s in ocpp_auth_local table", idTag);
  879. sprintf(sql,"select * from ocpp_auth_local where idtag='%s'", idTag);
  880. /* Execute SQL statement */
  881. rc = sqlite3_exec(db, sql, IdTagcallback, 0, (char **)&zErrMsg);
  882. if( rc != SQLITE_OK )
  883. {
  884. DEBUG_INFO("SQL error: %s\n", zErrMsg);
  885. }
  886. //return ver;
  887. }
  888. void OCPP_deleteIdTagFromLocalList(char idTag[])
  889. {
  890. //int ver = 0;
  891. //int isSuccess = FALSE;
  892. int rc = 0;
  893. char sql[100];
  894. char zErrMsg[100];
  895. memset(sql, 0, 100);
  896. memset(zErrMsg, 0, 100);
  897. sprintf(sql,"DELETE from ocpp_auth_local where idtag='%s'; SELECT * from ocpp_auth_local;", idTag);
  898. //* Execute SQL statement */
  899. rc = sqlite3_exec(db, sql, deleteIdTagcallback, 0,(char **)&zErrMsg);
  900. if( rc != SQLITE_OK )
  901. {
  902. DEBUG_INFO("SQL error: %s\n", zErrMsg);
  903. }
  904. }
  905. int getCurrentYear()
  906. {
  907. int result = 0;
  908. time_t CurrentTime;
  909. struct tm *tm;
  910. CurrentTime = time(NULL);
  911. tm=localtime(&CurrentTime);
  912. result = (tm->tm_year + 1900);
  913. return result;
  914. }
  915. int OCPP_insert_transaction_msg(uint8_t isStartTransaction, char *transactionMsg)
  916. {
  917. int result = PASS;
  918. char* errMsg = NULL;
  919. char sqlStr[8192];
  920. sprintf(sqlStr, "insert into ocpp_transaction_record(occurDatetime, message_type, message_content) values(CURRENT_TIMESTAMP, '%s', '%s');", (isStartTransaction?"startTransaction":"stopTransaction"), transactionMsg);
  921. if (sqlite3_exec(db, sqlStr, 0, 0, &errMsg) != SQLITE_OK)
  922. {
  923. result = FAIL;
  924. DEBUG_WARN( "Insert local transaction record error message: %s\n", errMsg);
  925. }
  926. 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));
  927. if (sqlite3_exec(db, sqlStr, 0, 0, &errMsg) != SQLITE_OK)
  928. {
  929. result = FAIL;
  930. DEBUG_WARN( "delete local transaction record error message: %s\n", errMsg);
  931. }
  932. return result;
  933. }
  934. int OCPP_updatePeriodEnergy(uint8_t gun_index)
  935. {
  936. int isSuccess = TRUE;
  937. int tempIndex;
  938. json_object *EnergyDataTransfer = json_object_new_object();
  939. json_object *periodEnergys = json_object_new_object();
  940. char sql[1024];
  941. char zErrMsg[200];
  942. memset(sql, 0, ARRAY_SIZE(sql));
  943. memset(zErrMsg, 0, ARRAY_SIZE(zErrMsg));
  944. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  945. {
  946. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  947. {
  948. tempIndex = ((gun_index==2) ? 1: 0);
  949. }
  950. else
  951. {
  952. tempIndex = gun_index;
  953. }
  954. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  955. {
  956. if ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex))
  957. {
  958. json_object_object_add(EnergyDataTransfer, "txId", json_object_new_int(ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId));
  959. for(uint8_t idxPeriod=0;idxPeriod<ARRAY_SIZE(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].presentChargedEnergyPeriod);idxPeriod++)
  960. {
  961. uint8_t period[3];
  962. sprintf((char*)period, "%d", idxPeriod);
  963. json_object_object_add(periodEnergys, (const char *)period, json_object_new_double(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].presentChargedEnergyPeriod[idxPeriod]));
  964. }
  965. json_object_object_add(EnergyDataTransfer, "periodEnergy", periodEnergys);
  966. } //end of the same index
  967. }//end of for CHAdeMO_QUANTITY
  968. }
  969. else if(gunType[gun_index] == GUN_TYPE_CCS)
  970. {
  971. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  972. {
  973. tempIndex = ((gun_index==2) ? 1: 0);
  974. }
  975. else
  976. {
  977. tempIndex = gun_index;
  978. }
  979. for (int index = 0; index < CCS_QUANTITY; index++)
  980. {
  981. if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  982. {
  983. json_object_object_add(EnergyDataTransfer, "txId", json_object_new_int(ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId));
  984. for(uint8_t idxPeriod=0;idxPeriod<ARRAY_SIZE(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].presentChargedEnergyPeriod);idxPeriod++)
  985. {
  986. uint8_t period[3];
  987. sprintf((char*)period, "%d", idxPeriod);
  988. json_object_object_add(periodEnergys, (const char *)period, json_object_new_double(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].presentChargedEnergyPeriod[idxPeriod]));
  989. }
  990. json_object_object_add(EnergyDataTransfer, "periodEnergy", periodEnergys);
  991. } //end of the same index
  992. } // end of for CCS_QUANTITY
  993. }
  994. else if(gunType[gun_index] == GUN_TYPE_GBT)
  995. {
  996. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  997. {
  998. tempIndex = ((gun_index==2) ? 1: 0);
  999. }
  1000. else
  1001. {
  1002. tempIndex = gun_index;
  1003. }
  1004. for (int index = 0; index < GB_QUANTITY; index++)
  1005. {
  1006. if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  1007. {
  1008. json_object_object_add(EnergyDataTransfer, "txId", json_object_new_int(ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId));
  1009. for(uint8_t idxPeriod=0;idxPeriod<ARRAY_SIZE(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].presentChargedEnergyPeriod);idxPeriod++)
  1010. {
  1011. uint8_t period[3];
  1012. sprintf((char*)period, "%d", idxPeriod);
  1013. json_object_object_add(periodEnergys, (const char *)period, json_object_new_double(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].presentChargedEnergyPeriod[idxPeriod]));
  1014. }
  1015. json_object_object_add(EnergyDataTransfer, "periodEnergy", periodEnergys);
  1016. } //end of the same index
  1017. } // end of for GB_QUANTITY
  1018. }
  1019. else if(gunType[gun_index] == GUN_TYPE_DO)
  1020. {
  1021. tempIndex = gun_index;
  1022. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  1023. {
  1024. if(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  1025. {
  1026. json_object_object_add(EnergyDataTransfer, "txId", json_object_new_int(ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId));
  1027. for(uint8_t idxPeriod=0;idxPeriod<ARRAY_SIZE(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.presentChargedEnergyPeriod);idxPeriod++)
  1028. {
  1029. uint8_t period[3];
  1030. sprintf((char*)period, "%d", idxPeriod);
  1031. json_object_object_add(periodEnergys, (const char *)period, json_object_new_double(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.presentChargedEnergyPeriod[idxPeriod]));
  1032. }
  1033. json_object_object_add(EnergyDataTransfer, "periodEnergy", periodEnergys);
  1034. } //end of the same index
  1035. }
  1036. }
  1037. else
  1038. {
  1039. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  1040. {
  1041. tempIndex = 2;
  1042. }
  1043. else
  1044. {
  1045. tempIndex = gun_index;
  1046. }
  1047. for (int index = 0; index < AC_QUANTITY; index++)
  1048. {
  1049. if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  1050. {
  1051. json_object_object_add(EnergyDataTransfer, "txId", json_object_new_int(ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId));
  1052. for(uint8_t idxPeriod=0;idxPeriod<ARRAY_SIZE(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].presentChargedEnergyPeriod);idxPeriod++)
  1053. {
  1054. uint8_t period[3];
  1055. sprintf((char*)period, "%d", idxPeriod);
  1056. json_object_object_add(periodEnergys, (const char *)period, json_object_new_double(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].presentChargedEnergyPeriod[idxPeriod]));
  1057. }
  1058. json_object_object_add(EnergyDataTransfer, "periodEnergy", periodEnergys);
  1059. }//end of the same index
  1060. }//end of for AC_QUANTITY
  1061. }
  1062. 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));
  1063. json_object_put(EnergyDataTransfer);
  1064. //* Execute SQL statement */
  1065. if( sqlite3_exec(db, sql, callback, 0, (char **)&zErrMsg) != SQLITE_OK )
  1066. {
  1067. DEBUG_WARN("SQL error: %s\n", zErrMsg);
  1068. isSuccess = FALSE;
  1069. }
  1070. sprintf(sql, "delete from ocpp_period_energy where (occurDatetime < '%04d-01-01 00:00:00');", (getCurrentYear()-3));
  1071. if (sqlite3_exec(db, sql, 0, 0, (char **)&zErrMsg) != SQLITE_OK)
  1072. {
  1073. DEBUG_WARN( "delete period energy record error message: %s\n", zErrMsg);
  1074. isSuccess = FALSE;
  1075. }
  1076. return isSuccess;
  1077. }
  1078. int OCPP_getPeriodEnergyToDataTransfer(int32_t transactionId)
  1079. {
  1080. int isSuccess = TRUE;
  1081. char sql[512];
  1082. char zErrMsg[200];
  1083. int rows, cols;
  1084. char **resultData;
  1085. sprintf(sql, "select * from ocpp_period_energy where transactionId=%d;", transactionId);
  1086. /* Execute SQL statement */
  1087. if( sqlite3_get_table(db, sql, &resultData, &rows, &cols, (char **)&zErrMsg) != SQLITE_OK)
  1088. {
  1089. DEBUG_WARN("SQL error: %s\n", zErrMsg);
  1090. isSuccess = FALSE;
  1091. }
  1092. else
  1093. {
  1094. if((rows > 0) && (atoi(resultData[4]) > 0))
  1095. {
  1096. sprintf((char*)ShmOCPP16Data->DataTransfer[0].ResponseData, "%s", resultData[7]);
  1097. }
  1098. else
  1099. {
  1100. DEBUG_WARN("There is not match transaction data.\n");
  1101. isSuccess = FALSE;
  1102. }
  1103. }
  1104. return isSuccess;
  1105. }
  1106. 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)
  1107. {
  1108. int result = PASS;
  1109. char* errMsg = NULL;
  1110. char sqlStr[8192];
  1111. 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');",
  1112. txId, creditNo, deductResult, isDonateInvoice, amount, vemData, ROC, RRN, approvalNo, storeId);
  1113. if (sqlite3_exec(db, sqlStr, 0, 0, &errMsg) != SQLITE_OK)
  1114. {
  1115. result = FAIL;
  1116. DEBUG_WARN( "Insert local report_deduct_info error message: %s\n", errMsg);
  1117. }
  1118. sprintf(sqlStr, "delete from report_deduct_info where (idx < (select idx from report_deduct_info order by idx desc limit 1)-5000);");
  1119. if (sqlite3_exec(db, sqlStr, 0, 0, &errMsg) != SQLITE_OK)
  1120. {
  1121. result = FAIL;
  1122. DEBUG_WARN( "delete local report_deduct_info error message: %s\n", errMsg);
  1123. }
  1124. return result;
  1125. }
  1126. int OCPP_update_deduct_info(int txId, char *creditNo)
  1127. {
  1128. int result = PASS;
  1129. char* errMsg = NULL;
  1130. char sqlStr[8192];
  1131. sprintf(sqlStr, "update report_deduct_info set isUploaded='1' where txId='%d' and creditNo='%s';", txId, creditNo);
  1132. if (sqlite3_exec(db, sqlStr, 0, 0, &errMsg) != SQLITE_OK)
  1133. {
  1134. result = FAIL;
  1135. DEBUG_WARN( "Update local report_deduct_info error message: %s\n", errMsg);
  1136. }
  1137. return result;
  1138. }
  1139. int queryDeductCallBack(void *data, int columenCount, char **columnValue, char **columnName)
  1140. {
  1141. sprintf((char*)ShmOCPP16Data->DataTransfer[0].VendorId, "%s", ShmSysConfigAndInfo->SysConfig.chargePointVendor);
  1142. sprintf((char*)ShmOCPP16Data->DataTransfer[0].MessageId,"%s","ID_CreditDeductResult");
  1143. sprintf((char*)ShmOCPP16Data->DataTransfer[0].Data, "{\\\"txId\\\":%d,\\\"creditNo\\\":\\\"%s\\\",\\\"deductResult\\\":%s,\\\"isDonateInvoice\\\":%s,\\\"amount\\\":%s,\\\"approvalNo\\\":\\\"%s\\\"}",
  1144. atoi(columnValue[1]),
  1145. columnValue[2],
  1146. atoi(columnValue[3])==1?"true":"false",
  1147. atoi(columnValue[4])==1?"true":"false",
  1148. columnValue[5],
  1149. columnValue[9]);
  1150. ShmOCPP16Data->CsMsg.bits[0].DataTransferReq = 1;
  1151. return 0;
  1152. }
  1153. void OCPP_query_deduct_info()
  1154. {
  1155. int rc = 0;
  1156. char sql[100];
  1157. char zErrMsg[100];
  1158. sprintf(sql,"select * from report_deduct_info where isUploaded='0' order by idx limit 1");
  1159. /* Execute SQL statement */
  1160. rc = sqlite3_exec(db, sql, queryDeductCallBack, 0, (char **)&zErrMsg);
  1161. if( rc != SQLITE_OK )
  1162. {
  1163. DEBUG_INFO("SQL error: %s\n", zErrMsg);
  1164. }
  1165. }
  1166. void reportReaderStatus(int gun_index)
  1167. {
  1168. struct timeval tmnow;
  1169. struct tm *tm;
  1170. char buf[28];//, usec_buf[6];
  1171. gettimeofday(&tmnow, NULL);
  1172. time_t t;
  1173. t = time(NULL);
  1174. /*UTC time and date*/
  1175. tm = gmtime(&t);
  1176. strftime(buf,28,"%Y-%m-%dT%H:%M:%SZ", tm);
  1177. #if 0 // remove temporally
  1178. strftime(buf,30,"%Y-%m-%dT%H:%M:%S", tm);
  1179. strcat(buf,".");
  1180. sprintf(usec_buf,"%dZ",(int)tmnow.tv_usec);
  1181. strcat(buf,usec_buf);
  1182. #endif
  1183. sprintf((char*)ShmOCPP16Data->DataTransfer[gun_index].VendorId, "%s", ShmSysConfigAndInfo->SysConfig.chargePointVendor);
  1184. sprintf((char*)ShmOCPP16Data->DataTransfer[gun_index].MessageId,"%s","ID_ReaderStatus");
  1185. sprintf((char*)ShmOCPP16Data->DataTransfer[gun_index].Data, "{\\\"connectorId\\\":%d,\\\"readerStatus\\\":%d,\\\"timestamp\\\":\\\"%s\\\",\\\"SerialNo\\\":\\\"%s\\\",\\\"creditNo\\\":\\\"%s\\\",\\\"VEMData\\\":\\\"%s\\\"}",
  1186. (gun_index+1),
  1187. ShmOCPP16Data->TcciCustomData.ReaderStatus[gun_index].readerStatus,
  1188. buf,
  1189. ShmOCPP16Data->TcciCustomData.SerialNo[gun_index],
  1190. ShmOCPP16Data->TcciCustomData.ReaderStatus[gun_index].creditNo,
  1191. ShmOCPP16Data->TcciCustomData.VEMData[gun_index]);
  1192. ShmOCPP16Data->CsMsg.bits[gun_index].DataTransferReq = 1;
  1193. }
  1194. //==========================================
  1195. // Check time passed since today
  1196. //==========================================
  1197. long long DiffTimebWithNow(struct timeb ST)
  1198. {
  1199. //return milli-second
  1200. struct timeb ET;
  1201. long long StartTime,StopTime;
  1202. ftime(&ET);
  1203. StartTime=(long long)ST.time;
  1204. StopTime=(long long)ET.time;
  1205. return ((StopTime-StartTime)*1000) + (ET.millitm-ST.millitm);
  1206. }
  1207. int getTimePassSinceToday(uint8_t gun_index)
  1208. {
  1209. int result = -1;
  1210. static time_t lastTime[4];
  1211. time_t t;
  1212. struct tm *tmStartToday;
  1213. struct timeb tbStartToday;
  1214. t=time(NULL);
  1215. if(difftime(t, lastTime[gun_index])>0)
  1216. {
  1217. tmStartToday=localtime(&t);
  1218. tmStartToday->tm_hour = 0;
  1219. tmStartToday->tm_min = 0;
  1220. tmStartToday->tm_sec = 0;
  1221. tbStartToday.time = mktime(tmStartToday);
  1222. tbStartToday.millitm = 0;
  1223. result = DiffTimebWithNow(tbStartToday)/1000;
  1224. lastTime[gun_index] = t;
  1225. }
  1226. return result;
  1227. }
  1228. void getNowDatetime(uint8_t *data)
  1229. {
  1230. time_t t = time(NULL);
  1231. struct tm tm = *localtime(&t);
  1232. 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);
  1233. }
  1234. int syncDateTimeRTC(uint8_t *data)
  1235. {
  1236. struct ParsingResult
  1237. {
  1238. int result;
  1239. int scanedElement;
  1240. int year;
  1241. int month;
  1242. int mday;
  1243. int hour;
  1244. int min;
  1245. int sec;
  1246. int tz_hour;
  1247. int tz_min;
  1248. float minSec;
  1249. }result;
  1250. struct tm tmOrg;
  1251. struct tm *tmTarget;
  1252. struct timeb tbTarget;
  1253. char buf[128];
  1254. memset(&result, 0x00, sizeof(struct ParsingResult));
  1255. result.result = PASS;
  1256. if(strstr((char*)data, ".") != NULL)
  1257. {
  1258. // Original data with mini second
  1259. if(strstr((char*)data, "Z") != NULL)
  1260. {
  1261. // Original data with Z
  1262. result.scanedElement = sscanf((char*)data, "%d-%d-%dT%d:%d:%d.%fZ",
  1263. &result.year,
  1264. &result.month,
  1265. &result.mday,
  1266. &result.hour,
  1267. &result.min,
  1268. &result.sec,
  1269. &result.minSec);
  1270. }
  1271. else
  1272. {
  1273. // Original data without Z
  1274. result.scanedElement = sscanf((char*)data, "%d-%d-%dT%d:%d:%d.%f%d:%d",
  1275. &result.year,
  1276. &result.month,
  1277. &result.mday,
  1278. &result.hour,
  1279. &result.min,
  1280. &result.sec,
  1281. &result.minSec,
  1282. &result.tz_hour,
  1283. &result.tz_min);
  1284. }
  1285. }
  1286. else
  1287. {
  1288. // Original data without mini second
  1289. if(strstr((char*)data, "Z") != NULL)
  1290. {
  1291. // Original data with Z
  1292. result.scanedElement = sscanf((char*)data, "%d-%d-%dT%d:%d:%dZ",
  1293. &result.year,
  1294. &result.month,
  1295. &result.mday,
  1296. &result.hour,
  1297. &result.min,
  1298. &result.sec);
  1299. }
  1300. else
  1301. {
  1302. // Original data without Z
  1303. result.scanedElement = sscanf((char*)data, "%d-%d-%dT%d:%d:%d%d:%d",
  1304. &result.year,
  1305. &result.month,
  1306. &result.mday,
  1307. &result.hour,
  1308. &result.min,
  1309. &result.sec,
  1310. &result.tz_hour,
  1311. &result.tz_min);
  1312. }
  1313. }
  1314. tmOrg.tm_year = result.year - 1900;
  1315. tmOrg.tm_mon = result.month - 1;
  1316. tmOrg.tm_mday = result.mday;
  1317. tmOrg.tm_hour = result.hour;
  1318. tmOrg.tm_min = result.min;
  1319. tmOrg.tm_sec = result.sec;
  1320. tmOrg.tm_gmtoff = 0;
  1321. tbTarget.time = mktime(&tmOrg);
  1322. tbTarget.timezone = 0;
  1323. tbTarget.time -= (result.tz_hour*3600) + (result.tz_min*60*(result.tz_hour>=0?1:-1));
  1324. tmTarget = gmtime(&tbTarget.time);
  1325. 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);
  1326. //DEBUG_INFO(" org date time: %s\n", data);
  1327. //DEBUG_INFO("parse date time: %s\n", buf);
  1328. system(buf);
  1329. system("/sbin/hwclock -w --systohc");
  1330. if(result.scanedElement < 6)
  1331. result.result = FAIL;
  1332. return result.result;
  1333. }
  1334. //==========================================
  1335. // GetCompositeSchedule logic related function
  1336. //==========================================
  1337. int DiffTimebSec(struct timeb ST, struct timeb ET)
  1338. {
  1339. //return milli-second
  1340. unsigned int StartTime,StopTime;
  1341. StartTime=(unsigned int)ST.time;
  1342. StopTime=(unsigned int)ET.time;
  1343. return (StopTime-StartTime);
  1344. }
  1345. int DiffTimebWithNowSec(struct timeb ST)
  1346. {
  1347. //return milli-second
  1348. struct timeb ET;
  1349. unsigned int StartTime,StopTime;
  1350. ftime(&ET);
  1351. StartTime=(unsigned int)ST.time;
  1352. StopTime=(unsigned int)ET.time;
  1353. return (StopTime-StartTime);
  1354. }
  1355. int getStartStop(uint8_t *start, uint8_t *stop)
  1356. {
  1357. struct ParsingResult
  1358. {
  1359. int result;
  1360. int scanedElement;
  1361. int year;
  1362. int month;
  1363. int mday;
  1364. int hour;
  1365. int min;
  1366. int sec;
  1367. int tz_hour;
  1368. int tz_min;
  1369. float minSec;
  1370. };
  1371. struct ParsingResult parseStart;
  1372. struct ParsingResult parseStop;
  1373. int result = -1;
  1374. struct tm tmStart;
  1375. struct timeb tbStart;
  1376. struct tm tmStop;
  1377. struct timeb tbStop;
  1378. memset(&parseStart, 0x00, sizeof(struct ParsingResult));
  1379. memset(&parseStop, 0x00, sizeof(struct ParsingResult));
  1380. // Scan start & stop date time
  1381. if(strstr((char*)start, ".") != NULL)
  1382. {
  1383. // Original data with mini second
  1384. if(strstr((char*)start, "Z") != NULL)
  1385. {
  1386. // Original data with Z
  1387. parseStart.scanedElement = sscanf((char*)start, "%d-%d-%dT%d:%d:%d.%fZ",
  1388. &parseStart.year,
  1389. &parseStart.month,
  1390. &parseStart.mday,
  1391. &parseStart.hour,
  1392. &parseStart.min,
  1393. &parseStart.sec,
  1394. &parseStart.minSec);
  1395. }
  1396. else
  1397. {
  1398. // Original data without Z
  1399. parseStart.scanedElement = sscanf((char*)start, "%d-%d-%dT%d:%d:%d.%f%d:%d",
  1400. &parseStart.year,
  1401. &parseStart.month,
  1402. &parseStart.mday,
  1403. &parseStart.hour,
  1404. &parseStart.min,
  1405. &parseStart.sec,
  1406. &parseStart.minSec,
  1407. &parseStart.tz_hour,
  1408. &parseStart.tz_min);
  1409. }
  1410. }
  1411. else
  1412. {
  1413. // Original data without mini second
  1414. if(strstr((char*)start, "Z") != NULL)
  1415. {
  1416. // Original data with Z
  1417. parseStart.scanedElement = sscanf((char*)start, "%d-%d-%dT%d:%d:%dZ",
  1418. &parseStart.year,
  1419. &parseStart.month,
  1420. &parseStart.mday,
  1421. &parseStart.hour,
  1422. &parseStart.min,
  1423. &parseStart.sec);
  1424. }
  1425. else
  1426. {
  1427. // Original data without Z
  1428. parseStart.scanedElement = sscanf((char*)start, "%d-%d-%dT%d:%d:%d%d:%d",
  1429. &parseStart.year,
  1430. &parseStart.month,
  1431. &parseStart.mday,
  1432. &parseStart.hour,
  1433. &parseStart.min,
  1434. &parseStart.sec,
  1435. &parseStart.tz_hour,
  1436. &parseStart.tz_min);
  1437. }
  1438. }
  1439. if(strstr((char*)stop, ".") != NULL)
  1440. {
  1441. // Original data with mini second
  1442. if(strstr((char*)stop, "Z") != NULL)
  1443. {
  1444. // Original data with Z
  1445. parseStop.scanedElement = sscanf((char*)stop, "%d-%d-%dT%d:%d:%d.%fZ",
  1446. &parseStop.year,
  1447. &parseStop.month,
  1448. &parseStop.mday,
  1449. &parseStop.hour,
  1450. &parseStop.min,
  1451. &parseStop.sec,
  1452. &parseStop.minSec);
  1453. }
  1454. else
  1455. {
  1456. // Original data without Z
  1457. parseStop.scanedElement = sscanf((char*)stop, "%d-%d-%dT%d:%d:%d.%f%d:%d",
  1458. &parseStop.year,
  1459. &parseStop.month,
  1460. &parseStop.mday,
  1461. &parseStop.hour,
  1462. &parseStop.min,
  1463. &parseStop.sec,
  1464. &parseStop.minSec,
  1465. &parseStop.tz_hour,
  1466. &parseStop.tz_min);
  1467. }
  1468. }
  1469. else
  1470. {
  1471. // Original data without mini second
  1472. if(strstr((char*)stop, "Z") != NULL)
  1473. {
  1474. // Original data with Z
  1475. parseStop.scanedElement = sscanf((char*)stop, "%d-%d-%dT%d:%d:%dZ",
  1476. &parseStop.year,
  1477. &parseStop.month,
  1478. &parseStop.mday,
  1479. &parseStop.hour,
  1480. &parseStop.min,
  1481. &parseStop.sec);
  1482. }
  1483. else
  1484. {
  1485. // Original data without Z
  1486. parseStop.scanedElement = sscanf((char*)stop, "%d-%d-%dT%d:%d:%d%d:%d",
  1487. &parseStop.year,
  1488. &parseStop.month,
  1489. &parseStop.mday,
  1490. &parseStop.hour,
  1491. &parseStop.min,
  1492. &parseStop.sec,
  1493. &parseStop.tz_hour,
  1494. &parseStop.tz_min);
  1495. }
  1496. }
  1497. // Calculate date time difference
  1498. if((parseStart.scanedElement >=6) &&
  1499. (parseStop.scanedElement >=6))
  1500. {
  1501. //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);
  1502. //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);
  1503. tmStart.tm_year = parseStart.year - 1900;
  1504. tmStart.tm_mon = parseStart.month - 1;
  1505. tmStart.tm_mday = parseStart.mday;
  1506. tmStart.tm_hour = parseStart.hour;
  1507. tmStart.tm_min = parseStart.min;
  1508. tmStart.tm_sec = parseStart.sec;
  1509. tmStart.tm_gmtoff = 0;
  1510. tbStart.time = mktime(&tmStart);
  1511. tbStart.timezone = 0;
  1512. tbStart.time -= (parseStart.tz_hour*3600) + (parseStart.tz_min*60*(parseStart.tz_hour>=0?1:-1));
  1513. tmStop.tm_year = parseStop.year - 1900;
  1514. tmStop.tm_mon = parseStop.month - 1;
  1515. tmStop.tm_mday = parseStop.mday;
  1516. tmStop.tm_hour = parseStop.hour;
  1517. tmStop.tm_min = parseStop.min;
  1518. tmStop.tm_sec = parseStop.sec;
  1519. tmStop.tm_gmtoff = 0;
  1520. tbStop.time = mktime(&tmStop);
  1521. tbStop.timezone = 0;
  1522. tbStop.time -= (parseStop.tz_hour*3600) + (parseStop.tz_min*60*(parseStop.tz_hour>=0?1:-1));
  1523. result = DiffTimebSec(tbStart, tbStop);
  1524. //DEBUG_INFO("getStartStop(): %d\n", result);
  1525. }
  1526. else
  1527. {
  1528. DEBUG_WARN("Start or stop date parsing error.\r\n");
  1529. }
  1530. return result;
  1531. }
  1532. int isOvertNow(uint8_t *start)
  1533. {
  1534. int result = NO;
  1535. struct ParsingResult
  1536. {
  1537. int result;
  1538. int scanedElement;
  1539. int year;
  1540. int month;
  1541. int mday;
  1542. int hour;
  1543. int min;
  1544. int sec;
  1545. int tz_hour;
  1546. int tz_min;
  1547. float minSec;
  1548. }parsingResult;
  1549. struct tm tmStart;
  1550. struct timeb tbStart;
  1551. memset(&parsingResult, 0x00, sizeof(struct ParsingResult));
  1552. if(strstr((char*)start, ".") != NULL)
  1553. {
  1554. // Original data with mini second
  1555. if(strstr((char*)start, "Z") != NULL)
  1556. {
  1557. // Original data with Z
  1558. parsingResult.scanedElement = sscanf((char*)start, "%d-%d-%dT%d:%d:%d.%fZ",
  1559. &parsingResult.year,
  1560. &parsingResult.month,
  1561. &parsingResult.mday,
  1562. &parsingResult.hour,
  1563. &parsingResult.min,
  1564. &parsingResult.sec,
  1565. &parsingResult.minSec);
  1566. }
  1567. else
  1568. {
  1569. // Original data without Z
  1570. parsingResult.scanedElement = sscanf((char*)start, "%d-%d-%dT%d:%d:%d.%f%d:%d",
  1571. &parsingResult.year,
  1572. &parsingResult.month,
  1573. &parsingResult.mday,
  1574. &parsingResult.hour,
  1575. &parsingResult.min,
  1576. &parsingResult.sec,
  1577. &parsingResult.minSec,
  1578. &parsingResult.tz_hour,
  1579. &parsingResult.tz_min);
  1580. }
  1581. }
  1582. else
  1583. {
  1584. // Original data without mini second
  1585. if(strstr((char*)start, "Z") != NULL)
  1586. {
  1587. // Original data with Z
  1588. parsingResult.scanedElement = sscanf((char*)start, "%d-%d-%dT%d:%d:%dZ",
  1589. &parsingResult.year,
  1590. &parsingResult.month,
  1591. &parsingResult.mday,
  1592. &parsingResult.hour,
  1593. &parsingResult.min,
  1594. &parsingResult.sec);
  1595. }
  1596. else
  1597. {
  1598. // Original data without Z
  1599. parsingResult.scanedElement = sscanf((char*)start, "%d-%d-%dT%d:%d:%d%d:%d",
  1600. &parsingResult.year,
  1601. &parsingResult.month,
  1602. &parsingResult.mday,
  1603. &parsingResult.hour,
  1604. &parsingResult.min,
  1605. &parsingResult.sec,
  1606. &parsingResult.tz_hour,
  1607. &parsingResult.tz_min);
  1608. }
  1609. }
  1610. if(parsingResult.scanedElement >= 6)
  1611. {
  1612. tmStart.tm_year = parsingResult.year - 1900;
  1613. tmStart.tm_mon = parsingResult.month - 1;
  1614. tmStart.tm_mday = parsingResult.mday;
  1615. tmStart.tm_hour = parsingResult.hour;
  1616. tmStart.tm_min = parsingResult.min;
  1617. tmStart.tm_sec = parsingResult.sec;
  1618. tmStart.tm_gmtoff = 0;
  1619. tbStart.time = mktime(&tmStart);
  1620. tbStart.timezone = 0;
  1621. tbStart.millitm = 0;
  1622. tbStart.time -= (parsingResult.tz_hour*3600) + (parsingResult.tz_min*60*(parsingResult.tz_hour>=0?1:-1));
  1623. if(DiffTimebWithNowSec(tbStart) <= 0)
  1624. result = NO;
  1625. else
  1626. result = YES;
  1627. }
  1628. else
  1629. {
  1630. DEBUG_WARN("Start date parsing error.\n");
  1631. }
  1632. return result;
  1633. }
  1634. int getStartSinceRecurring(uint8_t *start, uint8_t *stop, uint8_t isDaily)
  1635. {
  1636. struct ParsingResult
  1637. {
  1638. int result;
  1639. int scanedElement;
  1640. int year;
  1641. int month;
  1642. int mday;
  1643. int hour;
  1644. int min;
  1645. int sec;
  1646. int tz_hour;
  1647. int tz_min;
  1648. float minSec;
  1649. };
  1650. struct ParsingResult parseStart;
  1651. struct ParsingResult parseStop;
  1652. int result = -1;
  1653. struct tm tmStart;
  1654. struct timeb tbStart;
  1655. struct tm tmStop;
  1656. struct timeb tbStop;
  1657. memset(&parseStart, 0x00, sizeof(struct ParsingResult));
  1658. memset(&parseStop, 0x00, sizeof(struct ParsingResult));
  1659. // Scan start & stop date time
  1660. if(strstr((char*)start, ".") != NULL)
  1661. {
  1662. // Original data with mini second
  1663. if(strstr((char*)start, "Z") != NULL)
  1664. {
  1665. // Original data with Z
  1666. parseStart.scanedElement = sscanf((char*)start, "%d-%d-%dT%d:%d:%d.%fZ",
  1667. &parseStart.year,
  1668. &parseStart.month,
  1669. &parseStart.mday,
  1670. &parseStart.hour,
  1671. &parseStart.min,
  1672. &parseStart.sec,
  1673. &parseStart.minSec);
  1674. }
  1675. else
  1676. {
  1677. // Original data without Z
  1678. parseStart.scanedElement = sscanf((char*)start, "%d-%d-%dT%d:%d:%d.%f%d:%d",
  1679. &parseStart.year,
  1680. &parseStart.month,
  1681. &parseStart.mday,
  1682. &parseStart.hour,
  1683. &parseStart.min,
  1684. &parseStart.sec,
  1685. &parseStart.minSec,
  1686. &parseStart.tz_hour,
  1687. &parseStart.tz_min);
  1688. }
  1689. }
  1690. else
  1691. {
  1692. // Original data without mini second
  1693. if(strstr((char*)start, "Z") != NULL)
  1694. {
  1695. // Original data with Z
  1696. parseStart.scanedElement = sscanf((char*)start, "%d-%d-%dT%d:%d:%dZ",
  1697. &parseStart.year,
  1698. &parseStart.month,
  1699. &parseStart.mday,
  1700. &parseStart.hour,
  1701. &parseStart.min,
  1702. &parseStart.sec);
  1703. }
  1704. else
  1705. {
  1706. // Original data without Z
  1707. parseStart.scanedElement = sscanf((char*)start, "%d-%d-%dT%d:%d:%d%d:%d",
  1708. &parseStart.year,
  1709. &parseStart.month,
  1710. &parseStart.mday,
  1711. &parseStart.hour,
  1712. &parseStart.min,
  1713. &parseStart.sec,
  1714. &parseStart.tz_hour,
  1715. &parseStart.tz_min);
  1716. }
  1717. }
  1718. if(strstr((char*)stop, ".") != NULL)
  1719. {
  1720. // Original data with mini second
  1721. if(strstr((char*)stop, "Z") != NULL)
  1722. {
  1723. // Original data with Z
  1724. parseStop.scanedElement = sscanf((char*)stop, "%d-%d-%dT%d:%d:%d.%fZ",
  1725. &parseStop.year,
  1726. &parseStop.month,
  1727. &parseStop.mday,
  1728. &parseStop.hour,
  1729. &parseStop.min,
  1730. &parseStop.sec,
  1731. &parseStop.minSec);
  1732. }
  1733. else
  1734. {
  1735. // Original data without Z
  1736. parseStop.scanedElement = sscanf((char*)stop, "%d-%d-%dT%d:%d:%d.%f%d:%d",
  1737. &parseStop.year,
  1738. &parseStop.month,
  1739. &parseStop.mday,
  1740. &parseStop.hour,
  1741. &parseStop.min,
  1742. &parseStop.sec,
  1743. &parseStop.minSec,
  1744. &parseStop.tz_hour,
  1745. &parseStop.tz_min);
  1746. }
  1747. }
  1748. else
  1749. {
  1750. // Original data without mini second
  1751. if(strstr((char*)stop, "Z") != NULL)
  1752. {
  1753. // Original data with Z
  1754. parseStop.scanedElement = sscanf((char*)stop, "%d-%d-%dT%d:%d:%dZ",
  1755. &parseStop.year,
  1756. &parseStop.month,
  1757. &parseStop.mday,
  1758. &parseStop.hour,
  1759. &parseStop.min,
  1760. &parseStop.sec);
  1761. }
  1762. else
  1763. {
  1764. // Original data without Z
  1765. parseStop.scanedElement = sscanf((char*)stop, "%d-%d-%dT%d:%d:%d%d:%d",
  1766. &parseStop.year,
  1767. &parseStop.month,
  1768. &parseStop.mday,
  1769. &parseStop.hour,
  1770. &parseStop.min,
  1771. &parseStop.sec,
  1772. &parseStop.tz_hour,
  1773. &parseStop.tz_min);
  1774. }
  1775. }
  1776. // Calculate date time difference
  1777. if((parseStart.scanedElement >=6) &&
  1778. (parseStop.scanedElement >=6))
  1779. {
  1780. //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);
  1781. //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);
  1782. tmStart.tm_year = parseStart.year - 1900;
  1783. tmStart.tm_mon = parseStart.month - 1;
  1784. tmStart.tm_mday = parseStart.mday;
  1785. tmStart.tm_hour = parseStart.hour;
  1786. tmStart.tm_min = parseStart.min;
  1787. tmStart.tm_sec = parseStart.sec;
  1788. tmStart.tm_gmtoff = 0;
  1789. tbStart.time = mktime(&tmStart);
  1790. tbStart.timezone = 0;
  1791. tbStart.time -= (parseStart.tz_hour*3600) + (parseStart.tz_min*60*(parseStart.tz_hour>=0?1:-1));
  1792. tmStop.tm_year = parseStop.year - 1900;
  1793. tmStop.tm_mon = parseStop.month - 1;
  1794. tmStop.tm_mday = parseStop.mday;
  1795. tmStop.tm_hour = parseStop.hour;
  1796. tmStop.tm_min = parseStop.min;
  1797. tmStop.tm_sec = parseStop.sec;
  1798. tmStop.tm_gmtoff = 0;
  1799. tbStop.time = mktime(&tmStop);
  1800. tbStop.timezone = 0;
  1801. tbStop.time -= (parseStop.tz_hour*3600) + (parseStop.tz_min*60*(parseStop.tz_hour>=0?1:-1));
  1802. result = DiffTimebSec(tbStart, tbStop)%(isDaily?86400:604800);
  1803. //DEBUG_INFO("getStartStop(): %d\n", result);
  1804. }
  1805. else
  1806. {
  1807. DEBUG_WARN("Start or stop date parsing error.\r\n");
  1808. }
  1809. return result;
  1810. }
  1811. void checkChargePointMaxProfile(uint32_t durationReq, struct StructChargingProfile *targetCompositeProfile, uint8_t isUnitA)
  1812. {
  1813. FILE *fp;
  1814. char profileFileName[128];
  1815. char *line = NULL;
  1816. size_t len = 0;
  1817. time_t CurrentTime;
  1818. struct tm *tmComposite;
  1819. struct StructChargingProfile maxProfile;
  1820. struct StructChargingProfile compositeProfile;
  1821. uint8_t limitMax=0;
  1822. int compositePeriodIdx = 0;
  1823. //uint8_t isDurationNull = FALSE;
  1824. CurrentTime = time(NULL);
  1825. tmComposite=localtime(&CurrentTime);
  1826. 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);
  1827. if(isUnitA)
  1828. sprintf((char*)compositeProfile.ChargingSchedule.ChargingRateUnit, "A");
  1829. else
  1830. sprintf((char*)compositeProfile.ChargingSchedule.ChargingRateUnit, "W");
  1831. compositeProfile.ChargingSchedule.Duration = durationReq;
  1832. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(compositeProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  1833. {
  1834. compositeProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = -1;
  1835. compositeProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit = -1;
  1836. compositeProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases = 3;
  1837. }
  1838. compositeProfile.ChargingProfileId = 0;
  1839. compositeProfile.StackLevel = 99 ;
  1840. sprintf((char*)compositeProfile.ChargingProfileKind ,"Absolute");
  1841. maxProfile.ChargingProfileId = -1;
  1842. maxProfile.ChargingSchedule.Duration = -1;
  1843. system("rm -f /tmp/*.json");
  1844. system("cp /Storage/OCPP/*.json /tmp 2>/dev/null");
  1845. // Search max profile
  1846. sprintf(profileFileName, "/tmp/ChargePointMaxProfile.json");
  1847. if((access(profileFileName, F_OK))!=-1)
  1848. {
  1849. fp = fopen(profileFileName, "r");
  1850. while(getline(&line, &len, fp) != -1)
  1851. {
  1852. json_object *obj = NULL;
  1853. obj = json_tokener_parse(line);
  1854. if(is_error(obj))
  1855. {
  1856. DEBUG_ERROR("Parse MaxProfile from file error.\n");
  1857. }
  1858. else
  1859. {
  1860. if((json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileId")) != maxProfile.ChargingProfileId) &&
  1861. (json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "stackLevel")) >= maxProfile.StackLevel)
  1862. )
  1863. {
  1864. if((json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom") != NULL) &&
  1865. (json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo") != NULL)
  1866. )
  1867. {
  1868. struct tm tmFrom, tmTo;
  1869. struct timeb tbFrom, tbTo;
  1870. 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) &&
  1871. (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))
  1872. {
  1873. tmFrom.tm_year -= 1900;
  1874. tmFrom.tm_mon -= 1;
  1875. tbFrom.time = mktime(&tmFrom);
  1876. tmTo.tm_year -= 1900;
  1877. tmTo.tm_mon -= 1;
  1878. tbTo.time = mktime(&tmTo);
  1879. if((DiffTimebWithNowSec(tbFrom)>=0) && (DiffTimebWithNowSec(tbTo)<=0))
  1880. {
  1881. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  1882. {
  1883. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = -1;
  1884. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit = -1;
  1885. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases = 3;
  1886. }
  1887. if(maxProfile.ChargingProfileId == -1)
  1888. DEBUG_INFO("MaxProfile found.\n");
  1889. else
  1890. DEBUG_INFO("MaxProfile updated.\n");
  1891. // Required item
  1892. maxProfile.ChargingProfileId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileId"));
  1893. maxProfile.StackLevel = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "stackLevel"));
  1894. sprintf((char*)maxProfile.ChargingProfileKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileKind")));
  1895. if(isUnitA)
  1896. {
  1897. sprintf((char*)maxProfile.ChargingSchedule.ChargingRateUnit, "A");
  1898. 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++)
  1899. {
  1900. 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"));
  1901. 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?
  1902. 3:
  1903. 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")));
  1904. 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")));
  1905. }
  1906. }
  1907. else
  1908. {
  1909. sprintf((char*)maxProfile.ChargingSchedule.ChargingRateUnit, "W");
  1910. 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++)
  1911. {
  1912. 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"));
  1913. 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?
  1914. 3:
  1915. 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")));
  1916. 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));
  1917. }
  1918. }
  1919. // Optional item
  1920. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom") != NULL)
  1921. {
  1922. sprintf((char*)maxProfile.ValidFrom, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom")));
  1923. }
  1924. else
  1925. {
  1926. sprintf((char*)maxProfile.ValidFrom, " ");
  1927. }
  1928. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo") != NULL)
  1929. {
  1930. sprintf((char*)maxProfile.ValidTo, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo")));
  1931. }
  1932. else
  1933. {
  1934. sprintf((char*)maxProfile.ValidTo, " ");
  1935. }
  1936. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "recurrencyKind") != NULL)
  1937. {
  1938. sprintf((char*)maxProfile.RecurrencyKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "recurrencyKind")));
  1939. }
  1940. else
  1941. {
  1942. sprintf((char*)maxProfile.RecurrencyKind, " ");
  1943. }
  1944. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId") != NULL)
  1945. {
  1946. maxProfile.TransactionId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId"));
  1947. }
  1948. else
  1949. {
  1950. maxProfile.TransactionId = -1;
  1951. }
  1952. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration") != NULL)
  1953. {
  1954. maxProfile.ChargingSchedule.Duration = json_object_get_int(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration"));
  1955. }
  1956. else
  1957. {
  1958. maxProfile.ChargingSchedule.Duration = 86400;
  1959. //isDurationNull = TRUE;
  1960. }
  1961. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "startSchedule") != NULL)
  1962. {
  1963. 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")));
  1964. }
  1965. else
  1966. {
  1967. sprintf((char*)maxProfile.ChargingSchedule.StartSchedule, "%s", compositeProfile.ChargingSchedule.StartSchedule);
  1968. }
  1969. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate") != NULL)
  1970. {
  1971. maxProfile.ChargingSchedule.MinChargingRate = json_object_get_double(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate"));
  1972. }
  1973. else
  1974. {
  1975. maxProfile.ChargingSchedule.MinChargingRate = -1;
  1976. }
  1977. }
  1978. }
  1979. }
  1980. else
  1981. {
  1982. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  1983. {
  1984. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = -1;
  1985. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit = -1;
  1986. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases = 3;
  1987. }
  1988. if(maxProfile.ChargingProfileId == -1)
  1989. DEBUG_INFO("MaxProfile found.\n");
  1990. else
  1991. DEBUG_INFO("MaxProfile updated.\n");
  1992. // Required item
  1993. maxProfile.ChargingProfileId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileId"));
  1994. maxProfile.StackLevel = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "stackLevel"));
  1995. sprintf((char*)maxProfile.ChargingProfileKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileKind")));
  1996. if(isUnitA)
  1997. {
  1998. sprintf((char*)maxProfile.ChargingSchedule.ChargingRateUnit, "A");
  1999. 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++)
  2000. {
  2001. 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"));
  2002. 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?
  2003. 3:
  2004. 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")));
  2005. 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")));
  2006. }
  2007. }
  2008. else
  2009. {
  2010. sprintf((char*)maxProfile.ChargingSchedule.ChargingRateUnit, "W");
  2011. 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++)
  2012. {
  2013. 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"));
  2014. 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?
  2015. 3:
  2016. 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")));
  2017. 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));
  2018. }
  2019. }
  2020. // Optional item
  2021. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom") != NULL)
  2022. {
  2023. sprintf((char*)maxProfile.ValidFrom, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom")));
  2024. }
  2025. else
  2026. {
  2027. sprintf((char*)maxProfile.ValidFrom, " ");
  2028. }
  2029. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo") != NULL)
  2030. {
  2031. sprintf((char*)maxProfile.ValidTo, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo")));
  2032. }
  2033. else
  2034. {
  2035. sprintf((char*)maxProfile.ValidTo, " ");
  2036. }
  2037. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "recurrencyKind") != NULL)
  2038. {
  2039. sprintf((char*)maxProfile.RecurrencyKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "recurrencyKind")));
  2040. }
  2041. else
  2042. {
  2043. sprintf((char*)maxProfile.RecurrencyKind, " ");
  2044. }
  2045. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId") != NULL)
  2046. {
  2047. maxProfile.TransactionId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId"));
  2048. }
  2049. else
  2050. {
  2051. maxProfile.TransactionId = -1;
  2052. }
  2053. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration") != NULL)
  2054. {
  2055. maxProfile.ChargingSchedule.Duration = json_object_get_int(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration"));
  2056. }
  2057. else
  2058. {
  2059. maxProfile.ChargingSchedule.Duration = 86400;
  2060. //isDurationNull = TRUE;
  2061. }
  2062. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "startSchedule") != NULL)
  2063. {
  2064. 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")));
  2065. }
  2066. else
  2067. {
  2068. sprintf((char*)maxProfile.ChargingSchedule.StartSchedule, "%s", compositeProfile.ChargingSchedule.StartSchedule);
  2069. }
  2070. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate") != NULL)
  2071. {
  2072. maxProfile.ChargingSchedule.MinChargingRate = json_object_get_double(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate"));
  2073. }
  2074. else
  2075. {
  2076. maxProfile.ChargingSchedule.MinChargingRate = -1;
  2077. }
  2078. }
  2079. }
  2080. }
  2081. json_object_put(obj);
  2082. }
  2083. fclose(fp);
  2084. /*
  2085. if(maxProfile.ChargingProfileId !=-1)
  2086. {
  2087. DEBUG_INFO("Profile ID: %d\n", maxProfile.ChargingProfileId);
  2088. DEBUG_INFO("Profile stackLevel: %d\n", maxProfile.StackLevel);
  2089. DEBUG_INFO("Profile TransactionId: %d\n", maxProfile.TransactionId);
  2090. DEBUG_INFO("Profile valid from: %s\n", maxProfile.ValidFrom);
  2091. DEBUG_INFO("Profile valid to: %s\n", maxProfile.ValidTo);
  2092. DEBUG_INFO("Profile ChargingProfileKind: %s\n", maxProfile.ChargingProfileKind);
  2093. DEBUG_INFO("Profile recurrencyKind: %s\n", maxProfile.RecurrencyKind);
  2094. DEBUG_INFO("Profile start schedule: %s\n", maxProfile.ChargingSchedule.StartSchedule);
  2095. DEBUG_INFO("Profile schedule duration: %d\n", maxProfile.ChargingSchedule.Duration);
  2096. DEBUG_INFO("Profile charging rate unit: %s\n", maxProfile.ChargingSchedule.ChargingRateUnit);
  2097. DEBUG_INFO("Profile charging min rate: %f\n", maxProfile.ChargingSchedule.MinChargingRate);
  2098. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  2099. {
  2100. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod >= 0)
  2101. {
  2102. DEBUG_INFO("Period-%02d startPeriod: %d\n", idxPeriod, maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod);
  2103. DEBUG_INFO("Period-%02d limit: %f\n", idxPeriod, maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit);
  2104. DEBUG_INFO("Period-%02d NumberPhases: %d\n", idxPeriod, maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases);
  2105. }
  2106. }
  2107. }
  2108. else
  2109. DEBUG_INFO("MaxProfile not found.\n");
  2110. DEBUG_INFO("------------------------------------\n");*/
  2111. }
  2112. if(maxProfile.ChargingProfileId != -1)
  2113. {
  2114. if(strstr((char*)maxProfile.ChargingProfileKind, "Absolute") != NULL)
  2115. {
  2116. if((maxProfile.ChargingSchedule.Duration != -1)/* && (isDurationNull)*/)
  2117. {
  2118. maxProfile.ChargingSchedule.Duration = ((maxProfile.ChargingSchedule.Duration-getStartStop(maxProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule))<0?
  2119. 0:
  2120. (maxProfile.ChargingSchedule.Duration-getStartStop(maxProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule)));
  2121. }
  2122. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  2123. {
  2124. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  2125. {
  2126. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = ((maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartStop(maxProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule))<0?
  2127. 0:
  2128. (maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartStop(maxProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule)));
  2129. if(idxPeriod > 0)
  2130. {
  2131. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
  2132. {
  2133. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit = maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit;
  2134. }
  2135. }
  2136. }
  2137. }
  2138. }
  2139. else if(strstr((char*)maxProfile.ChargingProfileKind, "Relative") != NULL)
  2140. {
  2141. if(maxProfile.ChargingSchedule.Duration != -1)
  2142. {
  2143. maxProfile.ChargingSchedule.Duration = maxProfile.ChargingSchedule.Duration;
  2144. }
  2145. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  2146. {
  2147. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  2148. {
  2149. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod;
  2150. if(idxPeriod > 0)
  2151. {
  2152. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
  2153. {
  2154. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit = maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit;
  2155. }
  2156. }
  2157. }
  2158. }
  2159. }
  2160. else
  2161. {
  2162. if(strstr((char*)maxProfile.RecurrencyKind, "Weekly") != NULL)
  2163. {
  2164. if(maxProfile.ChargingSchedule.Duration != -1)
  2165. {
  2166. maxProfile.ChargingSchedule.Duration = ((maxProfile.ChargingSchedule.Duration-getStartSinceRecurring(maxProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule, FALSE))<0?
  2167. 0:
  2168. (maxProfile.ChargingSchedule.Duration-getStartSinceRecurring(maxProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule, FALSE)));
  2169. }
  2170. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  2171. {
  2172. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  2173. {
  2174. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = ((maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceRecurring(maxProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule, FALSE))<0?
  2175. 0:
  2176. (maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceRecurring(maxProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule, FALSE)));
  2177. if(idxPeriod > 0)
  2178. {
  2179. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
  2180. {
  2181. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit = maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit;
  2182. }
  2183. }
  2184. }
  2185. }
  2186. }
  2187. else
  2188. {
  2189. if(maxProfile.ChargingSchedule.Duration != -1)
  2190. {
  2191. maxProfile.ChargingSchedule.Duration = ((maxProfile.ChargingSchedule.Duration-getStartSinceRecurring(maxProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule, TRUE))<0?
  2192. 0:
  2193. (maxProfile.ChargingSchedule.Duration-getStartSinceRecurring(maxProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule, TRUE)));
  2194. }
  2195. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  2196. {
  2197. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  2198. {
  2199. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = ((maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceRecurring(maxProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule, TRUE))<0?
  2200. 0:
  2201. (maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceRecurring(maxProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule, TRUE)));
  2202. if(idxPeriod > 0)
  2203. {
  2204. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
  2205. {
  2206. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit = maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit;
  2207. }
  2208. }
  2209. }
  2210. }
  2211. }
  2212. }
  2213. /*
  2214. DEBUG_INFO("MaxProfile after align.\n");
  2215. DEBUG_INFO("Profile ID: %d\n", maxProfile.ChargingProfileId);
  2216. DEBUG_INFO("Profile stackLevel: %d\n", maxProfile.StackLevel);
  2217. DEBUG_INFO("Profile TransactionId: %d\n", maxProfile.TransactionId);
  2218. DEBUG_INFO("Profile valid from: %s\n", maxProfile.ValidFrom);
  2219. DEBUG_INFO("Profile valid to: %s\n", maxProfile.ValidTo);
  2220. DEBUG_INFO("Profile ChargingProfileKind: %s\n", maxProfile.ChargingProfileKind);
  2221. DEBUG_INFO("Profile RecurrencyKind: %s\n", maxProfile.RecurrencyKind);
  2222. DEBUG_INFO("Profile start schedule: %s\n", compositeProfile->ChargingSchedule.StartSchedule);
  2223. DEBUG_INFO("Profile schedule duration: %d\n", maxProfile.ChargingSchedule.Duration);
  2224. DEBUG_INFO("Profile charging rate unit: %s\n", maxProfile.ChargingSchedule.ChargingRateUnit);
  2225. DEBUG_INFO("Profile charging min rate: %f\n", maxProfile.ChargingSchedule.MinChargingRate);
  2226. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  2227. {
  2228. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod >= 0)
  2229. {
  2230. DEBUG_INFO("Period-%02d startPeriod: %d\n", idxPeriod, maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod);
  2231. DEBUG_INFO("Period-%02d limit: %f\n", idxPeriod, maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit);
  2232. DEBUG_INFO("Period-%02d NumberPhases: %d\n", idxPeriod, maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases);
  2233. }
  2234. }
  2235. DEBUG_INFO("------------------------------------\n");*/
  2236. }
  2237. // Find each profile period quantity
  2238. for(int idx=0;idx<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idx++)
  2239. {
  2240. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idx].Limit != -1)
  2241. limitMax = idx+1;
  2242. }
  2243. if(maxProfile.ChargingProfileId != -1)
  2244. {
  2245. for(int idxMaxPeriod=0;idxMaxPeriod<limitMax;idxMaxPeriod++)
  2246. {
  2247. if((maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].Limit != -1) &&
  2248. (maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].StartPeriod < durationReq) &&
  2249. (maxProfile.ChargingSchedule.Duration > 0))
  2250. {
  2251. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].StartPeriod != compositeProfile.ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].StartPeriod)
  2252. {
  2253. memcpy(&compositeProfile.ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx], &maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod],sizeof(struct StructChargingSchedulePeriod));
  2254. compositePeriodIdx++;
  2255. }
  2256. else
  2257. {
  2258. memcpy(&compositeProfile.ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)], &maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod],sizeof(struct StructChargingSchedulePeriod));
  2259. }
  2260. }
  2261. }
  2262. }
  2263. DEBUG_INFO("ChargePointMaxProfile ready.\n");
  2264. DEBUG_INFO("Schedule start: %s\n", compositeProfile.ChargingSchedule.StartSchedule);
  2265. DEBUG_INFO("Schedule duration: %d\n", compositeProfile.ChargingSchedule.Duration);
  2266. DEBUG_INFO("Rate unit: %s\n", compositeProfile.ChargingSchedule.ChargingRateUnit);
  2267. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(compositeProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  2268. {
  2269. if(compositeProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod >= 0)
  2270. {
  2271. compositeProfile.ChargingProfileId = 1;
  2272. DEBUG_INFO("Period-%02d startPeriod: %d\n", idxPeriod, compositeProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod);
  2273. DEBUG_INFO("Period-%02d limit: %f\n", idxPeriod, compositeProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit);
  2274. DEBUG_INFO("Period-%02d NumberPhases: %d\n", idxPeriod, compositeProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases);
  2275. }
  2276. if(compositeProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit == -1)
  2277. compositeProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit =0;
  2278. if(compositeProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod == -1)
  2279. compositeProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod =0;
  2280. }
  2281. memcpy(targetCompositeProfile, &compositeProfile, sizeof(struct StructChargingProfile));
  2282. if(line)
  2283. free(line);
  2284. }
  2285. void checkCompositeSchedule(uint8_t connectorId, uint32_t durationReq, struct StructChargingProfile *targetCompositeProfile, uint8_t isUnitA)
  2286. {
  2287. FILE *fp;
  2288. char profileFileName[128];
  2289. char *line = NULL;
  2290. size_t len = 0;
  2291. time_t CurrentTime;
  2292. struct tm *tmComposite;
  2293. struct StructChargingProfile maxProfile;
  2294. struct StructChargingProfile defaultTxProfile;
  2295. struct StructChargingProfile txProfile;
  2296. struct StructChargingProfile compositeProfile;
  2297. struct StructChargingSchedulePeriod tmpPeriod;
  2298. uint8_t limitMax=0;
  2299. uint8_t limitDef=0;
  2300. uint8_t limitTx=0;
  2301. int compositePeriodIdx = 0;
  2302. CurrentTime = time(NULL);
  2303. tmComposite=localtime(&CurrentTime);
  2304. 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);
  2305. if(isUnitA)
  2306. sprintf((char*)compositeProfile.ChargingSchedule.ChargingRateUnit, "A");
  2307. else
  2308. sprintf((char*)compositeProfile.ChargingSchedule.ChargingRateUnit, "W");
  2309. compositeProfile.ChargingSchedule.Duration = durationReq;
  2310. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(compositeProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  2311. {
  2312. compositeProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = -1;
  2313. compositeProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit = -1;
  2314. compositeProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases = 3;
  2315. }
  2316. compositeProfile.ChargingProfileId = 0;
  2317. compositeProfile.StackLevel = 99 ;
  2318. sprintf((char*)compositeProfile.ChargingProfileKind ,"Absolute");
  2319. maxProfile.ChargingProfileId = -1;
  2320. defaultTxProfile.ChargingProfileId = -1;
  2321. txProfile.ChargingProfileId = -1;
  2322. maxProfile.ChargingSchedule.Duration = -1;
  2323. defaultTxProfile.ChargingSchedule.Duration = -1;
  2324. txProfile.ChargingSchedule.Duration = -1;
  2325. system("rm -f /tmp/*.json");
  2326. system("cp /Storage/OCPP/*.json /tmp 2>/dev/null");
  2327. /*
  2328. * Search valid charging profile
  2329. */
  2330. //DEBUG_INFO("====================================\n");
  2331. // Search tx profile
  2332. sprintf(profileFileName, "/tmp/TxProfile_%d.json", connectorId);
  2333. if((access(profileFileName, F_OK))!=-1)
  2334. {
  2335. fp = fopen(profileFileName, "r");
  2336. while(getline(&line, &len, fp) != -1)
  2337. {
  2338. json_object *obj = NULL;
  2339. obj = json_tokener_parse(line);
  2340. if(is_error(obj))
  2341. {
  2342. DEBUG_ERROR("Parse txProfile from file error.\n");
  2343. }
  2344. else
  2345. {
  2346. if((json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileId")) != txProfile.ChargingProfileId) &&
  2347. (json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "stackLevel")) >= txProfile.StackLevel)
  2348. )
  2349. {
  2350. if((json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom") != NULL) &&
  2351. (json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo") != NULL)
  2352. )
  2353. {
  2354. struct tm tmFrom, tmTo;
  2355. struct timeb tbFrom, tbTo;
  2356. 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) &&
  2357. (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))
  2358. {
  2359. tmFrom.tm_year -= 1900;
  2360. tmFrom.tm_mon -= 1;
  2361. tbFrom.time = mktime(&tmFrom);
  2362. tmTo.tm_year -= 1900;
  2363. tmTo.tm_mon -= 1;
  2364. tbTo.time = mktime(&tmTo);
  2365. if((DiffTimebWithNowSec(tbFrom)>=0) && (DiffTimebWithNowSec(tbTo)<=0))
  2366. {
  2367. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(txProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  2368. {
  2369. txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = -1;
  2370. txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit = -1;
  2371. txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases = 3;
  2372. }
  2373. if(txProfile.ChargingProfileId == -1)
  2374. DEBUG_INFO("TxProfile found.\n");
  2375. else
  2376. DEBUG_INFO("TxProfile updated.\n");
  2377. // Required item
  2378. txProfile.ChargingProfileId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileId"));
  2379. txProfile.StackLevel = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "stackLevel"));
  2380. sprintf((char*)txProfile.ChargingProfileKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileKind")));
  2381. if(isUnitA)
  2382. {
  2383. sprintf((char*)txProfile.ChargingSchedule.ChargingRateUnit, "A");
  2384. 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++)
  2385. {
  2386. 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"));
  2387. 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?
  2388. 3:
  2389. 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")));
  2390. 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")));
  2391. }
  2392. }
  2393. else
  2394. {
  2395. sprintf((char*)txProfile.ChargingSchedule.ChargingRateUnit, "W");
  2396. 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++)
  2397. {
  2398. 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"));
  2399. 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?
  2400. 3:
  2401. 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")));
  2402. 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));
  2403. }
  2404. }
  2405. // Optional item
  2406. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom") != NULL)
  2407. {
  2408. sprintf((char*)txProfile.ValidFrom, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom")));
  2409. }
  2410. else
  2411. {
  2412. sprintf((char*)txProfile.ValidFrom, " ");
  2413. }
  2414. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo") != NULL)
  2415. {
  2416. sprintf((char*)txProfile.ValidTo, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo")));
  2417. }
  2418. else
  2419. {
  2420. sprintf((char*)txProfile.ValidTo, " ");
  2421. }
  2422. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "recurrencyKind") != NULL)
  2423. {
  2424. sprintf((char*)txProfile.RecurrencyKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "recurrencyKind")));
  2425. }
  2426. else
  2427. {
  2428. sprintf((char*)txProfile.RecurrencyKind, " ");
  2429. }
  2430. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId") != NULL)
  2431. {
  2432. txProfile.TransactionId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId"));
  2433. }
  2434. else
  2435. {
  2436. txProfile.TransactionId = -1;
  2437. }
  2438. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration") != NULL)
  2439. {
  2440. txProfile.ChargingSchedule.Duration = json_object_get_int(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration"));
  2441. }
  2442. else
  2443. {
  2444. txProfile.ChargingSchedule.Duration = 86400;
  2445. }
  2446. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "startSchedule") != NULL)
  2447. {
  2448. 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")));
  2449. }
  2450. else
  2451. {
  2452. 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));
  2453. }
  2454. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate") != NULL)
  2455. {
  2456. txProfile.ChargingSchedule.MinChargingRate = json_object_get_double(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate"));
  2457. }
  2458. else
  2459. {
  2460. txProfile.ChargingSchedule.MinChargingRate = -1;
  2461. }
  2462. }
  2463. }
  2464. }
  2465. else
  2466. {
  2467. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(txProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  2468. {
  2469. txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = -1;
  2470. txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit = -1;
  2471. txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases = 3;
  2472. }
  2473. if(txProfile.ChargingProfileId == -1)
  2474. DEBUG_INFO("TxProfile found.\n");
  2475. else
  2476. DEBUG_INFO("TxProfile updated.\n");
  2477. // Required item
  2478. txProfile.ChargingProfileId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileId"));
  2479. txProfile.StackLevel = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "stackLevel"));
  2480. sprintf((char*)txProfile.ChargingProfileKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileKind")));
  2481. if(isUnitA)
  2482. {
  2483. sprintf((char*)txProfile.ChargingSchedule.ChargingRateUnit, "A");
  2484. 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++)
  2485. {
  2486. 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"));
  2487. 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?
  2488. 3:
  2489. 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")));
  2490. 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")));
  2491. }
  2492. }
  2493. else
  2494. {
  2495. sprintf((char*)txProfile.ChargingSchedule.ChargingRateUnit, "W");
  2496. 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++)
  2497. {
  2498. 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"));
  2499. 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?
  2500. 3:
  2501. 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")));
  2502. 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));
  2503. }
  2504. }
  2505. // Optional item
  2506. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom") != NULL)
  2507. {
  2508. sprintf((char*)txProfile.ValidFrom, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom")));
  2509. }
  2510. else
  2511. {
  2512. sprintf((char*)txProfile.ValidFrom, " ");
  2513. }
  2514. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo") != NULL)
  2515. {
  2516. sprintf((char*)txProfile.ValidTo, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo")));
  2517. }
  2518. else
  2519. {
  2520. sprintf((char*)txProfile.ValidTo, " ");
  2521. }
  2522. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "recurrencyKind") != NULL)
  2523. {
  2524. sprintf((char*)txProfile.RecurrencyKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "recurrencyKind")));
  2525. }
  2526. else
  2527. {
  2528. sprintf((char*)txProfile.RecurrencyKind, " ");
  2529. }
  2530. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId") != NULL)
  2531. {
  2532. txProfile.TransactionId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId"));
  2533. }
  2534. else
  2535. {
  2536. txProfile.TransactionId = -1;
  2537. }
  2538. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration") != NULL)
  2539. {
  2540. txProfile.ChargingSchedule.Duration = json_object_get_int(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration"));
  2541. }
  2542. else
  2543. {
  2544. txProfile.ChargingSchedule.Duration = 86400;
  2545. }
  2546. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "startSchedule") != NULL)
  2547. {
  2548. 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")));
  2549. }
  2550. else
  2551. {
  2552. 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));
  2553. }
  2554. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate") != NULL)
  2555. {
  2556. txProfile.ChargingSchedule.MinChargingRate = json_object_get_double(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate"));
  2557. }
  2558. else
  2559. {
  2560. txProfile.ChargingSchedule.MinChargingRate = -1;
  2561. }
  2562. }
  2563. }
  2564. }
  2565. json_object_put(obj);
  2566. }
  2567. fclose(fp);
  2568. /*
  2569. if(txProfile.ChargingProfileId != -1)
  2570. {
  2571. DEBUG_INFO("Profile ID: %d\n", txProfile.ChargingProfileId);
  2572. DEBUG_INFO("Profile stackLevel: %d\n", txProfile.StackLevel);
  2573. DEBUG_INFO("Profile TransactionId: %d\n", txProfile.TransactionId);
  2574. DEBUG_INFO("Profile valid from: %s\n", txProfile.ValidFrom);
  2575. DEBUG_INFO("Profile valid to: %s\n", txProfile.ValidTo);
  2576. DEBUG_INFO("Profile ChargingProfileKind: %s\n", txProfile.ChargingProfileKind);
  2577. DEBUG_INFO("Profile recurrencyKind: %s\n", txProfile.RecurrencyKind);
  2578. DEBUG_INFO("Profile start schedule: %s\n", txProfile.ChargingSchedule.StartSchedule);
  2579. DEBUG_INFO("Profile schedule duration: %d\n", txProfile.ChargingSchedule.Duration);
  2580. DEBUG_INFO("Profile charging rate unit: %s\n", txProfile.ChargingSchedule.ChargingRateUnit);
  2581. DEBUG_INFO("Profile charging min rate: %f\n", txProfile.ChargingSchedule.MinChargingRate);
  2582. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(txProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  2583. {
  2584. if(txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod >= 0)
  2585. {
  2586. DEBUG_INFO("Period-%02d startPeriod: %d\n", idxPeriod, txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod);
  2587. DEBUG_INFO("Period-%02d limit: %f\n", idxPeriod, txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit);
  2588. DEBUG_INFO("Period-%02d NumberPhases: %d\n", idxPeriod, txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases);
  2589. }
  2590. }
  2591. }
  2592. else
  2593. DEBUG_INFO("TxProfile not found.\n");*/
  2594. }
  2595. // Search default tx profile
  2596. sprintf(profileFileName, "/tmp/TxDefaultProfile_%d.json", connectorId);
  2597. if((access(profileFileName, F_OK))==-1)
  2598. sprintf(profileFileName, "/tmp/TxDefaultProfile_0.json");
  2599. if((access(profileFileName, F_OK))!=-1)
  2600. {
  2601. fp = fopen(profileFileName, "r");
  2602. while(getline(&line, &len, fp) != -1)
  2603. {
  2604. json_object *obj = NULL;
  2605. obj = json_tokener_parse(line);
  2606. if(is_error(obj))
  2607. {
  2608. DEBUG_ERROR("Parse TxDefaultProfile from file error.\n");
  2609. }
  2610. else
  2611. {
  2612. if((json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileId")) != defaultTxProfile.ChargingProfileId) &&
  2613. (json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "stackLevel")) >= defaultTxProfile.StackLevel)
  2614. )
  2615. {
  2616. if((json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom") != NULL) &&
  2617. (json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo") != NULL)
  2618. )
  2619. {
  2620. struct tm tmFrom, tmTo;
  2621. struct timeb tbFrom, tbTo;
  2622. 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) &&
  2623. (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))
  2624. {
  2625. tmFrom.tm_year -= 1900;
  2626. tmFrom.tm_mon -= 1;
  2627. tbFrom.time = mktime(&tmFrom);
  2628. tmTo.tm_year -= 1900;
  2629. tmTo.tm_mon -= 1;
  2630. tbTo.time = mktime(&tmTo);
  2631. if((DiffTimebWithNowSec(tbFrom)>=0) && (DiffTimebWithNowSec(tbTo)<=0))
  2632. {
  2633. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  2634. {
  2635. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = -1;
  2636. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit = -1;
  2637. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases = 3;
  2638. }
  2639. if(defaultTxProfile.ChargingProfileId == -1)
  2640. DEBUG_INFO("TxDefaultProfile found.\n");
  2641. else
  2642. DEBUG_INFO("TxDefaultProfile updated.\n");
  2643. // Required item
  2644. defaultTxProfile.ChargingProfileId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileId"));
  2645. defaultTxProfile.StackLevel = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "stackLevel"));
  2646. sprintf((char*)defaultTxProfile.ChargingProfileKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileKind")));
  2647. if(isUnitA)
  2648. {
  2649. sprintf((char*)defaultTxProfile.ChargingSchedule.ChargingRateUnit, "A");
  2650. 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++)
  2651. {
  2652. 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"));
  2653. 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?
  2654. 3:
  2655. 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")));
  2656. 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")));
  2657. }
  2658. }
  2659. else
  2660. {
  2661. sprintf((char*)defaultTxProfile.ChargingSchedule.ChargingRateUnit, "W");
  2662. 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++)
  2663. {
  2664. 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"));
  2665. 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?
  2666. 3:
  2667. 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")));
  2668. 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));
  2669. }
  2670. }
  2671. // Optional item
  2672. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom") != NULL)
  2673. {
  2674. sprintf((char*)defaultTxProfile.ValidFrom, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom")));
  2675. }
  2676. else
  2677. {
  2678. sprintf((char*)defaultTxProfile.ValidFrom, " ");
  2679. }
  2680. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo") != NULL)
  2681. {
  2682. sprintf((char*)defaultTxProfile.ValidTo, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo")));
  2683. }
  2684. else
  2685. {
  2686. sprintf((char*)defaultTxProfile.ValidTo, " ");
  2687. }
  2688. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "recurrencyKind") != NULL)
  2689. {
  2690. sprintf((char*)defaultTxProfile.RecurrencyKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "recurrencyKind")));
  2691. }
  2692. else
  2693. {
  2694. sprintf((char*)defaultTxProfile.RecurrencyKind, " ");
  2695. }
  2696. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId") != NULL)
  2697. {
  2698. defaultTxProfile.TransactionId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId"));
  2699. }
  2700. else
  2701. {
  2702. defaultTxProfile.TransactionId = -1;
  2703. }
  2704. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration") != NULL)
  2705. {
  2706. defaultTxProfile.ChargingSchedule.Duration = json_object_get_int(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration"));
  2707. }
  2708. else
  2709. {
  2710. defaultTxProfile.ChargingSchedule.Duration = 86400;
  2711. }
  2712. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "startSchedule") != NULL)
  2713. {
  2714. 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")));
  2715. }
  2716. else
  2717. {
  2718. 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));
  2719. }
  2720. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate") != NULL)
  2721. {
  2722. defaultTxProfile.ChargingSchedule.MinChargingRate = json_object_get_double(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate"));
  2723. }
  2724. else
  2725. {
  2726. defaultTxProfile.ChargingSchedule.MinChargingRate = -1;
  2727. }
  2728. }
  2729. }
  2730. }
  2731. else
  2732. {
  2733. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  2734. {
  2735. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = -1;
  2736. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit = -1;
  2737. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases = 3;
  2738. }
  2739. if(defaultTxProfile.ChargingProfileId == -1)
  2740. DEBUG_INFO("TxDefaultProfile found.\n");
  2741. else
  2742. DEBUG_INFO("TxDefaultProfile updated.\n");
  2743. // Required item
  2744. defaultTxProfile.ChargingProfileId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileId"));
  2745. defaultTxProfile.StackLevel = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "stackLevel"));
  2746. sprintf((char*)defaultTxProfile.ChargingProfileKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileKind")));
  2747. if(isUnitA)
  2748. {
  2749. sprintf((char*)defaultTxProfile.ChargingSchedule.ChargingRateUnit, "A");
  2750. 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++)
  2751. {
  2752. 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"));
  2753. 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?
  2754. 3:
  2755. 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")));
  2756. 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")));
  2757. }
  2758. }
  2759. else
  2760. {
  2761. sprintf((char*)defaultTxProfile.ChargingSchedule.ChargingRateUnit, "W");
  2762. 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++)
  2763. {
  2764. 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"));
  2765. 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?
  2766. 3:
  2767. 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")));
  2768. 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));
  2769. }
  2770. }
  2771. // Optional item
  2772. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom") != NULL)
  2773. {
  2774. sprintf((char*)defaultTxProfile.ValidFrom, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom")));
  2775. }
  2776. else
  2777. {
  2778. sprintf((char*)defaultTxProfile.ValidFrom, " ");
  2779. }
  2780. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo") != NULL)
  2781. {
  2782. sprintf((char*)defaultTxProfile.ValidTo, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo")));
  2783. }
  2784. else
  2785. {
  2786. sprintf((char*)defaultTxProfile.ValidTo, " ");
  2787. }
  2788. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "recurrencyKind") != NULL)
  2789. {
  2790. sprintf((char*)defaultTxProfile.RecurrencyKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "recurrencyKind")));
  2791. }
  2792. else
  2793. {
  2794. sprintf((char*)defaultTxProfile.RecurrencyKind, " ");
  2795. }
  2796. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId") != NULL)
  2797. {
  2798. defaultTxProfile.TransactionId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId"));
  2799. }
  2800. else
  2801. {
  2802. defaultTxProfile.TransactionId = -1;
  2803. }
  2804. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration") != NULL)
  2805. {
  2806. defaultTxProfile.ChargingSchedule.Duration = json_object_get_int(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration"));
  2807. }
  2808. else
  2809. {
  2810. defaultTxProfile.ChargingSchedule.Duration = 86400;
  2811. }
  2812. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "startSchedule") != NULL)
  2813. {
  2814. 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")));
  2815. }
  2816. else
  2817. {
  2818. 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));
  2819. }
  2820. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate") != NULL)
  2821. {
  2822. defaultTxProfile.ChargingSchedule.MinChargingRate = json_object_get_double(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate"));
  2823. }
  2824. else
  2825. {
  2826. defaultTxProfile.ChargingSchedule.MinChargingRate = -1;
  2827. }
  2828. }
  2829. }
  2830. }
  2831. json_object_put(obj);
  2832. }
  2833. fclose(fp);
  2834. /*
  2835. if(defaultTxProfile.ChargingProfileId != -1)
  2836. {
  2837. DEBUG_INFO("Profile ID: %d\n", defaultTxProfile.ChargingProfileId);
  2838. DEBUG_INFO("Profile stackLevel: %d\n", defaultTxProfile.StackLevel);
  2839. DEBUG_INFO("Profile TransactionId: %d\n", defaultTxProfile.TransactionId);
  2840. DEBUG_INFO("Profile valid from: %s\n", defaultTxProfile.ValidFrom);
  2841. DEBUG_INFO("Profile valid to: %s\n", defaultTxProfile.ValidTo);
  2842. DEBUG_INFO("Profile ChargingProfileKind: %s\n", defaultTxProfile.ChargingProfileKind);
  2843. DEBUG_INFO("Profile recurrencyKind: %s\n", defaultTxProfile.RecurrencyKind);
  2844. DEBUG_INFO("Profile start schedule: %s\n", defaultTxProfile.ChargingSchedule.StartSchedule);
  2845. DEBUG_INFO("Profile schedule duration: %d\n", defaultTxProfile.ChargingSchedule.Duration);
  2846. DEBUG_INFO("Profile charging rate unit: %s\n", defaultTxProfile.ChargingSchedule.ChargingRateUnit);
  2847. DEBUG_INFO("Profile charging min rate: %f\n", defaultTxProfile.ChargingSchedule.MinChargingRate);
  2848. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  2849. {
  2850. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod >= 0)
  2851. {
  2852. DEBUG_INFO("Period-%02d startPeriod: %d\n", idxPeriod, defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod);
  2853. DEBUG_INFO("Period-%02d limit: %f\n", idxPeriod, defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit);
  2854. DEBUG_INFO("Period-%02d NumberPhases: %d\n", idxPeriod, defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases);
  2855. }
  2856. }
  2857. }
  2858. else
  2859. DEBUG_INFO("TxDefaultProfile not found.\n");
  2860. DEBUG_INFO("------------------------------------\n");*/
  2861. }
  2862. // Search max profile
  2863. sprintf(profileFileName, "/tmp/ChargePointMaxProfile.json");
  2864. if((access(profileFileName, F_OK))!=-1)
  2865. {
  2866. fp = fopen(profileFileName, "r");
  2867. while(getline(&line, &len, fp) != -1)
  2868. {
  2869. json_object *obj = NULL;
  2870. obj = json_tokener_parse(line);
  2871. if(is_error(obj))
  2872. {
  2873. DEBUG_ERROR("Parse MaxProfile from file error.\n");
  2874. }
  2875. else
  2876. {
  2877. if((json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileId")) != maxProfile.ChargingProfileId) &&
  2878. (json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "stackLevel")) >= maxProfile.StackLevel)
  2879. )
  2880. {
  2881. if((json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom") != NULL) &&
  2882. (json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo") != NULL)
  2883. )
  2884. {
  2885. struct tm tmFrom, tmTo;
  2886. struct timeb tbFrom, tbTo;
  2887. 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) &&
  2888. (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))
  2889. {
  2890. tmFrom.tm_year -= 1900;
  2891. tmFrom.tm_mon -= 1;
  2892. tbFrom.time = mktime(&tmFrom);
  2893. tmTo.tm_year -= 1900;
  2894. tmTo.tm_mon -= 1;
  2895. tbTo.time = mktime(&tmTo);
  2896. if((DiffTimebWithNowSec(tbFrom)>=0) && (DiffTimebWithNowSec(tbTo)<=0))
  2897. {
  2898. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  2899. {
  2900. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = -1;
  2901. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit = -1;
  2902. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases = 3;
  2903. }
  2904. if(maxProfile.ChargingProfileId == -1)
  2905. DEBUG_INFO("MaxProfile found.\n");
  2906. else
  2907. DEBUG_INFO("MaxProfile updated.\n");
  2908. // Required item
  2909. maxProfile.ChargingProfileId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileId"));
  2910. maxProfile.StackLevel = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "stackLevel"));
  2911. sprintf((char*)maxProfile.ChargingProfileKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileKind")));
  2912. if(isUnitA)
  2913. {
  2914. sprintf((char*)maxProfile.ChargingSchedule.ChargingRateUnit, "A");
  2915. 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++)
  2916. {
  2917. 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"));
  2918. 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?
  2919. 3:
  2920. 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")));
  2921. 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")));
  2922. }
  2923. }
  2924. else
  2925. {
  2926. sprintf((char*)maxProfile.ChargingSchedule.ChargingRateUnit, "W");
  2927. 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++)
  2928. {
  2929. 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"));
  2930. 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?
  2931. 3:
  2932. 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")));
  2933. 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));
  2934. }
  2935. }
  2936. // Optional item
  2937. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom") != NULL)
  2938. {
  2939. sprintf((char*)maxProfile.ValidFrom, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom")));
  2940. }
  2941. else
  2942. {
  2943. sprintf((char*)maxProfile.ValidFrom, " ");
  2944. }
  2945. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo") != NULL)
  2946. {
  2947. sprintf((char*)maxProfile.ValidTo, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo")));
  2948. }
  2949. else
  2950. {
  2951. sprintf((char*)maxProfile.ValidTo, " ");
  2952. }
  2953. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "recurrencyKind") != NULL)
  2954. {
  2955. sprintf((char*)maxProfile.RecurrencyKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "recurrencyKind")));
  2956. }
  2957. else
  2958. {
  2959. sprintf((char*)maxProfile.RecurrencyKind, " ");
  2960. }
  2961. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId") != NULL)
  2962. {
  2963. maxProfile.TransactionId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId"));
  2964. }
  2965. else
  2966. {
  2967. maxProfile.TransactionId = -1;
  2968. }
  2969. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration") != NULL)
  2970. {
  2971. maxProfile.ChargingSchedule.Duration = json_object_get_int(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration"));
  2972. }
  2973. else
  2974. {
  2975. maxProfile.ChargingSchedule.Duration = 86400;
  2976. }
  2977. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "startSchedule") != NULL)
  2978. {
  2979. 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")));
  2980. }
  2981. else
  2982. {
  2983. 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));
  2984. }
  2985. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate") != NULL)
  2986. {
  2987. maxProfile.ChargingSchedule.MinChargingRate = json_object_get_double(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate"));
  2988. }
  2989. else
  2990. {
  2991. maxProfile.ChargingSchedule.MinChargingRate = -1;
  2992. }
  2993. }
  2994. }
  2995. }
  2996. else
  2997. {
  2998. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  2999. {
  3000. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = -1;
  3001. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit = -1;
  3002. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases = 3;
  3003. }
  3004. if(maxProfile.ChargingProfileId == -1)
  3005. DEBUG_INFO("MaxProfile found.\n");
  3006. else
  3007. DEBUG_INFO("MaxProfile updated.\n");
  3008. // Required item
  3009. maxProfile.ChargingProfileId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileId"));
  3010. maxProfile.StackLevel = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "stackLevel"));
  3011. sprintf((char*)maxProfile.ChargingProfileKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileKind")));
  3012. if(isUnitA)
  3013. {
  3014. sprintf((char*)maxProfile.ChargingSchedule.ChargingRateUnit, "A");
  3015. 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++)
  3016. {
  3017. 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"));
  3018. 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?
  3019. 3:
  3020. 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")));
  3021. 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")));
  3022. }
  3023. }
  3024. else
  3025. {
  3026. sprintf((char*)maxProfile.ChargingSchedule.ChargingRateUnit, "W");
  3027. 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++)
  3028. {
  3029. 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"));
  3030. 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?
  3031. 3:
  3032. 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")));
  3033. 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));
  3034. }
  3035. }
  3036. // Optional item
  3037. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom") != NULL)
  3038. {
  3039. sprintf((char*)maxProfile.ValidFrom, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom")));
  3040. }
  3041. else
  3042. {
  3043. sprintf((char*)maxProfile.ValidFrom, " ");
  3044. }
  3045. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo") != NULL)
  3046. {
  3047. sprintf((char*)maxProfile.ValidTo, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo")));
  3048. }
  3049. else
  3050. {
  3051. sprintf((char*)maxProfile.ValidTo, " ");
  3052. }
  3053. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "recurrencyKind") != NULL)
  3054. {
  3055. sprintf((char*)maxProfile.RecurrencyKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "recurrencyKind")));
  3056. }
  3057. else
  3058. {
  3059. sprintf((char*)maxProfile.RecurrencyKind, " ");
  3060. }
  3061. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId") != NULL)
  3062. {
  3063. maxProfile.TransactionId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId"));
  3064. }
  3065. else
  3066. {
  3067. maxProfile.TransactionId = -1;
  3068. }
  3069. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration") != NULL)
  3070. {
  3071. maxProfile.ChargingSchedule.Duration = json_object_get_int(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration"));
  3072. }
  3073. else
  3074. {
  3075. maxProfile.ChargingSchedule.Duration = 86400;
  3076. }
  3077. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "startSchedule") != NULL)
  3078. {
  3079. 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")));
  3080. }
  3081. else
  3082. {
  3083. 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));
  3084. }
  3085. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate") != NULL)
  3086. {
  3087. maxProfile.ChargingSchedule.MinChargingRate = json_object_get_double(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate"));
  3088. }
  3089. else
  3090. {
  3091. maxProfile.ChargingSchedule.MinChargingRate = -1;
  3092. }
  3093. }
  3094. }
  3095. }
  3096. json_object_put(obj);
  3097. }
  3098. fclose(fp);
  3099. /*
  3100. if(maxProfile.ChargingProfileId !=-1)
  3101. {
  3102. DEBUG_INFO("Profile ID: %d\n", maxProfile.ChargingProfileId);
  3103. DEBUG_INFO("Profile stackLevel: %d\n", maxProfile.StackLevel);
  3104. DEBUG_INFO("Profile TransactionId: %d\n", maxProfile.TransactionId);
  3105. DEBUG_INFO("Profile valid from: %s\n", maxProfile.ValidFrom);
  3106. DEBUG_INFO("Profile valid to: %s\n", maxProfile.ValidTo);
  3107. DEBUG_INFO("Profile ChargingProfileKind: %s\n", maxProfile.ChargingProfileKind);
  3108. DEBUG_INFO("Profile recurrencyKind: %s\n", maxProfile.RecurrencyKind);
  3109. DEBUG_INFO("Profile start schedule: %s\n", maxProfile.ChargingSchedule.StartSchedule);
  3110. DEBUG_INFO("Profile schedule duration: %d\n", maxProfile.ChargingSchedule.Duration);
  3111. DEBUG_INFO("Profile charging rate unit: %s\n", maxProfile.ChargingSchedule.ChargingRateUnit);
  3112. DEBUG_INFO("Profile charging min rate: %f\n", maxProfile.ChargingSchedule.MinChargingRate);
  3113. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  3114. {
  3115. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod >= 0)
  3116. {
  3117. DEBUG_INFO("Period-%02d startPeriod: %d\n", idxPeriod, maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod);
  3118. DEBUG_INFO("Period-%02d limit: %f\n", idxPeriod, maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit);
  3119. DEBUG_INFO("Period-%02d NumberPhases: %d\n", idxPeriod, maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases);
  3120. }
  3121. }
  3122. }
  3123. else
  3124. DEBUG_INFO("MaxProfile not found.\n");
  3125. DEBUG_INFO("------------------------------------\n");*/
  3126. }
  3127. /*
  3128. * Align found profile start schedule & periods
  3129. */
  3130. //DEBUG_INFO("====================================\n");
  3131. /*
  3132. // For local test usage, force modify found profile start schedule info
  3133. 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);
  3134. 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);
  3135. 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);
  3136. */
  3137. if(txProfile.ChargingProfileId != -1)
  3138. {
  3139. if(strstr((char*)txProfile.ChargingProfileKind, "Absolute") != NULL)
  3140. {
  3141. if(txProfile.ChargingSchedule.Duration != -1)
  3142. {
  3143. txProfile.ChargingSchedule.Duration = ((txProfile.ChargingSchedule.Duration-getStartStop(txProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule))<0?
  3144. 0:
  3145. (txProfile.ChargingSchedule.Duration-getStartStop(txProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule)));
  3146. }
  3147. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(txProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  3148. {
  3149. if(txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  3150. {
  3151. txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = ((txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartStop(txProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule))<0?
  3152. 0:
  3153. (txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartStop(txProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule)));
  3154. if(idxPeriod > 0)
  3155. {
  3156. if(txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
  3157. {
  3158. txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit = txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit;
  3159. }
  3160. }
  3161. }
  3162. }
  3163. }
  3164. else if(strstr((char*)txProfile.ChargingProfileKind, "Relative") != NULL)
  3165. {
  3166. if(txProfile.ChargingSchedule.Duration != -1)
  3167. {
  3168. 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?
  3169. 0:
  3170. (txProfile.ChargingSchedule.Duration-getStartStop(ShmOCPP16Data->StartTransaction[(connectorId==0?0:connectorId-1)].Timestamp, compositeProfile.ChargingSchedule.StartSchedule)));
  3171. }
  3172. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(txProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  3173. {
  3174. if(txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  3175. {
  3176. 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?
  3177. 0:
  3178. (txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartStop(ShmOCPP16Data->StartTransaction[(connectorId==0?0:connectorId-1)].Timestamp, compositeProfile.ChargingSchedule.StartSchedule)));
  3179. if(idxPeriod > 0)
  3180. {
  3181. if(txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
  3182. {
  3183. txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit = txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit;
  3184. }
  3185. }
  3186. }
  3187. }
  3188. }
  3189. else
  3190. {
  3191. if(strstr((char*)txProfile.RecurrencyKind, "Weekly") != NULL)
  3192. {
  3193. if(txProfile.ChargingSchedule.Duration != -1)
  3194. {
  3195. txProfile.ChargingSchedule.Duration = ((txProfile.ChargingSchedule.Duration-getStartSinceRecurring(txProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule, FALSE))<0?
  3196. 0:
  3197. (txProfile.ChargingSchedule.Duration-getStartSinceRecurring(txProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule, FALSE)));
  3198. }
  3199. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(txProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  3200. {
  3201. if(txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  3202. {
  3203. txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = ((txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceRecurring(txProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule, FALSE))<0?
  3204. 0:
  3205. (txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceRecurring(txProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule, FALSE)));
  3206. if(idxPeriod > 0)
  3207. {
  3208. if(txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
  3209. {
  3210. txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit = txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit;
  3211. }
  3212. }
  3213. }
  3214. }
  3215. }
  3216. else
  3217. {
  3218. if(txProfile.ChargingSchedule.Duration != -1)
  3219. {
  3220. txProfile.ChargingSchedule.Duration = ((txProfile.ChargingSchedule.Duration-getStartSinceRecurring(txProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule, TRUE))<0?
  3221. 0:
  3222. (txProfile.ChargingSchedule.Duration-getStartSinceRecurring(txProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule, TRUE)));
  3223. }
  3224. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(txProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  3225. {
  3226. if(txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  3227. {
  3228. txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = ((txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceRecurring(txProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule, TRUE))<0?
  3229. 0:
  3230. (txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceRecurring(txProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule, TRUE)));
  3231. if(idxPeriod > 0)
  3232. {
  3233. if(txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
  3234. {
  3235. txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit = txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit;
  3236. }
  3237. }
  3238. }
  3239. }
  3240. }
  3241. }
  3242. /*
  3243. DEBUG_INFO("txProfile after align.\n");
  3244. DEBUG_INFO("Profile ID: %d\n", txProfile.ChargingProfileId);
  3245. DEBUG_INFO("Profile stackLevel: %d\n", txProfile.StackLevel);
  3246. DEBUG_INFO("Profile TransactionId: %d\n", txProfile.TransactionId);
  3247. DEBUG_INFO("Profile valid from: %s\n", txProfile.ValidFrom);
  3248. DEBUG_INFO("Profile valid to: %s\n", txProfile.ValidTo);
  3249. DEBUG_INFO("Profile ChargingProfileKind: %s\n", txProfile.ChargingProfileKind);
  3250. DEBUG_INFO("Profile recurrencyKind: %s\n", txProfile.RecurrencyKind);
  3251. DEBUG_INFO("Profile start schedule: %s\n", compositeProfile.ChargingSchedule.StartSchedule);
  3252. DEBUG_INFO("Profile schedule duration: %d\n", txProfile.ChargingSchedule.Duration);
  3253. DEBUG_INFO("Profile charging rate unit: %s\n", txProfile.ChargingSchedule.ChargingRateUnit);
  3254. DEBUG_INFO("Profile charging min rate: %f\n", txProfile.ChargingSchedule.MinChargingRate);
  3255. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(txProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  3256. {
  3257. if(txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod >= 0)
  3258. {
  3259. DEBUG_INFO("Period-%02d startPeriod: %d\n", idxPeriod, txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod);
  3260. DEBUG_INFO("Period-%02d limit: %f\n", idxPeriod, txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit);
  3261. DEBUG_INFO("Period-%02d NumberPhases: %d\n", idxPeriod, txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases);
  3262. }
  3263. }*/
  3264. }
  3265. if(defaultTxProfile.ChargingProfileId != -1)
  3266. {
  3267. if(strstr((char*)defaultTxProfile.ChargingProfileKind, "Absolute") != NULL)
  3268. {
  3269. if(defaultTxProfile.ChargingSchedule.Duration != -1)
  3270. {
  3271. defaultTxProfile.ChargingSchedule.Duration = ((defaultTxProfile.ChargingSchedule.Duration-getStartStop(defaultTxProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule))<0?
  3272. 0:
  3273. (defaultTxProfile.ChargingSchedule.Duration-getStartStop(defaultTxProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule)));
  3274. }
  3275. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  3276. {
  3277. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  3278. {
  3279. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = ((defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartStop(defaultTxProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule))<0?
  3280. 0:
  3281. (defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartStop(defaultTxProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule)));
  3282. if(idxPeriod > 0)
  3283. {
  3284. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
  3285. {
  3286. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit = defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit;
  3287. }
  3288. }
  3289. }
  3290. }
  3291. }
  3292. else if(strstr((char*)defaultTxProfile.ChargingProfileKind, "Relative") != NULL)
  3293. {
  3294. if(defaultTxProfile.ChargingSchedule.Duration != -1)
  3295. {
  3296. 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?
  3297. 0:
  3298. (defaultTxProfile.ChargingSchedule.Duration-getStartStop(ShmOCPP16Data->StartTransaction[(connectorId==0?0:connectorId-1)].Timestamp, compositeProfile.ChargingSchedule.StartSchedule)));
  3299. }
  3300. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  3301. {
  3302. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  3303. {
  3304. 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?
  3305. 0:
  3306. (defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartStop(ShmOCPP16Data->StartTransaction[(connectorId==0?0:connectorId-1)].Timestamp, compositeProfile.ChargingSchedule.StartSchedule)));
  3307. if(idxPeriod > 0)
  3308. {
  3309. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
  3310. {
  3311. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit = defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit;
  3312. }
  3313. }
  3314. }
  3315. }
  3316. }
  3317. else
  3318. {
  3319. if(strstr((char*)defaultTxProfile.RecurrencyKind, "Weekly") != NULL)
  3320. {
  3321. if(defaultTxProfile.ChargingSchedule.Duration != -1)
  3322. {
  3323. defaultTxProfile.ChargingSchedule.Duration = ((defaultTxProfile.ChargingSchedule.Duration-getStartSinceRecurring(defaultTxProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule, FALSE))<0?
  3324. 0:
  3325. (defaultTxProfile.ChargingSchedule.Duration-getStartSinceRecurring(defaultTxProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule, FALSE)));
  3326. }
  3327. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  3328. {
  3329. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  3330. {
  3331. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = ((defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceRecurring(defaultTxProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule, FALSE))<0?
  3332. 0:
  3333. (defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceRecurring(defaultTxProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule, FALSE)));
  3334. if(idxPeriod > 0)
  3335. {
  3336. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
  3337. {
  3338. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit = defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit;
  3339. }
  3340. }
  3341. }
  3342. }
  3343. }
  3344. else
  3345. {
  3346. if(defaultTxProfile.ChargingSchedule.Duration != -1)
  3347. {
  3348. defaultTxProfile.ChargingSchedule.Duration = ((defaultTxProfile.ChargingSchedule.Duration-getStartSinceRecurring(defaultTxProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule, TRUE))<0?
  3349. 0:
  3350. (defaultTxProfile.ChargingSchedule.Duration-getStartSinceRecurring(defaultTxProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule, TRUE)));
  3351. }
  3352. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  3353. {
  3354. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  3355. {
  3356. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = ((defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceRecurring(defaultTxProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule, TRUE))<0?
  3357. 0:
  3358. (defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceRecurring(defaultTxProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule, TRUE)));
  3359. if(idxPeriod > 0)
  3360. {
  3361. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
  3362. {
  3363. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit = defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit;
  3364. }
  3365. }
  3366. }
  3367. }
  3368. }
  3369. }
  3370. /*
  3371. DEBUG_INFO("defaultTxProfile after align.\n");
  3372. DEBUG_INFO("Profile ID: %d\n", defaultTxProfile.ChargingProfileId);
  3373. DEBUG_INFO("Profile stackLevel: %d\n", defaultTxProfile.StackLevel);
  3374. DEBUG_INFO("Profile TransactionId: %d\n", defaultTxProfile.TransactionId);
  3375. DEBUG_INFO("Profile valid from: %s\n", defaultTxProfile.ValidFrom);
  3376. DEBUG_INFO("Profile valid to: %s\n", defaultTxProfile.ValidTo);
  3377. DEBUG_INFO("Profile ChargingProfileKind: %s\n", defaultTxProfile.ChargingProfileKind);
  3378. DEBUG_INFO("Profile recurrencyKind: %s\n", defaultTxProfile.RecurrencyKind);
  3379. DEBUG_INFO("Profile start schedule: %s\n", compositeProfile.ChargingSchedule.StartSchedule);
  3380. DEBUG_INFO("Profile schedule duration: %d\n", defaultTxProfile.ChargingSchedule.Duration);
  3381. DEBUG_INFO("Profile charging rate unit: %s\n", defaultTxProfile.ChargingSchedule.ChargingRateUnit);
  3382. DEBUG_INFO("Profile charging min rate: %f\n", defaultTxProfile.ChargingSchedule.MinChargingRate);
  3383. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  3384. {
  3385. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod >= 0)
  3386. {
  3387. DEBUG_INFO("Period-%02d startPeriod: %d\n", idxPeriod, defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod);
  3388. DEBUG_INFO("Period-%02d limit: %f\n", idxPeriod, defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit);
  3389. DEBUG_INFO("Period-%02d NumberPhases: %d\n", idxPeriod, defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases);
  3390. }
  3391. }
  3392. DEBUG_INFO("------------------------------------\n");*/
  3393. }
  3394. if(maxProfile.ChargingProfileId != -1)
  3395. {
  3396. if(strstr((char*)maxProfile.ChargingProfileKind, "Absolute") != NULL)
  3397. {
  3398. if(maxProfile.ChargingSchedule.Duration != -1)
  3399. {
  3400. maxProfile.ChargingSchedule.Duration = ((maxProfile.ChargingSchedule.Duration-getStartStop(maxProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule))<0?
  3401. 0:
  3402. (maxProfile.ChargingSchedule.Duration-getStartStop(maxProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule)));
  3403. }
  3404. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  3405. {
  3406. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  3407. {
  3408. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = ((maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartStop(maxProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule))<0?
  3409. 0:
  3410. (maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartStop(maxProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule)));
  3411. if(idxPeriod > 0)
  3412. {
  3413. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
  3414. {
  3415. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit = maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit;
  3416. }
  3417. }
  3418. }
  3419. }
  3420. }
  3421. else if(strstr((char*)maxProfile.ChargingProfileKind, "Relative") != NULL)
  3422. {
  3423. if(maxProfile.ChargingSchedule.Duration != -1)
  3424. {
  3425. 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?
  3426. 0:
  3427. (maxProfile.ChargingSchedule.Duration-getStartStop(ShmOCPP16Data->StartTransaction[(connectorId==0?0:connectorId-1)].Timestamp, compositeProfile.ChargingSchedule.StartSchedule)));
  3428. }
  3429. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  3430. {
  3431. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  3432. {
  3433. 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?
  3434. 0:
  3435. (maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartStop(ShmOCPP16Data->StartTransaction[(connectorId==0?0:connectorId-1)].Timestamp, compositeProfile.ChargingSchedule.StartSchedule)));
  3436. if(idxPeriod > 0)
  3437. {
  3438. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
  3439. {
  3440. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit = maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit;
  3441. }
  3442. }
  3443. }
  3444. }
  3445. }
  3446. else
  3447. {
  3448. if(strstr((char*)maxProfile.RecurrencyKind, "Weekly") != NULL)
  3449. {
  3450. if(maxProfile.ChargingSchedule.Duration != -1)
  3451. {
  3452. maxProfile.ChargingSchedule.Duration = ((maxProfile.ChargingSchedule.Duration-getStartSinceRecurring(maxProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule, FALSE))<0?
  3453. 0:
  3454. (maxProfile.ChargingSchedule.Duration-getStartSinceRecurring(maxProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule, FALSE)));
  3455. }
  3456. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  3457. {
  3458. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  3459. {
  3460. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = ((maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceRecurring(maxProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule, FALSE))<0?
  3461. 0:
  3462. (maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceRecurring(maxProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule, FALSE)));
  3463. if(idxPeriod > 0)
  3464. {
  3465. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
  3466. {
  3467. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit = maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit;
  3468. }
  3469. }
  3470. }
  3471. }
  3472. }
  3473. else
  3474. {
  3475. if(maxProfile.ChargingSchedule.Duration != -1)
  3476. {
  3477. maxProfile.ChargingSchedule.Duration = ((maxProfile.ChargingSchedule.Duration-getStartSinceRecurring(maxProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule, TRUE))<0?
  3478. 0:
  3479. (maxProfile.ChargingSchedule.Duration-getStartSinceRecurring(maxProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule, TRUE)));
  3480. }
  3481. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  3482. {
  3483. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  3484. {
  3485. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = ((maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceRecurring(maxProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule, TRUE))<0?
  3486. 0:
  3487. (maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceRecurring(maxProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule, TRUE)));
  3488. if(idxPeriod > 0)
  3489. {
  3490. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
  3491. {
  3492. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit = maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit;
  3493. }
  3494. }
  3495. }
  3496. }
  3497. }
  3498. }
  3499. /*
  3500. DEBUG_INFO("MaxProfile after align.\n");
  3501. DEBUG_INFO("Profile ID: %d\n", maxProfile.ChargingProfileId);
  3502. DEBUG_INFO("Profile stackLevel: %d\n", maxProfile.StackLevel);
  3503. DEBUG_INFO("Profile TransactionId: %d\n", maxProfile.TransactionId);
  3504. DEBUG_INFO("Profile valid from: %s\n", maxProfile.ValidFrom);
  3505. DEBUG_INFO("Profile valid to: %s\n", maxProfile.ValidTo);
  3506. DEBUG_INFO("Profile ChargingProfileKind: %s\n", maxProfile.ChargingProfileKind);
  3507. DEBUG_INFO("Profile recurrencyKind: %s\n", maxProfile.RecurrencyKind);
  3508. DEBUG_INFO("Profile start schedule: %s\n", compositeProfile.ChargingSchedule.StartSchedule);
  3509. DEBUG_INFO("Profile schedule duration: %d\n", maxProfile.ChargingSchedule.Duration);
  3510. DEBUG_INFO("Profile charging rate unit: %s\n", maxProfile.ChargingSchedule.ChargingRateUnit);
  3511. DEBUG_INFO("Profile charging min rate: %f\n", maxProfile.ChargingSchedule.MinChargingRate);
  3512. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  3513. {
  3514. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod >= 0)
  3515. {
  3516. DEBUG_INFO("Period-%02d startPeriod: %d\n", idxPeriod, maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod);
  3517. DEBUG_INFO("Period-%02d limit: %f\n", idxPeriod, maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit);
  3518. DEBUG_INFO("Period-%02d NumberPhases: %d\n", idxPeriod, maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases);
  3519. }
  3520. }
  3521. DEBUG_INFO("------------------------------------\n");*/
  3522. }
  3523. /*
  3524. * Merge to conposite schedule
  3525. */
  3526. //DEBUG_INFO("====================================\n");
  3527. // Find each profile period quantity
  3528. for(int idx=0;idx<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idx++)
  3529. {
  3530. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idx].Limit != -1)
  3531. limitMax = idx+1;
  3532. }
  3533. for(int idx=0;idx<ARRAY_SIZE(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod);idx++)
  3534. {
  3535. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idx].Limit != -1)
  3536. limitDef = idx+1;
  3537. }
  3538. for(int idx=0;idx<ARRAY_SIZE(txProfile.ChargingSchedule.ChargingSchedulePeriod);idx++)
  3539. {
  3540. if(txProfile.ChargingSchedule.ChargingSchedulePeriod[idx].Limit != -1)
  3541. limitTx = idx+1;
  3542. }
  3543. // TxProfile found, composite schedule based on it
  3544. if(txProfile.ChargingProfileId != -1)
  3545. {
  3546. compositeProfile.ChargingSchedule.Duration = txProfile.ChargingSchedule.Duration;
  3547. for(int idxTxPeriod=0;idxTxPeriod<limitTx;idxTxPeriod++)
  3548. {
  3549. if((txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod].Limit != -1) &&
  3550. (txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod].StartPeriod < durationReq) &&
  3551. (txProfile.ChargingSchedule.Duration > 0))
  3552. {
  3553. if(maxProfile.ChargingProfileId != -1)
  3554. {
  3555. for(int idxMaxPeriod=0;idxMaxPeriod<limitMax;idxMaxPeriod++)
  3556. {
  3557. if((txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod].StartPeriod >= maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].StartPeriod))
  3558. {
  3559. if((maxProfile.ChargingSchedule.Duration > 0))
  3560. {
  3561. tmpPeriod.StartPeriod = txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod].StartPeriod;
  3562. tmpPeriod.NumberPhases = txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod].NumberPhases;
  3563. tmpPeriod.Limit = (txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod].Limit>maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].Limit?maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].Limit:txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod].Limit);
  3564. }
  3565. else
  3566. {
  3567. tmpPeriod.StartPeriod = txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod].StartPeriod;
  3568. tmpPeriod.NumberPhases = txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod].NumberPhases;
  3569. tmpPeriod.Limit = txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod].Limit;
  3570. }
  3571. }
  3572. if(idxMaxPeriod == (limitMax-1))
  3573. {
  3574. if(tmpPeriod.Limit != compositeProfile.ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].Limit)
  3575. {
  3576. if(tmpPeriod.StartPeriod != compositeProfile.ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].StartPeriod)
  3577. {
  3578. memcpy(&compositeProfile.ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx], &tmpPeriod , sizeof(struct StructChargingSchedulePeriod));
  3579. compositePeriodIdx++;
  3580. }
  3581. else
  3582. {
  3583. memcpy(&compositeProfile.ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)], &tmpPeriod , sizeof(struct StructChargingSchedulePeriod));
  3584. }
  3585. }
  3586. }
  3587. }
  3588. }
  3589. else
  3590. {
  3591. if(txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod].StartPeriod != compositeProfile.ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].StartPeriod)
  3592. {
  3593. memcpy(&compositeProfile.ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx], &txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod],sizeof(struct StructChargingSchedulePeriod));
  3594. compositePeriodIdx++;
  3595. }
  3596. else
  3597. {
  3598. memcpy(&compositeProfile.ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)], &txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod],sizeof(struct StructChargingSchedulePeriod));
  3599. }
  3600. }
  3601. }
  3602. if(idxTxPeriod == (limitTx-1))
  3603. {
  3604. if(defaultTxProfile.ChargingProfileId != -1)
  3605. {
  3606. compositeProfile.ChargingSchedule.Duration = (defaultTxProfile.ChargingSchedule.Duration>compositeProfile.ChargingSchedule.Duration)?defaultTxProfile.ChargingSchedule.Duration:compositeProfile.ChargingSchedule.Duration;
  3607. for(int idxDefPeriod=0;idxDefPeriod<limitDef;idxDefPeriod++)
  3608. {
  3609. if((defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].StartPeriod >= (txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod].StartPeriod + (txProfile.ChargingSchedule.Duration-defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].StartPeriod))) &&
  3610. (defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].StartPeriod < durationReq) &&
  3611. (defaultTxProfile.ChargingSchedule.Duration>0))
  3612. {
  3613. if(maxProfile.ChargingProfileId != -1)
  3614. {
  3615. for(int idxMaxPeriod=0;idxMaxPeriod<limitMax;idxMaxPeriod++)
  3616. {
  3617. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].StartPeriod >= maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].StartPeriod)
  3618. {
  3619. if((maxProfile.ChargingSchedule.Duration > 0))
  3620. {
  3621. tmpPeriod.StartPeriod = defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].StartPeriod;
  3622. tmpPeriod.NumberPhases = defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].NumberPhases;
  3623. tmpPeriod.Limit = (defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].Limit>maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].Limit?maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].Limit:defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod].Limit);
  3624. }
  3625. else
  3626. {
  3627. tmpPeriod.StartPeriod = defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].StartPeriod;
  3628. tmpPeriod.NumberPhases = defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].NumberPhases;
  3629. tmpPeriod.Limit = defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].Limit;
  3630. }
  3631. if(tmpPeriod.Limit != compositeProfile.ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].Limit)
  3632. {
  3633. if(tmpPeriod.StartPeriod != compositeProfile.ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].StartPeriod)
  3634. {
  3635. memcpy(&compositeProfile.ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx], &tmpPeriod , sizeof(struct StructChargingSchedulePeriod));
  3636. compositePeriodIdx++;
  3637. }
  3638. else
  3639. {
  3640. memcpy(&compositeProfile.ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)], &tmpPeriod , sizeof(struct StructChargingSchedulePeriod));
  3641. }
  3642. }
  3643. // Delete duplicate period
  3644. if(compositePeriodIdx > 1)
  3645. {
  3646. if(compositeProfile.ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx-1].Limit == compositeProfile.ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx-2].Limit)
  3647. {
  3648. compositeProfile.ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx-1].StartPeriod = -1;
  3649. compositeProfile.ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx-1].Limit = -1;
  3650. compositePeriodIdx -= 1;
  3651. }
  3652. }
  3653. }
  3654. else
  3655. {
  3656. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].StartPeriod != compositeProfile.ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].StartPeriod)
  3657. {
  3658. memcpy(&compositeProfile.ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx], &defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod],sizeof(struct StructChargingSchedulePeriod));
  3659. compositePeriodIdx++;
  3660. }
  3661. else
  3662. {
  3663. memcpy(&compositeProfile.ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)], &defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod],sizeof(struct StructChargingSchedulePeriod));
  3664. }
  3665. break;
  3666. }
  3667. }
  3668. }
  3669. else
  3670. {
  3671. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].StartPeriod != compositeProfile.ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].StartPeriod)
  3672. {
  3673. memcpy(&compositeProfile.ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx], &defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod],sizeof(struct StructChargingSchedulePeriod));
  3674. compositePeriodIdx++;
  3675. }
  3676. else
  3677. {
  3678. memcpy(&compositeProfile.ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)], &defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod],sizeof(struct StructChargingSchedulePeriod));
  3679. }
  3680. }
  3681. }
  3682. }
  3683. }
  3684. }
  3685. }
  3686. }
  3687. // TxProfile not found but defaultTxProfile found, composite schedule based on it
  3688. else if(defaultTxProfile.ChargingProfileId != -1)
  3689. {
  3690. compositeProfile.ChargingSchedule.Duration = defaultTxProfile.ChargingSchedule.Duration;
  3691. for(int idxDefPeriod=0;idxDefPeriod<limitDef;idxDefPeriod++)
  3692. {
  3693. if((defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].Limit != -1) &&
  3694. (defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].StartPeriod < durationReq) &&
  3695. (defaultTxProfile.ChargingSchedule.Duration > 0))
  3696. {
  3697. if(maxProfile.ChargingProfileId != -1)
  3698. {
  3699. for(int idxMaxPeriod=0;idxMaxPeriod<limitMax;idxMaxPeriod++)
  3700. {
  3701. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].StartPeriod >= maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].StartPeriod)
  3702. {
  3703. tmpPeriod.StartPeriod = defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].StartPeriod;
  3704. tmpPeriod.NumberPhases = defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].NumberPhases;
  3705. if((maxProfile.ChargingSchedule.Duration > 0))
  3706. {
  3707. tmpPeriod.Limit = (defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].Limit>maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].Limit?maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].Limit:defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].Limit);
  3708. }
  3709. else
  3710. {
  3711. tmpPeriod.Limit = defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].Limit;
  3712. }
  3713. if(tmpPeriod.Limit != compositeProfile.ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].Limit)
  3714. {
  3715. if(tmpPeriod.StartPeriod != compositeProfile.ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].StartPeriod)
  3716. {
  3717. memcpy(&compositeProfile.ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx], &tmpPeriod , sizeof(struct StructChargingSchedulePeriod));
  3718. compositePeriodIdx++;
  3719. }
  3720. else
  3721. {
  3722. memcpy(&compositeProfile.ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)], &tmpPeriod , sizeof(struct StructChargingSchedulePeriod));
  3723. }
  3724. }
  3725. // Delete duplicate period
  3726. if(compositePeriodIdx > 1)
  3727. {
  3728. if(compositeProfile.ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx-1].Limit == compositeProfile.ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx-2].Limit)
  3729. {
  3730. compositeProfile.ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx-1].StartPeriod = -1;
  3731. compositeProfile.ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx-1].Limit = -1;
  3732. compositePeriodIdx -= 1;
  3733. }
  3734. }
  3735. }
  3736. else
  3737. {
  3738. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].StartPeriod != compositeProfile.ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].StartPeriod)
  3739. {
  3740. memcpy(&compositeProfile.ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx], &defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod],sizeof(struct StructChargingSchedulePeriod));
  3741. compositePeriodIdx++;
  3742. }
  3743. else
  3744. {
  3745. memcpy(&compositeProfile.ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)], &defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod],sizeof(struct StructChargingSchedulePeriod));
  3746. }
  3747. break;
  3748. }
  3749. }
  3750. }
  3751. else
  3752. {
  3753. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].StartPeriod != compositeProfile.ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].StartPeriod)
  3754. {
  3755. memcpy(&compositeProfile.ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx], &defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod],sizeof(struct StructChargingSchedulePeriod));
  3756. compositePeriodIdx++;
  3757. }
  3758. else
  3759. {
  3760. memcpy(&compositeProfile.ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)], &defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod],sizeof(struct StructChargingSchedulePeriod));
  3761. }
  3762. }
  3763. }
  3764. }
  3765. }
  3766. // Fill other period by MaxProfile
  3767. if(maxProfile.ChargingProfileId != -1)
  3768. {
  3769. if(compositePeriodIdx==0)
  3770. {
  3771. compositeProfile.ChargingSchedule.Duration = maxProfile.ChargingSchedule.Duration;
  3772. for(int idxMaxPeriod=0;idxMaxPeriod<limitDef;idxMaxPeriod++)
  3773. {
  3774. if((maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].Limit != -1) &&
  3775. (maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].StartPeriod < durationReq) &&
  3776. (maxProfile.ChargingSchedule.Duration > 0))
  3777. {
  3778. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].StartPeriod != compositeProfile.ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].StartPeriod)
  3779. {
  3780. memcpy(&compositeProfile.ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx], &maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod],sizeof(struct StructChargingSchedulePeriod));
  3781. compositePeriodIdx++;
  3782. }
  3783. else
  3784. {
  3785. memcpy(&compositeProfile.ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)], &maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod],sizeof(struct StructChargingSchedulePeriod));
  3786. }
  3787. }
  3788. }
  3789. }
  3790. else
  3791. {
  3792. int lastCompositePeriodIdx = compositePeriodIdx;
  3793. for(int idxMaxPeriod=0;idxMaxPeriod<limitMax;idxMaxPeriod++)
  3794. {
  3795. if((maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].Limit != -1) &&
  3796. (maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].StartPeriod < durationReq) &&
  3797. (maxProfile.ChargingSchedule.Duration > 0))
  3798. {
  3799. if((maxProfile.ChargingSchedule.Duration >= compositeProfile.ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx-1].StartPeriod))
  3800. {
  3801. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].Limit > compositeProfile.ChargingSchedule.ChargingSchedulePeriod[lastCompositePeriodIdx-1].Limit)
  3802. {
  3803. tmpPeriod.StartPeriod = maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].StartPeriod;
  3804. tmpPeriod.NumberPhases = maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].NumberPhases;
  3805. tmpPeriod.Limit = compositeProfile.ChargingSchedule.ChargingSchedulePeriod[lastCompositePeriodIdx-1].Limit;
  3806. }
  3807. else
  3808. {
  3809. tmpPeriod.StartPeriod = maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].StartPeriod;
  3810. tmpPeriod.NumberPhases = maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].NumberPhases;
  3811. tmpPeriod.Limit = maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].Limit;
  3812. }
  3813. }
  3814. if(tmpPeriod.Limit != -1)
  3815. {
  3816. if(tmpPeriod.Limit != compositeProfile.ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx-1].Limit)
  3817. {
  3818. if(tmpPeriod.StartPeriod != compositeProfile.ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx-1].StartPeriod)
  3819. {
  3820. memcpy(&compositeProfile.ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx], &tmpPeriod , sizeof(struct StructChargingSchedulePeriod));
  3821. compositePeriodIdx++;
  3822. }
  3823. else
  3824. {
  3825. memcpy(&compositeProfile.ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx-1], &tmpPeriod , sizeof(struct StructChargingSchedulePeriod));
  3826. }
  3827. }
  3828. // Delete duplicate period
  3829. if(compositePeriodIdx > 1)
  3830. {
  3831. if(compositeProfile.ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx-1].Limit == compositeProfile.ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx-2].Limit)
  3832. {
  3833. compositeProfile.ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx-1].StartPeriod = -1;
  3834. compositeProfile.ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx-1].Limit = -1;
  3835. compositePeriodIdx -= 1;
  3836. }
  3837. }
  3838. }
  3839. }
  3840. }
  3841. }
  3842. }
  3843. compositeProfile.ChargingSchedule.Duration = durationReq;
  3844. DEBUG_INFO("Connector-%d composite schedule ready.\n", connectorId);
  3845. DEBUG_INFO("Schedule start: %s\n", compositeProfile.ChargingSchedule.StartSchedule);
  3846. DEBUG_INFO("Schedule duration: %d\n", compositeProfile.ChargingSchedule.Duration);
  3847. DEBUG_INFO("Rate unit: %s\n", compositeProfile.ChargingSchedule.ChargingRateUnit);
  3848. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(compositeProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  3849. {
  3850. if(compositeProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod >= 0)
  3851. {
  3852. compositeProfile.ChargingProfileId = 1;
  3853. DEBUG_INFO("Period-%02d startPeriod: %d\n", idxPeriod, compositeProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod);
  3854. DEBUG_INFO("Period-%02d limit: %f\n", idxPeriod, compositeProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit);
  3855. DEBUG_INFO("Period-%02d NumberPhases: %d\n", idxPeriod, compositeProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases);
  3856. }
  3857. if(compositeProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit == -1)
  3858. compositeProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit =0;
  3859. if(compositeProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod == -1)
  3860. compositeProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod =0;
  3861. }
  3862. memcpy(targetCompositeProfile, &compositeProfile, sizeof(struct StructChargingProfile));
  3863. if(line)
  3864. free(line);
  3865. checkChargePointMaxProfile(durationReq, &ShmOCPP16Data->MaxChargingProfile, isUnitA);
  3866. ShmOCPP16Data->CSUMsg.bits[(connectorId==0?0:connectorId-1)].ChargingProfileConf = 1;
  3867. }
  3868. //==========================================
  3869. // Init all share memory
  3870. //==========================================
  3871. int InitShareMemory()
  3872. {
  3873. int result = PASS;
  3874. int MeterSMId;
  3875. //creat ShmSysConfigAndInfo
  3876. if ((MeterSMId = shmget(ShmSysConfigAndInfoKey, sizeof(struct SysConfigAndInfo), 0777)) < 0)
  3877. {
  3878. DEBUG_ERROR("shmget ShmSysConfigAndInfo NG\n");
  3879. result = FAIL;
  3880. }
  3881. else if ((ShmSysConfigAndInfo = shmat(MeterSMId, NULL, 0)) == (void *) -1)
  3882. {
  3883. DEBUG_ERROR("shmat ShmSysConfigAndInfo NG\n");
  3884. result = FAIL;
  3885. }
  3886. else
  3887. {}
  3888. if ((MeterSMId = shmget(ShmStatusCodeKey, sizeof(struct StatusCodeData), 0777)) < 0)
  3889. {
  3890. DEBUG_ERROR("shmget ShmStatusCodeData NG\n");
  3891. result = FAIL;
  3892. }
  3893. else if ((ShmStatusCodeData = shmat(MeterSMId, NULL, 0)) == (void *) -1)
  3894. {
  3895. DEBUG_ERROR("shmat ShmStatusCodeData NG\n");
  3896. result = FAIL;
  3897. }
  3898. else
  3899. {}
  3900. //creat ShmPsuData
  3901. if ((MeterSMId = shmget(ShmPsuKey, sizeof(struct PsuData), 0777)) < 0)
  3902. {
  3903. DEBUG_ERROR("shmget ShmPsuData NG\n");
  3904. result = FAIL;
  3905. }
  3906. else if ((ShmPsuData = shmat(MeterSMId, NULL, 0)) == (void *) -1)
  3907. {
  3908. DEBUG_ERROR("shmat ShmPsuData NG\n");
  3909. result = FAIL;
  3910. }
  3911. else
  3912. {}
  3913. //creat ShmOCPP16Data
  3914. if ((MeterSMId = shmget(ShmOcppModuleKey, sizeof(struct OCPP16Data), 0777)) < 0)
  3915. {
  3916. DEBUG_ERROR("shmget ShmOCPP16Data NG\n");
  3917. result = FAIL;
  3918. }
  3919. else if ((ShmOCPP16Data = shmat(MeterSMId, NULL, 0)) == (void *) -1)
  3920. {
  3921. DEBUG_ERROR("shmat ShmOCPP16Data NG\n");
  3922. result = FAIL;
  3923. }
  3924. else
  3925. {}
  3926. /****************************** For Initial Settings************************************************/
  3927. ShmOCPP16Data->GetConfiguration.ResponseUnknownKey = NULL;
  3928. ShmOCPP16Data->SendLocalList.LocalAuthorizationList = NULL;
  3929. // allocate Configuration memory address
  3930. ShmOCPP16Data->GetConfiguration.Key = staticKeyArray;
  3931. ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey = staticResponseConfigurationKeyArray;
  3932. ShmOCPP16Data->GetConfiguration.ResponseUnknownKey = staticResponseUnknownKey;
  3933. ShmOCPP16Data->SendLocalList.LocalAuthorizationList = staticLocalAuthorizationList;
  3934. sprintf((char*)ShmOCPP16Data->FirmwareStatusNotification.Status, "%s",FirmwareStatusStr[FirmwareStatus_Idle]);
  3935. //offline MeterValue Interval
  3936. TempMeterValueInterval = 0;
  3937. return result;
  3938. }
  3939. int ProcessShareMemory()
  3940. {
  3941. int result = PASS;
  3942. if(InitShareMemory() == FAIL)
  3943. {
  3944. DEBUG_ERROR("InitShareMemory NG\n");
  3945. if(ShmStatusCodeData!=NULL)
  3946. {
  3947. ShmStatusCodeData->AlarmCode.AlarmEvents.bits.FailToCreateShareMemory=1;
  3948. }
  3949. result = FAIL;
  3950. }
  3951. // Model name parsing
  3952. if(RatedCurrentParsing((char*)ShmSysConfigAndInfo->SysConfig.ModelName, &modelnameInfo) != -1)
  3953. {
  3954. DEBUG_INFO("Model name rated power: %d\n", modelnameInfo.ratedPower);
  3955. if((ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D') &&
  3956. ((ShmSysConfigAndInfo->SysConfig.ModelName[1]=='B') ||
  3957. (ShmSysConfigAndInfo->SysConfig.ModelName[1]=='K') ||
  3958. (ShmSysConfigAndInfo->SysConfig.ModelName[1]=='O'))
  3959. ) // 'D' means DC
  3960. {
  3961. // DO series
  3962. for(int gun_index=0; gun_index<GENERAL_GUN_QUANTITY ; gun_index++)
  3963. {
  3964. gunTotalNumber += 1;
  3965. gunType[gun_index] = GUN_TYPE_DO;
  3966. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  3967. {
  3968. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == gun_index)
  3969. {
  3970. periousPeriodicPowerConsumption[gun_index] = ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PowerConsumption;
  3971. periousClockPowerConsumption[gun_index] = ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PowerConsumption;
  3972. DEBUG_INFO("Gun-%02d PowerConsumption: %.3f\n", gun_index, ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PowerConsumption);
  3973. }
  3974. }
  3975. switch(modelnameInfo.ParsingInfo[gun_index].GunType)
  3976. {
  3977. case Gun_Type_Chademo:
  3978. DEBUG_INFO("Gun-%02d type: Cabinet CHAdeMO\n", gun_index);
  3979. break;
  3980. case Gun_Type_CCS_2:
  3981. DEBUG_INFO("Gun-%02d type: Cabinet CCS\n", gun_index);
  3982. break;
  3983. case Gun_Type_GB:
  3984. DEBUG_INFO("Gun-%02d type: Cabinet GBT\n", gun_index);
  3985. break;
  3986. case Gun_Type_AC:
  3987. DEBUG_INFO("Gun-%02d type: Cabinet AC\n", gun_index);
  3988. break;
  3989. default:
  3990. DEBUG_WARN("Gun-%02d type: Cabinet unknown\n", gun_index);
  3991. break;
  3992. }
  3993. }
  3994. }
  3995. else
  3996. {
  3997. for(int gun_index=0;gun_index<modelnameInfo.GetGunCount;gun_index++)
  3998. {
  3999. gunTotalNumber += 1;
  4000. switch(modelnameInfo.ParsingInfo[gun_index].GunType)
  4001. {
  4002. case Gun_Type_Chademo:
  4003. gunType[gun_index] = GUN_TYPE_CHAdeMO;
  4004. DEBUG_INFO("Gun-%02d type: CHAdeMO\n", gun_index);
  4005. for(int index = 0; index < CHAdeMO_QUANTITY; index++)
  4006. {
  4007. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == gun_index)
  4008. {
  4009. periousPeriodicPowerConsumption[gun_index] = ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PowerConsumption;
  4010. periousClockPowerConsumption[gun_index] = ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PowerConsumption;
  4011. DEBUG_INFO("Gun-%02d PowerConsumption: %.3f\n", gun_index, ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PowerConsumption);
  4012. }
  4013. }
  4014. break;
  4015. case Gun_Type_CCS_2:
  4016. gunType[gun_index] = GUN_TYPE_CCS;
  4017. DEBUG_INFO("Gun-%02d type: CCS\n", gun_index);
  4018. for (int index = 0; index < CCS_QUANTITY; index++)
  4019. {
  4020. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == gun_index)
  4021. {
  4022. periousPeriodicPowerConsumption[gun_index] = ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PowerConsumption;
  4023. periousClockPowerConsumption[gun_index] = ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PowerConsumption;
  4024. DEBUG_INFO("Gun-%02d PowerConsumption: %.3f\n", gun_index, ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PowerConsumption);
  4025. }
  4026. }
  4027. break;
  4028. case Gun_Type_GB:
  4029. gunType[gun_index] = GUN_TYPE_GBT;
  4030. DEBUG_INFO("Gun-%02d type: GBT\n", gun_index);
  4031. for (int index = 0; index < GB_QUANTITY; index++)
  4032. {
  4033. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == gun_index)
  4034. {
  4035. periousPeriodicPowerConsumption[gun_index] = ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PowerConsumption;
  4036. periousClockPowerConsumption[gun_index] = ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PowerConsumption;
  4037. DEBUG_INFO("Gun-%02d PowerConsumption: %.3f\n", gun_index, ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PowerConsumption);
  4038. }
  4039. }
  4040. break;
  4041. case Gun_Type_AC:
  4042. gunType[gun_index] = GUN_TYPE_AC;
  4043. DEBUG_INFO("Gun-%02d type: AC\n", gun_index);
  4044. for (int index = 0; index < AC_QUANTITY; index++)
  4045. {
  4046. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == gun_index)
  4047. {
  4048. periousPeriodicPowerConsumption[gun_index] = ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PowerConsumption;
  4049. periousClockPowerConsumption[gun_index] = ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PowerConsumption;
  4050. DEBUG_INFO("Gun-%02d PowerConsumption: %.3f\n", gun_index, ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PowerConsumption);
  4051. }
  4052. }
  4053. break;
  4054. default:
  4055. DEBUG_WARN("Gun-%02d type: Unknown\n", gun_index);
  4056. break;
  4057. }
  4058. }
  4059. }
  4060. }
  4061. else
  4062. {
  4063. DEBUG_ERROR("Model name parsing fail.\n");
  4064. result = FAIL;
  4065. }
  4066. if(result != PASS)sleep(5);
  4067. return result;
  4068. }
  4069. void checkRemoteStart(uint8_t connectorIdInt)
  4070. {
  4071. uint8_t tempIndex;
  4072. int result = PASS;
  4073. char cmdBuf[512];
  4074. //check Transaction active
  4075. if(gunType[connectorIdInt -1] == GUN_TYPE_CHAdeMO)
  4076. {
  4077. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4078. {
  4079. tempIndex = ((connectorIdInt -1) == 2) ? 1: 0;
  4080. }
  4081. else
  4082. {
  4083. tempIndex = connectorIdInt -1;
  4084. }
  4085. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  4086. {
  4087. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  4088. {
  4089. if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ReservationId != -1) &&
  4090. (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ReservationId >= 0) &&
  4091. (strcmp((const char *)ShmOCPP16Data->ReserveNow[index].IdTag, (char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag) == 0))
  4092. {
  4093. //Reserved
  4094. DEBUG_INFO("CHAdeMO connector already reserved and idTag match.\n");
  4095. }
  4096. else if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ReservationId != -1) &&
  4097. (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ReservationId >= 0) &&
  4098. (strcmp((const char *)ShmOCPP16Data->ReserveNow[index].IdTag, (char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag) != 0))
  4099. {
  4100. //Reserved
  4101. DEBUG_INFO("CHAdeMO connector already reserved and idTag does not match.\n");
  4102. result = FAIL;
  4103. goto end;
  4104. }
  4105. else
  4106. {
  4107. if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  4108. && (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_PREPARING ) //S_PRECHARGE
  4109. && (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EV ) //S_PREPARING_FOR_EV
  4110. && (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EVSE )) // S_PREPARING_FOR_EVSE
  4111. {
  4112. DEBUG_WARN("CHAdeMO connector not allow start cause busy.\n");
  4113. result = FAIL;
  4114. goto end;
  4115. }
  4116. }//END FOR ELSE
  4117. }
  4118. }// END FOR CHAdeMO_QUANTITY
  4119. }
  4120. else if(gunType[connectorIdInt -1] == GUN_TYPE_CCS)
  4121. {
  4122. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4123. {
  4124. tempIndex = ((connectorIdInt -1) == 2) ? 1: 0;
  4125. }
  4126. else
  4127. {
  4128. tempIndex = connectorIdInt -1;
  4129. }
  4130. for (int index = 0; index < CCS_QUANTITY; index++)
  4131. {
  4132. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  4133. {
  4134. if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ReservationId != -1) &&
  4135. (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ReservationId >= 0) &&
  4136. (strcmp((const char *)ShmOCPP16Data->ReserveNow[index].IdTag, (char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag) == 0))
  4137. {
  4138. //Reserved
  4139. DEBUG_INFO("CCS connector already reserved and idTag match.\n");
  4140. }
  4141. else if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ReservationId != -1) &&
  4142. (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ReservationId >= 0) &&
  4143. (strcmp((const char *)ShmOCPP16Data->ReserveNow[index].IdTag, (char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag) != 0))
  4144. {
  4145. //Reserved
  4146. DEBUG_INFO("CCS connector already reserved and idTag does not match.\n");
  4147. result = FAIL;
  4148. goto end;
  4149. }
  4150. else
  4151. {
  4152. if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  4153. && (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_PREPARING) //S_PRECHARGE
  4154. && (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EV) //S_PREPARING_FOR_EV
  4155. && (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EVSE)) // S_PREPARING_FOR_EVSE
  4156. {
  4157. DEBUG_WARN("CCS connector not allow start cause busy.\n.");
  4158. result = FAIL;
  4159. goto end;
  4160. }
  4161. }// END FOR ELSE
  4162. }
  4163. }// END FOR CCS_QUANTITY
  4164. }
  4165. else if(gunType[connectorIdInt -1] == GUN_TYPE_GBT)
  4166. {
  4167. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4168. {
  4169. tempIndex = ((connectorIdInt -1) == 2) ? 1: 0;
  4170. }
  4171. else
  4172. {
  4173. tempIndex = connectorIdInt -1;
  4174. }
  4175. for (int index = 0; index < GB_QUANTITY; index++)
  4176. {
  4177. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex )
  4178. {
  4179. if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ReservationId != -1) &&
  4180. (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ReservationId >= 0) &&
  4181. (strcmp((const char *)ShmOCPP16Data->ReserveNow[index].IdTag, (char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag) == 0))
  4182. {
  4183. //Reserved
  4184. DEBUG_INFO("GBT connector already reserved and idTag match.\n");
  4185. }
  4186. else if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ReservationId != -1) &&
  4187. (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ReservationId >= 0) &&
  4188. (strcmp((const char *)ShmOCPP16Data->ReserveNow[index].IdTag, (char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag) != 0))
  4189. {
  4190. //Reserved
  4191. DEBUG_INFO("GBT connector already reserved and idTag does not match.\n");
  4192. result = FAIL;
  4193. goto end;
  4194. }
  4195. else
  4196. {
  4197. if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  4198. && (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_PREPARING) //S_PRECHARGE
  4199. && (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EV) //S_PREPARING_FOR_EV
  4200. && (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EVSE)) // S_PREPARING_FOR_EVSE
  4201. {
  4202. DEBUG_WARN("GBT connector not allow start cause busy.\n");
  4203. result = FAIL;
  4204. goto end;
  4205. }
  4206. }// END FOR ELSE
  4207. }
  4208. } // END FOR GB_QUANTITY
  4209. }
  4210. else if(gunType[connectorIdInt -1] == GUN_TYPE_DO)
  4211. {
  4212. tempIndex = connectorIdInt -1;
  4213. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  4214. {
  4215. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex )
  4216. {
  4217. if((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.ReservationId != -1) &&
  4218. (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.ReservationId >= 0) &&
  4219. (strcmp((const char *)ShmOCPP16Data->ReserveNow[index].IdTag, (char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag) == 0))
  4220. {
  4221. //Reserved
  4222. DEBUG_INFO("Dispenser connector already reserved and idTag match.\n");
  4223. }
  4224. else if((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.ReservationId != -1) &&
  4225. (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.ReservationId >= 0) &&
  4226. (strcmp((const char *)ShmOCPP16Data->ReserveNow[index].IdTag, (char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag) != 0))
  4227. {
  4228. //Reserved
  4229. DEBUG_INFO("Dispenser connector already reserved and idTag does not match.\n");
  4230. result = FAIL;
  4231. goto end;
  4232. }
  4233. else
  4234. {
  4235. if((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus != SYS_MODE_IDLE) //S_IDLE
  4236. && (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus != SYS_MODE_PREPARING) //S_PRECHARGE
  4237. && (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus != SYS_MODE_PREPARE_FOR_EV) //S_PREPARING_FOR_EV
  4238. && (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus != SYS_MODE_PREPARE_FOR_EVSE)) // S_PREPARING_FOR_EVSE
  4239. {
  4240. DEBUG_WARN("Dispenser connector not allow start cause busy.\n");
  4241. result = FAIL;
  4242. goto end;
  4243. }
  4244. }// END FOR ELSE
  4245. }
  4246. } // END FOR GB_QUANTITY
  4247. }
  4248. else
  4249. {
  4250. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D') // 'D' means DC
  4251. {
  4252. tempIndex = 2;
  4253. }
  4254. else
  4255. {
  4256. tempIndex = connectorIdInt -1;
  4257. }
  4258. for (int index = 0; index < AC_QUANTITY; index++)
  4259. {
  4260. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex )
  4261. {
  4262. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].ReservationId != -1) &&
  4263. (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].ReservationId >= 0) &&
  4264. (strcmp((const char *)ShmOCPP16Data->ReserveNow[index].IdTag, (char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag) == 0))
  4265. {
  4266. //Reserved
  4267. DEBUG_INFO("AC connector already reserved and idTag match.\n");
  4268. }
  4269. else if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].ReservationId != -1) &&
  4270. (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].ReservationId >= 0) &&
  4271. (strcmp((const char *)ShmOCPP16Data->ReserveNow[index].IdTag, (char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag) != 0))
  4272. {
  4273. //Reserved
  4274. DEBUG_INFO("AC connector already reserved and idTag does not match.\n");
  4275. result = FAIL;
  4276. goto end;
  4277. }
  4278. else
  4279. {
  4280. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  4281. && (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_PREPARING) //S_PRECHARGE
  4282. && (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EV) //S_PREPARING_FOR_EV
  4283. && (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EVSE)) // S_PREPARING_FOR_EVSE
  4284. {
  4285. DEBUG_WARN("AC connector not allow start cause busy.\n");
  4286. result = FAIL;
  4287. goto end;
  4288. }
  4289. }//END FOR ELSE
  4290. }
  4291. }// END FOR AC_QUANTITY
  4292. }
  4293. if(ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingProfileId > -1)
  4294. {
  4295. if(strcmp((char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingProfilePurpose, ChargingProfilePurposeTypeStr[TxProfile]) == 0)
  4296. {
  4297. if((access("/Storage/OCPP/TxProfile_Tmp.json", F_OK))!=-1)
  4298. {
  4299. sprintf(cmdBuf, "mv /Storage/OCPP/TxProfile_Tmp.json /Storage/OCPP/TxProfile_%d.json", connectorIdInt);
  4300. system(cmdBuf);
  4301. }
  4302. }
  4303. else
  4304. {
  4305. DEBUG_WARN("Profile purpose not TxProfile.\n.");
  4306. result = FAIL;
  4307. }
  4308. }
  4309. end:
  4310. if(result == PASS)
  4311. {
  4312. ShmOCPP16Data->CsMsg.bits[connectorIdInt -1].RemoteStartTransactionReq = 1;
  4313. memset((char *)ShmOCPP16Data->StartTransaction[connectorIdInt -1].IdTag, 0, 20);
  4314. strcpy((char *)ShmOCPP16Data->StartTransaction[connectorIdInt -1].IdTag, (char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag);
  4315. memset((char *)ShmOCPP16Data->StopTransaction[connectorIdInt -1].IdTag, 0, 20);
  4316. strcpy((char *)ShmOCPP16Data->StopTransaction[connectorIdInt -1].IdTag, (char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag);
  4317. }
  4318. }
  4319. void CheckSystemValue(void)
  4320. {
  4321. char filenmae[100]={0};
  4322. char str[100]={0};
  4323. int tempIndex = 0;
  4324. //===============================
  4325. // send Heartbeat
  4326. //===============================
  4327. if((server_sign == TRUE) && (getDiffSecNow(clientTime.Heartbeat) >= (HeartBeatWaitTime + HeartBeatWithNOResponse)))
  4328. {
  4329. //parameter for test
  4330. sendHeartbeatRequest(0);
  4331. //===========================
  4332. // Reset Waiting Time
  4333. //===========================
  4334. HeartBeatWithNOResponse += 1;
  4335. }
  4336. //===============================
  4337. // Credit deduct report
  4338. //===============================
  4339. if(ShmOCPP16Data->TcciCustomData.ReportCreditDeductReq)
  4340. {
  4341. OCPP_insert_deduct_info(ShmOCPP16Data->TcciCustomData.DeductInfo.txId, (char*)ShmOCPP16Data->TcciCustomData.DeductInfo.creditNo,
  4342. ShmOCPP16Data->TcciCustomData.DeductInfo.deductResult, ShmOCPP16Data->TcciCustomData.DeductInfo.isDonateInvoice,
  4343. ShmOCPP16Data->TcciCustomData.DeductInfo.amount, (char*)ShmOCPP16Data->TcciCustomData.DeductInfo.vemData,
  4344. (char*)ShmOCPP16Data->TcciCustomData.DeductInfo.ROC,(char*)ShmOCPP16Data->TcciCustomData.DeductInfo.RRN,
  4345. (char*)ShmOCPP16Data->TcciCustomData.DeductInfo.approvalNo,(char*)ShmOCPP16Data->TcciCustomData.DeductInfo.storeId);
  4346. ShmOCPP16Data->TcciCustomData.ReportCreditDeductReq = FALSE;
  4347. }
  4348. if(getDiffSecNow(clientTime.TcciQueryDeduct) > 5)
  4349. {
  4350. OCPP_query_deduct_info();
  4351. refreshStartTimer(&clientTime.TcciQueryDeduct);
  4352. }
  4353. for(int gun_index=0;gun_index < gunTotalNumber;gun_index++)
  4354. {
  4355. // ClockAlign MeterValue
  4356. if((server_sign == TRUE) && ((atoi((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemData) > 0)?((getTimePassSinceToday(gun_index)%(atoi((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemData)))==0):FALSE))
  4357. {
  4358. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  4359. {
  4360. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4361. {
  4362. tempIndex = ((gun_index==2) ? 1: 0);
  4363. }
  4364. else
  4365. {
  4366. tempIndex = gun_index;
  4367. }
  4368. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  4369. {
  4370. // 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault
  4371. if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  4372. {
  4373. reqClockAlignMeter[gun_index] = 1;
  4374. }
  4375. }// End for CHAdeMO
  4376. }
  4377. else if(gunType[gun_index] == GUN_TYPE_CCS)
  4378. {
  4379. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4380. {
  4381. tempIndex = ((gun_index==2) ? 1: 0);
  4382. }
  4383. else
  4384. {
  4385. tempIndex = gun_index;
  4386. }
  4387. for (int index = 0; index < CCS_QUANTITY; index++)
  4388. {
  4389. // 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault
  4390. if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  4391. {
  4392. reqClockAlignMeter[gun_index] = 1;
  4393. }
  4394. } // End for CCS
  4395. }
  4396. else if(gunType[gun_index] == GUN_TYPE_GBT)
  4397. {
  4398. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4399. {
  4400. tempIndex = ((gun_index==2) ? 1: 0);
  4401. }
  4402. else
  4403. {
  4404. tempIndex = gun_index;
  4405. }
  4406. for (int index = 0; index < GB_QUANTITY; index++)
  4407. {
  4408. // 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault
  4409. if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  4410. {
  4411. reqClockAlignMeter[gun_index] = 1;
  4412. }
  4413. }// End for GB
  4414. }
  4415. else if(gunType[gun_index] == GUN_TYPE_DO)
  4416. {
  4417. tempIndex = gun_index;
  4418. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  4419. {
  4420. // 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault
  4421. if(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  4422. {
  4423. reqClockAlignMeter[gun_index] = 1;
  4424. }
  4425. }
  4426. }
  4427. else
  4428. {
  4429. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  4430. {
  4431. tempIndex = 2;
  4432. }
  4433. else
  4434. {
  4435. tempIndex = gun_index;
  4436. }
  4437. for (int index = 0; index < AC_QUANTITY; index++)
  4438. {
  4439. // 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault
  4440. if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  4441. {
  4442. reqClockAlignMeter[gun_index] = 1;
  4443. }
  4444. }//End for AC
  4445. }
  4446. }
  4447. }
  4448. for(int gun_index=0;gun_index < gunTotalNumber ;gun_index++)
  4449. {
  4450. //==========================================
  4451. // Check remote start without connector id
  4452. //==========================================
  4453. if(ShmOCPP16Data->MsMsg.bits.isRemoteStartWaitReq)
  4454. {
  4455. int connectorIdInt = -1;
  4456. for(uint8_t gun_index=0;gun_index<gunTotalNumber;gun_index++)
  4457. {
  4458. if(!cpinitateMsg.bits[gun_index].isOnCharging && (strstr((char*)ShmOCPP16Data->StatusNotification[gun_index].Status, "Preparing") != NULL))
  4459. {
  4460. connectorIdInt = (gun_index+1);
  4461. DEBUG_INFO("Detect connector-%02d connected ready to start.\n", connectorIdInt);
  4462. checkRemoteStart(connectorIdInt);
  4463. ShmOCPP16Data->MsMsg.bits.isRemoteStartWaitReq = 0;
  4464. break;
  4465. }
  4466. }
  4467. if(getDiffSecNow(clientTime.RemoteStartWait) > atoi((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemData))
  4468. {
  4469. DEBUG_WARN("Remote start request without connector id wait link over %s seconds.\n", ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemData);
  4470. ShmOCPP16Data->MsMsg.bits.isRemoteStartWaitReq = 0;
  4471. }
  4472. }
  4473. //==========================================
  4474. // csu trigger DataTransferReq
  4475. //==========================================
  4476. if(isWebsocketSendable && (server_sign == TRUE) && (ShmOCPP16Data->CsMsg.bits[gun_index].DataTransferReq == 1))
  4477. {
  4478. sendDataTransferRequest(gun_index);
  4479. ShmOCPP16Data->CsMsg.bits[gun_index].DataTransferReq = 0;
  4480. }
  4481. //==========================================
  4482. // CSU Trigger Authorize Request
  4483. //==========================================
  4484. if(isWebsocketSendable && (server_sign == TRUE) && (ShmOCPP16Data->SpMsg.bits.AuthorizeReq == 1)&&(authorizeRetryTimes < 3))
  4485. {
  4486. sendAuthorizeRequest(0);
  4487. authorizeRetryTimes = authorizeRetryTimes + 1;
  4488. if(authorizeRetryTimes < 3)
  4489. ShmOCPP16Data->SpMsg.bits.AuthorizeReq = 0;
  4490. }
  4491. else if((server_sign == TRUE) && (ShmOCPP16Data->SpMsg.bits.AuthorizeReq == 1) && (authorizeRetryTimes >= 3))
  4492. {
  4493. authorizeRetryTimes = 0;
  4494. SetOcppConnStatus(FALSE);
  4495. server_sign = FALSE;
  4496. }
  4497. 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))
  4498. {
  4499. sendAuthorizeRequest(0);
  4500. }
  4501. //==========================================
  4502. // Charger start transaction
  4503. //==========================================
  4504. if(/*(server_sign == TRUE) &&*/ (ShmOCPP16Data->CpMsg.bits[gun_index].StartTransactionReq == 1))
  4505. {
  4506. ShmOCPP16Data->CpMsg.bits[gun_index].StartTransactionReq = 0;
  4507. sendStartTransactionRequest(gun_index);
  4508. refreshStartTimer(&clientTime.StartTransaction);
  4509. refreshStartTimer(&clientTime.MeterValues[gun_index]);
  4510. storeTempStopTransaction(gun_index);
  4511. }
  4512. //==========================================
  4513. // Charger stop transaction
  4514. //==========================================
  4515. if(/*(server_sign == TRUE) &&*/ ((ShmOCPP16Data->CpMsg.bits[gun_index].StopTransactionReq == 1)))
  4516. {
  4517. ShmOCPP16Data->CpMsg.bits[gun_index].StopTransactionReq = 0;
  4518. sendStopTransactionRequest(gun_index);
  4519. OCPP_updatePeriodEnergy(gun_index);
  4520. if(ShmSysConfigAndInfo->SysConfig.TTIA_Info.isEnableTTIA && (gunType[gun_index] != GUN_TYPE_AC) )sendTTIAInfo(gun_index);
  4521. refreshStartTimer(&clientTime.StopTransaction);
  4522. memset(&ShmOCPP16Data->SessionTarget[gun_index], 0x00, sizeof(struct StructSessionTarget));
  4523. }
  4524. //==========================================
  4525. // Charger OCMF message
  4526. //==========================================
  4527. if(/*(server_sign == TRUE) &&*/ ((ShmOCPP16Data->OcmfData[gun_index].SendOcmfDataReq == 1)))
  4528. {
  4529. sendOcmfByDataTransferRequest(gun_index);
  4530. ShmOCPP16Data->OcmfData[gun_index].SendOcmfDataReq = 0;
  4531. }
  4532. //==========================================
  4533. // Charger status report
  4534. //==========================================
  4535. //--- Check Mode Change ---//
  4536. // J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DCcc
  4537. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  4538. {
  4539. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4540. {
  4541. tempIndex = ((gun_index==2) ? 1: 0);
  4542. }
  4543. else
  4544. {
  4545. tempIndex = gun_index;
  4546. }
  4547. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  4548. {
  4549. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  4550. {
  4551. if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != ChademoPreviousSystemStatus[index]) || (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ConnectorPlugIn != ChademoPreviousConnectorPlugIn[index]) )
  4552. {
  4553. // Sent unplug message for California pricing logic
  4554. if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_COMPLETE) && (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ConnectorPlugIn == 0) && !interLock.isSentUnplug[gun_index])
  4555. {
  4556. uint8_t ts[36];
  4557. getNowDatetime(ts);
  4558. sprintf((char*)ShmOCPP16Data->DataTransfer[gun_index].VendorId, "org.openchargealliance.costmsg");
  4559. sprintf((char*)ShmOCPP16Data->DataTransfer[gun_index].MessageId, "ConnectorUnplugged");
  4560. if(strcmp((char*)dmsVersion, "2.0")==0)
  4561. sprintf((char*)ShmOCPP16Data->DataTransfer[gun_index].Data, "{\\\"transactionId\\\":%d,\\\"timestamp\\\":\\\"%s\\\"}", ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId, ts);
  4562. else
  4563. sprintf((char*)ShmOCPP16Data->DataTransfer[gun_index].Data, "{\\\"idTx\\\":%d,\\\"timestamp\\\":\\\"%s\\\"}", ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId, ts);
  4564. sendUnplugByDataTransferRequest(gun_index);
  4565. interLock.isSentUnplug[gun_index] = 1;
  4566. }
  4567. else if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_IDLE))
  4568. {
  4569. interLock.isSentUnplug[gun_index] = 0;
  4570. }
  4571. ChademoPreviousSystemStatus[index] = ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus;
  4572. ChademoPreviousConnectorPlugIn[index] = ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ConnectorPlugIn;
  4573. cpinitateMsg.bits[gun_index].StatusNotificationReq = 1;
  4574. if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex) && ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_COMPLETE) || (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus <= SYS_MODE_IDLE))) // complete
  4575. {
  4576. sprintf(filenmae,"/Storage/OCPP/TxProfile_%d.json",(gun_index+1));
  4577. if((access(filenmae,F_OK))!=-1)
  4578. {
  4579. DEBUG_INFO("TxProfile exist. OCPP will delete TX Charging Profile\n");
  4580. sprintf(str,"rm -f %s",filenmae);
  4581. system(str);
  4582. }
  4583. }
  4584. }
  4585. cpinitateMsg.bits[gun_index].isOnCharging = ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_TERMINATING)?1:0);
  4586. #if 1 // for TempStopTransaction
  4587. if(((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_BOOTING) || (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_IDLE)) &&
  4588. (ShmOCPP16Data->CpMsg.bits[gun_index].StopTransactionReq == 0))
  4589. {
  4590. checkTempStopTransaction(gun_index);
  4591. }
  4592. #endif
  4593. }
  4594. }
  4595. }
  4596. else if(gunType[gun_index] == GUN_TYPE_CCS)
  4597. {
  4598. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4599. {
  4600. tempIndex = ((gun_index==2) ? 1: 0);
  4601. }
  4602. else
  4603. {
  4604. tempIndex = gun_index;
  4605. }
  4606. for (int index = 0; index < CCS_QUANTITY; index++)
  4607. {
  4608. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  4609. {
  4610. 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]*/ )
  4611. {
  4612. // Sent unplug message for California pricing logic
  4613. if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_COMPLETE) && (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ConnectorPlugIn == 0) && !interLock.isSentUnplug[gun_index])
  4614. {
  4615. uint8_t ts[36];
  4616. getNowDatetime(ts);
  4617. sprintf((char*)ShmOCPP16Data->DataTransfer[gun_index].VendorId, "org.openchargealliance.costmsg");
  4618. sprintf((char*)ShmOCPP16Data->DataTransfer[gun_index].MessageId, "ConnectorUnplugged");
  4619. if(strcmp((char*)dmsVersion, "2.0")==0)
  4620. sprintf((char*)ShmOCPP16Data->DataTransfer[gun_index].Data, "{\\\"transactionId\\\":%d,\\\"timestamp\\\":\\\"%s\\\"}", ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId, ts);
  4621. else
  4622. sprintf((char*)ShmOCPP16Data->DataTransfer[gun_index].Data, "{\\\"idTx\\\":%d,\\\"timestamp\\\":\\\"%s\\\"}", ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId, ts);
  4623. sendUnplugByDataTransferRequest(gun_index);
  4624. interLock.isSentUnplug[gun_index] = 1;
  4625. }
  4626. else if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_IDLE))
  4627. {
  4628. interLock.isSentUnplug[gun_index] = 0;
  4629. }
  4630. CcsPreviousSystemStatus[index] = ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus;
  4631. CcsPreviousConnectorPlugIn[index] = ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ConnectorPlugIn;
  4632. cpinitateMsg.bits[gun_index].StatusNotificationReq = 1;
  4633. if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex) && ((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_COMPLETE) || (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus <= SYS_MODE_IDLE))) // complete
  4634. {
  4635. sprintf(filenmae,"/Storage/OCPP/TxProfile_%d.json",(gun_index+1));
  4636. if((access(filenmae,F_OK))!=-1)
  4637. {
  4638. DEBUG_INFO("TxProfile exist. OCPP will delete TX Charging Profile\n");
  4639. sprintf(str,"rm -f %s",filenmae);
  4640. system(str);
  4641. }
  4642. }
  4643. }
  4644. cpinitateMsg.bits[gun_index].isOnCharging = ((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_TERMINATING)?1:0);
  4645. #if 1 // for TempStopTransaction
  4646. if(((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_BOOTING) || (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_IDLE)) &&
  4647. (ShmOCPP16Data->CpMsg.bits[gun_index].StopTransactionReq == 0))
  4648. {
  4649. checkTempStopTransaction(gun_index);
  4650. }
  4651. #endif
  4652. }
  4653. }
  4654. }
  4655. else if(gunType[gun_index] == GUN_TYPE_GBT)
  4656. {
  4657. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4658. {
  4659. tempIndex = ((gun_index==2) ? 1: 0);
  4660. }
  4661. else
  4662. {
  4663. tempIndex = gun_index;
  4664. }
  4665. for (int index = 0; index < GB_QUANTITY; index++)
  4666. {
  4667. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  4668. {
  4669. if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != GbPreviousSystemStatus[index]) || (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ConnectorPlugIn != GbPreviousConnectorPlugIn[index]) )
  4670. {
  4671. // Sent unplug message for California pricing logic
  4672. if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_COMPLETE) && (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ConnectorPlugIn == 0) && !interLock.isSentUnplug[gun_index])
  4673. {
  4674. uint8_t ts[36];
  4675. getNowDatetime(ts);
  4676. sprintf((char*)ShmOCPP16Data->DataTransfer[gun_index].VendorId, "org.openchargealliance.costmsg");
  4677. sprintf((char*)ShmOCPP16Data->DataTransfer[gun_index].MessageId, "ConnectorUnplugged");
  4678. if(strcmp((char*)dmsVersion, "2.0")==0)
  4679. sprintf((char*)ShmOCPP16Data->DataTransfer[gun_index].Data, "{\\\"transactionId\\\":%d,\\\"timestamp\\\":\\\"%s\\\"}", ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId, ts);
  4680. else
  4681. sprintf((char*)ShmOCPP16Data->DataTransfer[gun_index].Data, "{\\\"idTx\\\":%d,\\\"timestamp\\\":\\\"%s\\\"}", ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId, ts);
  4682. sendUnplugByDataTransferRequest(gun_index);
  4683. interLock.isSentUnplug[gun_index] = 1;
  4684. }
  4685. else if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_IDLE))
  4686. {
  4687. interLock.isSentUnplug[gun_index] = 0;
  4688. }
  4689. GbPreviousSystemStatus[index] = ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus;
  4690. GbPreviousConnectorPlugIn[index] = ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ConnectorPlugIn;
  4691. cpinitateMsg.bits[gun_index].StatusNotificationReq = 1;
  4692. if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex) && ((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_COMPLETE) || (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus <= SYS_MODE_IDLE))) // complete
  4693. {
  4694. sprintf(filenmae,"/Storage/OCPP/TxProfile_%d.json",(gun_index+1));
  4695. if((access(filenmae,F_OK))!=-1)
  4696. {
  4697. DEBUG_INFO("TxProfile exist. OCPP will delete TX Charging Profile\n");
  4698. sprintf(str,"rm -f %s",filenmae);
  4699. system(str);
  4700. }
  4701. }
  4702. }
  4703. cpinitateMsg.bits[gun_index].isOnCharging = ((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_TERMINATING)?1:0);
  4704. #if 1 // for TempStopTransaction
  4705. if(((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_BOOTING) || (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_IDLE)) &&
  4706. (ShmOCPP16Data->CpMsg.bits[gun_index].StopTransactionReq == 0))
  4707. {
  4708. checkTempStopTransaction(gun_index);
  4709. }
  4710. #endif
  4711. }
  4712. }
  4713. }
  4714. else if(gunType[gun_index] == GUN_TYPE_DO)
  4715. {
  4716. tempIndex = gun_index;
  4717. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  4718. {
  4719. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  4720. {
  4721. if((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus != DoPreviousSystemStatus[index]) || (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.ConnectorPlugIn != DoPreviousConnectorPlugIn[index]) )
  4722. {
  4723. // Sent unplug message for California pricing logic
  4724. if((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_COMPLETE) && (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.ConnectorPlugIn == 0) && !interLock.isSentUnplug[gun_index])
  4725. {
  4726. uint8_t ts[36];
  4727. getNowDatetime(ts);
  4728. sprintf((char*)ShmOCPP16Data->DataTransfer[gun_index].VendorId, "org.openchargealliance.costmsg");
  4729. sprintf((char*)ShmOCPP16Data->DataTransfer[gun_index].MessageId, "ConnectorUnplugged");
  4730. if(strcmp((char*)dmsVersion, "2.0")==0)
  4731. sprintf((char*)ShmOCPP16Data->DataTransfer[gun_index].Data, "{\\\"transactionId\\\":%d,\\\"timestamp\\\":\\\"%s\\\"}", ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId, ts);
  4732. else
  4733. sprintf((char*)ShmOCPP16Data->DataTransfer[gun_index].Data, "{\\\"idTx\\\":%d,\\\"timestamp\\\":\\\"%s\\\"}", ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId, ts);
  4734. sendUnplugByDataTransferRequest(gun_index);
  4735. interLock.isSentUnplug[gun_index] = 1;
  4736. }
  4737. else if((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_IDLE))
  4738. {
  4739. interLock.isSentUnplug[gun_index] = 0;
  4740. }
  4741. DoPreviousSystemStatus[index] = ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus;
  4742. DoPreviousConnectorPlugIn[index] = ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.ConnectorPlugIn;
  4743. cpinitateMsg.bits[gun_index].StatusNotificationReq = 1;
  4744. 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
  4745. {
  4746. sprintf(filenmae,"/Storage/OCPP/TxProfile_%d.json",(gun_index+1));
  4747. if((access(filenmae,F_OK))!=-1)
  4748. {
  4749. DEBUG_INFO("TxProfile exist. OCPP will delete TX Charging Profile\n");
  4750. sprintf(str,"rm -f %s",filenmae);
  4751. system(str);
  4752. }
  4753. }
  4754. }
  4755. 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);
  4756. #if 1 // for TempStopTransaction
  4757. if(((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_BOOTING) || (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_IDLE)) &&
  4758. (ShmOCPP16Data->CpMsg.bits[gun_index].StopTransactionReq == 0))
  4759. {
  4760. checkTempStopTransaction(gun_index);
  4761. }
  4762. #endif
  4763. }
  4764. }
  4765. }
  4766. else
  4767. {
  4768. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  4769. {
  4770. tempIndex = 2;
  4771. }
  4772. else
  4773. {
  4774. tempIndex = gun_index;
  4775. }
  4776. for (int index = 0; index < AC_QUANTITY; index++)
  4777. {
  4778. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  4779. {
  4780. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != AcPreviousSystemStatus[index]) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PilotState != AcPreviousConnectorPlugIn[index]) )
  4781. {
  4782. // Sent unplug message for California pricing logic
  4783. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_COMPLETE) && (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PilotState == CP_STATE_A) && !interLock.isSentUnplug[gun_index])
  4784. {
  4785. uint8_t ts[36];
  4786. getNowDatetime(ts);
  4787. sprintf((char*)ShmOCPP16Data->DataTransfer[gun_index].VendorId, "org.openchargealliance.costmsg");
  4788. sprintf((char*)ShmOCPP16Data->DataTransfer[gun_index].MessageId, "ConnectorUnplugged");
  4789. if(strcmp((char*)dmsVersion, "2.0")==0)
  4790. sprintf((char*)ShmOCPP16Data->DataTransfer[gun_index].Data, "{\\\"transactionId\\\":%d,\\\"timestamp\\\":\\\"%s\\\"}", ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId, ts);
  4791. else
  4792. sprintf((char*)ShmOCPP16Data->DataTransfer[gun_index].Data, "{\\\"idTx\\\":%d,\\\"timestamp\\\":\\\"%s\\\"}", ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId, ts);
  4793. sendUnplugByDataTransferRequest(gun_index);
  4794. interLock.isSentUnplug[gun_index] = 1;
  4795. }
  4796. else if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_IDLE))
  4797. {
  4798. interLock.isSentUnplug[gun_index] = 0;
  4799. }
  4800. AcPreviousSystemStatus[index] = ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus;
  4801. AcPreviousConnectorPlugIn[index] = ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PilotState;
  4802. cpinitateMsg.bits[gun_index].StatusNotificationReq = 1;
  4803. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex) && ((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_COMPLETE) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus <= SYS_MODE_IDLE))) // complete
  4804. {
  4805. sprintf(filenmae,"/Storage/OCPP/TxProfile_%d.json",(gun_index+1));
  4806. if((access(filenmae,F_OK))!=-1)
  4807. {
  4808. DEBUG_INFO("TxProfile exist. OCPP will delete TX Charging Profile\n");
  4809. sprintf(str,"rm -f %s",filenmae);
  4810. system(str);
  4811. }
  4812. }
  4813. }
  4814. cpinitateMsg.bits[gun_index].isOnCharging = ((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_TERMINATING)?1:0);
  4815. #if 1 // for TempStopTransaction
  4816. if(((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_BOOTING) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_IDLE)) &&
  4817. (ShmOCPP16Data->CpMsg.bits[gun_index].StopTransactionReq == 0))
  4818. {
  4819. checkTempStopTransaction(gun_index);
  4820. }
  4821. #endif
  4822. }
  4823. }// END
  4824. }
  4825. if(isWebsocketSendable && (server_sign == TRUE) && (getDiffSecNow(clientTime.StatusNotification[gun_index]) >= 1) &&
  4826. (
  4827. (cpinitateMsg.bits[gun_index].StatusNotificationReq == 1) || (cpinitateMsg.bits[gun_index].TriggerStatusNotificationReq == 1) ||
  4828. ((strcmp((const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StatusNotificationPeriodically].ItemData, "TRUE") == 0) && (getDiffSecNow(clientTime.StatusNotification[gun_index]) >= atoi((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[StatusNotificationInterval].ItemData)))
  4829. )
  4830. )
  4831. {
  4832. sendStatusNotificationRequest(gun_index);
  4833. refreshStartTimer(&clientTime.StatusNotification[gun_index]);
  4834. }
  4835. //==============================================
  4836. // TCCI reader status report
  4837. //==============================================
  4838. if(isWebsocketSendable && (server_sign == TRUE) && (ShmOCPP16Data->TcciCustomData.ReaderStatus[gun_index].ReportReaderStatusReq == 1))
  4839. {
  4840. reportReaderStatus(gun_index);
  4841. //ShmOCPP16Data->TcciCustomData.ReaderStatus[gun_index].ReportReaderStatusReq = 0;
  4842. }
  4843. //==============================================
  4844. // CSU Trigger or timer timeout refresh Smart Charging Profile
  4845. //==============================================
  4846. if((ShmOCPP16Data->CSUMsg.bits[gun_index].ChargingProfileReq == 1) ||
  4847. ((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))))
  4848. {
  4849. checkCompositeSchedule(gun_index+1, 86400, &ShmOCPP16Data->SmartChargingProfile[gun_index], TRUE);
  4850. ShmOCPP16Data->CSUMsg.bits[gun_index].ChargingProfileReq = 0;
  4851. refreshStartTimer(&clientTime.CharingProfileRefresh[gun_index]);
  4852. }
  4853. //==============================================
  4854. // Meter report
  4855. //==============================================
  4856. // Trigger MeterValue
  4857. if(isWebsocketSendable && (server_sign == TRUE) && cpinitateMsg.bits[gun_index].TriggerMeterValue)
  4858. {
  4859. sendMeterValuesRequest(gun_index, ReadingContext_Trigger);
  4860. cpinitateMsg.bits[gun_index].TriggerMeterValue = 0;
  4861. }
  4862. // Clock-aligned Meter value
  4863. if(isWebsocketSendable && (reqClockAlignMeter[gun_index] == 1))
  4864. {
  4865. sendMeterValuesRequest(gun_index, ReadingContext_Sample_Clock);
  4866. reqClockAlignMeter[gun_index] = 0;
  4867. }
  4868. // Sample period MeterValue
  4869. 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))))
  4870. {
  4871. //check Transaction active
  4872. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  4873. {
  4874. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4875. {
  4876. tempIndex = ((gun_index==2) ? 1: 0);
  4877. }
  4878. else
  4879. {
  4880. tempIndex = gun_index;
  4881. }
  4882. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  4883. {
  4884. // 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault
  4885. if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  4886. {
  4887. if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_CHARGING)
  4888. {
  4889. reqSampleMeter[gun_index] = 1;
  4890. }
  4891. }
  4892. }// End for CHAdeMO
  4893. }
  4894. else if(gunType[gun_index] == GUN_TYPE_CCS)
  4895. {
  4896. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4897. {
  4898. tempIndex = ((gun_index==2) ? 1: 0);
  4899. }
  4900. else
  4901. {
  4902. tempIndex = gun_index;
  4903. }
  4904. for (int index = 0; index < CCS_QUANTITY; index++)
  4905. {
  4906. // 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault
  4907. if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  4908. {
  4909. if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_CHARGING)
  4910. {
  4911. reqSampleMeter[gun_index] = 1;
  4912. }
  4913. }
  4914. } // End for CCS
  4915. }
  4916. else if(gunType[gun_index] == GUN_TYPE_GBT)
  4917. {
  4918. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4919. {
  4920. tempIndex = ((gun_index==2) ? 1: 0);
  4921. }
  4922. else
  4923. {
  4924. tempIndex = gun_index;
  4925. }
  4926. for (int index = 0; index < GB_QUANTITY; index++)
  4927. {
  4928. // 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault
  4929. if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  4930. {
  4931. if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_CHARGING)
  4932. {
  4933. reqSampleMeter[gun_index] = 1;
  4934. }
  4935. }
  4936. }// End for GB
  4937. }
  4938. else if(gunType[gun_index] == GUN_TYPE_DO)
  4939. {
  4940. tempIndex = gun_index;
  4941. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  4942. {
  4943. // 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault
  4944. if(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  4945. {
  4946. if(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_CHARGING)
  4947. {
  4948. reqSampleMeter[gun_index] = 1;
  4949. }
  4950. }
  4951. }
  4952. }
  4953. else
  4954. {
  4955. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  4956. {
  4957. tempIndex = 2;
  4958. }
  4959. else
  4960. {
  4961. tempIndex = gun_index;
  4962. }
  4963. for (int index = 0; index < AC_QUANTITY; index++)
  4964. {
  4965. // 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault
  4966. if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  4967. {
  4968. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_TERMINATING))
  4969. {
  4970. reqSampleMeter[gun_index] = 1;
  4971. }
  4972. }
  4973. }//End for AC
  4974. }
  4975. if(reqSampleMeter[gun_index] == 1)
  4976. {
  4977. if(atoi((const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemData)>0)
  4978. sendMeterValuesRequest(gun_index, ReadingContext_Sample_Periodic);
  4979. storeTempStopTransaction(gun_index);
  4980. reqSampleMeter[gun_index] = 0;
  4981. }
  4982. refreshStartTimer(&clientTime.MeterValues[gun_index]);
  4983. }
  4984. //==============================================
  4985. // Check Connector reserved
  4986. //==============================================
  4987. //===============================
  4988. // Check if Reserve is expired
  4989. //===============================
  4990. if((server_sign == TRUE) && (ShmOCPP16Data->ReserveNow[gun_index].ExpiryDate[0] != 0))
  4991. {
  4992. if(isOvertNow(ShmOCPP16Data->ReserveNow[gun_index].ExpiryDate))
  4993. {
  4994. DEBUG_INFO("reserve expired.\n");
  4995. memset(ShmOCPP16Data->ReserveNow[gun_index].ExpiryDate,0,ARRAY_SIZE(ShmOCPP16Data->ReserveNow[gun_index].ExpiryDate));
  4996. }
  4997. }//END OF Check if Reserve is expired
  4998. //==========================================
  4999. // csu trigger FirmwareStatusNotificationReq
  5000. //==========================================
  5001. if(isWebsocketSendable && (server_sign == TRUE) && (ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationReq == 1))
  5002. {
  5003. sendFirmwareStatusNotificationRequest((char *)ShmOCPP16Data->FirmwareStatusNotification.Status);
  5004. }
  5005. //==========================================
  5006. // csu trigger DiagnosticsStatusNotificationReq
  5007. //==========================================
  5008. if(isWebsocketSendable && (server_sign == TRUE) && (ShmOCPP16Data->SpMsg.bits.DiagnosticsStatusNotificationReq == 1))
  5009. {
  5010. sendDiagnosticsStatusNotificationRequest((char *)ShmOCPP16Data->DiagnosticsStatusNotification.Status);
  5011. }
  5012. //==========================================
  5013. // csu trigger CancelReservationConf
  5014. //==========================================
  5015. if(isWebsocketSendable && (server_sign == TRUE) && (ShmOCPP16Data->CsMsg.bits[gun_index].CancelReservationConf == 1))
  5016. {
  5017. sendCancelReservationConfirmation((char *)ShmOCPP16Data->CancelReservation[gun_index].guid,(char *)ShmOCPP16Data->CancelReservation[gun_index].ResponseStatus);
  5018. ShmOCPP16Data->CsMsg.bits[gun_index].CancelReservationConf = 0;
  5019. }
  5020. //==========================================
  5021. // csu trigger ChangeAvailabilityConf
  5022. //==========================================
  5023. if(isWebsocketSendable && (server_sign == TRUE) && (ShmOCPP16Data->CsMsg.bits[gun_index].ChangeAvailabilityConf == 1))
  5024. {
  5025. //sendChangeAvailabilityConfirmation(,(char *)ShmOCPP16Data->ChangeAvailability[gun_index].ResponseStatus);
  5026. }
  5027. //==========================================
  5028. // csu trigger UnlockConnectorConf
  5029. //==========================================
  5030. if(isWebsocketSendable && (server_sign == TRUE) && (ShmOCPP16Data->CsMsg.bits[gun_index].UnlockConnectorConf == 1))
  5031. {
  5032. sendUnlockConnectorConfirmation((char *)ShmOCPP16Data->UnlockConnector[gun_index].guid, (char *)ShmOCPP16Data->UnlockConnector[gun_index].ResponseStatus);
  5033. ShmOCPP16Data->CsMsg.bits[gun_index].UnlockConnectorConf = 0;
  5034. }
  5035. //==========================================
  5036. // csu trigger ReserveNowConf
  5037. //==========================================
  5038. if(isWebsocketSendable && (server_sign == TRUE) && (ShmOCPP16Data->CsMsg.bits[gun_index].ReserveNowConf == 1))
  5039. {
  5040. sendReserveNowTransactionConfirmation((char *)ShmOCPP16Data->ReserveNow[gun_index].guid, (char *)ShmOCPP16Data->ReserveNow[gun_index].ResponseStatus);
  5041. ShmOCPP16Data->CsMsg.bits[gun_index].ReserveNowConf = 0;
  5042. }
  5043. if(isWebsocketSendable && (server_sign == TRUE) && (ShmOCPP16Data->SpMsg.bits.SignCertificateReq == 1) && (access("/Storage/OCPP/certCP.csr",F_OK) != -1))
  5044. {
  5045. sendSignCertificateRequest();
  5046. }
  5047. }
  5048. }
  5049. //==========================================
  5050. // send request routine
  5051. //==========================================
  5052. int sendAuthorizeRequest(int gun_index)
  5053. {
  5054. mtrace();
  5055. int result = FAIL;
  5056. char message[100]={0};
  5057. char guid[37];
  5058. char tempdata[65]={0};
  5059. DEBUG_INFO("sendAuthorizeRequest...\n");
  5060. memset(&(ShmOCPP16Data->Authorize.ResponseIdTagInfo),0,sizeof(struct StructIdTagInfo));
  5061. //Local Authorize
  5062. if((strcmp((const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemData , "TRUE")==0) &&(ShmOCPP16Data->OcppConnStatus == 0))
  5063. {
  5064. DEBUG_INFO("Allow OfflineTx UnknownId Pass.\n");
  5065. strcpy((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.ExpiryDate, "");
  5066. strcpy((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.ParentIdTag, "");
  5067. strcpy((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.Status, "Accepted");
  5068. result = PASS;
  5069. ShmOCPP16Data->SpMsg.bits.AuthorizeReq = 0;
  5070. ShmOCPP16Data->SpMsg.bits.AuthorizeConf = 1; // inform csu
  5071. authorizeRetryTimes = 0;
  5072. return result;
  5073. }
  5074. 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))||
  5075. ((strcmp((const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemData, "TRUE") == 0)&&(strcmp((const char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "TRUE") == 0)))
  5076. {
  5077. // Query from cache
  5078. DEBUG_INFO("Authorize from cache.\n");
  5079. OCPP_getIdTagFromLocalCache((char *)ShmSysConfigAndInfo->SysConfig.UserId);
  5080. // Query from list
  5081. if((strcmp(idTagQuery.idTagstr,"") == 0) || (strcmp(idTagQuery.idTagstatus,"Accepted") != 0) )
  5082. {
  5083. DEBUG_INFO("Authorize from list.\n");
  5084. OCPP_getIdTagFromLocalList((char *)ShmSysConfigAndInfo->SysConfig.UserId);
  5085. }
  5086. if((strcmp(idTagQuery.idTagstr,"") == 0) || (strcmp(idTagQuery.idTagstatus,"Accepted") != 0) )
  5087. {
  5088. if(strcmp(idTagQuery.idTagstr,"") == 0)
  5089. {
  5090. DEBUG_INFO("Local Authorization Fail, Card %s is not in local cache and list.\n", ShmSysConfigAndInfo->SysConfig.UserId);
  5091. }
  5092. else if(strcmp(idTagQuery.idTagstatus,"Accepted") != 0)
  5093. {
  5094. DEBUG_INFO("Local Authorization Fail, Card %s is not Accepted.\n", idTagQuery.idTagstr);
  5095. }
  5096. if(!GetOcppConnStatus())
  5097. {
  5098. DEBUG_INFO("off-line Local Authorization Fail.\n");
  5099. strcpy((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.ExpiryDate, idTagQuery.expiryDate);
  5100. strcpy((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.ParentIdTag, idTagQuery.parentIdTag);
  5101. strcpy((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.Status, "Invalid");
  5102. DEBUG_INFO("ShmOCPP16Data->Authorize.ResponseIdTagInfo.Status: %s \n", ShmOCPP16Data->Authorize.ResponseIdTagInfo.Status);
  5103. ShmOCPP16Data->SpMsg.bits.AuthorizeReq = 0;
  5104. ShmOCPP16Data->SpMsg.bits.AuthorizeConf = 1; // inform csu
  5105. authorizeRetryTimes = 0;
  5106. return result;
  5107. }
  5108. }
  5109. else
  5110. {
  5111. DEBUG_INFO("off-line Local Authorization get result !!!!\n");
  5112. strcpy((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.ExpiryDate, idTagQuery.expiryDate);
  5113. strcpy((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.ParentIdTag, idTagQuery.parentIdTag);
  5114. if(isOvertNow((uint8_t*)&idTagQuery.expiryDate[0]))
  5115. sprintf((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.Status, "Expired");
  5116. else
  5117. strcpy((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.Status, idTagQuery.idTagstatus);
  5118. DEBUG_INFO("ShmOCPP16Data->Authorize.ResponseIdTagInfo.Status: %s \n", ShmOCPP16Data->Authorize.ResponseIdTagInfo.Status);
  5119. result = PASS;
  5120. ShmOCPP16Data->SpMsg.bits.AuthorizeReq = 0;
  5121. ShmOCPP16Data->SpMsg.bits.AuthorizeConf = 1; // inform csu
  5122. authorizeRetryTimes = 0;
  5123. return result;
  5124. }
  5125. }
  5126. //initialize struct Authorize
  5127. memset(&(ShmOCPP16Data->Authorize), 0 , sizeof(struct StructAuthorize));
  5128. //get data from shared memory
  5129. strcpy((char *)ShmOCPP16Data->Authorize.IdTag, (const char *)ShmSysConfigAndInfo->SysConfig.UserId);
  5130. random_uuid(guid);
  5131. sprintf(message,"[%d,\"%s\",\"Authorize\",{\"idTag\":\"%s\"}]",MESSAGE_TYPE_CALL, guid, ShmOCPP16Data->Authorize.IdTag);
  5132. LWS_Send(message);
  5133. sprintf(tempdata, "Authorize,%d", gun_index);
  5134. if(hashmap_operation(HASH_OP_ADD, guid, tempdata) == 1)
  5135. {
  5136. result = PASS;
  5137. DEBUG_INFO("Authorize mapItem pass\n");
  5138. }
  5139. ShmOCPP16Data->SpMsg.bits.AuthorizeReq = 0;
  5140. return result;
  5141. }
  5142. int sendBootNotificationRequest(void)
  5143. {
  5144. mtrace();
  5145. int result = FAIL;
  5146. char message[500]={0}, payload[700]={0};
  5147. char guid[37]={0};
  5148. char tempdata[65]={0};
  5149. // Fill BootNotification fields
  5150. strcpy((char *)ShmOCPP16Data->BootNotification.CbSN,(const char *)ShmOCPP16Data->ChargeBoxId);
  5151. strcpy((char *)ShmOCPP16Data->BootNotification.CpModel,(const char *)ShmSysConfigAndInfo->SysConfig.ModelName);
  5152. strcpy((char *)ShmOCPP16Data->BootNotification.CpSN,(const char *)ShmSysConfigAndInfo->SysConfig.SerialNumber);
  5153. strcpy((char *)ShmOCPP16Data->BootNotification.CpVendor,(const char *)ShmSysConfigAndInfo->SysConfig.chargePointVendor);
  5154. strcpy((char *)ShmOCPP16Data->BootNotification.CpFwVersion,(const char *)ShmSysConfigAndInfo->SysInfo.CsuRootFsFwRev);
  5155. strcpy((char *)ShmOCPP16Data->BootNotification.CpIccid,(const char *)ShmSysConfigAndInfo->SysConfig.TelecomInterface.TelcomSimIccid);
  5156. strcpy((char *)ShmOCPP16Data->BootNotification.CpImsi,(const char *)ShmSysConfigAndInfo->SysConfig.TelecomInterface.TelcomSimImsi);
  5157. sprintf(payload, "{\"chargeBoxSerialNumber\":\"%s\",\"chargePointModel\":\"%s\",\"chargePointSerialNumber\":\"%s\",\"chargePointVendor\":\"%s\",\"firmwareVersion\":\"%s\",\"iccid\":\"%s\",\"imsi\":\"%s\"} ",
  5158. ShmOCPP16Data->ChargeBoxId
  5159. ,ShmSysConfigAndInfo->SysConfig.ModelName
  5160. ,ShmSysConfigAndInfo->SysConfig.SerialNumber
  5161. ,ShmSysConfigAndInfo->SysConfig.chargePointVendor
  5162. ,ShmOCPP16Data->BootNotification.CpFwVersion
  5163. ,ShmOCPP16Data->BootNotification.CpIccid
  5164. ,ShmOCPP16Data->BootNotification.CpImsi);
  5165. random_uuid(guid);
  5166. sprintf(message,"[%d,\"%s\",\"%s\",%s]",MESSAGE_TYPE_CALL, guid, "BootNotification", payload);
  5167. LWS_Send(message);
  5168. sprintf(tempdata, "BootNotification,0");
  5169. 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*/)
  5170. {
  5171. result = PASS;
  5172. }
  5173. memset(queuedata, 0, ARRAY_SIZE(queuedata));
  5174. strcpy(queuedata,message);
  5175. return result;
  5176. }
  5177. int sendDataTransferRequest(int gun_index)
  5178. {
  5179. mtrace();
  5180. char message[1000]={0};
  5181. char guid[37]={0};
  5182. char tempdata[65]={0};
  5183. int result = FAIL;
  5184. random_uuid(guid);
  5185. sprintf(message,"[%d,\"%s\",\"DataTransfer\",{\"vendorId\":\"%s\",\"messageId\":\"%s\",\"data\":\"%s\"}]",
  5186. MESSAGE_TYPE_CALL,
  5187. guid,
  5188. ShmOCPP16Data->DataTransfer[gun_index].VendorId,
  5189. ShmOCPP16Data->DataTransfer[gun_index].MessageId,
  5190. ShmOCPP16Data->DataTransfer[gun_index].Data);
  5191. LWS_Send(message);
  5192. sprintf(tempdata, "DataTransfer,%d", (gun_index + 1));
  5193. if(hashmap_operation(HASH_OP_ADD, guid, tempdata) == 1)
  5194. {
  5195. result = PASS;
  5196. DEBUG_INFO("DataTransfer mapItem pass\n");
  5197. }
  5198. return result;
  5199. }
  5200. int sendUnplugByDataTransferRequest(int gun_index)
  5201. {
  5202. mtrace();
  5203. char message[1000]={0};
  5204. char guid[37]={0};
  5205. char tempdata[65]={0};
  5206. int result = FAIL;
  5207. random_uuid(guid);
  5208. sprintf(message,"%d,[%d,\"%s\",\"DataTransfer\",{\"vendorId\":\"%s\",\"messageId\":\"%s\",\"data\":\"%s\"}]",
  5209. (gun_index+1),
  5210. MESSAGE_TYPE_CALL,
  5211. guid,
  5212. ShmOCPP16Data->DataTransfer[gun_index].VendorId,
  5213. ShmOCPP16Data->DataTransfer[gun_index].MessageId,
  5214. ShmOCPP16Data->DataTransfer[gun_index].Data);
  5215. sprintf(tempdata, "DataTransfer,%d", (gun_index + 1));
  5216. if(hashmap_operation(HASH_OP_ADD, guid, tempdata) == 1)
  5217. {
  5218. result = PASS;
  5219. DEBUG_INFO("DataTransfer mapItem pass\n");
  5220. }
  5221. queue_operation(QUEUE_OPERATION_ADD, guid, message);
  5222. return result;
  5223. }
  5224. int sendOcmfByDataTransferRequest(int gun_index)
  5225. {
  5226. sprintf((char*)ShmOCPP16Data->DataTransfer[gun_index].VendorId, (char*)ShmSysConfigAndInfo->SysConfig.chargePointVendor);
  5227. sprintf((char*)ShmOCPP16Data->DataTransfer[gun_index].MessageId, "ID_OCMF");
  5228. sprintf((char*)ShmOCPP16Data->DataTransfer[gun_index].Data, "{\\\"txId\\\":%d,\\\"dataString\\\":\\\"%s\\\",\\\"publicKey\\\":\\\"%s\\\"}", ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId, ShmOCPP16Data->OcmfData[gun_index].DataString, ShmOCPP16Data->OcmfData[gun_index].PublicKey);
  5229. mtrace();
  5230. char message[3000]={0};
  5231. char guid[37]={0};
  5232. char tempdata[65]={0};
  5233. int result = FAIL;
  5234. random_uuid(guid);
  5235. sprintf(message,"%d,[%d,\"%s\",\"DataTransfer\",{\"vendorId\":\"%s\",\"messageId\":\"%s\",\"data\":\"%s\"}]",
  5236. (gun_index+1),
  5237. MESSAGE_TYPE_CALL,
  5238. guid,
  5239. ShmOCPP16Data->DataTransfer[gun_index].VendorId,
  5240. ShmOCPP16Data->DataTransfer[gun_index].MessageId,
  5241. ShmOCPP16Data->DataTransfer[gun_index].Data);
  5242. sprintf(tempdata, "DataTransfer,%d", (gun_index + 1));
  5243. if(hashmap_operation(HASH_OP_ADD, guid, tempdata) == 1)
  5244. {
  5245. result = PASS;
  5246. DEBUG_INFO("DataTransfer mapItem pass\n");
  5247. }
  5248. queue_operation(QUEUE_OPERATION_ADD, guid, message);
  5249. return result;
  5250. }
  5251. int sendDiagnosticsStatusNotificationRequest(char *status)
  5252. {
  5253. mtrace();
  5254. int result = FAIL;
  5255. char message[110]={0};
  5256. char guid[37]={0};
  5257. char tempdata[65]={0};
  5258. //[ 2, "9f7bced1-b8b1-40ec-b3bb-2e15630e3cdc", "DiagnosticsStatusNotification", { "status": "Idle" } ]
  5259. DEBUG_INFO("sendDiagnosticsStatusNotificationRequest...\n");
  5260. sprintf((char *)ShmOCPP16Data->DiagnosticsStatusNotification.Status,"%s",(const char *)status);
  5261. random_uuid(guid);
  5262. sprintf(message,"[%d,\"%s\",\"DiagnosticsStatusNotification\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALL, guid,status);
  5263. LWS_SendNow(message);
  5264. sprintf(tempdata, "DiagnosticsStatusNotification,%d", 0);
  5265. if(hashmap_operation(HASH_OP_ADD, guid, tempdata) == 1)
  5266. {
  5267. result = PASS;
  5268. //DEBUG_INFO("DiagnosticsStatusNotification mapItem pass\n");
  5269. }
  5270. //#ifdef SystemLogMessage
  5271. //DEBUG_INFO(">>>>>DiagnosticsStatusNotification request\n");
  5272. //DEBUG_INFO("Message: %s\n", SendBuffer);
  5273. //DEBUG_INFO("After push hash length: %d\n", hashmapForMessageLength()/*hashmap_length(hashMap)*/);
  5274. //#endif
  5275. ShmOCPP16Data->SpMsg.bits.DiagnosticsStatusNotificationReq = 0;
  5276. ShmOCPP16Data->SpMsg.bits.DiagnosticsStatusNotificationConf = 0;
  5277. //record status
  5278. if(strcmp(status,"Idle")==0)
  5279. {
  5280. DiagnosticsStatusNotificationStatus = DIAGNOSTIC_STATUS_IDLE;
  5281. }
  5282. else if(strcmp(status,"Uploaded")==0)
  5283. {
  5284. DiagnosticsStatusNotificationStatus = DIAGNOSTIC_STATUS_UPLOADED;
  5285. }
  5286. else if(strcmp(status,"UploadFailed")==0)
  5287. {
  5288. DiagnosticsStatusNotificationStatus = DIAGNOSTIC_STATUS_UPLOAD_FAIL;
  5289. }
  5290. else if(strcmp(status,"Uploading")==0)
  5291. {
  5292. DiagnosticsStatusNotificationStatus = DIAGNOSTIC_STATUS_UPLOADING;
  5293. }
  5294. return result;
  5295. }
  5296. int sendFirmwareStatusNotificationRequest(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, "eb841424-ae56-42b0-8c84-d5296018c33c", "FirmwareStatusNotification", { "status": "Downloaded" } ]
  5304. DEBUG_INFO("sendFirmwareStatusNotificationRequest \n");
  5305. sprintf((char *)ShmOCPP16Data->FirmwareStatusNotification.Status, "%s", (const char *)status);
  5306. random_uuid(guid);
  5307. sprintf(message,"[%d,\"%s\",\"FirmwareStatusNotification\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALL, guid, status);
  5308. LWS_SendNow(message);
  5309. sprintf(tempdata, "FirmwareStatusNotification,%d", 0);
  5310. 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*/)
  5311. {
  5312. result = PASS;
  5313. DEBUG_INFO("FirmwareStatusNotification mapItem pass\n");
  5314. }
  5315. //#ifdef SystemLogMessage
  5316. //DEBUG_INFO(">>>>>FirmwareStatusNotification request\n");
  5317. //DEBUG_INFO("Message: %s\n", SendBuffer);
  5318. //#endif
  5319. ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationReq = 0;
  5320. ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationConf = 0;
  5321. //record status
  5322. if(strcmp(status,"Downloaded")==0)
  5323. {
  5324. FirmwareStatusNotificationStatus = FIRMWARE_STATUS_DOWNLOADED;
  5325. }
  5326. else if(strcmp(status,"DownloadFailed")==0)
  5327. {
  5328. FirmwareStatusNotificationStatus = FIRMWARE_STATUS_DOWNLOAD_FAILED;
  5329. }
  5330. else if(strcmp(status,"Downloading")==0)
  5331. {
  5332. FirmwareStatusNotificationStatus = FIRMWARE_STATUS_DOWNLOADING;
  5333. }
  5334. else if(strcmp(status,"Idle")==0)
  5335. {
  5336. FirmwareStatusNotificationStatus = FIRMWARE_STATUS_IDLE;
  5337. }
  5338. else if(strcmp(status,"InstallationFailed")==0)
  5339. {
  5340. FirmwareStatusNotificationStatus = FIRMWARE_STATUS_INSTALLATION_FAILED;
  5341. }
  5342. else if(strcmp(status,"Installing")==0)
  5343. {
  5344. FirmwareStatusNotificationStatus = FIRMWARE_STATUS_INSTALLING;
  5345. }
  5346. else if(strcmp(status,"Installed")==0)
  5347. {
  5348. FirmwareStatusNotificationStatus = FIRMWARE_STATUS_INSTALLED;
  5349. }
  5350. return result;
  5351. }
  5352. int sendHeartbeatRequest(int gun_index)
  5353. {
  5354. mtrace();
  5355. int result = FAIL;
  5356. char message[80]={0};
  5357. char guid[37]={0};
  5358. char tempdata[65]={0};
  5359. random_uuid(guid);
  5360. sprintf(message, "[%d,\"%s\",\"Heartbeat\",{ }]"
  5361. , MESSAGE_TYPE_CALL
  5362. , guid );
  5363. LWS_Send(message);
  5364. sprintf(tempdata, "Heartbeat,%d", 0);
  5365. 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*/)
  5366. {
  5367. result = PASS;
  5368. }
  5369. return result;
  5370. }
  5371. int sendStartTransactionRequest(int gun_index)
  5372. {
  5373. mtrace();
  5374. int result = FAIL;
  5375. char message[250]={0};
  5376. char guid[37]={0};
  5377. struct timeval tmnow;
  5378. struct tm *tm;
  5379. char buf[28];//, usec_buf[6];
  5380. char tempdata[65]={0};
  5381. int tempIndex = 0;
  5382. DEBUG_INFO("sendStartTransactionRequest...\n");
  5383. gettimeofday(&tmnow, NULL);
  5384. time_t t;
  5385. t = time(NULL);
  5386. /*UTC time and date*/
  5387. tm = gmtime(&t);
  5388. strftime(buf,28,"%Y-%m-%dT%H:%M:%SZ", tm);
  5389. #if 0 // remove temporally
  5390. strftime(buf,30,"%Y-%m-%dT%H:%M:%S", tm);
  5391. strcat(buf,".");
  5392. sprintf(usec_buf,"%dZ",(int)tmnow.tv_usec);
  5393. strcat(buf,usec_buf);
  5394. #endif
  5395. ShmOCPP16Data->StartTransaction[gun_index].ConnectorId = gun_index +1 ; // gun start from 1~
  5396. strcpy((char *)ShmOCPP16Data->StartTransaction[gun_index].Timestamp, buf);
  5397. //strcpy((char *)ShmOCPP16Data->StartTransaction[gun_index].IdTag, (const char *)ShmSysConfigAndInfo->SysConfig.UserId);
  5398. // clear StartTransaction Response
  5399. strcpy((char *)ShmOCPP16Data->StartTransaction[gun_index].ResponseIdTagInfo.ExpiryDate, "");
  5400. strcpy((char *)ShmOCPP16Data->StartTransaction[gun_index].ResponseIdTagInfo.ParentIdTag, "");
  5401. strcpy((char *)ShmOCPP16Data->StartTransaction[gun_index].ResponseIdTagInfo.Status, "");
  5402. ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId = 0;
  5403. refreshStartTimer(&clientTime.MeterValues[gun_index]);
  5404. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DCcc
  5405. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  5406. {
  5407. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  5408. {
  5409. tempIndex = ((gun_index==2) ? 1: 0);
  5410. }
  5411. else
  5412. {
  5413. tempIndex = gun_index;
  5414. }
  5415. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  5416. {
  5417. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  5418. {
  5419. ShmOCPP16Data->StartTransaction[gun_index].MeterStart = (int)(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PowerConsumption*1000);
  5420. ShmOCPP16Data->StartTransaction[gun_index].ReservationId = ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ReservationId;
  5421. periousPeriodicPowerConsumption[gun_index] = ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PowerConsumption;
  5422. }
  5423. }
  5424. }
  5425. else if(gunType[gun_index] == GUN_TYPE_CCS)
  5426. {
  5427. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  5428. {
  5429. tempIndex = ((gun_index==2) ? 1: 0);
  5430. }
  5431. else
  5432. {
  5433. tempIndex = gun_index;
  5434. }
  5435. for (int index = 0; index < CCS_QUANTITY; index++)
  5436. {
  5437. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  5438. {
  5439. ShmOCPP16Data->StartTransaction[gun_index].MeterStart = (int)(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PowerConsumption*1000);
  5440. ShmOCPP16Data->StartTransaction[gun_index].ReservationId = ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ReservationId;
  5441. periousPeriodicPowerConsumption[gun_index] = ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PowerConsumption;
  5442. }
  5443. }
  5444. }
  5445. else if(gunType[gun_index] == GUN_TYPE_GBT)
  5446. {
  5447. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  5448. {
  5449. tempIndex = ((gun_index==2) ? 1: 0);
  5450. }
  5451. else
  5452. {
  5453. tempIndex = gun_index;
  5454. }
  5455. for (int index = 0; index < GB_QUANTITY; index++)
  5456. {
  5457. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  5458. {
  5459. ShmOCPP16Data->StartTransaction[gun_index].MeterStart = (int)(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PowerConsumption*1000);
  5460. ShmOCPP16Data->StartTransaction[gun_index].ReservationId = ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ReservationId;
  5461. periousPeriodicPowerConsumption[gun_index] = ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PowerConsumption;
  5462. }
  5463. }
  5464. }
  5465. else if(gunType[gun_index] == GUN_TYPE_DO)
  5466. {
  5467. tempIndex = gun_index;
  5468. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  5469. {
  5470. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  5471. {
  5472. ShmOCPP16Data->StartTransaction[gun_index].MeterStart = (int)(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PowerConsumption*1000);
  5473. ShmOCPP16Data->StartTransaction[gun_index].ReservationId = ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.ReservationId;
  5474. periousPeriodicPowerConsumption[gun_index] = ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PowerConsumption;
  5475. }
  5476. }
  5477. }
  5478. else
  5479. {
  5480. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  5481. {
  5482. tempIndex = 2;
  5483. }
  5484. else
  5485. {
  5486. tempIndex = gun_index;
  5487. }
  5488. for (int index = 0; index < AC_QUANTITY; index++)
  5489. {
  5490. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  5491. {
  5492. ShmOCPP16Data->StartTransaction[gun_index].MeterStart = (int)(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PowerConsumption*1000);
  5493. ShmOCPP16Data->StartTransaction[gun_index].ReservationId = ShmSysConfigAndInfo->SysInfo.AcChargingData[index].ReservationId;
  5494. periousPeriodicPowerConsumption[gun_index] = ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PowerConsumption;
  5495. }
  5496. }
  5497. }
  5498. random_uuid(guid);
  5499. if(ShmOCPP16Data->StartTransaction[gun_index].ReservationId == -1) // No Reservation
  5500. {
  5501. sprintf(message, "%d,[%d,\"%s\",\"StartTransaction\",{\"connectorId\":%d,\"idTag\":\"%s\",\"meterStart\":%d,\"timestamp\":\"%s\"}]"
  5502. , gun_index +1
  5503. , MESSAGE_TYPE_CALL
  5504. , guid
  5505. , ShmOCPP16Data->StartTransaction[gun_index].ConnectorId
  5506. , ShmOCPP16Data->StartTransaction[gun_index].IdTag
  5507. , ShmOCPP16Data->StartTransaction[gun_index].MeterStart
  5508. , ShmOCPP16Data->StartTransaction[gun_index].Timestamp );
  5509. }
  5510. else
  5511. {
  5512. sprintf(message, "%d,[%d,\"%s\",\"StartTransaction\",{\"connectorId\":%d,\"idTag\":\"%s\",\"meterStart\":%d,\"reservationId\":%d,\"timestamp\":\"%s\"}]"
  5513. , gun_index +1
  5514. , MESSAGE_TYPE_CALL
  5515. , guid
  5516. , ShmOCPP16Data->StartTransaction[gun_index].ConnectorId
  5517. , ShmOCPP16Data->StartTransaction[gun_index].IdTag
  5518. , ShmOCPP16Data->StartTransaction[gun_index].MeterStart
  5519. , ShmOCPP16Data->StartTransaction[gun_index].ReservationId
  5520. , ShmOCPP16Data->StartTransaction[gun_index].Timestamp );
  5521. }
  5522. #if 1
  5523. sprintf(tempdata, "StartTransaction,%d", (gun_index));
  5524. 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*/)
  5525. {
  5526. result = PASS;
  5527. }
  5528. #endif
  5529. strcpy(queuedata, message);
  5530. queue_operation(QUEUE_OPERATION_ADD, guid, queuedata );//addq(guid, queuedata); ---> remove temporally
  5531. OCPP_insert_transaction_msg(YES, queuedata);
  5532. return result;
  5533. }
  5534. int sendStatusNotificationRequest(int gun_index)
  5535. {
  5536. mtrace();
  5537. int result = FAIL;
  5538. char message[600]={0};
  5539. char guid[37];
  5540. int currentStatus = 0;
  5541. struct timeval tmnow;
  5542. struct tm *tm;
  5543. char buf[28];//, usec_buf[6];
  5544. char tempdata[65]={0};
  5545. int tempIndex = 0;
  5546. uint8_t isStateChanged = TRUE;
  5547. uint8_t isContentIllegal = TRUE;
  5548. DEBUG_INFO("sendStatusNotificationRequest...\n");
  5549. gettimeofday(&tmnow, NULL);
  5550. time_t t;
  5551. t = time(NULL);
  5552. /*UTC time and date*/
  5553. tm = gmtime(&t);
  5554. strftime(buf,28,"%Y-%m-%dT%H:%M:%SZ", tm);
  5555. #if 0 // remove temporally
  5556. strftime(buf,30,"%Y-%m-%dT%H:%M:%S", tm);
  5557. strcat(buf,".");
  5558. sprintf(usec_buf,"%dZ",(int)tmnow.tv_usec);
  5559. strcat(buf,usec_buf);
  5560. #endif
  5561. //printf("%s",buf);
  5562. ShmOCPP16Data->StatusNotification[gun_index].ConnectorId = (gun_index + 1);
  5563. //strcpy(ShmOCPP16Data->StatusNotification[gun_index].ErrorCode, "NoError"); --- CSU Setting
  5564. // it's option
  5565. //strcpy((char *)ShmOCPP16Data->StatusNotification[gun_index].Info, "");
  5566. /*
  5567. enum _SYSTEM_STATUS
  5568. {
  5569. S_BOOTING = 0,
  5570. S_IDLE, = 1
  5571. S_AUTHORIZING, =2
  5572. S_REASSIGN_CHECK, =3
  5573. S_REASSIGN, =4
  5574. S_PRECHARGE, =5
  5575. S_PREPARING_FOR_EV, =6
  5576. S_PREPARING_FOR_EVSE, =7
  5577. S_CHARGING, =8
  5578. S_TERMINATING, =9
  5579. S_COMPLETE, =10
  5580. S_ALARM, =11
  5581. S_FAULT =12
  5582. }
  5583. */
  5584. //check Transaction active
  5585. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DCcc
  5586. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  5587. {
  5588. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  5589. {
  5590. tempIndex = ((gun_index==2) ? 1: 0);
  5591. }
  5592. else
  5593. {
  5594. tempIndex = gun_index;
  5595. }
  5596. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  5597. {
  5598. if ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex))
  5599. {
  5600. if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_IDLE)//S_IDLE
  5601. {
  5602. if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ConnectorPlugIn == 1) // //0: unplug, 1: Plug-in
  5603. {
  5604. currentStatus = Preparing; //OCPP Status: Preparing
  5605. }
  5606. else
  5607. {
  5608. currentStatus = Available; //OCPP Status: Available
  5609. }
  5610. }
  5611. else if ( ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus >= SYS_MODE_AUTHORIZING)&&( ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus <= SYS_MODE_PREPARE_FOR_EVSE)) ||
  5612. ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus >= SYS_MODE_CCS_PRECHARGE_STEP0) && ( ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus <= SYS_MODE_CCS_PRECHARGE_STEP1) )
  5613. ) //S_PRECHARGE
  5614. {
  5615. currentStatus = Preparing; //OCPP Status: Preparing
  5616. }
  5617. else if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_CHARGING) //S_CHARGING
  5618. {
  5619. currentStatus = Charging; //OCPP Status: Charging
  5620. }
  5621. else if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_COMPLETE) //S_COMPLETE
  5622. {
  5623. currentStatus = Finishing; //OCPP Status: Finishing
  5624. }
  5625. else if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_TERMINATING) // S_TERMINATING ---> SuspendedEV
  5626. {
  5627. currentStatus = SuspendedEV; //OCPP Status: SuspendedEV
  5628. }
  5629. 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
  5630. {
  5631. currentStatus = Unavailable; //OCPP Status: Unavailable
  5632. }
  5633. else if ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_FAULT) || (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_ALARM)) //S_ALARM,S_FAULT ---> Faulted
  5634. {
  5635. currentStatus = Faulted; //OCPP Status: Faulted
  5636. }
  5637. else if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_RESERVATION) // ---> Reserved
  5638. {
  5639. currentStatus = Reserved; //OCPP Status: Reserved
  5640. }
  5641. } //end of the same index
  5642. }//end of for CHAdeMO_QUANTITY
  5643. }
  5644. else if(gunType[gun_index] == GUN_TYPE_CCS)
  5645. {
  5646. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  5647. {
  5648. tempIndex = ((gun_index==2) ? 1: 0);
  5649. }
  5650. else
  5651. {
  5652. tempIndex = gun_index;
  5653. }
  5654. for (int index = 0; index < CCS_QUANTITY; index++)
  5655. {
  5656. if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  5657. {
  5658. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_IDLE) //S_IDLE
  5659. {
  5660. if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ConnectorPlugIn == 1) //0: unplug, 1: Plug-in
  5661. {
  5662. currentStatus = Preparing; //OCPP Status: Preparing
  5663. }
  5664. else
  5665. {
  5666. currentStatus = Available; //OCPP Status: Available
  5667. }
  5668. }
  5669. else if ( ((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus >= SYS_MODE_AUTHORIZING)&&( ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus <= SYS_MODE_PREPARE_FOR_EVSE)) ||
  5670. ((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus >= SYS_MODE_CCS_PRECHARGE_STEP0) && ( ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus <= SYS_MODE_CCS_PRECHARGE_STEP1) )
  5671. ) //S_PRECHARGE
  5672. {
  5673. currentStatus = Preparing; //OCPP Status: Preparing
  5674. }
  5675. else if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_CHARGING) //S_CHARGING
  5676. {
  5677. currentStatus = Charging; //OCPP Status: Charging
  5678. }
  5679. else if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_COMPLETE) //S_COMPLETE
  5680. {
  5681. currentStatus = Finishing; //OCPP Status: Finishing
  5682. }
  5683. else if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_TERMINATING) //S_TERMINATING ---> SuspendedEV
  5684. {
  5685. currentStatus = SuspendedEV; //OCPP Status: SuspendedEV
  5686. }
  5687. 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
  5688. {
  5689. currentStatus = Unavailable; //OCPP Status : Unavailable
  5690. }
  5691. else if ((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_FAULT) || (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_ALARM)) //S_ALARM ,S_FAULT ---> Faulted
  5692. {
  5693. currentStatus = Faulted; //OCPP Status: Faulted
  5694. }
  5695. else if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_RESERVATION) // ---> Reserved
  5696. {
  5697. currentStatus = Reserved; //OCPP Status: Reserved
  5698. }
  5699. } //end of the same index
  5700. } // end of for CCS_QUANTITY
  5701. }
  5702. else if(gunType[gun_index] == GUN_TYPE_GBT)
  5703. {
  5704. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  5705. {
  5706. tempIndex = ((gun_index==2) ? 1: 0);
  5707. }
  5708. else
  5709. {
  5710. tempIndex = gun_index;
  5711. }
  5712. for (int index = 0; index < GB_QUANTITY; index++)
  5713. {
  5714. if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  5715. {
  5716. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_IDLE) //S_IDLE
  5717. {
  5718. if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ConnectorPlugIn == 1) // //0: unplug, 1: Plug-in
  5719. {
  5720. currentStatus = Preparing; //OCPP Status: Preparing
  5721. }
  5722. else
  5723. {
  5724. currentStatus = Available; //OCPP Status: Available
  5725. }
  5726. }
  5727. else if ( ((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus >= SYS_MODE_AUTHORIZING)&&( ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus <= SYS_MODE_PREPARE_FOR_EVSE)) ||
  5728. ((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus >= SYS_MODE_CCS_PRECHARGE_STEP0) && ( ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus <= SYS_MODE_CCS_PRECHARGE_STEP1) )
  5729. ) //S_PRECHARGE
  5730. {
  5731. currentStatus = Preparing; //OCPP Status: Preparing
  5732. }
  5733. else if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_CHARGING) //S_CHARGING
  5734. {
  5735. currentStatus = Charging; //OCPP Status: Charging
  5736. }
  5737. else if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_COMPLETE) //S_COMPLETE
  5738. {
  5739. currentStatus = Finishing; //OCPP Status: Finishing
  5740. }
  5741. else if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_TERMINATING) // S_TERMINATING ---> SuspendedEV
  5742. {
  5743. currentStatus = SuspendedEV; //OCPP Status: SuspendedEV
  5744. }
  5745. 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
  5746. {
  5747. currentStatus = Unavailable; //OCPP Status: Unavailable
  5748. }
  5749. else if ((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_FAULT) || (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_ALARM)) //S_ALARM ,S_FAULT ---> Faulted
  5750. {
  5751. currentStatus = Faulted; //OCPP Status: Faulted
  5752. }
  5753. else if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_RESERVATION) // ---> Reserved
  5754. {
  5755. currentStatus = Reserved; //OCPP Status: Reserved
  5756. }
  5757. } //end of the same index
  5758. } // end of for GB_QUANTITY
  5759. }
  5760. else if(gunType[gun_index] == GUN_TYPE_DO)
  5761. {
  5762. tempIndex = gun_index;
  5763. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  5764. {
  5765. if(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  5766. {
  5767. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_IDLE) //S_IDLE
  5768. {
  5769. if(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.ConnectorPlugIn == 1) // //0: unplug, 1: Plug-in
  5770. {
  5771. currentStatus = Preparing; //OCPP Status: Preparing
  5772. }
  5773. else
  5774. {
  5775. currentStatus = Available; //OCPP Status: Available
  5776. }
  5777. }
  5778. else if ( ((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus >= SYS_MODE_AUTHORIZING) && (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus <= SYS_MODE_PREPARE_FOR_EVSE)) ||
  5779. ((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus >= SYS_MODE_CCS_PRECHARGE_STEP0) && (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus <= SYS_MODE_CCS_PRECHARGE_STEP1) )
  5780. ) //S_PRECHARGE
  5781. {
  5782. currentStatus = Preparing; //OCPP Status: Preparing
  5783. }
  5784. else if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_CHARGING) //S_CHARGING
  5785. {
  5786. currentStatus = Charging; //OCPP Status: Charging
  5787. }
  5788. else if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_COMPLETE) //S_COMPLETE
  5789. {
  5790. currentStatus = Finishing; //OCPP Status: Finishing
  5791. }
  5792. else if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_TERMINATING) // S_TERMINATING ---> SuspendedEV
  5793. {
  5794. currentStatus = SuspendedEV; //OCPP Status: SuspendedEV
  5795. }
  5796. 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
  5797. {
  5798. currentStatus = Unavailable; //OCPP Status: Unavailable
  5799. }
  5800. 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
  5801. {
  5802. currentStatus = Faulted; //OCPP Status: Faulted
  5803. }
  5804. else if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_RESERVATION) // ---> Reserved
  5805. {
  5806. currentStatus = Reserved; //OCPP Status: Reserved
  5807. }
  5808. } //end of the same index
  5809. }
  5810. }
  5811. else
  5812. {
  5813. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  5814. {
  5815. tempIndex = 2;
  5816. }
  5817. else
  5818. {
  5819. tempIndex = gun_index;
  5820. }
  5821. for (int index = 0; index < AC_QUANTITY; index++)
  5822. {
  5823. if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  5824. {
  5825. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_IDLE) //SYS_MODE_IDLE
  5826. {
  5827. 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))
  5828. {
  5829. currentStatus = Preparing; //OCPP Status: Preparing
  5830. }
  5831. else
  5832. {
  5833. currentStatus = Available; //OCPP Status: Available
  5834. }
  5835. }
  5836. else if ((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_AUTHORIZING) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_PREPARING)) //SYS_MODE_PREPARING
  5837. {
  5838. currentStatus = Preparing; //OCPP Status: Preparing
  5839. }
  5840. else if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_CHARGING) //SYS_MODE_CHARGING
  5841. {
  5842. currentStatus = Charging; //OCPP Status: Charging
  5843. }
  5844. else if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_COMPLETE) //SYS_MODE_COMPLETE
  5845. {
  5846. currentStatus = Finishing; //OCPP Status: Finishing
  5847. }
  5848. else if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_TERMINATING) // S_TERMINATING ---> SuspendedEV
  5849. {
  5850. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PilotState == CP_STATE_B))
  5851. currentStatus = SuspendedEV; //OCPP Status: SuspendedEV
  5852. else
  5853. currentStatus = SuspendedEVSE; //OCPP Status: SuspendedEVSE
  5854. }
  5855. 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
  5856. {
  5857. currentStatus = Unavailable; //OCPP Status: Unavailable
  5858. }
  5859. else if ((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_FAULT) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_ALARM)) //S_ALARM,S_FAULT ---> Faulted
  5860. {
  5861. currentStatus = Faulted; //OCPP Status: Faulted
  5862. }
  5863. else if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_RESERVATION) // ---> Reserved
  5864. {
  5865. currentStatus = Reserved; //OCPP Status: Reserved
  5866. }
  5867. }//end of the same index
  5868. }//end of for AC_QUANTITY
  5869. }
  5870. //it's option
  5871. if(((strstr((char *)ShmOCPP16Data->StatusNotification[gun_index].Status, ChargePointStatusStr[currentStatus]) != NULL) || (((currentStatus == SuspendedEV) || (currentStatus == SuspendedEVSE)) && ShmOCPP16Data->CsMsg.bits[gun_index].RemoteStopTransactionReq)) &&
  5872. !cpinitateMsg.bits[gun_index].TriggerStatusNotificationReq &&
  5873. (strcmp((const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StatusNotificationPeriodically].ItemData, "TRUE") != 0))
  5874. {
  5875. isStateChanged = FALSE;
  5876. }
  5877. cpinitateMsg.bits[gun_index].TriggerStatusNotificationReq = 0;
  5878. strcpy((char *)ShmOCPP16Data->StatusNotification[gun_index].Timestamp, buf);
  5879. strcpy((char *)ShmOCPP16Data->StatusNotification[gun_index].VendorId, (char*)ShmSysConfigAndInfo->SysConfig.chargePointVendor);
  5880. strcpy((char *)ShmOCPP16Data->StatusNotification[gun_index].Status, ChargePointStatusStr[currentStatus]);
  5881. isContentIllegal = TRUE;
  5882. for(int index = 0; index < ARRAY_SIZE(ChargePointErrorCodeStr); index++)
  5883. {
  5884. if(strcmp((char *)ShmOCPP16Data->StatusNotification[gun_index].ErrorCode, ChargePointErrorCodeStr[index])==0)
  5885. {
  5886. isContentIllegal = FALSE;
  5887. break;
  5888. }
  5889. }
  5890. if(isContentIllegal)
  5891. {
  5892. //DEBUG_WARN("Detect illegal ErrorCode: %s \n",(char *)ShmOCPP16Data->StatusNotification[gun_index].ErrorCode);
  5893. strcpy((char *)ShmOCPP16Data->StatusNotification[gun_index].ErrorCode, ChargePointErrorCodeStr[6]);
  5894. }
  5895. random_uuid(guid);
  5896. sprintf(message, "[%d,\"%s\",\"StatusNotification\",{\"connectorId\":%d,\"errorCode\":\"%s\",\"info\":\"%s\",\"status\":\"%s\",\"timestamp\":\"%s\",\"vendorId\":\"%s\",\"vendorErrorCode\":\"%s\"}]"
  5897. , MESSAGE_TYPE_CALL
  5898. , guid
  5899. , ShmOCPP16Data->StatusNotification[gun_index].ConnectorId
  5900. , ShmOCPP16Data->StatusNotification[gun_index].ErrorCode
  5901. , ShmOCPP16Data->StatusNotification[gun_index].Info
  5902. , ShmOCPP16Data->StatusNotification[gun_index].Status
  5903. , ShmOCPP16Data->StatusNotification[gun_index].Timestamp
  5904. , ShmOCPP16Data->StatusNotification[gun_index].VendorId
  5905. , ShmOCPP16Data->StatusNotification[gun_index].VendorErrorCode);
  5906. if((server_sign == TRUE) && isStateChanged)
  5907. {
  5908. cpinitateMsg.bits[gun_index].StatusNotificationReq = 0;
  5909. cpinitateMsg.bits[gun_index].TriggerStatusNotificationReq = 0;
  5910. LWS_Send(message);
  5911. sprintf(tempdata, "StatusNotification,%d", (gun_index));
  5912. 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*/)
  5913. {
  5914. //DEBUG_ERROR("statusNotification mapitem pass");
  5915. result = PASS;
  5916. }
  5917. }
  5918. else
  5919. {
  5920. cpinitateMsg.bits[gun_index].StatusNotificationReq = 0;
  5921. cpinitateMsg.bits[gun_index].TriggerStatusNotificationReq = 0;
  5922. result = PASS;
  5923. }
  5924. return result;
  5925. }
  5926. int sendStopTransactionRequest(int gun_index)
  5927. {
  5928. mtrace();
  5929. int result = FAIL;
  5930. //char message[1500]={0};
  5931. char guid[37]={0};
  5932. char tempdata[65]={0};
  5933. int tempIndex = 0;
  5934. char TempStopTransaction[256];
  5935. sprintf(TempStopTransaction, "/Storage/OCPP/TempStopTransaction_%d", (gun_index+1));
  5936. //int idx_sample=0;
  5937. DEBUG_INFO("sendStopTransactionRequest \n");
  5938. memset(queuedata, 0, ARRAY_SIZE(queuedata));
  5939. memset(&ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0], 0, ARRAY_SIZE(ShmOCPP16Data->StopTransaction[gun_index].TransactionData));
  5940. //=========================== ENERGY_ACTIVE_IMPORT_REGISTER =======================================
  5941. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DCcc
  5942. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  5943. {
  5944. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  5945. {
  5946. tempIndex = ((gun_index==2) ? 1: 0);
  5947. }
  5948. else
  5949. {
  5950. tempIndex = gun_index;
  5951. }
  5952. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  5953. {
  5954. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  5955. {
  5956. ShmOCPP16Data->StopTransaction[gun_index].MeterStop = (int)(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PowerConsumption*1000);
  5957. }
  5958. }// END OF CHAdeMO_QUANTITY
  5959. }
  5960. else if(gunType[gun_index] == GUN_TYPE_CCS)
  5961. {
  5962. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  5963. {
  5964. tempIndex = ((gun_index==2) ? 1: 0);
  5965. }
  5966. else
  5967. {
  5968. tempIndex = gun_index;
  5969. }
  5970. for (int index = 0; index < CCS_QUANTITY; index++)
  5971. {
  5972. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  5973. {
  5974. ShmOCPP16Data->StopTransaction[gun_index].MeterStop = (int)(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PowerConsumption*1000);
  5975. }
  5976. }// END OF CCS_QUANTITY
  5977. }
  5978. else if(gunType[gun_index] == GUN_TYPE_GBT)
  5979. {
  5980. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  5981. {
  5982. tempIndex = ((gun_index==2) ? 1: 0);
  5983. }
  5984. else
  5985. {
  5986. tempIndex = gun_index;
  5987. }
  5988. for (int index = 0; index < GB_QUANTITY; index++)
  5989. {
  5990. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  5991. {
  5992. ShmOCPP16Data->StopTransaction[gun_index].MeterStop = (int)(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PowerConsumption*1000);
  5993. }
  5994. }// END OF GB_QUANTITY
  5995. }
  5996. else if(gunType[gun_index] == GUN_TYPE_DO)
  5997. {
  5998. tempIndex = gun_index;
  5999. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  6000. {
  6001. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  6002. {
  6003. ShmOCPP16Data->StopTransaction[gun_index].MeterStop = (int)(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PowerConsumption*1000);
  6004. }
  6005. }// END OF GB_QUANTITY
  6006. }
  6007. else
  6008. {
  6009. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  6010. {
  6011. tempIndex = 2;
  6012. }
  6013. else
  6014. {
  6015. tempIndex = gun_index;
  6016. }
  6017. for (int index = 0; index < AC_QUANTITY; index++)
  6018. {
  6019. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  6020. {
  6021. ShmOCPP16Data->StopTransaction[gun_index].MeterStop = (int)(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PowerConsumption*1000);
  6022. }
  6023. }// END OF AC_QUANTITY
  6024. }
  6025. //====================================== Stop Transaction Time =====================================================
  6026. struct timeval tmnow;
  6027. struct tm *tm;
  6028. char buf[28];//, usec_buf[6];
  6029. gettimeofday(&tmnow, NULL);
  6030. time_t t;
  6031. t = time(NULL);
  6032. /*UTC time and date*/
  6033. tm = gmtime(&t);
  6034. strftime(buf,28,"%Y-%m-%dT%H:%M:%SZ", tm);
  6035. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].Timestamp,buf);
  6036. ShmOCPP16Data->StopTransaction[gun_index].TransactionId = ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId;
  6037. random_uuid(guid);
  6038. /***********************************transactionData******************************************************/
  6039. memset(ShmOCPP16Data->StopTransaction[gun_index].TransactionData, 0, sizeof(struct StructMeterValue));
  6040. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].TimeStamp, buf);
  6041. //=================================
  6042. // Transaction_Begin
  6043. //=================================
  6044. //=================================
  6045. // Transaction_End
  6046. //=================================
  6047. // ================================= Current.Import L1 ===============================================
  6048. if(strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Current.Import") != NULL)
  6049. {
  6050. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G : GBT DC
  6051. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  6052. {
  6053. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  6054. {
  6055. tempIndex = ((gun_index==2) ? 1: 0);
  6056. }
  6057. else
  6058. {
  6059. tempIndex = gun_index;
  6060. }
  6061. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  6062. {
  6063. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  6064. {
  6065. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargingCurrent );// PresentChargingCurrent is 0~6553.5 amp
  6066. }
  6067. }// End of for CHAdeMO_QUANTITY
  6068. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase,PhaseStr[L3_N]);
  6069. }
  6070. else if(gunType[gun_index] == GUN_TYPE_CCS)
  6071. {
  6072. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  6073. {
  6074. tempIndex = ((gun_index==2) ? 1: 0);
  6075. }
  6076. else
  6077. {
  6078. tempIndex = gun_index;
  6079. }
  6080. for (int index = 0; index < CCS_QUANTITY; index++)
  6081. {
  6082. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  6083. {
  6084. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargingCurrent );// PresentChargingCurrent is 0~6553.5 amp
  6085. }
  6086. }// End of for CCS_QUANTITY
  6087. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase,PhaseStr[L3_N]);
  6088. }
  6089. else if(gunType[gun_index] == GUN_TYPE_GBT)
  6090. {
  6091. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  6092. {
  6093. tempIndex = ((gun_index==2) ? 1: 0);
  6094. }
  6095. else
  6096. {
  6097. tempIndex = gun_index;
  6098. }
  6099. for (int index = 0; index < GB_QUANTITY; index++)
  6100. {
  6101. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  6102. {
  6103. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingCurrent );// PresentChargingCurrent is 0~6553.5 amp
  6104. }
  6105. }// End of for GB_QUANTITY
  6106. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase,PhaseStr[L3_N]);
  6107. }
  6108. else if(gunType[gun_index] == GUN_TYPE_DO)
  6109. {
  6110. tempIndex = gun_index;
  6111. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  6112. {
  6113. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  6114. {
  6115. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PresentChargingCurrent );// PresentChargingCurrent is 0~6553.5 amp
  6116. }
  6117. }
  6118. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase,PhaseStr[L3_N]);
  6119. }
  6120. else
  6121. {
  6122. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  6123. {
  6124. tempIndex = 2;
  6125. }
  6126. else
  6127. {
  6128. tempIndex = gun_index;
  6129. }
  6130. for (int index = 0; index < AC_QUANTITY; index++)
  6131. {
  6132. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  6133. {
  6134. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingCurrent );// 0~6553.5 amp for EVSE
  6135. }
  6136. }// End of for AC_QUANTITY
  6137. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase,PhaseStr[L1_N]);
  6138. }
  6139. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  6140. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Format,ValueFormatStr[Raw]);
  6141. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Measurand,MeasurandStr[Current_Import]);
  6142. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Location,LocationStr[Location_Outlet]);
  6143. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Unit,UnitOfMeasureStr[UnitOfMeasure_A]);
  6144. }
  6145. // ================================= Energy.Active.Import.Interval ==============================================
  6146. if(strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Energy.Active.Import.Interval") != NULL)
  6147. {
  6148. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  6149. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  6150. {
  6151. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  6152. {
  6153. tempIndex = ((gun_index==2) ? 1: 0);
  6154. }
  6155. else
  6156. {
  6157. tempIndex = gun_index;
  6158. }
  6159. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  6160. {
  6161. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  6162. {
  6163. 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
  6164. periousPeriodicPowerConsumption[gun_index] = ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PowerConsumption;
  6165. }
  6166. }// END OF CHAdeMO_QUANTITY
  6167. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase,PhaseStr[L3_N]);
  6168. }
  6169. else if(gunType[gun_index] == GUN_TYPE_CCS)
  6170. {
  6171. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  6172. {
  6173. tempIndex = ((gun_index==2) ? 1: 0);
  6174. }
  6175. else
  6176. {
  6177. tempIndex = gun_index;
  6178. }
  6179. for (int index = 0; index < CCS_QUANTITY; index++)
  6180. {
  6181. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  6182. {
  6183. 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
  6184. periousPeriodicPowerConsumption[gun_index] = ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PowerConsumption;
  6185. }
  6186. }// END OF CCS_QUANTITY
  6187. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase,PhaseStr[L3_N]);
  6188. }
  6189. else if(gunType[gun_index] == GUN_TYPE_GBT)
  6190. {
  6191. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  6192. {
  6193. tempIndex = ((gun_index==2) ? 1: 0);
  6194. }
  6195. else
  6196. {
  6197. tempIndex = gun_index;
  6198. }
  6199. for (int index = 0; index < GB_QUANTITY; index++)
  6200. {
  6201. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  6202. {
  6203. 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
  6204. periousPeriodicPowerConsumption[gun_index] = ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PowerConsumption;
  6205. }
  6206. }// END OF GB_QUANTITY
  6207. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase,PhaseStr[L3_N]);
  6208. }
  6209. else if(gunType[gun_index] == GUN_TYPE_DO)
  6210. {
  6211. tempIndex = gun_index;
  6212. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  6213. {
  6214. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  6215. {
  6216. 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
  6217. periousPeriodicPowerConsumption[gun_index] = ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PowerConsumption;
  6218. }
  6219. }
  6220. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase,PhaseStr[L3_N]);
  6221. }
  6222. else
  6223. {
  6224. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  6225. {
  6226. tempIndex = 2;
  6227. }
  6228. else
  6229. {
  6230. tempIndex = gun_index;
  6231. }
  6232. for (int index = 0; index < AC_QUANTITY; index++)
  6233. {
  6234. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  6235. {
  6236. 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
  6237. periousPeriodicPowerConsumption[gun_index] = ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PowerConsumption;
  6238. }
  6239. }// END OF AC_QUANTITY
  6240. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase,PhaseStr[L1_N]);
  6241. }
  6242. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  6243. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Format,ValueFormatStr[Raw]);
  6244. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Measurand,MeasurandStr[Energy_Active_Import_Interval]);
  6245. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Location,LocationStr[Location_Outlet]);
  6246. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Unit,UnitOfMeasureStr[UnitOfMeasure_kWh]);
  6247. }
  6248. //=================================== Power.Active.Import ==================================================
  6249. if(strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Power.Active.Import") != NULL)
  6250. {
  6251. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  6252. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  6253. {
  6254. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  6255. {
  6256. tempIndex = ((gun_index==2) ? 1: 0);
  6257. }
  6258. else
  6259. {
  6260. tempIndex = gun_index;
  6261. }
  6262. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  6263. {
  6264. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  6265. {
  6266. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargingPower );// PresentChargingPower is 0~6553.5 kW
  6267. }
  6268. } // End for CHAdeMO_QUANTITY
  6269. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase,PhaseStr[L3_N]);
  6270. }
  6271. else if(gunType[gun_index] == GUN_TYPE_CCS)
  6272. {
  6273. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  6274. {
  6275. tempIndex = ((gun_index==2) ? 1: 0);
  6276. }
  6277. else
  6278. {
  6279. tempIndex = gun_index;
  6280. }
  6281. for (int index = 0; index < CCS_QUANTITY; index++)
  6282. {
  6283. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  6284. {
  6285. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargingPower );// PresentChargingPower is 0~6553.5 kW
  6286. }
  6287. } // END for CCS_QUANTITY
  6288. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase,PhaseStr[L3_N]);
  6289. }
  6290. else if(gunType[gun_index] == GUN_TYPE_GBT)
  6291. {
  6292. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  6293. {
  6294. tempIndex = ((gun_index==2) ? 1: 0);
  6295. }
  6296. else
  6297. {
  6298. tempIndex = gun_index;
  6299. }
  6300. for (int index = 0; index < GB_QUANTITY; index++)
  6301. {
  6302. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  6303. {
  6304. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingPower );// PresentChargingPower is 0~6553.5 kW
  6305. }
  6306. }// END for GB_QUANTITY
  6307. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase,PhaseStr[L3_N]);
  6308. }
  6309. else if(gunType[gun_index] == GUN_TYPE_DO)
  6310. {
  6311. tempIndex = gun_index;
  6312. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  6313. {
  6314. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  6315. {
  6316. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PresentChargingPower );// PresentChargingPower is 0~6553.5 kW
  6317. }
  6318. }
  6319. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase,PhaseStr[L3_N]);
  6320. }
  6321. else
  6322. {
  6323. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  6324. {
  6325. tempIndex = 2;
  6326. }
  6327. else
  6328. {
  6329. tempIndex = gun_index;
  6330. }
  6331. for (int index = 0; index < AC_QUANTITY; index++)
  6332. {
  6333. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  6334. {
  6335. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingPower );// PresentChargingPower is 0~6553.5 kW
  6336. }
  6337. } // END for AC_QUANTITY
  6338. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase,PhaseStr[L1_N]);
  6339. }
  6340. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  6341. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Format,ValueFormatStr[Raw]);
  6342. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Measurand,MeasurandStr[Power_Active_Import]);
  6343. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Location,LocationStr[Location_Outlet]);
  6344. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Unit,UnitOfMeasureStr[UnitOfMeasure_kW/*UnitOfMeasure_kWh*/]);
  6345. }
  6346. //============================ Voltage L1 ====================================
  6347. if(strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Voltage") != NULL)
  6348. {
  6349. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  6350. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  6351. {
  6352. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  6353. {
  6354. tempIndex = ((gun_index==2) ? 1: 0);
  6355. }
  6356. else
  6357. {
  6358. tempIndex = gun_index;
  6359. }
  6360. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  6361. {
  6362. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  6363. {
  6364. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargingVoltage );// PresentChargingVoltage is 0~6553.5 volt
  6365. }
  6366. } // END OF FOR CHAdeMO_QUANTITY
  6367. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase,PhaseStr[L3_N]);
  6368. }
  6369. else if(gunType[gun_index] == GUN_TYPE_CCS)
  6370. {
  6371. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  6372. {
  6373. tempIndex = ((gun_index==2) ? 1: 0);
  6374. }
  6375. else
  6376. {
  6377. tempIndex = gun_index;
  6378. }
  6379. for (int index = 0; index < CCS_QUANTITY; index++)
  6380. {
  6381. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  6382. {
  6383. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargingVoltage );// PresentChargingVoltage is 0~6553.5 volt
  6384. }
  6385. } // END OF FOR CCS_QUANTITY
  6386. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase,PhaseStr[L3_N]);
  6387. }
  6388. else if(gunType[gun_index] == GUN_TYPE_GBT)
  6389. {
  6390. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  6391. {
  6392. tempIndex = ((gun_index==2) ? 1: 0);
  6393. }
  6394. else
  6395. {
  6396. tempIndex = gun_index;
  6397. }
  6398. for (int index = 0; index < GB_QUANTITY; index++)
  6399. {
  6400. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  6401. {
  6402. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingVoltage );// PresentChargingVoltage is 0~6553.5 volt
  6403. }
  6404. } // END OF FOR GB_QUANTITY
  6405. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase,PhaseStr[L3_N]);
  6406. }
  6407. else if(gunType[gun_index] == GUN_TYPE_DO)
  6408. {
  6409. tempIndex = gun_index;
  6410. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  6411. {
  6412. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  6413. {
  6414. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PresentChargingVoltage );// PresentChargingVoltage is 0~6553.5 volt
  6415. }
  6416. }
  6417. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase,PhaseStr[L3_N]);
  6418. }
  6419. else
  6420. {
  6421. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  6422. {
  6423. tempIndex = 2;
  6424. }
  6425. else
  6426. {
  6427. tempIndex = gun_index;
  6428. }
  6429. for (int index = 0; index < AC_QUANTITY; index++)
  6430. {
  6431. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  6432. {
  6433. 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
  6434. }
  6435. } // END OF FOR AC_QUANTITY
  6436. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase,PhaseStr[L1_N]);
  6437. }
  6438. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  6439. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Format,ValueFormatStr[Raw]);
  6440. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Measurand,MeasurandStr[Voltage]);
  6441. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Location,LocationStr[Location_Outlet]);
  6442. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Unit,UnitOfMeasureStr[UnitOfMeasure_V]);
  6443. }
  6444. //====================== End SoC ================================
  6445. if(strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, MeasurandStr[SoC]) != NULL)
  6446. {
  6447. //J : CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  6448. 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))
  6449. {
  6450. if((ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0') && (gunType[gun_index] != GUN_TYPE_DO))
  6451. {
  6452. tempIndex = ((gun_index==2) ? 1: 0);
  6453. }
  6454. else
  6455. {
  6456. tempIndex = gun_index;
  6457. }
  6458. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  6459. {
  6460. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  6461. {
  6462. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  6463. {
  6464. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].EvBatterySoc );// 0~100%
  6465. }
  6466. }
  6467. }
  6468. else if(gunType[gun_index] == GUN_TYPE_CCS)
  6469. {
  6470. for (int index = 0; index < CCS_QUANTITY; index++)
  6471. {
  6472. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  6473. {
  6474. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].EvBatterySoc );// 0~100%
  6475. }
  6476. }
  6477. }
  6478. else if(gunType[gun_index] == GUN_TYPE_GBT)
  6479. {
  6480. for (int index = 0; index < GB_QUANTITY; index++)
  6481. {
  6482. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  6483. {
  6484. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].EvBatterySoc );// 0~100%
  6485. }
  6486. }
  6487. }
  6488. else if(gunType[gun_index] == GUN_TYPE_DO)
  6489. {
  6490. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  6491. {
  6492. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  6493. {
  6494. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.EvBatterySoc );// 0~100%
  6495. }
  6496. }
  6497. }
  6498. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  6499. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Format,ValueFormatStr[Raw]);
  6500. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Measurand,MeasurandStr[SoC/*Energy_Reactive_Export_Register*/]);
  6501. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Phase,PhaseStr[L3_N]);
  6502. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Location,LocationStr[Location_EV]);
  6503. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Unit,UnitOfMeasureStr[UnitOfMeasure_Percent/*UnitOfMeasure_kWh*/]);
  6504. } // END FOR DC CASE
  6505. }
  6506. // ================================= Current.Import L2 ===============================================
  6507. if(strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Current.Import") != NULL)
  6508. {
  6509. // AC 3 phse L2 current
  6510. if((gunType[gun_index] == GUN_TYPE_AC) && ((ShmSysConfigAndInfo->SysConfig.ModelName[2]=='Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='W') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='D')))
  6511. {
  6512. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  6513. {
  6514. tempIndex = 2;
  6515. }
  6516. else
  6517. {
  6518. tempIndex = gun_index;
  6519. }
  6520. for (int index = 0; index < AC_QUANTITY; index++)
  6521. {
  6522. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  6523. {
  6524. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingCurrentL2 );// 0~6553.5 amp for EVSE
  6525. }
  6526. }// End of for AC_QUANTITY
  6527. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Phase,PhaseStr[L2_N]);
  6528. }
  6529. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  6530. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Format,ValueFormatStr[Raw]);
  6531. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Measurand,MeasurandStr[Current_Import]);
  6532. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Location,LocationStr[Location_Outlet]);
  6533. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Unit,UnitOfMeasureStr[UnitOfMeasure_A]);
  6534. }
  6535. // ================================= Current.Import L3 ===============================================
  6536. if(strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Current.Import") != NULL)
  6537. {
  6538. // AC 3 phse L3 current
  6539. if((gunType[gun_index] == GUN_TYPE_AC) && ((ShmSysConfigAndInfo->SysConfig.ModelName[2]=='Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='W') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='D')))
  6540. {
  6541. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  6542. {
  6543. tempIndex = 2;
  6544. }
  6545. else
  6546. {
  6547. tempIndex = gun_index;
  6548. }
  6549. for (int index = 0; index < AC_QUANTITY; index++)
  6550. {
  6551. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  6552. {
  6553. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingCurrentL3 );// 0~6553.5 amp for EVSE
  6554. }
  6555. }// End of for AC_QUANTITY
  6556. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Phase,PhaseStr[L3_N]);
  6557. }
  6558. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  6559. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Format,ValueFormatStr[Raw]);
  6560. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Measurand,MeasurandStr[Current_Import]);
  6561. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Location,LocationStr[Location_Outlet]);
  6562. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Unit,UnitOfMeasureStr[UnitOfMeasure_A]);
  6563. }
  6564. //============================ Voltage L2 ====================================
  6565. if(strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Voltage") != NULL)
  6566. {
  6567. // AC 3 phse L2 voltage
  6568. if((gunType[gun_index] == GUN_TYPE_AC) && ((ShmSysConfigAndInfo->SysConfig.ModelName[2]=='Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='W') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='D')))
  6569. {
  6570. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  6571. {
  6572. tempIndex = 2;
  6573. }
  6574. else
  6575. {
  6576. tempIndex = gun_index;
  6577. }
  6578. for (int index = 0; index < AC_QUANTITY; index++)
  6579. {
  6580. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  6581. {
  6582. 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
  6583. }
  6584. } // END OF FOR AC_QUANTITY
  6585. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Phase,PhaseStr[L2_N]);
  6586. }
  6587. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  6588. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Format,ValueFormatStr[Raw]);
  6589. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Measurand,MeasurandStr[Voltage]);
  6590. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Location,LocationStr[Location_Outlet]);
  6591. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Unit,UnitOfMeasureStr[UnitOfMeasure_V]);
  6592. }
  6593. //============================ Voltage L3 ====================================
  6594. if(strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Voltage") != NULL)
  6595. {
  6596. // AC 3 phse L3 voltage
  6597. if((gunType[gun_index] == GUN_TYPE_AC) && ((ShmSysConfigAndInfo->SysConfig.ModelName[2]=='Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='W') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='D')))
  6598. {
  6599. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  6600. {
  6601. tempIndex = 2;
  6602. }
  6603. else
  6604. {
  6605. tempIndex = gun_index;
  6606. }
  6607. for (int index = 0; index < AC_QUANTITY; index++)
  6608. {
  6609. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  6610. {
  6611. 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
  6612. }
  6613. } // END OF FOR AC_QUANTITY
  6614. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Phase,PhaseStr[L3_N]);
  6615. }
  6616. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  6617. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Format,ValueFormatStr[Raw]);
  6618. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Measurand,MeasurandStr[Voltage]);
  6619. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Location,LocationStr[Location_Outlet]);
  6620. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Unit,UnitOfMeasureStr[UnitOfMeasure_V]);
  6621. }
  6622. //====================== Start SoC ================================
  6623. if(strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, MeasurandStr[SoC]) != NULL)
  6624. {
  6625. //J : CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  6626. 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))
  6627. {
  6628. if((ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0') && (gunType[gun_index] != GUN_TYPE_DO))
  6629. {
  6630. tempIndex = ((gun_index==2) ? 1: 0);
  6631. }
  6632. else
  6633. {
  6634. tempIndex = gun_index;
  6635. }
  6636. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  6637. {
  6638. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  6639. {
  6640. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  6641. {
  6642. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].EvBatteryStartSoc );// 0~100%
  6643. }
  6644. }
  6645. }
  6646. else if(gunType[gun_index] == GUN_TYPE_CCS)
  6647. {
  6648. for (int index = 0; index < CCS_QUANTITY; index++)
  6649. {
  6650. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  6651. {
  6652. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].EvBatteryStartSoc );// 0~100%
  6653. }
  6654. }
  6655. }
  6656. else if(gunType[gun_index] == GUN_TYPE_GBT)
  6657. {
  6658. for (int index = 0; index < GB_QUANTITY; index++)
  6659. {
  6660. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  6661. {
  6662. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].EvBatteryStartSoc );// 0~100%
  6663. }
  6664. }
  6665. }
  6666. else if(gunType[gun_index] == GUN_TYPE_DO)
  6667. {
  6668. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  6669. {
  6670. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  6671. {
  6672. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.EvBatteryStartSoc );// 0~100%
  6673. }
  6674. }
  6675. }
  6676. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Context,ReadingContextStr[ReadingContext_Transaction_Begin]);
  6677. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Format,ValueFormatStr[Raw]);
  6678. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Measurand,MeasurandStr[SoC/*Energy_Reactive_Export_Register*/]);
  6679. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Phase,PhaseStr[L3_N]);
  6680. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Location,LocationStr[Location_EV]);
  6681. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Unit,UnitOfMeasureStr[UnitOfMeasure_Percent/*UnitOfMeasure_kWh*/]);
  6682. } // END FOR DC CASE
  6683. }
  6684. //================================================ Message create ====================================================
  6685. json_object *StopTransaction = json_object_new_object();
  6686. json_object *transactionDatas = json_object_new_array();
  6687. json_object *sampledValues = json_object_new_array();
  6688. if(strlen((char*)ShmOCPP16Data->StopTransaction[gun_index].IdTag) > 0)
  6689. json_object_object_add(StopTransaction, "idTag", json_object_new_string((char*)ShmOCPP16Data->StopTransaction[gun_index].IdTag));
  6690. json_object_object_add(StopTransaction, "meterStop", json_object_new_int(ShmOCPP16Data->StopTransaction[gun_index].MeterStop));
  6691. json_object_object_add(StopTransaction, "transactionId", json_object_new_int(ShmOCPP16Data->StopTransaction[gun_index].TransactionId));
  6692. json_object_object_add(StopTransaction, "timestamp", json_object_new_string((char*)ShmOCPP16Data->StopTransaction[gun_index].Timestamp));
  6693. if(strlen((char*)ShmOCPP16Data->StopTransaction[gun_index].StopReason) > 0)
  6694. json_object_object_add(StopTransaction, "reason", json_object_new_string((char*)ShmOCPP16Data->StopTransaction[gun_index].StopReason));
  6695. for(int idxTrans = 0;idxTrans<ARRAY_SIZE(ShmOCPP16Data->StopTransaction[gun_index].TransactionData);idxTrans++)
  6696. {
  6697. json_object *transactionData = json_object_new_object();
  6698. json_object_object_add(transactionData, "timestamp", json_object_new_string((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].TimeStamp));
  6699. for(int idx=0;idx<ARRAY_SIZE(ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue);idx++)
  6700. {
  6701. if(strlen((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Value) > 0)
  6702. {
  6703. json_object *sampledValue = json_object_new_object();
  6704. json_object_object_add(sampledValue, "value", json_object_new_string((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Value));
  6705. if(strlen((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Context) > 0)
  6706. json_object_object_add(sampledValue, "context", json_object_new_string((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Context));
  6707. if(strlen((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Format) > 0)
  6708. json_object_object_add(sampledValue, "format", json_object_new_string((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Format));
  6709. if(strlen((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Measurand) > 0)
  6710. json_object_object_add(sampledValue, "measurand", json_object_new_string((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Measurand));
  6711. if(strlen((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Phase) > 0)
  6712. json_object_object_add(sampledValue, "phase", json_object_new_string((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Phase));
  6713. if(strlen((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Location) > 0)
  6714. json_object_object_add(sampledValue, "location", json_object_new_string((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Location));
  6715. if(strlen((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Unit) > 0)
  6716. json_object_object_add(sampledValue, "unit", json_object_new_string((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Unit));
  6717. json_object_array_add(sampledValues, sampledValue);
  6718. }
  6719. }
  6720. json_object_object_add(transactionData, "sampledValue", sampledValues);
  6721. json_object_array_add(transactionDatas, transactionData);
  6722. }
  6723. json_object_object_add(StopTransaction, "transactionData", transactionDatas);
  6724. sprintf(queuedata, "%d,[%d,\"%s\",\"StopTransaction\",%s]",(gun_index+1)
  6725. ,MESSAGE_TYPE_CALL
  6726. ,guid
  6727. ,json_object_to_json_string_ext(StopTransaction, JSON_C_TO_STRING_PLAIN));
  6728. json_object_put(StopTransaction);
  6729. #if 1 // for TempStopTransaction
  6730. //Delete TempStopTransaction
  6731. if((access(TempStopTransaction,F_OK))!=-1)
  6732. {
  6733. remove(TempStopTransaction); // remove file "TempStopTransaction"
  6734. }
  6735. #endif
  6736. #if 1
  6737. sprintf(tempdata, "StopTransaction,%d", (gun_index));
  6738. if(hashmap_operation(HASH_OP_ADD, guid, tempdata) == 1)
  6739. {
  6740. result = PASS;
  6741. //DEBUG_INFO("StopTransaction mapitem pass\n");
  6742. }
  6743. #endif
  6744. queue_operation(QUEUE_OPERATION_ADD, guid, queuedata );//addq(guid, queuedata); ---> remove temporally
  6745. OCPP_insert_transaction_msg(NO, queuedata);
  6746. //----------------------------replace queue StopTransaction TransactionId ---------------------------//
  6747. //int gettransactionId = GetTransactionId(gun_index+1, ShmOCPP16Data->StopTransaction[gun_index].IdTag);
  6748. int gettransactionId = GetTransactionId(gun_index+1, ShmOCPP16Data->StartTransaction[gun_index].IdTag, TRUE);
  6749. if((ShmOCPP16Data->StopTransaction[gun_index].TransactionId != 0) && (gettransactionId != 0))
  6750. {
  6751. //SetTransactionIdZero(ShmOCPP16Data->StopTransaction[gun_index].TransactionId);
  6752. }
  6753. //for test
  6754. //ShmOCPP16Data->CpMsg.bits[gun_index].StopTransactionReq = 0;
  6755. return result;
  6756. }
  6757. int sendMeterValuesRequest(int gun_index, ReadingContext dataType)
  6758. {
  6759. mtrace();
  6760. int result = FAIL;
  6761. char guid[37]={0};
  6762. char tempdata[65]={0};
  6763. int tempIndex = 0;
  6764. DEBUG_INFO("sendMeterValuesRequest ...\n");
  6765. memset(queuedata, 0, ARRAY_SIZE(queuedata));
  6766. memset(&ShmOCPP16Data->MeterValues[gun_index], 0, sizeof(struct StructMeterValues));
  6767. //set value
  6768. ShmOCPP16Data->MeterValues[gun_index].ConnectorId = gun_index + 1; // gun start from 1~
  6769. ShmOCPP16Data->MeterValues[gun_index].TransactionId = (cpinitateMsg.bits[gun_index].isOnCharging?
  6770. ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId :
  6771. -1);
  6772. random_uuid(guid);
  6773. //UTC Date time
  6774. struct timeval tmnow;
  6775. struct tm *tm;
  6776. char buf[28];//, usec_buf[6];
  6777. gettimeofday(&tmnow, NULL);
  6778. time_t t;
  6779. t = time(NULL);
  6780. /*UTC time and date*/
  6781. tm = gmtime(&t);
  6782. if(dataType == ReadingContext_Sample_Clock)
  6783. {
  6784. struct tm *tmTarget;
  6785. struct timeb tbTarget;
  6786. tbTarget.time = mktime(tm);
  6787. tbTarget.time -= (atoi((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemData));
  6788. tmTarget = gmtime(&tbTarget.time);
  6789. strftime(buf,28,"%Y-%m-%dT%H:%M:%SZ", tmTarget);
  6790. }
  6791. else
  6792. {
  6793. strftime(buf,28,"%Y-%m-%dT%H:%M:%SZ", tm);
  6794. }
  6795. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].TimeStamp, buf);
  6796. //DEBUG_INFO("ShmSysConfigAndInfo->SysConfig.ModelName[0]=%c\n", ShmSysConfigAndInfo->SysConfig.ModelName[0]);
  6797. //********************************(1)Current.Import L1************************************************/
  6798. if(((dataType == ReadingContext_Sample_Clock) && (strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, MeasurandStr[Current_Import]) != NULL)) ||
  6799. ((dataType == ReadingContext_Sample_Periodic) && (strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, MeasurandStr[Current_Import]) != NULL)) ||
  6800. (dataType == ReadingContext_Trigger))
  6801. {
  6802. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  6803. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  6804. {
  6805. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  6806. {
  6807. tempIndex = ((gun_index==2) ? 1: 0);
  6808. }
  6809. else
  6810. {
  6811. tempIndex = gun_index;
  6812. }
  6813. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  6814. {
  6815. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  6816. {
  6817. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargingCurrent );
  6818. }
  6819. }
  6820. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Phase, PhaseStr[L3_N]);
  6821. }
  6822. else if(gunType[gun_index] == GUN_TYPE_CCS)
  6823. {
  6824. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  6825. {
  6826. tempIndex = ((gun_index==2) ? 1: 0);
  6827. }
  6828. else
  6829. {
  6830. tempIndex = gun_index;
  6831. }
  6832. for (int index = 0; index < CCS_QUANTITY; index++)
  6833. {
  6834. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  6835. {
  6836. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargingCurrent );
  6837. }
  6838. }
  6839. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Phase, PhaseStr[L3_N]);
  6840. }
  6841. else if(gunType[gun_index] == GUN_TYPE_GBT)
  6842. {
  6843. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  6844. {
  6845. tempIndex = ((gun_index==2) ? 1: 0);
  6846. }
  6847. else
  6848. {
  6849. tempIndex = gun_index;
  6850. }
  6851. for (int index = 0; index < GB_QUANTITY; index++)
  6852. {
  6853. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  6854. {
  6855. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingCurrent );
  6856. }
  6857. }
  6858. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Phase, PhaseStr[L3_N]);
  6859. }
  6860. else if(gunType[gun_index] == GUN_TYPE_DO)
  6861. {
  6862. tempIndex = gun_index;
  6863. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  6864. {
  6865. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  6866. {
  6867. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PresentChargingCurrent );
  6868. }
  6869. }
  6870. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Phase, PhaseStr[L3_N]);
  6871. }
  6872. else
  6873. {
  6874. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  6875. {
  6876. tempIndex = 2;
  6877. }
  6878. else
  6879. {
  6880. tempIndex = gun_index;
  6881. }
  6882. for (int index = 0; index < AC_QUANTITY; index++)
  6883. {
  6884. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  6885. {
  6886. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingCurrent );
  6887. }
  6888. }
  6889. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Phase, PhaseStr[L1_N]);
  6890. }
  6891. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Context, ReadingContextStr[dataType]);
  6892. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Format, ValueFormatStr[Raw]);
  6893. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Measurand, MeasurandStr[Current_Import]);
  6894. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Location, LocationStr[Location_Outlet]);
  6895. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Unit,UnitOfMeasureStr[UnitOfMeasure_A]);
  6896. }
  6897. //********************************(2)Energy.Active.Import.Register ************************************************/
  6898. if(((dataType == ReadingContext_Sample_Clock) && (strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, MeasurandStr[Energy_Active_Import_Register]) != NULL)) ||
  6899. ((dataType == ReadingContext_Sample_Periodic) && (strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, MeasurandStr[Energy_Active_Import_Register]) != NULL)) ||
  6900. (dataType == ReadingContext_Trigger))
  6901. {
  6902. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  6903. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  6904. {
  6905. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  6906. {
  6907. tempIndex = ((gun_index==2) ? 1: 0);
  6908. }
  6909. else
  6910. {
  6911. tempIndex = gun_index;
  6912. }
  6913. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  6914. {
  6915. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  6916. {
  6917. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PowerConsumption );
  6918. }
  6919. }
  6920. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Phase, PhaseStr[L3_N]);
  6921. }
  6922. else if(gunType[gun_index] == GUN_TYPE_CCS)
  6923. {
  6924. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  6925. {
  6926. tempIndex = ((gun_index==2) ? 1: 0);
  6927. }
  6928. else
  6929. {
  6930. tempIndex = gun_index;
  6931. }
  6932. for (int index = 0; index < CCS_QUANTITY; index++)
  6933. {
  6934. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  6935. {
  6936. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PowerConsumption );
  6937. }
  6938. }
  6939. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Phase, PhaseStr[L3_N]);
  6940. }
  6941. else if(gunType[gun_index] == GUN_TYPE_GBT)
  6942. {
  6943. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  6944. {
  6945. tempIndex = ((gun_index==2) ? 1: 0);
  6946. }
  6947. else
  6948. {
  6949. tempIndex = gun_index;
  6950. }
  6951. for (int index = 0; index < GB_QUANTITY; index++)
  6952. {
  6953. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  6954. {
  6955. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PowerConsumption );
  6956. }
  6957. }
  6958. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Phase, PhaseStr[L3_N]);
  6959. }
  6960. else if(gunType[gun_index] == GUN_TYPE_DO)
  6961. {
  6962. tempIndex = gun_index;
  6963. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  6964. {
  6965. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  6966. {
  6967. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PowerConsumption );
  6968. }
  6969. }
  6970. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Phase, PhaseStr[L3_N]);
  6971. }
  6972. else
  6973. {
  6974. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  6975. {
  6976. tempIndex = 2;
  6977. }
  6978. else
  6979. {
  6980. tempIndex = gun_index;
  6981. }
  6982. for (int index = 0; index < AC_QUANTITY; index++)
  6983. {
  6984. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  6985. {
  6986. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PowerConsumption );
  6987. }
  6988. }
  6989. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Phase, PhaseStr[L1_N]);
  6990. }
  6991. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Context, ReadingContextStr[dataType]);
  6992. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Format, ValueFormatStr[Raw]);
  6993. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Measurand, MeasurandStr[Energy_Active_Import_Register]);
  6994. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Location, LocationStr[Location_Outlet]);
  6995. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Unit,UnitOfMeasureStr[UnitOfMeasure_kWh]);
  6996. }
  6997. //****************************************************(3)Energy.Active.Import.Interval*********************************************/
  6998. if(((dataType == ReadingContext_Sample_Clock) && (strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, MeasurandStr[Energy_Active_Import_Interval]) != NULL)) ||
  6999. ((dataType == ReadingContext_Sample_Periodic) && (strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, MeasurandStr[Energy_Active_Import_Interval]) != NULL)) ||
  7000. (dataType == ReadingContext_Trigger))
  7001. {
  7002. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  7003. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  7004. {
  7005. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  7006. {
  7007. tempIndex = ((gun_index==2) ? 1: 0);
  7008. }
  7009. else
  7010. {
  7011. tempIndex = gun_index;
  7012. }
  7013. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  7014. {
  7015. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  7016. {
  7017. if(dataType == ReadingContext_Sample_Clock)
  7018. {
  7019. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Value, "%.3f" ,(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PowerConsumption - periousClockPowerConsumption[gun_index]));
  7020. periousClockPowerConsumption[gun_index] = ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PowerConsumption;
  7021. }
  7022. else if(dataType == ReadingContext_Sample_Periodic)
  7023. {
  7024. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Value, "%.3f" ,(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PowerConsumption - periousPeriodicPowerConsumption[gun_index]));
  7025. periousPeriodicPowerConsumption[gun_index] = ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PowerConsumption;
  7026. }
  7027. else
  7028. {
  7029. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Value, "0.000");
  7030. }
  7031. }
  7032. } // END OF FOR CHAdeMO_QUANTITY
  7033. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Phase, PhaseStr[L3_N]);
  7034. }
  7035. else if(gunType[gun_index] == GUN_TYPE_CCS)
  7036. {
  7037. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  7038. {
  7039. tempIndex = ((gun_index==2) ? 1: 0);
  7040. }
  7041. else
  7042. {
  7043. tempIndex = gun_index;
  7044. }
  7045. for (int index = 0; index < CCS_QUANTITY; index++)
  7046. {
  7047. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  7048. {
  7049. if(dataType == ReadingContext_Sample_Clock)
  7050. {
  7051. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Value, "%.3f" ,(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PowerConsumption - periousClockPowerConsumption[gun_index]));
  7052. periousClockPowerConsumption[gun_index] = ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PowerConsumption;
  7053. }
  7054. else if(dataType == ReadingContext_Sample_Periodic)
  7055. {
  7056. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Value, "%.3f" ,(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PowerConsumption - periousPeriodicPowerConsumption[gun_index]));
  7057. periousPeriodicPowerConsumption[gun_index] = ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PowerConsumption;
  7058. }
  7059. else
  7060. {
  7061. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Value, "0.000");
  7062. }
  7063. }
  7064. } // END OF CCS_QUANTITY
  7065. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Phase, PhaseStr[L3_N]);
  7066. }
  7067. else if(gunType[gun_index] == GUN_TYPE_GBT)
  7068. {
  7069. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  7070. {
  7071. tempIndex = ((gun_index==2) ? 1: 0);
  7072. }
  7073. else
  7074. {
  7075. tempIndex = gun_index;
  7076. }
  7077. for (int index = 0; index < GB_QUANTITY; index++)
  7078. {
  7079. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  7080. {
  7081. if(dataType == ReadingContext_Sample_Clock)
  7082. {
  7083. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Value, "%.3f" ,(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PowerConsumption - periousClockPowerConsumption[gun_index]));
  7084. periousClockPowerConsumption[gun_index] = ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PowerConsumption;
  7085. }
  7086. else if(dataType == ReadingContext_Sample_Periodic)
  7087. {
  7088. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Value, "%.3f" ,(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PowerConsumption - periousPeriodicPowerConsumption[gun_index]));
  7089. periousPeriodicPowerConsumption[gun_index] = ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PowerConsumption;
  7090. }
  7091. else
  7092. {
  7093. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Value, "0.000");
  7094. }
  7095. }
  7096. } // END OF GB_QUANTITY
  7097. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Phase, PhaseStr[L3_N]);
  7098. }
  7099. else if(gunType[gun_index] == GUN_TYPE_DO)
  7100. {
  7101. tempIndex = gun_index;
  7102. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  7103. {
  7104. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  7105. {
  7106. if(dataType == ReadingContext_Sample_Clock)
  7107. {
  7108. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Value, "%.3f" ,(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PowerConsumption - periousClockPowerConsumption[gun_index]));
  7109. periousClockPowerConsumption[gun_index] = ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PowerConsumption;
  7110. }
  7111. else if(dataType == ReadingContext_Sample_Periodic)
  7112. {
  7113. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Value, "%.3f" ,(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PowerConsumption - periousPeriodicPowerConsumption[gun_index]));
  7114. periousPeriodicPowerConsumption[gun_index] = ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PowerConsumption;
  7115. }
  7116. else
  7117. {
  7118. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Value, "0.000");
  7119. }
  7120. }
  7121. }
  7122. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Phase, PhaseStr[L3_N]);
  7123. }
  7124. else
  7125. {
  7126. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  7127. {
  7128. tempIndex = 2;
  7129. }
  7130. else
  7131. {
  7132. tempIndex = gun_index;
  7133. }
  7134. for (int index = 0; index < AC_QUANTITY; index++)
  7135. {
  7136. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  7137. {
  7138. if(dataType == ReadingContext_Sample_Clock)
  7139. {
  7140. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Value, "%.3f" ,(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PowerConsumption - periousClockPowerConsumption[gun_index]));
  7141. periousClockPowerConsumption[gun_index] = ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PowerConsumption;
  7142. }
  7143. else if(dataType == ReadingContext_Sample_Periodic)
  7144. {
  7145. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Value, "%.3f" ,(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PowerConsumption - periousPeriodicPowerConsumption[gun_index]));
  7146. periousPeriodicPowerConsumption[gun_index] = ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PowerConsumption;
  7147. }
  7148. else
  7149. {
  7150. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Value, "0.000");
  7151. }
  7152. }
  7153. }
  7154. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Phase, PhaseStr[L1_N]);
  7155. }
  7156. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Context, ReadingContextStr[dataType]);
  7157. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Format, ValueFormatStr[Raw]);
  7158. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Measurand, MeasurandStr[Energy_Active_Import_Interval]);
  7159. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Location, LocationStr[Location_Outlet]);
  7160. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Unit,UnitOfMeasureStr[UnitOfMeasure_kWh]);
  7161. }
  7162. //********************************(4)Power.Active.Import************************************************/
  7163. if(((dataType == ReadingContext_Sample_Clock) && (strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, MeasurandStr[Power_Active_Import]) != NULL)) ||
  7164. ((dataType == ReadingContext_Sample_Periodic) && (strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, MeasurandStr[Power_Active_Import]) != NULL)) ||
  7165. (dataType == ReadingContext_Trigger))
  7166. {
  7167. //J : CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  7168. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  7169. {
  7170. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  7171. {
  7172. tempIndex = ((gun_index==2) ? 1: 0);
  7173. }
  7174. else
  7175. {
  7176. tempIndex = gun_index;
  7177. }
  7178. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  7179. {
  7180. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  7181. {
  7182. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Value, "%.1f" , ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargingPower);
  7183. }
  7184. } // END OF FOR
  7185. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Phase, PhaseStr[L3_N]);
  7186. }
  7187. else if(gunType[gun_index] == GUN_TYPE_CCS)
  7188. {
  7189. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  7190. {
  7191. tempIndex = ((gun_index==2) ? 1: 0);
  7192. }
  7193. else
  7194. {
  7195. tempIndex = gun_index;
  7196. }
  7197. for (int index = 0; index < CCS_QUANTITY; index++)
  7198. {
  7199. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  7200. {
  7201. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Value, "%.1f" , ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargingPower);
  7202. }
  7203. }
  7204. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Phase, PhaseStr[L3_N]);
  7205. }
  7206. else if(gunType[gun_index] == GUN_TYPE_GBT)
  7207. {
  7208. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  7209. {
  7210. tempIndex = ((gun_index==2) ? 1: 0);
  7211. }
  7212. else
  7213. {
  7214. tempIndex = gun_index;
  7215. }
  7216. for (int index = 0; index < GB_QUANTITY; index++)
  7217. {
  7218. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  7219. {
  7220. //ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingPower = 100.0;
  7221. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Value, "%.1f" , ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingPower);
  7222. }
  7223. }
  7224. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Phase, PhaseStr[L3_N]);
  7225. }
  7226. else if(gunType[gun_index] == GUN_TYPE_DO)
  7227. {
  7228. tempIndex = gun_index;
  7229. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  7230. {
  7231. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  7232. {
  7233. //ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingPower = 100.0;
  7234. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Value, "%.1f" , ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PresentChargingPower);
  7235. }
  7236. }
  7237. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Phase, PhaseStr[L3_N]);
  7238. }
  7239. else
  7240. {
  7241. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  7242. {
  7243. tempIndex = 2;
  7244. }
  7245. else
  7246. {
  7247. tempIndex = gun_index;
  7248. }
  7249. for (int index = 0; index < AC_QUANTITY; index++)
  7250. {
  7251. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  7252. {
  7253. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Value, "%.1f" , ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingPower);
  7254. }
  7255. }
  7256. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Phase, PhaseStr[L1_N]);
  7257. }
  7258. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Context, ReadingContextStr[dataType]);
  7259. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Format, ValueFormatStr[Raw]);
  7260. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Measurand, MeasurandStr[Power_Active_Import]);
  7261. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Location, LocationStr[Location_Outlet]);
  7262. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Unit,UnitOfMeasureStr[UnitOfMeasure_kW]);
  7263. }
  7264. //***********************************************(5)VOLTAGE L1******************************************************/
  7265. if(((dataType == ReadingContext_Sample_Clock) && (strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, MeasurandStr[Voltage]) != NULL)) ||
  7266. ((dataType == ReadingContext_Sample_Periodic) && (strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, MeasurandStr[Voltage]) != NULL)) ||
  7267. (dataType == ReadingContext_Trigger))
  7268. {
  7269. //J : CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  7270. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  7271. {
  7272. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  7273. {
  7274. tempIndex = ((gun_index==2) ? 1: 0);
  7275. }
  7276. else
  7277. {
  7278. tempIndex = gun_index;
  7279. }
  7280. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  7281. {
  7282. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  7283. {
  7284. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargingVoltage );
  7285. }
  7286. }
  7287. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Phase, PhaseStr[L3_N]);
  7288. }
  7289. else if(gunType[gun_index] == GUN_TYPE_CCS)
  7290. {
  7291. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  7292. {
  7293. tempIndex = ((gun_index==2) ? 1: 0);
  7294. }
  7295. else
  7296. {
  7297. tempIndex = gun_index;
  7298. }
  7299. for (int index = 0; index < CCS_QUANTITY; index++)
  7300. {
  7301. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  7302. {
  7303. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargingVoltage );
  7304. }
  7305. }
  7306. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Phase, PhaseStr[L3_N]);
  7307. }
  7308. else if(gunType[gun_index] == GUN_TYPE_GBT)
  7309. {
  7310. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  7311. {
  7312. tempIndex = ((gun_index==2) ? 1: 0);
  7313. }
  7314. else
  7315. {
  7316. tempIndex = gun_index;
  7317. }
  7318. for (int index = 0; index < GB_QUANTITY; index++)
  7319. {
  7320. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  7321. {
  7322. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingVoltage );
  7323. }
  7324. }
  7325. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Phase, PhaseStr[L3_N]);
  7326. }
  7327. else if(gunType[gun_index] == GUN_TYPE_DO)
  7328. {
  7329. tempIndex = gun_index;
  7330. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  7331. {
  7332. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  7333. {
  7334. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PresentChargingVoltage );
  7335. }
  7336. }
  7337. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Phase, PhaseStr[L3_N]);
  7338. }
  7339. else
  7340. {
  7341. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  7342. {
  7343. tempIndex = 2;
  7344. }
  7345. else
  7346. {
  7347. tempIndex = gun_index;
  7348. }
  7349. for (int index = 0; index < AC_QUANTITY; index++)
  7350. {
  7351. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  7352. {
  7353. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingVoltage );
  7354. }
  7355. }
  7356. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Phase, PhaseStr[L1_N]);
  7357. }
  7358. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Context, ReadingContextStr[dataType]);
  7359. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Format, ValueFormatStr[Raw]);
  7360. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Measurand, MeasurandStr[Voltage]);
  7361. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Location, LocationStr[Location_Outlet]);
  7362. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Unit,UnitOfMeasureStr[UnitOfMeasure_V]);
  7363. }
  7364. //***********************************************(6)SOC******************************************************/
  7365. if(((dataType == ReadingContext_Sample_Clock) && (strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, MeasurandStr[SoC]) != NULL)) ||
  7366. ((dataType == ReadingContext_Sample_Periodic) && (strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, MeasurandStr[SoC]) != NULL)) ||
  7367. (dataType == ReadingContext_Trigger))
  7368. {
  7369. 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))
  7370. {
  7371. //idx_sample=5;
  7372. //sampledValue = NULL;
  7373. if((ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0') && (gunType[gun_index] != GUN_TYPE_DO))
  7374. {
  7375. tempIndex = ((gun_index==2) ? 1: 0);
  7376. }
  7377. else
  7378. {
  7379. tempIndex = gun_index;
  7380. }
  7381. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  7382. {
  7383. //tempIndex = ((gun_index==2) ? 1: 0);
  7384. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  7385. {
  7386. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  7387. {
  7388. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].EvBatterySoc );
  7389. }
  7390. }
  7391. }
  7392. else if(gunType[gun_index] == GUN_TYPE_CCS)
  7393. {
  7394. //tempIndex = ((gun_index==2) ? 1: 0);
  7395. for (int index = 0; index < CCS_QUANTITY; index++)
  7396. {
  7397. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  7398. {
  7399. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].EvBatterySoc );
  7400. }
  7401. }
  7402. }
  7403. else if(gunType[gun_index] == GUN_TYPE_GBT)
  7404. {
  7405. //tempIndex = ((gun_index==2) ? 1: 0);
  7406. for (int index = 0; index < GB_QUANTITY; index++)
  7407. {
  7408. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  7409. {
  7410. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].EvBatterySoc );
  7411. }
  7412. }
  7413. }
  7414. else if(gunType[gun_index] == GUN_TYPE_DO)
  7415. {
  7416. //tempIndex = ((gun_index==2) ? 1: 0);
  7417. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  7418. {
  7419. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  7420. {
  7421. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.EvBatterySoc );
  7422. }
  7423. }
  7424. }
  7425. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[5].Context, ReadingContextStr[dataType]);
  7426. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[5].Format, ValueFormatStr[Raw]);
  7427. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[5].Measurand, MeasurandStr[SoC]);
  7428. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[5].Phase, PhaseStr[L3_N]);
  7429. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[5].Location, LocationStr[Location_EV]);
  7430. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[5].Unit,UnitOfMeasureStr[UnitOfMeasure_Percent]);
  7431. }
  7432. }
  7433. //********************************(7)Current.Import L2************************************************/
  7434. if(((dataType == ReadingContext_Sample_Clock) && (strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, MeasurandStr[Current_Import]) != NULL)) ||
  7435. ((dataType == ReadingContext_Sample_Periodic) && (strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, MeasurandStr[Current_Import]) != NULL)) ||
  7436. (dataType == ReadingContext_Trigger))
  7437. {
  7438. // Only for AC 3 phase
  7439. if((gunType[gun_index] == GUN_TYPE_AC) && ((ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'W') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='D')))
  7440. {
  7441. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  7442. {
  7443. tempIndex = 2;
  7444. }
  7445. else
  7446. {
  7447. tempIndex = gun_index;
  7448. }
  7449. for (int index = 0; index < AC_QUANTITY; index++)
  7450. {
  7451. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  7452. {
  7453. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[6].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingCurrentL2);
  7454. }
  7455. }
  7456. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[6].Phase, PhaseStr[L2_N]);
  7457. }
  7458. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[6].Context, ReadingContextStr[dataType]);
  7459. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[6].Format, ValueFormatStr[Raw]);
  7460. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[6].Measurand, MeasurandStr[Current_Import]);
  7461. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[6].Location, LocationStr[Location_Outlet]);
  7462. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[6].Unit,UnitOfMeasureStr[UnitOfMeasure_A]);
  7463. }
  7464. //********************************(8)Current.Import L3************************************************/
  7465. if(((dataType == ReadingContext_Sample_Clock) && (strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, MeasurandStr[Current_Import]) != NULL)) ||
  7466. ((dataType == ReadingContext_Sample_Periodic) && (strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, MeasurandStr[Current_Import]) != NULL)) ||
  7467. (dataType == ReadingContext_Trigger))
  7468. {
  7469. // Only for AC 3 phase
  7470. if((gunType[gun_index] == GUN_TYPE_AC) && ((ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'W') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='D')))
  7471. {
  7472. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  7473. {
  7474. tempIndex = 2;
  7475. }
  7476. else
  7477. {
  7478. tempIndex = gun_index;
  7479. }
  7480. for (int index = 0; index < AC_QUANTITY; index++)
  7481. {
  7482. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  7483. {
  7484. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[7].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingCurrentL3);
  7485. }
  7486. }
  7487. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[7].Phase, PhaseStr[L3_N]);
  7488. }
  7489. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[7].Context, ReadingContextStr[dataType]);
  7490. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[7].Format, ValueFormatStr[Raw]);
  7491. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[7].Measurand, MeasurandStr[Current_Import]);
  7492. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[7].Location, LocationStr[Location_Outlet]);
  7493. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[7].Unit,UnitOfMeasureStr[UnitOfMeasure_A]);
  7494. }
  7495. //***********************************************(9)VOLTAGE L2******************************************************/
  7496. if(((dataType == ReadingContext_Sample_Clock) && (strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, MeasurandStr[Voltage]) != NULL)) ||
  7497. ((dataType == ReadingContext_Sample_Periodic) && (strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, MeasurandStr[Voltage]) != NULL)) ||
  7498. (dataType == ReadingContext_Trigger))
  7499. {
  7500. if((gunType[gun_index] == GUN_TYPE_AC) && ((ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'W') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='D')))
  7501. {
  7502. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  7503. {
  7504. tempIndex = 2;
  7505. }
  7506. else
  7507. {
  7508. tempIndex = gun_index;
  7509. }
  7510. for (int index = 0; index < AC_QUANTITY; index++)
  7511. {
  7512. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  7513. {
  7514. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[8].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingVoltageL2);
  7515. }
  7516. }
  7517. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[8].Phase, PhaseStr[L2_N]);
  7518. }
  7519. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[8].Context, ReadingContextStr[dataType]);
  7520. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[8].Format, ValueFormatStr[Raw]);
  7521. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[8].Measurand, MeasurandStr[Voltage]);
  7522. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[8].Location, LocationStr[Location_Outlet]);
  7523. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[8].Unit,UnitOfMeasureStr[UnitOfMeasure_V]);
  7524. }
  7525. //***********************************************(10)VOLTAGE L3******************************************************/
  7526. if(((dataType == ReadingContext_Sample_Clock) && (strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, MeasurandStr[Voltage]) != NULL)) ||
  7527. ((dataType == ReadingContext_Sample_Periodic) && (strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, MeasurandStr[Voltage]) != NULL)) ||
  7528. (dataType == ReadingContext_Trigger))
  7529. {
  7530. if((gunType[gun_index] == GUN_TYPE_AC) && ((ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'W') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='D')))
  7531. {
  7532. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  7533. {
  7534. tempIndex = 2;
  7535. }
  7536. else
  7537. {
  7538. tempIndex = gun_index;
  7539. }
  7540. for (int index = 0; index < AC_QUANTITY; index++)
  7541. {
  7542. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  7543. {
  7544. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[9].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingVoltageL3);
  7545. }
  7546. }
  7547. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[9].Phase, PhaseStr[L3_N]);
  7548. }
  7549. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[9].Context, ReadingContextStr[dataType]);
  7550. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[9].Format, ValueFormatStr[Raw]);
  7551. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[9].Measurand, MeasurandStr[Voltage]);
  7552. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[9].Location, LocationStr[Location_Outlet]);
  7553. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[9].Unit,UnitOfMeasureStr[UnitOfMeasure_V]);
  7554. }
  7555. //***********************************************(11)Current.Offered******************************************************/
  7556. if(((dataType == ReadingContext_Sample_Clock) && (strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, MeasurandStr[Current_Offered]) != NULL)) ||
  7557. ((dataType == ReadingContext_Sample_Periodic) && (strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, MeasurandStr[Current_Offered]) != NULL)) ||
  7558. (dataType == ReadingContext_Trigger))
  7559. {
  7560. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  7561. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  7562. {
  7563. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  7564. {
  7565. tempIndex = ((gun_index==2) ? 1: 0);
  7566. }
  7567. else
  7568. {
  7569. tempIndex = gun_index;
  7570. }
  7571. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  7572. {
  7573. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  7574. {
  7575. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[10].Value, "%d", (uint16_t) (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].CurrentOffered/10));
  7576. }
  7577. } // END OF FOR CHAdeMO_QUANTITY
  7578. }
  7579. else if(gunType[gun_index] == GUN_TYPE_CCS)
  7580. {
  7581. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  7582. {
  7583. tempIndex = ((gun_index==2) ? 1: 0);
  7584. }
  7585. else
  7586. {
  7587. tempIndex = gun_index;
  7588. }
  7589. for (int index = 0; index < CCS_QUANTITY; index++)
  7590. {
  7591. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  7592. {
  7593. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[10].Value, "%d", (uint16_t) (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].CurrentOffered/10));
  7594. }
  7595. } // END OF CCS_QUANTITY
  7596. }
  7597. else if(gunType[gun_index] == GUN_TYPE_GBT)
  7598. {
  7599. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  7600. {
  7601. tempIndex = ((gun_index==2) ? 1: 0);
  7602. }
  7603. else
  7604. {
  7605. tempIndex = gun_index;
  7606. }
  7607. for (int index = 0; index < GB_QUANTITY; index++)
  7608. {
  7609. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  7610. {
  7611. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[10].Value, "%d", (uint16_t) (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].CurrentOffered/10));
  7612. }
  7613. } // END OF GB_QUANTITY
  7614. }
  7615. else if(gunType[gun_index] == GUN_TYPE_DO)
  7616. {
  7617. tempIndex = gun_index;
  7618. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  7619. {
  7620. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  7621. {
  7622. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[10].Value, "%d", (uint16_t) (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.CurrentOffered/10));
  7623. }
  7624. }
  7625. }
  7626. else
  7627. {
  7628. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  7629. {
  7630. tempIndex = 2;
  7631. }
  7632. else
  7633. {
  7634. tempIndex = gun_index;
  7635. }
  7636. for (int index = 0; index < AC_QUANTITY; index++)
  7637. {
  7638. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  7639. {
  7640. uint16_t currentOffer;
  7641. if(ShmSysConfigAndInfo->SysConfig.MaxChargingCurrent == 0)
  7642. {
  7643. currentOffer = ShmSysConfigAndInfo->SysConfig.RatingCurrent;
  7644. }
  7645. else
  7646. {
  7647. currentOffer = ((ShmSysConfigAndInfo->SysConfig.MaxChargingCurrent>ShmSysConfigAndInfo->SysConfig.RatingCurrent)?ShmSysConfigAndInfo->SysConfig.RatingCurrent:ShmSysConfigAndInfo->SysConfig.MaxChargingCurrent);
  7648. }
  7649. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[10].Value, "%d", currentOffer);
  7650. }
  7651. }
  7652. }
  7653. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[10].Context, ReadingContextStr[dataType]);
  7654. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[10].Format, ValueFormatStr[Raw]);
  7655. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[10].Measurand, MeasurandStr[Current_Offered]);
  7656. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[10].Location, LocationStr[Location_Outlet]);
  7657. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[10].Unit,UnitOfMeasureStr[UnitOfMeasure_A]);
  7658. }
  7659. //***********************************************(12)Power.Offered******************************************************/
  7660. if(((dataType == ReadingContext_Sample_Clock) && (strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, MeasurandStr[Power_Offered]) != NULL) && (gunType[gun_index] != GUN_TYPE_AC)) ||
  7661. ((dataType == ReadingContext_Sample_Periodic) && (strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, MeasurandStr[Power_Offered]) != NULL) && (gunType[gun_index] != GUN_TYPE_AC)) ||
  7662. ((dataType == ReadingContext_Trigger) && (gunType[gun_index] != GUN_TYPE_AC)))
  7663. {
  7664. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  7665. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  7666. {
  7667. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  7668. {
  7669. tempIndex = ((gun_index==2) ? 1: 0);
  7670. }
  7671. else
  7672. {
  7673. tempIndex = gun_index;
  7674. }
  7675. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  7676. {
  7677. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  7678. {
  7679. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[11].Value, "%d", (uint32_t) (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PowerOffered*100));
  7680. }
  7681. } // END OF FOR CHAdeMO_QUANTITY
  7682. }
  7683. else if(gunType[gun_index] == GUN_TYPE_CCS)
  7684. {
  7685. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  7686. {
  7687. tempIndex = ((gun_index==2) ? 1: 0);
  7688. }
  7689. else
  7690. {
  7691. tempIndex = gun_index;
  7692. }
  7693. for (int index = 0; index < CCS_QUANTITY; index++)
  7694. {
  7695. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  7696. {
  7697. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[11].Value, "%d", (uint32_t) (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PowerOffered*100));
  7698. }
  7699. } // END OF CCS_QUANTITY
  7700. }
  7701. else if(gunType[gun_index] == GUN_TYPE_GBT)
  7702. {
  7703. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  7704. {
  7705. tempIndex = ((gun_index==2) ? 1: 0);
  7706. }
  7707. else
  7708. {
  7709. tempIndex = gun_index;
  7710. }
  7711. for (int index = 0; index < GB_QUANTITY; index++)
  7712. {
  7713. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  7714. {
  7715. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[11].Value, "%d", (uint32_t) (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PowerOffered*100));
  7716. }
  7717. } // END OF GB_QUANTITY
  7718. }
  7719. else if(gunType[gun_index] == GUN_TYPE_DO)
  7720. {
  7721. tempIndex = gun_index;
  7722. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  7723. {
  7724. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  7725. {
  7726. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[11].Value, "%d", (uint32_t) (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PowerOffered*100));
  7727. }
  7728. }
  7729. }
  7730. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[11].Context, ReadingContextStr[dataType]);
  7731. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[11].Format, ValueFormatStr[Raw]);
  7732. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[11].Measurand, MeasurandStr[Power_Offered]);
  7733. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[11].Location, LocationStr[Location_Outlet]);
  7734. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[11].Unit,UnitOfMeasureStr[UnitOfMeasure_W]);
  7735. }
  7736. // Message create ====================================================================================================
  7737. if(TRUE)
  7738. {
  7739. json_object *MeterValueReq = json_object_new_object();
  7740. json_object *MeterValues = json_object_new_array();
  7741. json_object *sampledValues = json_object_new_array();
  7742. json_object_object_add(MeterValueReq, "connectorId", json_object_new_int(ShmOCPP16Data->MeterValues[gun_index].ConnectorId));
  7743. if(ShmOCPP16Data->MeterValues[gun_index].TransactionId != -1)
  7744. json_object_object_add(MeterValueReq, "transactionId", json_object_new_int(ShmOCPP16Data->MeterValues[gun_index].TransactionId));
  7745. for(uint8_t idxMeter=0;idxMeter<ARRAY_SIZE(ShmOCPP16Data->MeterValues[gun_index].MeterValue);idxMeter++)
  7746. {
  7747. json_object *MeterValue = json_object_new_object();
  7748. for(int idxSample=0;idxSample<ARRAY_SIZE(ShmOCPP16Data->MeterValues[gun_index].MeterValue[idxMeter].SampledValue);idxSample++)
  7749. {
  7750. if(strlen((char*)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Value) > 0)
  7751. {
  7752. json_object *sampledValue = json_object_new_object();
  7753. json_object_object_add(sampledValue, "value", json_object_new_string((char*)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Value));
  7754. if(strlen((char*)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Context) > 0)
  7755. json_object_object_add(sampledValue, "context", json_object_new_string((char*)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Context));
  7756. if(strlen((char*)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Format) > 0)
  7757. json_object_object_add(sampledValue, "format", json_object_new_string((char*)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Format));
  7758. if(strlen((char*)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Measurand) > 0)
  7759. json_object_object_add(sampledValue, "measurand", json_object_new_string((char*)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Measurand));
  7760. if(strlen((char*)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Phase) > 0)
  7761. json_object_object_add(sampledValue, "phase", json_object_new_string((char*)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Phase));
  7762. if(strlen((char*)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Location) > 0)
  7763. json_object_object_add(sampledValue, "location", json_object_new_string((char*)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Location));
  7764. if(strlen((char*)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Unit) > 0)
  7765. json_object_object_add(sampledValue, "unit", json_object_new_string((char*)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Unit));
  7766. json_object_array_add(sampledValues, sampledValue);
  7767. }
  7768. }
  7769. json_object_object_add(MeterValue, "timestamp", json_object_new_string((char*)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idxMeter].TimeStamp));
  7770. json_object_object_add(MeterValue, "sampledValue", sampledValues);
  7771. json_object_array_add(MeterValues, MeterValue);
  7772. }
  7773. json_object_object_add(MeterValueReq, "meterValue", MeterValues);
  7774. sprintf(queuedata,"%d,[%d,\"%s\",\"MeterValues\",%s]"
  7775. ,gun_index + 1
  7776. ,MESSAGE_TYPE_CALL
  7777. ,guid
  7778. ,json_object_to_json_string_ext(MeterValueReq, JSON_C_TO_STRING_PLAIN));
  7779. json_object_put(MeterValueReq);
  7780. }
  7781. // Put request guid to hash map
  7782. sprintf(tempdata, "MeterValues,%d", (gun_index));
  7783. 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*/)
  7784. {
  7785. result = PASS;
  7786. //DEBUG_INFO("MeterValues mapitem pass\n");
  7787. }
  7788. if((dataType != ReadingContext_Trigger) &&
  7789. (dataType != ReadingContext_Sample_Clock) &&
  7790. ((ShmOCPP16Data->MeterValues[gun_index].TransactionId > 0) || (strstr((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[QueueOffLineMeterValues].ItemData, "TRUE"))))
  7791. queue_operation(QUEUE_OPERATION_ADD, guid, queuedata );
  7792. else
  7793. {
  7794. if(FirstHeartBeat)
  7795. LWS_Send(queuedata +2);
  7796. }
  7797. return result;
  7798. }
  7799. int sendLogStatusNotificationRequest(char *status)
  7800. {
  7801. mtrace();
  7802. int result = PASS;
  7803. char message[4096]={0};
  7804. char guid[37]={0};
  7805. char tempdata[128]={0};
  7806. json_object *LogStatusNotification = json_object_new_object();
  7807. DEBUG_INFO("sendLogStatusNotificationRequest...\n");
  7808. ShmOCPP16Data->LogStatusNotification.requestId = ShmOCPP16Data->GetLog.requestId;
  7809. sprintf((char *)ShmOCPP16Data->LogStatusNotification.status,"%s",(const char *)status);
  7810. json_object_object_add(LogStatusNotification, "status", json_object_new_string((char*)ShmOCPP16Data->LogStatusNotification.status));
  7811. json_object_object_add(LogStatusNotification, "requestId", json_object_new_int(ShmOCPP16Data->LogStatusNotification.requestId));
  7812. random_uuid(guid);
  7813. sprintf(message,"[%d,\"%s\",\"LogStatusNotification\",%s]",MESSAGE_TYPE_CALL, guid, json_object_to_json_string_ext(LogStatusNotification, JSON_C_TO_STRING_PLAIN));
  7814. json_object_put(LogStatusNotification);
  7815. LWS_Send(message);
  7816. sprintf(tempdata, "LogStatusNotification,%d", 0);
  7817. if(hashmap_operation(HASH_OP_ADD, guid, tempdata) == PASS)
  7818. {
  7819. result = PASS;
  7820. }
  7821. ShmOCPP16Data->SpMsg.bits.LogStatusNotificationReq = 0;
  7822. ShmOCPP16Data->SpMsg.bits.LogStatusNotificationConf = 0;
  7823. return result;
  7824. }
  7825. int sendSecurityEventNotificationRequest()
  7826. {
  7827. mtrace();
  7828. int result = PASS;
  7829. char message[4096]={0};
  7830. char guid[37]={0};
  7831. char tempdata[128]={0};
  7832. json_object *SecurityEventNotification = json_object_new_object();
  7833. DEBUG_INFO("sendSecurityEventNotificationRequest...\n");
  7834. json_object_object_add(SecurityEventNotification, "type", json_object_new_string((char*)ShmOCPP16Data->SecurityEventNotification.type));
  7835. json_object_object_add(SecurityEventNotification, "timestamp", json_object_new_string((char*)ShmOCPP16Data->SecurityEventNotification.timestamp));
  7836. json_object_object_add(SecurityEventNotification, "techInfo", json_object_new_string((char*)ShmOCPP16Data->SecurityEventNotification.techInfo));
  7837. random_uuid(guid);
  7838. sprintf(message,"[%d,\"%s\",\"%s\",%s]",MESSAGE_TYPE_CALL, guid, "SecurityEventNotification", json_object_to_json_string_ext(SecurityEventNotification, JSON_C_TO_STRING_PLAIN));
  7839. json_object_put(SecurityEventNotification);
  7840. LWS_Send(message);
  7841. sprintf(tempdata, "SecurityEventNotification,0");
  7842. if(hashmap_operation(HASH_OP_ADD, guid, tempdata) == PASS)
  7843. {
  7844. result = PASS;
  7845. }
  7846. ShmOCPP16Data->SpMsg.bits.SecurityEventNotificationReq = 0;
  7847. ShmOCPP16Data->SpMsg.bits.SecurityEventNotificationConf = 0;
  7848. return result;
  7849. }
  7850. int sendSignCertificateRequest()
  7851. {
  7852. mtrace();
  7853. int result = PASS;
  7854. char message[4096]={0};
  7855. char guid[37]={0};
  7856. char tempdata[128]={0};
  7857. json_object *SignCertificate = json_object_new_object();
  7858. DEBUG_INFO("sendSignCertificateRequest...\n");
  7859. // Read csr file content
  7860. memset(ShmOCPP16Data->SignCertificate.csr, 0x00, ARRAY_SIZE(ShmOCPP16Data->SignCertificate.csr));
  7861. FILE *fp=fopen("/Storage/OCPP/certCP.csr","r");
  7862. char *line = NULL;
  7863. size_t len = 0;
  7864. while(getline(&line, &len, fp) != -1)
  7865. {
  7866. if((strstr(line, "BEGIN CERTIFICATE REQUEST") == NULL) && (strstr(line, "END CERTIFICATE REQUEST") == NULL))
  7867. {
  7868. memcpy(&ShmOCPP16Data->SignCertificate.csr[strlen((char*)ShmOCPP16Data->SignCertificate.csr)], line, (strlen(line)-1));
  7869. }
  7870. }
  7871. fclose(fp);
  7872. json_object_object_add(SignCertificate, "csr", json_object_new_string((char*)ShmOCPP16Data->SignCertificate.csr));
  7873. random_uuid(guid);
  7874. sprintf(message,"[%d,\"%s\",\"%s\",%s]",MESSAGE_TYPE_CALL, guid, "SignCertificate", json_object_to_json_string_ext(SignCertificate, JSON_C_TO_STRING_PLAIN));
  7875. json_object_put(SignCertificate);
  7876. LWS_Send(message);
  7877. sprintf(tempdata, "SignCertificate,0");
  7878. if(hashmap_operation(HASH_OP_ADD, guid, tempdata) == PASS)
  7879. {
  7880. result = PASS;
  7881. }
  7882. ShmOCPP16Data->SpMsg.bits.SignCertificateReq = 0;
  7883. ShmOCPP16Data->SpMsg.bits.SignCertificateConf = 0;
  7884. return result;
  7885. }
  7886. int sendSignedFirmwareStatusNotificationRequest(char *status)
  7887. {
  7888. mtrace();
  7889. int result = PASS;
  7890. char message[110]={0};
  7891. char guid[37]={0};
  7892. char tempdata[65]={0};
  7893. json_object *FirmwareStatusNotification = json_object_new_object();
  7894. DEBUG_INFO("sendSignedFirmwareStatusNotificationRequest...\n");
  7895. sprintf((char *)ShmOCPP16Data->SignedFirmwareStatusNotification.status , "%s", (const char *)status);
  7896. ShmOCPP16Data->SignedFirmwareStatusNotification.requestId = ShmOCPP16Data->SignedUpdateFirmware.requestId;
  7897. json_object_object_add(FirmwareStatusNotification, "status", json_object_new_string((char*)ShmOCPP16Data->SignedFirmwareStatusNotification.status));
  7898. json_object_object_add(FirmwareStatusNotification, "requestId", json_object_new_int(ShmOCPP16Data->SignedFirmwareStatusNotification.requestId));
  7899. random_uuid(guid);
  7900. sprintf(message,"[%d,\"%s\",\"FirmwareStatusNotification\",%s]",MESSAGE_TYPE_CALL, guid, json_object_to_json_string_ext(FirmwareStatusNotification, JSON_C_TO_STRING_PLAIN));
  7901. json_object_put(FirmwareStatusNotification);
  7902. LWS_Send(message);
  7903. sprintf(tempdata, "FirmwareStatusNotification,%d", 0);
  7904. if(hashmap_operation(HASH_OP_ADD, guid, tempdata) == PASS)
  7905. {
  7906. result = PASS;
  7907. }
  7908. ShmOCPP16Data->SpMsg.bits.SignedFirmwareStatusNotificationReq = 0;
  7909. ShmOCPP16Data->SpMsg.bits.SignedFirmwareStatusNotificationConf = 0;
  7910. return result;
  7911. }
  7912. //==========================================
  7913. // send confirm routine
  7914. //==========================================
  7915. int sendCancelReservationConfirmation(char *uuid,char *payload)
  7916. {
  7917. mtrace();
  7918. int result = FAIL;
  7919. char message[100]={0};
  7920. DEBUG_INFO("sendCancelReservationConfirmation...\n");
  7921. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT,uuid, payload);
  7922. LWS_Send(message);
  7923. result = TRUE;
  7924. return result;
  7925. }
  7926. int sendChangeAvailabilityConfirmation(char *uuid,char *payload)
  7927. {
  7928. mtrace();
  7929. int result = FAIL;
  7930. char message[100]={0};
  7931. DEBUG_INFO("sendChangeAvailabilityConfirmation...\n");
  7932. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT,uuid, payload);
  7933. LWS_Send(message);
  7934. result = TRUE;
  7935. return result;
  7936. }
  7937. int sendChangeConfigurationConfirmation(char *uuid,char *payload)
  7938. {
  7939. mtrace();
  7940. int result = FAIL;
  7941. char message[100]={0};
  7942. DEBUG_INFO("sendChangeConfigurationConfirmation...\n");
  7943. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT,uuid, payload);
  7944. LWS_Send(message);
  7945. result = TRUE;
  7946. return result;
  7947. }
  7948. int sendClearCacheConfirmation(char *uuid,char *payload)
  7949. {
  7950. mtrace();
  7951. int result = FAIL;
  7952. char message[500]={0};
  7953. DEBUG_INFO("sendClearCacheConfirmation...\n");
  7954. sprintf(message,"[%d,\"%s\",{\"%s\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, "status", payload);
  7955. LWS_Send(message);
  7956. return result;
  7957. }
  7958. int sendClearChargingProfileConfirmation(char *uuid,char *payload)
  7959. {
  7960. mtrace();
  7961. int result = FAIL;
  7962. char message[500]={0};
  7963. DEBUG_INFO("sendClearChargingProfileConfirmation...\n");
  7964. sprintf(message,"[%d,\"%s\",{\"%s\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, "status", payload);
  7965. LWS_Send(message);
  7966. return result;
  7967. }
  7968. int sendDataTransferConfirmation(char *uuid,char *payload)
  7969. {
  7970. mtrace();
  7971. char statusStr[20]={0};
  7972. char dataStr[10]={0};
  7973. char sstr[20]={0};
  7974. int c = 0;
  7975. char *loc;
  7976. int result = FAIL;
  7977. DEBUG_INFO("sendDataTransferConfirmation...\n");
  7978. /**********************status**************************/
  7979. loc = strstr(payload, "status");
  7980. memset(sstr ,0, ARRAY_SIZE(sstr) );
  7981. c = 0;
  7982. while (loc[3+strlen("status")+c] != '\"')
  7983. {
  7984. sstr[c] = loc[3+strlen("status")+c];
  7985. c++;
  7986. }
  7987. sstr[c] = '\0';
  7988. strcpy(statusStr, sstr);
  7989. /**********************data**************************/
  7990. loc = strstr(payload, "data");
  7991. memset(sstr ,0, ARRAY_SIZE(sstr) );
  7992. c = 0;
  7993. while (loc[3+strlen("data")+c] != '\"')
  7994. {
  7995. sstr[c] = loc[3+strlen("data")+c];
  7996. c++;
  7997. }
  7998. sstr[c] = '\0';
  7999. strcpy(dataStr, sstr);
  8000. return result;
  8001. }
  8002. int sendGetCompositeScheduleConfirmation(char *uuid, char *payload, int connectorIdInt, int nPeriod)
  8003. {
  8004. mtrace();
  8005. int result = FAIL;
  8006. char message[1000]={0};
  8007. int CompositeScheduleIndex = 0;
  8008. DEBUG_INFO("sendGetCompositeScheduleConfirmation...\n");
  8009. CompositeScheduleIndex = (connectorIdInt > 0) ?(connectorIdInt -1) : 0;
  8010. if(nPeriod == 0)
  8011. {
  8012. if(strcmp((const char *)ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.StartSchedule,"")==0)
  8013. {
  8014. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\",\"connectorId\":%d}]"
  8015. ,MESSAGE_TYPE_CALLRESULT
  8016. ,uuid
  8017. ,payload
  8018. ,connectorIdInt);
  8019. }
  8020. else
  8021. {
  8022. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\",\"connectorId\":%d,\"scheduleStart\":\"%s\",\"chargingSchedule\":{\"duration\":%d,\"startSchedule\":\"%s\",\"chargingRateUnit\":\"%s\",\"chargingSchedulePeriod\":[{\"startPeriod\":0,\"limit\":%d}]}}]"
  8023. ,MESSAGE_TYPE_CALLRESULT
  8024. ,uuid
  8025. ,payload
  8026. ,connectorIdInt
  8027. ,ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.StartSchedule
  8028. ,ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.Duration
  8029. ,ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.StartSchedule
  8030. ,ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.ChargingRateUnit
  8031. ,ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.ChargingRateUnit[0]=='W'?modelnameInfo.ratedPower:(ShmSysConfigAndInfo->SysConfig.MaxChargingCurrent==0?ShmSysConfigAndInfo->SysConfig.RatingCurrent:ShmSysConfigAndInfo->SysConfig.MaxChargingCurrent));
  8032. }
  8033. }
  8034. else
  8035. {
  8036. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\",\"connectorId\":%d,\"scheduleStart\":\"%s\",\"chargingSchedule\":{\"duration\":%d,\"startSchedule\":\"%s\",\"chargingRateUnit\":\"%s\",\"chargingSchedulePeriod\":["
  8037. ,MESSAGE_TYPE_CALLRESULT
  8038. ,uuid
  8039. ,payload
  8040. ,connectorIdInt
  8041. ,ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.StartSchedule
  8042. ,ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.Duration
  8043. ,ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.StartSchedule
  8044. ,ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.ChargingRateUnit);
  8045. for(int idx_sample=0;idx_sample< nPeriod;idx_sample++)
  8046. {
  8047. if (idx_sample == 0)
  8048. {
  8049. sprintf(message + strlen(message), "{\"startPeriod\":%d,\"limit\":%.1f,\"numberPhases\":%d}"
  8050. , ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[idx_sample].StartPeriod
  8051. , ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[idx_sample].Limit
  8052. , ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[idx_sample].NumberPhases );
  8053. }
  8054. else
  8055. {
  8056. sprintf(message + strlen(message), ",{\"startPeriod\":%d,\"limit\":%.1f,\"numberPhases\":%d}"
  8057. , ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[idx_sample].StartPeriod
  8058. , ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[idx_sample].Limit
  8059. , ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[idx_sample].NumberPhases );
  8060. }
  8061. }
  8062. sprintf(message + strlen(message), "]}}]");
  8063. }
  8064. LWS_Send(message);
  8065. result = TRUE;
  8066. return result;
  8067. }
  8068. int sendGetConfigurationConfirmation(char *uuid)
  8069. {
  8070. mtrace();
  8071. int result = FAIL;
  8072. int MaxKeySupported = 0;
  8073. int sentConfigurationNumber= 0;
  8074. int sentunConfigurationNumber= 0;
  8075. char message[1024*10]={0};
  8076. DEBUG_INFO("sendGetConfigurationConfirmation...\n");
  8077. MaxKeySupported = atoi((const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemData);
  8078. sprintf(message,"[%d,\"%s\",{\"configurationKey\":["
  8079. ,MESSAGE_TYPE_CALLRESULT
  8080. ,uuid );
  8081. //configuration key
  8082. for(int idx_sample=0;idx_sample< MaxKeySupported/*43*/;idx_sample++)
  8083. {
  8084. if(strcmp((const char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[idx_sample].Key, "")!= 0)
  8085. {
  8086. if (sentConfigurationNumber == 0)
  8087. {
  8088. sprintf(message + strlen(message), "{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}"
  8089. , ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[idx_sample].Key
  8090. , atoi((const char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[idx_sample].ReadOnly) == 1 ? "true":"false"
  8091. , ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[idx_sample].Value );
  8092. }
  8093. else
  8094. {
  8095. sprintf(message + strlen(message), ", {\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}"
  8096. , ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[idx_sample].Key
  8097. , atoi((const char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[idx_sample].ReadOnly) == 1 ? "true":"false"
  8098. , ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[idx_sample].Value );
  8099. }
  8100. sentConfigurationNumber = sentConfigurationNumber + 1;
  8101. }
  8102. }
  8103. sprintf(message + strlen(message), "]");
  8104. if(UnknownKeynum != 0)
  8105. {
  8106. sprintf(message + strlen(message), ",\"unknownKey\":[");
  8107. //unkown key
  8108. for(int idx_sample=0;idx_sample< UnknownKeynum ;idx_sample++)
  8109. {
  8110. // json_object *jstring1 = json_object_new_string((const char *)((ShmOCPP16Data->GetConfiguration.ResponseUnknownKey + idx_sample)->Item));
  8111. DEBUG_INFO("unkown key:%s\n", ShmOCPP16Data->GetConfiguration.ResponseUnknownKey[idx_sample].Item);
  8112. if(sentunConfigurationNumber == 0)
  8113. {
  8114. sprintf(message + strlen(message), "\"%s\""
  8115. , ShmOCPP16Data->GetConfiguration.ResponseUnknownKey[idx_sample].Item );
  8116. }
  8117. else
  8118. {
  8119. sprintf(message + strlen(message), ",\"%s\""
  8120. , ShmOCPP16Data->GetConfiguration.ResponseUnknownKey[idx_sample].Item );
  8121. }
  8122. sentunConfigurationNumber = sentunConfigurationNumber + 1;
  8123. }
  8124. sprintf(message + strlen(message), "]");
  8125. }
  8126. sprintf(message + strlen(message), "}]");
  8127. LWS_Send(message);
  8128. return result;
  8129. }
  8130. int sendGetDiagnosticsConfirmation(char *uuid,char *payload)
  8131. {
  8132. mtrace();
  8133. int result = FAIL;
  8134. char message[400]={0};
  8135. DEBUG_INFO("sendGetDiagnosticsConfirmation...\n");
  8136. if(strcmp(payload,"")==0)
  8137. {
  8138. sprintf(message,"[%d,\"%s\",{}]",MESSAGE_TYPE_CALLRESULT, uuid);
  8139. }
  8140. else
  8141. {
  8142. sprintf(message,"[%d,\"%s\",{\"fileName\":\"%s\"}]", MESSAGE_TYPE_CALLRESULT, uuid, payload);
  8143. }
  8144. LWS_Send(message);
  8145. result = TRUE;
  8146. return result;
  8147. }
  8148. int sendGetLocalListVersionConfirmation(char *uuid,char *payload)
  8149. {
  8150. mtrace();
  8151. int result = FAIL;
  8152. char message[80]={0};
  8153. DEBUG_INFO("sendGetLocalListVersionConfirmation...\n");
  8154. sprintf(message,"[%d,\"%s\",{\"listVersion\":%d}]",MESSAGE_TYPE_CALLRESULT, uuid, ShmOCPP16Data->GetLocalListVersion.ResponseListVersion);
  8155. LWS_Send(message);
  8156. result = TRUE;
  8157. return result;
  8158. }
  8159. int sendRemoteStartConfirmation(char *uuid,char *payload)
  8160. {
  8161. mtrace();
  8162. int result = FAIL;
  8163. char message[80]={0};
  8164. DEBUG_INFO("sendRemoteStartConfirmation...\n");
  8165. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, payload);
  8166. LWS_Send(message);
  8167. result = TRUE;
  8168. return result;
  8169. }
  8170. int sendRemoteStopTransactionConfirmation(char *uuid,char *payload)
  8171. {
  8172. mtrace();
  8173. int result = FAIL;
  8174. char message[80]={0};
  8175. DEBUG_INFO("sendRemoteStopTransactionConfirmation...\n");
  8176. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, payload);
  8177. LWS_Send(message);
  8178. result = TRUE;
  8179. return result;
  8180. }
  8181. int sendReserveNowTransactionConfirmation(char *uuid,char *payload)
  8182. {
  8183. mtrace();
  8184. int result = FAIL;
  8185. char message[80]={0};
  8186. // [3,"287d837d-809e-41ea-8385-fdab7f72a01c",{"status":"Accepted"}]
  8187. DEBUG_INFO("sendReserveNowTransactionConfirmation...\n");
  8188. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, payload);
  8189. LWS_Send(message);
  8190. result = TRUE;
  8191. return result;
  8192. }
  8193. int sendResetConfirmation(char *uuid,char *payload)
  8194. {
  8195. mtrace();
  8196. int result = FAIL;
  8197. //[ 3, "6f88d461-4d17-462c-a69b-1f7a8c5b12df", { "status": 0 } ]
  8198. char message[80]={0};
  8199. ShmOCPP16Data->MsMsg.bits.ResetConf = 0;
  8200. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, payload);
  8201. LWS_Send(message);
  8202. result = TRUE;
  8203. return result;
  8204. }
  8205. int sendSendLocalListConfirmation(char *uuid,char *payload)
  8206. {
  8207. mtrace();
  8208. int result = FAIL;
  8209. char message[500]={0};
  8210. // [ 3, "1571284266109", { "status": "Accepted" } ]
  8211. sprintf(message,"[%d,\"%s\",{\"%s\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, "status", payload);
  8212. LWS_Send(message);
  8213. result = TRUE;
  8214. return result;
  8215. }
  8216. int sendSetChargingProfileConfirmation(char *uuid,char *payload)
  8217. {
  8218. mtrace();
  8219. int result = FAIL;
  8220. //[3,"5748585f-8524-4fa6-9b4f-4a7eca750b90",{"status":"NotSupported"}]
  8221. char message[80]={0};
  8222. DEBUG_INFO("sendSetChargingProfileConfirmation...\n");
  8223. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, payload);
  8224. LWS_Send(message);
  8225. result = TRUE;
  8226. return result;
  8227. }
  8228. int sendTriggerMessageConfirmation(char *uuid,char *payload)
  8229. {
  8230. mtrace();
  8231. int result = FAIL;
  8232. char message[80]={0};
  8233. DEBUG_INFO("sendTriggerMessageConfirmation...\n");
  8234. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, payload);
  8235. LWS_Send(message);
  8236. result = TRUE;
  8237. return result;
  8238. }
  8239. int sendUnlockConnectorConfirmation(char *uuid,char *payload)
  8240. {
  8241. mtrace();
  8242. int result = FAIL;
  8243. char message[80]={0};
  8244. //[ 3, "ba1cbd49-2a76-493a-8f76-fa23e7606532", { "status": "Unlocked" } ]
  8245. DEBUG_INFO("sendUnlockConnectorConfirmation...\n");
  8246. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, payload);
  8247. LWS_Send(message);
  8248. result = TRUE;
  8249. return result;
  8250. }
  8251. int sendUpdateFirmwareConfirmation(char *uuid)
  8252. {
  8253. mtrace();
  8254. int result = FAIL;
  8255. char message[60]={0};
  8256. //[ 3, "ba1cbd49-2a76-493a-8f76-fa23e7606532", { "status": "Unlocked" } ]
  8257. DEBUG_INFO("sendUpdateFirmwareConfirmation...\n");
  8258. sprintf(message,"[%d,\"%s\",{}]",MESSAGE_TYPE_CALLRESULT, uuid);
  8259. LWS_Send(message);
  8260. result = TRUE;
  8261. return result;
  8262. }
  8263. int sendCertificateSignedConfirmation(char *uuid)
  8264. {
  8265. mtrace();
  8266. int result = PASS;
  8267. char message[4096]={0};
  8268. json_object *CertificateSigned = json_object_new_object();
  8269. DEBUG_INFO("sendCertificateSignedConfirmation...\n");
  8270. json_object_object_add(CertificateSigned, "status", json_object_new_string((char*)ShmOCPP16Data->CertificateSigned.Response_status));
  8271. sprintf(message,"[%d,\"%s\",%s]"
  8272. ,MESSAGE_TYPE_CALLRESULT
  8273. ,uuid
  8274. ,json_object_to_json_string_ext(CertificateSigned, JSON_C_TO_STRING_PLAIN));
  8275. json_object_put(CertificateSigned);
  8276. LWS_Send(message);
  8277. return result;
  8278. }
  8279. int sendDeleteCertificateConfirmation(char *uuid)
  8280. {
  8281. mtrace();
  8282. int result = PASS;
  8283. char message[4096]={0};
  8284. json_object *DeleteCertificate = json_object_new_object();
  8285. DEBUG_INFO("sendDeleteCertificateConfirmation...\n");
  8286. json_object_object_add(DeleteCertificate, "status", json_object_new_string((char*)ShmOCPP16Data->DeleteCertificate.Response_status));
  8287. sprintf(message,"[%d,\"%s\",%s]"
  8288. ,MESSAGE_TYPE_CALLRESULT
  8289. ,uuid
  8290. ,json_object_to_json_string_ext(DeleteCertificate, JSON_C_TO_STRING_PLAIN));
  8291. json_object_put(DeleteCertificate);
  8292. LWS_Send(message);
  8293. return result;
  8294. }
  8295. int sendExtendedTriggerMessageConfirmation(char *uuid)
  8296. {
  8297. mtrace();
  8298. int result = PASS;
  8299. char message[4096]={0};
  8300. json_object *ExtendedTriggerMessage = json_object_new_object();
  8301. DEBUG_INFO("sendExtendedTriggerMessageConfirmation...\n");
  8302. json_object_object_add(ExtendedTriggerMessage, "status", json_object_new_string((char*)ShmOCPP16Data->ExtendedTriggerMessage.Response_status));
  8303. sprintf(message,"[%d,\"%s\",%s]"
  8304. ,MESSAGE_TYPE_CALLRESULT
  8305. ,uuid
  8306. ,json_object_to_json_string_ext(ExtendedTriggerMessage, JSON_C_TO_STRING_PLAIN));
  8307. json_object_put(ExtendedTriggerMessage);
  8308. LWS_Send(message);
  8309. return result;
  8310. }
  8311. int sendGetInstalledCertificateIdsConfirmation(char *uuid)
  8312. {
  8313. mtrace();
  8314. int result = PASS;
  8315. char message[4096]={0};
  8316. json_object *GetInstalledCertificateIds = json_object_new_object();
  8317. json_object *certificateHashDataDatas = json_object_new_array();
  8318. DEBUG_INFO("sendGetInstalledCertificateIdsConfirmation...\n");
  8319. json_object_object_add(GetInstalledCertificateIds, "status", json_object_new_string((char*)ShmOCPP16Data->GetInstalledCertificateIds.Response_status));
  8320. if(strlen((char*)ShmOCPP16Data->GetInstalledCertificateIds.Response_certificateHashData[0].hashAlgorithm) > 0)
  8321. {
  8322. for(int idx=0;idx<ARRAY_SIZE(ShmOCPP16Data->GetInstalledCertificateIds.Response_certificateHashData);idx++)
  8323. {
  8324. json_object *certificateHashData = json_object_new_object();
  8325. json_object_object_add(certificateHashData, "hashAlgorithm", json_object_new_string((char*)ShmOCPP16Data->GetInstalledCertificateIds.Response_certificateHashData[idx].hashAlgorithm));
  8326. json_object_object_add(certificateHashData, "issuerNameHash", json_object_new_string((char*)ShmOCPP16Data->GetInstalledCertificateIds.Response_certificateHashData[idx].issuerNameHash));
  8327. json_object_object_add(certificateHashData, "issuerKeyHash", json_object_new_string((char*)ShmOCPP16Data->GetInstalledCertificateIds.Response_certificateHashData[idx].issuerKeyHash));
  8328. json_object_object_add(certificateHashData, "serialNumber", json_object_new_string((char*)ShmOCPP16Data->GetInstalledCertificateIds.Response_certificateHashData[idx].serialNumber));
  8329. json_object_array_add(certificateHashDataDatas, certificateHashData);
  8330. }
  8331. json_object_object_add(GetInstalledCertificateIds , "certificateHashData", certificateHashDataDatas);
  8332. }
  8333. else
  8334. {
  8335. json_object_put(certificateHashDataDatas);
  8336. }
  8337. sprintf(message,"[%d,\"%s\",%s]"
  8338. ,MESSAGE_TYPE_CALLRESULT
  8339. ,uuid
  8340. ,json_object_to_json_string_ext(GetInstalledCertificateIds, JSON_C_TO_STRING_PLAIN));
  8341. json_object_put(GetInstalledCertificateIds);
  8342. LWS_Send(message);
  8343. return result;
  8344. }
  8345. int sendGetLogConfirmation(char *uuid)
  8346. {
  8347. mtrace();
  8348. int result = PASS;
  8349. char message[4096]={0};
  8350. json_object *GetLog = json_object_new_object();
  8351. DEBUG_INFO("sendGetLogConfirmation...\n");
  8352. json_object_object_add(GetLog, "status", json_object_new_string((char*)ShmOCPP16Data->GetLog.Response_status));
  8353. if(strlen((char*)ShmOCPP16Data->GetLog.Response_filename) > 0)
  8354. json_object_object_add(GetLog, "filename", json_object_new_string((char*)ShmOCPP16Data->GetLog.Response_filename));
  8355. sprintf(message,"[%d,\"%s\",%s]"
  8356. ,MESSAGE_TYPE_CALLRESULT
  8357. ,uuid
  8358. ,json_object_to_json_string_ext(GetLog, JSON_C_TO_STRING_PLAIN));
  8359. json_object_put(GetLog);
  8360. LWS_Send(message);
  8361. return result;
  8362. }
  8363. int sendInstallCertificateConfirmation(char *uuid)
  8364. {
  8365. mtrace();
  8366. int result = PASS;
  8367. char message[4096]={0};
  8368. json_object *InstallCertificate = json_object_new_object();
  8369. DEBUG_INFO("sendInstallCertificateConfirmation...\n");
  8370. json_object_object_add(InstallCertificate, "status", json_object_new_string((char*)ShmOCPP16Data->InstallCertificate.Response_status));
  8371. sprintf(message,"[%d,\"%s\",%s]"
  8372. ,MESSAGE_TYPE_CALLRESULT
  8373. ,uuid
  8374. ,json_object_to_json_string_ext(InstallCertificate, JSON_C_TO_STRING_PLAIN));
  8375. json_object_put(InstallCertificate);
  8376. LWS_Send(message);
  8377. return result;
  8378. }
  8379. int sendSignedUpdateFirmwareConfirmation(char *uuid)
  8380. {
  8381. mtrace();
  8382. int result = PASS;
  8383. char message[4096]={0};
  8384. json_object *SignedUpdateFirmware = json_object_new_object();
  8385. DEBUG_INFO("sendSignedUpdateFirmwareConfirmation...\n");
  8386. json_object_object_add(SignedUpdateFirmware, "status", json_object_new_string((char*)ShmOCPP16Data->SignedUpdateFirmware.Response_status));
  8387. sprintf(message,"[%d,\"%s\",%s]"
  8388. ,MESSAGE_TYPE_CALLRESULT
  8389. ,uuid
  8390. ,json_object_to_json_string_ext(SignedUpdateFirmware, JSON_C_TO_STRING_PLAIN));
  8391. json_object_put(SignedUpdateFirmware);
  8392. LWS_Send(message);
  8393. return result;
  8394. }
  8395. int sendUnknownConfirmation(char *uuid)
  8396. {
  8397. mtrace();
  8398. int result = PASS;
  8399. char message[256]={0};
  8400. DEBUG_INFO("sendUnknownConfirmation...\n");
  8401. sprintf(message,"[%d,\"%s\",\"NotImplemented\",\"Requested Action is not known by receiver\",{}]", MESSAGE_TYPE_CALLERROR, uuid);
  8402. LWS_Send(message);
  8403. return result;
  8404. }
  8405. //==========================================
  8406. // Handle server request routine Start
  8407. //==========================================
  8408. int handleCancelReservationRequest(char *uuid, char *payload)
  8409. {
  8410. mtrace();
  8411. int result = FAIL;
  8412. int gunNO = 0;
  8413. int reservationIdInt = -1;
  8414. char comfirmstr[20];
  8415. DEBUG_INFO("handleCancelReservationRequest...\n");
  8416. json_object *CancelReservation;
  8417. CancelReservation = json_tokener_parse(payload);
  8418. if(!is_error(CancelReservation))
  8419. {
  8420. // Required data
  8421. if(json_object_object_get(CancelReservation, "reservationId") != NULL)
  8422. reservationIdInt = json_object_get_int(json_object_object_get(CancelReservation, "reservationId"));
  8423. }
  8424. json_object_put(CancelReservation);
  8425. DEBUG_INFO("reservationIdInt = %d\n", reservationIdInt);
  8426. memset(comfirmstr, 0, ARRAY_SIZE(comfirmstr));
  8427. sprintf(comfirmstr, "%s", CancelReservationStatusStr[CancelReservationStatus_Rejected]);
  8428. if(reservationIdInt != -1)
  8429. {
  8430. //0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault, 8: Reserved, 9: maintain
  8431. //check Transaction active
  8432. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  8433. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  8434. {
  8435. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ReservationId == reservationIdInt)
  8436. {
  8437. sprintf(comfirmstr, "%s", CancelReservationStatusStr[CancelReservationStatus_Accepted] );
  8438. sprintf((char *)ShmOCPP16Data->CancelReservation[ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index].ResponseStatus, "%s", comfirmstr );
  8439. if(gunType[2] == GUN_TYPE_CHAdeMO)
  8440. {
  8441. gunNO = ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index + 1;
  8442. }
  8443. else
  8444. {
  8445. gunNO = ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index;
  8446. }
  8447. ShmOCPP16Data->CsMsg.bits[gunNO].CancelReservationReq = 1;
  8448. goto end;
  8449. }
  8450. }
  8451. for (int index = 0; index < CCS_QUANTITY; index++)
  8452. {
  8453. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ReservationId == reservationIdInt)
  8454. {
  8455. sprintf(comfirmstr, "%s", CancelReservationStatusStr[CancelReservationStatus_Accepted] );
  8456. sprintf((char *)ShmOCPP16Data->CancelReservation[ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index].ResponseStatus, "%s", comfirmstr );
  8457. if(gunType[2] == GUN_TYPE_CCS)
  8458. {
  8459. gunNO = ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index + 1;
  8460. }
  8461. else
  8462. {
  8463. gunNO = ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index;
  8464. }
  8465. ShmOCPP16Data->CsMsg.bits[gunNO].CancelReservationReq = 1;
  8466. goto end;
  8467. }
  8468. }
  8469. for (int index = 0; index < GB_QUANTITY; index++)
  8470. {
  8471. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ReservationId == reservationIdInt)
  8472. {
  8473. sprintf(comfirmstr, "%s", CancelReservationStatusStr[CancelReservationStatus_Accepted] );
  8474. sprintf((char *)ShmOCPP16Data->CancelReservation[ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index].ResponseStatus, "%s", comfirmstr );
  8475. if(gunType[2] == GUN_TYPE_GBT)
  8476. {
  8477. gunNO = ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index + 1;
  8478. }
  8479. else
  8480. {
  8481. gunNO = ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index;
  8482. }
  8483. ShmOCPP16Data->CsMsg.bits[gunNO].CancelReservationReq = 1;
  8484. goto end;
  8485. }
  8486. }
  8487. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  8488. {
  8489. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.ReservationId == reservationIdInt)
  8490. {
  8491. sprintf(comfirmstr, "%s", CancelReservationStatusStr[CancelReservationStatus_Accepted] );
  8492. sprintf((char *)ShmOCPP16Data->CancelReservation[ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index].ResponseStatus, "%s", comfirmstr );
  8493. gunNO = ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index;
  8494. ShmOCPP16Data->CsMsg.bits[gunNO].CancelReservationReq = 1;
  8495. goto end;
  8496. }
  8497. }
  8498. for (int index = 0; index < AC_QUANTITY; index++)
  8499. {
  8500. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].ReservationId == reservationIdInt)
  8501. {
  8502. sprintf(comfirmstr, "%s", CancelReservationStatusStr[CancelReservationStatus_Accepted] );
  8503. sprintf((char *)ShmOCPP16Data->CancelReservation[ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index].ResponseStatus, "%s", comfirmstr );
  8504. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  8505. {
  8506. gunNO = 1; //ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index ;
  8507. }
  8508. else
  8509. {
  8510. gunNO = ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index;
  8511. }
  8512. ShmOCPP16Data->CsMsg.bits[gunNO].CancelReservationReq = 1;
  8513. goto end;
  8514. }
  8515. }
  8516. }
  8517. //The reservationId does NOT match the reservationId
  8518. sendCancelReservationConfirmation(uuid, comfirmstr);
  8519. end:
  8520. // Fill in ocpp packet uuid
  8521. strcpy((char *)ShmOCPP16Data->CancelReservation[gunNO].guid, uuid);
  8522. return result;
  8523. }
  8524. int handleChangeAvailabilityRequest(char *uuid, char *payload)
  8525. {
  8526. mtrace();
  8527. int result = FAIL;
  8528. int gunIndex = -1;
  8529. char typeStr[16]={0};
  8530. char comfirmstr[20];
  8531. int specificId = FALSE;
  8532. DEBUG_INFO("handleChangeAvailabilityRequest...\n");
  8533. json_object *ChangeAvailability;
  8534. ChangeAvailability = json_tokener_parse(payload);
  8535. if(!is_error(ChangeAvailability))
  8536. {
  8537. // Required data
  8538. if((json_object_object_get(ChangeAvailability, "connectorId") != NULL) && (json_object_get_type(json_object_object_get(ChangeAvailability, "connectorId")) == json_type_int))
  8539. gunIndex = json_object_get_int(json_object_object_get(ChangeAvailability, "connectorId"));
  8540. if(json_object_object_get(ChangeAvailability, "type") != NULL)
  8541. sprintf((char*)typeStr, "%s", json_object_get_string(json_object_object_get(ChangeAvailability, "type")));
  8542. }
  8543. json_object_put(ChangeAvailability);
  8544. if((gunIndex > 0) && (gunIndex <= gunTotalNumber))
  8545. {
  8546. ShmOCPP16Data->ChangeAvailability[gunIndex - 1].ConnectorId= gunIndex;
  8547. sprintf((char *)ShmOCPP16Data->ChangeAvailability[gunIndex - 1].Type, "%s", typeStr);
  8548. }
  8549. else if(gunIndex == 0)
  8550. {
  8551. for(int i=0; i < gunTotalNumber; i++)
  8552. {
  8553. ShmOCPP16Data->ChangeAvailability[i].ConnectorId= gunIndex;
  8554. sprintf((char *)ShmOCPP16Data->ChangeAvailability[i].Type, "%s", typeStr);
  8555. }
  8556. }
  8557. memset(comfirmstr, 0, ARRAY_SIZE(comfirmstr));
  8558. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  8559. if((gunIndex == 0) || ((gunIndex > 0) && (gunIndex <= gunTotalNumber)))
  8560. {
  8561. specificId = TRUE;
  8562. }
  8563. if(specificId == FALSE)
  8564. goto end;
  8565. if(strcmp((const char *)typeStr, AvailabilityTypeStr[Inoperative]) == 0)
  8566. {
  8567. //----------------------gunIndex is 0 ------------------------------------------------//
  8568. if(gunIndex == 0)
  8569. {
  8570. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D') // 'D' means DC
  8571. {
  8572. for(int i=0; i < gunTotalNumber; i++)
  8573. {
  8574. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  8575. {
  8576. if ((gunType[i] == GUN_TYPE_CHAdeMO)&&(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == i))
  8577. {
  8578. if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_RESERVATION) // S_PRECHARGE
  8579. {
  8580. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  8581. goto end;
  8582. }
  8583. else if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_AUTHORIZING) ||
  8584. (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_PREPARING) ||
  8585. (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_CHARGING) ||
  8586. (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_TERMINATING) ||
  8587. (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_COMPLETE)) // S_CHARGING
  8588. {
  8589. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  8590. goto end;
  8591. }
  8592. }
  8593. }//END FOR CHAdeMO_QUANTITY
  8594. for (int index = 0; index < CCS_QUANTITY; index++)
  8595. {
  8596. if ((gunType[i] == GUN_TYPE_CCS)&&(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == i))
  8597. {
  8598. if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_RESERVATION)// S_PRECHARGE
  8599. {
  8600. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  8601. goto end;
  8602. }
  8603. else if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_AUTHORIZING) ||
  8604. (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_PREPARING) ||
  8605. (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_CHARGING) ||
  8606. (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_TERMINATING) ||
  8607. (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_COMPLETE)) // S_CHARGING
  8608. {
  8609. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  8610. goto end;
  8611. }
  8612. }
  8613. }//END FOR CCS_QUANTITY
  8614. for (int index = 0; index < GB_QUANTITY; index++)
  8615. {
  8616. if ((gunType[i] == GUN_TYPE_GBT)&&(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == i))
  8617. {
  8618. if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_RESERVATION) // S_PRECHARGE
  8619. {
  8620. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  8621. goto end;
  8622. }
  8623. else if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_AUTHORIZING) ||
  8624. (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_PREPARING) ||
  8625. (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_CHARGING) ||
  8626. (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_TERMINATING) ||
  8627. (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_COMPLETE)) // S_CHARGING
  8628. {
  8629. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  8630. goto end;
  8631. }
  8632. }
  8633. }// END FOR GB_QUANTITY
  8634. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  8635. {
  8636. if ((gunType[i] == GUN_TYPE_DO)&&(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == i))
  8637. {
  8638. if(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_RESERVATION) // S_PRECHARGE
  8639. {
  8640. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  8641. goto end;
  8642. }
  8643. else if((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_AUTHORIZING) ||
  8644. (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_PREPARING) ||
  8645. (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_CHARGING) ||
  8646. (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_TERMINATING) ||
  8647. (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_COMPLETE)) // S_CHARGING
  8648. {
  8649. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  8650. goto end;
  8651. }
  8652. }
  8653. }// END FOR GENERAL_GUN_QUANTITY
  8654. for (int index = 0; index < AC_QUANTITY; index++)
  8655. {
  8656. if ((gunType[i] == GUN_TYPE_AC)&&(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == i))
  8657. {
  8658. if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_RESERVATION) // S_PRECHARGE
  8659. {
  8660. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  8661. goto end;
  8662. }
  8663. else if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_AUTHORIZING) ||
  8664. (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_PREPARING) ||
  8665. (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_CHARGING) ||
  8666. (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_TERMINATING) ||
  8667. (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_COMPLETE)) // S_CHARGING
  8668. {
  8669. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  8670. goto end;
  8671. }
  8672. }
  8673. }//END FOR AC_QUANTITY
  8674. }// END FOR gunTotalNumber
  8675. }
  8676. else if (ShmSysConfigAndInfo->SysConfig.ModelName[0]=='A') //'A' means AC
  8677. {
  8678. for(int i=0; i < gunTotalNumber; i++)
  8679. {
  8680. if(ShmSysConfigAndInfo->SysInfo.AcChargingData[i].SystemStatus == SYS_MODE_RESERVATION) // S_PRECHARGE
  8681. {
  8682. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  8683. goto end;
  8684. }
  8685. else if((ShmSysConfigAndInfo->SysInfo.AcChargingData[i].SystemStatus == SYS_MODE_AUTHORIZING) ||
  8686. (ShmSysConfigAndInfo->SysInfo.AcChargingData[i].SystemStatus == SYS_MODE_PREPARING) ||
  8687. (ShmSysConfigAndInfo->SysInfo.AcChargingData[i].SystemStatus == SYS_MODE_CHARGING) ||
  8688. (ShmSysConfigAndInfo->SysInfo.AcChargingData[i].SystemStatus == SYS_MODE_TERMINATING) ||
  8689. (ShmSysConfigAndInfo->SysInfo.AcChargingData[i].SystemStatus == SYS_MODE_COMPLETE)) // S_CHARGING
  8690. {
  8691. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  8692. goto end;
  8693. }
  8694. }
  8695. }
  8696. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  8697. goto end;
  8698. }
  8699. //----------------------gunIndex is not 0 ------------------------------------------------//
  8700. //check Transaction active
  8701. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  8702. {
  8703. if ((gunIndex > 0)&&(gunType[gunIndex-1] == GUN_TYPE_CHAdeMO))
  8704. {
  8705. if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_RESERVATION) ) // S_PRECHARGE
  8706. {
  8707. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  8708. goto end;
  8709. }
  8710. else if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_AUTHORIZING) ||
  8711. (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_PREPARING) ||
  8712. (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_CHARGING) ||
  8713. (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_TERMINATING) ||
  8714. (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_COMPLETE)) // S_CHARGING
  8715. {
  8716. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  8717. goto end;
  8718. }
  8719. else
  8720. {
  8721. DEBUG_INFO("ShmSysConfigAndInfo->SysInfo.ChademoChargingData[%d].SystemStatus = %d\n",index, ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus);
  8722. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  8723. goto end;
  8724. }
  8725. }
  8726. }//END FOR CHAdeMO_QUANTITY
  8727. for (int index = 0; index < CCS_QUANTITY; index++)
  8728. {
  8729. if ((gunIndex > 0)&&(gunType[gunIndex - 1] == GUN_TYPE_CCS))
  8730. {
  8731. if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_RESERVATION) )// S_PRECHARGE
  8732. {
  8733. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  8734. goto end;
  8735. }
  8736. else if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_AUTHORIZING) ||
  8737. (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_PREPARING) ||
  8738. (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_CHARGING) ||
  8739. (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_TERMINATING) ||
  8740. (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_COMPLETE)) // S_CHARGING
  8741. {
  8742. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  8743. goto end;
  8744. }
  8745. else
  8746. {
  8747. DEBUG_INFO("ShmSysConfigAndInfo->SysInfo.CcsChargingData[%d].SystemStatus=%d\n",index, ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus);
  8748. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  8749. goto end;
  8750. }
  8751. }
  8752. }//END FOR CCS_QUANTITY
  8753. for (int index = 0; index < GB_QUANTITY; index++)
  8754. {
  8755. if ((gunIndex > 0)&&(gunType[gunIndex-1] == GUN_TYPE_GBT))
  8756. {
  8757. if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_RESERVATION)) // S_PRECHARGE
  8758. {
  8759. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  8760. goto end;
  8761. }
  8762. else if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_AUTHORIZING) ||
  8763. (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_PREPARING) ||
  8764. (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_CHARGING) ||
  8765. (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_TERMINATING) ||
  8766. (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_COMPLETE)) // S_CHARGING
  8767. {
  8768. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  8769. goto end;
  8770. }
  8771. else
  8772. {
  8773. DEBUG_INFO("ShmSysConfigAndInfo->SysInfo.GbChargingData[%d].SystemStatus=%d\n",index,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus);
  8774. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  8775. goto end;
  8776. }
  8777. }
  8778. }// END FOR GB_QUANTITY
  8779. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  8780. {
  8781. if ((gunIndex > 0)&&(gunType[gunIndex-1] == GUN_TYPE_DO))
  8782. {
  8783. if((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_RESERVATION)) // S_PRECHARGE
  8784. {
  8785. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  8786. goto end;
  8787. }
  8788. else if((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_AUTHORIZING) ||
  8789. (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_PREPARING) ||
  8790. (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_CHARGING) ||
  8791. (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_TERMINATING) ||
  8792. (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_COMPLETE)) // S_CHARGING
  8793. {
  8794. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  8795. goto end;
  8796. }
  8797. else
  8798. {
  8799. DEBUG_INFO("ShmSysConfigAndInfo->SysInfo.GbChargingData[%d].SystemStatus=%d\n",index,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus);
  8800. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  8801. goto end;
  8802. }
  8803. }
  8804. }// END FOR GENERAL_GUN_QUANTITY
  8805. for (int index = 0; index < AC_QUANTITY; index++)
  8806. {
  8807. if ((gunIndex > 0)&&(gunType[gunIndex-1] ==GUN_TYPE_AC))
  8808. {
  8809. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_RESERVATION)) // S_PRECHARGE
  8810. {
  8811. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  8812. goto end;
  8813. }
  8814. else if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_AUTHORIZING) ||
  8815. (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_PREPARING) ||
  8816. (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_CHARGING) ||
  8817. (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_TERMINATING) ||
  8818. (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_COMPLETE)) // S_CHARGING
  8819. {
  8820. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  8821. goto end;
  8822. }
  8823. else
  8824. {
  8825. DEBUG_INFO("ShmSysConfigAndInfo->SysInfo.AcChargingData[%d].SystemStatus=%d\n",index, ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus);
  8826. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  8827. goto end;
  8828. }
  8829. }
  8830. }//END FOR AC_QUANTITY
  8831. }//END FOR AvailabilityTypeStr[Inoperative]
  8832. if(strcmp((const char *)typeStr, AvailabilityTypeStr[Operative]) == 0)
  8833. {
  8834. //----------------------gunIndex is 0 ------------------------------------------------//
  8835. if(gunIndex == 0)
  8836. {
  8837. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D') // 'D' means DC
  8838. {
  8839. for(int i=0; i < gunTotalNumber; i++)
  8840. {
  8841. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  8842. {
  8843. 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
  8844. {
  8845. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  8846. goto end;
  8847. }
  8848. }//END FOR CHAdeMO_QUANTITY
  8849. for (int index = 0; index < CCS_QUANTITY; index++)
  8850. {
  8851. 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
  8852. {
  8853. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  8854. goto end;
  8855. }
  8856. }//END FOR CCS_QUANTITY
  8857. for (int index = 0; index < GB_QUANTITY; index++)
  8858. {
  8859. 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
  8860. {
  8861. //ShmOCPP16Data->CsMsg.bits[gunIndex - 1].ChangeAvailabilityReq = 1;
  8862. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  8863. goto end;
  8864. }
  8865. }// END FOR GB_QUANTITY
  8866. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  8867. {
  8868. 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
  8869. {
  8870. //ShmOCPP16Data->CsMsg.bits[gunIndex - 1].ChangeAvailabilityReq = 1;
  8871. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  8872. goto end;
  8873. }
  8874. }// END FOR GENERAL_GUN_QUANTITY
  8875. for (int index = 0; index < AC_QUANTITY; index++)
  8876. {
  8877. 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
  8878. {
  8879. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  8880. goto end;
  8881. }
  8882. }//END FOR CHAdeMO_QUANTITY
  8883. }// END FOR gunTotalNumber
  8884. }
  8885. else if (ShmSysConfigAndInfo->SysConfig.ModelName[0]=='A') //'A' means AC
  8886. {
  8887. for(int i=0; i < gunTotalNumber; i++)
  8888. {
  8889. for (int index = 0; index < AC_QUANTITY; index++)
  8890. {
  8891. 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
  8892. {
  8893. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  8894. goto end;
  8895. }
  8896. }//END FOR CHAdeMO_QUANTITY
  8897. } // END FOR gunTotalNumber
  8898. }
  8899. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  8900. goto end;
  8901. }
  8902. //----------------------gunIndex is not 0 ------------------------------------------------//
  8903. //check Transaction active
  8904. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  8905. {
  8906. if (((gunIndex > 0)&&(gunType[gunIndex-1] == GUN_TYPE_CHAdeMO) ) &&(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_FAULT)) //S_FAULT
  8907. {
  8908. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  8909. goto end;
  8910. }
  8911. }//END FOR CHAdeMO_QUANTITY
  8912. for (int index = 0; index < CCS_QUANTITY; index++)
  8913. {
  8914. if ((((gunIndex > 0)&&(gunType[gunIndex - 1] == GUN_TYPE_CCS)) )&&(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_FAULT)) //S_FAULT
  8915. {
  8916. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  8917. goto end;
  8918. }
  8919. }//END FOR CCS_QUANTITY
  8920. for (int index = 0; index < GB_QUANTITY; index++)
  8921. {
  8922. if (((gunIndex > 0)&&(gunType[gunIndex-1] == GUN_TYPE_GBT))&&(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_FAULT)) //S_FAULT
  8923. {
  8924. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  8925. goto end;
  8926. }
  8927. }// END FOR GB_QUANTITY
  8928. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  8929. {
  8930. if (((gunIndex > 0)&&(gunType[gunIndex-1] == GUN_TYPE_DO))&&(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus != SYS_MODE_FAULT)) //S_FAULT
  8931. {
  8932. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  8933. goto end;
  8934. }
  8935. }// END FOR GENERAL_GUN_QUANTITY
  8936. for (int index = 0; index < AC_QUANTITY; index++)
  8937. {
  8938. if (((gunIndex > 0)&&(gunType[gunIndex-1] == GUN_TYPE_AC)) &&(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_FAULT)) //S_FAULT
  8939. {
  8940. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  8941. goto end;
  8942. }
  8943. }//END FOR AC_QUANTITY
  8944. }//END FOR AvailabilityTypeStr[Operative]
  8945. end:
  8946. if((gunIndex != 0) && (gunIndex <= gunTotalNumber))
  8947. {
  8948. sprintf((char *)ShmOCPP16Data->ChangeAvailability[gunIndex - 1].ResponseStatus, "%s", comfirmstr );
  8949. }
  8950. else
  8951. {
  8952. sprintf((char *)ShmOCPP16Data->ChangeAvailability[0].ResponseStatus, "%s", comfirmstr );
  8953. }
  8954. if((gunIndex != 0) && (gunIndex <= gunTotalNumber))
  8955. {
  8956. if(strstr(comfirmstr, AvailabilityStatusStr[Rejected]) == NULL)
  8957. ShmOCPP16Data->CsMsg.bits[gunIndex - 1].ChangeAvailabilityReq = 1;
  8958. }
  8959. else if(gunIndex == 0)
  8960. {
  8961. if(strstr(comfirmstr, AvailabilityStatusStr[Rejected]) == NULL)
  8962. {
  8963. for(int i=0; i < gunTotalNumber/*(CHAdeMO_QUANTITY+ CCS_QUANTITY + GB_QUANTITY)*/; i++)
  8964. ShmOCPP16Data->CsMsg.bits[i].ChangeAvailabilityReq = 1;
  8965. }
  8966. }
  8967. sendChangeAvailabilityConfirmation(uuid, comfirmstr);
  8968. system("/bin/fsync -d /dev/mtdblock13;/bin/sync &");
  8969. return result;
  8970. }
  8971. int handleChangeConfigurationRequest(char *uuid, char *payload)
  8972. {
  8973. mtrace();
  8974. int valueInvalid = NO;
  8975. int result = FAIL;
  8976. char keystr[40]={0};
  8977. char valuestr[501]={0}; //value should be limited in 500 bytes
  8978. char comfirmstr[20]={0};
  8979. DEBUG_INFO("handleChangeConfigurationRequest...\n");
  8980. json_object *ChangeConfiguration;
  8981. ChangeConfiguration = json_tokener_parse(payload);
  8982. if(!is_error(ChangeConfiguration))
  8983. {
  8984. // Required data
  8985. if(json_object_object_get(ChangeConfiguration, "key") != NULL)
  8986. sprintf((char*)keystr, "%s", json_object_get_string(json_object_object_get(ChangeConfiguration, "key")));
  8987. if((json_object_object_get(ChangeConfiguration, "value") != NULL) && (strlen(json_object_get_string(json_object_object_get(ChangeConfiguration, "value"))) < ARRAY_SIZE(valuestr)))
  8988. {
  8989. sprintf((char*)valuestr, "%s", json_object_get_string(json_object_object_get(ChangeConfiguration, "value")));
  8990. }
  8991. else
  8992. {
  8993. valueInvalid = YES;
  8994. DEBUG_ERROR("The ChangeConfiguration value is NULL or OVER SIZE.\n");
  8995. }
  8996. }
  8997. json_object_put(ChangeConfiguration);
  8998. if((uuid==NULL) || (payload ==NULL) || (valueInvalid==YES))
  8999. {
  9000. DEBUG_ERROR("Payload is null or value is invalid.\n");
  9001. sprintf(comfirmstr, "%s", ConfigurationStatusStr[ConfigurationStatus_Rejected] );
  9002. }
  9003. else
  9004. {
  9005. int status = setKeyValue(keystr, valuestr);
  9006. switch(status)
  9007. {
  9008. case ConfigurationStatus_Accepted:
  9009. sprintf(comfirmstr, "%s", ConfigurationStatusStr[ConfigurationStatus_Accepted]);
  9010. ShmOCPP16Data->MsMsg.bits.ChangeConfigurationReq = 1;
  9011. StoreConfigurationTable();
  9012. break;
  9013. case RebootRequired:
  9014. sprintf(comfirmstr, "%s", ConfigurationStatusStr[RebootRequired]);
  9015. StoreConfigurationTable();
  9016. break;
  9017. case NotSupported:
  9018. sprintf(comfirmstr, "%s", ConfigurationStatusStr[NotSupported] );
  9019. break;
  9020. case ConfigurationStatus_Rejected:
  9021. default:
  9022. sprintf(comfirmstr, "%s", ConfigurationStatusStr[ConfigurationStatus_Rejected] );
  9023. break;
  9024. }
  9025. }
  9026. sendChangeConfigurationConfirmation(uuid, comfirmstr);
  9027. ShmOCPP16Data->MsMsg.bits.ChangeConfigurationConf = 1;
  9028. if(((strcmp(keystr,"AuthorizationKey")==0) || (strcmp(keystr,"SecurityProfile")==0) || (strcmp(keystr,"OcppServer")==0) || (strcmp(keystr,"MaintainServer")==0)) && (strcmp(comfirmstr,"Accepted")==0))
  9029. {
  9030. StoreUsrConfigData(&ShmSysConfigAndInfo->SysConfig);
  9031. SetOcppConnStatus(FALSE);
  9032. }
  9033. if(((strcmp(keystr,"FreeVend")==0) || (strcmp(keystr,"isEnableLocalPowerSharing")==0) || (strcmp(keystr,"PowerSharingServerIP")==0)) && (strcmp(comfirmstr,"Accepted")==0))
  9034. {
  9035. StoreUsrConfigData(&ShmSysConfigAndInfo->SysConfig);
  9036. }
  9037. return result;
  9038. }
  9039. int handleClearCacheRequest(char *uuid, char *payload)
  9040. {
  9041. mtrace();
  9042. int result = FAIL;
  9043. char comfirmstr[20];
  9044. char rmFileCmd[100]={0};
  9045. struct stat stats;
  9046. DEBUG_INFO("handleClearCacheRequest...\n");
  9047. stat("/Storage/OCPP", &stats);
  9048. // Check for directory existence
  9049. if (S_ISDIR(stats.st_mode) == 1)
  9050. {}
  9051. else
  9052. {
  9053. DEBUG_INFO("\n OCPP directory not exist, create dir \n");
  9054. sprintf(rmFileCmd,"mkdir -p %s","/Storage/OCPP");
  9055. system(rmFileCmd);
  9056. }
  9057. if(OCPP_cleanLocalCache())
  9058. {
  9059. sprintf(comfirmstr, "%s", ClearCacheStatusStr[ClearCacheStatus_Accepted] );
  9060. }
  9061. else
  9062. {
  9063. sprintf(comfirmstr, "%s", ClearCacheStatusStr[ClearCacheStatus_Rejected] );
  9064. }
  9065. sendClearCacheConfirmation(uuid, comfirmstr);
  9066. system("/bin/fsync -d /dev/mtdblock13;/bin/sync &");
  9067. return result;
  9068. }
  9069. int handleClearChargingProfileRequest(char *uuid, char *payload)
  9070. {
  9071. mtrace();
  9072. int result = FAIL;
  9073. int resultRename;
  9074. int connectorIdInt, chargingProfileIdInt, stackLevelInt;
  9075. char chargingProfilePurposeStr[26]={0};
  9076. int tempconnectorIdInt, tempchargingProfileIdInt, tempstackLevelInt;
  9077. char tempchargingProfilePurposeStr[26]={0};
  9078. char str[100]={0};
  9079. char fname[200]={0};
  9080. char comfirmstr[20]={0};
  9081. char word[1600]={0};
  9082. int clearflag = FALSE;
  9083. int chargingProfileIdIsNULL = FALSE;
  9084. int connectorIsNULL = FALSE;
  9085. int chargingProfilePurposeIsNULL = FALSE;
  9086. int stackLevelIsNULL = FALSE;
  9087. //int GotoEnd = FALSE;
  9088. FILE *fptr1, *fptr2;
  9089. char temp[] = "/Storage/OCPP/ClearChargingProfiletemp.json"; // Create temp file
  9090. int n_chargingProfile=0;
  9091. int isEmptyFile = FALSE;
  9092. char sLineWord[1600]={0};
  9093. char chargingProfiles[10][100]={0};
  9094. int ChargeProfileCount = 0;
  9095. int ch;
  9096. connectorIdInt = chargingProfileIdInt = stackLevelInt = 0;
  9097. DEBUG_INFO("handleClearChargingProfileRequest...\n");
  9098. json_object *ClearChargingProfile;
  9099. ClearChargingProfile = json_tokener_parse(payload);
  9100. if(!is_error(ClearChargingProfile))
  9101. {
  9102. // Optional data
  9103. if(json_object_object_get(ClearChargingProfile, "id") != NULL)
  9104. chargingProfileIdInt = json_object_get_int(json_object_object_get(ClearChargingProfile, "id"));
  9105. else
  9106. chargingProfileIdIsNULL = TRUE;
  9107. if(json_object_object_get(ClearChargingProfile, "connectorId") != NULL)
  9108. connectorIdInt = json_object_get_int(json_object_object_get(ClearChargingProfile, "connectorId"));
  9109. else
  9110. connectorIsNULL = TRUE;
  9111. if(json_object_object_get(ClearChargingProfile, "chargingProfilePurpose") != NULL)
  9112. sprintf((char*)chargingProfilePurposeStr, "%s", json_object_get_string(json_object_object_get(ClearChargingProfile, "chargingProfilePurpose")));
  9113. else
  9114. chargingProfilePurposeIsNULL = TRUE;
  9115. if(json_object_object_get(ClearChargingProfile, "stackLevel") != NULL)
  9116. stackLevelInt = json_object_get_int(json_object_object_get(ClearChargingProfile, "stackLevel"));
  9117. else
  9118. stackLevelIsNULL = TRUE;
  9119. }
  9120. json_object_put(ClearChargingProfile);
  9121. if(connectorIsNULL == FALSE)
  9122. {
  9123. switch(connectorIdInt)
  9124. {
  9125. case 0:
  9126. if(chargingProfilePurposeIsNULL == TRUE)
  9127. {
  9128. int l = 0;
  9129. strcpy(fname, ChargePointMaxProfile_JSON);
  9130. if((access(fname,F_OK))!=-1)
  9131. {
  9132. strcpy(chargingProfiles[l], fname);
  9133. l = l + 1;
  9134. }
  9135. strcpy(fname, TxDefaultProfile_0_JSON);
  9136. if((access(fname,F_OK))!=-1)
  9137. {
  9138. strcpy(chargingProfiles[l], fname);
  9139. l = l + 1;
  9140. }
  9141. ChargeProfileCount = l;
  9142. }
  9143. else if((chargingProfilePurposeIsNULL == FALSE)&&(strcmp(chargingProfilePurposeStr,"ChargePointMaxProfile")==0))
  9144. {
  9145. strcpy(fname, ChargePointMaxProfile_JSON);
  9146. if((access(fname,F_OK))!=-1)
  9147. {
  9148. strcpy(chargingProfiles[0], fname);
  9149. ChargeProfileCount = 1;
  9150. }
  9151. }
  9152. else if((chargingProfilePurposeIsNULL == FALSE)&&(strcmp(chargingProfilePurposeStr,"TxDefaultProfile")==0))
  9153. {
  9154. strcpy(fname, TxDefaultProfile_0_JSON);
  9155. if((access(fname,F_OK))!=-1)
  9156. {
  9157. strcpy(chargingProfiles[0], fname);
  9158. ChargeProfileCount = 1;
  9159. }
  9160. }
  9161. break;
  9162. default:
  9163. if(chargingProfilePurposeIsNULL == TRUE)
  9164. {
  9165. int m = 0;
  9166. memset(fname, 0, ARRAY_SIZE(fname));
  9167. sprintf(fname, "/Storage/OCPP/TxDefaultProfile_%d.json", connectorIdInt);
  9168. if((access(fname,F_OK))!=-1)
  9169. {
  9170. strcpy(chargingProfiles[m], fname);
  9171. m = m + 1;
  9172. }
  9173. memset(fname, 0, ARRAY_SIZE(fname));
  9174. sprintf(fname, "/Storage/OCPP/TxProfile_%d.json", connectorIdInt);
  9175. if((access(fname,F_OK))!=-1)
  9176. {
  9177. strcpy(chargingProfiles[m], fname);
  9178. m = m + 1;
  9179. }
  9180. ChargeProfileCount = m;
  9181. }
  9182. else if((chargingProfilePurposeIsNULL == FALSE)&&(strcmp(chargingProfilePurposeStr,"TxDefaultProfile")==0))
  9183. {
  9184. //strcpy(fname, TxDefaultProfile_1_JSON);
  9185. sprintf(fname, "/Storage/OCPP/TxDefaultProfile_%d.json", connectorIdInt);
  9186. if((access(fname,F_OK))!=-1)
  9187. {
  9188. strcpy(chargingProfiles[0], fname);
  9189. ChargeProfileCount = 1;
  9190. }
  9191. }
  9192. else if((chargingProfilePurposeIsNULL == FALSE)&&(strcmp(chargingProfilePurposeStr,"TxProfile")==0))
  9193. {
  9194. sprintf(fname, "/Storage/OCPP/TxProfile_%d.json", connectorIdInt);
  9195. if((access(fname,F_OK))!=-1)
  9196. {
  9197. strcpy(chargingProfiles[0], fname);
  9198. ChargeProfileCount = 1;
  9199. }
  9200. //strcpy(fname, TxProfile_1_JSON);
  9201. }
  9202. //strcpy(fname, ChargePointMaxProfile_JSON );
  9203. break;
  9204. }
  9205. }
  9206. else // Check all Charging Profiles
  9207. {
  9208. int i = 0;
  9209. char fnametemp[200]={0};
  9210. ChargeProfileCount = 0;
  9211. //Check ChargePointMaxProfile.json exit
  9212. if((access("/Storage/OCPP/ChargePointMaxProfile.json",F_OK))!=-1)
  9213. {
  9214. strcpy(chargingProfiles[i], "/Storage/OCPP/ChargePointMaxProfile.json");
  9215. i = i + 1;
  9216. }
  9217. //Check TxDefaultProfile_0.json exit
  9218. if((access("/Storage/OCPP/TxDefaultProfile_0.json",F_OK))!=-1)
  9219. {
  9220. strcpy(chargingProfiles[i], "/Storage/OCPP/TxDefaultProfile_0.json");
  9221. i = i + 1;
  9222. }
  9223. //Check TxDefaultProfile_%d.json
  9224. for(int j=1; j <= gunTotalNumber; j++)
  9225. {
  9226. memset(fnametemp, 0, ARRAY_SIZE(fnametemp));
  9227. sprintf(fnametemp, "/Storage/OCPP/TxDefaultProfile_%d.json", j);
  9228. if((access(fnametemp,F_OK))!=-1)
  9229. {
  9230. strcpy(chargingProfiles[i], fnametemp);
  9231. i = i + 1;
  9232. }
  9233. }
  9234. //Check TxProfile_%d.json
  9235. for(int j=1; j <= gunTotalNumber; j++)
  9236. {
  9237. memset(fnametemp, 0, ARRAY_SIZE(fnametemp));
  9238. sprintf(fnametemp, "/Storage/OCPP/TxProfile_%d.json", j);
  9239. if((access(fnametemp,F_OK))!=-1)
  9240. {
  9241. strcpy(chargingProfiles[i], fnametemp);
  9242. i = i + 1;
  9243. }
  9244. }
  9245. ChargeProfileCount = i;
  9246. }// End connectorIsNULL is TRUE
  9247. if(ChargeProfileCount == 0)
  9248. {
  9249. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Unknown] );
  9250. goto end;
  9251. }
  9252. if(connectorIsNULL == FALSE && (connectorIdInt != 0) && ( (connectorIdInt-1) > gunTotalNumber) )
  9253. {
  9254. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Unknown] );
  9255. goto end;
  9256. }
  9257. if((connectorIsNULL == FALSE) && (connectorIdInt == 0) )
  9258. {
  9259. memset(str, 0, ARRAY_SIZE(str));
  9260. // clear temp file
  9261. sprintf(str,"rm -f %s",temp);
  9262. system(str);
  9263. for(int k=0; k < ChargeProfileCount; k++)
  9264. {
  9265. memset(str, 0, ARRAY_SIZE(str));
  9266. //clear file in C
  9267. sprintf(str,"rm -f %s",chargingProfiles[k]);
  9268. system(str);
  9269. }
  9270. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Accepted] );
  9271. goto end;
  9272. }
  9273. else if(connectorIsNULL == TRUE)
  9274. {
  9275. for(int k=0; k < ChargeProfileCount; k++)
  9276. {
  9277. fptr1 = fopen(chargingProfiles[k], "r");
  9278. fptr2 = fopen("/Storage/OCPP/ClearChargingProfiletemp.json", "w+");
  9279. //Check Charging Profile Count
  9280. while(fscanf(fptr1, "%s", word) != EOF)
  9281. {
  9282. //DEBUG_INFO("word=%s\n",word);
  9283. if(strstr(word, "chargingProfileId")!= NULL)
  9284. {
  9285. //DEBUG_INFO("test chargingProfileId \n");
  9286. n_chargingProfile = n_chargingProfile + 1;
  9287. //DEBUG_INFO("chargingProfileId Found\n");
  9288. }
  9289. }
  9290. rewind(fptr1);
  9291. //search Charging Profile Element
  9292. //int i= 0;
  9293. while ( fgets( sLineWord, sizeof sLineWord, fptr1 ) != NULL )
  9294. {
  9295. json_object *tmpProfilee;
  9296. tmpProfilee = json_tokener_parse(sLineWord);
  9297. if(!is_error(tmpProfilee))
  9298. {
  9299. if(json_object_object_get(tmpProfilee, "connectorId") != NULL)
  9300. {
  9301. tempconnectorIdInt = json_object_get_int(json_object_object_get(tmpProfilee, "connectorId"));
  9302. DEBUG_INFO("file's gun number: %d\n", tempconnectorIdInt);
  9303. }
  9304. if(json_object_object_get(json_object_object_get(tmpProfilee, "csChargingProfiles"), "chargingProfileId") != NULL)
  9305. {
  9306. tempchargingProfileIdInt = json_object_get_int(json_object_object_get(json_object_object_get(tmpProfilee, "csChargingProfiles"), "chargingProfileId"));
  9307. DEBUG_INFO("file's chargingProfileId: %d\n", tempchargingProfileIdInt);
  9308. }
  9309. if(json_object_object_get(json_object_object_get(tmpProfilee, "csChargingProfiles"), "stackLevel") != NULL)
  9310. {
  9311. tempstackLevelInt = json_object_get_int(json_object_object_get(json_object_object_get(tmpProfilee, "csChargingProfiles"), "stackLevel"));
  9312. DEBUG_INFO("file's stackLevel: %d\n", tempstackLevelInt);
  9313. }
  9314. if(json_object_object_get(json_object_object_get(tmpProfilee, "csChargingProfiles"), "chargingProfilePurpose") != NULL)
  9315. {
  9316. sprintf((char*)tempchargingProfilePurposeStr, "%s", json_object_get_string(json_object_object_get(json_object_object_get(tmpProfilee, "csChargingProfiles"), "chargingProfilePurpose")));
  9317. DEBUG_INFO("file's chargingProfilePurpose: %s\n", tempchargingProfilePurposeStr);
  9318. }
  9319. }
  9320. json_object_put(tmpProfilee);
  9321. if((chargingProfileIdIsNULL == FALSE)&&(tempchargingProfileIdInt == chargingProfileIdInt))
  9322. {
  9323. //------- not write to fptr2-------//
  9324. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Accepted] );
  9325. //clearflag = TRUE;
  9326. }
  9327. else if((chargingProfilePurposeIsNULL == FALSE)&&(strcmp(tempchargingProfilePurposeStr, chargingProfilePurposeStr) == 0))
  9328. {
  9329. //------- not write to fptr2-------//
  9330. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Accepted] );
  9331. }
  9332. else if((stackLevelIsNULL == FALSE) &&(tempstackLevelInt == stackLevelInt))
  9333. {
  9334. //------- not write to fptr2-------//
  9335. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Accepted] );
  9336. }
  9337. else if(chargingProfileIdIsNULL && chargingProfilePurposeIsNULL && stackLevelIsNULL)
  9338. {
  9339. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Accepted] );
  9340. }
  9341. else
  9342. {
  9343. fprintf(fptr2, sLineWord);//writing data into file
  9344. }
  9345. memset(sLineWord, 0, ARRAY_SIZE(sLineWord));
  9346. } //End of while ( fgets( sLineWord, sizeof sLineWord, fptr1 ) != NULL )
  9347. if(clearflag == TRUE)
  9348. {
  9349. fclose(fptr1);
  9350. fclose(fptr2);
  9351. sprintf(str,"rm -f %s",chargingProfiles[k]);
  9352. system(str);
  9353. // clear temp file
  9354. sprintf(str,"rm -f %s",temp);
  9355. system(str);
  9356. }
  9357. else
  9358. {
  9359. fclose(fptr1);
  9360. fclose(fptr2);
  9361. memset(str, 0, ARRAY_SIZE(str));
  9362. sprintf(str,"rm -f %s",chargingProfiles[k]);
  9363. system(str);
  9364. resultRename = rename(temp, chargingProfiles[k]);
  9365. if(resultRename == 0)
  9366. {
  9367. DEBUG_INFO("File ChargingProfile renamed successfully\n");
  9368. }
  9369. else
  9370. {
  9371. DEBUG_INFO("Error: unable to rename the ChargingProfile file\n");
  9372. }
  9373. if(comfirmstr[0]== 0)
  9374. {
  9375. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Unknown] );
  9376. }
  9377. //Check chargingProfile is empty file
  9378. /*------ Read the file ----------------*/
  9379. fptr1=fopen(chargingProfiles[k],"r");
  9380. ch=fgetc(fptr1);
  9381. rewind(fptr1);
  9382. memset(sLineWord, 0, ARRAY_SIZE(sLineWord));
  9383. if(ch!=EOF)
  9384. {
  9385. while (fgets( sLineWord, sizeof sLineWord, fptr1) != NULL)
  9386. {
  9387. str[strlen(sLineWord) - 1] = '\0'; // eat the newline fgets() stores
  9388. if(sLineWord[0]=='\0')
  9389. {
  9390. isEmptyFile = TRUE;
  9391. break;
  9392. }
  9393. else
  9394. {
  9395. isEmptyFile = FALSE;
  9396. break;
  9397. }
  9398. }
  9399. }
  9400. else
  9401. isEmptyFile = TRUE;
  9402. fclose(fptr1);
  9403. if(isEmptyFile == TRUE)
  9404. {
  9405. memset(str, 0, ARRAY_SIZE(str));
  9406. sprintf(str,"rm -f %s",chargingProfiles[k]);
  9407. system(str);
  9408. }
  9409. }
  9410. }// End of while(int k=0; k < ChargePointCount; k++)
  9411. }
  9412. else if((connectorIsNULL == FALSE) && (connectorIdInt != 0) )
  9413. {
  9414. DEBUG_INFO("ChargeProfileCount = %d\n", ChargeProfileCount);
  9415. for(int k=0; k < ChargeProfileCount; k++)
  9416. {
  9417. fptr1 = fopen(chargingProfiles[k], "r");
  9418. fptr2 = fopen(temp, "w+");
  9419. //Check Charging Profile Count
  9420. while(fscanf(fptr1, "%s", word) != EOF)
  9421. {
  9422. //DEBUG_INFO("word=%s\n",word);
  9423. if(strstr(word, "chargingProfileId")!= NULL)
  9424. {
  9425. n_chargingProfile = n_chargingProfile + 1;
  9426. }
  9427. }
  9428. rewind(fptr1);
  9429. //search Charging Profile Element
  9430. //int i= 0;
  9431. while ( fgets( sLineWord, sizeof sLineWord, fptr1 ) != NULL )
  9432. {
  9433. json_object *tmpProfilee;
  9434. tmpProfilee = json_tokener_parse(sLineWord);
  9435. if(!is_error(tmpProfilee))
  9436. {
  9437. if(json_object_object_get(tmpProfilee, "connectorId") != NULL)
  9438. {
  9439. tempconnectorIdInt = json_object_get_int(json_object_object_get(tmpProfilee, "connectorId"));
  9440. DEBUG_INFO("file's gun number: %d\n", tempconnectorIdInt);
  9441. }
  9442. if(json_object_object_get(json_object_object_get(tmpProfilee, "csChargingProfiles"), "chargingProfileId") != NULL)
  9443. {
  9444. tempchargingProfileIdInt = json_object_get_int(json_object_object_get(json_object_object_get(tmpProfilee, "csChargingProfiles"), "chargingProfileId"));
  9445. DEBUG_INFO("file's chargingProfileId: %d\n", tempchargingProfileIdInt);
  9446. }
  9447. if(json_object_object_get(json_object_object_get(tmpProfilee, "csChargingProfiles"), "stackLevel") != NULL)
  9448. {
  9449. tempstackLevelInt = json_object_get_int(json_object_object_get(json_object_object_get(tmpProfilee, "csChargingProfiles"), "stackLevel"));
  9450. DEBUG_INFO("file's stackLevel: %d\n", tempstackLevelInt);
  9451. }
  9452. if(json_object_object_get(json_object_object_get(tmpProfilee, "csChargingProfiles"), "chargingProfilePurpose") != NULL)
  9453. {
  9454. sprintf((char*)tempchargingProfilePurposeStr, "%s", json_object_get_string(json_object_object_get(json_object_object_get(tmpProfilee, "csChargingProfiles"), "chargingProfilePurpose")));
  9455. DEBUG_INFO("file's chargingProfilePurpose: %s\n", tempchargingProfilePurposeStr);
  9456. }
  9457. }
  9458. json_object_put(tmpProfilee);
  9459. if((chargingProfileIdIsNULL == FALSE)&&(tempchargingProfileIdInt == chargingProfileIdInt))
  9460. {
  9461. //------- not write to fptr2-------//
  9462. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Accepted] );
  9463. //clearflag = TRUE;
  9464. }
  9465. else if((stackLevelIsNULL == FALSE) &&(tempstackLevelInt == stackLevelInt))
  9466. {
  9467. //------- not write to fptr2-------//
  9468. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Accepted] );
  9469. }
  9470. else if(stackLevelIsNULL == TRUE)
  9471. {
  9472. //Clear Whole File
  9473. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Accepted] );
  9474. clearflag = TRUE;
  9475. break;
  9476. }
  9477. else
  9478. {
  9479. fprintf(fptr2, sLineWord);//writing data into file
  9480. }
  9481. memset(sLineWord, 0, ARRAY_SIZE(sLineWord));
  9482. }
  9483. if(clearflag == TRUE)
  9484. {
  9485. fclose(fptr1);
  9486. fclose(fptr2);
  9487. sprintf(str,"rm -f %s",chargingProfiles[k]);
  9488. system(str);
  9489. // clear temp file
  9490. sprintf(str,"rm -f %s",temp);
  9491. system(str);
  9492. }
  9493. else
  9494. {
  9495. fclose(fptr1);
  9496. fclose(fptr2);
  9497. sprintf(str,"rm -f %s",chargingProfiles[k]);
  9498. system(str);
  9499. resultRename = rename(temp, chargingProfiles[k]);
  9500. if(resultRename == 0)
  9501. {
  9502. DEBUG_INFO("File ChargingProfile renamed successfully");
  9503. }
  9504. else
  9505. {
  9506. DEBUG_INFO("Error: unable to rename the ChargingProfile file");
  9507. }
  9508. if(comfirmstr[0]== 0)
  9509. {
  9510. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Unknown] );
  9511. }
  9512. //Check chargingProfile is empty file
  9513. /*------ Read the file ----------------*/
  9514. fptr1=fopen(chargingProfiles[k],"r");
  9515. ch=fgetc(fptr1);
  9516. rewind(fptr1);
  9517. memset(sLineWord, 0, ARRAY_SIZE(sLineWord));
  9518. if(ch!=EOF)
  9519. {
  9520. while (fgets( sLineWord, sizeof sLineWord, fptr1) != NULL)
  9521. {
  9522. str[strlen(sLineWord) - 1] = '\0'; // eat the newline fgets() stores
  9523. if(sLineWord[0]=='\0')
  9524. {
  9525. isEmptyFile = TRUE;
  9526. break;
  9527. }
  9528. else
  9529. {
  9530. isEmptyFile = FALSE;
  9531. break;
  9532. }
  9533. }
  9534. }
  9535. else
  9536. isEmptyFile = TRUE;
  9537. fclose(fptr1);
  9538. if(isEmptyFile == TRUE)
  9539. {
  9540. memset(str, 0, ARRAY_SIZE(str));
  9541. sprintf(str,"rm -f %s",chargingProfiles[k]);
  9542. system(str);
  9543. }
  9544. /*------- End of reading ---------------*/
  9545. }
  9546. } // while(int k=0; k < ChargeProfileCount; k++)
  9547. }// (connectorIsNULL == FALSE) && (connectorIdInt != 0)
  9548. end:
  9549. if(strcmp(comfirmstr, ClearChargingProfileStatusStr[ClearChargingProfileStatus_Accepted]) == 0)
  9550. {
  9551. if(connectorIdInt == 0)
  9552. {
  9553. for(uint8_t idx=0;idx<gunTotalNumber;idx++)
  9554. {
  9555. checkCompositeSchedule((idx+1), 86400, &ShmOCPP16Data->SmartChargingProfile[idx], TRUE);
  9556. }
  9557. }
  9558. else
  9559. checkCompositeSchedule(connectorIdInt, 86400, &ShmOCPP16Data->SmartChargingProfile[connectorIdInt-1], TRUE);
  9560. }
  9561. sendClearChargingProfileConfirmation(uuid, comfirmstr);
  9562. system("/bin/fsync -d /dev/mtdblock13;/bin/sync &");
  9563. return result;
  9564. }
  9565. void createFirmwareVersionByDataTransfer(void)
  9566. {
  9567. json_object *FirmwareDataTransfer = json_object_new_object();
  9568. // AC & DC model
  9569. json_object_object_add(FirmwareDataTransfer, "CsuBootLoadFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.CsuBootLoadFwRev));
  9570. json_object_object_add(FirmwareDataTransfer, "CsuKernelFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.CsuKernelFwRev));
  9571. json_object_object_add(FirmwareDataTransfer, "CsuRootFsFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.CsuRootFsFwRev));
  9572. json_object_object_add(FirmwareDataTransfer, "CsuPrimFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.CsuPrimFwRev));
  9573. // DC model
  9574. if((ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D'))
  9575. {
  9576. if((gunType[1] != GUN_TYPE_UNKNOWN) ||
  9577. (gunType[2] != GUN_TYPE_UNKNOWN) ||
  9578. (gunType[3] != GUN_TYPE_UNKNOWN))
  9579. {
  9580. json_object_object_add(FirmwareDataTransfer, "Connector2FwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.Connector2FwRev));
  9581. }
  9582. if((ShmSysConfigAndInfo->SysConfig.ModelName[1]!='B') && (ShmSysConfigAndInfo->SysConfig.ModelName[1]!='K') && (ShmSysConfigAndInfo->SysConfig.ModelName[1]!='O'))
  9583. {
  9584. // DS DM DW
  9585. json_object_object_add(FirmwareDataTransfer, "FanModuleFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.FanModuleFwRev));
  9586. json_object_object_add(FirmwareDataTransfer, "RelayModuleFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.RelayModuleFwRev));
  9587. json_object_object_add(FirmwareDataTransfer, "LedModuleFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.LedModuleFwRev));
  9588. json_object_object_add(FirmwareDataTransfer, "Connector1FwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.Connector1FwRev));
  9589. json_object_object_add(FirmwareDataTransfer, "PsuPrimFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.PsuPrimFwRev));
  9590. json_object_object_add(FirmwareDataTransfer, "PsuSecFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.PsuSecFwRev));
  9591. }
  9592. else
  9593. {
  9594. json_object_object_add(FirmwareDataTransfer, "FanModuleFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.FanModuleFwRev));
  9595. json_object_object_add(FirmwareDataTransfer, "RelayModuleFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.RelayModuleFwRev));
  9596. json_object_object_add(FirmwareDataTransfer, "PsuPrimFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.PsuPrimFwRev));
  9597. json_object_object_add(FirmwareDataTransfer, "PsuSecFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.PsuSecFwRev));
  9598. json_object_object_add(FirmwareDataTransfer, "DD0_CsuBootLoadFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[0].CsuBootLoadFwRev));
  9599. json_object_object_add(FirmwareDataTransfer, "DD0_CsuKernelFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[0].CsuKernelFwRev));
  9600. json_object_object_add(FirmwareDataTransfer, "DD0_CsuRootFsFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[0].CsuRootFsFwRev));
  9601. json_object_object_add(FirmwareDataTransfer, "DD0_CsuPrimFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[0].CsuPrimFwRev));
  9602. json_object_object_add(FirmwareDataTransfer, "DD0_FanModuleFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[0].FanModuleFwRev));
  9603. json_object_object_add(FirmwareDataTransfer, "DD0_RelayModuleFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[0].RelayModuleFwRev));
  9604. json_object_object_add(FirmwareDataTransfer, "DD0_LedModuleFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[0].LedModuleFwRev));
  9605. json_object_object_add(FirmwareDataTransfer, "DD0_Connector1FwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[0].Connector1FwRev));
  9606. json_object_object_add(FirmwareDataTransfer, "DD0_Connector2FwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[0].Connector2FwRev));
  9607. if(strlen((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].CsuBootLoadFwRev) > 0)
  9608. json_object_object_add(FirmwareDataTransfer, "DD1_CsuBootLoadFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].CsuBootLoadFwRev));
  9609. if(strlen((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].CsuKernelFwRev) > 0)
  9610. json_object_object_add(FirmwareDataTransfer, "DD1_CsuKernelFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].CsuKernelFwRev));
  9611. if(strlen((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].CsuRootFsFwRev) > 0)
  9612. json_object_object_add(FirmwareDataTransfer, "DD1_CsuRootFsFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].CsuRootFsFwRev));
  9613. if(strlen((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].CsuPrimFwRev) > 0)
  9614. json_object_object_add(FirmwareDataTransfer, "DD1_CsuPrimFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].CsuPrimFwRev));
  9615. if(strlen((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].FanModuleFwRev) > 0)
  9616. json_object_object_add(FirmwareDataTransfer, "DD1_FanModuleFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].FanModuleFwRev));
  9617. if(strlen((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].RelayModuleFwRev) > 0)
  9618. json_object_object_add(FirmwareDataTransfer, "DD1_RelayModuleFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].RelayModuleFwRev));
  9619. if(strlen((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].LedModuleFwRev) > 0)
  9620. json_object_object_add(FirmwareDataTransfer, "DD1_LedModuleFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].LedModuleFwRev));
  9621. if(strlen((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].Connector1FwRev) > 0)
  9622. json_object_object_add(FirmwareDataTransfer, "DD1_Connector1FwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].Connector1FwRev));
  9623. if(strlen((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].Connector2FwRev) > 0)
  9624. json_object_object_add(FirmwareDataTransfer, "D11_Connector2FwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].Connector2FwRev));
  9625. }
  9626. }
  9627. // 4G model
  9628. if((ShmSysConfigAndInfo->SysConfig.ModelName[10]=='T')||(ShmSysConfigAndInfo->SysConfig.ModelName[10]=='D'))
  9629. {
  9630. json_object_object_add(FirmwareDataTransfer, "TelcomModemFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysConfig.TelecomInterface.TelcomSoftwareVer));
  9631. }
  9632. sprintf((char*)ShmOCPP16Data->DataTransfer[0].ResponseData, json_object_to_json_string_ext(FirmwareDataTransfer, JSON_C_TO_STRING_PLAIN));
  9633. json_object_put(FirmwareDataTransfer);
  9634. }
  9635. int handleDataTransferRequest(char *uuid, char *payload)
  9636. {
  9637. mtrace();
  9638. json_object *response = json_object_new_object();
  9639. int result = FAIL;
  9640. char tempvendorId[255]={0};
  9641. char tempmessageId[50]={0};
  9642. char tempdata[1024]={0};
  9643. char message[2048]={0};
  9644. DEBUG_INFO("handleDataTransferRequest...\n");
  9645. if((uuid != NULL) && (payload != NULL))
  9646. {
  9647. json_object *DataTransfer;
  9648. DataTransfer = json_tokener_parse(payload);
  9649. if(!is_error(DataTransfer))
  9650. {
  9651. // Required data
  9652. if(json_object_object_get(DataTransfer, "vendorId") != NULL)
  9653. sprintf((char*)tempvendorId, "%s", json_object_get_string(json_object_object_get(DataTransfer, "vendorId")));
  9654. // Optional data
  9655. if(json_object_object_get(DataTransfer, "messageId") != NULL)
  9656. sprintf((char*)tempmessageId, "%s", json_object_get_string(json_object_object_get(DataTransfer, "messageId")));
  9657. if(json_object_object_get(DataTransfer, "data") != NULL)
  9658. sprintf((char*)tempdata, "%s", json_object_get_string(json_object_object_get(DataTransfer, "data")));
  9659. result = PASS;
  9660. }
  9661. json_object_put(DataTransfer);
  9662. if(strstr(tempmessageId, "ID_FirmwareVersion") != NULL)
  9663. {
  9664. // Send all moudle firmware version on EVSE
  9665. createFirmwareVersionByDataTransfer();
  9666. json_object_object_add(response, "status", json_object_new_string("Accepted"));
  9667. json_object_object_add(response, "data", json_object_new_string((char*)ShmOCPP16Data->DataTransfer[0].ResponseData));
  9668. sprintf(message,"[%d,\"%s\",%s]",MESSAGE_TYPE_CALLRESULT, uuid, json_object_to_json_string_ext(response, JSON_C_TO_STRING_PLAIN));
  9669. json_object_put(response);
  9670. }
  9671. else if(strstr(tempmessageId, "ID_Tmate") != NULL)
  9672. {
  9673. system("/usr/bin/run_tmate_restart.sh &");
  9674. json_object_object_add(response, "status", json_object_new_string("Accepted"));
  9675. sprintf(message,"[%d,\"%s\",%s]",MESSAGE_TYPE_CALLRESULT, uuid, json_object_to_json_string_ext(response, JSON_C_TO_STRING_PLAIN));
  9676. json_object_put(response);
  9677. }
  9678. else if(strstr(tempmessageId, "ID_ChargingPreference") != NULL)
  9679. {
  9680. json_object *data;
  9681. data = json_tokener_parse(tempdata);
  9682. if(!is_error(data))
  9683. {
  9684. 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))
  9685. {
  9686. DEBUG_INFO("ChargeingPreference connector id: %d\n", json_object_get_int(json_object_object_get(data, "ConnectorId")));
  9687. memset(&ShmOCPP16Data->SessionTarget[json_object_get_int(json_object_object_get(data, "ConnectorId"))], 0x00, sizeof(struct StructSessionTarget));
  9688. if(json_object_object_get(data, "SOC") != NULL)
  9689. {
  9690. ShmOCPP16Data->SessionTarget[json_object_get_int(json_object_object_get(data, "ConnectorId"))-1].targetSoc = json_object_get_int(json_object_object_get(data, "SOC"));
  9691. DEBUG_INFO("ChargeingPreference target soc: %d\n", json_object_get_int(json_object_object_get(data, "SOC")));
  9692. }
  9693. if(json_object_object_get(data, "Energy") != NULL)
  9694. {
  9695. ShmOCPP16Data->SessionTarget[json_object_get_int(json_object_object_get(data, "ConnectorId"))-1].targetEnergy = json_object_get_int(json_object_object_get(data, "Energy"));
  9696. DEBUG_INFO("ChargeingPreference target energy: %d KWH\n", json_object_get_int(json_object_object_get(data, "Energy")));
  9697. }
  9698. if(json_object_object_get(data, "Duration") != NULL)
  9699. {
  9700. ShmOCPP16Data->SessionTarget[json_object_get_int(json_object_object_get(data, "ConnectorId"))-1].targetDuration = json_object_get_int(json_object_object_get(data, "Duration"));
  9701. DEBUG_INFO("ChargeingPreference target duration: %d minutes\n", json_object_get_int(json_object_object_get(data, "Duration")));
  9702. }
  9703. json_object_object_add(response, "status", json_object_new_string("Accepted"));
  9704. }
  9705. else
  9706. {
  9707. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  9708. json_object_object_add(response, "data", json_object_new_string("Connector id must > 0."));
  9709. }
  9710. }
  9711. else
  9712. {
  9713. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  9714. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  9715. }
  9716. json_object_put(data);
  9717. sprintf(message,"[%d,\"%s\",%s]",MESSAGE_TYPE_CALLRESULT, uuid, json_object_to_json_string_ext(response, JSON_C_TO_STRING_PLAIN));
  9718. json_object_put(response);
  9719. }
  9720. else if(strstr(tempmessageId, "SetLEDBar") != NULL)
  9721. {
  9722. json_object *data;
  9723. data = json_tokener_parse(tempdata);
  9724. if(!is_error(data))
  9725. {
  9726. ShmSysConfigAndInfo->SysConfig.LedInfo.Intensity = json_object_get_int(json_object_object_get(data, "Intensity"));
  9727. ShmSysConfigAndInfo->SysConfig.LedInfo.Red[0] = json_object_get_int(json_object_object_get(json_object_object_get(data, "Idle"), "R"));
  9728. ShmSysConfigAndInfo->SysConfig.LedInfo.Green[0]= json_object_get_int(json_object_object_get(json_object_object_get(data, "Idle"), "G"));
  9729. ShmSysConfigAndInfo->SysConfig.LedInfo.Blue[0] = json_object_get_int(json_object_object_get(json_object_object_get(data, "Idle"), "B"));
  9730. ShmSysConfigAndInfo->SysConfig.LedInfo.Red[1] = json_object_get_int(json_object_object_get(json_object_object_get(data, "Charging"), "R"));
  9731. ShmSysConfigAndInfo->SysConfig.LedInfo.Green[1]= json_object_get_int(json_object_object_get(json_object_object_get(data, "Charging"), "G"));
  9732. ShmSysConfigAndInfo->SysConfig.LedInfo.Blue[1] = json_object_get_int(json_object_object_get(json_object_object_get(data, "Charging"), "B"));
  9733. ShmSysConfigAndInfo->SysConfig.LedInfo.Red[2] = json_object_get_int(json_object_object_get(json_object_object_get(data, "Fault"), "R"));
  9734. ShmSysConfigAndInfo->SysConfig.LedInfo.Green[2]= json_object_get_int(json_object_object_get(json_object_object_get(data, "Fault"), "G"));
  9735. ShmSysConfigAndInfo->SysConfig.LedInfo.Blue[2] = json_object_get_int(json_object_object_get(json_object_object_get(data, "Fault"), "B"));
  9736. json_object_object_add(response, "status", json_object_new_string("Accepted"));
  9737. }
  9738. else
  9739. {
  9740. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  9741. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  9742. }
  9743. json_object_put(data);
  9744. sprintf(message,"[%d,\"%s\",%s]",MESSAGE_TYPE_CALLRESULT, uuid, json_object_to_json_string_ext(response, JSON_C_TO_STRING_PLAIN));
  9745. json_object_put(response);
  9746. }
  9747. else if(strstr(tempmessageId, "SetUserPrice") != NULL)
  9748. {
  9749. json_object *data;
  9750. data = json_tokener_parse(tempdata);
  9751. if(!is_error(data))
  9752. {
  9753. memset(&ShmOCPP16Data->Cost.SetUserPrice, 0x00, sizeof(struct StrcutSetUserPrice));
  9754. json_object_object_add(response, "status", json_object_new_string("Accepted"));
  9755. if(json_object_object_get(data, "idToken") != NULL)
  9756. {
  9757. sprintf((char*)ShmOCPP16Data->Cost.SetUserPrice.idToken, "%s", json_object_get_string(json_object_object_get(data, "idToken")));
  9758. DEBUG_INFO("idToken: %s\n", json_object_get_string(json_object_object_get(data, "idToken")));
  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("idToken not found."));
  9764. }
  9765. if(json_object_object_get(data, "price") != NULL) //v1.0
  9766. {
  9767. sprintf((char*)ShmOCPP16Data->Cost.SetUserPrice.price, "%s", json_object_get_string(json_object_object_get(data, "price")));
  9768. DEBUG_INFO("price: %s\n", json_object_get_string(json_object_object_get(data, "price")));
  9769. }
  9770. else if(json_object_object_get(data, "priceText") != NULL) //v2.0
  9771. {
  9772. sprintf((char*)ShmOCPP16Data->Cost.SetUserPrice.price, "%s", json_object_get_string(json_object_object_get(data, "priceText")));
  9773. DEBUG_INFO("priceText: %s\n", json_object_get_string(json_object_object_get(data, "priceText")));
  9774. }
  9775. else
  9776. {
  9777. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  9778. json_object_object_add(response, "data", json_object_new_string("price or priceText not found."));
  9779. }
  9780. }
  9781. else
  9782. {
  9783. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  9784. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  9785. }
  9786. json_object_put(data);
  9787. sprintf(message,"[%d,\"%s\",%s]",MESSAGE_TYPE_CALLRESULT, uuid, json_object_to_json_string_ext(response, JSON_C_TO_STRING_PLAIN));
  9788. json_object_put(response);
  9789. }
  9790. else if(strstr(tempmessageId, "RunningCost") != NULL)
  9791. {
  9792. json_object *data;
  9793. data = json_tokener_parse(tempdata);
  9794. if(!is_error(data))
  9795. {
  9796. json_object_object_add(response, "status", json_object_new_string("Accepted"));
  9797. if(json_object_object_get(data, "txId") != NULL)
  9798. {
  9799. // California pricing V1.0
  9800. DEBUG_INFO("California pricing V1.0\n");
  9801. DEBUG_INFO("txId: %d\n", json_object_get_int(json_object_object_get(data, "txId")));
  9802. sprintf((char*)dmsVersion, "1.0");
  9803. for(int idx = 0;idx<gunTotalNumber;idx++)
  9804. {
  9805. if(ShmOCPP16Data->StartTransaction[idx].ResponseTransactionId == json_object_get_int(json_object_object_get(data, "txId")))
  9806. {
  9807. memset(&ShmOCPP16Data->Cost.RunningCost[idx], 0x00, sizeof(struct StrcutRunningCost));
  9808. ShmOCPP16Data->Cost.RunningCost[idx].txId = json_object_get_int(json_object_object_get(data, "txId"));
  9809. if(json_object_object_get(data, "description") != NULL)
  9810. {
  9811. DEBUG_INFO("description: %s\n", json_object_get_string(json_object_object_get(data, "description")));
  9812. sprintf((char*)ShmOCPP16Data->Cost.RunningCost[idx].description, "%s", json_object_get_string(json_object_object_get(data, "description")));
  9813. }
  9814. else
  9815. {
  9816. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  9817. json_object_object_add(response, "data", json_object_new_string("description not found."));
  9818. }
  9819. }
  9820. }
  9821. }
  9822. else if(json_object_object_get(data, "transactionId") != NULL)
  9823. {
  9824. // California pricing V2.0
  9825. DEBUG_INFO("California pricing V2.0\n");
  9826. DEBUG_INFO("transactionId: %d\n", json_object_get_int(json_object_object_get(data, "transactionId")));
  9827. sprintf((char*)dmsVersion, "2.0");
  9828. for(int idx=0;idx<gunTotalNumber;idx++)
  9829. {
  9830. if(ShmOCPP16Data->StartTransaction[idx].ResponseTransactionId == json_object_get_int(json_object_object_get(data, "transactionId")))
  9831. {
  9832. ShmOCPP16Data->Cost.RunningCost[idx].txId = json_object_get_int(json_object_object_get(data, "transactionId"));
  9833. if(json_object_object_get(data, "timestamp") != NULL)
  9834. {
  9835. DEBUG_INFO("timestamp: %s\n", json_object_get_string(json_object_object_get(data, "timestamp")));
  9836. sprintf((char*)ShmOCPP16Data->Cost.RunningCost[idx].timestamp, "%s", json_object_get_string(json_object_object_get(data, "timestamp")));
  9837. }
  9838. else
  9839. {
  9840. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  9841. json_object_object_add(response, "data", json_object_new_string("timestamp not found."));
  9842. }
  9843. if(json_object_object_get(data, "meterValue") != NULL)
  9844. {
  9845. DEBUG_INFO("meterValue: %d\n", json_object_get_int(json_object_object_get(data, "meterValue")));
  9846. ShmOCPP16Data->Cost.RunningCost[idx].meterValue = json_object_get_int(json_object_object_get(data, "meterValue"));
  9847. }
  9848. else
  9849. {
  9850. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  9851. json_object_object_add(response, "data", json_object_new_string("meterValue not found."));
  9852. }
  9853. if(json_object_object_get(data, "cost") != NULL)
  9854. {
  9855. DEBUG_INFO("cost: %f\n", json_object_get_double(json_object_object_get(data, "cost")));
  9856. ShmOCPP16Data->Cost.RunningCost[idx].cost = json_object_get_double(json_object_object_get(data, "cost"));
  9857. }
  9858. else
  9859. {
  9860. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  9861. json_object_object_add(response, "data", json_object_new_string("cost not found."));
  9862. }
  9863. if(json_object_object_get(data, "state") != NULL)
  9864. {
  9865. DEBUG_INFO("state: %s\n", json_object_get_string(json_object_object_get(data, "state")));
  9866. sprintf((char*)ShmOCPP16Data->Cost.RunningCost[idx].state, "%s", json_object_get_string(json_object_object_get(data, "state")));
  9867. }
  9868. else
  9869. {
  9870. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  9871. json_object_object_add(response, "data", json_object_new_string("state not found."));
  9872. }
  9873. if(json_object_object_get(data, "chargingPrice") != NULL)
  9874. {
  9875. if(json_object_object_get(json_object_object_get(data, "chargingPrice"), "kWhPrice") != NULL)
  9876. {
  9877. DEBUG_INFO("chargingPrice-kWhPrice: %f\n", json_object_get_double(json_object_object_get(json_object_object_get(data, "chargingPrice"), "kWhPrice")));
  9878. ShmOCPP16Data->Cost.RunningCost[idx].chargingPrice.kWhPrice = json_object_get_double(json_object_object_get(json_object_object_get(data, "chargingPrice"), "kWhPrice"));
  9879. }
  9880. if(json_object_object_get(json_object_object_get(data, "chargingPrice"), "hourPrice") != NULL)
  9881. {
  9882. DEBUG_INFO("chargingPrice-hourPrice: %f\n", json_object_get_double(json_object_object_get(json_object_object_get(data, "chargingPrice"), "hourPrice")));
  9883. ShmOCPP16Data->Cost.RunningCost[idx].chargingPrice.hourPrice = json_object_get_double(json_object_object_get(json_object_object_get(data, "chargingPrice"), "hourPrice"));
  9884. }
  9885. if(json_object_object_get(json_object_object_get(data, "chargingPrice"), "flatFee") != NULL)
  9886. {
  9887. DEBUG_INFO("chargingPrice-flatFee: %f\n", json_object_get_double(json_object_object_get(json_object_object_get(data, "chargingPrice"), "flatFee")));
  9888. ShmOCPP16Data->Cost.RunningCost[idx].chargingPrice.flatFee = json_object_get_double(json_object_object_get(json_object_object_get(data, "chargingPrice"), "flatFee"));
  9889. }
  9890. }
  9891. else
  9892. {
  9893. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  9894. json_object_object_add(response, "data", json_object_new_string("chargingPrice not found."));
  9895. }
  9896. if(json_object_object_get(data, "idlePrice") != NULL)
  9897. {
  9898. if(json_object_object_get(json_object_object_get(data, "idlePrice"), "graceMinutes") != NULL)
  9899. {
  9900. DEBUG_INFO("idlePrice-graceMinutes: %d\n", json_object_get_int(json_object_object_get(json_object_object_get(data, "idlePrice"), "graceMinutes")));
  9901. ShmOCPP16Data->Cost.RunningCost[idx].idlePrice.graceMinutes = json_object_get_int(json_object_object_get(json_object_object_get(data, "idlePrice"), "graceMinutes"));
  9902. }
  9903. if(json_object_object_get(json_object_object_get(data, "idlePrice"), "hourPrice") != NULL)
  9904. {
  9905. DEBUG_INFO("idlePrice-hourPrice: %f\n", json_object_get_double(json_object_object_get(json_object_object_get(data, "idlePrice"), "hourPrice")));
  9906. ShmOCPP16Data->Cost.RunningCost[idx].idlePrice.hourPrice = json_object_get_double(json_object_object_get(json_object_object_get(data, "idlePrice"), "hourPrice"));
  9907. }
  9908. }
  9909. if(json_object_object_get(data, "nextPeriod") != NULL)
  9910. {
  9911. if(json_object_object_get(json_object_object_get(data, "nextPeriod"), "atTime") != NULL)
  9912. {
  9913. DEBUG_INFO("nextPeriod-atTime: %s\n", json_object_get_string(json_object_object_get(json_object_object_get(data, "nextPeriod"), "atTime")));
  9914. sprintf((char*)ShmOCPP16Data->Cost.RunningCost[idx].nextPeriod.atTime, "%s", json_object_get_string(json_object_object_get(json_object_object_get(data, "nextPeriod"), "atTime")));
  9915. }
  9916. else
  9917. {
  9918. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  9919. json_object_object_add(response, "data", json_object_new_string("atTime not found."));
  9920. }
  9921. if(json_object_object_get(json_object_object_get(data, "nextPeriod"), "chargingPrice") != NULL)
  9922. {
  9923. if(json_object_object_get(json_object_object_get(json_object_object_get(data, "nextPeriod"), "chargingPrice"), "kWhPrice") != NULL)
  9924. {
  9925. 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")));
  9926. 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"));
  9927. }
  9928. if(json_object_object_get(json_object_object_get(json_object_object_get(data, "nextPeriod"), "chargingPrice"), "hourPrice") != NULL)
  9929. {
  9930. 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")));
  9931. 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"));
  9932. }
  9933. if(json_object_object_get(json_object_object_get(json_object_object_get(data, "nextPeriod"), "chargingPrice"), "flatFee") != NULL)
  9934. {
  9935. 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")));
  9936. 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"));
  9937. }
  9938. }
  9939. else
  9940. {
  9941. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  9942. json_object_object_add(response, "data", json_object_new_string("chargingPrice not found."));
  9943. }
  9944. if(json_object_object_get(json_object_object_get(data, "nextPeriod"), "idlePrice") != NULL)
  9945. {
  9946. if(json_object_object_get(json_object_object_get(json_object_object_get(data, "nextPeriod"), "idlePrice"), "graceMinutes") != NULL)
  9947. {
  9948. 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")));
  9949. 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"));
  9950. }
  9951. if(json_object_object_get(json_object_object_get(json_object_object_get(data, "nextPeriod"), "idlePrice"), "hourPrice") != NULL)
  9952. {
  9953. 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")));
  9954. 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"));
  9955. }
  9956. }
  9957. }
  9958. if(json_object_object_get(data, "triggerMeterValue") != NULL)
  9959. {
  9960. if(json_object_object_get(json_object_object_get(data, "triggerMeterValue"), "atTime") != NULL)
  9961. {
  9962. DEBUG_INFO("triggerMeterValue-atTime: %s\n", json_object_get_string(json_object_object_get(json_object_object_get(data, "triggerMeterValue"), "atTime")));
  9963. sprintf((char*)ShmOCPP16Data->Cost.RunningCost[idx].triggerMeterValue.atTime, "%s", json_object_get_string(json_object_object_get(json_object_object_get(data, "triggerMeterValue"), "atTime")));
  9964. }
  9965. if(json_object_object_get(json_object_object_get(data, "triggerMeterValue"), "atEnergykWh") != NULL)
  9966. {
  9967. DEBUG_INFO("triggerMeterValue-atEnergykWh: %f\n", json_object_get_double(json_object_object_get(json_object_object_get(data, "triggerMeterValue"), "atEnergykWh")));
  9968. ShmOCPP16Data->Cost.RunningCost[idx].triggerMeterValue.atEnergykWh = json_object_get_double(json_object_object_get(json_object_object_get(data, "triggerMeterValue"), "atEnergykWh"));
  9969. }
  9970. if(json_object_object_get(json_object_object_get(data, "triggerMeterValue"), "atPowerkW") != NULL)
  9971. {
  9972. DEBUG_INFO("triggerMeterValue-atPowerkW: %f\n", json_object_get_double(json_object_object_get(json_object_object_get(data, "triggerMeterValue"), "atPowerkW")));
  9973. ShmOCPP16Data->Cost.RunningCost[idx].triggerMeterValue.atPowerkW = json_object_get_double(json_object_object_get(json_object_object_get(data, "triggerMeterValue"), "atPowerkW"));
  9974. }
  9975. if(json_object_object_get(json_object_object_get(data, "triggerMeterValue"), "atCPStatus") != NULL)
  9976. {
  9977. DEBUG_INFO("triggerMeterValue-atCPStatus: %s\n", json_object_get_string(json_object_object_get(json_object_object_get(data, "triggerMeterValue"), "atCPStatus")));
  9978. sprintf((char*)ShmOCPP16Data->Cost.RunningCost[idx].triggerMeterValue.atCPStatus, "%s", json_object_get_string(json_object_object_get(json_object_object_get(data, "triggerMeterValue"), "atCPStatus")));
  9979. }
  9980. }
  9981. }
  9982. }
  9983. }
  9984. else
  9985. {
  9986. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  9987. json_object_object_add(response, "data", json_object_new_string("txId or transactionId not found."));
  9988. }
  9989. }
  9990. else
  9991. {
  9992. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  9993. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  9994. }
  9995. json_object_put(data);
  9996. sprintf(message,"[%d,\"%s\",%s]",MESSAGE_TYPE_CALLRESULT, uuid, json_object_to_json_string_ext(response, JSON_C_TO_STRING_PLAIN));
  9997. json_object_put(response);
  9998. }
  9999. else if(strstr(tempmessageId, "FinalCost") != NULL)
  10000. {
  10001. json_object *data;
  10002. data = json_tokener_parse(tempdata);
  10003. if(!is_error(data))
  10004. {
  10005. json_object_object_add(response, "status", json_object_new_string("Accepted"));
  10006. if(json_object_object_get(data, "txId") != NULL)
  10007. {
  10008. DEBUG_INFO("v1.0 txId: %d\n", json_object_get_int(json_object_object_get(data, "txId")));
  10009. for(int idx = 0;idx<gunTotalNumber;idx++)
  10010. {
  10011. if(ShmOCPP16Data->StartTransaction[idx].ResponseTransactionId == json_object_get_int(json_object_object_get(data, "txId")))
  10012. {
  10013. memset(&ShmOCPP16Data->Cost.FinalCost[idx], 0x00, sizeof(struct StrcutFinalCost));
  10014. ShmOCPP16Data->Cost.FinalCost[idx].txId = json_object_get_int(json_object_object_get(data, "txId"));
  10015. if(json_object_object_get(data, "description") != NULL)
  10016. {
  10017. DEBUG_INFO("description: %s\n", json_object_get_string(json_object_object_get(data, "description")));
  10018. sprintf((char*)ShmOCPP16Data->Cost.FinalCost[idx].description, "%s", json_object_get_string(json_object_object_get(data, "description")));
  10019. }
  10020. else
  10021. {
  10022. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  10023. json_object_object_add(response, "data", json_object_new_string("description not found."));
  10024. }
  10025. }
  10026. }
  10027. }
  10028. else if(json_object_object_get(data, "transactionId") != NULL)
  10029. {
  10030. DEBUG_INFO("v2.0 transactionId: %d\n", json_object_get_int(json_object_object_get(data, "transactionId")));
  10031. for(int idx = 0;idx<gunTotalNumber;idx++)
  10032. {
  10033. if(ShmOCPP16Data->StartTransaction[idx].ResponseTransactionId == json_object_get_int(json_object_object_get(data, "transactionId")))
  10034. {
  10035. memset(&ShmOCPP16Data->Cost.FinalCost[idx], 0x00, sizeof(struct StrcutFinalCost));
  10036. ShmOCPP16Data->Cost.FinalCost[idx].txId = json_object_get_int(json_object_object_get(data, "transactionId"));
  10037. if(json_object_object_get(data, "cost") != NULL)
  10038. {
  10039. DEBUG_INFO("cost: %s\n", json_object_get_string(json_object_object_get(data, "cost")));
  10040. ShmOCPP16Data->Cost.FinalCost[idx].cost = json_object_get_double(json_object_object_get(data, "cost"));
  10041. }
  10042. else
  10043. {
  10044. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  10045. json_object_object_add(response, "data", json_object_new_string("cost not found."));
  10046. }
  10047. if(json_object_object_get(data, "priceText") != NULL)
  10048. {
  10049. DEBUG_INFO("priceText: %s\n", json_object_get_string(json_object_object_get(data, "priceText")));
  10050. sprintf((char*)ShmOCPP16Data->Cost.FinalCost[idx].priceText, "%s", json_object_get_string(json_object_object_get(data, "priceText")));
  10051. }
  10052. else
  10053. {
  10054. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  10055. json_object_object_add(response, "data", json_object_new_string("priceText not found."));
  10056. }
  10057. if(json_object_object_get(data, "qrCodeText") != NULL)
  10058. {
  10059. DEBUG_INFO(": %s\n", json_object_get_string(json_object_object_get(data, "qrCodeText")));
  10060. sprintf((char*)ShmOCPP16Data->Cost.FinalCost[idx].qrCodeText, "%s", json_object_get_string(json_object_object_get(data, "qrCodeText")));
  10061. }
  10062. }
  10063. }
  10064. }
  10065. else
  10066. {
  10067. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  10068. json_object_object_add(response, "data", json_object_new_string("txId or transactionId not found."));
  10069. }
  10070. }
  10071. else
  10072. {
  10073. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  10074. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  10075. }
  10076. json_object_put(data);
  10077. sprintf(message,"[%d,\"%s\",%s]",MESSAGE_TYPE_CALLRESULT, uuid, json_object_to_json_string_ext(response, JSON_C_TO_STRING_PLAIN));
  10078. json_object_put(response);
  10079. }
  10080. else if(strstr(tempmessageId, "ID_ConfigQR") != NULL)
  10081. {
  10082. json_object *data;
  10083. data = json_tokener_parse(tempdata);
  10084. if(!is_error(data))
  10085. {
  10086. json_object_object_add(response, "status", json_object_new_string("Accepted"));
  10087. if(json_object_object_get(data, "Content_Type") != NULL)
  10088. {
  10089. 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))
  10090. {
  10091. ShmSysConfigAndInfo->SysConfig.QRCodeMadeMode = json_object_get_int(json_object_object_get(data, "Content_Type"));
  10092. if(json_object_object_get(data, "Customization_Conent") != NULL)
  10093. {
  10094. sprintf((char*)ShmSysConfigAndInfo->SysConfig.QRCodeContent, "%s", json_object_get_string(json_object_object_get(data, "Customization_Conent")));
  10095. }
  10096. }
  10097. else
  10098. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  10099. }
  10100. StoreUsrConfigData(&ShmSysConfigAndInfo->SysConfig);
  10101. }
  10102. else
  10103. {
  10104. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  10105. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  10106. }
  10107. json_object_put(data);
  10108. sprintf(message,"[%d,\"%s\",%s]",MESSAGE_TYPE_CALLRESULT, uuid, json_object_to_json_string_ext(response, JSON_C_TO_STRING_PLAIN));
  10109. json_object_put(response);
  10110. }
  10111. else if(strstr(tempmessageId, "ID_LineStatusPage") != NULL)
  10112. {
  10113. json_object *data;
  10114. data = json_tokener_parse(tempdata);
  10115. if(!is_error(data))
  10116. {
  10117. json_object_object_add(response, "status", json_object_new_string("Accepted"));
  10118. if(json_object_object_get(data, "ConnectorId") != NULL)
  10119. {
  10120. ShmSysConfigAndInfo->SysInfo.LcdOveride.connectorId = json_object_get_int(json_object_object_get(data, "ConnectorId"));
  10121. }
  10122. if(json_object_object_get(data, "SerialNo") != NULL)
  10123. {
  10124. sprintf((char *)ShmOCPP16Data->TcciCustomData.SerialNo[(ShmSysConfigAndInfo->SysInfo.LcdOveride.connectorId-1)], "%s", json_object_get_string(json_object_object_get(data,"SerialNo")));
  10125. }
  10126. if(json_object_object_get(data, "Page_Index") != NULL)
  10127. {
  10128. ShmSysConfigAndInfo->SysInfo.LcdOveride.page_index = json_object_get_int(json_object_object_get(data, "Page_Index"));
  10129. }
  10130. if(json_object_object_get(data, "Duration") != NULL)
  10131. {
  10132. ShmSysConfigAndInfo->SysInfo.LcdOveride.duration = json_object_get_int(json_object_object_get(data, "Duration"));
  10133. }
  10134. ShmSysConfigAndInfo->SysInfo.LcdOveride.isOverideReq = 1;
  10135. }
  10136. else
  10137. {
  10138. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  10139. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  10140. }
  10141. json_object_put(data);
  10142. sprintf(message,"[%d,\"%s\",%s]",MESSAGE_TYPE_CALLRESULT, uuid, json_object_to_json_string_ext(response, JSON_C_TO_STRING_PLAIN));
  10143. json_object_put(response);
  10144. }
  10145. else if(strstr(tempmessageId, "ID_CpConfiguration") != NULL)
  10146. {
  10147. json_object *data;
  10148. data = json_tokener_parse(tempdata);
  10149. if(!is_error(data))
  10150. {
  10151. json_object_object_add(response, "status", json_object_new_string("Accepted"));
  10152. if(json_object_object_get(data, "MaxChargingCurrent") != NULL)
  10153. {
  10154. if(json_object_get_int(json_object_object_get(data, "MaxChargingCurrent")) >= 0)
  10155. ShmSysConfigAndInfo->SysConfig.MaxChargingCurrent = json_object_get_int(json_object_object_get(data, "MaxChargingCurrent"));
  10156. else
  10157. {
  10158. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  10159. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  10160. }
  10161. }
  10162. if(json_object_object_get(data, "MaxChargingDuration") != NULL)
  10163. {
  10164. if(json_object_get_int(json_object_object_get(data, "MaxChargingDuration")) >= 0)
  10165. ShmSysConfigAndInfo->SysConfig.MaxChargingDuration = json_object_get_int(json_object_object_get(data, "MaxChargingDuration"));
  10166. else
  10167. {
  10168. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  10169. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  10170. }
  10171. }
  10172. if(json_object_object_get(data, "MaxChargingEnergy") != NULL)
  10173. {
  10174. if(json_object_get_int(json_object_object_get(data, "MaxChargingEnergy")) >= 0)
  10175. ShmSysConfigAndInfo->SysConfig.MaxChargingEnergy = json_object_get_int(json_object_object_get(data, "MaxChargingEnergy"));
  10176. else
  10177. {
  10178. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  10179. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  10180. }
  10181. }
  10182. if(json_object_object_get(data, "MaxChargingPower") != NULL)
  10183. {
  10184. if(json_object_get_int(json_object_object_get(data, "MaxChargingPower")) >= 0)
  10185. ShmSysConfigAndInfo->SysConfig.MaxChargingPower = json_object_get_int(json_object_object_get(data, "MaxChargingPower"));
  10186. else
  10187. {
  10188. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  10189. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  10190. }
  10191. }
  10192. if(json_object_object_get(data, "OfflineMaxChargeEnergy") != NULL)
  10193. {
  10194. if(json_object_get_int(json_object_object_get(data, "OfflineMaxChargeEnergy")) >= 0)
  10195. ShmSysConfigAndInfo->SysConfig.OfflineMaxChargeEnergy = json_object_get_int(json_object_object_get(data, "OfflineMaxChargeEnergy"));
  10196. else
  10197. {
  10198. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  10199. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  10200. }
  10201. }
  10202. if(json_object_object_get(data, "OfflinePolicy") != NULL)
  10203. {
  10204. if((json_object_get_int(json_object_object_get(data, "OfflinePolicy")) == 0) ||
  10205. (json_object_get_int(json_object_object_get(data, "OfflinePolicy")) == 2) ||
  10206. (json_object_get_int(json_object_object_get(data, "OfflinePolicy")) == 3))
  10207. ShmSysConfigAndInfo->SysConfig.OfflinePolicy = json_object_get_int(json_object_object_get(data, "OfflinePolicy"));
  10208. else
  10209. {
  10210. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  10211. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  10212. }
  10213. }
  10214. if(json_object_object_get(data, "isAuthentication") != NULL)
  10215. {
  10216. switch(json_object_get_int(json_object_object_get(data, "isAuthentication")))
  10217. {
  10218. case 0:
  10219. case 1:
  10220. ShmSysConfigAndInfo->SysConfig.AuthorisationMode = json_object_get_int(json_object_object_get(data, "isAuthentication"))^1;
  10221. break;
  10222. default:
  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. break;
  10226. }
  10227. }
  10228. if(strstr(json_object_get_string(json_object_object_get(response, "status")), "Accepted") != NULL)
  10229. StoreUsrConfigData(&ShmSysConfigAndInfo->SysConfig);
  10230. }
  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. json_object_put(data);
  10237. sprintf(message,"[%d,\"%s\",%s]",MESSAGE_TYPE_CALLRESULT, uuid, json_object_to_json_string_ext(response, JSON_C_TO_STRING_PLAIN));
  10238. json_object_put(response);
  10239. }
  10240. else if(strstr(tempmessageId, "ID_TxEnergy") != NULL)
  10241. {
  10242. json_object *data;
  10243. data = json_tokener_parse(tempdata);
  10244. if(!is_error(data))
  10245. {
  10246. if((json_object_object_get(data, "ConnectorId") != NULL) && (json_object_object_get(data, "txId") != NULL))
  10247. {
  10248. if(OCPP_getPeriodEnergyToDataTransfer(json_object_get_int(json_object_object_get(data, "txId"))) == PASS)
  10249. {
  10250. json_object_object_add(response, "status", json_object_new_string("Accepted"));
  10251. json_object_object_add(response, "data", json_object_new_string((char*)ShmOCPP16Data->DataTransfer[0].ResponseData));
  10252. }
  10253. else
  10254. {
  10255. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  10256. json_object_object_add(response, "data", json_object_new_string("Present charged energy data can not get."));
  10257. }
  10258. }
  10259. else
  10260. {
  10261. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  10262. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  10263. }
  10264. }
  10265. else
  10266. {
  10267. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  10268. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  10269. }
  10270. sprintf(message,"[%d,\"%s\",%s]",MESSAGE_TYPE_CALLRESULT, uuid, json_object_to_json_string_ext(response, JSON_C_TO_STRING_PLAIN));
  10271. json_object_put(response);
  10272. }
  10273. else if(strstr(tempmessageId, "ID_Station_Location") != NULL)
  10274. {
  10275. json_object *data;
  10276. data = json_tokener_parse(tempdata);
  10277. if(!is_error(data))
  10278. {
  10279. json_object_object_add(response, "status", json_object_new_string("Accepted"));
  10280. if(json_object_object_get(data, "stationName") != NULL)
  10281. {
  10282. sprintf((char *)ShmOCPP16Data->TcciCustomData.ChargerInfo.station_name, "%s", json_object_get_string(json_object_object_get(data,"stationName")));
  10283. }
  10284. else
  10285. {
  10286. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  10287. json_object_object_add(response, "data", json_object_new_string("station_name data can not get."));
  10288. }
  10289. if(strcmp(json_object_get_string(json_object_object_get(response,"status")),"Accepted")==0)
  10290. {
  10291. ShmOCPP16Data->TcciCustomData.ChargerInfoReq = 1;
  10292. DEBUG_INFO("<<< ID_Station_Location:{station_name:%s}\n",
  10293. ShmOCPP16Data->TcciCustomData.ChargerInfo.station_name);
  10294. }
  10295. }
  10296. else
  10297. {
  10298. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  10299. json_object_object_add(response, "data", json_object_new_string("charger_info content got something wrong."));
  10300. }
  10301. sprintf(message,"[%d,\"%s\",%s]",MESSAGE_TYPE_CALLRESULT, uuid, json_object_to_json_string_ext(response, JSON_C_TO_STRING_PLAIN));
  10302. json_object_put(response);
  10303. }
  10304. else if(strstr(tempmessageId, "ID_Weather_Info") != NULL)
  10305. {
  10306. json_object *data;
  10307. data = json_tokener_parse(tempdata);
  10308. if(!is_error(data))
  10309. {
  10310. json_object_object_add(response, "status", json_object_new_string("Accepted"));
  10311. if(json_object_object_get(data, "weatherId") != NULL)
  10312. {
  10313. ShmOCPP16Data->TcciCustomData.WeatherInfo.weatherId = json_object_get_int(json_object_object_get(data, "weatherId"));
  10314. }
  10315. else
  10316. {
  10317. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  10318. json_object_object_add(response, "data", json_object_new_string("weather data can not get."));
  10319. }
  10320. if(json_object_object_get(data, "Temperature") != NULL)
  10321. {
  10322. ShmOCPP16Data->TcciCustomData.WeatherInfo.temperature = json_object_get_double(json_object_object_get(data,"Temperature"));
  10323. }
  10324. else
  10325. {
  10326. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  10327. json_object_object_add(response, "data", json_object_new_string("temperature data can not get."));
  10328. }
  10329. if(strcmp(json_object_get_string(json_object_object_get(response,"status")),"Accepted")==0)
  10330. {
  10331. ShmOCPP16Data->TcciCustomData.WeatherInfoReq = 1;
  10332. DEBUG_INFO("<<< ID_Weather_Info:{weather:%d, temperature:%.1f}\n",
  10333. ShmOCPP16Data->TcciCustomData.WeatherInfo.weatherId,
  10334. ShmOCPP16Data->TcciCustomData.WeatherInfo.temperature
  10335. );
  10336. }
  10337. }
  10338. else
  10339. {
  10340. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  10341. json_object_object_add(response, "data", json_object_new_string("weather_info content got something wrong."));
  10342. }
  10343. sprintf(message,"[%d,\"%s\",%s]",MESSAGE_TYPE_CALLRESULT, uuid, json_object_to_json_string_ext(response, JSON_C_TO_STRING_PLAIN));
  10344. json_object_put(response);
  10345. }
  10346. else if(strstr(tempmessageId, "ID_TriggerCreditReader") != NULL)
  10347. {
  10348. json_object *data;
  10349. data = json_tokener_parse(tempdata);
  10350. if(!is_error(data))
  10351. {
  10352. json_object_object_add(response, "status", json_object_new_string("Accepted"));
  10353. if(json_object_get_int(json_object_object_get(data, "ConnectorId")) > 0)
  10354. {
  10355. ShmOCPP16Data->TcciCustomData.TriggerReaderReq[json_object_get_int(json_object_object_get(data, "ConnectorId")) -1] = TRUE;
  10356. DEBUG_INFO("<<< ID_TriggerCreditReader:{ConnectorId: %d}\n", json_object_get_int(json_object_object_get(data, "ConnectorId")));
  10357. }
  10358. else
  10359. {
  10360. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  10361. json_object_object_add(response, "data", json_object_new_string("ConnectorId does not valid."));
  10362. }
  10363. }
  10364. else
  10365. {
  10366. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  10367. json_object_object_add(response, "data", json_object_new_string("charger_info content got something wrong."));
  10368. }
  10369. sprintf(message,"[%d,\"%s\",%s]",MESSAGE_TYPE_CALLRESULT, uuid, json_object_to_json_string_ext(response, JSON_C_TO_STRING_PLAIN));
  10370. json_object_put(response);
  10371. }
  10372. else if(strstr(tempmessageId, "ID_GetTxUserInfo") != NULL)
  10373. {
  10374. json_object *data;
  10375. data = json_tokener_parse(tempdata);
  10376. if(!is_error(data))
  10377. {
  10378. if((json_object_object_get(data, "ConnectorId") != NULL) && (json_object_object_get(data, "txId") != NULL))
  10379. {
  10380. int gun_index = json_object_get_int(json_object_object_get(data, "ConnectorId"))-1;
  10381. json_object_object_add(response, "status", json_object_new_string("Accepted"));
  10382. if(gun_index < gunTotalNumber)
  10383. {
  10384. if(ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId == json_object_get_int(json_object_object_get(data, "txId")))
  10385. {
  10386. json_object *responsedata = json_object_new_object();
  10387. json_object_object_add(responsedata, "txId", json_object_new_int(ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId));
  10388. json_object_object_add(responsedata, "ConnectorId", json_object_new_int(gun_index+1));
  10389. json_object_object_add(responsedata, "SerialNo", json_object_new_string((char*)ShmOCPP16Data->TcciCustomData.SerialNo[gun_index]));
  10390. json_object_object_add(responsedata, "StartTime", json_object_new_string((char*)ShmOCPP16Data->StartTransaction[gun_index].Timestamp));
  10391. json_object_object_add(responsedata, "VEMData", json_object_new_string((char*)ShmOCPP16Data->TcciCustomData.VEMData[gun_index]));
  10392. json_object_object_add(response, "data", json_object_new_string(json_object_to_json_string_ext(responsedata, JSON_C_TO_STRING_PLAIN)));
  10393. }
  10394. else
  10395. {
  10396. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  10397. json_object_object_add(response, "data", json_object_new_string("txId doesn't match the current transactionId."));
  10398. }
  10399. }
  10400. else
  10401. {
  10402. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  10403. json_object_object_add(response, "data", json_object_new_string("ConnectorId is invalid."));
  10404. }
  10405. }
  10406. else
  10407. {
  10408. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  10409. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  10410. }
  10411. }
  10412. else
  10413. {
  10414. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  10415. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  10416. }
  10417. sprintf(message,"[%d,\"%s\",%s]",MESSAGE_TYPE_CALLRESULT, uuid, json_object_to_json_string_ext(response, JSON_C_TO_STRING_PLAIN));
  10418. json_object_put(response);
  10419. }
  10420. else
  10421. {
  10422. // Can not find valid message id
  10423. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\",\"data\":\"vendorId-%s messageId-%s data-%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, "UnknownMessageId", tempvendorId, tempmessageId, tempdata);
  10424. }
  10425. }
  10426. else
  10427. {
  10428. // Payload is null
  10429. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\",\"data\":\"{}\"}]",MESSAGE_TYPE_CALLRESULT, uuid, "UnknownMessageId");
  10430. }
  10431. LWS_Send(message);
  10432. return result;
  10433. }
  10434. int handleGetCompositeScheduleRequest(char *uuid, char *payload)
  10435. {
  10436. mtrace();
  10437. int result = FAIL;
  10438. int connectorIdInt, durationInt;
  10439. char chargingRateUnitStr[4]={0};
  10440. char comfirmstr[20];
  10441. int confirmPeriods = 0;
  10442. DEBUG_INFO("handleGetCompositeScheduleRequest...\n");
  10443. json_object *GetCompositeSchedule;
  10444. GetCompositeSchedule = json_tokener_parse(payload);
  10445. if(!is_error(GetCompositeSchedule))
  10446. {
  10447. // Required data
  10448. if(json_object_object_get(GetCompositeSchedule, "connectorId") != NULL)
  10449. connectorIdInt = json_object_get_int(json_object_object_get(GetCompositeSchedule, "connectorId"));
  10450. else
  10451. connectorIdInt = -1;
  10452. if(json_object_object_get(GetCompositeSchedule, "duration"))
  10453. durationInt = json_object_get_int(json_object_object_get(GetCompositeSchedule, "duration"));
  10454. else
  10455. durationInt = 86400;
  10456. // Optional data
  10457. if(json_object_object_get(GetCompositeSchedule, "chargingRateUnit") != NULL)
  10458. sprintf((char*)chargingRateUnitStr, "%s", json_object_get_string(json_object_object_get(GetCompositeSchedule, "chargingRateUnit")));
  10459. }
  10460. json_object_put(GetCompositeSchedule);
  10461. memset(ShmOCPP16Data->GetCompositeSchedule, 0, sizeof(struct StructChargingSchedulePeriod)*gunTotalNumber);
  10462. if((connectorIdInt == 0) ||
  10463. ((connectorIdInt > 0) && ((connectorIdInt -1) < gunTotalNumber)))
  10464. {
  10465. int gun_index = (connectorIdInt==0?0:connectorIdInt-1);
  10466. struct StructChargingProfile tmpProfile[1];
  10467. if(strstr(chargingRateUnitStr, "W") != NULL)
  10468. checkCompositeSchedule(connectorIdInt, durationInt, &tmpProfile[0], FALSE);
  10469. else
  10470. checkCompositeSchedule(connectorIdInt, durationInt, &tmpProfile[0], TRUE);
  10471. for(int idx=0;idx<ARRAY_SIZE(ShmOCPP16Data->GetCompositeSchedule[gun_index].ResponseChargingSchedule.ChargingSchedulePeriod);idx++)
  10472. {
  10473. DEBUG_INFO("Smart Period-%02d start: %d\n", idx, tmpProfile[0].ChargingSchedule.ChargingSchedulePeriod[idx].StartPeriod);
  10474. DEBUG_INFO("Smart Period-%02d limit: %f\n", idx, tmpProfile[0].ChargingSchedule.ChargingSchedulePeriod[idx].Limit);
  10475. }
  10476. ShmOCPP16Data->GetCompositeSchedule[gun_index].ResponseConnectorId = connectorIdInt;
  10477. memcpy(&ShmOCPP16Data->GetCompositeSchedule[gun_index].ResponseChargingSchedule, &tmpProfile[0].ChargingSchedule, sizeof(struct StructChargingSchedule));
  10478. memcpy(&ShmOCPP16Data->GetCompositeSchedule[gun_index].ResponseScheduleStart ,&tmpProfile[0].ChargingSchedule.StartSchedule, ARRAY_SIZE(tmpProfile[0].ChargingSchedule.StartSchedule));
  10479. for(int idx=0;idx<ARRAY_SIZE(ShmOCPP16Data->GetCompositeSchedule[gun_index].ResponseChargingSchedule.ChargingSchedulePeriod);idx++)
  10480. {
  10481. DEBUG_INFO("Composite Period-%02d start: %d\n", idx, ShmOCPP16Data->GetCompositeSchedule[gun_index].ResponseChargingSchedule.ChargingSchedulePeriod[idx].StartPeriod);
  10482. DEBUG_INFO("Composite Period-%02d limit: %f\n", idx, ShmOCPP16Data->GetCompositeSchedule[gun_index].ResponseChargingSchedule.ChargingSchedulePeriod[idx].Limit);
  10483. if((ShmOCPP16Data->GetCompositeSchedule[gun_index].ResponseChargingSchedule.ChargingSchedulePeriod[idx].StartPeriod==0) &&
  10484. (ShmOCPP16Data->GetCompositeSchedule[gun_index].ResponseChargingSchedule.ChargingSchedulePeriod[idx].Limit==0) &&
  10485. (idx<(ARRAY_SIZE(ShmOCPP16Data->GetCompositeSchedule[gun_index].ResponseChargingSchedule.ChargingSchedulePeriod)-1)?(ShmOCPP16Data->GetCompositeSchedule[gun_index].ResponseChargingSchedule.ChargingSchedulePeriod[idx+1].StartPeriod==0):TRUE))
  10486. {
  10487. confirmPeriods = idx;
  10488. break;
  10489. }
  10490. }
  10491. if((confirmPeriods == 0) && (tmpProfile[0].ChargingProfileId > 0))
  10492. {
  10493. confirmPeriods += 1;
  10494. }
  10495. sprintf(comfirmstr, "%s", GetCompositeScheduleStatusStr[GetCompositeScheduleStatus_Accepted] );
  10496. }
  10497. else
  10498. {
  10499. sprintf(comfirmstr, "%s", GetCompositeScheduleStatusStr[GetCompositeScheduleStatus_Rejected] );
  10500. }
  10501. sendGetCompositeScheduleConfirmation(uuid, comfirmstr, connectorIdInt, confirmPeriods);
  10502. return result;
  10503. }
  10504. int handleGetConfigurationRequest(char *uuid, char *payload)
  10505. {
  10506. mtrace();
  10507. int result = FAIL;
  10508. int MaxKeySupported = 0;
  10509. int n_keys = 0;
  10510. char requestKey[GetConfigurationMaxKeysNUM][50]={0};
  10511. DEBUG_INFO("handleGetConfigurationRequest...\n");
  10512. json_object *GetConfiguration;
  10513. GetConfiguration = json_tokener_parse(payload);
  10514. if(!is_error(GetConfiguration))
  10515. {
  10516. // Optional data
  10517. if(json_object_object_get(GetConfiguration, "key") != NULL)
  10518. {
  10519. for(int idx=0;idx<json_object_array_length(json_object_object_get(GetConfiguration, "key"));idx++)
  10520. {
  10521. sprintf((char*)requestKey[idx], "%s", json_object_get_string(json_object_array_get_idx(json_object_object_get(GetConfiguration, "key"), idx)));
  10522. n_keys = idx + 1;
  10523. }
  10524. }
  10525. }
  10526. json_object_put(GetConfiguration);
  10527. UnknownKeynum = 0;
  10528. memset( (void *)unknownkey, 0, sizeof(unknownkey));
  10529. MaxKeySupported = GetConfigurationMaxKeysNUM;
  10530. memset(ShmOCPP16Data->GetConfiguration.Key, 0 ,sizeof(struct StructConfigurationKeyItems)*MaxKeySupported);
  10531. memset(ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey, 0, sizeof(struct StructConfigurationKey)*MaxKeySupported);
  10532. if(n_keys != 0)
  10533. {
  10534. for(int i=0;i<n_keys;i++)
  10535. {
  10536. getKeyValue(requestKey[i]);
  10537. }
  10538. }
  10539. else
  10540. {
  10541. DEBUG_INFO("There is no key in Message, get all configuration\n");
  10542. getKeyValue("");
  10543. }
  10544. processUnkownKey();
  10545. sendGetConfigurationConfirmation(uuid);
  10546. return result;
  10547. }
  10548. static char fnamePlusPath[100]={0};
  10549. static char fnamePWithNoPath[60]={0};
  10550. void checkUploadLog(void)
  10551. {
  10552. FILE *fp;
  10553. /* Open the command for reading. */
  10554. fp = popen("find /mnt/ -type f -name \"*.zip\" |xargs ls -t", "r");
  10555. if (fp == NULL) {
  10556. DEBUG_WARN("Failed to run command\n" );
  10557. exit(1);
  10558. }
  10559. int ftppathlen = 0;
  10560. memset(fnamePlusPath, 0, ARRAY_SIZE(fnamePlusPath));
  10561. int i = 0;
  10562. /* Read the output a line at a time - output it. */
  10563. while (fgets(fnamePlusPath, sizeof(fnamePlusPath), fp) != NULL) {
  10564. if(i==0)
  10565. {
  10566. ftppathlen = strlen(fnamePlusPath);
  10567. DEBUG_INFO("%s\n", fnamePlusPath);
  10568. fnamePlusPath[ftppathlen]='\0';
  10569. break;
  10570. }
  10571. i= i+1;
  10572. }
  10573. /* close */
  10574. pclose(fp);
  10575. for(int k=0; k< ARRAY_SIZE(fnamePlusPath); k++)
  10576. {
  10577. if((fnamePlusPath[k]=='\n') || (fnamePlusPath[k]=='\r'))
  10578. {
  10579. fnamePlusPath[k]='\0';
  10580. }
  10581. }
  10582. i=1;
  10583. //char fname[60]={0};
  10584. while(i < ftppathlen)
  10585. {
  10586. int len=ftppathlen-i;
  10587. if(fnamePlusPath[len]== 47) // '/' ascll code: 47
  10588. {
  10589. DEBUG_INFO("compare '/' all right\n");
  10590. break;
  10591. }
  10592. i=i+1;
  10593. }
  10594. memset(fnamePWithNoPath, 0, ARRAY_SIZE(fnamePWithNoPath));
  10595. strncpy(fnamePWithNoPath, fnamePlusPath+(ftppathlen-i+1), i+1);
  10596. fnamePWithNoPath[i+1] = '\0';
  10597. for(int j=0; j< ARRAY_SIZE(fnamePWithNoPath); j++)
  10598. {
  10599. if((fnamePWithNoPath[j]=='\n') || (fnamePWithNoPath[j]=='r'))
  10600. {
  10601. fnamePWithNoPath[j]='\0';
  10602. }
  10603. }
  10604. FILE* fp1 = fopen(fnamePlusPath, "r");
  10605. if (fp1)
  10606. {
  10607. DEBUG_INFO("testfuc : fnamePlusPath=%s exist.\n", fnamePlusPath);
  10608. // file exists
  10609. fclose(fp1);
  10610. }
  10611. else
  10612. {
  10613. // file doesn't exist
  10614. DEBUG_WARN("testfuc : fnamePlusPath=%s not exist!\n", fnamePlusPath);
  10615. }
  10616. }
  10617. int handleGetDiagnosticsRequest(char *uuid, char *payload)
  10618. {
  10619. mtrace();
  10620. int result = FAIL;
  10621. time_t CurrentTime;
  10622. struct tm *tm;
  10623. pthread_t th_Status;
  10624. CurrentTime = time(NULL);
  10625. tm = localtime(&CurrentTime);
  10626. memset(ShmOCPP16Data->GetDiagnostics.ResponseFileName, 0x00, ARRAY_SIZE(ShmOCPP16Data->GetDiagnostics.ResponseFileName));
  10627. 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);
  10628. sendGetDiagnosticsConfirmation(uuid, (char*)ShmOCPP16Data->GetDiagnostics.ResponseFileName);
  10629. if(!interLock.isGetDiagnosticGoing)
  10630. {
  10631. interLock.isGetDiagnosticGoing = 1;
  10632. pthread_create(&th_Status, NULL, GetDiagnosticsProcess, stringtrimspace(payload));
  10633. sleep(1);
  10634. }
  10635. else
  10636. DEBUG_WARN("Other GetDiagnostic request on going.\n");
  10637. return result;
  10638. }
  10639. void* GetDiagnosticsProcess(void* data)
  10640. {
  10641. pthread_detach(pthread_self());
  10642. mtrace();
  10643. int retriesInt=0, retryIntervalInt=0;
  10644. char locationstr[1024]={0}, startTimestr[30]={0}, stopTimestr[30]={0} ;
  10645. 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};
  10646. int port=0;
  10647. int isSuccess = FALSE;
  10648. char cmdBuf[2048];
  10649. struct tm *tmNow;
  10650. time_t CurrentTime;
  10651. struct tm tmStart;
  10652. struct tm tmStop;
  10653. CurrentTime = time(NULL);
  10654. tmNow=localtime(&CurrentTime);
  10655. uint16_t targetYear, targetMonth;
  10656. json_object *GetDiagnostics;
  10657. DEBUG_INFO("GetDiagnosticsProcess...\n");
  10658. GetDiagnostics = json_tokener_parse(data);
  10659. if(!is_error(GetDiagnostics))
  10660. {
  10661. // Required data
  10662. if(json_object_object_get(GetDiagnostics, "location") != NULL)
  10663. sprintf(locationstr, "%s", json_object_get_string(json_object_object_get(GetDiagnostics, "location")));
  10664. // Optional data
  10665. if(json_object_object_get(GetDiagnostics, "retries") != NULL)
  10666. retriesInt = json_object_get_int(json_object_object_get(GetDiagnostics, "retries"));
  10667. else
  10668. retriesInt = 3; // If this field is not present, it is left to Charge Point to decide how many times it wants to retry.
  10669. if(json_object_object_get(GetDiagnostics, "retryInterval") != NULL)
  10670. retryIntervalInt = json_object_get_int(json_object_object_get(GetDiagnostics, "retryInterval"));
  10671. else
  10672. retryIntervalInt = 30;
  10673. if(json_object_object_get(GetDiagnostics, "startTime") != NULL)
  10674. sprintf(startTimestr, "%s", json_object_get_string(json_object_object_get(GetDiagnostics, "startTime")));
  10675. if(json_object_object_get(GetDiagnostics, "stopTime") != NULL)
  10676. sprintf(stopTimestr, "%s", json_object_get_string(json_object_object_get(GetDiagnostics, "stopTime")));
  10677. }
  10678. json_object_put(GetDiagnostics);
  10679. // Pack log to compress file
  10680. 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) &&
  10681. (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))
  10682. {
  10683. // Pack system log
  10684. memset(cmdBuf, 0x00, ARRAY_SIZE(cmdBuf));
  10685. sprintf(cmdBuf, "exec zip -9 --password %04d%02d%s /mnt/system.zip", tmNow->tm_year+1900, tmNow->tm_mon+1, ShmSysConfigAndInfo->SysConfig.SerialNumber);
  10686. targetYear = tmStart.tm_year;
  10687. targetMonth = tmStart.tm_mon;
  10688. do
  10689. {
  10690. sprintf(cmdBuf, "%s /Storage/SystemLog/*%04d*%02d*", cmdBuf, targetYear, targetMonth);
  10691. sprintf(cmdBuf, "%s /Storage/OCPP/*%04d*%02d*SystemLog*", cmdBuf, targetYear, targetMonth);
  10692. if(targetMonth+1>=13)
  10693. {
  10694. targetYear += 1;
  10695. targetMonth = 1;
  10696. }
  10697. else
  10698. {
  10699. targetMonth += 1;
  10700. }
  10701. }while((targetYear < (tmNow->tm_year+1900)) ||
  10702. ((targetYear <= (tmNow->tm_year+1900)) && (targetMonth <= (tmNow->tm_mon+1))));
  10703. sprintf(cmdBuf, "%s /Storage/CCS*.zip", cmdBuf);
  10704. sprintf(cmdBuf, "%s /Storage/OCPP/*.db", cmdBuf);
  10705. system(cmdBuf);
  10706. // Pack charging & event log
  10707. memset(cmdBuf, 0x00, ARRAY_SIZE(cmdBuf));
  10708. sprintf(cmdBuf, "exec zip -9 /mnt/charging_event.zip");
  10709. targetYear = tmStart.tm_year;
  10710. targetMonth = tmStart.tm_mon;
  10711. do
  10712. {
  10713. sprintf(cmdBuf, "%s /Storage/EventLog/*%04d*%02d*", cmdBuf, targetYear, targetMonth);
  10714. sprintf(cmdBuf, "%s /Storage/OCPP/*%04d*%02d*OcppMessageLog*", cmdBuf, targetYear, targetMonth);
  10715. if(targetMonth+1>=13)
  10716. {
  10717. targetYear += 1;
  10718. targetMonth = 1;
  10719. }
  10720. else
  10721. {
  10722. targetMonth += 1;
  10723. }
  10724. }while((targetYear < (tmNow->tm_year+1900)) ||
  10725. ((targetYear <= (tmNow->tm_year+1900)) && (targetMonth <= (tmNow->tm_mon+1))));
  10726. sprintf(cmdBuf, "%s /Storage/ChargeLog/*.db", cmdBuf);
  10727. sprintf(cmdBuf, "%s /Storage/EventLog/*.db", cmdBuf);
  10728. system(cmdBuf);
  10729. // Combine log file
  10730. system("exec zip -9 /mnt/log.zip /mnt/system.zip /mnt/charging_event.zip");
  10731. system("exec rm -f /mnt/system.zip /mnt/charging_event.zip");
  10732. }
  10733. else
  10734. {
  10735. system("exec /root/logPackTools 'log' 6");
  10736. }
  10737. sprintf(cmdBuf, "mv /mnt/log.zip /mnt/%s", ShmOCPP16Data->GetDiagnostics.ResponseFileName);
  10738. system(cmdBuf);
  10739. checkUploadLog();
  10740. //****************location*******************/
  10741. if(strcmp(locationstr,"")==0)
  10742. {
  10743. DEBUG_INFO("location is <Empty>!\n");
  10744. sprintf((char*)ShmOCPP16Data->DiagnosticsStatusNotification.Status, "%s", DiagnosticsStatusStr[DiagnosticsStatus_UploadFailed]);
  10745. ShmOCPP16Data->SpMsg.bits.DiagnosticsStatusNotificationReq = 1;
  10746. goto end;
  10747. }
  10748. memset(protocol, 0, ARRAY_SIZE(protocol));
  10749. memset(user, 0, ARRAY_SIZE(user) );
  10750. memset(password, 0, ARRAY_SIZE(password));
  10751. memset(host, 0, ARRAY_SIZE(host));
  10752. memset(path, 0, ARRAY_SIZE(path));
  10753. memset(ftppath, 0, ARRAY_SIZE(ftppath));
  10754. memset(host1, 0, ARRAY_SIZE(host1));
  10755. memset(path1, 0, ARRAY_SIZE(path1));
  10756. /*location: ftp://user:password@host:port/path*/
  10757. //DEBUG_INFO("fnamePlusPath =%s\n",fnamePlusPath);
  10758. if((access(fnamePlusPath,F_OK))!=-1)
  10759. {
  10760. DEBUG_INFO("fnamePlusPath exist.\n");
  10761. }
  10762. else
  10763. {
  10764. DEBUG_INFO("fnamePlusPath not exist!\n");
  10765. sprintf((char*)ShmOCPP16Data->DiagnosticsStatusNotification.Status, "%s", DiagnosticsStatusStr[DiagnosticsStatus_UploadFailed]);
  10766. ShmOCPP16Data->SpMsg.bits.DiagnosticsStatusNotificationReq = 1;
  10767. goto end;
  10768. }
  10769. if(strchr(locationstr,'@')==NULL)
  10770. {
  10771. sscanf(locationstr,
  10772. "%[^:]:%*2[/]%[^:]:%i/%[a-zA-Z0-9._/-]",
  10773. protocol, host, &port, path);
  10774. strcpy(user,"anonymous");
  10775. strcpy(password,"");
  10776. }
  10777. else
  10778. {
  10779. //DEBUG_INFO("pch=%s\n", pch);
  10780. sscanf(locationstr,"%[^:]:%*2[/]%[^:]:%[^@]@%[^:]:%i/%199[^\n]",
  10781. protocol, user, password, host, &port, path);
  10782. }
  10783. if((strcmp(protocol,"ftp")!=0)&&(strcmp(protocol,"http")!=0)&&(strcmp(protocol,"https")!=0))
  10784. {
  10785. DEBUG_INFO("protocol is not ftp/http ! \n");
  10786. sprintf((char*)ShmOCPP16Data->DiagnosticsStatusNotification.Status, "%s", DiagnosticsStatusStr[DiagnosticsStatus_UploadFailed]);
  10787. ShmOCPP16Data->SpMsg.bits.DiagnosticsStatusNotificationReq = 1;
  10788. goto end;
  10789. }
  10790. if(strncmp(locationstr,"http", 4) == 0)
  10791. {
  10792. sscanf(locationstr,"%[^:]:%*2[/]%[^/]/%199[^\n]", protocol, host, path);
  10793. sprintf(ftppath,"/%s", path);
  10794. do
  10795. {
  10796. sprintf((char*)ShmOCPP16Data->DiagnosticsStatusNotification.Status, "%s", DiagnosticsStatusStr[DiagnosticsStatus_Uploading]);
  10797. ShmOCPP16Data->SpMsg.bits.DiagnosticsStatusNotificationReq = 1;
  10798. sleep(3);
  10799. isSuccess = httpUploadFile(host, ftppath, fnamePlusPath, locationstr);
  10800. if(!isSuccess)
  10801. {
  10802. DEBUG_INFO("Diagnostics fail.\n");
  10803. sprintf((char*)ShmOCPP16Data->DiagnosticsStatusNotification.Status, "%s", DiagnosticsStatusStr[DiagnosticsStatus_UploadFailed]);
  10804. ShmOCPP16Data->SpMsg.bits.DiagnosticsStatusNotificationReq = 1;
  10805. sleep(retryIntervalInt);
  10806. }
  10807. else
  10808. {
  10809. DEBUG_INFO("sendDiagnosticsStatusNotificationRequest Uploaded\n");
  10810. sprintf((char*)ShmOCPP16Data->DiagnosticsStatusNotification.Status, "%s", DiagnosticsStatusStr[DiagnosticsStatus_Uploaded]);
  10811. ShmOCPP16Data->SpMsg.bits.DiagnosticsStatusNotificationReq = 1;
  10812. }
  10813. retriesInt--;
  10814. }while((isSuccess == 0)&&(retriesInt >= 0));
  10815. }
  10816. else
  10817. {
  10818. sscanf(host,"%[^/]%s",host1, path1);
  10819. if(strlen(path) > 0)
  10820. sprintf(ftppath,"/%s", path);
  10821. else
  10822. sprintf(ftppath,"/%s", path1);
  10823. int ftppathlen=strlen(ftppath);
  10824. int i=1;
  10825. char filenametemp[50];
  10826. while(i < ftppathlen)
  10827. {
  10828. int len=ftppathlen-i;
  10829. if(ftppath[len]== 47) // '/' ascll code: 47
  10830. {
  10831. DEBUG_INFO("find '/' all right\n");
  10832. break;
  10833. }
  10834. i=i+1;
  10835. }
  10836. memset(filenametemp, 0, ARRAY_SIZE(filenametemp));
  10837. strncpy(filenametemp, ftppath+(ftppathlen-i+1), i+1);
  10838. filenametemp[i+1] = 0;
  10839. if(port == 0)
  10840. port = 21;
  10841. do
  10842. {
  10843. sprintf((char*)ShmOCPP16Data->DiagnosticsStatusNotification.Status, "%s", DiagnosticsStatusStr[DiagnosticsStatus_Uploading]);
  10844. ShmOCPP16Data->SpMsg.bits.DiagnosticsStatusNotificationReq = 1;
  10845. sleep(3);
  10846. isSuccess = ftpUploadFile(host1, user, password, port, ftppath, fnamePlusPath, fnamePWithNoPath);
  10847. if(!isSuccess)
  10848. {
  10849. DEBUG_INFO("Diagnostics fail.\n");
  10850. sprintf((char*)ShmOCPP16Data->DiagnosticsStatusNotification.Status, "%s", DiagnosticsStatusStr[DiagnosticsStatus_UploadFailed]);
  10851. ShmOCPP16Data->SpMsg.bits.DiagnosticsStatusNotificationReq = 1;
  10852. sleep(retryIntervalInt);
  10853. }
  10854. else
  10855. {
  10856. DEBUG_INFO("sendDiagnosticsStatusNotificationRequest Uploaded\n");
  10857. sprintf((char*)ShmOCPP16Data->DiagnosticsStatusNotification.Status, "%s", DiagnosticsStatusStr[DiagnosticsStatus_Uploaded]);
  10858. ShmOCPP16Data->SpMsg.bits.DiagnosticsStatusNotificationReq = 1;
  10859. }
  10860. retriesInt--;
  10861. }while((!isSuccess)&&(retriesInt >= 0));
  10862. }
  10863. end:
  10864. system("rm -f /mnt/*");
  10865. sleep(5);
  10866. sprintf((char*)ShmOCPP16Data->DiagnosticsStatusNotification.Status, "%s", DiagnosticsStatusStr[DiagnosticsStatus_Idle]);
  10867. ShmOCPP16Data->SpMsg.bits.DiagnosticsStatusNotificationReq = 1;
  10868. interLock.isGetDiagnosticGoing = 0;
  10869. pthread_exit(NULL);
  10870. }
  10871. int handleGetLocalListVersionRequest(char *uuid, char *payload)
  10872. {
  10873. mtrace();
  10874. int result = FAIL;
  10875. DEBUG_INFO("handle GetLocalListVersionRequest\n");
  10876. if(strcmp((const char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "FALSE") == 0)
  10877. {
  10878. DEBUG_INFO("LocalAuthListEnabled is FALSE \n");
  10879. locallistVersion = -1;
  10880. }
  10881. else
  10882. {
  10883. DEBUG_INFO("handle GetLocalListVersionRequest OCPP_getListVerion \n");
  10884. locallistVersion = 0;
  10885. OCPP_getListVerion();
  10886. }
  10887. //from db.OCPP_getListVerion
  10888. ShmOCPP16Data->GetLocalListVersion.ResponseListVersion = locallistVersion;
  10889. //ShmOCPP16Data->MsMsg.bits.GetLocalListVersionReq = 1;
  10890. sendGetLocalListVersionConfirmation(uuid,"");
  10891. //ShmOCPP16Data->MsMsg.bits.GetLocalListVersionConf = 1;
  10892. return result;
  10893. }
  10894. int handleRemoteStartRequest(char *uuid, char *payload)
  10895. {
  10896. mtrace();
  10897. int result = PASS;
  10898. int connectorIdInt=-1;
  10899. int tempIndex = 0;
  10900. char comfirmstr[20]={0};
  10901. char cmdBuf[512];
  10902. json_object *RemoteStartTransaction;
  10903. FILE *fp;
  10904. DEBUG_INFO("handleRemoteStartRequest ...\n");
  10905. if(server_pending == TRUE)
  10906. {
  10907. result = FAIL;
  10908. }
  10909. RemoteStartTransaction = json_tokener_parse(payload);
  10910. if(!is_error(RemoteStartTransaction))
  10911. {
  10912. if(json_object_object_get(RemoteStartTransaction, "connectorId") != NULL)
  10913. {
  10914. connectorIdInt = json_object_get_int(json_object_object_get(RemoteStartTransaction, "connectorId"));
  10915. }
  10916. else
  10917. {
  10918. for(uint8_t gun_index=0;gun_index<gunTotalNumber;gun_index++)
  10919. {
  10920. if(!cpinitateMsg.bits[gun_index].isOnCharging && (strstr((char*)ShmOCPP16Data->StatusNotification[gun_index].Status, "Preparing") != NULL))
  10921. {
  10922. connectorIdInt = (gun_index+1);
  10923. DEBUG_INFO("Remote start without connectorId but detect connector-%02d connected ready to start.\n", connectorIdInt);
  10924. break;
  10925. }
  10926. }
  10927. }
  10928. if(connectorIdInt == 0)
  10929. {
  10930. DEBUG_WARN("Connector id shall not equal 0.\n");
  10931. result = FAIL;
  10932. }
  10933. else if(connectorIdInt == -1)
  10934. {
  10935. DEBUG_INFO("Connector id does not specific.\n");
  10936. for(uint8_t gun_index=0;gun_index<gunTotalNumber;gun_index++)
  10937. {
  10938. memset(&ShmOCPP16Data->RemoteStartTransaction[gun_index], 0x00, sizeof(struct StructRemoteStartTransaction));
  10939. // Required data
  10940. sprintf((char*)ShmOCPP16Data->RemoteStartTransaction[gun_index].IdTag, "%s", json_object_get_string(json_object_object_get(RemoteStartTransaction, "idTag")));
  10941. // Optional data
  10942. if(json_object_object_get(RemoteStartTransaction, "chargingProfile") != NULL)
  10943. {
  10944. ShmOCPP16Data->RemoteStartTransaction[gun_index].ChargingProfile.ChargingProfileId = json_object_get_int(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingProfileId"));
  10945. ShmOCPP16Data->RemoteStartTransaction[gun_index].ChargingProfile.StackLevel = json_object_get_int(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "stackLevel"));
  10946. sprintf((char*)ShmOCPP16Data->RemoteStartTransaction[gun_index].ChargingProfile.ChargingProfilePurpose, "%s", json_object_get_string(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingProfilePurpose")));
  10947. sprintf((char*)ShmOCPP16Data->RemoteStartTransaction[gun_index].ChargingProfile.ChargingProfileKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingProfileKind")));
  10948. if(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "transactionId") != NULL)
  10949. ShmOCPP16Data->RemoteStartTransaction[gun_index].ChargingProfile.TransactionId = json_object_get_int(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "transactionId"));
  10950. if(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "recurrencyKind") != NULL)
  10951. sprintf((char*)ShmOCPP16Data->RemoteStartTransaction[gun_index].ChargingProfile.RecurrencyKind , "%s", json_object_get_string(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "recurrencyKind")));
  10952. if(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "validFrom") != NULL)
  10953. sprintf((char*)ShmOCPP16Data->RemoteStartTransaction[gun_index].ChargingProfile.ValidFrom , "%s", json_object_get_string(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "validFrom")));
  10954. if(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "validTo") != NULL)
  10955. sprintf((char*)ShmOCPP16Data->RemoteStartTransaction[gun_index].ChargingProfile.ValidTo , "%s", json_object_get_string(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "validTo")));
  10956. if(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingSchedule") != NULL)
  10957. {
  10958. 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")));
  10959. if(json_object_object_get(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingSchedule"), "duration") != NULL)
  10960. 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"));
  10961. if(json_object_object_get(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingSchedule"), "minChargingRate") != NULL)
  10962. 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"));
  10963. if(json_object_object_get(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingSchedule"), "startSchedule") != NULL)
  10964. 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")));
  10965. if(json_object_object_get(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingSchedule"), "chargingSchedulePeriod") != NULL)
  10966. {
  10967. 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++)
  10968. {
  10969. 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"));
  10970. 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"));
  10971. 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)
  10972. 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"));
  10973. }
  10974. }
  10975. }
  10976. }
  10977. else
  10978. {
  10979. ShmOCPP16Data->RemoteStartTransaction[gun_index].ChargingProfile.ChargingProfileId = -1;
  10980. }
  10981. }
  10982. }
  10983. else if(((0 < connectorIdInt) && (connectorIdInt <= gunTotalNumber)))
  10984. {
  10985. DEBUG_INFO("Connector id: %d\n", connectorIdInt);
  10986. memset(&ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1], 0x00, sizeof(struct StructRemoteStartTransaction));
  10987. // Required data
  10988. sprintf((char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag, "%s", json_object_get_string(json_object_object_get(RemoteStartTransaction, "idTag")));
  10989. // Optional data
  10990. if(json_object_object_get(RemoteStartTransaction, "chargingProfile") != NULL)
  10991. {
  10992. ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingProfileId = json_object_get_int(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingProfileId"));
  10993. ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.StackLevel = json_object_get_int(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "stackLevel"));
  10994. sprintf((char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingProfilePurpose, "%s", json_object_get_string(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingProfilePurpose")));
  10995. sprintf((char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingProfileKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingProfileKind")));
  10996. if(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "transactionId") != NULL)
  10997. ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.TransactionId = json_object_get_int(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "transactionId"));
  10998. if(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "recurrencyKind") != NULL)
  10999. sprintf((char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.RecurrencyKind , "%s", json_object_get_string(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "recurrencyKind")));
  11000. if(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "validFrom") != NULL)
  11001. sprintf((char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ValidFrom , "%s", json_object_get_string(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "validFrom")));
  11002. if(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "validTo") != NULL)
  11003. sprintf((char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ValidTo , "%s", json_object_get_string(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "validTo")));
  11004. if(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingSchedule") != NULL)
  11005. {
  11006. 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")));
  11007. if(json_object_object_get(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingSchedule"), "duration") != NULL)
  11008. 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"));
  11009. if(json_object_object_get(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingSchedule"), "minChargingRate") != NULL)
  11010. 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"));
  11011. if(json_object_object_get(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingSchedule"), "startSchedule") != NULL)
  11012. 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")));
  11013. if(json_object_object_get(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingSchedule"), "chargingSchedulePeriod") != NULL)
  11014. {
  11015. 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++)
  11016. {
  11017. 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"));
  11018. 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"));
  11019. 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)
  11020. 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"));
  11021. }
  11022. }
  11023. }
  11024. }
  11025. else
  11026. {
  11027. ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingProfileId = -1;
  11028. }
  11029. }
  11030. else
  11031. {
  11032. DEBUG_WARN("Connector id is over maximun value.\n");
  11033. result = FAIL;
  11034. }
  11035. }
  11036. if(result == PASS)
  11037. {
  11038. if(connectorIdInt > 0)
  11039. {
  11040. //check Transaction active
  11041. if(gunType[connectorIdInt -1] == GUN_TYPE_CHAdeMO)
  11042. {
  11043. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  11044. {
  11045. tempIndex = ((connectorIdInt -1) == 2) ? 1: 0;
  11046. }
  11047. else
  11048. {
  11049. tempIndex = connectorIdInt -1;
  11050. }
  11051. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  11052. {
  11053. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  11054. {
  11055. if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ReservationId != -1) &&
  11056. (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ReservationId >= 0) &&
  11057. (strcmp((const char *)ShmOCPP16Data->ReserveNow[index].IdTag, (char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag) == 0))
  11058. {
  11059. //Reserved
  11060. DEBUG_INFO("CHAdeMO connector already reserved and idTag match.\n");
  11061. }
  11062. else if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ReservationId != -1) &&
  11063. (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ReservationId >= 0) &&
  11064. (strcmp((const char *)ShmOCPP16Data->ReserveNow[index].IdTag, (char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag) != 0))
  11065. {
  11066. //Reserved
  11067. DEBUG_INFO("CHAdeMO connector already reserved and idTag does not match.\n");
  11068. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  11069. goto end;
  11070. }
  11071. else
  11072. {
  11073. if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_IDLE) || ShmOCPP16Data->MsMsg.bits.isRemoteStartWaitReq)
  11074. {
  11075. DEBUG_WARN("CHAdeMO connector not allow start cause busy.\n");
  11076. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  11077. goto end;
  11078. }
  11079. }//END FOR ELSE
  11080. }
  11081. }// END FOR CHAdeMO_QUANTITY
  11082. }
  11083. else if(gunType[connectorIdInt -1] == GUN_TYPE_CCS)
  11084. {
  11085. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  11086. {
  11087. tempIndex = ((connectorIdInt -1) == 2) ? 1: 0;
  11088. }
  11089. else
  11090. {
  11091. tempIndex = connectorIdInt -1;
  11092. }
  11093. for (int index = 0; index < CCS_QUANTITY; index++)
  11094. {
  11095. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  11096. {
  11097. if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ReservationId != -1) &&
  11098. (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ReservationId >= 0) &&
  11099. (strcmp((const char *)ShmOCPP16Data->ReserveNow[index].IdTag, (char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag) == 0))
  11100. {
  11101. //Reserved
  11102. DEBUG_INFO("CCS connector already reserved and idTag match.\n");
  11103. }
  11104. else if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ReservationId != -1) &&
  11105. (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ReservationId >= 0) &&
  11106. (strcmp((const char *)ShmOCPP16Data->ReserveNow[index].IdTag, (char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag) != 0))
  11107. {
  11108. //Reserved
  11109. DEBUG_INFO("CCS connector already reserved and idTag does not match.\n");
  11110. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  11111. goto end;
  11112. }
  11113. else
  11114. {
  11115. if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_IDLE) || ShmOCPP16Data->MsMsg.bits.isRemoteStartWaitReq)
  11116. {
  11117. DEBUG_WARN("CCS connector not allow start cause busy.\n");
  11118. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  11119. goto end;
  11120. }
  11121. }// END FOR ELSE
  11122. }
  11123. }// END FOR CCS_QUANTITY
  11124. }
  11125. else if(gunType[connectorIdInt -1] == GUN_TYPE_GBT)
  11126. {
  11127. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  11128. {
  11129. tempIndex = ((connectorIdInt -1) == 2) ? 1: 0;
  11130. }
  11131. else
  11132. {
  11133. tempIndex = connectorIdInt -1;
  11134. }
  11135. for (int index = 0; index < GB_QUANTITY; index++)
  11136. {
  11137. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex )
  11138. {
  11139. if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ReservationId != -1) &&
  11140. (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ReservationId >= 0) &&
  11141. (strcmp((const char *)ShmOCPP16Data->ReserveNow[index].IdTag, (char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag) == 0))
  11142. {
  11143. //Reserved
  11144. DEBUG_INFO("GBT connector already reserved and idTag match.\n");
  11145. }
  11146. else if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ReservationId != -1) &&
  11147. (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ReservationId >= 0) &&
  11148. (strcmp((const char *)ShmOCPP16Data->ReserveNow[index].IdTag, (char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag) != 0))
  11149. {
  11150. //Reserved
  11151. DEBUG_INFO("GBT connector already reserved and idTag does not match.\n");
  11152. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  11153. goto end;
  11154. }
  11155. else
  11156. {
  11157. if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_IDLE) || ShmOCPP16Data->MsMsg.bits.isRemoteStartWaitReq)
  11158. {
  11159. DEBUG_WARN("GBT connector not allow start cause busy.\n");
  11160. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  11161. goto end;
  11162. }
  11163. }// END FOR ELSE
  11164. }
  11165. } // END FOR GB_QUANTITY
  11166. }
  11167. else if(gunType[connectorIdInt -1] == GUN_TYPE_DO)
  11168. {
  11169. tempIndex = connectorIdInt -1;
  11170. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  11171. {
  11172. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex )
  11173. {
  11174. if((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.ReservationId != -1) &&
  11175. (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.ReservationId >= 0) &&
  11176. (strcmp((const char *)ShmOCPP16Data->ReserveNow[index].IdTag, (char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag) == 0))
  11177. {
  11178. //Reserved
  11179. DEBUG_INFO("Dispenser connector already reserved and idTag match.\n");
  11180. }
  11181. else if((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.ReservationId != -1) &&
  11182. (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.ReservationId >= 0) &&
  11183. (strcmp((const char *)ShmOCPP16Data->ReserveNow[index].IdTag, (char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag) != 0))
  11184. {
  11185. //Reserved
  11186. DEBUG_INFO("Dispenser connector already reserved and idTag does not match.\n");
  11187. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  11188. goto end;
  11189. }
  11190. else
  11191. {
  11192. if((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus != SYS_MODE_IDLE) || ShmOCPP16Data->MsMsg.bits.isRemoteStartWaitReq)
  11193. {
  11194. DEBUG_WARN("Dispenser connector not allow start cause busy.\n");
  11195. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  11196. goto end;
  11197. }
  11198. }// END FOR ELSE
  11199. }
  11200. } // END FOR GB_QUANTITY
  11201. }
  11202. else
  11203. {
  11204. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D') // 'D' means DC
  11205. {
  11206. tempIndex = 2;
  11207. }
  11208. else
  11209. {
  11210. tempIndex = connectorIdInt -1;
  11211. }
  11212. for (int index = 0; index < AC_QUANTITY; index++)
  11213. {
  11214. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex )
  11215. {
  11216. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].ReservationId != -1) &&
  11217. (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].ReservationId >= 0) &&
  11218. (strcmp((const char *)ShmOCPP16Data->ReserveNow[index].IdTag, (char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag) == 0))
  11219. {
  11220. //Reserved
  11221. DEBUG_INFO("AC connector already reserved and idTag match.\n");
  11222. }
  11223. else if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].ReservationId != -1) &&
  11224. (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].ReservationId >= 0) &&
  11225. (strcmp((const char *)ShmOCPP16Data->ReserveNow[index].IdTag, (char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag) != 0))
  11226. {
  11227. //Reserved
  11228. DEBUG_INFO("AC connector already reserved and idTag does not match.\n");
  11229. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  11230. goto end;
  11231. }
  11232. else
  11233. {
  11234. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_IDLE) || ShmOCPP16Data->MsMsg.bits.isRemoteStartWaitReq)
  11235. {
  11236. DEBUG_WARN("AC connector not allow start cause busy.\n");
  11237. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  11238. goto end;
  11239. }
  11240. }//END FOR ELSE
  11241. }
  11242. }// END FOR AC_QUANTITY
  11243. }
  11244. if(ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingProfileId > -1)
  11245. {
  11246. if(strcmp((char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingProfilePurpose, ChargingProfilePurposeTypeStr[TxProfile]) == 0)
  11247. {
  11248. // Save profile to file
  11249. sprintf(cmdBuf, "rm -f /Storage/OCPP/TxProfile_%d.json", connectorIdInt);
  11250. system(cmdBuf);
  11251. sprintf(cmdBuf, "/Storage/OCPP/TxProfile_%d.json", connectorIdInt);
  11252. fp = fopen(cmdBuf, "w");
  11253. 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));
  11254. fclose(fp);
  11255. }
  11256. else
  11257. {
  11258. DEBUG_WARN("Profile purpose not TxProfile.\n");
  11259. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  11260. goto end;
  11261. }
  11262. }
  11263. ShmOCPP16Data->CsMsg.bits[connectorIdInt -1].RemoteStartTransactionReq = 1;
  11264. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Accepted]);
  11265. memset((char *)ShmOCPP16Data->StartTransaction[connectorIdInt -1].IdTag,0, 20);
  11266. strcpy((char *)ShmOCPP16Data->StartTransaction[connectorIdInt -1].IdTag, (char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag);
  11267. memset((char *)ShmOCPP16Data->StopTransaction[connectorIdInt -1].IdTag,0, 20);
  11268. strcpy((char *)ShmOCPP16Data->StopTransaction[connectorIdInt -1].IdTag, (char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag);
  11269. }
  11270. else
  11271. {
  11272. uint8_t isHasIdleConnector = FALSE;
  11273. for(uint8_t gun_index=0;gun_index<gunTotalNumber;gun_index++)
  11274. {
  11275. if(!cpinitateMsg.bits[gun_index].isOnCharging)
  11276. {
  11277. isHasIdleConnector = TRUE;
  11278. break;
  11279. }
  11280. }
  11281. if((isHasIdleConnector == TRUE) && !ShmOCPP16Data->MsMsg.bits.isRemoteStartWaitReq)
  11282. {
  11283. DEBUG_INFO("Start wait connector link to EV in %s seconds.\n", ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemData);
  11284. if(ShmOCPP16Data->RemoteStartTransaction[0].ChargingProfile.ChargingProfileId > -1)
  11285. {
  11286. if(strcmp((char*)ShmOCPP16Data->RemoteStartTransaction[0].ChargingProfile.ChargingProfilePurpose, ChargingProfilePurposeTypeStr[TxProfile]) == 0)
  11287. {
  11288. // Save profile to file
  11289. sprintf(cmdBuf, "rm -f /Storage/OCPP/TxProfile_Tmp.json");
  11290. system(cmdBuf);
  11291. sprintf(cmdBuf, "/Storage/OCPP/TxProfile_Tmp.json");
  11292. fp = fopen(cmdBuf, "w");
  11293. fprintf(fp, "{\"connectorId\":0,\"csChargingProfiles\":%s}\n", json_object_to_json_string_ext(json_object_object_get(RemoteStartTransaction, "chargingProfile"), JSON_C_TO_STRING_PLAIN));
  11294. fclose(fp);
  11295. refreshStartTimer(&clientTime.RemoteStartWait);
  11296. ShmOCPP16Data->MsMsg.bits.isRemoteStartWaitReq = 1;
  11297. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Accepted]);
  11298. }
  11299. else
  11300. {
  11301. DEBUG_WARN("Profile purpose not TxProfile.\n");
  11302. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  11303. }
  11304. }
  11305. else
  11306. {
  11307. refreshStartTimer(&clientTime.RemoteStartWait);
  11308. ShmOCPP16Data->MsMsg.bits.isRemoteStartWaitReq = 1;
  11309. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Accepted]);
  11310. }
  11311. }
  11312. else
  11313. {
  11314. DEBUG_INFO("There is not any connector is idle.\n");
  11315. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  11316. }
  11317. }
  11318. }
  11319. else
  11320. {
  11321. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  11322. }
  11323. end:
  11324. json_object_put(RemoteStartTransaction);
  11325. sendRemoteStartConfirmation(uuid, comfirmstr);
  11326. return result;
  11327. }
  11328. int handleRemoteStopTransactionRequest(char *uuid, char *payload)
  11329. {
  11330. mtrace();
  11331. int result = FAIL;
  11332. int match = FALSE;
  11333. int GunNO = 0;
  11334. int tempIndex = 0;
  11335. int transactionIdInt=0;
  11336. int transactionIdIsNULL= TRUE;
  11337. char comfirmstr[20];
  11338. json_object *RemoteStopTransaction;
  11339. //[2,"ff522854-0dea-436e-87ba-23a229269994","RemoteStopTransaction",{"transactionId":1373618380}]
  11340. DEBUG_INFO("handleRemoteStopTransactionRequest...\n");
  11341. if(server_pending == TRUE)
  11342. {
  11343. return 0;
  11344. }
  11345. RemoteStopTransaction = json_tokener_parse(payload);
  11346. if(!is_error(RemoteStopTransaction))
  11347. {
  11348. if(json_object_object_get(RemoteStopTransaction, "transactionId") != NULL)
  11349. {
  11350. transactionIdInt = json_object_get_int(json_object_object_get(RemoteStopTransaction, "transactionId"));
  11351. transactionIdIsNULL = FALSE;
  11352. }
  11353. }
  11354. json_object_put(RemoteStopTransaction);
  11355. if(transactionIdIsNULL == FALSE)
  11356. {
  11357. for(int gun_index=0;gun_index < gunTotalNumber;gun_index++)
  11358. {
  11359. if(ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId == transactionIdInt)
  11360. {
  11361. //check Transaction active
  11362. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  11363. {
  11364. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  11365. {
  11366. tempIndex = ((gun_index==2) ? 1: 0);
  11367. }
  11368. else
  11369. {
  11370. tempIndex = gun_index;
  11371. }
  11372. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  11373. {
  11374. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  11375. {
  11376. if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_TERMINATING)) // SYS_MODE_CHARGING, SYS_MODE_TERMINATING
  11377. {
  11378. match = TRUE;
  11379. GunNO = gun_index;
  11380. }
  11381. }
  11382. }// END FOR CHAdeMO_QUANTITY
  11383. }
  11384. else if(gunType[gun_index] == GUN_TYPE_CCS)
  11385. {
  11386. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  11387. {
  11388. tempIndex = ((gun_index==2) ? 1: 0);
  11389. }
  11390. else
  11391. {
  11392. tempIndex = gun_index;
  11393. }
  11394. for (int index = 0; index < CCS_QUANTITY; index++)
  11395. {
  11396. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  11397. {
  11398. if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_TERMINATING) ) // SYS_MODE_CHARGING, SYS_MODE_TERMINATING
  11399. {
  11400. match = TRUE;
  11401. GunNO = gun_index;
  11402. }
  11403. }
  11404. }// END FOR CCS_QUANTITY
  11405. }
  11406. else if(gunType[gun_index] == GUN_TYPE_GBT)
  11407. {
  11408. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  11409. {
  11410. tempIndex = ((gun_index==2) ? 1: 0);
  11411. }
  11412. else
  11413. {
  11414. tempIndex = gun_index;
  11415. }
  11416. for (int index = 0; index < GB_QUANTITY; index++)
  11417. {
  11418. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  11419. {
  11420. if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_TERMINATING)) // SYS_MODE_CHARGING, SYS_MODE_TERMINATING
  11421. {
  11422. match = TRUE;
  11423. GunNO = gun_index;
  11424. }
  11425. }
  11426. }// END FOR GB_QUANTITY
  11427. }
  11428. else if(gunType[gun_index] == GUN_TYPE_DO)
  11429. {
  11430. tempIndex = gun_index;
  11431. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  11432. {
  11433. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  11434. {
  11435. 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
  11436. {
  11437. match = TRUE;
  11438. GunNO = gun_index;
  11439. }
  11440. }
  11441. }// END FOR GB_QUANTITY
  11442. }
  11443. else
  11444. {
  11445. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D') // 'D' means DC
  11446. {
  11447. tempIndex = 2;
  11448. }
  11449. else
  11450. {
  11451. tempIndex = gun_index;
  11452. }
  11453. for (int index = 0; index < AC_QUANTITY; index++)
  11454. {
  11455. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  11456. {
  11457. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_TERMINATING)) // SYS_MODE_CHARGING, SYS_MODE_TERMINATING
  11458. {
  11459. match = TRUE;
  11460. GunNO = gun_index;
  11461. }
  11462. }
  11463. }// END FOR CHAdeMO_QUANTITY
  11464. } // END FOR AC ELSE
  11465. }// CHECK IF ResponseTransactionId == transactionIdInt
  11466. }//END FOR
  11467. if( match == TRUE)
  11468. {
  11469. ShmOCPP16Data->CsMsg.bits[GunNO].RemoteStopTransactionReq = 1; // inform csu of StopTransaction
  11470. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Accepted]);
  11471. sprintf((char *)ShmOCPP16Data->RemoteStopTransaction[GunNO].ResponseStatus, "%s" ,comfirmstr);
  11472. }
  11473. else
  11474. {
  11475. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  11476. }
  11477. }
  11478. else
  11479. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  11480. sendRemoteStopTransactionConfirmation(uuid, comfirmstr);
  11481. return result;
  11482. }
  11483. int handleReserveNowTransactionRequest(char *uuid, char *payload)
  11484. {
  11485. mtrace();
  11486. int result = FAIL;
  11487. int connectorIdInt=0, reservationIdInt=0;
  11488. int tempIndex = 0;
  11489. char expiryDatestr[30]={0}, idTagstr[21]={0},parentIdTagstr[21]={0};
  11490. char comfirmstr[20]={0};
  11491. char sstr[180]={ 0 },sstrtemp[200]={ 0 };
  11492. int c = 0;
  11493. char *loc;
  11494. //char *ptr;
  11495. DEBUG_INFO("handleReserveNowTransactionRequest ...\n");
  11496. strcpy(sstrtemp, stringtrimspace(payload));
  11497. //***(1)connectorId ****/
  11498. c=0;
  11499. loc = strstr(sstrtemp, "connectorId");
  11500. memset(sstr ,0, ARRAY_SIZE(sstr) );
  11501. while ((loc != NULL) &&(loc[strlen("connectorId")+2+c] != ',') && (loc[strlen("connectorId")+2+c] != '}'))
  11502. {
  11503. sstr[c] = loc[strlen("connectorId")+2+c];
  11504. //printf("i=%d sstr=%c\n",c, sstr[c]);
  11505. c++;
  11506. }
  11507. sstr[c] = '\0';
  11508. connectorIdInt = atoi(sstr);
  11509. //***(2)expiryDate ****/
  11510. loc = strstr(sstrtemp, "expiryDate");
  11511. memset(sstr ,0, ARRAY_SIZE(sstr) );
  11512. c = 0;
  11513. while ((loc != NULL) &&(loc[3+strlen("expiryDate")+c] != '\"'))
  11514. {
  11515. sstr[c] = loc[3+strlen("expiryDate")+c];
  11516. c++;
  11517. }
  11518. sstr[c] = '\0';
  11519. strcpy(expiryDatestr, sstr);
  11520. //***(3)idTag ****/
  11521. loc = strstr(sstrtemp, "idTag");
  11522. memset(sstr ,0, ARRAY_SIZE(sstr) );
  11523. c = 0;
  11524. while ((loc != NULL) &&(loc[3+strlen("idTag")+c] != '\"'))
  11525. {
  11526. sstr[c] = loc[3+strlen("idTag")+c];
  11527. c++;
  11528. }
  11529. sstr[c] = '\0';
  11530. strcpy(idTagstr, sstr);
  11531. //***(4)parentIdTag ****/
  11532. loc = strstr(sstrtemp, "parentIdTag");
  11533. memset(sstr ,0, ARRAY_SIZE(sstr) );
  11534. c = 0;
  11535. if(loc == NULL)
  11536. {
  11537. strcpy(parentIdTagstr, "");
  11538. }
  11539. else
  11540. {
  11541. while ((loc != NULL) &&(loc[3+strlen("parentIdTag")+c] != '\"'))
  11542. {
  11543. sstr[c] = loc[3+strlen("parentIdTag")+c];
  11544. c++;
  11545. }
  11546. sstr[c] = '\0';
  11547. strcpy(parentIdTagstr, sstr);
  11548. }
  11549. //***(5)reservationId ****/
  11550. c=0;
  11551. loc = strstr(sstrtemp, "reservationId");
  11552. memset(sstr ,0, ARRAY_SIZE(sstr) );
  11553. while ((loc != NULL) &&((loc[strlen("reservationId")+2+c] != '}') && (loc[strlen("reservationId")+2+c] != ',')))
  11554. {
  11555. sstr[c] = loc[strlen("reservationId")+2+c];
  11556. //printf("i=%d sstr=%c\n",c, sstr[c]);
  11557. c++;
  11558. }
  11559. sstr[c] = '\0';
  11560. reservationIdInt = atoi(sstr);
  11561. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  11562. /*
  11563. enum SYSTEM_STATUS
  11564. {
  11565. SYS_MODE_BOOTING = 0,
  11566. SYS_MODE_IDLE = 1,
  11567. SYS_MODE_AUTHORIZING = 2,
  11568. SYS_MODE_MODE_REASSIGN_CHECK = 3,
  11569. SYS_MODE_REASSIGN = 4,
  11570. SYS_MODE_PREPARING = 5,
  11571. SYS_MODE_PREPARE_FOR_EV = 6,
  11572. SYS_MODE_PREPARE_FOR_EVSE = 7,
  11573. SYS_MODE_CHARGING = 8,
  11574. SYS_MODE_TERMINATING = 9,
  11575. SYS_MODE_COMPLETE = 10,
  11576. SYS_MODE_ALARM = 11,
  11577. SYS_MODE_FAULT = 12,
  11578. SYS_MODE_RESERVATION = 13,
  11579. SYS_MODE_BOOKING = 14,
  11580. SYS_MODE_MAINTAIN = 15,
  11581. SYS_MODE_DEBUG = 16,
  11582. SYS_MODE_CCS_PRECHARGE_STEP0 = 17,
  11583. SYS_MODE_CCS_PRECHARGE_STEP1 = 18,
  11584. SYS_MODE_UPDATE = 19
  11585. };
  11586. */
  11587. if((connectorIdInt == 0) &&(strcmp((const char *)ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemData, "FALSE") == 0)) //For OCTT Test case
  11588. {
  11589. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  11590. goto end;
  11591. }
  11592. if((connectorIdInt > 0) && ((connectorIdInt -1) <= gunTotalNumber))
  11593. {
  11594. //check Transaction active
  11595. if(gunType[connectorIdInt -1] == GUN_TYPE_CHAdeMO)
  11596. {
  11597. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  11598. {
  11599. tempIndex = (((connectorIdInt -1)==2) ? 1: 0);
  11600. }
  11601. else
  11602. {
  11603. tempIndex = connectorIdInt -1;
  11604. }
  11605. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  11606. {
  11607. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  11608. {
  11609. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ReservationId)
  11610. {
  11611. if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_FAULT)&&(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_ALARM)) //S_FAULT
  11612. {
  11613. if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_IDLE) //S_IDLE
  11614. {
  11615. if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ConnectorPlugIn == 1) || (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].InProgress == 1))
  11616. {
  11617. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  11618. }
  11619. else
  11620. {
  11621. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  11622. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  11623. }
  11624. }
  11625. 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'))
  11626. {
  11627. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  11628. }
  11629. else if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_PREPARING) || (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_RESERVATION) ) //S_PRECHARGE
  11630. {
  11631. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  11632. }
  11633. else
  11634. {
  11635. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  11636. }
  11637. }
  11638. 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
  11639. {
  11640. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  11641. }
  11642. }
  11643. else
  11644. {
  11645. //replace reservation
  11646. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  11647. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  11648. }
  11649. }
  11650. } // END FOR CHAdeMO_QUANTITY
  11651. }
  11652. else if(gunType[connectorIdInt -1] == GUN_TYPE_CCS)
  11653. {
  11654. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  11655. {
  11656. tempIndex = (((connectorIdInt -1)==2) ? 1: 0);
  11657. }
  11658. else
  11659. {
  11660. tempIndex = connectorIdInt -1;
  11661. }
  11662. for (int index = 0; index < CCS_QUANTITY; index++)
  11663. {
  11664. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  11665. {
  11666. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ReservationId)
  11667. {
  11668. //SystemStatus: 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault, 8: Reserved, 9: maintain
  11669. if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_FAULT)&&(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_ALARM)) //S_FAULT
  11670. {
  11671. if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_IDLE) //S_IDLE
  11672. {
  11673. if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ConnectorPlugIn == 1) || (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].InProgress == 1))
  11674. {
  11675. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  11676. }
  11677. else
  11678. {
  11679. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  11680. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  11681. }
  11682. }
  11683. 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'))
  11684. {
  11685. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  11686. }
  11687. else if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_PREPARING) || (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_RESERVATION)) //S_PRECHARGE
  11688. {
  11689. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  11690. }
  11691. else
  11692. {
  11693. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  11694. }
  11695. }
  11696. 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
  11697. {
  11698. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  11699. }
  11700. }
  11701. else
  11702. {
  11703. //replace reservation
  11704. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  11705. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  11706. }
  11707. }
  11708. } // END FOR CCS_QUANTITY
  11709. }
  11710. else if(gunType[connectorIdInt -1] == GUN_TYPE_GBT)
  11711. {
  11712. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  11713. {
  11714. tempIndex = (((connectorIdInt -1)==2) ? 1: 0);
  11715. }
  11716. else
  11717. {
  11718. tempIndex = connectorIdInt -1;
  11719. }
  11720. for (int index = 0; index < GB_QUANTITY; index++)
  11721. {
  11722. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  11723. {
  11724. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ReservationId)
  11725. {
  11726. //SystemStatus: 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault, 8: Reserved, 9: maintain
  11727. if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_FAULT)&&(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_ALARM)) //SYS_MODE_FAULT, SYS_MODE_ALARM
  11728. {
  11729. if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_IDLE) //S_IDLE
  11730. {
  11731. if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ConnectorPlugIn == 1) || (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].InProgress == 1))
  11732. {
  11733. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  11734. }
  11735. else
  11736. {
  11737. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  11738. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  11739. }
  11740. }
  11741. 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'))
  11742. {
  11743. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  11744. }
  11745. else if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_PREPARING) || (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_RESERVATION) ) //S_PRECHARGE
  11746. {
  11747. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  11748. }
  11749. else
  11750. {
  11751. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  11752. }
  11753. }
  11754. 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
  11755. {
  11756. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  11757. }
  11758. }
  11759. else
  11760. {
  11761. //replace reservation
  11762. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  11763. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  11764. }
  11765. }
  11766. }// END FOR GB_QUANTITY
  11767. }
  11768. else if(gunType[connectorIdInt -1] == GUN_TYPE_DO)
  11769. {
  11770. tempIndex = connectorIdInt -1;
  11771. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  11772. {
  11773. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  11774. {
  11775. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.ReservationId)
  11776. {
  11777. //SystemStatus: 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault, 8: Reserved, 9: maintain
  11778. 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
  11779. {
  11780. if(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_IDLE) //S_IDLE
  11781. {
  11782. if((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.ConnectorPlugIn == 1) || (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.InProgress == 1))
  11783. {
  11784. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  11785. }
  11786. else
  11787. {
  11788. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  11789. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  11790. }
  11791. }
  11792. 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'))
  11793. {
  11794. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  11795. }
  11796. else if((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_PREPARING) || (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_RESERVATION) ) //S_PRECHARGE
  11797. {
  11798. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  11799. }
  11800. else
  11801. {
  11802. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  11803. }
  11804. }
  11805. 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
  11806. {
  11807. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  11808. }
  11809. }
  11810. else
  11811. {
  11812. //replace reservation
  11813. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  11814. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  11815. }
  11816. }
  11817. }// END FOR GB_QUANTITY
  11818. }
  11819. else
  11820. {
  11821. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D') // 'D' means DC
  11822. {
  11823. tempIndex = 2;
  11824. }
  11825. else
  11826. {
  11827. tempIndex = (connectorIdInt -1);
  11828. }
  11829. for (int index = 0; index < AC_QUANTITY; index++)
  11830. {
  11831. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  11832. {
  11833. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.AcChargingData[index].ReservationId)
  11834. {
  11835. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_FAULT)&&(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_ALARM)) //SYS_MODE_FAULT, SYS_MODE_ALARM
  11836. {
  11837. if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_IDLE) //S_IDLE
  11838. {
  11839. 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))
  11840. {
  11841. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  11842. }
  11843. else
  11844. {
  11845. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  11846. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  11847. }
  11848. }
  11849. 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'))
  11850. {
  11851. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  11852. }
  11853. else if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_PREPARING) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_RESERVATION) ) //S_PRECHARGE
  11854. {
  11855. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  11856. }
  11857. else
  11858. {
  11859. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  11860. }
  11861. }
  11862. 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
  11863. {
  11864. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  11865. }
  11866. }
  11867. else
  11868. {
  11869. //replace reservation
  11870. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  11871. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  11872. }
  11873. }
  11874. } // END FOR AC_QUANTITY
  11875. }
  11876. sprintf((char *)ShmOCPP16Data->ReserveNow[connectorIdInt-1].ResponseStatus, "%s" ,comfirmstr);
  11877. }
  11878. else if(connectorIdInt == 0)
  11879. {
  11880. //check Transaction active
  11881. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  11882. {
  11883. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ReservationId)
  11884. {
  11885. 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'))
  11886. {
  11887. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  11888. goto end;
  11889. }
  11890. else if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_PREPARING) //S_PRECHARGE
  11891. {
  11892. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  11893. goto end;
  11894. }
  11895. 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
  11896. {
  11897. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  11898. goto end;
  11899. }
  11900. else if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  11901. {
  11902. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  11903. goto end;
  11904. }
  11905. }
  11906. }// END FOR CHAdeMO_QUANTITY
  11907. for (int index = 0; index < CCS_QUANTITY; index++)
  11908. {
  11909. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ReservationId)
  11910. {
  11911. 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'))
  11912. {
  11913. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  11914. goto end;
  11915. }
  11916. else if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_PREPARING) //SYS_MODE_PREPARING
  11917. {
  11918. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  11919. goto end;
  11920. }
  11921. 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
  11922. {
  11923. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  11924. goto end;
  11925. }
  11926. else if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  11927. {
  11928. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  11929. goto end;
  11930. }
  11931. }
  11932. } // END FOR CCS_QUANTITY
  11933. for (int index = 0; index < GB_QUANTITY; index++)
  11934. {
  11935. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ReservationId)
  11936. {
  11937. 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'))
  11938. {
  11939. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  11940. goto end;
  11941. }
  11942. else if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_PREPARING) //S_PRECHARGE
  11943. {
  11944. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  11945. goto end;
  11946. }
  11947. 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
  11948. {
  11949. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  11950. goto end;
  11951. }
  11952. else if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  11953. {
  11954. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  11955. goto end;
  11956. }
  11957. }
  11958. } // END FOR GB_QUANTITY
  11959. for (int index = 0; index < AC_QUANTITY; index++)
  11960. {
  11961. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.AcChargingData[index].ReservationId)
  11962. {
  11963. 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'))
  11964. {
  11965. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  11966. goto end;
  11967. }
  11968. else if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_PREPARING) //S_PRECHARGE
  11969. {
  11970. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  11971. goto end;
  11972. }
  11973. 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
  11974. {
  11975. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  11976. goto end;
  11977. }
  11978. if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_IDLE) //S_IDLE
  11979. {
  11980. 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))
  11981. {
  11982. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  11983. goto end;
  11984. }
  11985. }
  11986. else if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  11987. {
  11988. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  11989. goto end;
  11990. }
  11991. }
  11992. }// END FOR AC_QUANTITY
  11993. //The connectorId is 0
  11994. ShmOCPP16Data->CsMsg.bits[0].ReserveNowReq = 1;
  11995. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  11996. sprintf((char *)ShmOCPP16Data->ReserveNow[0].ResponseStatus, "%s" ,comfirmstr);
  11997. ShmOCPP16Data->ReserveNow[0].ConnectorId = connectorIdInt;
  11998. sprintf((char *)ShmOCPP16Data->ReserveNow[0].ExpiryDate, "%s" , expiryDatestr);
  11999. sprintf((char *)ShmOCPP16Data->ReserveNow[0].IdTag, "%s" , idTagstr);
  12000. sprintf((char *)ShmOCPP16Data->ReserveNow[0].ParentIdTag, "%s" , parentIdTagstr);
  12001. ShmOCPP16Data->ReserveNow[0].ReservationId = reservationIdInt;
  12002. strcpy((char *)ShmOCPP16Data->ReserveNow[0].guid, uuid);
  12003. result = TRUE;
  12004. return result;
  12005. }
  12006. else
  12007. {
  12008. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  12009. sprintf((char *)ShmOCPP16Data->ReserveNow[connectorIdInt-1].ResponseStatus, "%s" ,comfirmstr);
  12010. }
  12011. if(strcmp(comfirmstr,"Accepted") == 0)
  12012. {
  12013. ShmOCPP16Data->ReserveNow[connectorIdInt-1].ConnectorId = connectorIdInt;
  12014. sprintf((char *)ShmOCPP16Data->ReserveNow[connectorIdInt-1].ExpiryDate, "%s" , expiryDatestr);
  12015. sprintf((char *)ShmOCPP16Data->ReserveNow[connectorIdInt-1].IdTag, "%s" , idTagstr);
  12016. sprintf((char *)ShmOCPP16Data->ReserveNow[connectorIdInt-1].ParentIdTag, "%s" , parentIdTagstr);
  12017. ShmOCPP16Data->ReserveNow[connectorIdInt-1].ReservationId = reservationIdInt;
  12018. strcpy((char *)ShmOCPP16Data->ReserveNow[connectorIdInt-1].guid, uuid);
  12019. result = TRUE;
  12020. return result;
  12021. }
  12022. end:
  12023. sendReserveNowTransactionConfirmation(uuid,comfirmstr);
  12024. //ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].ReserveNowConf = 1;
  12025. return result;
  12026. }
  12027. int handleResetRequest(char *uuid, char *payload)
  12028. {
  12029. mtrace();
  12030. int result = FAIL;
  12031. char sstr[10]={0},sstrtemp[30]={ 0 };
  12032. char typestr[10]={0};
  12033. char comfirmstr[20]={0};
  12034. int c = 0;
  12035. char *loc;
  12036. DEBUG_INFO("handleResetRequest...\n");
  12037. strcpy(sstrtemp, stringtrimspace(payload));
  12038. loc = strstr(sstrtemp, "type");
  12039. memset(sstr ,0, ARRAY_SIZE(sstr) );
  12040. c = 0;
  12041. while (loc[3+strlen("type")+c] != '\"')
  12042. {
  12043. sstr[c] = loc[3+strlen("type")+c];
  12044. c++;
  12045. }
  12046. sstr[c] = '\0';
  12047. strcpy(typestr,sstr);
  12048. sprintf((char *)ShmOCPP16Data->Reset.Type, "%s" ,typestr);
  12049. if((strcmp(typestr, ResetTypeStr[Hard])==0) || (strcmp(typestr, ResetTypeStr[Soft])==0))
  12050. {
  12051. ShmOCPP16Data->MsMsg.bits.ResetReq = 1;
  12052. strcpy((char *)ShmOCPP16Data->Reset.guid, uuid);
  12053. strcpy(comfirmstr, ResetStatusStr[ResetStatus_Accepted]);
  12054. sprintf((char *)ShmOCPP16Data->Reset.ResponseStatus, "%s" ,comfirmstr);
  12055. }
  12056. else
  12057. {
  12058. strcpy(comfirmstr, ResetStatusStr[ResetStatus_Rejected]);
  12059. sprintf((char *)ShmOCPP16Data->Reset.ResponseStatus, "%s" ,comfirmstr);
  12060. result = PASS;
  12061. }
  12062. sendResetConfirmation(uuid, comfirmstr);
  12063. return result;
  12064. }
  12065. int handleSendLocalListRequest(char *uuid, char *payload)
  12066. {
  12067. mtrace();
  12068. int result = FAIL;
  12069. char comfirmstr[20];
  12070. int checkState_Faulted = FALSE;
  12071. json_object *SendLocalList;
  12072. DEBUG_INFO("handleSendLocalListRequest...\n");
  12073. if(strcmp((const char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "FALSE") == 0) //For OCTT Test case
  12074. {
  12075. strcpy(comfirmstr, UpdateStatusStr[UpdateStatus_NotSupported]);
  12076. goto end;
  12077. }
  12078. //check Charge Point state
  12079. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  12080. {
  12081. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_FAULT) //S_FAULT ---> Faulted
  12082. {
  12083. checkState_Faulted = TRUE; //OCPP Status: Faulted
  12084. }
  12085. }
  12086. for (int index = 0; index < CCS_QUANTITY; index++)
  12087. {
  12088. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_FAULT) //S_FAULT ---> Faulted
  12089. {
  12090. checkState_Faulted = TRUE; //OCPP Status
  12091. }
  12092. }
  12093. for (int index = 0; index < GB_QUANTITY; index++)
  12094. {
  12095. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_FAULT) //S_FAULT ---> Faulted
  12096. {
  12097. checkState_Faulted = TRUE; //OCPP Status: Faulted
  12098. }
  12099. }
  12100. //check Charge Point state
  12101. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  12102. {
  12103. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_FAULT) //S_FAULT ---> Faulted
  12104. {
  12105. checkState_Faulted = TRUE; //OCPP Status: Faulted
  12106. }
  12107. }
  12108. //check Charge Point state
  12109. for (int index = 0; index < AC_QUANTITY; index++)
  12110. {
  12111. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_FAULT) //S_FAULT ---> Faulted
  12112. {
  12113. checkState_Faulted = TRUE; //OCPP Status: Faulted
  12114. }
  12115. }
  12116. if(checkState_Faulted == TRUE)
  12117. {
  12118. strcpy(comfirmstr, UpdateStatusStr[UpdateStatus_Failed]);
  12119. goto end;
  12120. }
  12121. // Parsing payload
  12122. SendLocalList = json_tokener_parse(payload);
  12123. if(!is_error(SendLocalList))
  12124. {
  12125. // Required data
  12126. ShmOCPP16Data->SendLocalList.ListVersion = json_object_get_int(json_object_object_get(SendLocalList, "listVersion"));
  12127. sprintf((char*)ShmOCPP16Data->SendLocalList.UpdateType, "%s", json_object_get_string(json_object_object_get(SendLocalList, "updateType")));
  12128. // Optional data
  12129. if(json_object_object_get(SendLocalList, "localAuthorizationList") != NULL)
  12130. {
  12131. //Check UpdateType
  12132. if(strcmp((char*)ShmOCPP16Data->SendLocalList.UpdateType, UpdateTypeStr[Full]) == 0)
  12133. {
  12134. //Local list full update
  12135. DEBUG_INFO("Local list full update.\n");
  12136. locallistVersion = 0;
  12137. OCPP_getListVerion();
  12138. /*if(ShmOCPP16Data->SendLocalList.ListVersion < locallistVersion)
  12139. {
  12140. strcpy(comfirmstr, UpdateStatusStr[UpdateStatus_Failed]);
  12141. goto end;
  12142. }*/
  12143. OCPP_cleanLocalList();
  12144. }
  12145. else if(strcmp((char*)ShmOCPP16Data->SendLocalList.UpdateType, UpdateTypeStr[Differential]) == 0)
  12146. {
  12147. //Local list different update
  12148. DEBUG_INFO("Local list different update.\n");
  12149. locallistVersion = 0;
  12150. OCPP_getListVerion();
  12151. if(ShmOCPP16Data->SendLocalList.ListVersion < locallistVersion)
  12152. {
  12153. strcpy(comfirmstr, UpdateStatusStr[UpdateStatus_VersionMismatch]);
  12154. goto end;
  12155. }
  12156. }
  12157. else
  12158. {
  12159. strcpy(comfirmstr, UpdateStatusStr[UpdateStatus_NotSupported]);
  12160. goto end;
  12161. }
  12162. if(json_object_array_length(json_object_object_get(SendLocalList, "localAuthorizationList")) > atoi((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemData))
  12163. {
  12164. DEBUG_WARN("Local list length is over SendLocalListMaxLength.\n");
  12165. strcpy(comfirmstr, UpdateStatusStr[UpdateStatus_Failed]);
  12166. goto end;
  12167. }
  12168. memset(ShmOCPP16Data->SendLocalList.LocalAuthorizationList, 0 , sizeof(struct StructLocalAuthorizationList)*1);
  12169. for(int idx=0;idx<json_object_array_length(json_object_object_get(SendLocalList, "localAuthorizationList"));idx++)
  12170. {
  12171. 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")));
  12172. if(json_object_object_get(json_object_array_get_idx(json_object_object_get(SendLocalList, "localAuthorizationList"), idx), "idTagInfo") != NULL)
  12173. {
  12174. 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")));
  12175. if(json_object_object_get(json_object_object_get(json_object_array_get_idx(json_object_object_get(SendLocalList, "localAuthorizationList"), idx), "idTagInfo"), "expiryDate") != NULL)
  12176. 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")));
  12177. if(json_object_object_get(json_object_object_get(json_object_array_get_idx(json_object_object_get(SendLocalList, "localAuthorizationList"), idx), "idTagInfo"), "parentIdTag") != NULL)
  12178. 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")));
  12179. }
  12180. // Add to db
  12181. if(strcmp((char*)ShmOCPP16Data->SendLocalList.UpdateType, UpdateTypeStr[Full]) == 0)
  12182. {
  12183. //Local list full update
  12184. DEBUG_INFO("Local list full update item: %d, listVer: %d, %s, %s, %s, %s.\n",
  12185. idx,
  12186. ShmOCPP16Data->SendLocalList.ListVersion,
  12187. ShmOCPP16Data->SendLocalList.LocalAuthorizationList[0].IdTag,
  12188. ShmOCPP16Data->SendLocalList.LocalAuthorizationList[0].IdTagInfo.ParentIdTag,
  12189. ShmOCPP16Data->SendLocalList.LocalAuthorizationList[0].IdTagInfo.ExpiryDate,
  12190. ShmOCPP16Data->SendLocalList.LocalAuthorizationList[0].IdTagInfo.Status);
  12191. // update list
  12192. OCPP_addLocalList(ShmOCPP16Data->SendLocalList.ListVersion,
  12193. (char*)ShmOCPP16Data->SendLocalList.LocalAuthorizationList[0].IdTag,
  12194. (char*)ShmOCPP16Data->SendLocalList.LocalAuthorizationList[0].IdTagInfo.ParentIdTag,
  12195. (char*)ShmOCPP16Data->SendLocalList.LocalAuthorizationList[0].IdTagInfo.ExpiryDate,
  12196. (char*)ShmOCPP16Data->SendLocalList.LocalAuthorizationList[0].IdTagInfo.Status);
  12197. }
  12198. else if(strcmp((char*)ShmOCPP16Data->SendLocalList.UpdateType, UpdateTypeStr[Differential]) == 0)
  12199. {
  12200. DEBUG_INFO("Local list diff update item: %d,listVer: %d, %s, %s, %s, %s.\n",
  12201. idx,
  12202. ShmOCPP16Data->SendLocalList.ListVersion,
  12203. ShmOCPP16Data->SendLocalList.LocalAuthorizationList[0].IdTag,
  12204. ShmOCPP16Data->SendLocalList.LocalAuthorizationList[0].IdTagInfo.ParentIdTag,
  12205. ShmOCPP16Data->SendLocalList.LocalAuthorizationList[0].IdTagInfo.ExpiryDate,
  12206. ShmOCPP16Data->SendLocalList.LocalAuthorizationList[0].IdTagInfo.Status);
  12207. OCPP_addLocalList(ShmOCPP16Data->SendLocalList.ListVersion,
  12208. (char*)ShmOCPP16Data->SendLocalList.LocalAuthorizationList[0].IdTag,
  12209. (char*)ShmOCPP16Data->SendLocalList.LocalAuthorizationList[0].IdTagInfo.ParentIdTag,
  12210. (char*)ShmOCPP16Data->SendLocalList.LocalAuthorizationList[0].IdTagInfo.ExpiryDate,
  12211. (char*)ShmOCPP16Data->SendLocalList.LocalAuthorizationList[0].IdTagInfo.Status);
  12212. }
  12213. }
  12214. }
  12215. else
  12216. {
  12217. //Check UpdateType
  12218. if(strcmp((char*)ShmOCPP16Data->SendLocalList.UpdateType, UpdateTypeStr[Full]) == 0)
  12219. {
  12220. //Local list full update
  12221. DEBUG_INFO("If no (empty) localAuthorizationList is given and the updateType is Full, all identifications are removed from the list. \n");
  12222. OCPP_cleanLocalList();
  12223. strcpy(comfirmstr, UpdateStatusStr[UpdateStatus_Accepted]);
  12224. goto end;
  12225. }
  12226. if(strcmp((char*)ShmOCPP16Data->SendLocalList.UpdateType, UpdateTypeStr[Differential]) == 0)
  12227. {
  12228. //Local list different update
  12229. DEBUG_INFO("Requesting a Differential update without (empty) localAuthorizationList will have no effect on the list\n");
  12230. strcpy(comfirmstr, UpdateStatusStr[UpdateStatus_Accepted]);
  12231. goto end;
  12232. }
  12233. }
  12234. result = PASS;
  12235. }
  12236. strcpy(comfirmstr, UpdateStatusStr[UpdateStatus_Accepted]);
  12237. end:
  12238. json_object_put(SendLocalList);
  12239. sendSendLocalListConfirmation(uuid, comfirmstr);
  12240. return result;
  12241. }
  12242. int handleSetChargingProfileRequest(char *uuid, char *payload)
  12243. {
  12244. mtrace();
  12245. int result = FAIL;
  12246. struct StructSetChargingProfile SetProfileReq = {0};
  12247. int tempchargingProfileIdInt;
  12248. int tempstackLevelInt;
  12249. int chargingSchedulePeriodCount = 0;
  12250. char comfirmstr[20]={0};
  12251. char tempfile[] = "/Storage/OCPP/SetChargingProfiletemp.json";
  12252. char rmFileCmd[128]={0};
  12253. int profileQuantity = 0;
  12254. int replaceableProfileCnt = 0;
  12255. json_object *SetChargingProfile;
  12256. DEBUG_INFO("handleSetChargingProfileRequest\n");
  12257. SetChargingProfile = json_tokener_parse(payload);
  12258. if(!is_error(SetChargingProfile))
  12259. {
  12260. if(json_object_object_get(SetChargingProfile, "connectorId") != NULL)
  12261. {
  12262. SetProfileReq.ConnectorId = json_object_get_int(json_object_object_get(SetChargingProfile, "connectorId"));
  12263. }
  12264. if(json_object_object_get(SetChargingProfile, "csChargingProfiles") != NULL)
  12265. {
  12266. if(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingProfileId") != NULL)
  12267. {
  12268. SetProfileReq.ChargingProfile.ChargingProfileId = json_object_get_int(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingProfileId"));
  12269. }
  12270. else
  12271. {
  12272. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  12273. DEBUG_WARN("Cannot find chargingProfileId field.");
  12274. goto end;
  12275. }
  12276. if(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "stackLevel") != NULL)
  12277. {
  12278. SetProfileReq.ChargingProfile.StackLevel = json_object_get_int(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "stackLevel"));
  12279. }
  12280. else
  12281. {
  12282. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  12283. DEBUG_WARN("Cannot find stackLevel field.");
  12284. goto end;
  12285. }
  12286. if(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingProfilePurpose") != NULL)
  12287. {
  12288. strcpy((char*)SetProfileReq.ChargingProfile.ChargingProfilePurpose, json_object_get_string(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingProfilePurpose")));
  12289. }
  12290. else
  12291. {
  12292. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  12293. DEBUG_WARN("Cannot find chargingProfilePurpose field.");
  12294. goto end;
  12295. }
  12296. if(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingProfileKind") != NULL)
  12297. {
  12298. strcpy((char*)SetProfileReq.ChargingProfile.ChargingProfileKind, json_object_get_string(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingProfileKind")));
  12299. }
  12300. else
  12301. {
  12302. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  12303. DEBUG_WARN("Cannot find chargingProfileKind field.");
  12304. goto end;
  12305. }
  12306. if(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "transactionId") != NULL)
  12307. {
  12308. SetProfileReq.ChargingProfile.TransactionId = json_object_get_int(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "transactionId"));
  12309. }
  12310. if(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "recurrencyKind") != NULL)
  12311. {
  12312. strcpy((char*)SetProfileReq.ChargingProfile.RecurrencyKind, json_object_get_string(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "recurrencyKind")));
  12313. }
  12314. if(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "validFrom") != NULL)
  12315. {
  12316. strcpy((char*)SetProfileReq.ChargingProfile.ValidFrom, json_object_get_string(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "validFrom")));
  12317. }
  12318. if(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "validTo") != NULL)
  12319. {
  12320. strcpy((char*)SetProfileReq.ChargingProfile.ValidTo, json_object_get_string(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "validTo")));
  12321. }
  12322. if(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingSchedule") != NULL)
  12323. {
  12324. if(json_object_object_get(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingSchedule"), "chargingRateUnit") != NULL)
  12325. {
  12326. 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")));
  12327. }
  12328. else
  12329. {
  12330. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  12331. DEBUG_WARN("Cannot find chargingRateUnit field.");
  12332. goto end;
  12333. }
  12334. if(json_object_object_get(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingSchedule"), "duration") != NULL)
  12335. {
  12336. SetProfileReq.ChargingProfile.ChargingSchedule.Duration = json_object_get_int(json_object_object_get(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingSchedule"), "duration"));
  12337. }
  12338. if(json_object_object_get(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingSchedule"), "minChargingRate") != NULL)
  12339. {
  12340. SetProfileReq.ChargingProfile.ChargingSchedule.MinChargingRate = json_object_get_double(json_object_object_get(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingSchedule"), "minChargingRate"));
  12341. }
  12342. if(json_object_object_get(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingSchedule"), "startSchedule") != NULL)
  12343. {
  12344. 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")));
  12345. }
  12346. if(json_object_object_get(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod") != NULL)
  12347. {
  12348. chargingSchedulePeriodCount = json_object_array_length(json_object_object_get(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"));
  12349. if(chargingSchedulePeriodCount <= 10)
  12350. {
  12351. 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++)
  12352. {
  12353. 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)
  12354. {
  12355. 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"));
  12356. }
  12357. else
  12358. {
  12359. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  12360. DEBUG_WARN("Cannot find startPeriod field.");
  12361. goto end;
  12362. }
  12363. 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)
  12364. {
  12365. 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"));
  12366. }
  12367. else
  12368. {
  12369. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  12370. DEBUG_WARN("Cannot find limit field.");
  12371. goto end;
  12372. }
  12373. 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)
  12374. {
  12375. 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"));
  12376. }
  12377. }
  12378. }
  12379. }
  12380. else
  12381. {
  12382. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  12383. DEBUG_WARN("Cannot find chargingSchedulePeriod field.");
  12384. goto end;
  12385. }
  12386. }
  12387. else
  12388. {
  12389. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  12390. DEBUG_WARN("Cannot find chargingSchedule field.");
  12391. goto end;
  12392. }
  12393. }
  12394. }
  12395. // Profile periods quantity check
  12396. if( chargingSchedulePeriodCount > atoi((const char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemData))
  12397. {
  12398. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  12399. DEBUG_WARN("Profile period is over limit %s. \n", ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemData);
  12400. goto end;
  12401. }
  12402. // Check invalid limit
  12403. if((strcmp((char*)SetProfileReq.ChargingProfile.ChargingProfilePurpose, ChargingProfilePurposeTypeStr[ChargePointMaxProfile]) != 0) ||
  12404. ((strcmp((char*)SetProfileReq.ChargingProfile.ChargingProfilePurpose, ChargingProfilePurposeTypeStr[ChargePointMaxProfile]) == 0) && (ShmSysConfigAndInfo->SysConfig.isEnableLocalPowerSharing != 1)))
  12405. {
  12406. if(ShmSysConfigAndInfo->SysConfig.ModelName[0] == 'A')
  12407. {
  12408. for(uint8_t idxPeriod=0;idxPeriod<chargingSchedulePeriodCount;idxPeriod++)
  12409. {
  12410. 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)))) ||
  12411. (SetProfileReq.ChargingProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit > (SetProfileReq.ChargingProfile.ChargingSchedule.ChargingRateUnit[0]=='W'?modelnameInfo.ratedPower:ShmSysConfigAndInfo->SysConfig.RatingCurrent)))
  12412. {
  12413. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  12414. DEBUG_WARN("Profile period-%02d is invalid limit: %.2f %s with phase %d.\n", idxPeriod,
  12415. SetProfileReq.ChargingProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit,
  12416. SetProfileReq.ChargingProfile.ChargingSchedule.ChargingRateUnit,
  12417. (SetProfileReq.ChargingProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases==0?3:SetProfileReq.ChargingProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases));
  12418. goto end;
  12419. }
  12420. }
  12421. }
  12422. else
  12423. {
  12424. for(uint8_t idxPeriod=0;idxPeriod<chargingSchedulePeriodCount;idxPeriod++)
  12425. {
  12426. 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) ||
  12427. (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)))
  12428. {
  12429. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  12430. DEBUG_WARN("Profile period-%02d is invalid limit: %.2f %s with phase %d.\n", idxPeriod,
  12431. SetProfileReq.ChargingProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit,
  12432. SetProfileReq.ChargingProfile.ChargingSchedule.ChargingRateUnit,
  12433. (SetProfileReq.ChargingProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases==0?3:SetProfileReq.ChargingProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases));
  12434. goto end;
  12435. }
  12436. }
  12437. }
  12438. }
  12439. // Profile purpose info check
  12440. if(strcmp((char*)SetProfileReq.ChargingProfile.ChargingProfilePurpose, ChargingProfilePurposeTypeStr[ChargePointMaxProfile]) == 0)
  12441. {
  12442. FILE *fp;
  12443. DEBUG_INFO("Profile purpose is ChargePointMaxProfile.\n");
  12444. if(SetProfileReq.ConnectorId != 0)
  12445. {
  12446. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  12447. DEBUG_WARN("Profile connector id is not 0.\n");
  12448. goto end;
  12449. }
  12450. fp = fopen(ChargePointMaxProfile_JSON, "r");
  12451. if (!fp)
  12452. {
  12453. DEBUG_INFO("%s does not create.\n", ChargePointMaxProfile_JSON);
  12454. fp = fopen(ChargePointMaxProfile_JSON, "w+");
  12455. }
  12456. else
  12457. {
  12458. char *line = NULL;
  12459. size_t len = 0;
  12460. while(getline(&line, &len, fp) != -1)
  12461. {
  12462. json_object *obj = NULL;
  12463. obj = json_tokener_parse(line);
  12464. if(is_error(obj))
  12465. {
  12466. DEBUG_ERROR("Parse txProfile from file error.\n");
  12467. }
  12468. else
  12469. {
  12470. if((json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileId")) != SetProfileReq.ChargingProfile.ChargingProfileId) &&
  12471. (json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "stackLevel")) != SetProfileReq.ChargingProfile.StackLevel))
  12472. {
  12473. profileQuantity += 1;
  12474. }
  12475. else
  12476. replaceableProfileCnt += 1;
  12477. }
  12478. }
  12479. }
  12480. fclose(fp);
  12481. }
  12482. else if(strcmp((char*)SetProfileReq.ChargingProfile.ChargingProfilePurpose, ChargingProfilePurposeTypeStr[TxDefaultProfile]) == 0)
  12483. {
  12484. FILE *fp;
  12485. char filename[128]={0};
  12486. int tmpProfileQuantity;
  12487. DEBUG_INFO("Profile purpose is TxDefaultProfile.\n");
  12488. if((SetProfileReq.ConnectorId != 0) && (SetProfileReq.ConnectorId > gunTotalNumber))
  12489. {
  12490. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  12491. DEBUG_WARN("Profile connector id is over max gun number.\n");
  12492. goto end;
  12493. }
  12494. if(SetProfileReq.ConnectorId == 0)
  12495. {
  12496. for(int idxCon=1;idxCon<=gunTotalNumber;idxCon++)
  12497. {
  12498. tmpProfileQuantity = 0;
  12499. memset(filename, 0, ARRAY_SIZE(filename));
  12500. sprintf(filename, "/Storage/OCPP/TxDefaultProfile_%d.json", idxCon);
  12501. fp = fopen(filename, "r");
  12502. if (!fp)
  12503. {
  12504. DEBUG_INFO("%s does not create.\n", filename);
  12505. fp = fopen(filename, "w+");
  12506. }
  12507. else
  12508. {
  12509. char *line = NULL;
  12510. size_t len = 0;
  12511. while(getline(&line, &len, fp) != -1)
  12512. {
  12513. json_object *obj = NULL;
  12514. obj = json_tokener_parse(line);
  12515. if(is_error(obj))
  12516. {
  12517. DEBUG_ERROR("Parse txProfile from file error.\n");
  12518. }
  12519. else
  12520. {
  12521. if((json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileId")) != SetProfileReq.ChargingProfile.ChargingProfileId) &&
  12522. (json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "stackLevel")) != SetProfileReq.ChargingProfile.StackLevel))
  12523. {
  12524. tmpProfileQuantity += 1;
  12525. }
  12526. else
  12527. replaceableProfileCnt += 1;
  12528. }
  12529. }
  12530. }
  12531. fclose(fp);
  12532. profileQuantity = (profileQuantity < tmpProfileQuantity) ? tmpProfileQuantity : profileQuantity;
  12533. }
  12534. }
  12535. else
  12536. {
  12537. memset(filename, 0, ARRAY_SIZE(filename));
  12538. sprintf(filename, "/Storage/OCPP/TxDefaultProfile_%d.json", SetProfileReq.ConnectorId);
  12539. fp = fopen(filename, "r");
  12540. if (!fp)
  12541. {
  12542. DEBUG_INFO("%s does not create.\n", filename);
  12543. fp = fopen(filename, "w+");
  12544. }
  12545. else
  12546. {
  12547. char *line = NULL;
  12548. size_t len = 0;
  12549. while(getline(&line, &len, fp) != -1)
  12550. {
  12551. json_object *obj = NULL;
  12552. obj = json_tokener_parse(line);
  12553. if(is_error(obj))
  12554. {
  12555. DEBUG_ERROR("Parse txProfile from file error.\n");
  12556. }
  12557. else
  12558. {
  12559. if((json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileId")) != SetProfileReq.ChargingProfile.ChargingProfileId) &&
  12560. (json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "stackLevel")) != SetProfileReq.ChargingProfile.StackLevel))
  12561. {
  12562. profileQuantity += 1;
  12563. }
  12564. else
  12565. replaceableProfileCnt += 1;
  12566. }
  12567. }
  12568. }
  12569. fclose(fp);
  12570. }
  12571. }
  12572. else if(strcmp((char*)SetProfileReq.ChargingProfile.ChargingProfilePurpose, ChargingProfilePurposeTypeStr[TxProfile]) == 0)
  12573. {
  12574. int isMatchTransactiodId= FALSE;
  12575. FILE *fp;
  12576. char filename[128]={0};
  12577. DEBUG_INFO("Profile purposeStr is TxProfile.\n");
  12578. //---TxProfile SHALL only be set at Charge Point ConnectorId > 0. ---//
  12579. if(SetProfileReq.ConnectorId == 0)
  12580. {
  12581. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  12582. DEBUG_WARN("Profile connector id is 0.\n");
  12583. goto end;
  12584. }
  12585. int tempIndex = 0;
  12586. //check Transaction active
  12587. if(gunType[SetProfileReq.ConnectorId -1] == GUN_TYPE_CHAdeMO)
  12588. {
  12589. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  12590. {
  12591. tempIndex = (((SetProfileReq.ConnectorId -1)==2) ? 1: 0);
  12592. }
  12593. else
  12594. {
  12595. tempIndex = SetProfileReq.ConnectorId -1;
  12596. }
  12597. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  12598. {
  12599. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  12600. {
  12601. if((SYS_MODE_PREPARING <= ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus) && (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus <= SYS_MODE_TERMINATING)) // S_CHARGING
  12602. {
  12603. if(SetProfileReq.ChargingProfile.TransactionId == ShmOCPP16Data->StartTransaction[SetProfileReq.ConnectorId -1].ResponseTransactionId)
  12604. {
  12605. isMatchTransactiodId = TRUE;
  12606. break;
  12607. }
  12608. }
  12609. }
  12610. }
  12611. }
  12612. else if(gunType[SetProfileReq.ConnectorId -1] == GUN_TYPE_CCS)
  12613. {
  12614. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  12615. {
  12616. tempIndex = (((SetProfileReq.ConnectorId -1)==2) ? 1: 0);
  12617. }
  12618. else
  12619. {
  12620. tempIndex = SetProfileReq.ConnectorId -1;
  12621. }
  12622. for (int index = 0; index < CCS_QUANTITY; index++)
  12623. {
  12624. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  12625. {
  12626. if(((SYS_MODE_PREPARING <= ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus) && (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus <= SYS_MODE_TERMINATING)) ||
  12627. ((SYS_MODE_CCS_PRECHARGE_STEP0 <= ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus) && (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus <= SYS_MODE_CCS_PRECHARGE_STEP1))) // S_CHARGING
  12628. {
  12629. if(SetProfileReq.ChargingProfile.TransactionId == ShmOCPP16Data->StartTransaction[SetProfileReq.ConnectorId -1].ResponseTransactionId)
  12630. {
  12631. isMatchTransactiodId = TRUE;
  12632. break;
  12633. }
  12634. }
  12635. }
  12636. }
  12637. }
  12638. else if(gunType[SetProfileReq.ConnectorId -1] == GUN_TYPE_GBT)
  12639. {
  12640. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  12641. {
  12642. tempIndex = (((SetProfileReq.ConnectorId -1)==2) ? 1: 0);
  12643. }
  12644. else
  12645. {
  12646. tempIndex = SetProfileReq.ConnectorId -1;
  12647. }
  12648. for (int index = 0; index < GB_QUANTITY; index++)
  12649. {
  12650. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  12651. {
  12652. if((SYS_MODE_PREPARING <= ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus) && (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus <= SYS_MODE_TERMINATING)) // S_CHARGING
  12653. {
  12654. if(SetProfileReq.ChargingProfile.TransactionId == ShmOCPP16Data->StartTransaction[SetProfileReq.ConnectorId -1].ResponseTransactionId)
  12655. {
  12656. isMatchTransactiodId = TRUE;
  12657. break;
  12658. }
  12659. }
  12660. }
  12661. }
  12662. }
  12663. else if(gunType[SetProfileReq.ConnectorId -1] == GUN_TYPE_DO)
  12664. {
  12665. tempIndex = SetProfileReq.ConnectorId -1;
  12666. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  12667. {
  12668. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  12669. {
  12670. if(((SYS_MODE_PREPARING <= ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus) && (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus <= SYS_MODE_TERMINATING)) ||
  12671. ((SYS_MODE_CCS_PRECHARGE_STEP0 <= ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus) && (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus <= SYS_MODE_CCS_PRECHARGE_STEP1))) // S_CHARGING
  12672. {
  12673. if(SetProfileReq.ChargingProfile.TransactionId == ShmOCPP16Data->StartTransaction[SetProfileReq.ConnectorId -1].ResponseTransactionId)
  12674. {
  12675. isMatchTransactiodId = TRUE;
  12676. break;
  12677. }
  12678. }
  12679. }
  12680. }
  12681. }
  12682. else
  12683. {
  12684. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D') // 'D' means DC
  12685. {
  12686. tempIndex = 2;
  12687. }
  12688. else
  12689. {
  12690. tempIndex = (SetProfileReq.ConnectorId -1);
  12691. }
  12692. for (int index = 0; index < AC_QUANTITY; index++)
  12693. {
  12694. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  12695. {
  12696. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_TERMINATING)) // S_CHARGING
  12697. {
  12698. if(SetProfileReq.ChargingProfile.TransactionId == ShmOCPP16Data->StartTransaction[SetProfileReq.ConnectorId -1].ResponseTransactionId)
  12699. {
  12700. isMatchTransactiodId = TRUE;
  12701. break;
  12702. }
  12703. }
  12704. }
  12705. }
  12706. }
  12707. //check Transaction active
  12708. if(isMatchTransactiodId == FALSE)
  12709. {
  12710. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  12711. DEBUG_WARN("Tx profile transaction id is not match.\n");
  12712. goto end;
  12713. }
  12714. if((SetProfileReq.ConnectorId != 0) && (SetProfileReq.ConnectorId > gunTotalNumber))
  12715. {
  12716. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  12717. DEBUG_WARN("Connector id is over max gun number.\n");
  12718. goto end;
  12719. }
  12720. sprintf(filename, "/Storage/OCPP/TxProfile_%d.json", SetProfileReq.ConnectorId);
  12721. fp = fopen(filename, "r");
  12722. if (!fp)
  12723. {
  12724. DEBUG_INFO("%s does not create.\n", filename);
  12725. fp = fopen(filename, "w+");
  12726. }
  12727. else
  12728. {
  12729. char *line = NULL;
  12730. size_t len = 0;
  12731. while(getline(&line, &len, fp) != -1)
  12732. {
  12733. json_object *obj = NULL;
  12734. obj = json_tokener_parse(line);
  12735. if(is_error(obj))
  12736. {
  12737. DEBUG_ERROR("Parse txProfile from file error.\n");
  12738. }
  12739. else
  12740. {
  12741. if((json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileId")) != SetProfileReq.ChargingProfile.ChargingProfileId) &&
  12742. (json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "stackLevel")) != SetProfileReq.ChargingProfile.StackLevel))
  12743. {
  12744. profileQuantity += 1;
  12745. }
  12746. else
  12747. replaceableProfileCnt += 1;
  12748. }
  12749. }
  12750. }
  12751. fclose(fp);
  12752. }
  12753. // Check ChargeProfileMaxStackLevel
  12754. DEBUG_INFO("%s profile quantity: %d\n", SetProfileReq.ChargingProfile.ChargingProfilePurpose, profileQuantity);
  12755. if(profileQuantity >= atoi((const char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemData))
  12756. {
  12757. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  12758. DEBUG_WARN("Purpose profile quantify is over stack limit %s.\n", ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemData);
  12759. goto end;
  12760. }
  12761. //------------------------------Start: Check Configuration Key "MaxChargingProfilesInstalled" Logic---------------------------------------//
  12762. {
  12763. FILE *fp;
  12764. char dataLine[4096]={0};
  12765. char fnametemp[128]={0};
  12766. int tmpProfileQuantity;
  12767. //Check ChargePointMaxProfile.json exit
  12768. profileQuantity = 0;
  12769. if((access("/Storage/OCPP/ChargePointMaxProfile.json",F_OK))!=-1)
  12770. {
  12771. fp = fopen("/Storage/OCPP/ChargePointMaxProfile.json", "r");
  12772. //Check Charging Profile Count
  12773. tmpProfileQuantity = 0;
  12774. while(fscanf(fp, "%s", dataLine) != EOF)
  12775. {
  12776. if(strstr(dataLine, "chargingProfileId")!= NULL)
  12777. {
  12778. profileQuantity += 1;
  12779. tmpProfileQuantity += 1;
  12780. }
  12781. memset(dataLine, 0, ARRAY_SIZE(dataLine));
  12782. }
  12783. fclose(fp);
  12784. DEBUG_INFO("ChargePointMaxProfile.json has %d charging Profile\n", tmpProfileQuantity);
  12785. }
  12786. //Check TxDefaultProfile_%d.json
  12787. for(int idxCon=1; idxCon <= gunTotalNumber; idxCon++)
  12788. {
  12789. memset(fnametemp, 0, ARRAY_SIZE(fnametemp));
  12790. sprintf(fnametemp, "/Storage/OCPP/TxDefaultProfile_%d.json", idxCon);
  12791. if((access(fnametemp,F_OK))!=-1)
  12792. {
  12793. fp = fopen(fnametemp, "r");
  12794. //Check Charging Profile Count
  12795. tmpProfileQuantity = 0;
  12796. while(fscanf(fp, "%s", dataLine) != EOF)
  12797. {
  12798. //DEBUG_INFO("word=%s\n",word);
  12799. if(strstr(dataLine, "chargingProfileId")!= NULL)
  12800. {
  12801. profileQuantity += 1;
  12802. tmpProfileQuantity += 1;
  12803. }
  12804. memset(dataLine, 0, ARRAY_SIZE(dataLine));
  12805. }
  12806. fclose(fp);
  12807. DEBUG_INFO("%s has %d charging Profile\n",fnametemp, tmpProfileQuantity);
  12808. }
  12809. }
  12810. //Check TxProfile_%d.json
  12811. for(int idxCon=1; idxCon <= gunTotalNumber; idxCon++)
  12812. {
  12813. memset(fnametemp, 0, ARRAY_SIZE(fnametemp));
  12814. sprintf(fnametemp, "/Storage/OCPP/TxProfile_%d.json", idxCon);
  12815. if((access(fnametemp,F_OK))!=-1)
  12816. {
  12817. fp = fopen(fnametemp, "r");
  12818. //Check Charging Profile Count
  12819. tmpProfileQuantity = 0;
  12820. while(fscanf(fp, "%s", dataLine) != EOF)
  12821. {
  12822. if(strstr(dataLine, "chargingProfileId")!= NULL)
  12823. {
  12824. profileQuantity += 1;
  12825. tmpProfileQuantity += 1;
  12826. }
  12827. memset(dataLine, 0, ARRAY_SIZE(dataLine));
  12828. }
  12829. fclose(fp);
  12830. DEBUG_INFO("%s has %d charging Profile\n",fnametemp, tmpProfileQuantity);
  12831. }
  12832. }
  12833. DEBUG_INFO("All purpose profile quantity: %d\n", profileQuantity);
  12834. DEBUG_INFO("Replaceable profile quantity: %d\n", replaceableProfileCnt);
  12835. // To check total Profile quantity
  12836. if((SetProfileReq.ConnectorId > 0) || (strcmp((char*)SetProfileReq.ChargingProfile.ChargingProfilePurpose, ChargingProfilePurposeTypeStr[ChargePointMaxProfile]) == 0))
  12837. {
  12838. if((profileQuantity-replaceableProfileCnt) >= atoi((const char*)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemData))
  12839. {
  12840. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected]);
  12841. DEBUG_WARN("Total profile quantify is over installed limit %s.\n", ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemData);
  12842. goto end;
  12843. }
  12844. }
  12845. else
  12846. {
  12847. if((profileQuantity+gunTotalNumber-replaceableProfileCnt) > atoi((const char*)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemData))
  12848. {
  12849. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected]);
  12850. DEBUG_WARN("Total profile quantify is over installed limit %s.\n", ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemData);
  12851. goto end;
  12852. }
  12853. }
  12854. }
  12855. //------------------------------End: Check Configuration Key "MaxChargingProfilesInstalled" Logic---------------------------------------//
  12856. //**********************************Write to File********************************************************/
  12857. {
  12858. FILE *infile;
  12859. FILE *outfile;
  12860. char dataLine[4096]={0};
  12861. char filename[128]={0};
  12862. int chkChar=0;
  12863. for(int idxCon=1; idxCon <= (SetProfileReq.ConnectorId==0?gunTotalNumber:1); idxCon++)
  12864. {
  12865. if(strcmp((char*)SetProfileReq.ChargingProfile.ChargingProfilePurpose, ChargingProfilePurposeTypeStr[ChargePointMaxProfile]) == 0)
  12866. {
  12867. sprintf(filename, "%s", ChargePointMaxProfile_JSON);
  12868. }
  12869. else if(strcmp((char*)SetProfileReq.ChargingProfile.ChargingProfilePurpose, ChargingProfilePurposeTypeStr[TxDefaultProfile]) == 0)
  12870. {
  12871. if(SetProfileReq.ConnectorId==0)
  12872. sprintf(filename, "/Storage/OCPP/TxDefaultProfile_%d.json", idxCon);
  12873. else
  12874. sprintf(filename, "/Storage/OCPP/TxDefaultProfile_%d.json", SetProfileReq.ConnectorId);
  12875. }
  12876. else
  12877. {
  12878. sprintf(filename, "/Storage/OCPP/TxProfile_%d.json", SetProfileReq.ConnectorId);
  12879. }
  12880. infile = fopen (filename, "r");
  12881. outfile = fopen (tempfile, "w");
  12882. chkChar = fgetc(infile);
  12883. rewind(infile);
  12884. if(chkChar == EOF)
  12885. {
  12886. // Profile is empty
  12887. if((strcmp((char*)SetProfileReq.ChargingProfile.ChargingProfilePurpose, ChargingProfilePurposeTypeStr[TxDefaultProfile]) == 0) && (SetProfileReq.ConnectorId==0))
  12888. json_object_object_add(SetChargingProfile, "connectorId", json_object_new_int(idxCon));
  12889. fprintf(outfile,"%s\n",json_object_to_json_string_ext(SetChargingProfile, JSON_C_TO_STRING_PLAIN));
  12890. fclose(infile);
  12891. fclose(outfile);
  12892. sprintf(rmFileCmd,"rm -f %s",filename);
  12893. system(rmFileCmd);
  12894. rename(tempfile, filename);
  12895. }
  12896. else
  12897. {
  12898. // Profile is not empty
  12899. int ChargingProfileAdded = FALSE;
  12900. while (fgets(dataLine, ARRAY_SIZE(dataLine), infile) != NULL)
  12901. {
  12902. dataLine[strlen(dataLine) - 1] = '\0'; // eat the newline fgets() stores
  12903. json_object *tmpChargingProfile;
  12904. tmpChargingProfile = json_tokener_parse(dataLine);
  12905. if(!is_error(SetChargingProfile))
  12906. {
  12907. if(json_object_object_get(tmpChargingProfile, "csChargingProfiles") != NULL)
  12908. {
  12909. if(json_object_object_get(json_object_object_get(tmpChargingProfile, "csChargingProfiles"), "chargingProfileId") != NULL)
  12910. {
  12911. tempchargingProfileIdInt = json_object_get_int(json_object_object_get(json_object_object_get(tmpChargingProfile, "csChargingProfiles"), "chargingProfileId"));
  12912. }
  12913. if(json_object_object_get(json_object_object_get(tmpChargingProfile, "csChargingProfiles"), "stackLevel") != NULL)
  12914. {
  12915. tempstackLevelInt = json_object_get_int(json_object_object_get(json_object_object_get(tmpChargingProfile, "csChargingProfiles"), "stackLevel"));
  12916. }
  12917. }
  12918. }
  12919. json_object_put(tmpChargingProfile);
  12920. if((tempchargingProfileIdInt == SetProfileReq.ChargingProfile.ChargingProfileId))
  12921. {
  12922. if(ChargingProfileAdded == FALSE)
  12923. {
  12924. if((strcmp((char*)SetProfileReq.ChargingProfile.ChargingProfilePurpose, ChargingProfilePurposeTypeStr[TxDefaultProfile]) == 0) && (SetProfileReq.ConnectorId==0))
  12925. json_object_object_add(SetChargingProfile, "connectorId", json_object_new_int(idxCon));
  12926. fprintf(outfile,"%s\n",json_object_to_json_string_ext(SetChargingProfile, JSON_C_TO_STRING_PLAIN));
  12927. ChargingProfileAdded = TRUE;
  12928. }
  12929. }
  12930. else if(tempstackLevelInt == SetProfileReq.ChargingProfile.StackLevel)
  12931. {
  12932. if(ChargingProfileAdded == FALSE)
  12933. {
  12934. if((strcmp((char*)SetProfileReq.ChargingProfile.ChargingProfilePurpose, ChargingProfilePurposeTypeStr[TxDefaultProfile]) == 0) && (SetProfileReq.ConnectorId==0))
  12935. json_object_object_add(SetChargingProfile, "connectorId", json_object_new_int(idxCon));
  12936. fprintf(outfile,"%s\n",json_object_to_json_string_ext(SetChargingProfile, JSON_C_TO_STRING_PLAIN));
  12937. ChargingProfileAdded = TRUE;
  12938. }
  12939. }
  12940. else
  12941. {
  12942. fprintf(outfile,"%s\n",dataLine);
  12943. if(ChargingProfileAdded == FALSE)
  12944. {
  12945. if((strcmp((char*)SetProfileReq.ChargingProfile.ChargingProfilePurpose, ChargingProfilePurposeTypeStr[TxDefaultProfile]) == 0) && (SetProfileReq.ConnectorId==0))
  12946. json_object_object_add(SetChargingProfile, "connectorId", json_object_new_int(idxCon));
  12947. fprintf(outfile,"%s\n",json_object_to_json_string_ext(SetChargingProfile, JSON_C_TO_STRING_PLAIN));
  12948. ChargingProfileAdded = TRUE;
  12949. }
  12950. }
  12951. } // end of while loop
  12952. fclose(infile);
  12953. fclose(outfile);
  12954. sprintf(rmFileCmd,"rm -f %s",filename);
  12955. system(rmFileCmd);
  12956. rename(tempfile, filename);
  12957. }
  12958. }
  12959. sleep(1);
  12960. result = TRUE;
  12961. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Accepted] );
  12962. }
  12963. end:
  12964. json_object_put(SetChargingProfile);
  12965. if(strcmp(comfirmstr, ChargingProfileStatusStr[ChargingProfileStatus_Accepted]) == 0)
  12966. {
  12967. if(SetProfileReq.ConnectorId == 0)
  12968. {
  12969. for(uint8_t idx=0;idx<gunTotalNumber;idx++)
  12970. {
  12971. checkCompositeSchedule((idx+1), 86400, &ShmOCPP16Data->SmartChargingProfile[idx], TRUE);
  12972. }
  12973. }
  12974. else
  12975. checkCompositeSchedule(SetProfileReq.ConnectorId, 86400, &ShmOCPP16Data->SmartChargingProfile[SetProfileReq.ConnectorId-1], TRUE);
  12976. }
  12977. sendSetChargingProfileConfirmation(uuid, comfirmstr);
  12978. system("/bin/fsync -d /dev/mtdblock13;/bin/sync &");
  12979. return result;
  12980. }
  12981. int handleTriggerMessageRequest(char *uuid, char *payload)
  12982. {
  12983. mtrace();
  12984. int result = FAIL;
  12985. int connectorIdIsNULL = FALSE;
  12986. int connectorIdInt =0;
  12987. char sstr[40]={0},sstrtemp[100]={ 0 };
  12988. char requestedMessagestr[40]={0};
  12989. char comfirmstr[20]={0};
  12990. int c = 0;
  12991. char *loc;
  12992. DEBUG_INFO("handleTriggerMessageRequest\n");
  12993. //[2,"266e23f4-27a4-41cf-84cb-aadf56b9523f","TriggerMessage",{"requestedMessage":"DiagnosticsStatusNotification","connectorId":1}]
  12994. strcpy(sstrtemp, stringtrimspace(payload));
  12995. c = 0;
  12996. loc = strstr(sstrtemp, "requestedMessage");
  12997. while (loc[3+strlen("requestedMessage")+c] != '\"')
  12998. {
  12999. sstr[c] = loc[3+strlen("requestedMessage")+c];
  13000. c++;
  13001. }
  13002. sstr[c] = '\0';
  13003. strcpy(requestedMessagestr, sstr);
  13004. c = 0;
  13005. loc = strstr(sstrtemp, "connectorId");
  13006. if(loc == NULL)
  13007. {
  13008. connectorIdIsNULL = TRUE;
  13009. }
  13010. else
  13011. {
  13012. memset(sstr ,0, ARRAY_SIZE(sstr) );
  13013. while ((loc[strlen("connectorId")+2+c] != ',')&&(loc[strlen("connectorId")+2+c] != '}'))
  13014. {
  13015. sstr[c] = loc[strlen("connectorId")+2+c];
  13016. //printf("i=%d sstr=%c\n",c, sstr[c]);
  13017. c++;
  13018. }
  13019. sstr[c] = '\0';
  13020. connectorIdInt = atoi(sstr);
  13021. }
  13022. if((connectorIdIsNULL == TRUE) || ((connectorIdIsNULL == FALSE) && ((connectorIdInt > 0) && (connectorIdInt <= gunTotalNumber /*(CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY)*/ ))) )
  13023. {
  13024. sprintf((char *)ShmOCPP16Data->TriggerMessage[connectorIdInt -1].RequestedMessage, "%s" ,requestedMessagestr);
  13025. ShmOCPP16Data->TriggerMessage[connectorIdInt -1].ConnectorId = connectorIdInt;
  13026. if((strcmp(requestedMessagestr, MessageTriggerStr[FirmwareStatusNotification]) != 0) &&
  13027. (strcmp(requestedMessagestr, MessageTriggerStr[DiagnosticsStatusNotification]) != 0) &&
  13028. (strcmp(requestedMessagestr, MessageTriggerStr[BootNotification]) != 0 ) &&
  13029. (strcmp(requestedMessagestr, MessageTriggerStr[Heartbeat]) != 0) &&
  13030. (strcmp(requestedMessagestr, MessageTriggerStr[MeterValues]) != 0) &&
  13031. (strcmp(requestedMessagestr, MessageTriggerStr[StatusNotification]) != 0 ))
  13032. {
  13033. sprintf(comfirmstr, "%s",TriggerMessageStatusStr[TriggerMessageStatus_NotImplemented] );
  13034. sendTriggerMessageConfirmation(uuid,comfirmstr);
  13035. return TRUE;
  13036. }
  13037. else
  13038. {
  13039. sprintf(comfirmstr, "%s",TriggerMessageStatusStr[TriggerMessageStatus_Accepted] );
  13040. sendTriggerMessageConfirmation(uuid,comfirmstr);
  13041. }
  13042. }
  13043. else if(connectorIdIsNULL == FALSE && ((connectorIdInt <= 0) || (connectorIdInt > gunTotalNumber /*(CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY)*/) ))
  13044. {
  13045. sprintf(comfirmstr, "%s",TriggerMessageStatusStr[TriggerMessageStatus_Rejected] );
  13046. sendTriggerMessageConfirmation(uuid,comfirmstr);
  13047. return TRUE;
  13048. }
  13049. //==========================
  13050. // Trigger message
  13051. //==========================
  13052. if( strcmp(requestedMessagestr, MessageTriggerStr[FirmwareStatusNotification]) == 0)
  13053. {
  13054. if((strlen((char*)ShmOCPP16Data->FirmwareStatusNotification.Status) == 0) ||
  13055. ((FirmwareStatusNotificationStatus != FIRMWARE_STATUS_DOWNLOADING) && (FirmwareStatusNotificationStatus != FIRMWARE_STATUS_DOWNLOADED) && (FirmwareStatusNotificationStatus != FIRMWARE_STATUS_IDLE) && (FirmwareStatusNotificationStatus != FIRMWARE_STATUS_INSTALLING)))
  13056. {
  13057. FirmwareStatusNotificationStatus = FIRMWARE_STATUS_IDLE;
  13058. sprintf((char*)ShmOCPP16Data->FirmwareStatusNotification.Status, "%s", FirmwareStatusStr[FirmwareStatus_Idle]);
  13059. }
  13060. ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationReq = 1;
  13061. }
  13062. else if(strcmp(requestedMessagestr, MessageTriggerStr[DiagnosticsStatusNotification]) == 0 )
  13063. {
  13064. if(strlen((char*)ShmOCPP16Data->DiagnosticsStatusNotification.Status) == 0)
  13065. sprintf((char*)ShmOCPP16Data->DiagnosticsStatusNotification.Status, "%s", DiagnosticsStatusStr[DiagnosticsStatus_Idle]);
  13066. ShmOCPP16Data->SpMsg.bits.DiagnosticsStatusNotificationReq = 1;
  13067. }
  13068. else if(strcmp(requestedMessagestr, MessageTriggerStr[BootNotification]) == 0 )
  13069. {
  13070. //sendBootNotificationRequest();
  13071. server_sign = FALSE;
  13072. }
  13073. else if(strcmp(requestedMessagestr, MessageTriggerStr[Heartbeat]) == 0 )
  13074. {
  13075. refreshStartTimer(&clientTime.Heartbeat);
  13076. clientTime.Heartbeat.tv_sec -= ShmOCPP16Data->BootNotification.ResponseHeartbeatInterval;
  13077. }
  13078. else if (strcmp(requestedMessagestr, MessageTriggerStr[MeterValues]) == 0 )
  13079. {
  13080. if(connectorIdIsNULL == FALSE)
  13081. {
  13082. if((connectorIdInt > 0) && ((connectorIdInt -1) < gunTotalNumber))
  13083. {
  13084. //sendMeterValuesRequest((connectorIdInt -1), ReadingContext_Trigger);
  13085. cpinitateMsg.bits[connectorIdInt -1].TriggerMeterValue = 1;
  13086. }
  13087. }
  13088. else
  13089. {
  13090. for(int idx=0;idx< gunTotalNumber;idx++)
  13091. {
  13092. //sendMeterValuesRequest(idx, ReadingContext_Trigger);
  13093. cpinitateMsg.bits[idx].TriggerMeterValue = 1;
  13094. }
  13095. }
  13096. }
  13097. else if(strcmp(requestedMessagestr, MessageTriggerStr[StatusNotification]) == 0 )
  13098. {
  13099. if(connectorIdIsNULL == FALSE)
  13100. {
  13101. if((connectorIdInt > 0) && ((connectorIdInt-1) < gunTotalNumber))
  13102. {
  13103. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].TriggerMessageReq = 1;
  13104. cpinitateMsg.bits[connectorIdInt-1].TriggerStatusNotificationReq = 1;
  13105. //clientTime.StatusNotification[connectorIdInt-1] = time((time_t*)NULL);
  13106. }
  13107. }
  13108. else
  13109. {
  13110. for(int idx=0;idx< gunTotalNumber;idx++)
  13111. {
  13112. ShmOCPP16Data->CsMsg.bits[idx].TriggerMessageReq = 1;
  13113. cpinitateMsg.bits[idx].TriggerStatusNotificationReq = 1;
  13114. //clientTime.StatusNotification[idx] = time((time_t*)NULL);
  13115. }
  13116. }
  13117. }
  13118. return result;
  13119. }
  13120. int handleUnlockConnectorRequest(char *uuid, char *payload)
  13121. {
  13122. mtrace();
  13123. int result = FAIL;
  13124. int connectorIdInt =0;
  13125. char comfirmstr[20]={0};
  13126. int tempIndex = 0;
  13127. json_object *UnlockConnector;
  13128. //[2,"ba1cbd49-2a76-493a-8f76-fa23e7606532","UnlockConnector",{"connectorId":1}]
  13129. DEBUG_INFO("handleUnlockConnectorRequest ...\n");
  13130. UnlockConnector = json_tokener_parse(payload);
  13131. if(!is_error(UnlockConnector))
  13132. {
  13133. if(json_object_object_get(UnlockConnector, "connectorId") != NULL)
  13134. {
  13135. connectorIdInt = json_object_get_int(json_object_object_get(UnlockConnector, "connectorId"));
  13136. }
  13137. }
  13138. json_object_put(UnlockConnector);
  13139. DEBUG_INFO("Unlock connectorIdInt = %d\n",connectorIdInt);
  13140. if(gunTotalNumber == 0)
  13141. {
  13142. sprintf(comfirmstr, "%s", UnlockStatusStr[UnlockStatus_NotSupported] );
  13143. goto end;
  13144. }
  13145. else if((connectorIdInt > gunTotalNumber/*CHAdeMO_QUANTITY+ CCS_QUANTITY + GB_QUANTITY*/) || (connectorIdInt <= 0))
  13146. {
  13147. //sprintf(comfirmstr, "%s", UnlockStatusStr[UnlockStatus_NotSupported] );
  13148. sprintf(comfirmstr, "%s", UnlockStatusStr[UnlockStatus_NotSupported] );
  13149. goto end;
  13150. }
  13151. else
  13152. {
  13153. //check Transaction active
  13154. if(gunType[connectorIdInt-1] == GUN_TYPE_CHAdeMO)
  13155. {
  13156. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  13157. {
  13158. tempIndex = (((connectorIdInt -1)==2) ? 1: 0);
  13159. }
  13160. else
  13161. {
  13162. tempIndex = connectorIdInt -1;
  13163. }
  13164. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  13165. {
  13166. if ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex ))
  13167. {
  13168. //stop Transaction
  13169. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].UnlockConnectorReq = 1;
  13170. }
  13171. }
  13172. }
  13173. else if(gunType[connectorIdInt-1] == GUN_TYPE_CCS)
  13174. {
  13175. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  13176. {
  13177. tempIndex = (((connectorIdInt -1)==2) ? 1: 0);
  13178. }
  13179. else
  13180. {
  13181. tempIndex = connectorIdInt -1;
  13182. }
  13183. for (int index = 0; index < CCS_QUANTITY; index++)
  13184. {
  13185. if ((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex ))
  13186. {
  13187. //stop Transaction
  13188. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].UnlockConnectorReq = 1;
  13189. }
  13190. }
  13191. }
  13192. else if(gunType[connectorIdInt-1] == GUN_TYPE_GBT)
  13193. {
  13194. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  13195. {
  13196. tempIndex = (((connectorIdInt -1)==2) ? 1: 0);
  13197. }
  13198. else
  13199. {
  13200. tempIndex = connectorIdInt -1;
  13201. }
  13202. for (int index = 0; index < GB_QUANTITY; index++)
  13203. {
  13204. if ((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex ))
  13205. {
  13206. //stop Transaction
  13207. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].UnlockConnectorReq = 1;
  13208. }
  13209. }
  13210. }
  13211. else if(gunType[connectorIdInt-1] == GUN_TYPE_DO)
  13212. {
  13213. tempIndex = connectorIdInt -1;
  13214. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  13215. {
  13216. if ((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex ))
  13217. {
  13218. //stop Transaction
  13219. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].UnlockConnectorReq = 1;
  13220. }
  13221. }
  13222. }
  13223. else
  13224. {
  13225. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  13226. {
  13227. tempIndex = 2;
  13228. }
  13229. else
  13230. {
  13231. tempIndex = connectorIdInt-1;
  13232. }
  13233. for (int index = 0; index < AC_QUANTITY; index++)
  13234. {
  13235. if ((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex ))
  13236. {
  13237. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].UnlockConnectorReq = 1;
  13238. }
  13239. }
  13240. }
  13241. ShmOCPP16Data->UnlockConnector[connectorIdInt-1].ConnectorId = connectorIdInt;
  13242. strcpy((char *)ShmOCPP16Data->UnlockConnector[connectorIdInt-1].guid, uuid);
  13243. result = TRUE;
  13244. return result;
  13245. }
  13246. end:
  13247. //json_object_put(obj); --- remove temporally
  13248. sendUnlockConnectorConfirmation(uuid, comfirmstr);
  13249. return result;
  13250. }
  13251. static char UpdateFirmwarepayloadData[300]={0};
  13252. int handleUpdateFirmwareRequest(char *uuid, char *payload)
  13253. {
  13254. mtrace();
  13255. int result = FAIL;
  13256. pthread_t t;
  13257. sendUpdateFirmwareConfirmation(uuid);
  13258. memset(UpdateFirmwarepayloadData, 0, 300);
  13259. strcpy(UpdateFirmwarepayloadData, stringtrimspace(payload));
  13260. if(!interLock.isUpdateFirmwareGoing)
  13261. {
  13262. interLock.isUpdateFirmwareGoing = 1;
  13263. pthread_create(&t, NULL, UpdateFirmwareProcess, stringtrimspace(payload));
  13264. sleep(1);
  13265. }
  13266. else
  13267. DEBUG_WARN("Other UpdateFirmware request on going.\n");
  13268. ShmOCPP16Data->MsMsg.bits.UpdateFirmwareConf =1;
  13269. return result;
  13270. }
  13271. void *UpdateFirmwareProcess(void *data)
  13272. {
  13273. pthread_detach(pthread_self());
  13274. mtrace();
  13275. int retriesInt =0, retryIntervalInt=0;
  13276. char protocol[10], user[64],password[64],host[128], path[512], ftppath[512],host1[128],path1[512];
  13277. int port=0;
  13278. char locationstr[1024]={0}, retrieveDatestr[36]={0};
  13279. int isSuccess = 0;
  13280. char ftpbuf[1024];
  13281. char temp[1024];
  13282. char * pch;
  13283. DEBUG_INFO("handleUpdateFirmwareRequest ...\n");
  13284. json_object *UpdateFirmware;
  13285. UpdateFirmware = json_tokener_parse(UpdateFirmwarepayloadData);
  13286. if(!is_error(UpdateFirmware))
  13287. {
  13288. // Required data
  13289. if(json_object_object_get(UpdateFirmware, "location") != NULL)
  13290. sprintf((char*)locationstr, "%s", json_object_get_string(json_object_object_get(UpdateFirmware, "location")));
  13291. if(json_object_object_get(UpdateFirmware, "retrieveDate") != NULL)
  13292. sprintf((char*)retrieveDatestr, "%s", json_object_get_string(json_object_object_get(UpdateFirmware, "retrieveDate")));
  13293. // Optional data
  13294. if(json_object_object_get(UpdateFirmware, "retries"))
  13295. {
  13296. retriesInt = json_object_get_int(json_object_object_get(UpdateFirmware, "retries"));
  13297. }
  13298. if(json_object_object_get(UpdateFirmware, "retryInterval"))
  13299. {
  13300. retryIntervalInt = json_object_get_int(json_object_object_get(UpdateFirmware, "retryInterval"));
  13301. }
  13302. }
  13303. json_object_put(UpdateFirmware);
  13304. memset(ftppath, 0, ARRAY_SIZE(ftppath));
  13305. memset(path, 0, ARRAY_SIZE(path));
  13306. // Wait retrieveData
  13307. if(strlen(retrieveDatestr) > 10)
  13308. {
  13309. do
  13310. {
  13311. sleep(1);
  13312. }while(!isOvertNow((uint8_t*)retrieveDatestr));
  13313. }
  13314. // Ready to download
  13315. system("rm -f /mnt/*");
  13316. if(strncmp(locationstr,"http", 4) == 0)
  13317. {
  13318. sscanf(locationstr,"%[^:]:%*2[/]%[^/]/%199[^\n]", protocol, host, path);
  13319. sprintf(ftppath,"/%s", path);
  13320. DEBUG_INFO("locationstr: %s\n", locationstr);
  13321. DEBUG_INFO("protocol: %s\n",protocol);
  13322. DEBUG_INFO("host: %s\n",host);
  13323. DEBUG_INFO("path: %s\n",path);
  13324. DEBUG_INFO("ftppath: %s\n",ftppath);
  13325. int ftppathlen=strlen(ftppath);
  13326. int i=1;
  13327. char filenametemp[50];
  13328. while(i < ftppathlen)
  13329. {
  13330. int len=ftppathlen-i;
  13331. if(ftppath[len]== 47) // '/' ascll code: 47
  13332. {
  13333. DEBUG_INFO("compare '/' all right\n");
  13334. break;
  13335. }
  13336. i=i+1;
  13337. }
  13338. memset(filenametemp, 0, ARRAY_SIZE(filenametemp));
  13339. strncpy(filenametemp, ftppath+(ftppathlen-i+1), i+1);
  13340. filenametemp[i+1] = 0;
  13341. do
  13342. {
  13343. sprintf((char*)ShmOCPP16Data->FirmwareStatusNotification.Status, "%s",FirmwareStatusStr[FirmwareStatus_Downloading]);
  13344. ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationReq = 1;
  13345. sleep(1);
  13346. isSuccess = httpDownLoadFile(host, ftppath, filenametemp, locationstr);
  13347. if(!isSuccess)
  13348. {
  13349. sprintf((char*)ShmOCPP16Data->FirmwareStatusNotification.Status, "%s",FirmwareStatusStr[FirmwareStatus_DownloadFailed]);
  13350. ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationReq = 1;
  13351. if(retriesInt>0)sleep(retryIntervalInt);else sleep(1);
  13352. sprintf((char*)ShmOCPP16Data->FirmwareStatusNotification.Status, "%s",FirmwareStatusStr[FirmwareStatus_Idle]);
  13353. ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationReq = 1;
  13354. }
  13355. else
  13356. {
  13357. sprintf((char*)ShmOCPP16Data->FirmwareStatusNotification.Status, "%s",FirmwareStatusStr[FirmwareStatus_Downloaded]);
  13358. ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationReq = 1;
  13359. }
  13360. retriesInt--;
  13361. }while((isSuccess == 0)&&(retriesInt >= 0));
  13362. }
  13363. else if(strncmp(locationstr,"sftp", 4) == 0) // sftp
  13364. {
  13365. memset(ftpbuf, 0, ARRAY_SIZE(ftpbuf));
  13366. memset(temp, 0, ARRAY_SIZE(temp));
  13367. //DEBUG_INFO("locationstr=%s\n",locationstr);
  13368. strcpy(ftpbuf, locationstr);
  13369. int ftppathlen=strlen(ftpbuf);
  13370. int i=1;
  13371. char filenametemp[50];
  13372. while(i < ftppathlen)
  13373. {
  13374. int len=ftppathlen-i;
  13375. if(ftpbuf[len]== 47) // '/' ascii code: 47
  13376. {
  13377. DEBUG_INFO(" compare '/' all right\n");
  13378. break;
  13379. }
  13380. i=i+1;
  13381. }
  13382. memset(filenametemp, 0, ARRAY_SIZE(filenametemp));
  13383. strncpy(filenametemp, ftpbuf+(ftppathlen-i+1), i+1);
  13384. filenametemp[i+1] = 0;
  13385. strncpy(temp, ftpbuf, ftppathlen-i+1);
  13386. pch=strchr(temp,'@');
  13387. if(pch==NULL)
  13388. {
  13389. sscanf(temp,"%[^:]:%*2[/]%[^:]:%i/%[a-zA-Z0-9._/-]",
  13390. protocol, host, &port, path);
  13391. strcpy(user,"anonymous");
  13392. strcpy(password,"");
  13393. }
  13394. else
  13395. {
  13396. sscanf(temp,"%[^:]:%*2[/]%[^@]@%[^:]:%i/%199[^\n]",
  13397. protocol, user, host, &port, path);
  13398. }
  13399. sscanf(host,"%[^/]%s",host1, path1);
  13400. sprintf(ftppath,"%s:/%s", host,path);
  13401. if(port == 0)
  13402. {
  13403. port = 21;
  13404. }
  13405. do
  13406. {
  13407. sprintf((char*)ShmOCPP16Data->FirmwareStatusNotification.Status, "%s",FirmwareStatusStr[FirmwareStatus_Downloading]);
  13408. ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationReq = 1;
  13409. sleep(1);
  13410. isSuccess = sftpDownLoadFile(host1, user, port, ftppath, filenametemp, locationstr);
  13411. if(!isSuccess)
  13412. {
  13413. //BulldogUtil.sleepMs(interval*1000);
  13414. DEBUG_INFO("Update firmware request and download file fail.\n");
  13415. sprintf((char*)ShmOCPP16Data->FirmwareStatusNotification.Status, "%s",FirmwareStatusStr[FirmwareStatus_DownloadFailed]);
  13416. ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationReq = 1;
  13417. if(retriesInt>0)sleep(retryIntervalInt);else sleep(1);
  13418. sprintf((char*)ShmOCPP16Data->FirmwareStatusNotification.Status, "%s",FirmwareStatusStr[FirmwareStatus_Idle]);
  13419. ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationReq = 1;
  13420. }
  13421. else
  13422. {
  13423. sprintf((char*)ShmOCPP16Data->FirmwareStatusNotification.Status, "%s",FirmwareStatusStr[FirmwareStatus_Downloaded]);
  13424. ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationReq = 1;
  13425. }
  13426. retriesInt--;
  13427. }while((!isSuccess)&&(retriesInt >= 0));
  13428. }
  13429. else if(strncmp(locationstr,"ftp", 3) == 0) // ftp
  13430. {
  13431. memset(ftpbuf, 0, ARRAY_SIZE(ftpbuf));
  13432. memset(temp, 0, ARRAY_SIZE(temp));
  13433. //DEBUG_INFO("locationstr=%s\n",locationstr);
  13434. strcpy(ftpbuf, locationstr/*"ftp://ipc_ui:pht2016@ftp.phihong.com.tw/DC/log/DemoDC1_2018-07-13_185011_PSULog.zip"*/ );
  13435. int ftppathlen=strlen(ftpbuf);
  13436. int i=1;
  13437. char filenametemp[50];
  13438. while(i < ftppathlen)
  13439. {
  13440. int len=ftppathlen-i;
  13441. if(ftpbuf[len]== 47) // '/' ascll code: 47
  13442. {
  13443. DEBUG_INFO(" compare '/' all right\n");
  13444. break;
  13445. }
  13446. i=i+1;
  13447. }
  13448. memset(filenametemp, 0, ARRAY_SIZE(filenametemp));
  13449. strncpy(filenametemp, ftpbuf+(ftppathlen-i+1), i+1);
  13450. filenametemp[i+1] = 0;
  13451. strncpy(temp, ftpbuf, ftppathlen-i+1);
  13452. pch=strchr(temp,'@');
  13453. if(pch==NULL)
  13454. {
  13455. sscanf(temp,"%[^:]:%*2[/]%[^:]:%i/%[a-zA-Z0-9._/-]",
  13456. protocol, host, &port, path);
  13457. strcpy(user,"anonymous");
  13458. strcpy(password,"");
  13459. }
  13460. else
  13461. {
  13462. sscanf(temp,"%[^:]:%*2[/]%[^:]:%[^@]@%[^:]:%i/%199[^\n]",
  13463. protocol, user, password, host, &port, path);
  13464. }
  13465. sscanf(host,"%[^/]%s",host1, path1);
  13466. sprintf(ftppath,"%s", path1);
  13467. //DEBUG_INFO("protocol =%s\n",protocol);
  13468. //DEBUG_INFO("user =%s\n",user);
  13469. //DEBUG_INFO("password =%s\n",password);
  13470. //DEBUG_INFO("host1 =%s\n",host1);
  13471. //DEBUG_INFO("port =%d\n",port);
  13472. //DEBUG_INFO("path1 =%s\n",path1);
  13473. //DEBUG_INFO("ftppath=%s\n",ftppath);
  13474. //ftpFile(host, user, password, port, ftppath, fname);
  13475. //download firmware pthred
  13476. if(port == 0)
  13477. {
  13478. port = 21;
  13479. }
  13480. do
  13481. {
  13482. sprintf((char*)ShmOCPP16Data->FirmwareStatusNotification.Status, "%s",FirmwareStatusStr[FirmwareStatus_Downloading]);
  13483. ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationReq = 1;
  13484. sleep(1);
  13485. isSuccess = ftpDownLoadFile(host1, user, password, 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(1);
  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
  13505. {
  13506. sprintf((char*)ShmOCPP16Data->FirmwareStatusNotification.Status, "%s",FirmwareStatusStr[FirmwareStatus_DownloadFailed]);
  13507. ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationReq = 1;
  13508. sleep(1);
  13509. sprintf((char*)ShmOCPP16Data->FirmwareStatusNotification.Status, "%s",FirmwareStatusStr[FirmwareStatus_Idle]);
  13510. ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationReq = 1;
  13511. }
  13512. if(strstr((char*)ShmOCPP16Data->FirmwareStatusNotification.Status, FirmwareStatusStr[FirmwareStatus_Downloaded]) != NULL)ShmOCPP16Data->MsMsg.bits.UpdateFirmwareReq = 1;
  13513. interLock.isUpdateFirmwareGoing = 0;
  13514. pthread_exit(NULL);
  13515. }
  13516. int handleCertificateSignedRequest(char *uuid, char *payload)
  13517. {
  13518. mtrace();
  13519. int result = PASS;
  13520. json_object *CertificateSigned;
  13521. DEBUG_INFO("handleCertificateSignedRequest...\n");
  13522. CertificateSigned = json_tokener_parse(payload);
  13523. if(!is_error(CertificateSigned))
  13524. {
  13525. sprintf((char*)ShmOCPP16Data->CertificateSigned.certificateChain, "%s", json_object_get_string(json_object_object_get(CertificateSigned, "certificateChain")));
  13526. }
  13527. json_object_put(CertificateSigned);
  13528. FILE *fp = fopen("/Storage/OCPP/certCP.crt", "w");
  13529. fprintf(fp, "%s", ShmOCPP16Data->CertificateSigned.certificateChain);
  13530. fclose(fp);
  13531. system("/bin/fsync -d /dev/mtdblock13;/bin/sync &");
  13532. ShmOCPP16Data->MsMsg.bits.CertificateSignedReq = 1;
  13533. sprintf((char*)ShmOCPP16Data->CertificateSigned.Response_status, "Accepted");
  13534. sendCertificateSignedConfirmation(uuid);
  13535. return result;
  13536. }
  13537. int handleDeleteCertificateRequest(char *uuid, char *payload)
  13538. {
  13539. mtrace();
  13540. int result = PASS;
  13541. json_object *DeleteCertificate;
  13542. DEBUG_INFO("handleDeleteCertificateRequest...\n");
  13543. DeleteCertificate = json_tokener_parse(payload);
  13544. if(!is_error(DeleteCertificate))
  13545. {
  13546. sprintf((char*)ShmOCPP16Data->DeleteCertificate.certificateHashData.hashAlgorithm, "%s", json_object_get_string(json_object_object_get(json_object_object_get(DeleteCertificate, "certificateHashData"), "hashAlgorithm")));
  13547. sprintf((char*)ShmOCPP16Data->DeleteCertificate.certificateHashData.issuerNameHash, "%s", json_object_get_string(json_object_object_get(json_object_object_get(DeleteCertificate, "certificateHashData"), "issuerNameHash")));
  13548. sprintf((char*)ShmOCPP16Data->DeleteCertificate.certificateHashData.issuerKeyHash, "%s", json_object_get_string(json_object_object_get(json_object_object_get(DeleteCertificate, "certificateHashData"), "issuerKeyHash")));
  13549. sprintf((char*)ShmOCPP16Data->DeleteCertificate.certificateHashData.serialNumber, "%s", json_object_get_string(json_object_object_get(json_object_object_get(DeleteCertificate, "certificateHashData"), "serialNumber")));
  13550. }
  13551. json_object_put(DeleteCertificate);
  13552. /*
  13553. * TODO: Delete certificateSigned process
  13554. */
  13555. ShmOCPP16Data->MsMsg.bits.DeleteCertificateReq = 1;
  13556. DEBUG_INFO("hashAlgorithm: %s\n", ShmOCPP16Data->DeleteCertificate.certificateHashData.hashAlgorithm);
  13557. DEBUG_INFO("issuerNameHash: %s\n", ShmOCPP16Data->DeleteCertificate.certificateHashData.issuerNameHash);
  13558. DEBUG_INFO("issuerKeyHash: %s\n", ShmOCPP16Data->DeleteCertificate.certificateHashData.issuerKeyHash);
  13559. DEBUG_INFO("serialNumber: %s\n", ShmOCPP16Data->DeleteCertificate.certificateHashData.serialNumber);
  13560. sprintf((char*)ShmOCPP16Data->DeleteCertificate.Response_status, "NotFound");
  13561. sendDeleteCertificateConfirmation(uuid);
  13562. return result;
  13563. }
  13564. int handleExtendedTriggerMessageRequest(char *uuid, char *payload)
  13565. {
  13566. mtrace();
  13567. int result = PASS;
  13568. json_object *ExtendedTriggerMessage;
  13569. DEBUG_INFO("handleExtendedTriggerMessageRequest...\n");
  13570. ExtendedTriggerMessage = json_tokener_parse(payload);
  13571. if(!is_error(ExtendedTriggerMessage))
  13572. {
  13573. sprintf((char*)ShmOCPP16Data->ExtendedTriggerMessage.requestedMessage, "%s", json_object_get_string(json_object_object_get(ExtendedTriggerMessage, "requestedMessage")));
  13574. if(json_object_object_get(ExtendedTriggerMessage, "connectorId") != NULL)
  13575. {
  13576. ShmOCPP16Data->ExtendedTriggerMessage.connectorId = json_object_get_int(json_object_object_get(ExtendedTriggerMessage, "connectorId"));
  13577. }
  13578. else
  13579. {
  13580. ShmOCPP16Data->ExtendedTriggerMessage.connectorId = -1;
  13581. }
  13582. }
  13583. json_object_put(ExtendedTriggerMessage);
  13584. DEBUG_INFO("requestedMessage: %s\n", ShmOCPP16Data->ExtendedTriggerMessage.requestedMessage);
  13585. DEBUG_INFO("connectorIdInt: %d\n", ShmOCPP16Data->ExtendedTriggerMessage.connectorId);
  13586. if((ShmOCPP16Data->ExtendedTriggerMessage.connectorId == 0) || (ShmOCPP16Data->ExtendedTriggerMessage.connectorId > gunTotalNumber))
  13587. {
  13588. sprintf((char*)ShmOCPP16Data->ExtendedTriggerMessage.Response_status, TriggerMessageStatusStr[TriggerMessageStatus_Rejected]);
  13589. }
  13590. else
  13591. {
  13592. if((strcmp((char*)ShmOCPP16Data->ExtendedTriggerMessage.requestedMessage, MessageTriggerStr[BootNotification]) != 0 ) &&
  13593. (strcmp((char*)ShmOCPP16Data->ExtendedTriggerMessage.requestedMessage, "LogStatusNotification") != 0) &&
  13594. (strcmp((char*)ShmOCPP16Data->ExtendedTriggerMessage.requestedMessage, MessageTriggerStr[FirmwareStatusNotification]) != 0) &&
  13595. (strcmp((char*)ShmOCPP16Data->ExtendedTriggerMessage.requestedMessage, MessageTriggerStr[Heartbeat]) != 0) &&
  13596. (strcmp((char*)ShmOCPP16Data->ExtendedTriggerMessage.requestedMessage, MessageTriggerStr[MeterValues]) != 0) &&
  13597. (strcmp((char*)ShmOCPP16Data->ExtendedTriggerMessage.requestedMessage, "SignChargePointCertificate") != 0 ) &&
  13598. (strcmp((char*)ShmOCPP16Data->ExtendedTriggerMessage.requestedMessage, MessageTriggerStr[StatusNotification]) != 0 ))
  13599. {
  13600. sprintf((char*)ShmOCPP16Data->ExtendedTriggerMessage.Response_status, "%s",TriggerMessageStatusStr[TriggerMessageStatus_NotImplemented] );
  13601. }
  13602. else
  13603. {
  13604. sprintf((char*)ShmOCPP16Data->ExtendedTriggerMessage.Response_status, "%s",TriggerMessageStatusStr[TriggerMessageStatus_Accepted] );
  13605. }
  13606. }
  13607. sendExtendedTriggerMessageConfirmation(uuid);
  13608. //==========================
  13609. // Trigger message
  13610. //==========================
  13611. if(strcmp((char*)ShmOCPP16Data->ExtendedTriggerMessage.requestedMessage, MessageTriggerStr[BootNotification]) == 0 )
  13612. {
  13613. //sendBootNotificationRequest();
  13614. server_sign = FALSE;
  13615. }
  13616. else if( strcmp((char*)ShmOCPP16Data->ExtendedTriggerMessage.requestedMessage, "LogStatusNotification") == 0)
  13617. {
  13618. ShmOCPP16Data->SpMsg.bits.LogStatusNotificationReq = 1;
  13619. }
  13620. else if( strcmp((char*)ShmOCPP16Data->ExtendedTriggerMessage.requestedMessage, MessageTriggerStr[FirmwareStatusNotification]) == 0)
  13621. {
  13622. if((strlen((char*)ShmOCPP16Data->FirmwareStatusNotification.Status) == 0) ||
  13623. ((FirmwareStatusNotificationStatus != FIRMWARE_STATUS_DOWNLOADING) && (FirmwareStatusNotificationStatus != FIRMWARE_STATUS_DOWNLOADED) && (FirmwareStatusNotificationStatus != FIRMWARE_STATUS_IDLE) && (FirmwareStatusNotificationStatus != FIRMWARE_STATUS_INSTALLING)))
  13624. {
  13625. FirmwareStatusNotificationStatus = FIRMWARE_STATUS_IDLE;
  13626. sprintf((char*)ShmOCPP16Data->FirmwareStatusNotification.Status, "%s", FirmwareStatusStr[FirmwareStatus_Idle]);
  13627. }
  13628. ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationReq = 1;
  13629. }
  13630. else if(strcmp((char*)ShmOCPP16Data->ExtendedTriggerMessage.requestedMessage, MessageTriggerStr[Heartbeat]) == 0 )
  13631. {
  13632. refreshStartTimer(&clientTime.Heartbeat);
  13633. clientTime.Heartbeat.tv_sec -= ShmOCPP16Data->BootNotification.ResponseHeartbeatInterval;
  13634. }
  13635. else if (strcmp((char*)ShmOCPP16Data->ExtendedTriggerMessage.requestedMessage, MessageTriggerStr[MeterValues]) == 0 )
  13636. {
  13637. if((ShmOCPP16Data->ExtendedTriggerMessage.connectorId > 0) && (ShmOCPP16Data->ExtendedTriggerMessage.connectorId <= gunTotalNumber))
  13638. {
  13639. cpinitateMsg.bits[ShmOCPP16Data->ExtendedTriggerMessage.connectorId-1].TriggerMeterValue = 1;
  13640. }
  13641. else
  13642. {
  13643. for(int idx=0;idx< gunTotalNumber;idx++)
  13644. {
  13645. //sendMeterValuesRequest(idx, ReadingContext_Trigger);
  13646. cpinitateMsg.bits[idx].TriggerMeterValue = 1;
  13647. }
  13648. }
  13649. }
  13650. else if(strcmp((char*)ShmOCPP16Data->ExtendedTriggerMessage.requestedMessage, "SignChargePointCertificate") == 0 )
  13651. {
  13652. ShmOCPP16Data->SpMsg.bits.SignCertificateReq = 1;
  13653. if(access("/Storage/OCPP/certCP.csr",F_OK) == -1)
  13654. {
  13655. 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\" &");
  13656. }
  13657. }
  13658. else if(strcmp((char*)ShmOCPP16Data->ExtendedTriggerMessage.requestedMessage, MessageTriggerStr[StatusNotification]) == 0 )
  13659. {
  13660. if((ShmOCPP16Data->ExtendedTriggerMessage.connectorId > 0) && (ShmOCPP16Data->ExtendedTriggerMessage.connectorId <= gunTotalNumber))
  13661. {
  13662. cpinitateMsg.bits[ShmOCPP16Data->ExtendedTriggerMessage.connectorId -1].StatusNotificationReq = 1;
  13663. }
  13664. else
  13665. {
  13666. for(int idx=0;idx< gunTotalNumber;idx++)
  13667. cpinitateMsg.bits[idx].StatusNotificationReq = 1;
  13668. }
  13669. }
  13670. return result;
  13671. }
  13672. int handleGetInstalledCertificateIdsRequest(char *uuid, char *payload)
  13673. {
  13674. mtrace();
  13675. int result = PASS;
  13676. json_object *GetInstalledCertificateIds;
  13677. DEBUG_INFO("handleGetInstalledCertificateIdsRequest...\n");
  13678. GetInstalledCertificateIds = json_tokener_parse(payload);
  13679. if(!is_error(GetInstalledCertificateIds))
  13680. {
  13681. sprintf((char*)ShmOCPP16Data->GetInstalledCertificateIds.certificateType, "%s", json_object_get_string(json_object_object_get(GetInstalledCertificateIds, "certificateType")));
  13682. }
  13683. json_object_put(GetInstalledCertificateIds);
  13684. /*
  13685. * TODO: Return installed certificate process
  13686. */
  13687. ShmOCPP16Data->MsMsg.bits.GetInstalledCertificateIdsReq = 1;
  13688. DEBUG_INFO("requestedMessage: %s\n", (char*)ShmOCPP16Data->GetInstalledCertificateIds.certificateType);
  13689. memset(ShmOCPP16Data->GetInstalledCertificateIds.Response_certificateHashData, 0x00, ARRAY_SIZE(ShmOCPP16Data->GetInstalledCertificateIds.Response_certificateHashData)*sizeof(struct CertificateHashDataType));
  13690. sprintf((char*)ShmOCPP16Data->GetInstalledCertificateIds.Response_status, "NotFound");
  13691. sendGetInstalledCertificateIdsConfirmation(uuid);
  13692. return result;
  13693. }
  13694. int handleGetLogRequest(char *uuid, char *payload)
  13695. {
  13696. mtrace();
  13697. int result = PASS;
  13698. json_object *GetLog;
  13699. DEBUG_INFO("handleGetLogRequest...\n");
  13700. GetLog = json_tokener_parse(payload);
  13701. if(!is_error(GetLog))
  13702. {
  13703. sprintf((char*)ShmOCPP16Data->GetLog.logType, "%s", json_object_get_string(json_object_object_get(GetLog, "logType")));
  13704. ShmOCPP16Data->GetLog.requestId = json_object_get_int(json_object_object_get(GetLog, "requestId"));
  13705. if(json_object_object_get(GetLog, "retries") != NULL)
  13706. {
  13707. ShmOCPP16Data->GetLog.retries = json_object_get_int(json_object_object_get(GetLog, "retries"));
  13708. }
  13709. if(json_object_object_get(GetLog, "retryInterval") != NULL)
  13710. {
  13711. ShmOCPP16Data->GetLog.retryInterval = json_object_get_int(json_object_object_get(GetLog, "retryInterval"));
  13712. }
  13713. sprintf((char*)ShmOCPP16Data->GetLog.log.remoteLocation, "%s", json_object_get_string(json_object_object_get(json_object_object_get(GetLog, "log"), "remoteLocation")));
  13714. if(json_object_object_get(json_object_object_get(GetLog, "log"), "oldestTimestamp") != NULL)
  13715. {
  13716. sprintf((char*)ShmOCPP16Data->GetLog.log.oldestTimestamp, "%s", json_object_get_string(json_object_object_get(json_object_object_get(GetLog, "log"), "oldestTimestamp")));
  13717. }
  13718. if(json_object_object_get(json_object_object_get(GetLog, "log"), "latestTimestamp") != NULL)
  13719. {
  13720. sprintf((char*)ShmOCPP16Data->GetLog.log.latestTimestamp, "%s", json_object_get_string(json_object_object_get(json_object_object_get(GetLog, "log"), "latestTimestamp")));
  13721. }
  13722. }
  13723. json_object_put(GetLog);
  13724. /*
  13725. * TODO: Upload log process
  13726. */
  13727. ShmOCPP16Data->MsMsg.bits.GetLogReq = 1;
  13728. DEBUG_INFO("logType: %s\n", ShmOCPP16Data->GetLog.logType);
  13729. DEBUG_INFO("requestId: %d\n", ShmOCPP16Data->GetLog.requestId);
  13730. DEBUG_INFO("retries: %d\n", ShmOCPP16Data->GetLog.retries);
  13731. DEBUG_INFO("retryInterval: %d\n", ShmOCPP16Data->GetLog.retryInterval);
  13732. DEBUG_INFO("remoteLocation: %s\n", ShmOCPP16Data->GetLog.log.remoteLocation);
  13733. DEBUG_INFO("oldestTimestamp: %s\n", ShmOCPP16Data->GetLog.log.oldestTimestamp);
  13734. DEBUG_INFO("latestTimestamp: %s\n", ShmOCPP16Data->GetLog.log.latestTimestamp);
  13735. sprintf((char*)ShmOCPP16Data->GetLog.Response_status, "Rejected");
  13736. sendGetLogConfirmation(uuid);
  13737. return result;
  13738. }
  13739. int handleInstallCertificateRequest(char *uuid, char *payload)
  13740. {
  13741. mtrace();
  13742. int result = PASS;
  13743. json_object *InstallCertificate;
  13744. DEBUG_INFO("handleInstallCertificateRequest...\n");
  13745. InstallCertificate = json_tokener_parse(payload);
  13746. if(!is_error(InstallCertificate))
  13747. {
  13748. sprintf((char*)ShmOCPP16Data->InstallCertificate.certificateType, "%s", json_object_get_string(json_object_object_get(InstallCertificate, "certificateType")));
  13749. sprintf((char*)ShmOCPP16Data->InstallCertificate.certificate, "%s", json_object_get_string(json_object_object_get(InstallCertificate, "certificate")));
  13750. /*
  13751. * TODO: Install certificate process
  13752. */
  13753. ShmOCPP16Data->MsMsg.bits.InstallCertificateReq = 1;
  13754. DEBUG_INFO("certificateType: %s\n", (char*)ShmOCPP16Data->InstallCertificate.certificateType);
  13755. DEBUG_INFO("certificate: %s\n", (char*)ShmOCPP16Data->InstallCertificate.certificate);
  13756. sprintf((char*)ShmOCPP16Data->InstallCertificate.Response_status, "Rejected");
  13757. sendInstallCertificateConfirmation(uuid);
  13758. }
  13759. json_object_put(InstallCertificate);
  13760. return result;
  13761. }
  13762. int handleSignedUpdateFirmwareRequest(char *uuid, char *payload)
  13763. {
  13764. mtrace();
  13765. int result = PASS;
  13766. json_object *SignedUpdateFirmware;
  13767. DEBUG_INFO("handleSignedUpdateFirmwareRequest...\n");
  13768. SignedUpdateFirmware = json_tokener_parse(payload);
  13769. if(!is_error(SignedUpdateFirmware))
  13770. {
  13771. if(json_object_object_get(SignedUpdateFirmware, "retries") != NULL)
  13772. {
  13773. ShmOCPP16Data->SignedUpdateFirmware.retries = json_object_get_int(json_object_object_get(SignedUpdateFirmware, "retries"));
  13774. }
  13775. if(json_object_object_get(SignedUpdateFirmware, "retryInterval") != NULL)
  13776. {
  13777. ShmOCPP16Data->SignedUpdateFirmware.retryInterval = json_object_get_int(json_object_object_get(SignedUpdateFirmware, "retryInterval"));
  13778. }
  13779. ShmOCPP16Data->SignedUpdateFirmware.requestId = json_object_get_int(json_object_object_get(SignedUpdateFirmware, "requestId"));
  13780. sprintf((char*)ShmOCPP16Data->SignedUpdateFirmware.firmware.location, "%s", json_object_get_string(json_object_object_get(json_object_object_get(SignedUpdateFirmware, "firmware"), "location")));
  13781. sprintf((char*)ShmOCPP16Data->SignedUpdateFirmware.firmware.retrieveDateTime, "%s", json_object_get_string(json_object_object_get(json_object_object_get(SignedUpdateFirmware, "firmware"), "retrieveDateTime")));
  13782. if(json_object_object_get(json_object_object_get(SignedUpdateFirmware, "firmware"), "installDateTime") != NULL)
  13783. {
  13784. sprintf((char*)ShmOCPP16Data->SignedUpdateFirmware.firmware.installDateTime, "%s", json_object_get_string(json_object_object_get(json_object_object_get(SignedUpdateFirmware, "firmware"), "installDateTime")));
  13785. }
  13786. sprintf((char*)ShmOCPP16Data->SignedUpdateFirmware.firmware.signingCertificate, "%s", json_object_get_string(json_object_object_get(json_object_object_get(SignedUpdateFirmware, "firmware"), "signingCertificate")));
  13787. sprintf((char*)ShmOCPP16Data->SignedUpdateFirmware.firmware.signature, "%s", json_object_get_string(json_object_object_get(json_object_object_get(SignedUpdateFirmware, "firmware"), "signature")));
  13788. }
  13789. json_object_put(SignedUpdateFirmware);
  13790. /*
  13791. * TODO: Upgrade firmware process
  13792. */
  13793. ShmOCPP16Data->MsMsg.bits.SignedUpdateFirmwareReq = 1;
  13794. DEBUG_INFO("retries: %d\n", ShmOCPP16Data->SignedUpdateFirmware.retries);
  13795. DEBUG_INFO("retryInterval: %d\n", ShmOCPP16Data->SignedUpdateFirmware.retryInterval);
  13796. DEBUG_INFO("requestId: %d\n", ShmOCPP16Data->SignedUpdateFirmware.requestId);
  13797. DEBUG_INFO("location: %s\n", ShmOCPP16Data->SignedUpdateFirmware.firmware.location);
  13798. DEBUG_INFO("retrieveDateTime: %s\n", ShmOCPP16Data->SignedUpdateFirmware.firmware.retrieveDateTime);
  13799. DEBUG_INFO("installDateTime: %s\n", ShmOCPP16Data->SignedUpdateFirmware.firmware.installDateTime);
  13800. DEBUG_INFO("signingCertificate: %s\n", ShmOCPP16Data->SignedUpdateFirmware.firmware.signingCertificate);
  13801. DEBUG_INFO("signature: %s\n", ShmOCPP16Data->SignedUpdateFirmware.firmware.signature);
  13802. sprintf((char*)ShmOCPP16Data->SignedUpdateFirmware.Response_status, "Rejected");
  13803. sendInstallCertificateConfirmation(uuid);
  13804. return result;
  13805. }
  13806. int handleUnknownRequest(char *uuid, char *payload)
  13807. {
  13808. mtrace();
  13809. int result = PASS;
  13810. DEBUG_INFO("handleUnknownRequest...\n");
  13811. sendUnknownConfirmation(uuid);
  13812. result = PASS;
  13813. return result;
  13814. }
  13815. //==========================================
  13816. // Handle server response routine
  13817. //==========================================
  13818. void handleAuthorizeResponse(char *payload, int gun_index)
  13819. {
  13820. mtrace();
  13821. char expiryDatestr[36]={0};
  13822. char parentIdTagstr[21]={0};
  13823. char statusstr[20]={0};
  13824. int expiryDateISNULL=FALSE;
  13825. int parentIdTagISNULL=FALSE;
  13826. DEBUG_INFO("handleAuthorizeResponse...\n");
  13827. json_object *Authorize;
  13828. Authorize = json_tokener_parse(payload);
  13829. if(!is_error(Authorize))
  13830. {
  13831. if(json_object_object_get(Authorize, "idTagInfo") != NULL)
  13832. {
  13833. // Required data
  13834. sprintf((char *)statusstr, "%s", json_object_get_string(json_object_object_get(json_object_object_get(Authorize,"idTagInfo"), "status")));
  13835. // Optional data
  13836. if(json_object_object_get(json_object_object_get(Authorize,"idTagInfo"), "expiryDate") != NULL)
  13837. sprintf((char *)expiryDatestr, "%s", json_object_get_string(json_object_object_get(json_object_object_get(Authorize,"idTagInfo"), "expiryDate")));
  13838. if(json_object_object_get(json_object_object_get(Authorize,"idTagInfo"), "parentIdTag") != NULL)
  13839. sprintf((char *)parentIdTagstr, "%s", json_object_get_string(json_object_object_get(json_object_object_get(Authorize,"idTagInfo"), "parentIdTag")));
  13840. }
  13841. }
  13842. json_object_put(Authorize);
  13843. if(expiryDateISNULL == FALSE)
  13844. strcpy((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.ExpiryDate, expiryDatestr);
  13845. if(parentIdTagISNULL == FALSE)
  13846. strcpy((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.ParentIdTag, parentIdTagstr);
  13847. strcpy((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.Status, statusstr);
  13848. //Update idTag information to authorization cache if supproted
  13849. if((strcmp((const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemData, "TRUE") == 0) && (ShmOCPP16Data->Authorize.ResponseIdTagInfo.ParentIdTag != NULL) && (ShmOCPP16Data->Authorize.ResponseIdTagInfo.ExpiryDate != NULL) )
  13850. {
  13851. OCPP_addLocalCache((char*)ShmOCPP16Data->Authorize.IdTag, parentIdTagstr, expiryDatestr, statusstr);
  13852. }
  13853. ShmOCPP16Data->SpMsg.bits.AuthorizeReq = 0;
  13854. ShmOCPP16Data->SpMsg.bits.AuthorizeConf = 1; // inform csu
  13855. authorizeRetryTimes = 0;
  13856. }
  13857. void handleBootNotificationResponse(char *payload, int gun_index)
  13858. {
  13859. mtrace();
  13860. char statusStr[12]={0};
  13861. char currentTimeStr[30]={0};
  13862. int intervalInt = 0;
  13863. DEBUG_INFO("handleBootNotificationResponse...\n");
  13864. json_object *BootNotification;
  13865. BootNotification = json_tokener_parse(payload);
  13866. if(!is_error(BootNotification))
  13867. {
  13868. // Required data
  13869. sprintf((char *)currentTimeStr, "%s", json_object_get_string(json_object_object_get(BootNotification,"currentTime")));
  13870. intervalInt = json_object_get_int(json_object_object_get(BootNotification,"interval"));
  13871. sprintf((char *)statusStr, "%s", json_object_get_string(json_object_object_get(BootNotification,"status")));
  13872. }
  13873. json_object_put(BootNotification);
  13874. ShmOCPP16Data->BootNotification.ResponseHeartbeatInterval = intervalInt;
  13875. BootNotificationInterval = intervalInt;
  13876. //write back to ShmOCPP16Data->BootNotification
  13877. strcpy((char *)ShmOCPP16Data->BootNotification.ResponseCurrentTime, currentTimeStr);
  13878. ShmOCPP16Data->BootNotification.ResponseHeartbeatInterval = intervalInt;
  13879. strcpy((char *)ShmOCPP16Data->BootNotification.ResponseStatus, statusStr);
  13880. if((strcmp(statusStr, RegistrationStatusStr[RegistrationStatus_Accepted]) == 0 ))
  13881. {
  13882. BootNotificationInterval = 0;
  13883. if((intervalInt == 0) || (intervalInt >= 10))
  13884. {
  13885. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemData, "%d", intervalInt);
  13886. HeartBeatWaitTime = intervalInt;
  13887. DEBUG_INFO("BootNotificationResponse setting interval to %d...\n",intervalInt);
  13888. }
  13889. server_sign = TRUE;
  13890. server_pending =FALSE;
  13891. }
  13892. else if(strcmp(statusStr, RegistrationStatusStr[RegistrationStatus_Pending]) == 0)
  13893. {
  13894. server_pending = TRUE;
  13895. }
  13896. syncDateTimeRTC(ShmOCPP16Data->BootNotification.ResponseCurrentTime);
  13897. srand(time(NULL));
  13898. refreshStartTimer(&clientTime.Heartbeat);
  13899. clientTime.Heartbeat.tv_sec -= (ShmOCPP16Data->BootNotification.ResponseHeartbeatInterval-((rand()%8)+3));
  13900. SetOcppConnStatus(TRUE);
  13901. ShmOCPP16Data->SpMsg.bits.BootNotificationConf = 1;
  13902. }
  13903. void handleDataTransferResponse(char *payload, int gun_index)
  13904. {
  13905. json_object *DataTransfer = json_tokener_parse(payload);
  13906. if(!is_error(DataTransfer))
  13907. {
  13908. // Required data
  13909. DEBUG_INFO("Status: %s.\n", json_object_get_string(json_object_object_get(DataTransfer, "status")));
  13910. // Optional data
  13911. if(json_object_object_get(DataTransfer, "data") != NULL)
  13912. {
  13913. DEBUG_INFO("Data: %s\n", json_object_get_string(json_object_object_get(DataTransfer, "data")));
  13914. json_object *Data = json_tokener_parse(json_object_get_string(json_object_object_get(DataTransfer, "data")));
  13915. if(!is_error(Data))
  13916. {
  13917. if(json_object_object_get(Data, "msgId") != NULL)
  13918. {
  13919. if(strstr(json_object_get_string(json_object_object_get(Data, "msgId")), "ID_CreditDeductResult") != NULL)
  13920. {
  13921. 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")));
  13922. }
  13923. if(strstr(json_object_get_string(json_object_object_get(Data, "msgId")), "ID_ReaderStatus") != NULL)
  13924. {
  13925. if(json_object_object_get(Data, "ConnectorId") != NULL)
  13926. ShmOCPP16Data->TcciCustomData.ReaderStatus[json_object_get_int(json_object_object_get(Data, "ConnectorId"))-1].ReportReaderStatusReq = 0;
  13927. }
  13928. }
  13929. }
  13930. json_object_put(Data);
  13931. }
  13932. }
  13933. json_object_put(DataTransfer);
  13934. }
  13935. void handleDiagnosticsStatusNotificationResponse(char *payload, int gun_index)
  13936. {
  13937. DEBUG_INFO("handleDiagnosticsStatusNotificationResponse ...\n");
  13938. //struct json_object *obj;
  13939. // obj = json_tokener_parse(payload);
  13940. ShmOCPP16Data->SpMsg.bits.DiagnosticsStatusNotificationReq = 0;
  13941. ShmOCPP16Data->SpMsg.bits.DiagnosticsStatusNotificationConf = 1;
  13942. //No fields are defined.
  13943. }
  13944. void handleFirmwareStatusNotificationResponse(char *payload, int gun_index)
  13945. {
  13946. DEBUG_INFO("handleFirmwareStatusNotificationResponse ...\n");
  13947. //struct json_object *obj;
  13948. // obj = json_tokener_parse(payload);
  13949. ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationReq = 0;
  13950. ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationConf = 1;
  13951. //No fields are defined.
  13952. }
  13953. void handleHeartbeatResponse(char *payload, int gun_index)
  13954. {
  13955. mtrace();
  13956. DEBUG_INFO("handleHeartbeatResponse...\n");
  13957. json_object *Heartbeat;
  13958. Heartbeat = json_tokener_parse(payload);
  13959. if(!is_error(Heartbeat))
  13960. {
  13961. // Required data
  13962. sprintf((char *)ShmOCPP16Data->Heartbeat.ResponseCurrentTime, "%s", json_object_get_string(json_object_object_get(Heartbeat,"currentTime")));
  13963. }
  13964. json_object_put(Heartbeat);
  13965. if(FirstHeartBeat == 0)
  13966. {
  13967. FirstHeartBeat = 1;
  13968. DEBUG_INFO("FirstHeartBeat \n");
  13969. }
  13970. HeartBeatWithNOResponse = 0;
  13971. refreshStartTimer(&clientTime.Heartbeat);
  13972. syncDateTimeRTC(ShmOCPP16Data->Heartbeat.ResponseCurrentTime);
  13973. }
  13974. void handleMeterValuesResponse(char *payload, int gun_index)
  13975. {
  13976. mtrace();
  13977. DEBUG_INFO("handleMeterValuesResponse...\n");
  13978. isQueueSendable = 1;
  13979. }
  13980. void handleStartTransactionResponse(char *payload, int gun_index)
  13981. {
  13982. mtrace();
  13983. //int transactionIdInt = 0;
  13984. FILE *outfile;
  13985. char data[100]={0};
  13986. DEBUG_INFO("handleStartTransactionResponse...\n");
  13987. json_object *StartTransaction;
  13988. StartTransaction = json_tokener_parse(payload);
  13989. if(!is_error(StartTransaction))
  13990. {
  13991. // Required data
  13992. sprintf((char *)ShmOCPP16Data->StartTransaction[gun_index].ResponseIdTagInfo.Status, "%s", json_object_get_string(json_object_object_get(json_object_object_get(StartTransaction,"idTagInfo"), "status")));
  13993. ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId = json_object_get_int(json_object_object_get(StartTransaction,"transactionId"));
  13994. // Optional data
  13995. if(json_object_object_get(json_object_object_get(StartTransaction,"idTagInfo"), "expiryDate") != NULL)
  13996. sprintf((char *)ShmOCPP16Data->StartTransaction[gun_index].ResponseIdTagInfo.ExpiryDate, "%s", json_object_get_string(json_object_object_get(json_object_object_get(StartTransaction,"idTagInfo"), "expiryDate")));
  13997. if(json_object_object_get(json_object_object_get(StartTransaction,"idTagInfo"), "parentIdTag") != NULL)
  13998. sprintf((char *)ShmOCPP16Data->StartTransaction[gun_index].ResponseIdTagInfo.ParentIdTag, "%s", json_object_get_string(json_object_object_get(json_object_object_get(StartTransaction,"idTagInfo"), "parentIdTag")));
  13999. }
  14000. json_object_put(StartTransaction);
  14001. OCPP_updatePeriodEnergy(gun_index);
  14002. //-----------Start : write to the Queue TransactionId file -----------------//
  14003. if((access("/Storage/OCPP/QueueTransactionId",F_OK))!=-1)
  14004. {}
  14005. else
  14006. {
  14007. FILE *log = fopen("/Storage/OCPP/QueueTransactionId", "w+");
  14008. if(log == NULL)
  14009. {
  14010. DEBUG_INFO("Can't Create File QueueTransactionId \n");
  14011. return ;
  14012. }
  14013. else
  14014. {
  14015. fclose(log);
  14016. }
  14017. }
  14018. // open file for writing
  14019. //-------------Start: write to the Queue TransactionId file------------------------------------------//
  14020. if((ShmOCPP16Data->StartTransaction[gun_index].ConnectorId !=0)&&(strcmp((const char *)ShmOCPP16Data->StartTransaction[gun_index].IdTag,"")!=0)&&(ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId !=0))
  14021. {
  14022. outfile = fopen ("/Storage/OCPP/QueueTransactionId", "a");
  14023. sprintf(data,"%d,%s,%d\n", ShmOCPP16Data->StartTransaction[gun_index].ConnectorId , ShmOCPP16Data->StartTransaction[gun_index].IdTag, ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId); // GunIndex, idtag, TransactionId
  14024. fputs(data, outfile);
  14025. fclose (outfile);
  14026. }
  14027. DEBUG_INFO("idTagInfo-expiryDate: %s\n", ShmOCPP16Data->StartTransaction[gun_index].ResponseIdTagInfo.ExpiryDate);
  14028. DEBUG_INFO("idTagInfo-parentIdTag: %s\n", ShmOCPP16Data->StartTransaction[gun_index].ResponseIdTagInfo.ParentIdTag);
  14029. DEBUG_INFO("idTagInfo-status: %s\n", ShmOCPP16Data->StartTransaction[gun_index].ResponseIdTagInfo.Status);
  14030. DEBUG_INFO("transactionId: %d\n", ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId);
  14031. system("/bin/fsync -d /dev/mtdblock13;/bin/sync &");
  14032. isQueueSendable = 1;
  14033. ShmOCPP16Data->CpMsg.bits[gun_index].StartTransactionConf = 1;
  14034. ShmOCPP16Data->CpMsg.bits[gun_index].StartTransactionReq = 0;
  14035. }
  14036. void handleStatusNotificationResponse(char *payload, int gun_index)
  14037. {
  14038. mtrace();
  14039. DEBUG_INFO("handleStatusNotificationResponse...\n");
  14040. //cpinitateMsg.bits[gun_index].TriggerStatusNotificationReq = 0;
  14041. //cpinitateMsg.bits[gun_index].StatusNotificationReq = 0;
  14042. cpinitateMsg.bits[gun_index].StatusNotificationConf = 1;
  14043. }
  14044. void handleStopTransactionnResponse(char *payload, int gun_index)
  14045. {
  14046. mtrace();
  14047. DEBUG_INFO("handleStopTransactionnResponse...\n");
  14048. json_object *StopTransaction;
  14049. StopTransaction = json_tokener_parse(payload);
  14050. if(!is_error(StopTransaction))
  14051. {
  14052. // Optional data
  14053. if(json_object_object_get(StopTransaction, "idTagInfo") != NULL)
  14054. {
  14055. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].ResponseIdTagInfo.Status, "%s", json_object_get_string(json_object_object_get(json_object_object_get(StopTransaction,"idTagInfo"), "status")));
  14056. if(json_object_object_get(json_object_object_get(StopTransaction,"idTagInfo"), "expiryDate") != NULL)
  14057. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].ResponseIdTagInfo.ExpiryDate, "%s", json_object_get_string(json_object_object_get(json_object_object_get(StopTransaction,"idTagInfo"), "expiryDate")));
  14058. if(json_object_object_get(json_object_object_get(StopTransaction,"idTagInfo"), "parentIdTag") != NULL)
  14059. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].ResponseIdTagInfo.ParentIdTag, "%s", json_object_get_string(json_object_object_get(json_object_object_get(StopTransaction,"idTagInfo"), "parentIdTag")));
  14060. }
  14061. }
  14062. json_object_put(StopTransaction);
  14063. isQueueSendable = 1;
  14064. ShmOCPP16Data->CpMsg.bits[gun_index].StopTransactionConf = 1;
  14065. ShmOCPP16Data->CpMsg.bits[gun_index].StopTransactionReq = 0;
  14066. DEBUG_INFO("idTagInfo-expiryDate: %s\n", ShmOCPP16Data->StopTransaction[gun_index].ResponseIdTagInfo.ExpiryDate);
  14067. DEBUG_INFO("idTagInfo-parentIdTag: %s\n", ShmOCPP16Data->StopTransaction[gun_index].ResponseIdTagInfo.ParentIdTag);
  14068. DEBUG_INFO("idTagInfo-status: %s\n", ShmOCPP16Data->StopTransaction[gun_index].ResponseIdTagInfo.Status);
  14069. SetTransactionIdZero(queueOpInfo.stopTransactionId);
  14070. }
  14071. void handleLogStatusNotificationResponse(char *payload, int gun_index)
  14072. {
  14073. mtrace();
  14074. DEBUG_INFO("handleLogStatusNotificationResponse...\n");
  14075. ShmOCPP16Data->SpMsg.bits.LogStatusNotificationConf = 1;
  14076. }
  14077. void handleSecurityEventNotificationResponse(char *payload, int gun_index)
  14078. {
  14079. mtrace();
  14080. DEBUG_INFO("handleSecurityEventNotificationResponse...\n");
  14081. ShmOCPP16Data->SpMsg.bits.SecurityEventNotificationConf = 1;
  14082. }
  14083. void handleSignCertificateResponse(char *payload, int gun_index)
  14084. {
  14085. mtrace();
  14086. DEBUG_INFO("handleSignCertificateResponse...\n");
  14087. json_object *SignCertificate;
  14088. SignCertificate = json_tokener_parse(payload);
  14089. if(!is_error(SignCertificate))
  14090. {
  14091. sprintf((char*)ShmOCPP16Data->SignCertificate.Response_status, "%s", json_object_get_string(json_object_object_get(SignCertificate, "status")));
  14092. DEBUG_INFO("status: %s\n", ShmOCPP16Data->SignCertificate.Response_status);
  14093. }
  14094. json_object_put(SignCertificate);
  14095. ShmOCPP16Data->SpMsg.bits.SignCertificateConf = 1;
  14096. }
  14097. void handleSignedFirmwareStatusNotificationResponse(char *payload, int gun_index)
  14098. {
  14099. mtrace();
  14100. DEBUG_INFO("handleSignedFirmwareStatusNotificationResponse...\n");
  14101. ShmOCPP16Data->SpMsg.bits.SignedFirmwareStatusNotificationConf = 1;
  14102. }
  14103. //==========================================
  14104. // Handle Error routine
  14105. //==========================================
  14106. void handleError(char *id, char *errorCode, char *errorDescription,char *payload)
  14107. {
  14108. mtrace();
  14109. #ifdef SystemLogMessage
  14110. DEBUG_INFO("errorCode: %s\n", errorCode);
  14111. DEBUG_INFO("errorDescription: %s\n", errorDescription);
  14112. DEBUG_INFO("errorDetails: %s\n", payload);
  14113. #endif
  14114. }
  14115. //===============================================
  14116. // Common routine
  14117. //===============================================
  14118. int initialConfigurationTable(void)
  14119. {
  14120. //clock_t start_t, end_t, total_t;
  14121. FILE *fp;
  14122. FILE *outfile;
  14123. char str[512]={0};
  14124. char sstr[256]={0};
  14125. int c = 0;
  14126. char *loc;
  14127. int confVersion = 19;
  14128. DEBUG_INFO("initialConfigurationTable...version: %d\n", confVersion);
  14129. //start_t = clock();
  14130. //printf("Starting of the program, start_t = %ld\n", start_t);
  14131. memset(&(ShmOCPP16Data->ConfigurationTable), 0, sizeof(struct OCPP16ConfigurationTable) );
  14132. // Check configuration file size is correct
  14133. if((access("/Storage/OCPP/OCPPConfiguration",F_OK))!=-1)
  14134. {
  14135. struct stat st;
  14136. stat("/Storage/OCPP/OCPPConfiguration", &st);
  14137. if(st.st_size < 3100)
  14138. {
  14139. system("rm -f /Storage/OCPP/OCPPConfiguration");
  14140. DEBUG_INFO("OCPPConfiguration file size: %d is smaller than 3100 bytes, restore to default value.\n", st.st_size);
  14141. }
  14142. }
  14143. if((access("/Storage/OCPP/OCPPConfiguration",F_OK))==-1)
  14144. {
  14145. outfile = fopen("/Storage/OCPP/OCPPConfiguration" , "w+");
  14146. if(outfile == NULL)
  14147. {
  14148. DEBUG_INFO("Error opening file\n");
  14149. return FALSE;
  14150. }
  14151. /*Core Profile*/
  14152. //AllowOfflineTxForUnknownId
  14153. ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemAccessibility = 1;
  14154. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemName, "AllowOfflineTxForUnknownId");
  14155. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemData, "FALSE" );
  14156. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","AllowOfflineTxForUnknownId", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemData);
  14157. //AuthorizationCacheEnabled
  14158. ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemAccessibility = 1;
  14159. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemName, "AuthorizationCacheEnabled");
  14160. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemData, "FALSE" );
  14161. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","AuthorizationCacheEnabled", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemData);
  14162. //AuthorizeRemoteTxRequests
  14163. ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemAccessibility = 0;
  14164. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemName, "AuthorizeRemoteTxRequests");
  14165. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemData, "FALSE" );
  14166. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","AuthorizeRemoteTxRequests", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemData);
  14167. //BlinkRepeat
  14168. ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemAccessibility = 1;
  14169. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemName, "BlinkRepeat");
  14170. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemData, "0" );
  14171. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","BlinkRepeat", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemData);
  14172. //ClockAlignedDataInterval
  14173. ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemAccessibility = 1;
  14174. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemName, "ClockAlignedDataInterval");
  14175. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemData, "0" );
  14176. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ClockAlignedDataInterval", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemData);
  14177. //ConnectionTimeOut
  14178. ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemAccessibility = 1;
  14179. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemName, "ConnectionTimeOut");
  14180. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemData, "180" );
  14181. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ConnectionTimeOut", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemData);
  14182. //GetConfigurationMaxKeys
  14183. ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemAccessibility =0;
  14184. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemName, "GetConfigurationMaxKeys");
  14185. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemData, "%d", _GetConfiguration_CNT);
  14186. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","GetConfigurationMaxKeys", "true", ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemData);
  14187. // HeartbeatInterval
  14188. ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemAccessibility = 1;
  14189. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemName, "HeartbeatInterval");
  14190. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemData, "20" );
  14191. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","HeartbeatInterval", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemData);
  14192. // LightIntensity
  14193. ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemAccessibility = 1;
  14194. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemName, "LightIntensity");
  14195. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemData, "0" );
  14196. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LightIntensity", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemData);
  14197. // LocalAuthorizeOffline
  14198. ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemAccessibility = 1;
  14199. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemName, "LocalAuthorizeOffline");
  14200. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemData, "TRUE" );
  14201. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LocalAuthorizeOffline", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemData);
  14202. // LocalPreAuthorize
  14203. ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemAccessibility = 1;
  14204. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemName, "LocalPreAuthorize");
  14205. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemData, "FALSE" );
  14206. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LocalPreAuthorize", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemData);
  14207. // MaxEnergyOnInvalidId
  14208. ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemAccessibility = 1;
  14209. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemName, "MaxEnergyOnInvalidId");
  14210. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemData, "0" );
  14211. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MaxEnergyOnInvalidId", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemData);
  14212. // MeterValuesAlignedData
  14213. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemAccessibility = 1;
  14214. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemName, "MeterValuesAlignedData");
  14215. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  14216. 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" );
  14217. else
  14218. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, "Current.Import,Energy.Active.Import.Register,Energy.Active.Import.Interval,Power.Active.Import,Voltage,Current.Offered" );
  14219. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValuesAlignedData", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData);
  14220. // MeterValuesAlignedDataMaxLength
  14221. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemAccessibility = 0;
  14222. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemName, "MeterValuesAlignedDataMaxLength");
  14223. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  14224. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemData, "8" );
  14225. else
  14226. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemData, "10" );
  14227. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValuesAlignedDataMaxLength", "true", ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemData);
  14228. // MeterValuesSampledData
  14229. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemAccessibility = 1;
  14230. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemName, "MeterValuesSampledData");
  14231. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  14232. 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" );
  14233. else
  14234. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, "Current.Import,Energy.Active.Import.Register,Energy.Active.Import.Interval,Power.Active.Import,Voltage,Current.Offered" );
  14235. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValuesSampledData", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData);
  14236. // MeterValuesSampledDataMaxLength
  14237. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemAccessibility = 0;
  14238. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemName, "MeterValuesSampledDataMaxLength");
  14239. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  14240. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemData, "8" );
  14241. else
  14242. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemData, "10" );
  14243. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValuesSampledDataMaxLength", "true", ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemData);
  14244. // MeterValueSampleInterval
  14245. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemAccessibility = 1;
  14246. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemName, "MeterValueSampleInterval");
  14247. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemData, "30" );
  14248. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValueSampleInterval", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemData);
  14249. // MinimumStatusDuration
  14250. ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemAccessibility = 1;
  14251. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemName, "MinimumStatusDuration");
  14252. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemData, "120" );
  14253. server_cycle_Status = atoi((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemData); //StatusNotification cycle
  14254. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MinimumStatusDuration", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemData);
  14255. // NumberOfConnectors
  14256. ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemAccessibility = 0;
  14257. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemName, "NumberOfConnectors");
  14258. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  14259. {
  14260. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData, "%d", (CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY));
  14261. }
  14262. else
  14263. {
  14264. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData, "%d", AC_QUANTITY);
  14265. }
  14266. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","NumberOfConnectors", "true", ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData);
  14267. // ResetRetries
  14268. ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemAccessibility = 1;
  14269. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemName, "ResetRetries");
  14270. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemData, "3" );
  14271. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ResetRetries", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemData);
  14272. // ConnectorPhaseRotation
  14273. ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemAccessibility = 1;
  14274. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemName, "ConnectorPhaseRotation");
  14275. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "NotApplicable" );
  14276. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ConnectorPhaseRotation", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData);
  14277. // ConnectorPhaseRotationMaxLength
  14278. ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemAccessibility = 0;
  14279. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemName, "ConnectorPhaseRotationMaxLength");
  14280. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemData, "1" );
  14281. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ConnectorPhaseRotationMaxLength", "true", ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemData);
  14282. // StopTransactionOnEVSideDisconnect
  14283. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemAccessibility = 0;
  14284. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemName, "StopTransactionOnEVSideDisconnect");
  14285. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemData, "TRUE" );
  14286. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTransactionOnEVSideDisconnect", "true", ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemData);
  14287. // StopTransactionOnInvalidId
  14288. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemAccessibility = 1; //1;
  14289. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemName, "StopTransactionOnInvalidId");
  14290. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemData, "FALSE" );
  14291. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTransactionOnInvalidId", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemData);
  14292. // StopTxnAlignedData
  14293. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemAccessibility = 0;
  14294. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemName, "StopTxnAlignedData");
  14295. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemData, "" );
  14296. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTxnAlignedData", "true", ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemData);
  14297. // StopTxnAlignedDataMaxLength
  14298. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemAccessibility = 0;
  14299. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemName, "StopTxnAlignedDataMaxLength");
  14300. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemData, "0" );
  14301. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTxnAlignedDataMaxLength", "true", ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemData);
  14302. // StopTxnSampledData
  14303. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemAccessibility = 1;
  14304. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemName, "StopTxnSampledData");
  14305. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  14306. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Current.Import,Energy.Active.Import.Interval,Power.Active.Import,Voltage,SoC" );
  14307. else
  14308. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Current.Import,Energy.Active.Import.Interval,Power.Active.Import,Voltage" );
  14309. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTxnSampledData", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData);
  14310. // StopTxnSampledDataMaxLength
  14311. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemAccessibility = 0;
  14312. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemName, "StopTxnSampledDataMaxLength");
  14313. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  14314. {
  14315. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemData, "%d", 7);
  14316. }
  14317. else
  14318. {
  14319. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemData, "%d", 9);
  14320. }
  14321. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTxnSampledDataMaxLength", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemData);
  14322. // SupportedFeatureProfiles
  14323. ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemAccessibility = 0;
  14324. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemName, "SupportedFeatureProfiles");
  14325. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemData, "Core,FirmwareManagement,LocalAuthListManagement,Reservation,SmartCharging,RemoteTrigger" );
  14326. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","SupportedFeatureProfiles", "true", ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemData);
  14327. // SupportedFeatureProfilesMaxLength
  14328. ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemAccessibility = 0;
  14329. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemName, "SupportedFeatureProfilesMaxLength");
  14330. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemData, "6" );
  14331. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","SupportedFeatureProfilesMaxLength", "true", ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemData);
  14332. // TransactionMessageAttempts
  14333. ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemAccessibility = 1;
  14334. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemName, "TransactionMessageAttempts");
  14335. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData, "3" );
  14336. TransactionMessageAttemptsValue = atoi((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData);
  14337. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","TransactionMessageAttempts", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData);
  14338. // TransactionMessageRetryInterval
  14339. ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemAccessibility = 1;
  14340. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemName, "TransactionMessageRetryInterval");
  14341. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData, "60" );
  14342. TransactionMessageRetryIntervalValue = atoi((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData);
  14343. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","TransactionMessageRetryInterval", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData);
  14344. // UnlockConnectorOnEVSideDisconnect
  14345. ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemAccessibility = 0;
  14346. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemName, "UnlockConnectorOnEVSideDisconnect");
  14347. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemData, "TRUE" );
  14348. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","UnlockConnectorOnEVSideDisconnect", "true", ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemData);
  14349. // WebSocketPingInterval
  14350. ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemAccessibility = 1;
  14351. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemName, "WebSocketPingInterval");
  14352. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemData, "30" );
  14353. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","WebSocketPingInterval", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemData);
  14354. // QueueOffLineMeterValues
  14355. ShmOCPP16Data->ConfigurationTable.CoreProfile[QueueOffLineMeterValues].ItemAccessibility = 1;
  14356. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[QueueOffLineMeterValues].ItemName, "QueueOffLineMeterValues");
  14357. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[QueueOffLineMeterValues].ItemData, "FALSE" );
  14358. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","QueueOffLineMeterValues", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[QueueOffLineMeterValues].ItemData);
  14359. // AuthorizationKey
  14360. ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationKey].ItemAccessibility = 1;
  14361. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationKey].ItemName, "AuthorizationKey");
  14362. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationKey].ItemData, (char*)ShmSysConfigAndInfo->SysConfig.OcppSecurityPassword);
  14363. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","AuthorizationKey", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationKey].ItemData);
  14364. // SecurityProfile
  14365. ShmOCPP16Data->ConfigurationTable.CoreProfile[SecurityProfile].ItemAccessibility = 1;
  14366. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SecurityProfile].ItemName, "SecurityProfile");
  14367. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SecurityProfile].ItemData, "%d", ShmSysConfigAndInfo->SysConfig.OcppSecurityProfile);
  14368. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","SecurityProfile", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[SecurityProfile].ItemData);
  14369. // DefaultPrice
  14370. ShmOCPP16Data->ConfigurationTable.CoreProfile[DefaultPrice].ItemAccessibility = 1;
  14371. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[DefaultPrice].ItemName, "DefaultPrice");
  14372. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[DefaultPrice].ItemData, "" );
  14373. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","DefaultPrice", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[DefaultPrice].ItemData);
  14374. // CustomDisplayCostAndPrice
  14375. ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemAccessibility = 1;
  14376. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemName, "CustomDisplayCostAndPrice");
  14377. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemData, "FALSE" );
  14378. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","CustomDisplayCostAndPrice", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemData);
  14379. // CustomIdleFeeAfterStop
  14380. ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemAccessibility = 1;
  14381. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemName, "CustomIdleFeeAfterStop");
  14382. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemData, "FALSE" );
  14383. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","CustomIdleFeeAfterStop", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemData);
  14384. // TimeOffset
  14385. ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffset].ItemAccessibility = 1;
  14386. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffset].ItemName, "TimeOffset");
  14387. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffset].ItemData, "+00:00" );
  14388. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","TimeOffset", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffset].ItemData);
  14389. // NextTimeOffsetTransitionDateTime
  14390. ShmOCPP16Data->ConfigurationTable.CoreProfile[NextTimeOffsetTransitionDateTime].ItemAccessibility = 1;
  14391. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NextTimeOffsetTransitionDateTime].ItemName, "NextTimeOffsetTransitionDateTime");
  14392. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NextTimeOffsetTransitionDateTime].ItemData, " " );
  14393. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","NextTimeOffsetTransitionDateTime", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[NextTimeOffsetTransitionDateTime].ItemData);
  14394. // TimeOffsetNextTransition
  14395. ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffsetNextTransition].ItemAccessibility = 1;
  14396. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffsetNextTransition].ItemName, "TimeOffsetNextTransition");
  14397. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffsetNextTransition].ItemData, "+00:00" );
  14398. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","TimeOffsetNextTransition", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffsetNextTransition].ItemData);
  14399. // SystemUptimeSec
  14400. ShmOCPP16Data->ConfigurationTable.CoreProfile[SystemUptimeSec].ItemAccessibility = 1;
  14401. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SystemUptimeSec].ItemName, "SystemUptimeSec");
  14402. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SystemUptimeSec].ItemData, "0" );
  14403. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","SystemUptimeSec", "true", ShmOCPP16Data->ConfigurationTable.CoreProfile[SystemUptimeSec].ItemData);
  14404. // FreeVend
  14405. ShmOCPP16Data->ConfigurationTable.CoreProfile[FreeVend].ItemAccessibility = 1;
  14406. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[FreeVend].ItemName, "FreeVend");
  14407. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[FreeVend].ItemData, (ShmSysConfigAndInfo->SysConfig.AuthorisationMode?"TRUE":"FALSE") );
  14408. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","FreeVend", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[FreeVend].ItemData);
  14409. // FreeVendIdtag
  14410. ShmOCPP16Data->ConfigurationTable.CoreProfile[FreeVendIdtag].ItemAccessibility = 1;
  14411. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[FreeVendIdtag].ItemName, "FreeVendIdtag");
  14412. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[FreeVendIdtag].ItemData, "FreeVendIdtag" );
  14413. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","FreeVendIdtag", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[FreeVendIdtag].ItemData);
  14414. // OcppServer
  14415. ShmOCPP16Data->ConfigurationTable.CoreProfile[OcppServer].ItemAccessibility = 1;
  14416. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[OcppServer].ItemName, "OcppServer");
  14417. memcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[OcppServer].ItemData, (char*)ShmSysConfigAndInfo->SysConfig.OcppServerURL, 500);
  14418. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","OcppServer", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[OcppServer].ItemData);
  14419. // MaintainServer
  14420. ShmOCPP16Data->ConfigurationTable.CoreProfile[MaintainServer].ItemAccessibility = 1;
  14421. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MaintainServer].ItemName, "MaintainServer");
  14422. memcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MaintainServer].ItemData, (char*)ShmSysConfigAndInfo->SysConfig.MaintainServerURL, 500);
  14423. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MaintainServer", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[MaintainServer].ItemData);
  14424. // StatusNotificationPeriodically
  14425. ShmOCPP16Data->ConfigurationTable.CoreProfile[StatusNotificationPeriodically].ItemAccessibility = 1;
  14426. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StatusNotificationPeriodically].ItemName, "StatusNotificationPeriodically");
  14427. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StatusNotificationPeriodically].ItemData, "FALSE" );
  14428. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StatusNotificationPeriodically", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[StatusNotificationPeriodically].ItemData);
  14429. // StatusNotificationInterval
  14430. ShmOCPP16Data->ConfigurationTable.CoreProfile[StatusNotificationInterval].ItemAccessibility = 1;
  14431. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StatusNotificationInterval].ItemName, "StatusNotificationInterval");
  14432. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StatusNotificationInterval].ItemData, "120" );
  14433. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StatusNotificationInterval", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[StatusNotificationInterval].ItemData);
  14434. // PreAuthAmount
  14435. ShmOCPP16Data->ConfigurationTable.CoreProfile[PreAuthAmount].ItemAccessibility = 1;
  14436. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[PreAuthAmount].ItemName, "PreAuthAmount");
  14437. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[PreAuthAmount].ItemData, "888" );
  14438. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","PreAuthAmount", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[PreAuthAmount].ItemData);
  14439. // isEnableLocalPowerSharing
  14440. ShmOCPP16Data->ConfigurationTable.CoreProfile[isEnableLocalPowerSharing].ItemAccessibility = 1;
  14441. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[isEnableLocalPowerSharing].ItemName, "isEnableLocalPowerSharing");
  14442. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[isEnableLocalPowerSharing].ItemData, "%d", ShmSysConfigAndInfo->SysConfig.isEnableLocalPowerSharing);
  14443. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","isEnableLocalPowerSharing", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[isEnableLocalPowerSharing].ItemData);
  14444. // PowerSharingServerIP
  14445. ShmOCPP16Data->ConfigurationTable.CoreProfile[PowerSharingServerIP].ItemAccessibility = 1;
  14446. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[PowerSharingServerIP].ItemName, "PowerSharingServerIP");
  14447. memcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[PowerSharingServerIP].ItemData, (char*)ShmSysConfigAndInfo->SysConfig.PowerSharingServerIP, 500);
  14448. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","PowerSharingServerIP", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[PowerSharingServerIP].ItemData);
  14449. // EVCCID_PREFIX
  14450. ShmOCPP16Data->ConfigurationTable.CoreProfile[EVCCID_PREFIX].ItemAccessibility = 1;
  14451. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[EVCCID_PREFIX].ItemName, "EVCCID_PREFIX");
  14452. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[EVCCID_PREFIX].ItemData, "" );
  14453. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","EVCCID_PREFIX", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[EVCCID_PREFIX].ItemData);
  14454. // OffLineMaxChargingPower
  14455. ShmOCPP16Data->ConfigurationTable.CoreProfile[OffLineMaxChargingPower].ItemAccessibility = 1;
  14456. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[OffLineMaxChargingPower].ItemName, "OffLineMaxChargingPower");
  14457. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[OffLineMaxChargingPower].ItemData, "0" );
  14458. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","OffLineMaxChargingPower", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[OffLineMaxChargingPower].ItemData);
  14459. // Configuration Version
  14460. ShmOCPP16Data->ConfigurationTable.CoreProfile[ConfigurationVersion].ItemAccessibility = 0;
  14461. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConfigurationVersion].ItemName, "ConfigurationVersion");
  14462. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConfigurationVersion].ItemData, "%d", confVersion);
  14463. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ConfigurationVersion", "true", ShmOCPP16Data->ConfigurationTable.CoreProfile[ConfigurationVersion].ItemData);
  14464. // Charging profile refresh interval
  14465. ShmOCPP16Data->ConfigurationTable.CoreProfile[CharingProfileRefreshInterval].ItemAccessibility = 1;
  14466. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CharingProfileRefreshInterval].ItemName, "CharingProfileRefreshInterval");
  14467. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CharingProfileRefreshInterval].ItemData, "30");
  14468. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","CharingProfileRefreshInterval", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[CharingProfileRefreshInterval].ItemData);
  14469. // Ocpp Software certificated version
  14470. ShmOCPP16Data->ConfigurationTable.CoreProfile[OcppSoftwareVersion].ItemAccessibility = 0;
  14471. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[OcppSoftwareVersion].ItemName, "OcppSoftwareVersion");
  14472. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[OcppSoftwareVersion].ItemData, "%s", "V1.00");
  14473. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","OcppSoftwareVersion", "true", ShmOCPP16Data->ConfigurationTable.CoreProfile[OcppSoftwareVersion].ItemData);
  14474. //* Local Auth List Management Profile*/
  14475. #if 0
  14476. //For OCTT Test Case
  14477. ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemAccessibility = 1;
  14478. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemName, "LocalAuthorizationListEnabled");
  14479. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "TRUE" );
  14480. #endif
  14481. #if 1
  14482. //LocalAuthListEnabled
  14483. ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemAccessibility = 1;
  14484. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemName, "LocalAuthListEnabled");
  14485. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "TRUE" );
  14486. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LocalAuthListEnabled", "false", ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData);
  14487. #endif
  14488. //LocalAuthListMaxLength
  14489. ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemAccessibility = 0;
  14490. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemName, "LocalAuthListMaxLength");
  14491. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemData, "100000" );
  14492. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LocalAuthListMaxLength", "true", ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemData);
  14493. //SendLocalListMaxLength
  14494. ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemAccessibility = 0;
  14495. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemName, "SendLocalListMaxLength");
  14496. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemData, "1000" );
  14497. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","SendLocalListMaxLength", "true", ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemData);
  14498. //ReserveConnectorZeroSupported
  14499. ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemAccessibility = 0;
  14500. strcpy((char *)ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemName, "ReserveConnectorZeroSupported");
  14501. strcpy((char *)ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemData, "FALSE" );
  14502. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ReserveConnectorZeroSupported", "true", ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemData);
  14503. //* Smart Charging Profile */
  14504. //ChargeProfileMaxStackLevel
  14505. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemAccessibility = 0;
  14506. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemName, "ChargeProfileMaxStackLevel");
  14507. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemData, "8" );
  14508. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ChargeProfileMaxStackLevel", "true", ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemData);
  14509. // ChargingScheduleAllowedChargingRateUnit
  14510. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemAccessibility = 0;
  14511. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemName, "ChargingScheduleAllowedChargingRateUnit");
  14512. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemData, "Current,Power" );
  14513. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ChargingScheduleAllowedChargingRateUnit", "true", ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemData);
  14514. // ChargingScheduleMaxPeriods
  14515. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemAccessibility = 0;
  14516. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemName, "ChargingScheduleMaxPeriods");
  14517. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemData, "10" );
  14518. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ChargingScheduleMaxPeriods", "true", ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemData);
  14519. // ConnectorSwitch3to1PhaseSupported
  14520. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemAccessibility = 0;
  14521. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemName, "ConnectorSwitch3to1PhaseSupported");
  14522. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemData, "FALSE" );
  14523. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ConnectorSwitch3to1PhaseSupported", "true", ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemData);
  14524. // MaxChargingProfilesInstalled
  14525. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemAccessibility = 0;
  14526. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemName, "MaxChargingProfilesInstalled");
  14527. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemData, "50" );
  14528. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MaxChargingProfilesInstalled", "true", ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemData);
  14529. fclose(outfile);
  14530. }
  14531. else
  14532. {
  14533. //DEBUG_INFO("../Storage/OCPP/OCPPConfiguration EXit\n");
  14534. char keystr[60]={0};
  14535. char readonlystr[10]={0};
  14536. char valuestr[256]={0};
  14537. fp = fopen("/Storage/OCPP/OCPPConfiguration" , "r");
  14538. if(fp == NULL) {
  14539. DEBUG_INFO("Error opening file");
  14540. return FALSE;
  14541. }
  14542. while( fgets (str, ARRAY_SIZE(str), fp)!=NULL )
  14543. {
  14544. //DEBUG_INFO("Get Configuration \n");
  14545. if(strlen(str) > 0)
  14546. {
  14547. str[strlen(str) - 1] = '\0'; // eat the newline fgets() stores
  14548. //*************************key*********************************/
  14549. if(strstr(str, "key") != NULL)
  14550. {
  14551. loc = strstr(str, "key");
  14552. c = 0;
  14553. memset(sstr ,0, ARRAY_SIZE(sstr) );
  14554. while ((loc[strlen("key")+3+c] != '\"') && (c < (ARRAY_SIZE(sstr)-1)))
  14555. {
  14556. sstr[c] = loc[strlen("key")+3+c];
  14557. c++;
  14558. }
  14559. sstr[c] = '\0';
  14560. strcpy(keystr,sstr);
  14561. }
  14562. //*************************readonly*********************************/
  14563. if(strstr(str, "readonly") != NULL)
  14564. {
  14565. loc = strstr(str, "readonly");
  14566. c = 0;
  14567. memset(sstr ,0, ARRAY_SIZE(sstr) );
  14568. while ((loc[strlen("readonly")+2+c] != ',') && (c < (ARRAY_SIZE(sstr)-1)))
  14569. {
  14570. sstr[c] = loc[strlen("readonly")+2+c];
  14571. c++;
  14572. }
  14573. sstr[c] = '\0';
  14574. strcpy(readonlystr,sstr);
  14575. }
  14576. //*************************value*********************************/
  14577. if(strstr(str, "value") != NULL)
  14578. {
  14579. loc = strstr(str, "value");
  14580. c = 0;
  14581. memset(sstr ,0, ARRAY_SIZE(sstr) );
  14582. while ((loc[strlen("value")+3+c] != '\"') && (c < (ARRAY_SIZE(sstr)-1)))
  14583. {
  14584. sstr[c] = loc[strlen("value")+3+c];
  14585. c++;
  14586. }
  14587. sstr[c] = '\0';
  14588. strcpy(valuestr,sstr);
  14589. }
  14590. // DEBUG_INFO("keystr=%s\n",keystr);
  14591. // DEBUG_INFO("readonlystr=%s\n",readonlystr);
  14592. // DEBUG_INFO("valuestr=%s\n",valuestr);
  14593. if(strcmp(keystr, "AllowOfflineTxForUnknownId") == 0)
  14594. {
  14595. //Charger.AllowOfflineTxForUnknownId = (value.toLowerCase().equals("true")?true:false);
  14596. ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14597. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemData, "%s", valuestr );
  14598. // DEBUG_INFO("AllowOfflineTxForUnknownId setting\n");
  14599. // DEBUG_INFO("AllowOfflineTxForUnknownId setting\n");
  14600. }
  14601. if(strcmp(keystr, "AuthorizationCacheEnabled") == 0)
  14602. {
  14603. //Charger.AuthorizationCacheEnabled = (value.toLowerCase().equals("true")?true:false);
  14604. ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14605. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemData, "%s", valuestr );
  14606. }
  14607. if(strcmp(keystr, "AuthorizeRemoteTxRequests") == 0)
  14608. {
  14609. ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14610. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemData, "%s", valuestr );
  14611. }
  14612. if(strcmp(keystr, "BlinkRepeat") == 0)
  14613. {
  14614. //Charger.BlinkRepeat = Integer.parseInt(value);
  14615. ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14616. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemData, "%d", atoi(valuestr) );
  14617. }
  14618. if(strcmp(keystr, "ClockAlignedDataInterval") == 0)
  14619. {
  14620. ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14621. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemData, "%d", atoi(valuestr) );
  14622. }
  14623. if(strcmp(keystr, "ConnectionTimeOut") == 0 )
  14624. {
  14625. ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14626. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemData, "%d", atoi(valuestr));
  14627. }
  14628. if(strcmp(keystr, "GetConfigurationMaxKeys") == 0)
  14629. {
  14630. ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14631. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemData, "%d", (atoi(valuestr)!=GetConfigurationMaxKeysNUM?GetConfigurationMaxKeysNUM:atoi(valuestr)));
  14632. }
  14633. if(strcmp(keystr, "HeartbeatInterval") == 0)
  14634. {
  14635. ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14636. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemData, "%d", atoi(valuestr));
  14637. HeartBeatWaitTime = atoi(valuestr);
  14638. }
  14639. if(strcmp(keystr, "LightIntensity") == 0)
  14640. {
  14641. ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14642. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemData, "%d", atoi(valuestr));
  14643. }
  14644. if(strcmp(keystr, "LocalAuthorizeOffline") == 0)
  14645. {
  14646. ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14647. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemData, "%s", valuestr );
  14648. }
  14649. if(strcmp(keystr, "LocalPreAuthorize") == 0)
  14650. {
  14651. ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14652. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemData, "%s", valuestr );
  14653. }
  14654. if(strcmp(keystr, "MaxEnergyOnInvalidId") == 0)
  14655. {
  14656. ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14657. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemData, "%d", atoi(valuestr) );
  14658. }
  14659. if(strcmp(keystr, "MeterValuesAlignedData") == 0)
  14660. {
  14661. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14662. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, "%s", valuestr );
  14663. }
  14664. if(strcmp(keystr, "MeterValuesAlignedDataMaxLength") == 0)
  14665. {
  14666. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14667. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemData, "%d", atoi(valuestr));
  14668. }
  14669. if(strcmp(keystr, "MeterValuesSampledData") == 0 )
  14670. {
  14671. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14672. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, "%s", valuestr );
  14673. }
  14674. if(strcmp(keystr, "MeterValuesSampledDataMaxLength") == 0)
  14675. {
  14676. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14677. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemData, "%d", atoi(valuestr));
  14678. }
  14679. if(strcmp(keystr, "MeterValueSampleInterval") == 0)
  14680. {
  14681. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14682. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemData, "%d", atoi(valuestr));
  14683. }
  14684. if(strcmp(keystr, "MinimumStatusDuration") == 0)
  14685. {
  14686. ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14687. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemData, "%d", atoi(valuestr) );
  14688. server_cycle_Status = atoi(valuestr); //StatusNotification cycle
  14689. }
  14690. if(strcmp(keystr, "NumberOfConnectors") == 0)
  14691. {
  14692. ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14693. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData, "%d", atoi(valuestr) );
  14694. }
  14695. if(strcmp(keystr, "ResetRetries") == 0)
  14696. {
  14697. ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14698. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemData, "%d", atoi(valuestr) );
  14699. }
  14700. if(strcmp(keystr, "ConnectorPhaseRotation") == 0)
  14701. {
  14702. ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14703. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "%s", valuestr );
  14704. }
  14705. if(strcmp(keystr, "ConnectorPhaseRotationMaxLength") == 0)
  14706. {
  14707. ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14708. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemData, "%d", atoi(valuestr) );
  14709. }
  14710. if(strcmp(keystr, "StopTransactionOnEVSideDisconnect") == 0)
  14711. {
  14712. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14713. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemData, "%s", valuestr );
  14714. }
  14715. if(strcmp(keystr, "StopTransactionOnInvalidId") == 0)
  14716. {
  14717. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14718. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemData, "%s", valuestr );
  14719. }
  14720. if(strcmp(keystr, "StopTxnAlignedData") == 0)
  14721. {
  14722. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14723. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemData, "%s", valuestr );
  14724. }
  14725. if(strcmp(keystr, "StopTxnAlignedDataMaxLength") == 0)
  14726. {
  14727. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14728. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemData, "%d", atoi(valuestr) );
  14729. }
  14730. if(strcmp(keystr, "StopTxnSampledData") == 0)
  14731. {
  14732. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14733. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "%s", valuestr );
  14734. }
  14735. if(strcmp(keystr, "StopTxnSampledDataMaxLength") == 0)
  14736. {
  14737. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14738. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemData, "%d", atoi(valuestr) );
  14739. }
  14740. if(strcmp(keystr, "SupportedFeatureProfiles") == 0)
  14741. {
  14742. ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14743. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemData, "%s", valuestr );
  14744. }
  14745. if(strcmp(keystr, "SupportedFeatureProfilesMaxLength") == 0)
  14746. {
  14747. ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14748. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemData, "%d", atoi(valuestr) );
  14749. }
  14750. if(strcmp(keystr, "TransactionMessageAttempts") == 0)
  14751. {
  14752. ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14753. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData, "%d", atoi(valuestr) );
  14754. TransactionMessageAttemptsValue = atoi(valuestr);
  14755. }
  14756. if(strcmp(keystr, "TransactionMessageRetryInterval") == 0)
  14757. {
  14758. ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemAccessibility= (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14759. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData, "%d", atoi(valuestr) );
  14760. TransactionMessageRetryIntervalValue = atoi(valuestr);
  14761. }
  14762. if(strcmp(keystr, "UnlockConnectorOnEVSideDisconnect") == 0)
  14763. {
  14764. ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14765. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemData, "%s", valuestr );
  14766. }
  14767. if(strcmp(keystr, "WebSocketPingInterval") == 0)
  14768. {
  14769. ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14770. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemData, "%d", atoi(valuestr) );
  14771. }
  14772. if(strcmp(keystr, "QueueOffLineMeterValues") == 0)
  14773. {
  14774. ShmOCPP16Data->ConfigurationTable.CoreProfile[QueueOffLineMeterValues].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14775. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[QueueOffLineMeterValues].ItemData, "%s", valuestr);
  14776. }
  14777. if(strcmp(keystr, "AuthorizationKey") == 0)
  14778. {
  14779. ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationKey].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14780. //sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationKey].ItemData, "%s", valuestr);
  14781. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationKey].ItemData, "%s", ShmSysConfigAndInfo->SysConfig.OcppSecurityPassword);
  14782. }
  14783. if(strcmp(keystr, "SecurityProfile") == 0)
  14784. {
  14785. ShmOCPP16Data->ConfigurationTable.CoreProfile[SecurityProfile].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14786. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SecurityProfile].ItemData, "%d", ShmSysConfigAndInfo->SysConfig.OcppSecurityProfile);
  14787. }
  14788. if(strcmp(keystr, "DefaultPrice") == 0)
  14789. {
  14790. ShmOCPP16Data->ConfigurationTable.CoreProfile[DefaultPrice].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14791. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[DefaultPrice].ItemData, "%s", valuestr);
  14792. }
  14793. if(strcmp(keystr, "CustomDisplayCostAndPrice") == 0)
  14794. {
  14795. ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14796. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemData, "%s", valuestr);
  14797. }
  14798. if(strcmp(keystr, "CustomIdleFeeAfterStop") == 0)
  14799. {
  14800. ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14801. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemData, "%s", valuestr);
  14802. }
  14803. if(strcmp(keystr, "TimeOffset") == 0)
  14804. {
  14805. ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffset].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14806. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffset].ItemData, "%s", valuestr);
  14807. }
  14808. if(strcmp(keystr, "NextTimeOffsetTransitionDateTime") == 0)
  14809. {
  14810. ShmOCPP16Data->ConfigurationTable.CoreProfile[NextTimeOffsetTransitionDateTime].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14811. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NextTimeOffsetTransitionDateTime].ItemData, "%s", valuestr);
  14812. }
  14813. if(strcmp(keystr, "TimeOffsetNextTransition") == 0)
  14814. {
  14815. ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffsetNextTransition].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14816. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffsetNextTransition].ItemData, "%s", valuestr);
  14817. }
  14818. if(strcmp(keystr, "SystemUptimeSec") == 0)
  14819. {
  14820. ShmOCPP16Data->ConfigurationTable.CoreProfile[SystemUptimeSec].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14821. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SystemUptimeSec].ItemData, "%s", valuestr);
  14822. }
  14823. if(strcmp(keystr, "FreeVend") == 0)
  14824. {
  14825. ShmOCPP16Data->ConfigurationTable.CoreProfile[FreeVend].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14826. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[FreeVend].ItemData, "%s", (ShmSysConfigAndInfo->SysConfig.AuthorisationMode ? "TRUE" : "FALSE"));
  14827. }
  14828. if(strcmp(keystr, "FreeVendIdtag") == 0)
  14829. {
  14830. ShmOCPP16Data->ConfigurationTable.CoreProfile[FreeVendIdtag].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14831. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[FreeVendIdtag].ItemData, "%s", valuestr);
  14832. }
  14833. if(strcmp(keystr, "OcppServer") == 0)
  14834. {
  14835. ShmOCPP16Data->ConfigurationTable.CoreProfile[OcppServer].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14836. memcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[OcppServer].ItemData, (char *)ShmSysConfigAndInfo->SysConfig.OcppServerURL, 500);
  14837. }
  14838. if(strcmp(keystr, "MaintainServer") == 0)
  14839. {
  14840. ShmOCPP16Data->ConfigurationTable.CoreProfile[MaintainServer].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14841. memcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MaintainServer].ItemData, (char *)ShmSysConfigAndInfo->SysConfig.MaintainServerURL,500);
  14842. }
  14843. if(strcmp(keystr, "StatusNotificationPeriodically") == 0)
  14844. {
  14845. ShmOCPP16Data->ConfigurationTable.CoreProfile[StatusNotificationPeriodically].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14846. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StatusNotificationPeriodically].ItemData, "%s", valuestr);
  14847. }
  14848. if(strcmp(keystr, "StatusNotificationInterval") == 0)
  14849. {
  14850. ShmOCPP16Data->ConfigurationTable.CoreProfile[StatusNotificationInterval].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14851. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StatusNotificationInterval].ItemData, "%d", atoi(valuestr));
  14852. }
  14853. if(strcmp(keystr, "PreAuthAmount") == 0)
  14854. {
  14855. ShmOCPP16Data->ConfigurationTable.CoreProfile[PreAuthAmount].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14856. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[PreAuthAmount].ItemData, "%.2f", atof(valuestr));
  14857. }
  14858. if(strcmp(keystr, "isEnableLocalPowerSharing") == 0)
  14859. {
  14860. ShmOCPP16Data->ConfigurationTable.CoreProfile[isEnableLocalPowerSharing].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14861. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[isEnableLocalPowerSharing].ItemData, "%d", ShmSysConfigAndInfo->SysConfig.isEnableLocalPowerSharing);
  14862. }
  14863. if(strcmp(keystr, "PowerSharingServerIP") == 0)
  14864. {
  14865. ShmOCPP16Data->ConfigurationTable.CoreProfile[PowerSharingServerIP].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14866. memcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[PowerSharingServerIP].ItemData, (char *)ShmSysConfigAndInfo->SysConfig.PowerSharingServerIP,500);
  14867. }
  14868. if(strcmp(keystr, "EVCCID_PREFIX") == 0)
  14869. {
  14870. ShmOCPP16Data->ConfigurationTable.CoreProfile[EVCCID_PREFIX].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14871. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[EVCCID_PREFIX].ItemData, "%s", valuestr);
  14872. }
  14873. if(strcmp(keystr, "OffLineMaxChargingPower") == 0)
  14874. {
  14875. ShmOCPP16Data->ConfigurationTable.CoreProfile[OffLineMaxChargingPower].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14876. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[OffLineMaxChargingPower].ItemData, "%s", valuestr);
  14877. }
  14878. if(strcmp(keystr, "ConfigurationVersion") == 0)
  14879. {
  14880. ShmOCPP16Data->ConfigurationTable.CoreProfile[ConfigurationVersion].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14881. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConfigurationVersion].ItemData, "%d", atoi(valuestr));
  14882. }
  14883. if(strcmp(keystr, "CharingProfileRefreshInterval") == 0)
  14884. {
  14885. ShmOCPP16Data->ConfigurationTable.CoreProfile[CharingProfileRefreshInterval].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14886. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CharingProfileRefreshInterval].ItemData, "%s", valuestr);
  14887. }
  14888. if(strcmp(keystr, "OcppSoftwareVersion") == 0)
  14889. {
  14890. ShmOCPP16Data->ConfigurationTable.CoreProfile[OcppSoftwareVersion].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14891. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[OcppSoftwareVersion].ItemData, "%s", valuestr);
  14892. }
  14893. if(strcmp(keystr, "LocalAuthListEnabled") == 0)
  14894. {
  14895. ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14896. sprintf((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "%s", valuestr );
  14897. }
  14898. if(strcmp(keystr, "LocalAuthListMaxLength") == 0)
  14899. {
  14900. ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14901. sprintf((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemData, "%d", atoi(valuestr) );
  14902. }
  14903. if(strcmp(keystr, "SendLocalListMaxLength") == 0)
  14904. {
  14905. ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14906. sprintf((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemData, "%d", atoi(valuestr) );
  14907. }
  14908. if(strcmp(keystr, "ReserveConnectorZeroSupported") == 0)
  14909. {
  14910. ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14911. sprintf((char *)ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemData, "%s", valuestr );
  14912. }
  14913. if(strcmp(keystr, "ChargeProfileMaxStackLevel") == 0)
  14914. {
  14915. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14916. sprintf((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemData, "%d", atoi(valuestr) );
  14917. }
  14918. if(strcmp(keystr, "ChargingScheduleAllowedChargingRateUnit") == 0)
  14919. {
  14920. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14921. sprintf((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemData, "%s", valuestr );
  14922. }
  14923. if(strcmp(keystr, "ChargingScheduleMaxPeriods") == 0)
  14924. {
  14925. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14926. sprintf((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemData, "%d", atoi(valuestr) );
  14927. }
  14928. if(strcmp(keystr, "ConnectorSwitch3to1PhaseSupported") == 0)
  14929. {
  14930. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14931. sprintf((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemData, "%s", valuestr);
  14932. }
  14933. if(strcmp(keystr, "MaxChargingProfilesInstalled") == 0)
  14934. {
  14935. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14936. sprintf((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemData, "%d", atoi(valuestr) );
  14937. }
  14938. }
  14939. }
  14940. fclose(fp);
  14941. }
  14942. if(atoi((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConfigurationVersion].ItemData) == confVersion)
  14943. {
  14944. return PASS;
  14945. }
  14946. else
  14947. {
  14948. return FAIL;
  14949. }
  14950. }
  14951. void StoreConfigurationTable(void)
  14952. {
  14953. FILE *outfile;
  14954. outfile = fopen("/Storage/OCPP/OCPPConfiguration" , "w+");
  14955. if(outfile == NULL)
  14956. {
  14957. DEBUG_INFO("Error opening file");
  14958. return ;
  14959. }
  14960. /*Core Profile*/
  14961. //AllowOfflineTxForUnknownId
  14962. /*
  14963. ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemAccessibility = 1;
  14964. printf("AllowoddlineTXForUnknownId type: %d \n", ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemAccessibility);
  14965. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemName, "AllowOfflineTxForUnknownId");
  14966. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemData, "TRUE" );
  14967. */
  14968. //DEBUG_INFO("data=%s\n",data);
  14969. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","AllowOfflineTxForUnknownId", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemData);
  14970. //AuthorizationCacheEnabled
  14971. /*
  14972. ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemAccessibility = 1;
  14973. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemName, "AuthorizationCacheEnabled");
  14974. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemData, "FALSE" );
  14975. */
  14976. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","AuthorizationCacheEnabled", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemData);
  14977. //AuthorizeRemoteTxRequests
  14978. /*
  14979. ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemAccessibility = 0;
  14980. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemName, "AuthorizeRemoteTxRequests");
  14981. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemData, "TRUE" );
  14982. */
  14983. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","AuthorizeRemoteTxRequests", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemData);
  14984. //BlinkRepeat
  14985. /*
  14986. ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemAccessibility = 1;
  14987. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemName, "BlinkRepeat");
  14988. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemData, "0" );
  14989. */
  14990. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","BlinkRepeat", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemData);
  14991. //ClockAlignedDataInterval
  14992. /*
  14993. ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemAccessibility = 1;
  14994. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemName, "ClockAlignedDataInterval");
  14995. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemData, "0" );
  14996. */
  14997. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ClockAlignedDataInterval", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemData);
  14998. //ConnectionTimeOut
  14999. /*
  15000. ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemAccessibility = 1;
  15001. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemName, "ConnectionTimeOut");
  15002. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemData, "180" );
  15003. */
  15004. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ConnectionTimeOut", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemData);
  15005. //GetConfigurationMaxKeys
  15006. /*
  15007. ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemAccessibility =0;
  15008. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemName, "GetConfigurationMaxKeys");
  15009. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemData, "43" );
  15010. */
  15011. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","GetConfigurationMaxKeys", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemData);
  15012. // HeartbeatInterval
  15013. /*
  15014. ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemAccessibility = 1;
  15015. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemName, "HeartbeatInterval");
  15016. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemData, "10" );
  15017. */
  15018. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","HeartbeatInterval", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemData);
  15019. // LightIntensity
  15020. /*
  15021. ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemAccessibility = 1;
  15022. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemName, "LightIntensity");
  15023. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemData, "0" );
  15024. */
  15025. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LightIntensity", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemData);
  15026. // LocalAuthorizeOffline
  15027. /*
  15028. ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemAccessibility = 0;
  15029. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemName, "LocalAuthorizeOffline");
  15030. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemData, "TRUE" );
  15031. */
  15032. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LocalAuthorizeOffline", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemData);
  15033. // LocalPreAuthorize
  15034. /*
  15035. ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemAccessibility = 0;
  15036. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemName, "LocalPreAuthorize");
  15037. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemData, "FALSE" );
  15038. */
  15039. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LocalPreAuthorize", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemData);
  15040. // MaxEnergyOnInvalidId
  15041. /*
  15042. ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemAccessibility = 1;
  15043. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemName, "MaxEnergyOnInvalidId");
  15044. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemData, "0" );
  15045. */
  15046. //ShmSysConfigAndInfo->SysConfig.OfflineMaxChargeEnergy = 0;
  15047. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MaxEnergyOnInvalidId", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemData);
  15048. // MeterValuesAlignedData
  15049. /*
  15050. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemAccessibility = 1;
  15051. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemName, "MeterValuesAlignedData");
  15052. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, "Current.Export,Energy.Active.Export.Interval,Power.Active.Export,Voltage,SOC" );
  15053. */
  15054. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValuesAlignedData", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData);
  15055. // MeterValuesAlignedDataMaxLength
  15056. /*
  15057. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemAccessibility = 0;
  15058. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemName, "MeterValuesAlignedDataMaxLength");
  15059. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemData, "5" );
  15060. */
  15061. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValuesAlignedDataMaxLength", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemData);
  15062. // MeterValuesSampledData
  15063. /*
  15064. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemAccessibility = 1;
  15065. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemName, "MeterValuesSampledData");
  15066. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, "Current.Export,Energy.Active.Export.Interval,Power.Active.Export,Voltage,SOC" );
  15067. */
  15068. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValuesSampledData", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData);
  15069. // MeterValuesSampledDataMaxLength
  15070. /*
  15071. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemAccessibility = 0;
  15072. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemName, "MeterValuesSampledDataMaxLength");
  15073. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemData, "5" );
  15074. */
  15075. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValuesSampledDataMaxLength", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemData);
  15076. // MeterValueSampleInterval
  15077. /*
  15078. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemAccessibility = 1;
  15079. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemName, "MeterValueSampleInterval");
  15080. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemData, "10" );
  15081. */
  15082. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValueSampleInterval", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemData);
  15083. // MinimumStatusDuration
  15084. /*
  15085. ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemAccessibility = 1;
  15086. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemName, "MinimumStatusDuration");
  15087. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemData, "0" );
  15088. */
  15089. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MinimumStatusDuration", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemData);
  15090. // NumberOfConnectors
  15091. /*
  15092. ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemAccessibility = 0;
  15093. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemName, "NumberOfConnectors");
  15094. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  15095. {
  15096. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData, "%d", (CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY));
  15097. }
  15098. else
  15099. {
  15100. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData, "%d", AC_QUANTITY);
  15101. }
  15102. */
  15103. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","NumberOfConnectors", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData);
  15104. // ResetRetries
  15105. /*
  15106. ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemAccessibility = 1;
  15107. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemName, "ResetRetries");
  15108. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemData, "3" );
  15109. */
  15110. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ResetRetries", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemData);
  15111. // ConnectorPhaseRotation
  15112. /*
  15113. ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemAccessibility = 1;
  15114. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemName, "ConnectorPhaseRotation");
  15115. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "NotApplicable" );
  15116. */
  15117. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ConnectorPhaseRotation", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData);
  15118. // ConnectorPhaseRotationMaxLength
  15119. /*
  15120. ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemAccessibility = 0;
  15121. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemName, "ConnectorPhaseRotationMaxLength");
  15122. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemData, "1" );
  15123. */
  15124. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ConnectorPhaseRotationMaxLength", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemData);
  15125. // StopTransactionOnEVSideDisconnect
  15126. /*
  15127. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemAccessibility = 0;
  15128. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemName, "StopTransactionOnEVSideDisconnect");
  15129. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemData, "TRUE" );
  15130. */
  15131. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTransactionOnEVSideDisconnect", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemData);
  15132. // StopTransactionOnInvalidId
  15133. /*
  15134. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemAccessibility = 0;
  15135. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemName, "StopTransactionOnInvalidId");
  15136. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemData, "FALSE" );
  15137. */
  15138. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTransactionOnInvalidId", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemData);
  15139. // StopTxnAlignedData
  15140. /*
  15141. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemAccessibility = 1;
  15142. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemName, "StopTxnAlignedData");
  15143. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemData, "Energy.Active.Import.Register" );
  15144. */
  15145. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTxnAlignedData", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemData);
  15146. // StopTxnAlignedDataMaxLength
  15147. /*
  15148. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemAccessibility = 0;
  15149. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemName, "StopTxnAlignedDataMaxLength");
  15150. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemData, "0" );
  15151. */
  15152. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTxnAlignedDataMaxLength", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemData);
  15153. // StopTxnSampledData
  15154. /*
  15155. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemAccessibility = 1;
  15156. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemName, "StopTxnSampledData");
  15157. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Energy.Active.Import.Register" );
  15158. */
  15159. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTxnSampledData", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData);
  15160. // StopTxnSampledDataMaxLength
  15161. /*
  15162. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemAccessibility = 0;
  15163. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemName, "StopTxnSampledDataMaxLength");
  15164. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemData, "0" );
  15165. */
  15166. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTxnSampledDataMaxLength", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemData);
  15167. // SupportedFeatureProfiles
  15168. /*
  15169. ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemAccessibility = 0;
  15170. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemName, "SupportedFeatureProfiles");
  15171. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemData, "Core,FirmwareManagement,LocalAuthListManagement,Reservation,SmartCharging,RemoteTrigger" );
  15172. */
  15173. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","SupportedFeatureProfiles", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemData);
  15174. // SupportedFeatureProfilesMaxLength
  15175. /*
  15176. ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemAccessibility = 0;
  15177. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemName, "SupportedFeatureProfilesMaxLength");
  15178. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemData, "6" );
  15179. */
  15180. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","SupportedFeatureProfilesMaxLength", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemData);
  15181. // TransactionMessageAttempts
  15182. /*
  15183. ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemAccessibility = 1;
  15184. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemName, "TransactionMessageAttempts");
  15185. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData, "3" );
  15186. */
  15187. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","TransactionMessageAttempts", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData);
  15188. // TransactionMessageRetryInterval
  15189. /*
  15190. ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemAccessibility = 1;
  15191. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemName, "TransactionMessageRetryInterval");
  15192. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData, "60" );
  15193. */
  15194. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","TransactionMessageRetryInterval", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData);
  15195. // UnlockConnectorOnEVSideDisconnect
  15196. /*
  15197. ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemAccessibility = 0;
  15198. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemName, "UnlockConnectorOnEVSideDisconnect");
  15199. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemData, "TRUE" );
  15200. */
  15201. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","UnlockConnectorOnEVSideDisconnect", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemData);
  15202. // WebSocketPingInterval
  15203. /*
  15204. ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemAccessibility = 1;
  15205. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemName, "WebSocketPingInterval");
  15206. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemData, "30" );
  15207. */
  15208. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","WebSocketPingInterval", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemData);
  15209. // QueueOffLineMeterValues
  15210. /*
  15211. ShmOCPP16Data->ConfigurationTable.CoreProfile[QueueOffLineMeterValues].ItemAccessibility = 0;
  15212. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[QueueOffLineMeterValues].ItemName, "QueueOffLineMeterValues");
  15213. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[QueueOffLineMeterValues].ItemData, "TRUE" );
  15214. */
  15215. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","QueueOffLineMeterValues", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[QueueOffLineMeterValues].ItemData);
  15216. // AuthorizationKey
  15217. /*
  15218. ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationKey].ItemAccessibility = 1;
  15219. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationKey].ItemName, "AuthorizationKey");
  15220. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationKey].ItemData, "0" );
  15221. */
  15222. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","AuthorizationKey", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationKey].ItemData);
  15223. // SecurityProfile
  15224. /*
  15225. ShmOCPP16Data->ConfigurationTable.CoreProfile[SecurityProfile].ItemAccessibility = 1;
  15226. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SecurityProfile].ItemName, "SecurityProfile");
  15227. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SecurityProfile].ItemData, "30" );
  15228. */
  15229. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","SecurityProfile", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SecurityProfile].ItemData);
  15230. // DefaultPrice
  15231. /*
  15232. ShmOCPP16Data->ConfigurationTable.CoreProfile[DefaultPrice].ItemAccessibility = 1;
  15233. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[DefaultPrice].ItemName, "DefaultPrice");
  15234. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[DefaultPrice].ItemData, "" );
  15235. */
  15236. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","DefaultPrice", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[DefaultPrice].ItemData);
  15237. // CustomDisplayCostAndPrice
  15238. /*
  15239. ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemAccessibility = 1;
  15240. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemName, "CustomDisplayCostAndPrice");
  15241. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemData, "FALSE" );
  15242. */
  15243. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","CustomDisplayCostAndPrice", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemData);
  15244. // CustomIdleFeeAfterStop
  15245. /*
  15246. ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemAccessibility = 1;
  15247. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemName, "CustomIdleFeeAfterStop");
  15248. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemData, "FALSE" );
  15249. */
  15250. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","CustomIdleFeeAfterStop", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemData);
  15251. // TimeOffset
  15252. /*
  15253. ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffset].ItemAccessibility = 1;
  15254. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffset].ItemName, "TimeOffset");
  15255. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffset].ItemData, "FALSE" );
  15256. */
  15257. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","TimeOffset", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffset].ItemData);
  15258. // NextTimeOffsetTransitionDateTime
  15259. /*
  15260. ShmOCPP16Data->ConfigurationTable.CoreProfile[NextTimeOffsetTransitionDateTime].ItemAccessibility = 1;
  15261. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NextTimeOffsetTransitionDateTime].ItemName, "NextTimeOffsetTransitionDateTime");
  15262. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NextTimeOffsetTransitionDateTime].ItemData, "FALSE" );
  15263. */
  15264. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","NextTimeOffsetTransitionDateTime", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NextTimeOffsetTransitionDateTime].ItemData);
  15265. // TimeOffsetNextTransition
  15266. /*
  15267. ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffsetNextTransition].ItemAccessibility = 1;
  15268. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffsetNextTransition].ItemName, "TimeOffsetNextTransition");
  15269. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffsetNextTransition].ItemData, "FALSE" );
  15270. */
  15271. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","TimeOffsetNextTransition", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffsetNextTransition].ItemData);
  15272. // SystemUptimeSec
  15273. /*
  15274. ShmOCPP16Data->ConfigurationTable.CoreProfile[SystemUptimeSec].ItemAccessibility = 1;
  15275. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SystemUptimeSec].ItemName, "SystemUptimeSec");
  15276. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SystemUptimeSec].ItemData, "0" );
  15277. */
  15278. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","SystemUptimeSec", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SystemUptimeSec].ItemData);
  15279. // FreeVend
  15280. /*
  15281. ShmOCPP16Data->ConfigurationTable.CoreProfile[FreeVend].ItemAccessibility = 1;
  15282. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[FreeVend].ItemName, "FreeVend");
  15283. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[FreeVend].ItemData, "FALSE" );
  15284. */
  15285. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","FreeVend", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[FreeVend].ItemData);
  15286. // FreeVendIdtag
  15287. /*
  15288. ShmOCPP16Data->ConfigurationTable.CoreProfile[FreeVendIdtag].ItemAccessibility = 1;
  15289. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[FreeVendIdtag].ItemName, "FreeVendIdtag");
  15290. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[FreeVendIdtag].ItemData, "FreeVendIdtag" );
  15291. */
  15292. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","FreeVendIdtag", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[FreeVendIdtag].ItemData);
  15293. // OcppServer
  15294. /*
  15295. ShmOCPP16Data->ConfigurationTable.CoreProfile[OcppServer].ItemAccessibility = 1;
  15296. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[OcppServer].ItemName, "OcppServer");
  15297. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[OcppServer].ItemData, "FALSE" );
  15298. */
  15299. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","OcppServer", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[OcppServer].ItemData);
  15300. // MaintainServer
  15301. /*
  15302. ShmOCPP16Data->ConfigurationTable.CoreProfile[MaintainServer].ItemAccessibility = 1;
  15303. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MaintainServer].ItemName, "MaintainServer");
  15304. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MaintainServer].ItemData, "FALSE" );
  15305. */
  15306. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MaintainServer", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MaintainServer].ItemData);
  15307. // StatusNotificationPeriodically
  15308. /*
  15309. ShmOCPP16Data->ConfigurationTable.CoreProfile[StatusNotificationPeriodically].ItemAccessibility =0;
  15310. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StatusNotificationPeriodically].ItemName, "StatusNotificationPeriodically");
  15311. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StatusNotificationPeriodically].ItemData, "FALSE" );
  15312. */
  15313. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StatusNotificationPeriodically", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StatusNotificationPeriodically].ItemData);
  15314. // StatusNotificationInterval
  15315. /*
  15316. ShmOCPP16Data->ConfigurationTable.CoreProfile[StatusNotificationInterval].ItemAccessibility = 1;
  15317. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StatusNotificationInterval].ItemName, "StatusNotificationInterval");
  15318. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StatusNotificationInterval].ItemData, "120" );
  15319. */
  15320. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StatusNotificationInterval", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StatusNotificationInterval].ItemData);
  15321. // PreAuthAmount
  15322. /*
  15323. ShmOCPP16Data->ConfigurationTable.CoreProfile[PreAuthAmount].ItemAccessibility = 1;
  15324. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[PreAuthAmount].ItemName, "PreAuthAmount");
  15325. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[PreAuthAmount].ItemData, "120" );
  15326. */
  15327. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","PreAuthAmount", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[PreAuthAmount].ItemData);
  15328. // isEnableLocalPowerSharing
  15329. /*
  15330. ShmOCPP16Data->ConfigurationTable.CoreProfile[isEnableLocalPowerSharing].ItemAccessibility = 1;
  15331. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[isEnableLocalPowerSharing].ItemName, "isEnableLocalPowerSharing");
  15332. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[isEnableLocalPowerSharing].ItemData, "0" );
  15333. */
  15334. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","isEnableLocalPowerSharing", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[isEnableLocalPowerSharing].ItemData);
  15335. // PowerSharingServerIP
  15336. /*
  15337. ShmOCPP16Data->ConfigurationTable.CoreProfile[PowerSharingServerIP].ItemAccessibility = 1;
  15338. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[PowerSharingServerIP].ItemName, "PowerSharingServerIP");
  15339. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[PowerSharingServerIP].ItemData, "" );
  15340. */
  15341. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","PowerSharingServerIP", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[PowerSharingServerIP].ItemData);
  15342. // EVCCID_PREFIX
  15343. /*
  15344. ShmOCPP16Data->ConfigurationTable.CoreProfile[EVCCID_PREFIX].ItemAccessibility = 1;
  15345. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[EVCCID_PREFIX].ItemName, "EVCCID_PREFIX");
  15346. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[EVCCID_PREFIX].ItemData, "" );
  15347. */
  15348. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","EVCCID_PREFIX", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[EVCCID_PREFIX].ItemData);
  15349. // OffLineMaxChargingPower
  15350. /*
  15351. ShmOCPP16Data->ConfigurationTable.CoreProfile[OffLineMaxChargingPower].ItemAccessibility = 1;
  15352. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[OffLineMaxChargingPower].ItemName, "OffLineMaxChargingPower");
  15353. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[OffLineMaxChargingPower].ItemData, "" );
  15354. */
  15355. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","OffLineMaxChargingPower", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[OffLineMaxChargingPower].ItemData);
  15356. // ConfigurationVersion
  15357. /*
  15358. ShmOCPP16Data->ConfigurationTable.CoreProfile[ConfigurationVersion].ItemAccessibility = 1;
  15359. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConfigurationVersion].ItemName, "ConfigurationVersion");
  15360. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConfigurationVersion].ItemData, "1" );
  15361. */
  15362. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ConfigurationVersion", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConfigurationVersion].ItemData);
  15363. // CharingProfileRefreshInterval
  15364. /*
  15365. ShmOCPP16Data->ConfigurationTable.CoreProfile[CharingProfileRefreshInterval].ItemAccessibility = 1;
  15366. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CharingProfileRefreshInterval].ItemName, "CharingProfileRefreshInterval");
  15367. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CharingProfileRefreshInterval].ItemData, "" );
  15368. */
  15369. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","CharingProfileRefreshInterval", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CharingProfileRefreshInterval].ItemData);
  15370. // OcppSoftwareVersion
  15371. /*
  15372. ShmOCPP16Data->ConfigurationTable.CoreProfile[OcppSoftwareVersion].ItemAccessibility = 1;
  15373. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[OcppSoftwareVersion].ItemName, "OcppSoftwareVersion");
  15374. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[OcppSoftwareVersion].ItemData, "" );
  15375. */
  15376. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","OcppSoftwareVersion", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[OcppSoftwareVersion].ItemData);
  15377. //* Local Auth List Management Profile*/
  15378. //LocalAuthListEnabled
  15379. /*
  15380. ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemAccessibility = 1;
  15381. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemName, "LocalAuthListEnabled");
  15382. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "TRUE" );
  15383. */
  15384. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LocalAuthListEnabled", "false", (char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData);
  15385. //LocalAuthListMaxLength
  15386. /*
  15387. ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemAccessibility = 0;
  15388. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemName, "LocalAuthListMaxLength");
  15389. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemData, "500" );
  15390. */
  15391. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LocalAuthListMaxLength", "true", (char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemData);
  15392. //SendLocalListMaxLength
  15393. /*
  15394. ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemAccessibility = 0;
  15395. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemName, "SendLocalListMaxLength");
  15396. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemData, "500" );
  15397. */
  15398. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","SendLocalListMaxLength", "true", (char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemData);
  15399. //ReserveConnectorZeroSupported
  15400. /*
  15401. ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemAccessibility = 0;
  15402. strcpy((char *)ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemName, "ReserveConnectorZeroSupported");
  15403. strcpy((char *)ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemData, "FALSE" );
  15404. */
  15405. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ReserveConnectorZeroSupported", "true", (char *)ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemData);
  15406. //* Smart Charging Profile */
  15407. //ChargeProfileMaxStackLevel
  15408. /*
  15409. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemAccessibility = 0;
  15410. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemName, "ChargeProfileMaxStackLevel");
  15411. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemData, "3" );
  15412. */
  15413. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ChargeProfileMaxStackLevel", "true", (char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemData);
  15414. // ChargingScheduleAllowedChargingRateUnit
  15415. /*
  15416. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemAccessibility = 0;
  15417. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemName, "ChargingScheduleAllowedChargingRateUnit");
  15418. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemData, "Current" );
  15419. */
  15420. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ChargingScheduleAllowedChargingRateUnit", "true", (char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemData);
  15421. // ChargingScheduleMaxPeriods
  15422. /*
  15423. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemAccessibility = 0;
  15424. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemName, "ChargingScheduleMaxPeriods");
  15425. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemData, "10" );
  15426. */
  15427. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ChargingScheduleMaxPeriods", "true", (char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemData);
  15428. // ConnectorSwitch3to1PhaseSupported
  15429. /*
  15430. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemAccessibility = 0;
  15431. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemName, "ConnectorSwitch3to1PhaseSupported");
  15432. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemData, "TRUE" );
  15433. */
  15434. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ConnectorSwitch3to1PhaseSupported", "true", (char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemData);
  15435. // MaxChargingProfilesInstalled
  15436. /*
  15437. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemAccessibility = 0;
  15438. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemName, "MaxChargingProfilesInstalled");
  15439. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemData, "10" );
  15440. */
  15441. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MaxChargingProfilesInstalled", "true", (char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemData);
  15442. fclose(outfile);
  15443. system("/bin/fsync -d /dev/mtdblock13;/bin/sync &");
  15444. }
  15445. void getKeyValue(char *keyReq)
  15446. {
  15447. int isEmpty = FALSE;
  15448. int isKnowKey = FALSE;
  15449. DEBUG_INFO("keyReq = %s\n", keyReq);
  15450. if((keyReq == NULL) || (strlen(keyReq) == 0))
  15451. isEmpty = TRUE;
  15452. if(isEmpty || strcmp(keyReq, "AllowOfflineTxForUnknownId") == 0)
  15453. {
  15454. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_AllowOfflineTxForUnknownId].Item, "AllowOfflineTxForUnknownId");
  15455. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AllowOfflineTxForUnknownId].Key, "AllowOfflineTxForUnknownId");
  15456. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemAccessibility == 1)
  15457. {
  15458. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AllowOfflineTxForUnknownId].ReadOnly, "0"/*"FALSE"*/);
  15459. }
  15460. else
  15461. {
  15462. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AllowOfflineTxForUnknownId].ReadOnly, "1"/*"TRUE"*/);
  15463. }
  15464. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AllowOfflineTxForUnknownId].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemData );
  15465. isKnowKey = TRUE;
  15466. }
  15467. if(isEmpty || strcmp(keyReq, "AuthorizationCacheEnabled") == 0 )
  15468. {
  15469. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_AuthorizationCacheEnabled].Item, "AuthorizationCacheEnabled");
  15470. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizationCacheEnabled].Key, "AuthorizationCacheEnabled");
  15471. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemAccessibility == 1)
  15472. {
  15473. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizationCacheEnabled].ReadOnly, "0"/*"FALSE"*/);
  15474. }
  15475. else
  15476. {
  15477. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizationCacheEnabled].ReadOnly, "1"/*"TRUE"*/);
  15478. }
  15479. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizationCacheEnabled].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemData );
  15480. isKnowKey = TRUE;
  15481. }
  15482. if(isEmpty || strcmp(keyReq, "AuthorizeRemoteTxRequests") == 0 )
  15483. {
  15484. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_AuthorizeRemoteTxRequests].Item, "AuthorizeRemoteTxRequests");
  15485. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizeRemoteTxRequests].Key, "AuthorizeRemoteTxRequests");
  15486. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemAccessibility == 1)
  15487. {
  15488. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizeRemoteTxRequests].ReadOnly, "0"/*"FALSE"*/);
  15489. }
  15490. else
  15491. {
  15492. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizeRemoteTxRequests].ReadOnly, "1"/*"TRUE"*/);
  15493. }
  15494. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizeRemoteTxRequests].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemData );
  15495. isKnowKey = TRUE;
  15496. }
  15497. if(isEmpty || strcmp(keyReq, "BlinkRepeat") == 0 )
  15498. {
  15499. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_BlinkRepeat].Item, "BlinkRepeat");
  15500. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_BlinkRepeat].Key, "BlinkRepeat");
  15501. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemAccessibility == 1)
  15502. {
  15503. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_BlinkRepeat].ReadOnly, "0"/*"FALSE"*/);
  15504. }
  15505. else
  15506. {
  15507. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_BlinkRepeat].ReadOnly, "1"/*"TRUE"*/);
  15508. }
  15509. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_BlinkRepeat].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemData );
  15510. isKnowKey = TRUE;
  15511. }
  15512. if(isEmpty || strcmp(keyReq, "ClockAlignedDataInterval") == 0 )
  15513. {
  15514. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_ClockAlignedDataInterval].Item, "ClockAlignedDataInterval");
  15515. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ClockAlignedDataInterval].Key, "ClockAlignedDataInterval");
  15516. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemAccessibility == 1)
  15517. {
  15518. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ClockAlignedDataInterval].ReadOnly, "0"/*"FALSE"*/);
  15519. }
  15520. else
  15521. {
  15522. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ClockAlignedDataInterval].ReadOnly, "1"/*"TRUE"*/);
  15523. }
  15524. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ClockAlignedDataInterval].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemData );
  15525. isKnowKey = TRUE;
  15526. }
  15527. if(isEmpty || strcmp(keyReq, "ConnectionTimeOut") == 0 )
  15528. {
  15529. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_ConnectionTimeOut].Item, "ConnectionTimeOut");
  15530. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectionTimeOut].Key, "ConnectionTimeOut");
  15531. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemAccessibility == 1)
  15532. {
  15533. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectionTimeOut].ReadOnly, "0"/*"FALSE"*/);
  15534. }
  15535. else
  15536. {
  15537. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectionTimeOut].ReadOnly, "1"/*"TRUE"*/);
  15538. }
  15539. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectionTimeOut].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemData );
  15540. isKnowKey = TRUE;
  15541. }
  15542. if(isEmpty || strcmp(keyReq, "GetConfigurationMaxKeys") == 0 )
  15543. {
  15544. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_GetConfigurationMaxKeys].Item, "GetConfigurationMaxKeys");
  15545. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_GetConfigurationMaxKeys].Key, "GetConfigurationMaxKeys");
  15546. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemAccessibility == 1)
  15547. {
  15548. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_GetConfigurationMaxKeys].ReadOnly, "0"/*"FALSE"*/);
  15549. }
  15550. else
  15551. {
  15552. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_GetConfigurationMaxKeys].ReadOnly, "1"/*"TRUE"*/);
  15553. }
  15554. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_GetConfigurationMaxKeys].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemData );
  15555. isKnowKey = TRUE;
  15556. }
  15557. if(isEmpty || strcmp(keyReq, "HeartbeatInterval") == 0 )
  15558. {
  15559. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_HeartbeatInterval].Item, "HeartbeatInterval");
  15560. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_HeartbeatInterval].Key, "HeartbeatInterval");
  15561. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemAccessibility == 1)
  15562. {
  15563. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_HeartbeatInterval].ReadOnly, "0"/*"FALSE"*/);
  15564. }
  15565. else
  15566. {
  15567. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_HeartbeatInterval].ReadOnly, "1"/*"TRUE"*/);
  15568. }
  15569. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_HeartbeatInterval].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemData );
  15570. isKnowKey = TRUE;
  15571. }
  15572. if(isEmpty || strcmp(keyReq, "LightIntensity") == 0 )
  15573. {
  15574. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_LightIntensity].Item, "LightIntensity");
  15575. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LightIntensity].Key, "LightIntensity");
  15576. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemAccessibility == 1)
  15577. {
  15578. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LightIntensity].ReadOnly, "0"/*"FALSE"*/);
  15579. }
  15580. else
  15581. {
  15582. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LightIntensity].ReadOnly, "1"/*"TRUE"*/);
  15583. }
  15584. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LightIntensity].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemData );
  15585. isKnowKey = TRUE;
  15586. }
  15587. if(isEmpty || strcmp(keyReq, "LocalAuthorizeOffline") == 0 )
  15588. {
  15589. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_LocalAuthorizeOffline].Item, "LocalAuthorizeOffline");
  15590. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthorizeOffline].Key, "LocalAuthorizeOffline");
  15591. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemAccessibility == 1)
  15592. {
  15593. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthorizeOffline].ReadOnly, "0"/*"FALSE"*/);
  15594. }
  15595. else
  15596. {
  15597. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthorizeOffline].ReadOnly, "1"/*"TRUE"*/);
  15598. }
  15599. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthorizeOffline].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemData );
  15600. isKnowKey = TRUE;
  15601. }
  15602. if(isEmpty || strcmp(keyReq, "LocalPreAuthorize") == 0 )
  15603. {
  15604. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_LocalPreAuthorize].Item, "LocalPreAuthorize");
  15605. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalPreAuthorize].Key, "LocalPreAuthorize");
  15606. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemAccessibility == 1)
  15607. {
  15608. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalPreAuthorize].ReadOnly, "0"/*"FALSE"*/);
  15609. }
  15610. else
  15611. {
  15612. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalPreAuthorize].ReadOnly, "1"/*"TRUE"*/);
  15613. }
  15614. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalPreAuthorize].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemData );
  15615. isKnowKey = TRUE;
  15616. }
  15617. if(isEmpty || strcmp(keyReq, "MaxEnergyOnInvalidId") == 0 )
  15618. {
  15619. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_MaxEnergyOnInvalidId].Item, "MaxEnergyOnInvalidId");
  15620. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaxEnergyOnInvalidId].Key, "MaxEnergyOnInvalidId");
  15621. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemAccessibility == 1)
  15622. {
  15623. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaxEnergyOnInvalidId].ReadOnly, "0"/*"FALSE"*/);
  15624. }
  15625. else
  15626. {
  15627. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaxEnergyOnInvalidId].ReadOnly, "1"/*"TRUE"*/);
  15628. }
  15629. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaxEnergyOnInvalidId].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemData );
  15630. isKnowKey = TRUE;
  15631. }
  15632. if(isEmpty || strcmp(keyReq, "MeterValuesAlignedData") == 0 )
  15633. {
  15634. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_MeterValuesAlignedData].Item, "MeterValuesAlignedData");
  15635. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesAlignedData].Key, "MeterValuesAlignedData");
  15636. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemAccessibility == 1)
  15637. {
  15638. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesAlignedData].ReadOnly, "0"/*"FALSE"*/);
  15639. }
  15640. else
  15641. {
  15642. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesAlignedData].ReadOnly, "1"/*"TRUE"*/);
  15643. }
  15644. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesAlignedData].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData );
  15645. isKnowKey = TRUE;
  15646. }
  15647. if(isEmpty || strcmp(keyReq, "MeterValuesAlignedDataMaxLength") == 0 )
  15648. {
  15649. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_MeterValuesAlignedDataMaxLength].Item, "MeterValuesAlignedDataMaxLength");
  15650. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesAlignedDataMaxLength].Key, "MeterValuesAlignedDataMaxLength");
  15651. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemAccessibility == 1)
  15652. {
  15653. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesAlignedDataMaxLength].ReadOnly, "0"/*"FALSE"*/);
  15654. }
  15655. else
  15656. {
  15657. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesAlignedDataMaxLength].ReadOnly, "1"/*"TRUE"*/);
  15658. }
  15659. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesAlignedDataMaxLength].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemData );
  15660. isKnowKey = TRUE;
  15661. }
  15662. if(isEmpty || strcmp(keyReq, "MeterValuesSampledData") == 0 )
  15663. {
  15664. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_MeterValuesSampledData].Item, "MeterValuesSampledData");
  15665. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesSampledData].Key, "MeterValuesSampledData");
  15666. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemAccessibility == 1)
  15667. {
  15668. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesSampledData].ReadOnly, "0"/*"FALSE"*/);
  15669. }
  15670. else
  15671. {
  15672. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesSampledData].ReadOnly, "1"/*"TRUE"*/);
  15673. }
  15674. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesSampledData].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData );
  15675. isKnowKey = TRUE;
  15676. }
  15677. if(isEmpty || strcmp(keyReq, "MeterValuesSampledDataMaxLength") == 0 )
  15678. {
  15679. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_MeterValuesSampledDataMaxLength].Item, "MeterValuesSampledDataMaxLength");
  15680. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesSampledDataMaxLength].Key, "MeterValuesSampledDataMaxLength");
  15681. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemAccessibility == 1)
  15682. {
  15683. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesSampledDataMaxLength].ReadOnly, "0"/*"FALSE"*/);
  15684. }
  15685. else
  15686. {
  15687. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesSampledDataMaxLength].ReadOnly, "1"/*"TRUE"*/);
  15688. }
  15689. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesSampledDataMaxLength].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemData );
  15690. isKnowKey = TRUE;
  15691. }
  15692. if(isEmpty || strcmp(keyReq, "MeterValueSampleInterval") == 0 )
  15693. {
  15694. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_MeterValueSampleInterval].Item, "MeterValueSampleInterval");
  15695. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValueSampleInterval].Key, "MeterValueSampleInterval");
  15696. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemAccessibility == 1)
  15697. {
  15698. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValueSampleInterval].ReadOnly, "0"/*"FALSE"*/);
  15699. }
  15700. else
  15701. {
  15702. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValueSampleInterval].ReadOnly, "1"/*"TRUE"*/);
  15703. }
  15704. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValueSampleInterval].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemData );
  15705. isKnowKey = TRUE;
  15706. }
  15707. if(isEmpty || strcmp(keyReq, "MinimumStatusDuration") == 0 )
  15708. {
  15709. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_MinimumStatusDuration].Item, "MinimumStatusDuration");
  15710. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MinimumStatusDuration].Key, "MinimumStatusDuration");
  15711. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemAccessibility == 1)
  15712. {
  15713. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MinimumStatusDuration].ReadOnly, "0"/*"FALSE"*/);
  15714. }
  15715. else
  15716. {
  15717. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MinimumStatusDuration].ReadOnly, "1"/*"TRUE"*/);
  15718. }
  15719. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MinimumStatusDuration].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[17].ItemData );
  15720. isKnowKey = TRUE;
  15721. }
  15722. if(isEmpty || strcmp(keyReq, "NumberOfConnectors") == 0 )
  15723. {
  15724. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_NumberOfConnectors].Item, "NumberOfConnectors");
  15725. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_NumberOfConnectors].Key, "NumberOfConnectors");
  15726. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemAccessibility == 1)
  15727. {
  15728. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_NumberOfConnectors].ReadOnly, "0"/*"FALSE"*/);
  15729. }
  15730. else
  15731. {
  15732. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_NumberOfConnectors].ReadOnly, "1"/*"TRUE"*/);
  15733. }
  15734. sprintf((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData, "%d", gunTotalNumber);
  15735. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_NumberOfConnectors].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData );
  15736. isKnowKey = TRUE;
  15737. }
  15738. if(isEmpty || strcmp(keyReq, "ResetRetries") == 0 )
  15739. {
  15740. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_ResetRetries].Item, "ResetRetries");
  15741. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ResetRetries].Key, "ResetRetries");
  15742. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemAccessibility == 1)
  15743. {
  15744. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ResetRetries].ReadOnly, "0"/*"FALSE"*/);
  15745. }
  15746. else
  15747. {
  15748. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ResetRetries].ReadOnly, "1"/*"TRUE"*/);
  15749. }
  15750. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ResetRetries].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemData );
  15751. isKnowKey = TRUE;
  15752. }
  15753. if(isEmpty || strcmp(keyReq, "ConnectorPhaseRotation") == 0 )
  15754. {
  15755. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_ConnectorPhaseRotation].Item, "ConnectorPhaseRotation");
  15756. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorPhaseRotation].Key, "ConnectorPhaseRotation");
  15757. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemAccessibility == 1)
  15758. {
  15759. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorPhaseRotation].ReadOnly, "0"/*"FALSE"*/);
  15760. }
  15761. else
  15762. {
  15763. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorPhaseRotation].ReadOnly, "1"/*"TRUE"*/);
  15764. }
  15765. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorPhaseRotation].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData );
  15766. isKnowKey = TRUE;
  15767. }
  15768. if(isEmpty || strcmp(keyReq, "ConnectorPhaseRotationMaxLength") == 0 )
  15769. {
  15770. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_ConnectorPhaseRotationMaxLength].Item, "ConnectorPhaseRotationMaxLength");
  15771. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorPhaseRotationMaxLength].Key, "ConnectorPhaseRotationMaxLength");
  15772. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemAccessibility == 1)
  15773. {
  15774. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorPhaseRotationMaxLength].ReadOnly, "0"/*"FALSE"*/);
  15775. }
  15776. else
  15777. {
  15778. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorPhaseRotationMaxLength].ReadOnly, "1"/*"TRUE"*/);
  15779. }
  15780. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorPhaseRotationMaxLength].Value,(const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemData );
  15781. isKnowKey = TRUE;
  15782. }
  15783. if(isEmpty || strcmp(keyReq, "StopTransactionOnEVSideDisconnect") == 0 )
  15784. {
  15785. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_StopTransactionOnEVSideDisconnect].Item, "StopTransactionOnEVSideDisconnect");
  15786. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTransactionOnEVSideDisconnect].Key, "StopTransactionOnEVSideDisconnect");
  15787. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemAccessibility == 1)
  15788. {
  15789. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTransactionOnEVSideDisconnect].ReadOnly, "0"/*"FALSE"*/);
  15790. }
  15791. else
  15792. {
  15793. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTransactionOnEVSideDisconnect].ReadOnly, "1"/*"TRUE"*/);
  15794. }
  15795. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTransactionOnEVSideDisconnect].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemData );
  15796. isKnowKey = TRUE;
  15797. }
  15798. if(isEmpty || strcmp(keyReq, "StopTransactionOnInvalidId") == 0 )
  15799. {
  15800. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_StopTransactionOnInvalidId].Item, "StopTransactionOnInvalidId");
  15801. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTransactionOnInvalidId].Key, "StopTransactionOnInvalidId");
  15802. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemAccessibility == 1)
  15803. {
  15804. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTransactionOnInvalidId].ReadOnly, "0"/*"FALSE"*/);
  15805. }
  15806. else
  15807. {
  15808. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTransactionOnInvalidId].ReadOnly, "1"/*"TRUE"*/);
  15809. }
  15810. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTransactionOnInvalidId].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemData );
  15811. isKnowKey = TRUE;
  15812. }
  15813. if(isEmpty || strcmp(keyReq, "StopTxnAlignedData") == 0 )
  15814. {
  15815. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_StopTxnAlignedData].Item, "StopTxnAlignedData");
  15816. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnAlignedData].Key, "StopTxnAlignedData");
  15817. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemAccessibility == 1)
  15818. {
  15819. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnAlignedData].ReadOnly, "0"/*"FALSE"*/);
  15820. }
  15821. else
  15822. {
  15823. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnAlignedData].ReadOnly, "1"/*"TRUE"*/);
  15824. }
  15825. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnAlignedData].Value,(const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemData );
  15826. isKnowKey = TRUE;
  15827. }
  15828. if(isEmpty || strcmp(keyReq, "StopTxnAlignedDataMaxLength") == 0 )
  15829. {
  15830. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_StopTxnAlignedDataMaxLength].Item, "StopTxnAlignedDataMaxLength");
  15831. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnAlignedDataMaxLength].Key, "StopTxnAlignedDataMaxLength");
  15832. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemAccessibility == 1)
  15833. {
  15834. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnAlignedDataMaxLength].ReadOnly, "0"/*"FALSE"*/);
  15835. }
  15836. else
  15837. {
  15838. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnAlignedDataMaxLength].ReadOnly, "1"/*"TRUE"*/);
  15839. }
  15840. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnAlignedDataMaxLength].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemData );
  15841. isKnowKey = TRUE;
  15842. }
  15843. if(isEmpty || strcmp(keyReq, "StopTxnSampledData") == 0 )
  15844. {
  15845. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_StopTxnSampledData].Item, "StopTxnSampledData");
  15846. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnSampledData].Key, "StopTxnSampledData");
  15847. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemAccessibility == 1)
  15848. {
  15849. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnSampledData].ReadOnly, "0"/*"FALSE"*/);
  15850. }
  15851. else
  15852. {
  15853. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnSampledData].ReadOnly, "1"/*"TRUE"*/);
  15854. }
  15855. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnSampledData].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData );
  15856. isKnowKey = TRUE;
  15857. }
  15858. if(isEmpty || strcmp(keyReq, "StopTxnSampledDataMaxLength") == 0 )
  15859. {
  15860. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_StopTxnSampledDataMaxLength].Item, "StopTxnSampledDataMaxLength");
  15861. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnSampledDataMaxLength].Key, "StopTxnSampledDataMaxLength");
  15862. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemAccessibility == 1)
  15863. {
  15864. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnSampledDataMaxLength].ReadOnly, "0"/*"FALSE"*/);
  15865. }
  15866. else
  15867. {
  15868. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnSampledDataMaxLength].ReadOnly, "1"/*"TRUE"*/);
  15869. }
  15870. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnSampledDataMaxLength].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemData );
  15871. isKnowKey = TRUE;
  15872. }
  15873. if(isEmpty || strcmp(keyReq, "SupportedFeatureProfiles") == 0 )
  15874. {
  15875. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_SupportedFeatureProfiles].Item, "SupportedFeatureProfiles");
  15876. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SupportedFeatureProfiles].Key, "SupportedFeatureProfiles");
  15877. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemAccessibility == 1)
  15878. {
  15879. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SupportedFeatureProfiles].ReadOnly, "0"/*"FALSE"*/);
  15880. }
  15881. else
  15882. {
  15883. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SupportedFeatureProfiles].ReadOnly, "1"/*"TRUE"*/);
  15884. }
  15885. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SupportedFeatureProfiles].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemData );
  15886. isKnowKey = TRUE;
  15887. }
  15888. if(isEmpty || strcmp(keyReq, "SupportedFeatureProfilesMaxLength") == 0 )
  15889. {
  15890. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_SupportedFeatureProfilesMaxLength].Item, "SupportedFeatureProfilesMaxLength");
  15891. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SupportedFeatureProfilesMaxLength].Key, "SupportedFeatureProfilesMaxLength");
  15892. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemAccessibility == 1)
  15893. {
  15894. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SupportedFeatureProfilesMaxLength].ReadOnly, "0"/*"FALSE"*/);
  15895. }
  15896. else
  15897. {
  15898. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SupportedFeatureProfilesMaxLength].ReadOnly, "1"/*"TRUE"*/);
  15899. }
  15900. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SupportedFeatureProfilesMaxLength].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemData );
  15901. isKnowKey = TRUE;
  15902. }
  15903. if(isEmpty || strcmp(keyReq, "TransactionMessageAttempts") == 0 )
  15904. {
  15905. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_TransactionMessageAttempts].Item, "TransactionMessageAttempts");
  15906. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TransactionMessageAttempts].Key, "TransactionMessageAttempts");
  15907. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemAccessibility == 1)
  15908. {
  15909. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TransactionMessageAttempts].ReadOnly, "0"/*"FALSE"*/);
  15910. }
  15911. else
  15912. {
  15913. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TransactionMessageAttempts].ReadOnly, "1"/*"TRUE"*/);
  15914. }
  15915. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TransactionMessageAttempts].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData );
  15916. isKnowKey = TRUE;
  15917. }
  15918. if(isEmpty || strcmp(keyReq, "TransactionMessageRetryInterval") == 0 )
  15919. {
  15920. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_TransactionMessageRetryInterval].Item, "TransactionMessageRetryInterval");
  15921. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TransactionMessageRetryInterval].Key, "TransactionMessageRetryInterval");
  15922. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemAccessibility == 1)
  15923. {
  15924. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TransactionMessageRetryInterval].ReadOnly, "0"/*"FALSE"*/);
  15925. }
  15926. else
  15927. {
  15928. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TransactionMessageRetryInterval].ReadOnly, "1"/*"TRUE"*/);
  15929. }
  15930. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TransactionMessageRetryInterval].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData );
  15931. isKnowKey = TRUE;
  15932. }
  15933. if(isEmpty || strcmp(keyReq, "UnlockConnectorOnEVSideDisconnect") == 0 )
  15934. {
  15935. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_UnlockConnectorOnEVSideDisconnect].Item, "UnlockConnectorOnEVSideDisconnect");
  15936. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_UnlockConnectorOnEVSideDisconnect].Key, "UnlockConnectorOnEVSideDisconnect");
  15937. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemAccessibility == 1)
  15938. {
  15939. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_UnlockConnectorOnEVSideDisconnect].ReadOnly, "0"/*"FALSE"*/);
  15940. }
  15941. else
  15942. {
  15943. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_UnlockConnectorOnEVSideDisconnect].ReadOnly, "1"/*"TRUE"*/);
  15944. }
  15945. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_UnlockConnectorOnEVSideDisconnect].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemData );
  15946. isKnowKey = TRUE;
  15947. }
  15948. if(isEmpty || strcmp(keyReq, "WebSocketPingInterval") == 0 )
  15949. {
  15950. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_WebSocketPingInterval].Item, "WebSocketPingInterval");
  15951. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_WebSocketPingInterval].Key, "WebSocketPingInterval");
  15952. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemAccessibility == 1)
  15953. {
  15954. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_WebSocketPingInterval].ReadOnly, "0"/*"FALSE"*/);
  15955. }
  15956. else
  15957. {
  15958. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_WebSocketPingInterval].ReadOnly, "1"/*"TRUE"*/);
  15959. }
  15960. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_WebSocketPingInterval].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemData );
  15961. isKnowKey = TRUE;
  15962. }
  15963. if(isEmpty || strcmp(keyReq, "QueueOffLineMeterValues") == 0 )
  15964. {
  15965. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_QueueOffLineMeterValues].Item, "QueueOffLineMeterValues");
  15966. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_QueueOffLineMeterValues].Key, "QueueOffLineMeterValues");
  15967. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[QueueOffLineMeterValues].ItemAccessibility == 1)
  15968. {
  15969. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_QueueOffLineMeterValues].ReadOnly, "0"/*"FALSE"*/);
  15970. }
  15971. else
  15972. {
  15973. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_QueueOffLineMeterValues].ReadOnly, "1"/*"TRUE"*/);
  15974. }
  15975. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_QueueOffLineMeterValues].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[QueueOffLineMeterValues].ItemData );
  15976. isKnowKey = TRUE;
  15977. }
  15978. /*
  15979. if(isEmpty || strcmp(keyReq, "AuthorizationKey") == 0 )
  15980. {
  15981. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_AuthorizationKey].Item, "AuthorizationKey");
  15982. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizationKey].Key, "AuthorizationKey");
  15983. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationKey].ItemAccessibility == 1)
  15984. {
  15985. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizationKey].ReadOnly, "0");
  15986. }
  15987. else
  15988. {
  15989. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizationKey].ReadOnly, "1");
  15990. }
  15991. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizationKey].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationKey].ItemData );
  15992. isKnowKey = TRUE;
  15993. }*/
  15994. if(isEmpty || strcmp(keyReq, "SecurityProfile") == 0 )
  15995. {
  15996. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_SecurityProfile].Item, "SecurityProfile");
  15997. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SecurityProfile].Key, "SecurityProfile");
  15998. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[SecurityProfile].ItemAccessibility == 1)
  15999. {
  16000. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SecurityProfile].ReadOnly, "0"/*"FALSE"*/);
  16001. }
  16002. else
  16003. {
  16004. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SecurityProfile].ReadOnly, "1"/*"TRUE"*/);
  16005. }
  16006. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SecurityProfile].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SecurityProfile].ItemData );
  16007. isKnowKey = TRUE;
  16008. }
  16009. if(isEmpty || strcmp(keyReq, "DefaultPrice") == 0 )
  16010. {
  16011. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_DefaultPrice].Item, "DefaultPrice");
  16012. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_DefaultPrice].Key, "DefaultPrice");
  16013. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[DefaultPrice].ItemAccessibility == 1)
  16014. {
  16015. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_DefaultPrice].ReadOnly, "0"/*"FALSE"*/);
  16016. }
  16017. else
  16018. {
  16019. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_DefaultPrice].ReadOnly, "1"/*"TRUE"*/);
  16020. }
  16021. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_DefaultPrice].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[DefaultPrice].ItemData );
  16022. isKnowKey = TRUE;
  16023. }
  16024. if(isEmpty || strcmp(keyReq, "CustomDisplayCostAndPrice") == 0 )
  16025. {
  16026. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_CustomDisplayCostAndPrice].Item, "CustomDisplayCostAndPrice");
  16027. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_CustomDisplayCostAndPrice].Key, "CustomDisplayCostAndPrice");
  16028. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemAccessibility == 1)
  16029. {
  16030. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_CustomDisplayCostAndPrice].ReadOnly, "0"/*"FALSE"*/);
  16031. }
  16032. else
  16033. {
  16034. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_CustomDisplayCostAndPrice].ReadOnly, "1"/*"TRUE"*/);
  16035. }
  16036. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_CustomDisplayCostAndPrice].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemData );
  16037. isKnowKey = TRUE;
  16038. }
  16039. if(isEmpty || strcmp(keyReq, "CustomIdleFeeAfterStop") == 0 )
  16040. {
  16041. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_CustomIdleFeeAfterStop].Item, "CustomIdleFeeAfterStop");
  16042. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_CustomIdleFeeAfterStop].Key, "CustomIdleFeeAfterStop");
  16043. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemAccessibility == 1)
  16044. {
  16045. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_CustomIdleFeeAfterStop].ReadOnly, "0"/*"FALSE"*/);
  16046. }
  16047. else
  16048. {
  16049. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_CustomIdleFeeAfterStop].ReadOnly, "1"/*"TRUE"*/);
  16050. }
  16051. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_CustomIdleFeeAfterStop].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemData );
  16052. isKnowKey = TRUE;
  16053. }
  16054. if(isEmpty || strcmp(keyReq, "TimeOffset") == 0 )
  16055. {
  16056. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_TimeOffset].Item, "TimeOffset");
  16057. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TimeOffset].Key, "TimeOffset");
  16058. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffset].ItemAccessibility == 1)
  16059. {
  16060. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TimeOffset].ReadOnly, "0"/*"FALSE"*/);
  16061. }
  16062. else
  16063. {
  16064. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TimeOffset].ReadOnly, "1"/*"TRUE"*/);
  16065. }
  16066. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TimeOffset].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffset].ItemData );
  16067. isKnowKey = TRUE;
  16068. }
  16069. if(isEmpty || strcmp(keyReq, "NextTimeOffsetTransitionDateTime") == 0 )
  16070. {
  16071. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_NextTimeOffsetTransitionDateTime].Item, "NextTimeOffsetTransitionDateTime");
  16072. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_NextTimeOffsetTransitionDateTime].Key, "NextTimeOffsetTransitionDateTime");
  16073. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[NextTimeOffsetTransitionDateTime].ItemAccessibility == 1)
  16074. {
  16075. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_NextTimeOffsetTransitionDateTime].ReadOnly, "0"/*"FALSE"*/);
  16076. }
  16077. else
  16078. {
  16079. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_NextTimeOffsetTransitionDateTime].ReadOnly, "1"/*"TRUE"*/);
  16080. }
  16081. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_NextTimeOffsetTransitionDateTime].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NextTimeOffsetTransitionDateTime].ItemData );
  16082. isKnowKey = TRUE;
  16083. }
  16084. if(isEmpty || strcmp(keyReq, "TimeOffsetNextTransition") == 0 )
  16085. {
  16086. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_TimeOffsetNextTransition].Item, "TimeOffsetNextTransition");
  16087. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TimeOffsetNextTransition].Key, "TimeOffsetNextTransition");
  16088. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffsetNextTransition].ItemAccessibility == 1)
  16089. {
  16090. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TimeOffsetNextTransition].ReadOnly, "0"/*"FALSE"*/);
  16091. }
  16092. else
  16093. {
  16094. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TimeOffsetNextTransition].ReadOnly, "1"/*"TRUE"*/);
  16095. }
  16096. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TimeOffsetNextTransition].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffsetNextTransition].ItemData );
  16097. isKnowKey = TRUE;
  16098. }
  16099. if(isEmpty || strcmp(keyReq, "SystemUptimeSec") == 0 )
  16100. {
  16101. struct sysinfo s_info;
  16102. int error = sysinfo(&s_info);
  16103. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_SystemUptimeSec].Item, "SystemUptimeSec");
  16104. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SystemUptimeSec].Key, "SystemUptimeSec");
  16105. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[SystemUptimeSec].ItemAccessibility == 1)
  16106. {
  16107. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SystemUptimeSec].ReadOnly, "0"/*"FALSE"*/);
  16108. }
  16109. else
  16110. {
  16111. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SystemUptimeSec].ReadOnly, "1"/*"TRUE"*/);
  16112. }
  16113. if(error != 0)
  16114. {
  16115. DEBUG_WARN("System uptime get error: %d\n", error);
  16116. }
  16117. else
  16118. {
  16119. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SystemUptimeSec].ItemData, "%ld", s_info.uptime);
  16120. sprintf((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SystemUptimeSec].Value, "%ld", s_info.uptime);
  16121. }
  16122. isKnowKey = TRUE;
  16123. }
  16124. if(isEmpty || strcmp(keyReq, "FreeVend") == 0 )
  16125. {
  16126. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_FreeVend].Item, "FreeVend");
  16127. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_FreeVend].Key, "FreeVend");
  16128. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[FreeVend].ItemAccessibility == 1)
  16129. {
  16130. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_FreeVend].ReadOnly, "0"/*"FALSE"*/);
  16131. }
  16132. else
  16133. {
  16134. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_FreeVend].ReadOnly, "1"/*"TRUE"*/);
  16135. }
  16136. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_FreeVend].Value, (ShmSysConfigAndInfo->SysConfig.AuthorisationMode?"TRUE":"FALSE"));
  16137. isKnowKey = TRUE;
  16138. }
  16139. if(isEmpty || strcmp(keyReq, "FreeVendIdtag") == 0 )
  16140. {
  16141. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_FreeVendIdtag].Item, "FreeVendIdtag");
  16142. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_FreeVendIdtag].Key, "FreeVendIdtag");
  16143. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[FreeVendIdtag].ItemAccessibility == 1)
  16144. {
  16145. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_FreeVendIdtag].ReadOnly, "0"/*"FALSE"*/);
  16146. }
  16147. else
  16148. {
  16149. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_FreeVendIdtag].ReadOnly, "1"/*"TRUE"*/);
  16150. }
  16151. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_FreeVendIdtag].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[FreeVendIdtag].ItemData);
  16152. isKnowKey = TRUE;
  16153. }
  16154. if(isEmpty || strcmp(keyReq, "OcppServer") == 0 )
  16155. {
  16156. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_OcppServer].Item, "OcppServer");
  16157. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_OcppServer].Key, "OcppServer");
  16158. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[OcppServer].ItemAccessibility == 1)
  16159. {
  16160. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_OcppServer].ReadOnly, "0"/*"FALSE"*/);
  16161. }
  16162. else
  16163. {
  16164. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_OcppServer].ReadOnly, "1"/*"TRUE"*/);
  16165. }
  16166. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_OcppServer].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[OcppServer].ItemData);
  16167. isKnowKey = TRUE;
  16168. }
  16169. if(isEmpty || strcmp(keyReq, "MaintainServer") == 0 )
  16170. {
  16171. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_MaintainServer].Item, "MaintainServer");
  16172. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaintainServer].Key, "MaintainServer");
  16173. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MaintainServer].ItemAccessibility == 1)
  16174. {
  16175. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaintainServer].ReadOnly, "0"/*"FALSE"*/);
  16176. }
  16177. else
  16178. {
  16179. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaintainServer].ReadOnly, "1"/*"TRUE"*/);
  16180. }
  16181. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaintainServer].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MaintainServer].ItemData);
  16182. isKnowKey = TRUE;
  16183. }
  16184. if(isEmpty || strcmp(keyReq, "StatusNotificationPeriodically") == 0 )
  16185. {
  16186. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_StatusNotificationPeriodically].Item, "StatusNotificationPeriodically");
  16187. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StatusNotificationPeriodically].Key, "StatusNotificationPeriodically");
  16188. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StatusNotificationPeriodically].ItemAccessibility == 1)
  16189. {
  16190. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StatusNotificationPeriodically].ReadOnly, "0"/*"FALSE"*/);
  16191. }
  16192. else
  16193. {
  16194. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StatusNotificationPeriodically].ReadOnly, "1"/*"TRUE"*/);
  16195. }
  16196. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StatusNotificationPeriodically].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StatusNotificationPeriodically].ItemData );
  16197. isKnowKey = TRUE;
  16198. }
  16199. if(isEmpty || strcmp(keyReq, "StatusNotificationInterval") == 0 )
  16200. {
  16201. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_StatusNotificationInterval].Item, "StatusNotificationInterval");
  16202. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StatusNotificationInterval].Key, "StatusNotificationInterval");
  16203. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StatusNotificationInterval].ItemAccessibility == 1)
  16204. {
  16205. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StatusNotificationInterval].ReadOnly, "0"/*"FALSE"*/);
  16206. }
  16207. else
  16208. {
  16209. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StatusNotificationInterval].ReadOnly, "1"/*"TRUE"*/);
  16210. }
  16211. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StatusNotificationInterval].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StatusNotificationInterval].ItemData );
  16212. isKnowKey = TRUE;
  16213. }
  16214. if(isEmpty || strcmp(keyReq, "PreAuthAmount") == 0 )
  16215. {
  16216. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_PreAuthAmount].Item, "PreAuthAmount");
  16217. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_PreAuthAmount].Key, "PreAuthAmount");
  16218. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[PreAuthAmount].ItemAccessibility == 1)
  16219. {
  16220. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_PreAuthAmount].ReadOnly, "0"/*"FALSE"*/);
  16221. }
  16222. else
  16223. {
  16224. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_PreAuthAmount].ReadOnly, "1"/*"TRUE"*/);
  16225. }
  16226. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_PreAuthAmount].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[PreAuthAmount].ItemData );
  16227. isKnowKey = TRUE;
  16228. }
  16229. if(isEmpty || strcmp(keyReq, "isEnableLocalPowerSharing") == 0 )
  16230. {
  16231. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_isEnableLocalPowerSharing].Item, "isEnableLocalPowerSharing");
  16232. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_isEnableLocalPowerSharing].Key, "isEnableLocalPowerSharing");
  16233. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[isEnableLocalPowerSharing].ItemAccessibility == 1)
  16234. {
  16235. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_isEnableLocalPowerSharing].ReadOnly, "0"/*"FALSE"*/);
  16236. }
  16237. else
  16238. {
  16239. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_isEnableLocalPowerSharing].ReadOnly, "1"/*"TRUE"*/);
  16240. }
  16241. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_isEnableLocalPowerSharing].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[isEnableLocalPowerSharing].ItemData );
  16242. isKnowKey = TRUE;
  16243. }
  16244. if(isEmpty || strcmp(keyReq, "PowerSharingServerIP") == 0 )
  16245. {
  16246. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_PowerSharingServerIP].Item, "PowerSharingServerIP");
  16247. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_PowerSharingServerIP].Key, "PowerSharingServerIP");
  16248. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[PowerSharingServerIP].ItemAccessibility == 1)
  16249. {
  16250. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_PowerSharingServerIP].ReadOnly, "0"/*"FALSE"*/);
  16251. }
  16252. else
  16253. {
  16254. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_PowerSharingServerIP].ReadOnly, "1"/*"TRUE"*/);
  16255. }
  16256. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_PowerSharingServerIP].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[PowerSharingServerIP].ItemData );
  16257. isKnowKey = TRUE;
  16258. }
  16259. if(isEmpty || strcmp(keyReq, "EVCCID_PREFIX") == 0 )
  16260. {
  16261. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_EVCCID_PREFIX].Item, "EVCCID_PREFIX");
  16262. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_EVCCID_PREFIX].Key, "EVCCID_PREFIX");
  16263. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[EVCCID_PREFIX].ItemAccessibility == 1)
  16264. {
  16265. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_EVCCID_PREFIX].ReadOnly, "0"/*"FALSE"*/);
  16266. }
  16267. else
  16268. {
  16269. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_EVCCID_PREFIX].ReadOnly, "1"/*"TRUE"*/);
  16270. }
  16271. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_EVCCID_PREFIX].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[EVCCID_PREFIX].ItemData );
  16272. isKnowKey = TRUE;
  16273. }
  16274. if(isEmpty || strcmp(keyReq, "OffLineMaxChargingPower") == 0 )
  16275. {
  16276. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_OffLineMaxChargingPower].Item, "OffLineMaxChargingPower");
  16277. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_OffLineMaxChargingPower].Key, "OffLineMaxChargingPower");
  16278. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[OffLineMaxChargingPower].ItemAccessibility == 1)
  16279. {
  16280. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_OffLineMaxChargingPower].ReadOnly, "0"/*"FALSE"*/);
  16281. }
  16282. else
  16283. {
  16284. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_OffLineMaxChargingPower].ReadOnly, "1"/*"TRUE"*/);
  16285. }
  16286. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_OffLineMaxChargingPower].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[OffLineMaxChargingPower].ItemData );
  16287. isKnowKey = TRUE;
  16288. }
  16289. if(isEmpty || strcmp(keyReq, "ConfigurationVersion") == 0 )
  16290. {
  16291. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_ConfigurationVersion].Item, "ConfigurationVersion");
  16292. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConfigurationVersion].Key, "ConfigurationVersion");
  16293. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[ConfigurationVersion].ItemAccessibility == 1)
  16294. {
  16295. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConfigurationVersion].ReadOnly, "0"/*"FALSE"*/);
  16296. }
  16297. else
  16298. {
  16299. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConfigurationVersion].ReadOnly, "1"/*"TRUE"*/);
  16300. }
  16301. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConfigurationVersion].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConfigurationVersion].ItemData );
  16302. isKnowKey = TRUE;
  16303. }
  16304. if(isEmpty || strcmp(keyReq, "CharingProfileRefreshInterval") == 0 )
  16305. {
  16306. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_CharingProfileRefreshInterval].Item, "CharingProfileRefreshInterval");
  16307. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_CharingProfileRefreshInterval].Key, "CharingProfileRefreshInterval");
  16308. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[CharingProfileRefreshInterval].ItemAccessibility == 1)
  16309. {
  16310. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_CharingProfileRefreshInterval].ReadOnly, "0"/*"FALSE"*/);
  16311. }
  16312. else
  16313. {
  16314. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_CharingProfileRefreshInterval].ReadOnly, "1"/*"TRUE"*/);
  16315. }
  16316. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_CharingProfileRefreshInterval].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CharingProfileRefreshInterval].ItemData );
  16317. isKnowKey = TRUE;
  16318. }
  16319. if(isEmpty || strcmp(keyReq, "OcppSoftwareVersion") == 0 )
  16320. {
  16321. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_OcppSoftwareVersion].Item, "OcppSoftwareVersion");
  16322. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_OcppSoftwareVersion].Key, "OcppSoftwareVersion");
  16323. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[OcppSoftwareVersion].ItemAccessibility == 1)
  16324. {
  16325. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_OcppSoftwareVersion].ReadOnly, "0"/*"FALSE"*/);
  16326. }
  16327. else
  16328. {
  16329. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_OcppSoftwareVersion].ReadOnly, "1"/*"TRUE"*/);
  16330. }
  16331. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_OcppSoftwareVersion].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[OcppSoftwareVersion].ItemData );
  16332. isKnowKey = TRUE;
  16333. }
  16334. #if 1
  16335. if(isEmpty || strcmp(keyReq, "LocalAuthListEnabled") == 0 )
  16336. {
  16337. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_LocalAuthListEnabled].Item, "LocalAuthListEnabled");
  16338. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListEnabled].Key, "LocalAuthListEnabled");
  16339. if(ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemAccessibility == 1)
  16340. {
  16341. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListEnabled].ReadOnly, "0"/*"FALSE"*/);
  16342. }
  16343. else
  16344. {
  16345. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListEnabled].ReadOnly, "1"/*"TRUE"*/);
  16346. }
  16347. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListEnabled].Value, (const char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData );
  16348. isKnowKey = TRUE;
  16349. }
  16350. #endif
  16351. if(isEmpty || strcmp(keyReq, "LocalAuthListMaxLength") == 0 )
  16352. {
  16353. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_LocalAuthListMaxLength].Item, "LocalAuthListMaxLength");
  16354. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListMaxLength].Key, "LocalAuthListMaxLength");
  16355. if(ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemAccessibility == 1)
  16356. {
  16357. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListMaxLength].ReadOnly, "0"/*"FALSE"*/);
  16358. }
  16359. else
  16360. {
  16361. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListMaxLength].ReadOnly, "1"/*"TRUE"*/);
  16362. }
  16363. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListMaxLength].Value, (const char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemData );
  16364. isKnowKey = TRUE;
  16365. }
  16366. if(isEmpty || strcmp(keyReq, "SendLocalListMaxLength") == 0 )
  16367. {
  16368. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_SendLocalListMaxLength].Item, "SendLocalListMaxLength");
  16369. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SendLocalListMaxLength].Key, "SendLocalListMaxLength");
  16370. if(ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemAccessibility == 1)
  16371. {
  16372. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SendLocalListMaxLength].ReadOnly, "0"/*"FALSE"*/);
  16373. }
  16374. else
  16375. {
  16376. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SendLocalListMaxLength].ReadOnly, "1"/*"TRUE"*/);
  16377. }
  16378. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SendLocalListMaxLength].Value, (const char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemData );
  16379. isKnowKey = TRUE;
  16380. }
  16381. if(isEmpty || strcmp(keyReq, "ReserveConnectorZeroSupported") == 0 )
  16382. {
  16383. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_ReserveConnectorZeroSupported].Item, "ReserveConnectorZeroSupported");
  16384. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ReserveConnectorZeroSupported].Key, "ReserveConnectorZeroSupported");
  16385. if(ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemAccessibility == 1)
  16386. {
  16387. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ReserveConnectorZeroSupported].ReadOnly, "0"/*"FALSE"*/);
  16388. }
  16389. else
  16390. {
  16391. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ReserveConnectorZeroSupported].ReadOnly, "1"/*"TRUE"*/);
  16392. }
  16393. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ReserveConnectorZeroSupported].Value,(const char *)ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemData);
  16394. isKnowKey = TRUE;
  16395. }
  16396. if(isEmpty || strcmp(keyReq, "ChargeProfileMaxStackLevel") == 0 )
  16397. {
  16398. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_ChargeProfileMaxStackLevel].Item, "ChargeProfileMaxStackLevel");
  16399. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargeProfileMaxStackLevel].Key, "ChargeProfileMaxStackLevel");
  16400. if(ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemAccessibility == 1)
  16401. {
  16402. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargeProfileMaxStackLevel].ReadOnly, "0"/*"FALSE"*/);
  16403. }
  16404. else
  16405. {
  16406. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargeProfileMaxStackLevel].ReadOnly, "1"/*"TRUE"*/);
  16407. }
  16408. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargeProfileMaxStackLevel].Value, (const char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemData);
  16409. isKnowKey = TRUE;
  16410. }
  16411. if(isEmpty || strcmp(keyReq, "ChargingScheduleAllowedChargingRateUnit") == 0 )
  16412. {
  16413. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_ChargingScheduleAllowedChargingRateUnit].Item, "ChargingScheduleAllowedChargingRateUnit");
  16414. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargingScheduleAllowedChargingRateUnit].Key, "ChargingScheduleAllowedChargingRateUnit");
  16415. if(ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemAccessibility == 1)
  16416. {
  16417. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargingScheduleAllowedChargingRateUnit].ReadOnly, "0"/*"FALSE"*/);
  16418. }
  16419. else
  16420. {
  16421. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargingScheduleAllowedChargingRateUnit].ReadOnly, "1"/*"TRUE"*/);
  16422. }
  16423. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargingScheduleAllowedChargingRateUnit].Value, (const char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemData);
  16424. isKnowKey = TRUE;
  16425. }
  16426. if(isEmpty || strcmp(keyReq, "ChargingScheduleMaxPeriods") == 0 )
  16427. {
  16428. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_ChargingScheduleMaxPeriods].Item, "ChargingScheduleMaxPeriods");
  16429. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargingScheduleMaxPeriods].Key, "ChargingScheduleMaxPeriods");
  16430. if(ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemAccessibility == 1)
  16431. {
  16432. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargingScheduleMaxPeriods].ReadOnly, "0"/*"FALSE"*/);
  16433. }
  16434. else
  16435. {
  16436. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargingScheduleMaxPeriods].ReadOnly, "1"/*"TRUE"*/);
  16437. }
  16438. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargingScheduleMaxPeriods].Value, (const char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemData);
  16439. isKnowKey = TRUE;
  16440. }
  16441. if(isEmpty || strcmp(keyReq, "ConnectorSwitch3to1PhaseSupported") == 0 )
  16442. {
  16443. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_ConnectorSwitch3to1PhaseSupported].Item, "ConnectorSwitch3to1PhaseSupported");
  16444. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorSwitch3to1PhaseSupported].Key, "ConnectorSwitch3to1PhaseSupported");
  16445. if(ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemAccessibility == 1)
  16446. {
  16447. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorSwitch3to1PhaseSupported].ReadOnly, "0"/*"FALSE"*/);
  16448. }
  16449. else
  16450. {
  16451. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorSwitch3to1PhaseSupported].ReadOnly, "1"/*"TRUE"*/);
  16452. }
  16453. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorSwitch3to1PhaseSupported].Value, (const char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemData);
  16454. isKnowKey = TRUE;
  16455. }
  16456. if(isEmpty || strcmp(keyReq, "MaxChargingProfilesInstalled") == 0 )
  16457. {
  16458. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_MaxChargingProfilesInstalled].Item, "MaxChargingProfilesInstalled");
  16459. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaxChargingProfilesInstalled].Key, "MaxChargingProfilesInstalled");
  16460. if(ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemAccessibility == 1)
  16461. {
  16462. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaxChargingProfilesInstalled].ReadOnly, "0"/*"FLASE"*/);
  16463. }
  16464. else
  16465. {
  16466. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaxChargingProfilesInstalled].ReadOnly, "1"/*"TRUE"*/);
  16467. }
  16468. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaxChargingProfilesInstalled].Value, (const char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemData);
  16469. isKnowKey = TRUE;
  16470. }
  16471. //=========================================================
  16472. if(!isEmpty && !isKnowKey)
  16473. {
  16474. DEBUG_INFO("unKnowIndex =%d\n", UnknownKeynum);
  16475. strcpy(unknownkey[UnknownKeynum], keyReq);
  16476. UnknownKeynum = UnknownKeynum + 1;
  16477. }
  16478. }
  16479. void processUnkownKey(void)
  16480. {
  16481. DEBUG_INFO("processUnkownKey...\n");
  16482. memset(ShmOCPP16Data->GetConfiguration.ResponseUnknownKey, 0 , sizeof(struct StructConfigurationKeyItems)* 10);
  16483. for(int index=0; index < UnknownKeynum; index++)
  16484. {
  16485. if(ShmOCPP16Data->GetConfiguration.ResponseUnknownKey[index].Item[0] == 0)
  16486. {
  16487. strcpy((char *)(ShmOCPP16Data->GetConfiguration.ResponseUnknownKey[index].Item), unknownkey[index]);
  16488. }
  16489. }
  16490. }
  16491. int setKeyValue(char *key, char *value)
  16492. {
  16493. int isSuccess = NotSupported;
  16494. int check_ascii=0;
  16495. char str[501]={0};
  16496. DEBUG_INFO(" setKeyValue %s = %s\n", key, value);
  16497. if(strcmp(key, "AllowOfflineTxForUnknownId") == 0)
  16498. {
  16499. //Charger.AllowOfflineTxForUnknownId = (value.toLowerCase().equals("true")?true:false);
  16500. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemAccessibility == 1)
  16501. {
  16502. strcpy(str, (const char*)value);
  16503. for(int i = 0; str[i]; i++){
  16504. str[i] = tolower(str[i]);
  16505. }
  16506. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  16507. isSuccess = ConfigurationStatus_Accepted;
  16508. }
  16509. else
  16510. {
  16511. isSuccess = ConfigurationStatus_Rejected;
  16512. }
  16513. }
  16514. if(strcmp(key, "AuthorizationCacheEnabled") == 0)
  16515. {
  16516. //Charger.AuthorizationCacheEnabled = (value.toLowerCase().equals("true")?true:false);
  16517. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemAccessibility == 1)
  16518. {
  16519. strcpy(str, (const char*)value);
  16520. for(int i = 0; str[i]; i++){
  16521. str[i] = tolower(str[i]);
  16522. }
  16523. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  16524. isSuccess = ConfigurationStatus_Accepted;
  16525. //updateSetting("AuthorizationCacheEnabled",(char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[1].ItemData);
  16526. }
  16527. else
  16528. {
  16529. isSuccess = ConfigurationStatus_Rejected;
  16530. }
  16531. }
  16532. if(strcmp(key, "AuthorizeRemoteTxRequests") == 0)
  16533. {
  16534. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemAccessibility == 1)
  16535. {
  16536. strcpy(str, (const char*)value);
  16537. for(int i = 0; str[i]; i++)
  16538. {
  16539. str[i] = tolower(str[i]);
  16540. }
  16541. //Charger.AuthorizeRemoteTxRequests = (value.toLowerCase().equals("true")?true:false);
  16542. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  16543. isSuccess = ConfigurationStatus_Accepted;
  16544. }
  16545. else
  16546. {
  16547. isSuccess = ConfigurationStatus_Rejected;
  16548. }
  16549. }
  16550. if(strcmp(key, "BlinkRepeat") == 0)
  16551. {
  16552. //Charger.BlinkRepeat = Integer.parseInt(value);
  16553. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemAccessibility == 1)
  16554. {
  16555. check_ascii = value[0];
  16556. if( (check_ascii < 48) || (check_ascii > 57) )
  16557. {
  16558. isSuccess = ConfigurationStatus_Rejected;
  16559. }
  16560. else
  16561. {
  16562. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemData, "%d", atoi(value) );
  16563. isSuccess = ConfigurationStatus_Accepted;
  16564. }
  16565. }
  16566. else
  16567. {
  16568. isSuccess = ConfigurationStatus_Rejected;
  16569. }
  16570. }
  16571. if(strcmp(key, "ClockAlignedDataInterval") == 0)
  16572. {
  16573. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemAccessibility == 1)
  16574. {
  16575. check_ascii = value[0];
  16576. if( (check_ascii < 48) || (check_ascii > 57) )
  16577. {
  16578. isSuccess = ConfigurationStatus_Rejected;
  16579. }
  16580. else
  16581. {
  16582. if((atoi(value) == 0) || (atoi(value) >= 5))
  16583. {
  16584. //Charger.ClockAlignedDataInterval = Integer.parseInt(value)*1000;
  16585. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemData, "%d", atoi(value) );
  16586. isSuccess = ConfigurationStatus_Accepted;
  16587. }
  16588. else
  16589. isSuccess = ConfigurationStatus_Rejected;
  16590. }
  16591. }
  16592. else
  16593. {
  16594. isSuccess = ConfigurationStatus_Rejected;
  16595. }
  16596. }
  16597. if(strcmp(key, "ConnectionTimeOut") == 0 )
  16598. {
  16599. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemAccessibility == 1)
  16600. {
  16601. check_ascii = value[0];
  16602. if( (check_ascii < 48) || (check_ascii > 57) )
  16603. {
  16604. isSuccess = ConfigurationStatus_Rejected;
  16605. }
  16606. else
  16607. {
  16608. //Charger.ConnectionTimeOut = Integer.parseInt(value)*1000;
  16609. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemData, "%d", atoi(value));
  16610. isSuccess = ConfigurationStatus_Accepted;
  16611. }
  16612. }
  16613. else
  16614. {
  16615. isSuccess = ConfigurationStatus_Rejected;
  16616. }
  16617. }
  16618. if(strcmp(key, "GetConfigurationMaxKeys") == 0)
  16619. {
  16620. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemAccessibility == 1)
  16621. {
  16622. check_ascii = value[0];
  16623. if( (check_ascii < 48) || (check_ascii > 57) )
  16624. {
  16625. isSuccess = ConfigurationStatus_Rejected;
  16626. }
  16627. else
  16628. {
  16629. //Charger.HeartbeatInterval = Integer.parseInt(value)*1000;
  16630. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemData, "%d", atoi(value) );
  16631. isSuccess = ConfigurationStatus_Accepted;
  16632. }
  16633. }
  16634. else
  16635. {
  16636. isSuccess = ConfigurationStatus_Rejected;
  16637. }
  16638. }
  16639. if(strcmp(key, "HeartbeatInterval") == 0)
  16640. {
  16641. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemAccessibility == 1)
  16642. {
  16643. check_ascii = value[0];
  16644. if( (check_ascii < 48) || (check_ascii > 57) )
  16645. {
  16646. isSuccess = ConfigurationStatus_Rejected;
  16647. }
  16648. else
  16649. {
  16650. if((atoi(value) == 0) || (atoi(value) >= 10))
  16651. {
  16652. //Charger.HeartbeatInterval = Integer.parseInt(value)*1000;
  16653. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemData, "%d", atoi(value));
  16654. HeartBeatWaitTime = atoi(value);
  16655. isSuccess = ConfigurationStatus_Accepted;
  16656. }
  16657. else
  16658. {
  16659. isSuccess = ConfigurationStatus_Rejected;
  16660. }
  16661. }
  16662. }
  16663. else
  16664. {
  16665. isSuccess = ConfigurationStatus_Rejected;
  16666. }
  16667. }
  16668. if(strcmp(key, "LightIntensity") == 0)
  16669. {
  16670. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemAccessibility == 1)
  16671. {
  16672. check_ascii = value[0];
  16673. if( (check_ascii < 48) || (check_ascii > 57) )
  16674. {
  16675. isSuccess = ConfigurationStatus_Rejected;
  16676. }
  16677. else
  16678. {
  16679. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemData, "%d", atoi(value) );
  16680. isSuccess = ConfigurationStatus_Accepted;
  16681. }
  16682. }
  16683. else
  16684. {
  16685. isSuccess = ConfigurationStatus_Rejected;
  16686. }
  16687. }
  16688. if(strcmp(key, "LocalAuthorizeOffline") == 0)
  16689. {
  16690. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemAccessibility == 1)
  16691. {
  16692. strcpy(str, (const char*)value);
  16693. for(int i = 0; str[i]; i++)
  16694. {
  16695. str[i] = tolower(str[i]);
  16696. }
  16697. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  16698. isSuccess = ConfigurationStatus_Accepted;
  16699. //updateSetting("LocalAuthorizeOffline", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemData);
  16700. }
  16701. else
  16702. {
  16703. isSuccess = ConfigurationStatus_Rejected;
  16704. }
  16705. }
  16706. if(strcmp(key, "LocalPreAuthorize") == 0)
  16707. {
  16708. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemAccessibility == 1)
  16709. {
  16710. strcpy(str, (const char*)value);
  16711. for(int i = 0; str[i]; i++)
  16712. {
  16713. str[i] = tolower(str[i]);
  16714. }
  16715. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  16716. isSuccess = ConfigurationStatus_Accepted;
  16717. }
  16718. else
  16719. {
  16720. isSuccess = ConfigurationStatus_Rejected;
  16721. }
  16722. }
  16723. if(strcmp(key, "MaxEnergyOnInvalidId") == 0)
  16724. {
  16725. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemAccessibility == 1)
  16726. {
  16727. check_ascii = value[0];
  16728. if( (check_ascii < 48) || (check_ascii > 57) )
  16729. {
  16730. isSuccess = ConfigurationStatus_Rejected;
  16731. }
  16732. else
  16733. {
  16734. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemData, "%d", atoi(value) );
  16735. isSuccess = ConfigurationStatus_Accepted;
  16736. }
  16737. }
  16738. else
  16739. {
  16740. isSuccess = ConfigurationStatus_Rejected;
  16741. }
  16742. }
  16743. if(strcmp(key, "MeterValuesAlignedData") == 0)
  16744. {
  16745. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemAccessibility == 1)
  16746. {
  16747. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, "%s", value );
  16748. isSuccess = ConfigurationStatus_Accepted;
  16749. }
  16750. else
  16751. {
  16752. isSuccess = ConfigurationStatus_Rejected;
  16753. }
  16754. }
  16755. if(strcmp(key, "MeterValuesAlignedDataMaxLength") == 0)
  16756. {
  16757. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemAccessibility == 1)
  16758. {
  16759. check_ascii = value[0];
  16760. if( (check_ascii < 48) || (check_ascii > 57) )
  16761. {
  16762. isSuccess = ConfigurationStatus_Rejected;
  16763. }
  16764. else
  16765. {
  16766. //Charger.MeterValueSampleInterval = Integer.parseInt(value)*1000;
  16767. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemData, "%d", atoi(value));
  16768. isSuccess = ConfigurationStatus_Accepted;
  16769. }
  16770. }
  16771. else
  16772. {
  16773. isSuccess = ConfigurationStatus_Rejected;
  16774. }
  16775. }
  16776. if(strcmp(key, "MeterValuesSampledData") == 0 )
  16777. {
  16778. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemAccessibility == 1)
  16779. {
  16780. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, "%s", value );
  16781. isSuccess = ConfigurationStatus_Accepted;
  16782. }
  16783. else
  16784. {
  16785. isSuccess = ConfigurationStatus_Rejected;
  16786. }
  16787. }
  16788. if(strcmp(key, "MeterValuesSampledDataMaxLength") == 0)
  16789. {
  16790. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemAccessibility == 1)
  16791. {
  16792. check_ascii = value[0];
  16793. if( (check_ascii < 48) || (check_ascii > 57) )
  16794. {
  16795. isSuccess = ConfigurationStatus_Rejected;
  16796. }
  16797. else
  16798. {
  16799. //Charger.MeterValueSampleInterval = Integer.parseInt(value)*1000;
  16800. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemData, "%d", atoi(value));
  16801. isSuccess = ConfigurationStatus_Accepted;
  16802. }
  16803. }
  16804. else
  16805. {
  16806. isSuccess = ConfigurationStatus_Rejected;
  16807. }
  16808. }
  16809. if(strcmp(key, "MeterValueSampleInterval") == 0)
  16810. {
  16811. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemAccessibility == 1)
  16812. {
  16813. check_ascii = value[0];
  16814. if( (check_ascii < 48) || (check_ascii > 57) )
  16815. {
  16816. isSuccess = ConfigurationStatus_Rejected;
  16817. }
  16818. else
  16819. {
  16820. if((atoi(value) == 0) || (atoi(value) >= 3))
  16821. {
  16822. //Charger.MeterValueSampleInterval = Integer.parseInt(value)*1000;
  16823. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemData, "%d", atoi(value));
  16824. isSuccess = ConfigurationStatus_Accepted;
  16825. }
  16826. else
  16827. {
  16828. isSuccess = ConfigurationStatus_Rejected;
  16829. }
  16830. }
  16831. }
  16832. else
  16833. {
  16834. isSuccess = ConfigurationStatus_Rejected;
  16835. }
  16836. }
  16837. if(strcmp(key, "MinimumStatusDuration") == 0)
  16838. {
  16839. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemAccessibility == 1)
  16840. {
  16841. check_ascii = value[0];
  16842. if( (check_ascii < 48) || (check_ascii > 57) )
  16843. {
  16844. isSuccess = ConfigurationStatus_Rejected;
  16845. }
  16846. else
  16847. {
  16848. if(atoi(value) == 0) // MinimumStatusDuration's value can not be 0
  16849. {
  16850. isSuccess = ConfigurationStatus_Rejected;
  16851. }
  16852. else
  16853. {
  16854. //Charger.MinimumStatusDuration = Integer.parseInt(value);
  16855. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemData, "%d", atoi(value) );
  16856. server_cycle_Status = atoi(value); //StatusNotification Cycle
  16857. isSuccess = ConfigurationStatus_Accepted;
  16858. }
  16859. }
  16860. }
  16861. else
  16862. {
  16863. isSuccess = ConfigurationStatus_Rejected;
  16864. }
  16865. }
  16866. if(strcmp(key, "NumberOfConnectors") == 0)
  16867. {
  16868. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemAccessibility == 1)
  16869. {
  16870. check_ascii = value[0];
  16871. if( (check_ascii < 48) || (check_ascii > 57) )
  16872. {
  16873. isSuccess = ConfigurationStatus_Rejected;
  16874. }
  16875. else
  16876. {
  16877. //Charger.ResetRetries = Integer.parseInt(value);
  16878. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData, "%d", atoi(value) );
  16879. isSuccess = ConfigurationStatus_Accepted;
  16880. }
  16881. }
  16882. else
  16883. {
  16884. isSuccess = ConfigurationStatus_Rejected;
  16885. }
  16886. }
  16887. if(strcmp(key, "ResetRetries") == 0)
  16888. {
  16889. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemAccessibility == 1)
  16890. {
  16891. check_ascii = value[0];
  16892. if( (check_ascii < 48) || (check_ascii > 57) )
  16893. {
  16894. isSuccess = ConfigurationStatus_Rejected;
  16895. }
  16896. else
  16897. {
  16898. //Charger.ResetRetries = Integer.parseInt(value);
  16899. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemData, "%d", atoi(value) );
  16900. isSuccess = ConfigurationStatus_Accepted;
  16901. }
  16902. }
  16903. else
  16904. {
  16905. isSuccess = ConfigurationStatus_Rejected;
  16906. }
  16907. }
  16908. if(strcmp(key, "ConnectorPhaseRotation") == 0)
  16909. {
  16910. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemAccessibility == 1)
  16911. {
  16912. strcpy(str, (const char*)value);
  16913. for(int i = 0; str[i]; i++)
  16914. {
  16915. str[i] = tolower(str[i]);
  16916. }
  16917. if(strcmp(str, "notapplicable")== 0)
  16918. {
  16919. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "%s", "NotApplicable" );
  16920. isSuccess = ConfigurationStatus_Accepted;
  16921. }
  16922. else if(strcmp(str, "unknown")== 0)
  16923. {
  16924. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "%s", "Unknown" );
  16925. isSuccess = ConfigurationStatus_Accepted;
  16926. }
  16927. else if(strcmp(str, "rst")== 0)
  16928. {
  16929. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "%s", "RST" );
  16930. isSuccess = ConfigurationStatus_Accepted;
  16931. }
  16932. else if(strcmp(str, "rts")== 0)
  16933. {
  16934. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "%s", "RTS" );
  16935. isSuccess = ConfigurationStatus_Accepted;
  16936. }
  16937. else if(strcmp(str, "srt")== 0)
  16938. {
  16939. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "%s", "SRT" );
  16940. isSuccess = ConfigurationStatus_Accepted;
  16941. }
  16942. else if(strcmp(str, "str")== 0)
  16943. {
  16944. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "%s", "STR" );
  16945. isSuccess = ConfigurationStatus_Accepted;
  16946. }
  16947. else if(strcmp(str, "trs")== 0)
  16948. {
  16949. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "%s", "TRS" );
  16950. isSuccess = ConfigurationStatus_Accepted;
  16951. }
  16952. else if(strcmp(str, "tsr")== 0)
  16953. {
  16954. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "%s", "TSR" );
  16955. isSuccess = ConfigurationStatus_Accepted;
  16956. }
  16957. else
  16958. {
  16959. isSuccess = ConfigurationStatus_Rejected;
  16960. }
  16961. }
  16962. else
  16963. {
  16964. isSuccess = ConfigurationStatus_Rejected;
  16965. }
  16966. }
  16967. if(strcmp(key, "ConnectorPhaseRotationMaxLength") == 0)
  16968. {
  16969. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemAccessibility == 1)
  16970. {
  16971. check_ascii = value[0];
  16972. if( (check_ascii < 48) || (check_ascii > 57) )
  16973. {
  16974. isSuccess = ConfigurationStatus_Rejected;
  16975. }
  16976. else
  16977. {
  16978. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemData, "%d", atoi(value) );
  16979. isSuccess = ConfigurationStatus_Accepted;
  16980. }
  16981. }
  16982. else
  16983. {
  16984. isSuccess = ConfigurationStatus_Rejected;
  16985. }
  16986. }
  16987. if(strcmp(key, "StopTransactionOnEVSideDisconnect") == 0)
  16988. {
  16989. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemAccessibility == 1)
  16990. {
  16991. strcpy(str, (const char*)value);
  16992. for(int i = 0; str[i]; i++)
  16993. {
  16994. str[i] = tolower(str[i]);
  16995. }
  16996. //Charger.StopTransactionOnEVSideDisconnect = (value.toLowerCase().equals("true")?true:false);
  16997. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  16998. isSuccess = ConfigurationStatus_Accepted;
  16999. }
  17000. else
  17001. {
  17002. isSuccess = ConfigurationStatus_Rejected;
  17003. }
  17004. }
  17005. if(strcmp(key, "StopTransactionOnInvalidId") == 0)
  17006. {
  17007. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemAccessibility == 1)
  17008. {
  17009. strcpy(str, (const char*)value);
  17010. for(int i = 0; str[i]; i++)
  17011. {
  17012. str[i] = tolower(str[i]);
  17013. }
  17014. //Charger.StopTransactionOnInvalidId = (value.toLowerCase().equals("true")?true:false);
  17015. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  17016. isSuccess = ConfigurationStatus_Accepted;
  17017. }
  17018. else
  17019. {
  17020. isSuccess = ConfigurationStatus_Rejected;
  17021. }
  17022. }
  17023. if(strcmp(key, "StopTxnAlignedData") == 0)
  17024. {
  17025. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemAccessibility == 1)
  17026. {
  17027. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemData, "%s", value );
  17028. isSuccess = ConfigurationStatus_Accepted;
  17029. }
  17030. else
  17031. {
  17032. isSuccess = ConfigurationStatus_Rejected;
  17033. }
  17034. }
  17035. if(strcmp(key, "StopTxnAlignedDataMaxLength") == 0)
  17036. {
  17037. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemAccessibility == 1)
  17038. {
  17039. check_ascii = value[0];
  17040. if( (check_ascii < 48) || (check_ascii > 57) )
  17041. {
  17042. isSuccess = ConfigurationStatus_Rejected;
  17043. }
  17044. else
  17045. {
  17046. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemData, "%d", atoi(value) );
  17047. isSuccess = ConfigurationStatus_Accepted;
  17048. }
  17049. }
  17050. else
  17051. {
  17052. isSuccess = ConfigurationStatus_Rejected;
  17053. }
  17054. }
  17055. if(strcmp(key, "StopTxnSampledData") == 0)
  17056. {
  17057. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemAccessibility == 1)
  17058. {
  17059. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "%s", value );
  17060. isSuccess = ConfigurationStatus_Accepted;
  17061. }
  17062. else
  17063. {
  17064. isSuccess = ConfigurationStatus_Rejected;
  17065. }
  17066. }
  17067. if(strcmp(key, "StopTxnSampledDataMaxLength") == 0)
  17068. {
  17069. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemAccessibility == 1)
  17070. {
  17071. check_ascii = value[0];
  17072. if( (check_ascii < 48) || (check_ascii > 57) )
  17073. {
  17074. isSuccess = ConfigurationStatus_Rejected;
  17075. }
  17076. else
  17077. {
  17078. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemData, "%d", atoi(value) );
  17079. isSuccess = ConfigurationStatus_Accepted;
  17080. }
  17081. }
  17082. else
  17083. {
  17084. isSuccess = ConfigurationStatus_Rejected;
  17085. }
  17086. }
  17087. if(strcmp(key, "SupportedFeatureProfiles") == 0)
  17088. {
  17089. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemAccessibility == 1)
  17090. {
  17091. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemData, "%s", value );
  17092. isSuccess = ConfigurationStatus_Accepted;
  17093. }
  17094. else
  17095. {
  17096. isSuccess = ConfigurationStatus_Rejected;
  17097. }
  17098. }
  17099. if(strcmp(key, "SupportedFeatureProfilesMaxLength") == 0)
  17100. {
  17101. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemAccessibility == 1)
  17102. {
  17103. check_ascii = value[0];
  17104. if( (check_ascii < 48) || (check_ascii > 57) )
  17105. {
  17106. isSuccess = ConfigurationStatus_Rejected;
  17107. }
  17108. else
  17109. {
  17110. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemData, "%d", atoi(value) );
  17111. isSuccess = ConfigurationStatus_Accepted;
  17112. }
  17113. }
  17114. else
  17115. {
  17116. isSuccess = ConfigurationStatus_Rejected;
  17117. }
  17118. }
  17119. if(strcmp(key, "TransactionMessageAttempts") == 0)
  17120. {
  17121. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemAccessibility == 1)
  17122. {
  17123. check_ascii = value[0];
  17124. if( (check_ascii < 48) || (check_ascii > 57) )
  17125. {
  17126. isSuccess = ConfigurationStatus_Rejected;
  17127. }
  17128. else
  17129. {
  17130. //Charger.TransactionMessageAttempts = Integer.parseInt(value);
  17131. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData, "%d", atoi(value) );
  17132. TransactionMessageAttemptsValue = atoi(value);
  17133. isSuccess = ConfigurationStatus_Accepted;
  17134. }
  17135. }
  17136. else
  17137. {
  17138. isSuccess = ConfigurationStatus_Rejected;
  17139. }
  17140. }
  17141. if(strcmp(key, "TransactionMessageRetryInterval") == 0)
  17142. {
  17143. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemAccessibility == 1)
  17144. {
  17145. check_ascii = value[0];
  17146. if( (check_ascii < 48) || (check_ascii > 57) )
  17147. {
  17148. isSuccess = ConfigurationStatus_Rejected;
  17149. }
  17150. else
  17151. {
  17152. //Charger.TransactionMessageRetryInterval = Integer.parseInt(value)*1000;
  17153. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData, "%d", atoi(value) );
  17154. TransactionMessageRetryIntervalValue = atoi(value);
  17155. isSuccess = ConfigurationStatus_Accepted;
  17156. }
  17157. }
  17158. else
  17159. {
  17160. isSuccess = ConfigurationStatus_Rejected;
  17161. }
  17162. }
  17163. if(strcmp(key, "UnlockConnectorOnEVSideDisconnect") == 0)
  17164. {
  17165. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemAccessibility == 1)
  17166. {
  17167. strcpy(str, (const char*)value);
  17168. for(int i = 0; str[i]; i++)
  17169. {
  17170. str[i] = tolower(str[i]);
  17171. }
  17172. //Charger.UnlockConnectorOnEVSideDisconnect = (value.toLowerCase().equals("true")?true:false);
  17173. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  17174. isSuccess = ConfigurationStatus_Accepted;
  17175. }
  17176. else
  17177. {
  17178. isSuccess = ConfigurationStatus_Rejected;
  17179. }
  17180. }
  17181. if(strcmp(key, "WebSocketPingInterval") == 0)
  17182. {
  17183. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemAccessibility == 1)
  17184. {
  17185. check_ascii = value[0];
  17186. if( (check_ascii < 48) || (check_ascii > 57) )
  17187. {
  17188. isSuccess = ConfigurationStatus_Rejected;
  17189. }
  17190. else
  17191. {
  17192. if((atoi(value) == 0) || (atoi(value) >= 10))
  17193. {
  17194. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemData, "%d", atoi(value) );
  17195. isSuccess = ConfigurationStatus_Accepted;
  17196. }
  17197. else
  17198. isSuccess = ConfigurationStatus_Rejected;
  17199. }
  17200. }
  17201. else
  17202. {
  17203. isSuccess = ConfigurationStatus_Rejected;
  17204. }
  17205. }
  17206. if(strcmp(key, "QueueOffLineMeterValues") == 0)
  17207. {
  17208. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[QueueOffLineMeterValues].ItemAccessibility == 1)
  17209. {
  17210. strcpy(str, (const char*)value);
  17211. for(int i = 0; str[i]; i++)
  17212. {
  17213. str[i] = tolower(str[i]);
  17214. }
  17215. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[QueueOffLineMeterValues].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  17216. isSuccess = ConfigurationStatus_Accepted;
  17217. }
  17218. else
  17219. {
  17220. isSuccess = ConfigurationStatus_Rejected;
  17221. }
  17222. }
  17223. if(strcmp(key, "AuthorizationKey") == 0)
  17224. {
  17225. if((ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationKey].ItemAccessibility == 1) && (strlen(value) <= 40))
  17226. {
  17227. strcpy(str, (const char*)value);
  17228. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationKey].ItemData, "%s", str);
  17229. strcpy((char*)ShmSysConfigAndInfo->SysConfig.OcppSecurityPassword, (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationKey].ItemData);
  17230. isSuccess = ConfigurationStatus_Accepted;
  17231. }
  17232. else
  17233. {
  17234. isSuccess = ConfigurationStatus_Rejected;
  17235. }
  17236. }
  17237. if(strcmp(key, "SecurityProfile") == 0)
  17238. {
  17239. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[SecurityProfile].ItemAccessibility == 1)
  17240. {
  17241. check_ascii = value[0];
  17242. if( (check_ascii < 0x30) || (check_ascii > 0x33) )
  17243. {
  17244. isSuccess = ConfigurationStatus_Rejected;
  17245. }
  17246. else if(check_ascii == 0x33)
  17247. {
  17248. isSuccess = NotSupported;
  17249. }
  17250. else
  17251. {
  17252. if(atoi((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SecurityProfile].ItemData) <= (check_ascii - 0x30))
  17253. {
  17254. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SecurityProfile].ItemData, "%d", atoi(value) );
  17255. ShmSysConfigAndInfo->SysConfig.OcppSecurityProfile = atoi(value);
  17256. isSuccess = ConfigurationStatus_Accepted;
  17257. }
  17258. else
  17259. isSuccess = ConfigurationStatus_Rejected;
  17260. }
  17261. }
  17262. else
  17263. {
  17264. isSuccess = ConfigurationStatus_Rejected;
  17265. }
  17266. }
  17267. if(strcmp(key, "DefaultPrice") == 0)
  17268. {
  17269. if((ShmOCPP16Data->ConfigurationTable.CoreProfile[DefaultPrice].ItemAccessibility == 1))
  17270. {
  17271. strcpy(str, (const char*)value);
  17272. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[DefaultPrice].ItemData, "%s", str);
  17273. isSuccess = ConfigurationStatus_Accepted;
  17274. }
  17275. else
  17276. {
  17277. isSuccess = ConfigurationStatus_Rejected;
  17278. }
  17279. }
  17280. if(strcmp(key, "CustomDisplayCostAndPrice") == 0)
  17281. {
  17282. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemAccessibility == 1)
  17283. {
  17284. strcpy(str, (const char*)value);
  17285. for(int i = 0; str[i]; i++)
  17286. {
  17287. str[i] = tolower(str[i]);
  17288. }
  17289. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  17290. isSuccess = ConfigurationStatus_Accepted;
  17291. }
  17292. else
  17293. {
  17294. isSuccess = ConfigurationStatus_Rejected;
  17295. }
  17296. }
  17297. if(strcmp(key, "CustomIdleFeeAfterStop") == 0)
  17298. {
  17299. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemAccessibility == 1)
  17300. {
  17301. strcpy(str, (const char*)value);
  17302. for(int i = 0; str[i]; i++)
  17303. {
  17304. str[i] = tolower(str[i]);
  17305. }
  17306. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  17307. isSuccess = ConfigurationStatus_Accepted;
  17308. }
  17309. else
  17310. {
  17311. isSuccess = ConfigurationStatus_Rejected;
  17312. }
  17313. }
  17314. if(strcmp(key, "TimeOffset") == 0)
  17315. {
  17316. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffset].ItemAccessibility == 1)
  17317. {
  17318. strcpy(str, (const char*)value);
  17319. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffset].ItemData, "%s", str);
  17320. isSuccess = ConfigurationStatus_Accepted;
  17321. }
  17322. else
  17323. {
  17324. isSuccess = ConfigurationStatus_Rejected;
  17325. }
  17326. }
  17327. if(strcmp(key, "NextTimeOffsetTransitionDateTime") == 0)
  17328. {
  17329. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[NextTimeOffsetTransitionDateTime].ItemAccessibility == 1)
  17330. {
  17331. strcpy(str, (const char*)value);
  17332. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NextTimeOffsetTransitionDateTime].ItemData, "%s", str);
  17333. isSuccess = ConfigurationStatus_Accepted;
  17334. }
  17335. else
  17336. {
  17337. isSuccess = ConfigurationStatus_Rejected;
  17338. }
  17339. }
  17340. if(strcmp(key, "TimeOffsetNextTransition") == 0)
  17341. {
  17342. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffsetNextTransition].ItemAccessibility == 1)
  17343. {
  17344. strcpy(str, (const char*)value);
  17345. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffsetNextTransition].ItemData, "%s", str);
  17346. isSuccess = ConfigurationStatus_Accepted;
  17347. }
  17348. else
  17349. {
  17350. isSuccess = ConfigurationStatus_Rejected;
  17351. }
  17352. }
  17353. if(strcmp(key, "SystemUptimeSec") == 0)
  17354. {
  17355. isSuccess = NotSupported;
  17356. }
  17357. if(strcmp(key, "FreeVend") == 0)
  17358. {
  17359. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[FreeVend].ItemAccessibility == 1)
  17360. {
  17361. strcpy(str, (const char*)value);
  17362. for(int i = 0; str[i]; i++)
  17363. {
  17364. str[i] = tolower(str[i]);
  17365. }
  17366. ShmSysConfigAndInfo->SysConfig.AuthorisationMode = ((strcmp(str, "true")==0) ? 1 : 0 );
  17367. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[FreeVend].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  17368. isSuccess = ConfigurationStatus_Accepted;
  17369. }
  17370. else
  17371. {
  17372. isSuccess = ConfigurationStatus_Rejected;
  17373. }
  17374. }
  17375. if(strcmp(key, "FreeVendIdtag") == 0)
  17376. {
  17377. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[FreeVendIdtag].ItemAccessibility == 1)
  17378. {
  17379. strcpy(str, (const char*)value);
  17380. if(strlen(str) <= 20)
  17381. {
  17382. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[FreeVendIdtag].ItemData, "%s", str );
  17383. isSuccess = ConfigurationStatus_Accepted;
  17384. }
  17385. else
  17386. {
  17387. DEBUG_WARN("FreeVendIdtag(%s) length over 20 bytes.\n", str);
  17388. isSuccess = ConfigurationStatus_Rejected;
  17389. }
  17390. }
  17391. else
  17392. {
  17393. isSuccess = ConfigurationStatus_Rejected;
  17394. }
  17395. }
  17396. if(strcmp(key, "OcppServer") == 0)
  17397. {
  17398. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[OcppServer].ItemAccessibility == 1)
  17399. {
  17400. strcpy(str, (const char*)value);
  17401. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[OcppServer].ItemData, "%s", str );
  17402. sprintf((char *)ShmSysConfigAndInfo->SysConfig.OcppServerURL, "%s", str );
  17403. isSuccess = ConfigurationStatus_Accepted;
  17404. }
  17405. else
  17406. {
  17407. isSuccess = ConfigurationStatus_Rejected;
  17408. }
  17409. }
  17410. if(strcmp(key, "MaintainServer") == 0)
  17411. {
  17412. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MaintainServer].ItemAccessibility == 1)
  17413. {
  17414. strcpy(str, (const char*)value);
  17415. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MaintainServer].ItemData, "%s", str );
  17416. sprintf((char *)ShmSysConfigAndInfo->SysConfig.MaintainServerURL, "%s", str );
  17417. isSuccess = ConfigurationStatus_Accepted;
  17418. }
  17419. else
  17420. {
  17421. isSuccess = ConfigurationStatus_Rejected;
  17422. }
  17423. }
  17424. if(strcmp(key, "StatusNotificationPeriodically") == 0)
  17425. {
  17426. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StatusNotificationPeriodically].ItemAccessibility == 1)
  17427. {
  17428. strcpy(str, (const char*)value);
  17429. for(int i = 0; str[i]; i++)
  17430. {
  17431. str[i] = tolower(str[i]);
  17432. }
  17433. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StatusNotificationPeriodically].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE");
  17434. isSuccess = ConfigurationStatus_Accepted;
  17435. }
  17436. else
  17437. {
  17438. isSuccess = ConfigurationStatus_Rejected;
  17439. }
  17440. }
  17441. if(strcmp(key, "StatusNotificationInterval") == 0)
  17442. {
  17443. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StatusNotificationInterval].ItemAccessibility == 1)
  17444. {
  17445. check_ascii = value[0];
  17446. if( (check_ascii < 48) || (check_ascii > 57) )
  17447. {
  17448. isSuccess = ConfigurationStatus_Rejected;
  17449. }
  17450. else
  17451. {
  17452. if((atoi(value) == 0) || (atoi(value) >= 10))
  17453. {
  17454. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StatusNotificationInterval].ItemData, "%d", atoi(value) );
  17455. isSuccess = ConfigurationStatus_Accepted;
  17456. }
  17457. else
  17458. isSuccess = ConfigurationStatus_Rejected;
  17459. }
  17460. }
  17461. else
  17462. {
  17463. isSuccess = ConfigurationStatus_Rejected;
  17464. }
  17465. }
  17466. if(strcmp(key, "PreAuthAmount") == 0)
  17467. {
  17468. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[PreAuthAmount].ItemAccessibility == 1)
  17469. {
  17470. check_ascii = value[0];
  17471. if( (check_ascii < 48) || (check_ascii > 57) )
  17472. {
  17473. isSuccess = ConfigurationStatus_Rejected;
  17474. }
  17475. else
  17476. {
  17477. if(atof(value) >= 0)
  17478. {
  17479. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[PreAuthAmount].ItemData, "%.2f", atof(value) );
  17480. isSuccess = ConfigurationStatus_Accepted;
  17481. }
  17482. else
  17483. isSuccess = ConfigurationStatus_Rejected;
  17484. }
  17485. }
  17486. else
  17487. {
  17488. isSuccess = ConfigurationStatus_Rejected;
  17489. }
  17490. }
  17491. if(strcmp(key, "isEnableLocalPowerSharing") == 0)
  17492. {
  17493. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[isEnableLocalPowerSharing].ItemAccessibility == 1)
  17494. {
  17495. check_ascii = value[0];
  17496. if( (check_ascii < 48) || (check_ascii > 57) )
  17497. {
  17498. isSuccess = ConfigurationStatus_Rejected;
  17499. }
  17500. else
  17501. {
  17502. if(atoi(value) >= 0)
  17503. {
  17504. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[isEnableLocalPowerSharing].ItemData, "%d", atoi(value));
  17505. ShmSysConfigAndInfo->SysConfig.isEnableLocalPowerSharing = (unsigned char)atoi(value);
  17506. isSuccess = ConfigurationStatus_Accepted;
  17507. }
  17508. else
  17509. isSuccess = ConfigurationStatus_Rejected;
  17510. }
  17511. }
  17512. else
  17513. {
  17514. isSuccess = ConfigurationStatus_Rejected;
  17515. }
  17516. }
  17517. if(strcmp(key, "PowerSharingServerIP") == 0)
  17518. {
  17519. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[PowerSharingServerIP].ItemAccessibility == 1)
  17520. {
  17521. strcpy(str, (const char*)value);
  17522. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[PowerSharingServerIP].ItemData, "%s", str );
  17523. sprintf((char *)ShmSysConfigAndInfo->SysConfig.PowerSharingServerIP, "%s", str );
  17524. isSuccess = ConfigurationStatus_Accepted;
  17525. }
  17526. else
  17527. {
  17528. isSuccess = ConfigurationStatus_Rejected;
  17529. }
  17530. }
  17531. if(strcmp(key, "EVCCID_PREFIX") == 0)
  17532. {
  17533. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[EVCCID_PREFIX].ItemAccessibility == 1)
  17534. {
  17535. strcpy(str, (const char*)value);
  17536. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[EVCCID_PREFIX].ItemData, "%s", str );
  17537. isSuccess = ConfigurationStatus_Accepted;
  17538. }
  17539. else
  17540. {
  17541. isSuccess = ConfigurationStatus_Rejected;
  17542. }
  17543. }
  17544. if(strcmp(key, "OffLineMaxChargingPower") == 0)
  17545. {
  17546. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[OffLineMaxChargingPower].ItemAccessibility == 1)
  17547. {
  17548. if(atoi(value) > modelnameInfo.ratedPower)
  17549. {
  17550. isSuccess = ConfigurationStatus_Rejected;
  17551. }
  17552. else{
  17553. strcpy(str, (const char*)value);
  17554. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[OffLineMaxChargingPower].ItemData, "%s", str );
  17555. isSuccess = ConfigurationStatus_Accepted;
  17556. }
  17557. }
  17558. else
  17559. {
  17560. isSuccess = ConfigurationStatus_Rejected;
  17561. }
  17562. }
  17563. if(strcmp(key, "CharingProfileRefreshInterval") == 0)
  17564. {
  17565. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[CharingProfileRefreshInterval].ItemAccessibility == 1)
  17566. {
  17567. if((atoi(value) != 0) && (atoi(value) < 5))
  17568. {
  17569. isSuccess = ConfigurationStatus_Rejected;
  17570. }
  17571. else{
  17572. strcpy(str, (const char*)value);
  17573. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CharingProfileRefreshInterval].ItemData, "%s", str );
  17574. isSuccess = ConfigurationStatus_Accepted;
  17575. }
  17576. }
  17577. else
  17578. {
  17579. isSuccess = ConfigurationStatus_Rejected;
  17580. }
  17581. }
  17582. #if 0
  17583. //For OCPP Test Case
  17584. if(strcmp(key, "LocalAuthorizationListEnabled") == 0)
  17585. {
  17586. if(ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemAccessibility == 1)
  17587. {
  17588. strcpy(str, (const char*)value);
  17589. for(int i = 0; str[i]; i++)
  17590. {
  17591. str[i] = tolower(str[i]);
  17592. }
  17593. sprintf((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  17594. isSuccess = ConfigurationStatus_Accepted;
  17595. //updateSetting("LocalAuthorizationListEnabled", (char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData);
  17596. }
  17597. else
  17598. {
  17599. isSuccess = ConfigurationStatus_Rejected;
  17600. }
  17601. }
  17602. #endif
  17603. #if 1
  17604. if(strcmp(key, "LocalAuthListEnabled") == 0)
  17605. {
  17606. if(ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemAccessibility == 1)
  17607. {
  17608. strcpy(str, (const char*)value);
  17609. for(int i = 0; str[i]; i++)
  17610. {
  17611. str[i] = tolower(str[i]);
  17612. }
  17613. sprintf((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  17614. isSuccess = ConfigurationStatus_Accepted;
  17615. //updateSetting("LocalAuthListEnabled", (char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData);
  17616. }
  17617. else
  17618. {
  17619. isSuccess = ConfigurationStatus_Rejected;
  17620. }
  17621. }
  17622. #endif
  17623. if(strcmp(key, "LocalAuthListMaxLength") == 0)
  17624. {
  17625. if(ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemAccessibility == 1)
  17626. {
  17627. check_ascii = value[0];
  17628. if( (check_ascii < 48) || (check_ascii > 57) )
  17629. {
  17630. isSuccess = ConfigurationStatus_Rejected;
  17631. }
  17632. else
  17633. {
  17634. sprintf((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemData, "%d", atoi(value) );
  17635. isSuccess = ConfigurationStatus_Accepted;
  17636. }
  17637. }
  17638. else
  17639. {
  17640. isSuccess = ConfigurationStatus_Rejected;
  17641. }
  17642. }
  17643. if(strcmp(key, "SendLocalListMaxLength") == 0)
  17644. {
  17645. if(ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemAccessibility == 1)
  17646. {
  17647. check_ascii = value[0];
  17648. if( (check_ascii < 48) || (check_ascii > 57) )
  17649. {
  17650. isSuccess = ConfigurationStatus_Rejected;
  17651. }
  17652. else
  17653. {
  17654. sprintf((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemData, "%d", atoi(value) );
  17655. isSuccess = ConfigurationStatus_Accepted;
  17656. }
  17657. }
  17658. else
  17659. {
  17660. isSuccess = ConfigurationStatus_Rejected;
  17661. }
  17662. }
  17663. if(strcmp(key, "ReserveConnectorZeroSupported") == 0)
  17664. {
  17665. if(ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemAccessibility == 1)
  17666. {
  17667. strcpy(str, (const char*)value);
  17668. for(int i = 0; str[i]; i++)
  17669. {
  17670. str[i] = tolower(str[i]);
  17671. }
  17672. sprintf((char *)ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  17673. isSuccess = ConfigurationStatus_Accepted;
  17674. }
  17675. else
  17676. {
  17677. isSuccess = ConfigurationStatus_Rejected;
  17678. }
  17679. }
  17680. if(strcmp(key, "ChargeProfileMaxStackLevel") == 0)
  17681. {
  17682. if(ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemAccessibility == 1)
  17683. {
  17684. check_ascii = value[0];
  17685. if( (check_ascii < 48) || (check_ascii > 57) )
  17686. {
  17687. isSuccess = ConfigurationStatus_Rejected;
  17688. }
  17689. else
  17690. {
  17691. sprintf((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemData, "%d", atoi(value) );
  17692. isSuccess = ConfigurationStatus_Accepted;
  17693. }
  17694. }
  17695. else
  17696. {
  17697. isSuccess = ConfigurationStatus_Rejected;
  17698. }
  17699. }
  17700. if(strcmp(key, "ChargingScheduleAllowedChargingRateUnit") == 0)
  17701. {
  17702. if(ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemAccessibility == 1)
  17703. {
  17704. sprintf((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemData, "%s", value );
  17705. isSuccess = ConfigurationStatus_Accepted;
  17706. }
  17707. else
  17708. {
  17709. isSuccess = ConfigurationStatus_Rejected;
  17710. }
  17711. }
  17712. if(strcmp(key, "ChargingScheduleMaxPeriods") == 0)
  17713. {
  17714. if(ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemAccessibility == 1)
  17715. {
  17716. check_ascii = value[0];
  17717. if( (check_ascii < 48) || (check_ascii > 57) )
  17718. {
  17719. isSuccess = ConfigurationStatus_Rejected;
  17720. }
  17721. else
  17722. {
  17723. sprintf((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemData, "%d", atoi(value) );
  17724. isSuccess = ConfigurationStatus_Accepted;
  17725. }
  17726. }
  17727. else
  17728. {
  17729. isSuccess = ConfigurationStatus_Rejected;
  17730. }
  17731. }
  17732. if(strcmp(key, "ConnectorSwitch3to1PhaseSupported") == 0)
  17733. {
  17734. if(ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemAccessibility == 1)
  17735. {
  17736. strcpy(str, (const char*)value);
  17737. for(int i = 0; str[i]; i++)
  17738. {
  17739. str[i] = tolower(str[i]);
  17740. }
  17741. sprintf((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  17742. isSuccess = ConfigurationStatus_Accepted;
  17743. }
  17744. else
  17745. {
  17746. isSuccess = ConfigurationStatus_Rejected;
  17747. }
  17748. }
  17749. if(strcmp(key, "MaxChargingProfilesInstalled") == 0)
  17750. {
  17751. if(ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemAccessibility == 1)
  17752. {
  17753. check_ascii = value[0];
  17754. if( (check_ascii < 48) || (check_ascii > 57) )
  17755. {
  17756. isSuccess = ConfigurationStatus_Rejected;
  17757. }
  17758. else
  17759. {
  17760. sprintf((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemData, "%d", atoi(value) );
  17761. isSuccess = ConfigurationStatus_Accepted;
  17762. }
  17763. }
  17764. else
  17765. {
  17766. isSuccess = ConfigurationStatus_Rejected;
  17767. }
  17768. }
  17769. system("/bin/fsync -d /dev/mtdblock13;/bin/sync &");
  17770. return isSuccess;
  17771. }
  17772. int TransactionMessageAttemptsGet(void)
  17773. {
  17774. return TransactionMessageAttemptsValue;
  17775. }
  17776. int FirstHeartBeatResponse(void)
  17777. {
  17778. return FirstHeartBeat;
  17779. }
  17780. int TransactionMessageRetryIntervalGet(void)
  17781. {
  17782. return TransactionMessageRetryIntervalValue;//atoi((const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData);
  17783. }
  17784. int ReadHttpStatus(int sock)
  17785. {
  17786. //char c;
  17787. char buff[1024]="",*ptr=buff+1;
  17788. int bytes_received, status;
  17789. DEBUG_INFO("Begin Response ..\n");
  17790. while((bytes_received = recv(sock, ptr, 1, 0))){
  17791. if(bytes_received==-1){
  17792. perror("ReadHttpStatus");
  17793. exit(1);
  17794. }
  17795. if((ptr[-1]=='\r') && (*ptr=='\n' )) break;
  17796. ptr++;
  17797. }
  17798. *ptr=0;
  17799. ptr=buff+1;
  17800. sscanf(ptr,"%*s %d ", &status);
  17801. DEBUG_INFO("%s\n",ptr);
  17802. DEBUG_INFO("status=%d\n",status);
  17803. DEBUG_INFO("End Response ..\n");
  17804. return (bytes_received>0)?status:0;
  17805. }
  17806. //the only filed that it parsed is 'Content-Length'
  17807. int ParseHeader(int sock)
  17808. {
  17809. //char c;
  17810. char buff[1024]="",*ptr=buff+4;
  17811. int bytes_received;
  17812. DEBUG_INFO("Begin HEADER ..\n");
  17813. while((bytes_received = recv(sock, ptr, 1, 0))){
  17814. if(bytes_received==-1){
  17815. perror("Parse Header");
  17816. exit(1);
  17817. }
  17818. if(
  17819. (ptr[-3]=='\r') && (ptr[-2]=='\n' ) &&
  17820. (ptr[-1]=='\r') && (*ptr=='\n' )
  17821. ) break;
  17822. ptr++;
  17823. }
  17824. *ptr=0;
  17825. ptr=buff+4;
  17826. //printf("%s",ptr);
  17827. if(bytes_received){
  17828. ptr=strstr(ptr,"Content-Length:");
  17829. if(ptr){
  17830. sscanf(ptr,"%*s %d",&bytes_received);
  17831. }else
  17832. bytes_received=-1; //unknown size
  17833. DEBUG_INFO("Content-Length: %d\n",bytes_received);
  17834. }
  17835. DEBUG_INFO("End HEADER ..\n");
  17836. return bytes_received ;
  17837. }
  17838. int httpDownLoadFile(char *location, char *path, char *filename,char *url)
  17839. {
  17840. int result = TRUE;
  17841. char rmFileCmd[100]={0};
  17842. char FilePath[100]={0};
  17843. char ftpbuf[200];
  17844. int systemresult;
  17845. sprintf(FilePath,"/mnt/%s",filename);
  17846. system("ping 8.8.8.8 &");
  17847. if((access(FilePath,F_OK))!=-1)
  17848. {
  17849. DEBUG_INFO("filename=%s exist.\n",FilePath);
  17850. sprintf(rmFileCmd,"rm -f %s",FilePath);
  17851. system(rmFileCmd);
  17852. }
  17853. memset(ftpbuf, 0, ARRAY_SIZE(ftpbuf));
  17854. sprintf(ftpbuf, "wget --tries=1 -O /mnt/%s -c %s -T 120 --no-check-certificate",filename, url);
  17855. DEBUG_INFO("Download command: %s\n",ftpbuf);
  17856. systemresult = system(ftpbuf);
  17857. if(systemresult != 0)
  17858. {
  17859. DEBUG_INFO("HTTP/HTTPS downLoad fail!\n");
  17860. result = FALSE;
  17861. }
  17862. system("pkill ping");
  17863. return result;
  17864. }
  17865. int sftpDownLoadFile(char *location, char *user, int port, char *path, char *filename,char *url)
  17866. {
  17867. int result = TRUE;
  17868. char rmFileCmd[100]={0};
  17869. char FilePath[100]={0};
  17870. char ftpbuf[200];
  17871. int systemresult;
  17872. sprintf(FilePath,"/mnt/%s",filename);
  17873. system("ping 8.8.8.8 &");
  17874. if((access(FilePath,F_OK))!=-1)
  17875. {
  17876. DEBUG_INFO("filename=%s exist.\n",FilePath);
  17877. sprintf(rmFileCmd,"rm -f %s",FilePath);
  17878. system(rmFileCmd);
  17879. }
  17880. memset(ftpbuf, 0, ARRAY_SIZE(ftpbuf));
  17881. sprintf(ftpbuf,"timeout -t 360 scp -i /root/.ssh/id_rsa_bear -P %d %s@%s%s /mnt/%s", port, user, path, filename, filename);
  17882. DEBUG_INFO("Download command: %s\n",ftpbuf);
  17883. systemresult = system(ftpbuf);
  17884. if(systemresult != 0)
  17885. {
  17886. DEBUG_WARN("scp error!\n");
  17887. result = FALSE;
  17888. }
  17889. system("pkill ping");
  17890. return result;
  17891. }
  17892. int ftpDownLoadFile(char *location, char *user, char *password, int port, char *path, char *filename,char *url)
  17893. {
  17894. int result = TRUE;
  17895. char rmFileCmd[100]={0};
  17896. char FilePath[100]={0};
  17897. char ftpbuf[200];
  17898. int systemresult;
  17899. sprintf(FilePath,"/mnt/%s",filename);
  17900. system("ping 8.8.8.8 &");
  17901. if((access(FilePath,F_OK))!=-1)
  17902. {
  17903. DEBUG_INFO("filename=%s exist.\n",FilePath);
  17904. sprintf(rmFileCmd,"rm -f %s",FilePath);
  17905. system(rmFileCmd);
  17906. }
  17907. memset(ftpbuf, 0, ARRAY_SIZE(ftpbuf));
  17908. sprintf(ftpbuf, "wget --tries=1 -O /mnt/%s -c %s -T 120",filename, url);
  17909. DEBUG_INFO("Download command: %s\n",ftpbuf);
  17910. systemresult = system(ftpbuf);
  17911. if(systemresult != 0)
  17912. {
  17913. sprintf(ftpbuf, "wget --tries=1 -O /mnt/%s -c %s -T 120 --no-passive-ftp",filename, url);
  17914. DEBUG_INFO("Download command: %s\n",ftpbuf);
  17915. systemresult = system(ftpbuf);
  17916. if(systemresult != 0)
  17917. {
  17918. DEBUG_WARN("FTP download fail!\n");
  17919. result = FALSE;
  17920. }
  17921. }
  17922. system("pkill ping");
  17923. return result;
  17924. }
  17925. int httpUploadFile(char *location, char *path, char *filename,char *url)
  17926. {
  17927. char rmFileCmd[100]={0};
  17928. char FilePath[100]={0};
  17929. char buf[512];
  17930. int systemresult = 0;
  17931. //DEBUG_INFO("filename=%s\n",filename);
  17932. //DEBUG_INFO("url=%s\n",url);
  17933. sprintf(FilePath,"%s","/mnt/upload_file.txt");
  17934. if((access(FilePath,F_OK))!=-1)
  17935. {
  17936. DEBUG_INFO("filename=%s exist.\n",FilePath);
  17937. sprintf(rmFileCmd,"rm -f %s",FilePath);
  17938. system(rmFileCmd);
  17939. }
  17940. FILE *fp = fopen("/mnt/upload_file.txt", "w+");
  17941. if(fp == NULL)
  17942. {
  17943. DEBUG_INFO("log is NULL\n");
  17944. return FALSE;
  17945. }
  17946. else
  17947. {
  17948. fprintf(fp, "%s\n", url);
  17949. fprintf(fp, "%s\n", filename);
  17950. fclose(fp);
  17951. }
  17952. FILE *phpFP = popen("/bin/php-cgi /var/www/ocpp_upload.php", "r");
  17953. if(phpFP == NULL)
  17954. {
  17955. DEBUG_INFO("PHP upload fail.\n");
  17956. return FALSE;
  17957. }
  17958. else
  17959. {
  17960. while(fgets(buf, sizeof(buf), phpFP) != NULL)
  17961. {
  17962. if(strstr(buf, "result") != NULL)
  17963. {
  17964. sscanf(buf, "result: %d", &systemresult);
  17965. DEBUG_INFO("PHP HTTP upload result: %d\n", systemresult);
  17966. }
  17967. }
  17968. pclose(phpFP);
  17969. }
  17970. if(systemresult != 1)
  17971. {
  17972. DEBUG_WARN("HTTP POST upload error, change to PUT method\n");
  17973. FILE *phpFP = popen("/bin/php-cgi /var/www/ocpp_upload_put.php", "r");
  17974. if(phpFP == NULL)
  17975. {
  17976. DEBUG_WARN("PHP PUT upload fail.\n");
  17977. return FALSE;
  17978. }
  17979. else
  17980. {
  17981. while(fgets(buf, sizeof(buf), phpFP) != NULL)
  17982. {
  17983. if(strstr(buf, "result") != NULL)
  17984. {
  17985. sscanf(buf, "result: %d", &systemresult);
  17986. DEBUG_INFO("PHP HTTP PUT upload result: %d\n", systemresult);
  17987. }
  17988. }
  17989. pclose(phpFP);
  17990. }
  17991. }
  17992. if(systemresult != 1)
  17993. {
  17994. DEBUG_WARN("PHP PUT upload fail.\n");
  17995. return FALSE;
  17996. }
  17997. return TRUE;
  17998. }
  17999. int ftpUploadFile(char *location, char *user, char *password, int port, char *path, char *fnamePlusPath,char *filename)
  18000. {
  18001. int result = FALSE;
  18002. char ftpbuf[200];
  18003. int systemresult;
  18004. /*
  18005. // Domaind name transfer to IP address
  18006. struct hostent* server;
  18007. char *IPbuffer;
  18008. server = gethostbyname(location);
  18009. IPbuffer = inet_ntoa(*((struct in_addr*)server->h_addr_list[0]));*/
  18010. memset(ftpbuf, 0, ARRAY_SIZE(ftpbuf));
  18011. sprintf(ftpbuf, "ftpput -u %s -p %s %s -P %d %s%s %s", user, password, location, port/*21*/, path, filename, fnamePlusPath);
  18012. DEBUG_INFO("ftp command: %s\n",ftpbuf);
  18013. systemresult = system(ftpbuf);
  18014. if(systemresult != 0)
  18015. {
  18016. DEBUG_INFO("ftpput error!\n");
  18017. }
  18018. else
  18019. {
  18020. result = TRUE;
  18021. DEBUG_INFO("ftpput OK!\n");
  18022. }
  18023. return result;
  18024. }
  18025. int GetOcppServerURL()
  18026. {
  18027. int result = FALSE;
  18028. memset(OcppProtocol, 0, ARRAY_SIZE(OcppProtocol));
  18029. memset(OcppHost, 0, ARRAY_SIZE(OcppHost));
  18030. memset(OcppTempPath, 0, ARRAY_SIZE(OcppTempPath));
  18031. struct yuarel url;
  18032. char urlStr[512];
  18033. if((ShmSysConfigAndInfo->SysConfig.OcppServerURL != NULL) && (strcmp((const char *)ShmSysConfigAndInfo->SysConfig.OcppServerURL,"") != 0) )
  18034. {
  18035. /*sscanf((const char *)ShmSysConfigAndInfo->SysConfig.OcppServerURL,
  18036. "%[^:]:%*2[/]%[^:]:%i/%[a-zA-Z0-9._/-]",
  18037. OcppProtocol, OcppHost, &OcppPort, OcppTempPath);*/
  18038. memcpy(urlStr, ShmSysConfigAndInfo->SysConfig.OcppServerURL, ARRAY_SIZE(ShmSysConfigAndInfo->SysConfig.OcppServerURL));
  18039. if(yuarel_parse(&url, urlStr) != -1)
  18040. {
  18041. sprintf(OcppProtocol, "%s", url.scheme);
  18042. sprintf(OcppHost, "%s", url.host);
  18043. if(url.path == NULL)
  18044. OcppTempPath[0] = '\0';
  18045. else
  18046. {
  18047. if((url.path[strlen(url.path)-1] != '/') && (strlen(url.path) > 0))
  18048. {
  18049. sprintf(OcppTempPath, "%s/", url.path);
  18050. }
  18051. else
  18052. {
  18053. sprintf(OcppTempPath, "%s", url.path);
  18054. }
  18055. }
  18056. if(url.port == 0)
  18057. {
  18058. if(strcmp(OcppProtocol, "wss") == 0)
  18059. OcppPort = 443;
  18060. else
  18061. OcppPort = 80;
  18062. }
  18063. else
  18064. OcppPort = url.port;
  18065. result = TRUE;
  18066. }
  18067. }
  18068. else if((ShmOCPP16Data->OcppServerURL != NULL) && (strcmp((const char *)ShmOCPP16Data->OcppServerURL,"") != 0))
  18069. {
  18070. /*sscanf((const char *)ShmOCPP16Data->OcppServerURL,
  18071. "%[^:]:%*2[/]%[^:]:%i/%[a-zA-Z0-9._/-]",
  18072. OcppProtocol, OcppHost, &OcppPort, OcppTempPath);*/
  18073. memcpy(urlStr, ShmOCPP16Data->OcppServerURL, ARRAY_SIZE(ShmOCPP16Data->OcppServerURL));
  18074. if(yuarel_parse(&url, urlStr) != -1)
  18075. {
  18076. sprintf(OcppProtocol, "%s", url.scheme);
  18077. sprintf(OcppHost, "%s", url.host);
  18078. if(url.path == NULL)
  18079. OcppTempPath[0] = '\0';
  18080. else
  18081. sprintf(OcppTempPath, "%s", url.path);
  18082. if(url.port == 0)
  18083. {
  18084. if(strcmp(OcppProtocol, "wss") == 0)
  18085. OcppPort = 443;
  18086. else
  18087. OcppPort = 80;
  18088. }
  18089. else
  18090. OcppPort = url.port;
  18091. result = TRUE;
  18092. }
  18093. }
  18094. else
  18095. {
  18096. strcpy(OcppHost,"");
  18097. }
  18098. return result;
  18099. }
  18100. int GetOcppPath()
  18101. {
  18102. int result = FALSE;
  18103. if((ShmSysConfigAndInfo->SysConfig.ChargeBoxId != NULL) && (strcmp((const char *)ShmSysConfigAndInfo->SysConfig.ChargeBoxId,"") != 0) )
  18104. {
  18105. if(OcppTempPath == NULL)
  18106. {
  18107. sprintf(OcppPath,"/%s",ShmSysConfigAndInfo->SysConfig.ChargeBoxId);
  18108. }
  18109. else
  18110. {
  18111. sprintf(OcppPath,"/%s%s",OcppTempPath,ShmSysConfigAndInfo->SysConfig.ChargeBoxId);
  18112. }
  18113. result = TRUE;
  18114. goto End;
  18115. }
  18116. else if((ShmOCPP16Data->ChargeBoxId != NULL) && (strcmp((const char *)ShmOCPP16Data->ChargeBoxId,"") != 0))
  18117. {
  18118. if(OcppTempPath == NULL)
  18119. {
  18120. sprintf(OcppPath,"/%s",ShmOCPP16Data->ChargeBoxId);
  18121. }
  18122. else
  18123. {
  18124. sprintf(OcppPath,"/%s%s",OcppTempPath,ShmOCPP16Data->ChargeBoxId);
  18125. }
  18126. result = TRUE;
  18127. goto End;
  18128. }
  18129. else
  18130. {
  18131. strcpy(OcppPath,"");
  18132. }
  18133. End:
  18134. return result;
  18135. }
  18136. int GetOcppPort()
  18137. {
  18138. return OcppPort;
  18139. }
  18140. int GetOcppConnStatus(void)
  18141. {
  18142. return ShmOCPP16Data->OcppConnStatus;
  18143. }
  18144. void SetOcppConnStatus(uint8_t status)
  18145. {
  18146. ShmOCPP16Data->OcppConnStatus = status;
  18147. ShmSysConfigAndInfo->SysInfo.OcppConnStatus = status;
  18148. }
  18149. int GetHeartBeatWithNOResponse(void)
  18150. {
  18151. return HeartBeatWithNOResponse;
  18152. }
  18153. void SetHeartBeatWithNOResponse(void)
  18154. {
  18155. HeartBeatWithNOResponse = 0;
  18156. }
  18157. void GetStartTransactionIdTag(int gun_index)
  18158. {
  18159. memset(StartTransactionIdTagTemp, 0 ,ARRAY_SIZE(StartTransactionIdTagTemp));
  18160. strcpy((char *)StartTransactionIdTagTemp, (const char *)ShmOCPP16Data->StartTransaction[gun_index].IdTag);
  18161. }
  18162. int GetStartTransactionId(int gun_index)
  18163. {
  18164. return ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId;
  18165. }
  18166. int GetTransactionId(int gunindex, unsigned char idTag[], uint8_t isStopTransaction)
  18167. {
  18168. char ch;
  18169. FILE *fptr1;
  18170. int temptransactionId;
  18171. char str[100]={0};
  18172. temptransactionId = 0;
  18173. if(((strcmp((const char*)idTag, "")==0)||(idTag[0]=='\0')) && isStopTransaction)
  18174. {
  18175. DEBUG_INFO("IdTag is empty.\n");
  18176. return temptransactionId;
  18177. }
  18178. /*------ Read the file ----------------*/
  18179. fptr1=fopen("/Storage/OCPP/QueueTransactionId","r");
  18180. if (!fptr1)
  18181. {
  18182. DEBUG_INFO("QueueTransactionId file open error.\n");
  18183. //printf(" File not found or unable to open the input file!!\n");
  18184. return temptransactionId;
  18185. }
  18186. ch=fgetc(fptr1);
  18187. //printf(" Now the content of the file %s is : \n","/Storage/OCPP/QueueTransactionId");
  18188. rewind(fptr1);
  18189. if(ch!=EOF)
  18190. {
  18191. // printf("%c",ch);
  18192. while (fgets(str, 100, fptr1) != NULL)
  18193. {
  18194. str[strlen(str) - 1] = '\0'; // eat the newline fgets() stores
  18195. if(str[0]=='\0')
  18196. {
  18197. break;
  18198. }
  18199. char *revbuf[8] = {0}; // Variable store string split
  18200. int num = 0;// Quantity after string split
  18201. DEBUG_INFO("Transaction queue data= %s\n", str);
  18202. splitstring(str,",",revbuf,&num); // String split
  18203. DEBUG_INFO(" revbuf[0]= %s\n", revbuf[0]);
  18204. DEBUG_INFO(" revbuf[1]= %s\n", revbuf[1]);
  18205. DEBUG_INFO(" revbuf[2]= %s\n", revbuf[2]);
  18206. DEBUG_INFO("------------------------------\n");
  18207. if((revbuf[1][0] != '\0')&&(revbuf[2][0] != '\0'))
  18208. {
  18209. if(isStopTransaction)
  18210. {
  18211. if((atoi(revbuf[0])==gunindex) && (strcmp(revbuf[1],(const char *)idTag)==0))
  18212. {
  18213. temptransactionId = atoi(revbuf[2]);
  18214. //break;
  18215. }
  18216. }
  18217. else
  18218. {
  18219. if((atoi(revbuf[0])==gunindex) || (strcmp(revbuf[1],(const char *)idTag)==0))
  18220. {
  18221. temptransactionId = atoi(revbuf[2]);
  18222. //break;
  18223. }
  18224. }
  18225. }
  18226. }
  18227. }
  18228. else
  18229. DEBUG_INFO("EOF\n");
  18230. fclose(fptr1);
  18231. /*------- End of reading ---------------*/
  18232. return temptransactionId;
  18233. }
  18234. void SetTransactionIdZero(int transactionId)
  18235. {
  18236. char ch;
  18237. FILE *fptr1, *fptr2;
  18238. int temptransactionId = 0;
  18239. char str[100]={0}, strtemp[100]={0}, temp[] = "/Storage/OCPP/QueueTransactionIdtemp.json";
  18240. fptr1 = fopen("/Storage/OCPP/QueueTransactionId", "r");
  18241. if (!fptr1)
  18242. {
  18243. //printf(" File not found or unable to open the input file!!\n");
  18244. return ;
  18245. }
  18246. fptr2 = fopen(temp, "w"); // open the temporary file in write mode
  18247. if (!fptr2)
  18248. {
  18249. DEBUG_INFO("Unable to open a temporary file to write!!\n");
  18250. fclose(fptr1);
  18251. return ;
  18252. }
  18253. ch=fgetc(fptr1);
  18254. rewind(fptr1);
  18255. if(ch!=EOF)
  18256. {
  18257. // copy all contents to the temporary file except the specific line
  18258. while (fgets(str, 100, fptr1) != NULL)
  18259. {
  18260. str[strlen(str) - 1] = '\0'; // eat the newline fgets() stores
  18261. if(str[0]=='\0')
  18262. {
  18263. break;
  18264. }
  18265. char *revbuf[8] = {0};
  18266. int num = 0;
  18267. strcpy(strtemp, str);
  18268. splitstring(str,",",revbuf,&num);
  18269. if(revbuf[2][0] != '\0')
  18270. {
  18271. temptransactionId = atoi(revbuf[2]);
  18272. if(transactionId != temptransactionId)
  18273. {
  18274. fprintf(fptr2, "%s\n", strtemp);
  18275. }
  18276. }
  18277. }
  18278. }
  18279. fclose(fptr1);
  18280. fclose(fptr2);
  18281. remove("/Storage/OCPP/QueueTransactionId"); // remove the original file
  18282. rename(temp, "/Storage/OCPP/QueueTransactionId"); // rename the temporary file to original name
  18283. /*------ Read the file ----------------*/
  18284. }
  18285. int InternetDisconnect(void)
  18286. {
  18287. return (ShmStatusCodeData->InfoCode.InfoEvents.bits.InternetDisconnectVia4Gi && ShmStatusCodeData->InfoCode.InfoEvents.bits.InternetDisconnectViaEthernet && ShmStatusCodeData->InfoCode.InfoEvents.bits.InternetDisconnectViaWiFi );
  18288. }
  18289. //Note: It is not real StopTransaction. It is temporary StopTransaction.
  18290. void storeTempStopTransaction(int gun_index)
  18291. {
  18292. char guid[37]={0};
  18293. int tempIndex = 0;
  18294. char TempStopTransaction[256];
  18295. sprintf(TempStopTransaction, "/Storage/OCPP/TempStopTransaction_%d", (gun_index+1));
  18296. DEBUG_INFO("storeTempStopTransaction...\n");
  18297. memset(queuedata, 0, ARRAY_SIZE(queuedata));
  18298. memset(&ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0], 0, ARRAY_SIZE(ShmOCPP16Data->StopTransaction[gun_index].TransactionData));
  18299. //======================== ENERGY_ACTIVE_IMPORT_REGISTER =======================================
  18300. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DCcc
  18301. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  18302. {
  18303. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  18304. {
  18305. tempIndex = ((gun_index==2) ? 1: 0);
  18306. }
  18307. else
  18308. {
  18309. tempIndex = gun_index;
  18310. }
  18311. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  18312. {
  18313. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  18314. {
  18315. ShmOCPP16Data->StopTransaction[gun_index].MeterStop = (int)(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PowerConsumption*1000);
  18316. }
  18317. }// END OF CHAdeMO_QUANTITY
  18318. }
  18319. else if(gunType[gun_index] == GUN_TYPE_CCS)
  18320. {
  18321. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  18322. {
  18323. tempIndex = ((gun_index==2) ? 1: 0);
  18324. }
  18325. else
  18326. {
  18327. tempIndex = gun_index;
  18328. }
  18329. for (int index = 0; index < CCS_QUANTITY; index++)
  18330. {
  18331. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  18332. {
  18333. ShmOCPP16Data->StopTransaction[gun_index].MeterStop = (int)(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PowerConsumption*1000);
  18334. }
  18335. }// END OF CCS_QUANTITY
  18336. }
  18337. else if(gunType[gun_index] == GUN_TYPE_GBT)
  18338. {
  18339. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  18340. {
  18341. tempIndex = ((gun_index==2) ? 1: 0);
  18342. }
  18343. else
  18344. {
  18345. tempIndex = gun_index;
  18346. }
  18347. for (int index = 0; index < GB_QUANTITY; index++)
  18348. {
  18349. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  18350. {
  18351. ShmOCPP16Data->StopTransaction[gun_index].MeterStop = (int)(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PowerConsumption*1000);
  18352. }
  18353. }// END OF GB_QUANTITY
  18354. }
  18355. else if(gunType[gun_index] == GUN_TYPE_DO)
  18356. {
  18357. tempIndex = gun_index;
  18358. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  18359. {
  18360. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  18361. {
  18362. ShmOCPP16Data->StopTransaction[gun_index].MeterStop = (int)(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PowerConsumption*1000);
  18363. }
  18364. }
  18365. }
  18366. else
  18367. {
  18368. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  18369. {
  18370. tempIndex = 2;
  18371. }
  18372. else
  18373. {
  18374. tempIndex = gun_index;
  18375. }
  18376. for (int index = 0; index < AC_QUANTITY; index++)
  18377. {
  18378. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  18379. {
  18380. ShmOCPP16Data->StopTransaction[gun_index].MeterStop = (int)(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PowerConsumption*1000);
  18381. }
  18382. }// END OF AC_QUANTITY
  18383. }
  18384. //Stop Transaction Time
  18385. struct timeval tmnow;
  18386. struct tm *tm;
  18387. char buf[28];//, usec_buf[6];
  18388. gettimeofday(&tmnow, NULL);
  18389. time_t t;
  18390. t = time(NULL);
  18391. /*UTC time and date*/
  18392. tm = gmtime(&t);
  18393. strftime(buf,28,"%Y-%m-%dT%H:%M:%SZ", tm);
  18394. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].Timestamp,buf);
  18395. ShmOCPP16Data->StopTransaction[gun_index].TransactionId = ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId;
  18396. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].IdTag, (const char*)ShmOCPP16Data->StartTransaction[gun_index].IdTag);
  18397. random_uuid(guid);
  18398. /***********************************transactionData******************************************************/
  18399. memset(ShmOCPP16Data->StopTransaction[gun_index].TransactionData, 0, sizeof(struct StructMeterValue));
  18400. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].TimeStamp, buf);
  18401. //=================================
  18402. //1. Transaction_Begin
  18403. //=================================
  18404. //============================== Energy.Active.Import.Interval ===========================================
  18405. //=================================
  18406. //2. Transaction_End
  18407. //=================================
  18408. //2.1====================================== Current.Import L1 ==============================================
  18409. if(strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Current.Import") != NULL)
  18410. {
  18411. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G : GBT DC
  18412. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  18413. {
  18414. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  18415. {
  18416. tempIndex = ((gun_index==2) ? 1: 0);
  18417. }
  18418. else
  18419. {
  18420. tempIndex = gun_index;
  18421. }
  18422. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  18423. {
  18424. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  18425. {
  18426. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargingCurrent );// PresentChargingCurrent is 0~6553.5 amp
  18427. }
  18428. }// End of for CHAdeMO_QUANTITY
  18429. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase,PhaseStr[L3_N]);
  18430. }
  18431. else if(gunType[gun_index] == GUN_TYPE_CCS)
  18432. {
  18433. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  18434. {
  18435. tempIndex = ((gun_index==2) ? 1: 0);
  18436. }
  18437. else
  18438. {
  18439. tempIndex = gun_index;
  18440. }
  18441. for (int index = 0; index < CCS_QUANTITY; index++)
  18442. {
  18443. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  18444. {
  18445. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargingCurrent );// PresentChargingCurrent is 0~6553.5 amp
  18446. }
  18447. }// End of for CCS_QUANTITY
  18448. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase,PhaseStr[L3_N]);
  18449. }
  18450. else if(gunType[gun_index] == GUN_TYPE_GBT)
  18451. {
  18452. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  18453. {
  18454. tempIndex = ((gun_index==2) ? 1: 0);
  18455. }
  18456. else
  18457. {
  18458. tempIndex = gun_index;
  18459. }
  18460. for (int index = 0; index < GB_QUANTITY; index++)
  18461. {
  18462. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  18463. {
  18464. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingCurrent );// PresentChargingCurrent is 0~6553.5 amp
  18465. }
  18466. }// End of for GB_QUANTITY
  18467. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase,PhaseStr[L3_N]);
  18468. }
  18469. else if(gunType[gun_index] == GUN_TYPE_DO)
  18470. {
  18471. tempIndex = gun_index;
  18472. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  18473. {
  18474. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  18475. {
  18476. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PresentChargingCurrent );// PresentChargingCurrent is 0~6553.5 amp
  18477. }
  18478. }
  18479. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase,PhaseStr[L3_N]);
  18480. }
  18481. else
  18482. {
  18483. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  18484. {
  18485. tempIndex = 2;
  18486. }
  18487. else
  18488. {
  18489. tempIndex = gun_index;
  18490. }
  18491. for (int index = 0; index < AC_QUANTITY; index++)
  18492. {
  18493. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  18494. {
  18495. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingCurrent );// 0~6553.5 amp for EVSE
  18496. }
  18497. }// End of for AC_QUANTITY
  18498. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase,PhaseStr[L1_N]);
  18499. }
  18500. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  18501. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Format,ValueFormatStr[Raw]);
  18502. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Measurand,MeasurandStr[Current_Import]);
  18503. //strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase,PhaseStr[L1_N]);
  18504. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Location,LocationStr[Location_Outlet]);
  18505. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Unit,UnitOfMeasureStr[UnitOfMeasure_A]);
  18506. }
  18507. //2.2===================================== Energy.Active.Import.Interval ==========================================
  18508. if(strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Energy.Active.Import.Interval") != NULL)
  18509. {
  18510. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  18511. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  18512. {
  18513. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  18514. {
  18515. tempIndex = ((gun_index==2) ? 1: 0);
  18516. }
  18517. else
  18518. {
  18519. tempIndex = gun_index;
  18520. }
  18521. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  18522. {
  18523. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  18524. {
  18525. 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
  18526. }
  18527. }// END OF CHAdeMO_QUANTITY
  18528. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase,PhaseStr[L3_N]);
  18529. }
  18530. else if(gunType[gun_index] == GUN_TYPE_CCS)
  18531. {
  18532. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  18533. {
  18534. tempIndex = ((gun_index==2) ? 1: 0);
  18535. }
  18536. else
  18537. {
  18538. tempIndex = gun_index;
  18539. }
  18540. for (int index = 0; index < CCS_QUANTITY; index++)
  18541. {
  18542. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  18543. {
  18544. 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
  18545. }
  18546. }// END OF CCS_QUANTITY
  18547. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase,PhaseStr[L3_N]);
  18548. }
  18549. else if(gunType[gun_index] == GUN_TYPE_GBT)
  18550. {
  18551. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  18552. {
  18553. tempIndex = ((gun_index==2) ? 1: 0);
  18554. }
  18555. else
  18556. {
  18557. tempIndex = gun_index;
  18558. }
  18559. for (int index = 0; index < GB_QUANTITY; index++)
  18560. {
  18561. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  18562. {
  18563. 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
  18564. }
  18565. }// END OF GB_QUANTITY
  18566. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase,PhaseStr[L3_N]);
  18567. }
  18568. else if(gunType[gun_index] == GUN_TYPE_DO)
  18569. {
  18570. tempIndex = gun_index;
  18571. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  18572. {
  18573. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  18574. {
  18575. 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
  18576. }
  18577. }
  18578. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase,PhaseStr[L3_N]);
  18579. }
  18580. else
  18581. {
  18582. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  18583. {
  18584. tempIndex = 2;
  18585. }
  18586. else
  18587. {
  18588. tempIndex = gun_index;
  18589. }
  18590. for (int index = 0; index < AC_QUANTITY; index++)
  18591. {
  18592. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  18593. {
  18594. 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
  18595. }
  18596. }// END OF AC_QUANTITY
  18597. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase,PhaseStr[L1_N]);
  18598. }
  18599. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  18600. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Format,ValueFormatStr[Raw]);
  18601. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Measurand,MeasurandStr[Energy_Active_Import_Interval]);
  18602. //strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase,PhaseStr[L1_N]);
  18603. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Location,LocationStr[Location_Outlet]);
  18604. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Unit,UnitOfMeasureStr[UnitOfMeasure_kWh]);
  18605. }
  18606. //2.3====================================== Power.Active.Import =========================================
  18607. if(strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Power.Active.Import") != NULL)
  18608. {
  18609. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  18610. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  18611. {
  18612. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  18613. {
  18614. tempIndex = ((gun_index==2) ? 1: 0);
  18615. }
  18616. else
  18617. {
  18618. tempIndex = gun_index;
  18619. }
  18620. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  18621. {
  18622. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  18623. {
  18624. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargingPower );// PresentChargingPower is 0~6553.5 kW
  18625. }
  18626. } // End for CHAdeMO_QUANTITY
  18627. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase,PhaseStr[L3_N]);
  18628. }
  18629. else if(gunType[gun_index] == GUN_TYPE_CCS)
  18630. {
  18631. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  18632. {
  18633. tempIndex = ((gun_index==2) ? 1: 0);
  18634. }
  18635. else
  18636. {
  18637. tempIndex = gun_index;
  18638. }
  18639. for (int index = 0; index < CCS_QUANTITY; index++)
  18640. {
  18641. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  18642. {
  18643. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargingPower );// PresentChargingPower is 0~6553.5 kW
  18644. }
  18645. } // END for CCS_QUANTITY
  18646. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase,PhaseStr[L3_N]);
  18647. }
  18648. else if(gunType[gun_index] == GUN_TYPE_GBT)
  18649. {
  18650. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  18651. {
  18652. tempIndex = ((gun_index==2) ? 1: 0);
  18653. }
  18654. else
  18655. {
  18656. tempIndex = gun_index;
  18657. }
  18658. for (int index = 0; index < GB_QUANTITY; index++)
  18659. {
  18660. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  18661. {
  18662. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingPower );// PresentChargingPower is 0~6553.5 kW
  18663. }
  18664. }// END for GB_QUANTITY
  18665. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase,PhaseStr[L3_N]);
  18666. }
  18667. else if(gunType[gun_index] == GUN_TYPE_DO)
  18668. {
  18669. tempIndex = gun_index;
  18670. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  18671. {
  18672. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  18673. {
  18674. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PresentChargingPower );// PresentChargingPower is 0~6553.5 kW
  18675. }
  18676. }
  18677. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase,PhaseStr[L3_N]);
  18678. }
  18679. else
  18680. {
  18681. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  18682. {
  18683. tempIndex = 2;
  18684. }
  18685. else
  18686. {
  18687. tempIndex = gun_index;
  18688. }
  18689. for (int index = 0; index < AC_QUANTITY; index++)
  18690. {
  18691. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  18692. {
  18693. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingPower );// PresentChargingPower is 0~6553.5 kW
  18694. }
  18695. } // END for AC_QUANTITY
  18696. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase,PhaseStr[L1_N]);
  18697. }
  18698. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  18699. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Format,ValueFormatStr[Raw]);
  18700. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Measurand,MeasurandStr[Power_Active_Import]);
  18701. //strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase,PhaseStr[L1_N]);
  18702. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Location,LocationStr[Location_Outlet]);
  18703. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Unit,UnitOfMeasureStr[UnitOfMeasure_kW/*UnitOfMeasure_kWh*/]);
  18704. }
  18705. //2.4====================================== Voltage L1 ====================================================
  18706. if(strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Voltage") != NULL)
  18707. {
  18708. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  18709. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  18710. {
  18711. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  18712. {
  18713. tempIndex = ((gun_index==2) ? 1: 0);
  18714. }
  18715. else
  18716. {
  18717. tempIndex = gun_index;
  18718. }
  18719. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  18720. {
  18721. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  18722. {
  18723. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargingVoltage );// PresentChargingVoltage is 0~6553.5 volt
  18724. }
  18725. } // END OF FOR CHAdeMO_QUANTITY
  18726. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase,PhaseStr[L3_N]);
  18727. }
  18728. else if(gunType[gun_index] == GUN_TYPE_CCS)
  18729. {
  18730. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  18731. {
  18732. tempIndex = ((gun_index==2) ? 1: 0);
  18733. }
  18734. else
  18735. {
  18736. tempIndex = gun_index;
  18737. }
  18738. for (int index = 0; index < CCS_QUANTITY; index++)
  18739. {
  18740. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  18741. {
  18742. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargingVoltage );// PresentChargingVoltage is 0~6553.5 volt
  18743. }
  18744. } // END OF FOR CCS_QUANTITY
  18745. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase,PhaseStr[L3_N]);
  18746. }
  18747. else if(gunType[gun_index] == GUN_TYPE_GBT)
  18748. {
  18749. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  18750. {
  18751. tempIndex = ((gun_index==2) ? 1: 0);
  18752. }
  18753. else
  18754. {
  18755. tempIndex = gun_index;
  18756. }
  18757. for (int index = 0; index < GB_QUANTITY; index++)
  18758. {
  18759. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  18760. {
  18761. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingVoltage );// PresentChargingVoltage is 0~6553.5 volt
  18762. }
  18763. } // END OF FOR GB_QUANTITY
  18764. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase,PhaseStr[L3_N]);
  18765. }
  18766. else if(gunType[gun_index] == GUN_TYPE_DO)
  18767. {
  18768. tempIndex = gun_index;
  18769. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  18770. {
  18771. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  18772. {
  18773. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PresentChargingVoltage );// PresentChargingVoltage is 0~6553.5 volt
  18774. }
  18775. }
  18776. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase,PhaseStr[L3_N]);
  18777. }
  18778. else
  18779. {
  18780. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  18781. {
  18782. tempIndex = 2;
  18783. }
  18784. else
  18785. {
  18786. tempIndex = gun_index;
  18787. }
  18788. for (int index = 0; index < AC_QUANTITY; index++)
  18789. {
  18790. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  18791. {
  18792. 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
  18793. }
  18794. } // END OF FOR AC_QUANTITY
  18795. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase,PhaseStr[L1_N]);
  18796. }
  18797. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  18798. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Format,ValueFormatStr[Raw]);
  18799. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Measurand,MeasurandStr[Voltage]);
  18800. //strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase,PhaseStr[L1_N]);
  18801. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Location,LocationStr[Location_Outlet]);
  18802. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Unit,UnitOfMeasureStr[UnitOfMeasure_V]);
  18803. }
  18804. //2.5============================================== End SoC =========================================================
  18805. if(strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, MeasurandStr[SoC]) != NULL)
  18806. {
  18807. //J : CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  18808. 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))
  18809. {
  18810. if((ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0') && (gunType[gun_index] != GUN_TYPE_DO))
  18811. {
  18812. tempIndex = ((gun_index==2) ? 1: 0);
  18813. }
  18814. else
  18815. {
  18816. tempIndex = gun_index;
  18817. }
  18818. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  18819. {
  18820. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  18821. {
  18822. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  18823. {
  18824. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].EvBatterySoc );// 0~100%
  18825. }
  18826. }
  18827. }
  18828. else if(gunType[gun_index] == GUN_TYPE_CCS)
  18829. {
  18830. for (int index = 0; index < CCS_QUANTITY; index++)
  18831. {
  18832. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  18833. {
  18834. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].EvBatterySoc );// 0~100%
  18835. }
  18836. }
  18837. }
  18838. else if(gunType[gun_index] == GUN_TYPE_GBT)
  18839. {
  18840. for (int index = 0; index < GB_QUANTITY; index++)
  18841. {
  18842. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  18843. {
  18844. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].EvBatterySoc );// 0~100%
  18845. }
  18846. }
  18847. }
  18848. else if(gunType[gun_index] == GUN_TYPE_DO)
  18849. {
  18850. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  18851. {
  18852. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  18853. {
  18854. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.EvBatterySoc );// 0~100%
  18855. }
  18856. }
  18857. }
  18858. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  18859. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Format,ValueFormatStr[Raw]);
  18860. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Measurand,MeasurandStr[SoC/*Energy_Reactive_Export_Register*/]);
  18861. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Phase,PhaseStr[L3_N]);
  18862. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Location,LocationStr[Location_EV]);
  18863. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Unit,UnitOfMeasureStr[UnitOfMeasure_Percent/*UnitOfMeasure_kWh*/]);
  18864. } // END FOR DC CASE
  18865. }
  18866. //2.6====================================== Current.Import L2 ==============================================
  18867. if(strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Current.Import") != NULL)
  18868. {
  18869. // AC 3 phase L2 current
  18870. if((gunType[gun_index] == GUN_TYPE_AC) && ((ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'W') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='D')))
  18871. {
  18872. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  18873. {
  18874. tempIndex = 2;
  18875. }
  18876. else
  18877. {
  18878. tempIndex = gun_index;
  18879. }
  18880. for (int index = 0; index < AC_QUANTITY; index++)
  18881. {
  18882. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  18883. {
  18884. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingCurrentL2);// 0~6553.5 amp for EVSE
  18885. }
  18886. }// End of for AC_QUANTITY
  18887. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Phase,PhaseStr[L2_N]);
  18888. }
  18889. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  18890. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Format,ValueFormatStr[Raw]);
  18891. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Measurand,MeasurandStr[Current_Import]);
  18892. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Location,LocationStr[Location_Outlet]);
  18893. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Unit,UnitOfMeasureStr[UnitOfMeasure_A]);
  18894. }
  18895. //2.7====================================== Current.Import L3 ==============================================
  18896. if(strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Current.Import") != NULL)
  18897. {
  18898. // AC 3 phase L3 current
  18899. if((gunType[gun_index] == GUN_TYPE_AC) && ((ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'W') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='D')))
  18900. {
  18901. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  18902. {
  18903. tempIndex = 2;
  18904. }
  18905. else
  18906. {
  18907. tempIndex = gun_index;
  18908. }
  18909. for (int index = 0; index < AC_QUANTITY; index++)
  18910. {
  18911. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  18912. {
  18913. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingCurrentL3);// 0~6553.5 amp for EVSE
  18914. }
  18915. }// End of for AC_QUANTITY
  18916. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Phase,PhaseStr[L3_N]);
  18917. }
  18918. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  18919. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Format,ValueFormatStr[Raw]);
  18920. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Measurand,MeasurandStr[Current_Import]);
  18921. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Location,LocationStr[Location_Outlet]);
  18922. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Unit,UnitOfMeasureStr[UnitOfMeasure_A]);
  18923. }
  18924. //2.9====================================== Voltage L2 ====================================================
  18925. if(strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Voltage") != NULL)
  18926. {
  18927. // AC 3 phase L2 volatge
  18928. if((gunType[gun_index] == GUN_TYPE_AC) && ((ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'W') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='D')))
  18929. {
  18930. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  18931. {
  18932. tempIndex = 2;
  18933. }
  18934. else
  18935. {
  18936. tempIndex = gun_index;
  18937. }
  18938. for (int index = 0; index < AC_QUANTITY; index++)
  18939. {
  18940. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  18941. {
  18942. 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
  18943. }
  18944. } // END OF FOR AC_QUANTITY
  18945. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Phase,PhaseStr[L2_N]);
  18946. }
  18947. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  18948. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Format,ValueFormatStr[Raw]);
  18949. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Measurand,MeasurandStr[Voltage]);
  18950. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Location,LocationStr[Location_Outlet]);
  18951. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Unit,UnitOfMeasureStr[UnitOfMeasure_V]);
  18952. }
  18953. //2.10====================================== Voltage L3 ====================================================
  18954. if(strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Voltage") != NULL)
  18955. {
  18956. // AC 3 phase L3 volatge
  18957. if((gunType[gun_index] == GUN_TYPE_AC) && ((ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'W') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='D')))
  18958. {
  18959. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  18960. {
  18961. tempIndex = 2;
  18962. }
  18963. else
  18964. {
  18965. tempIndex = gun_index;
  18966. }
  18967. for (int index = 0; index < AC_QUANTITY; index++)
  18968. {
  18969. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  18970. {
  18971. 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
  18972. }
  18973. } // END OF FOR AC_QUANTITY
  18974. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Phase,PhaseStr[L3_N]);
  18975. }
  18976. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  18977. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Format,ValueFormatStr[Raw]);
  18978. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Measurand,MeasurandStr[Voltage]);
  18979. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Location,LocationStr[Location_Outlet]);
  18980. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Unit,UnitOfMeasureStr[UnitOfMeasure_V]);
  18981. }
  18982. //====================== Start SoC ================================
  18983. if(strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, MeasurandStr[SoC]) != NULL)
  18984. {
  18985. //J : CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  18986. 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))
  18987. {
  18988. if((ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0') && (gunType[gun_index] != GUN_TYPE_DO))
  18989. {
  18990. tempIndex = ((gun_index==2) ? 1: 0);
  18991. }
  18992. else
  18993. {
  18994. tempIndex = gun_index;
  18995. }
  18996. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  18997. {
  18998. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  18999. {
  19000. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  19001. {
  19002. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].EvBatteryStartSoc );// 0~100%
  19003. }
  19004. }
  19005. }
  19006. else if(gunType[gun_index] == GUN_TYPE_CCS)
  19007. {
  19008. for (int index = 0; index < CCS_QUANTITY; index++)
  19009. {
  19010. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  19011. {
  19012. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].EvBatteryStartSoc );// 0~100%
  19013. }
  19014. }
  19015. }
  19016. else if(gunType[gun_index] == GUN_TYPE_GBT)
  19017. {
  19018. for (int index = 0; index < GB_QUANTITY; index++)
  19019. {
  19020. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  19021. {
  19022. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].EvBatteryStartSoc );// 0~100%
  19023. }
  19024. }
  19025. }
  19026. else if(gunType[gun_index] == GUN_TYPE_DO)
  19027. {
  19028. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  19029. {
  19030. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  19031. {
  19032. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.EvBatteryStartSoc );// 0~100%
  19033. }
  19034. }
  19035. }
  19036. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Context,ReadingContextStr[ReadingContext_Transaction_Begin]);
  19037. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Format,ValueFormatStr[Raw]);
  19038. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Measurand,MeasurandStr[SoC/*Energy_Reactive_Export_Register*/]);
  19039. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Phase,PhaseStr[L3_N]);
  19040. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Location,LocationStr[Location_EV]);
  19041. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Unit,UnitOfMeasureStr[UnitOfMeasure_Percent/*UnitOfMeasure_kWh*/]);
  19042. } // END FOR DC CASE
  19043. }
  19044. //======================================== Message create ==============================================
  19045. json_object *StopTransaction = json_object_new_object();
  19046. json_object *transactionDatas = json_object_new_array();
  19047. json_object *sampledValues = json_object_new_array();
  19048. if(strlen((char*)ShmOCPP16Data->StopTransaction[gun_index].IdTag) > 0)
  19049. json_object_object_add(StopTransaction, "idTag", json_object_new_string((char*)ShmOCPP16Data->StopTransaction[gun_index].IdTag));
  19050. json_object_object_add(StopTransaction, "meterStop", json_object_new_int(ShmOCPP16Data->StopTransaction[gun_index].MeterStop));
  19051. json_object_object_add(StopTransaction, "transactionId", json_object_new_int(ShmOCPP16Data->StopTransaction[gun_index].TransactionId));
  19052. json_object_object_add(StopTransaction, "timestamp", json_object_new_string((char*)ShmOCPP16Data->StopTransaction[gun_index].Timestamp));
  19053. json_object_object_add(StopTransaction, "reason", json_object_new_string("PowerLoss"));
  19054. for(int idxTrans = 0;idxTrans<ARRAY_SIZE(ShmOCPP16Data->StopTransaction[gun_index].TransactionData);idxTrans++)
  19055. {
  19056. json_object *transactionData = json_object_new_object();
  19057. json_object_object_add(transactionData, "timestamp", json_object_new_string((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].TimeStamp));
  19058. for(int idx=0;idx<ARRAY_SIZE(ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue);idx++)
  19059. {
  19060. if(strlen((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Value) > 0)
  19061. {
  19062. json_object *sampledValue = json_object_new_object();
  19063. json_object_object_add(sampledValue, "value", json_object_new_string((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Value));
  19064. if(strlen((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Context) > 0)
  19065. json_object_object_add(sampledValue, "context", json_object_new_string((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Context));
  19066. if(strlen((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Format) > 0)
  19067. json_object_object_add(sampledValue, "format", json_object_new_string((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Format));
  19068. if(strlen((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Measurand) > 0)
  19069. json_object_object_add(sampledValue, "measurand", json_object_new_string((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Measurand));
  19070. if(strlen((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Phase) > 0)
  19071. json_object_object_add(sampledValue, "phase", json_object_new_string((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Phase));
  19072. if(strlen((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Location) > 0)
  19073. json_object_object_add(sampledValue, "location", json_object_new_string((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Location));
  19074. if(strlen((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Unit) > 0)
  19075. json_object_object_add(sampledValue, "unit", json_object_new_string((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Unit));
  19076. json_object_array_add(sampledValues, sampledValue);
  19077. }
  19078. }
  19079. json_object_object_add(transactionData, "sampledValue", sampledValues);
  19080. json_object_array_add(transactionDatas, transactionData);
  19081. }
  19082. json_object_object_add(StopTransaction, "transactionData", transactionDatas);
  19083. sprintf(queuedata, "%d,[%d,\"%s\",\"StopTransaction\",%s]",(gun_index+1)
  19084. ,MESSAGE_TYPE_CALL
  19085. ,guid
  19086. ,json_object_to_json_string_ext(StopTransaction, JSON_C_TO_STRING_PLAIN));
  19087. json_object_put(StopTransaction);
  19088. // Check File "TempStopTransaction" Exist
  19089. if((access(TempStopTransaction,F_OK))!=-1)
  19090. {
  19091. //DEBUG_INFO("TransactionRelatedQueue exist.\n");
  19092. fclose(fopen(TempStopTransaction, "w"));
  19093. }
  19094. else
  19095. {
  19096. //DEBUG_INFO("TransactionRelatedQueue not exist\n");
  19097. FILE *log = fopen(TempStopTransaction, "w+");
  19098. if(log == NULL)
  19099. {
  19100. //DEBUG_INFO("Can't Create File TransactionRelatedQueue \n");
  19101. return ;
  19102. }
  19103. else
  19104. {
  19105. fclose(log);
  19106. }
  19107. }
  19108. //Add TempStopTransaction | Update TempStopTransaction
  19109. // open file for writing
  19110. FILE *outfile;
  19111. outfile = fopen (TempStopTransaction, "a");
  19112. //DEBUG_INFO("data = %s\n", queuedata);
  19113. fputs(queuedata, outfile);
  19114. fputs("\n", outfile);
  19115. fclose (outfile);
  19116. system("/bin/fsync -d /dev/mtdblock13;/bin/sync &");
  19117. OCPP_updatePeriodEnergy(gun_index);
  19118. }
  19119. void checkTempStopTransaction(int gun_index)
  19120. {
  19121. FILE *fptr1;
  19122. char ch;
  19123. char str[QUEUE_MESSAGE_LENGTH]={0};
  19124. char guid[37]={0};
  19125. char tempdata[65]={0};
  19126. char connectorStr[2]={0};
  19127. char TempStopTransaction[256];
  19128. sprintf(TempStopTransaction, "/Storage/OCPP/TempStopTransaction_%d", (gun_index+1));
  19129. fptr1 = fopen(TempStopTransaction, "r");
  19130. //TempStopTransaction格式: 槍號,StopTransaction封包
  19131. if (!fptr1)
  19132. {
  19133. //printf(" File not found or unable to open the input file!!\n");
  19134. return ;
  19135. }
  19136. ch=fgetc(fptr1);
  19137. //printf(" Now the content of the file %s is : \n",fname);
  19138. rewind(fptr1);
  19139. if(ch!=EOF)
  19140. {
  19141. // copy all contents to the temporary file except the specific line
  19142. while (fgets(str, QUEUE_MESSAGE_LENGTH, fptr1) != NULL)
  19143. {
  19144. str[strlen(str) - 1] = '\0'; // eat the newline fgets() stores
  19145. if(str[0]=='\0')
  19146. {
  19147. break;
  19148. }
  19149. //TempStopTransaction格式: 槍號,StopTransaction封包
  19150. strncpy(connectorStr, str, 1);
  19151. if(atoi(connectorStr) != (gun_index+1))
  19152. {
  19153. DEBUG_INFO("atoi(connectorStr) = %d, gun_index = %d\n", atoi(connectorStr), gun_index);
  19154. fclose(fptr1);
  19155. return ;
  19156. }
  19157. //random_uuid(guid);
  19158. strncpy(guid, str+6, 36); //copy guid
  19159. sprintf(tempdata, "StopTransaction,%d", (gun_index));
  19160. if(hashmap_operation(HASH_OP_ADD, guid, tempdata) == 1)
  19161. {
  19162. //DEBUG_INFO("StopTransaction mapitem pass\n");
  19163. }
  19164. queue_operation(QUEUE_OPERATION_ADD, guid, str);//addq(guid, queuedata); ---> remove temporally
  19165. OCPP_insert_transaction_msg(NO, str);
  19166. memset(str,0,ARRAY_SIZE(str));
  19167. }
  19168. }
  19169. // fptr1=freopen(NULL,"w",fptr1); // reset the fptr1 again
  19170. fclose(fptr1);
  19171. remove(TempStopTransaction); // remove the original file
  19172. system("/bin/fsync -d /dev/mtdblock13;/bin/sync &");
  19173. }
  19174. void FillStartTransaction(int ConnectorId, unsigned char IdTag[], int MeterStart,int ReservationId,unsigned char Timestamp[])
  19175. {
  19176. ShmOCPP16Data->StartTransaction[ConnectorId-1].ConnectorId = ConnectorId;
  19177. ShmOCPP16Data->StartTransaction[ConnectorId-1].ReservationId = ReservationId;
  19178. ShmOCPP16Data->StartTransaction[ConnectorId-1].MeterStart = MeterStart;
  19179. strcpy((char *)ShmOCPP16Data->StartTransaction[ConnectorId-1].IdTag, (char *)IdTag);
  19180. strcpy((char *)ShmOCPP16Data->StartTransaction[ConnectorId-1].Timestamp,(char *) Timestamp);
  19181. }
  19182. int GetWebSocketPingInterval(void)
  19183. {
  19184. return atoi((const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemData);
  19185. }
  19186. int GetServerSign(void)
  19187. {
  19188. return server_sign;
  19189. }
  19190. uint8_t GetOcppSecurityProfile()
  19191. {
  19192. return atoi((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[SecurityProfile].ItemData);
  19193. }
  19194. void GetOcppChargerBoxId(uint8_t *data)
  19195. {
  19196. sprintf((char*)data, "%s", ShmSysConfigAndInfo->SysConfig.ChargeBoxId);
  19197. }
  19198. void GetOcppSecurityPassword(uint8_t *data)
  19199. {
  19200. sprintf((char*)data, "%s", ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationKey].ItemData);
  19201. }
  19202. void SetOcppVersion(uint8_t *version)
  19203. {
  19204. for (uint8_t idx=0; idx<strlen((char*)version); idx++) version[idx] = tolower(version[idx]);
  19205. DEBUG_INFO("ocpp version: %s\n", version);
  19206. if(strstr((char*)version, "ocpp1.6") != NULL)
  19207. {
  19208. ShmSysConfigAndInfo->SysInfo.OcppRunningVer = OCPP_RUNNING_VERSION_16;
  19209. }
  19210. else if(strstr((char*)version, "ocpp2.0") != NULL)
  19211. {
  19212. ShmSysConfigAndInfo->SysInfo.OcppRunningVer = OCPP_RUNNING_VERSION_20;
  19213. system("pkill OcppBackend");
  19214. }
  19215. }
  19216. void SetServerSign(int value)
  19217. {
  19218. server_sign = value;
  19219. }
  19220. int GetBootNotificationInterval(void)
  19221. {
  19222. return BootNotificationInterval;
  19223. }
  19224. int GetInternetConn(void)
  19225. {
  19226. return ShmSysConfigAndInfo->SysInfo.InternetConn;
  19227. }
  19228. int GetBackendConnectionTimeout(void)
  19229. {
  19230. return ShmSysConfigAndInfo->SysConfig.BackendConnTimeout>=0?ShmSysConfigAndInfo->SysConfig.BackendConnTimeout:300;
  19231. }
  19232. int isConnectorInitMode(int gun_index)
  19233. {
  19234. int tempIndex = 0;
  19235. int result = TRUE;
  19236. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DCcc
  19237. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  19238. {
  19239. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  19240. {
  19241. tempIndex = ((gun_index==2) ? 1: 0);
  19242. }
  19243. else
  19244. {
  19245. tempIndex = gun_index;
  19246. }
  19247. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  19248. {
  19249. if ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex))
  19250. {
  19251. result = (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus==SYS_MODE_BOOTING)?TRUE:FALSE;
  19252. } //end of the same index
  19253. }//end of for CHAdeMO_QUANTITY
  19254. }
  19255. else if(gunType[gun_index] == GUN_TYPE_CCS)
  19256. {
  19257. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  19258. {
  19259. tempIndex = ((gun_index==2) ? 1: 0);
  19260. }
  19261. else
  19262. {
  19263. tempIndex = gun_index;
  19264. }
  19265. for (int index = 0; index < CCS_QUANTITY; index++)
  19266. {
  19267. if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  19268. {
  19269. result = (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus==SYS_MODE_BOOTING)?TRUE:FALSE;
  19270. } //end of the same index
  19271. } // end of for CCS_QUANTITY
  19272. }
  19273. else if(gunType[gun_index] == GUN_TYPE_GBT)
  19274. {
  19275. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  19276. {
  19277. tempIndex = ((gun_index==2) ? 1: 0);
  19278. }
  19279. else
  19280. {
  19281. tempIndex = gun_index;
  19282. }
  19283. for (int index = 0; index < GB_QUANTITY; index++)
  19284. {
  19285. if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  19286. {
  19287. result = (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus==SYS_MODE_BOOTING)?TRUE:FALSE;
  19288. } //end of the same index
  19289. } // end of for GB_QUANTITY
  19290. }
  19291. else if(gunType[gun_index] == GUN_TYPE_DO)
  19292. {
  19293. tempIndex = gun_index;
  19294. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  19295. {
  19296. if(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  19297. {
  19298. result = (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus==SYS_MODE_BOOTING)?TRUE:FALSE;
  19299. } //end of the same index
  19300. }
  19301. }
  19302. else
  19303. {
  19304. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  19305. {
  19306. tempIndex = 2;
  19307. }
  19308. else
  19309. {
  19310. tempIndex = gun_index;
  19311. }
  19312. for (int index = 0; index < AC_QUANTITY; index++)
  19313. {
  19314. if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  19315. {
  19316. result = (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus==SYS_MODE_BOOTING)?TRUE:FALSE;
  19317. }//end of the same index
  19318. }//end of for AC_QUANTITY
  19319. }
  19320. return result;
  19321. }
  19322. void refreshProcDogTimer()
  19323. {
  19324. ShmOCPP16Data->procDogTime = time((time_t*)NULL);
  19325. }
  19326. void InitialSystemValue(void)
  19327. {
  19328. server_cycle_Status = atoi((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemData);
  19329. locallistVersion=0;
  19330. BootNotificationInterval = 0;
  19331. authorizeRetryTimes = 0;
  19332. GunStatusInterval = 10;
  19333. TransactionMessageAttemptsValue = atoi((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData);
  19334. TransactionMessageRetryIntervalValue = atoi((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData);
  19335. //Hear Beat
  19336. HeartBeatWithNOResponse = 0;
  19337. HeartBeatWaitTime = atoi((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemData);;
  19338. FirstHeartBeat = 0;
  19339. FirmwareStatusNotificationStatus = FIRMWARE_STATUS_IDLE; // Idle
  19340. DiagnosticsStatusNotificationStatus = DIAGNOSTIC_STATUS_IDLE; // Idle
  19341. memset(CurrentChargingProfileScheduleStr, 0, ARRAY_SIZE(CurrentChargingProfileScheduleStr));
  19342. memset(ChademoPreviousSystemStatus, 0, ARRAY_SIZE(ChademoPreviousSystemStatus));
  19343. memset(CcsPreviousSystemStatus, 0, ARRAY_SIZE(CcsPreviousSystemStatus));
  19344. memset(GbPreviousSystemStatus, 0, ARRAY_SIZE(GbPreviousSystemStatus));
  19345. memset(AcPreviousSystemStatus, 0, ARRAY_SIZE(AcPreviousSystemStatus));
  19346. memset(ChademoPreviousConnectorPlugIn, 0, ARRAY_SIZE(ChademoPreviousConnectorPlugIn));
  19347. memset(CcsPreviousConnectorPlugIn, 0, ARRAY_SIZE(CcsPreviousConnectorPlugIn));
  19348. memset(GbPreviousConnectorPlugIn, 0, ARRAY_SIZE(GbPreviousConnectorPlugIn));
  19349. memset(AcPreviousConnectorPlugIn, 0, ARRAY_SIZE(AcPreviousConnectorPlugIn));
  19350. //Status && ConnectorPlugIn Setting
  19351. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  19352. {
  19353. ChademoPreviousSystemStatus[index] = 99; //ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PreviousSystemStatus;
  19354. ChademoPreviousConnectorPlugIn[index] = ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ConnectorPlugIn;
  19355. }
  19356. for (int index = 0; index < CCS_QUANTITY; index++)
  19357. {
  19358. CcsPreviousSystemStatus[index] = 99; //ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PreviousSystemStatus;
  19359. CcsPreviousConnectorPlugIn[index] = ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ConnectorPlugIn;
  19360. }
  19361. for (int index = 0; index < GB_QUANTITY; index++)
  19362. {
  19363. GbPreviousSystemStatus[index] = 99; //ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PreviousSystemStatus;
  19364. GbPreviousConnectorPlugIn[index] = ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ConnectorPlugIn;
  19365. }
  19366. for (int index = 0; index < AC_QUANTITY; index++)
  19367. {
  19368. AcPreviousSystemStatus[index] = 99; //ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PreviousSystemStatus;
  19369. AcPreviousConnectorPlugIn[index] = ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PilotState;
  19370. }
  19371. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  19372. {
  19373. DoPreviousSystemStatus[index] = 99; //ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PreviousSystemStatus;
  19374. DoPreviousConnectorPlugIn[index] = ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PilotState;
  19375. }
  19376. for(int gun_index=0; gun_index < gunTotalNumber; gun_index++ )
  19377. {
  19378. cpinitateMsg.bits[gun_index].TriggerStatusNotificationReq = 0;
  19379. cpinitateMsg.bits[gun_index].StatusNotificationReq = 0;
  19380. cpinitateMsg.bits[gun_index].StatusNotificationConf = 0;
  19381. //clientTime.MeterValues[gun_index] = time((time_t*)NULL);
  19382. //memset(&ShmOCPP16Data->StatusNotification[gun_index], 0x00, sizeof(struct StructStatusNotification));
  19383. memset(&ShmOCPP16Data->StatusNotification[gun_index].Status, 0x00, sizeof(ShmOCPP16Data->StatusNotification[gun_index].Status));
  19384. }
  19385. memset( (void *)unknownkey, 0, sizeof(unknownkey));
  19386. refreshStartTimer(&clientTime.Heartbeat);
  19387. sleep(1);
  19388. }
  19389. void LWS_Send(char *str)
  19390. {
  19391. //=====================================================
  19392. // Check InternetConn 0: disconnected, 1: connected
  19393. //====================================================
  19394. if(GetOcppConnStatus() == 0)
  19395. {
  19396. DEBUG_INFO("offline now !!!\n");
  19397. return;
  19398. }
  19399. // Only disable isWebsocketSendable operation initiated by charger
  19400. if((strstr((char*)str, "\"Authorize\"") != NULL)
  19401. || (strstr((char*)str, "\"BootNotification\"") != NULL)
  19402. || (strstr((char*)str, "\"DataTransfer\"") != NULL)
  19403. || (strstr((char*)str, "\"DiagnosticsStatusNotification\"") != NULL)
  19404. || (strstr((char*)str, "\"FirmwareStatusNotification\"") != NULL)
  19405. || (strstr((char*)str, "\"Heartbeat\"") != NULL)
  19406. || (strstr((char*)str, "\"MeterValues\"") != NULL)
  19407. || (strstr((char*)str, "\"StartTransaction\"") != NULL)
  19408. || (strstr((char*)str, "\"StatusNotification\"") != NULL)
  19409. || (strstr((char*)str, "\"StopTransaction\"") != NULL)
  19410. || (strstr((char*)str, "\"LogStatusNotification\"") != NULL)
  19411. || (strstr((char*)str, "\"SecurityEventNotification\"") != NULL)
  19412. || (strstr((char*)str, "\"SignCertificate\"") != NULL)
  19413. || (strstr((char*)str, "\"SignedFirmwareStatusNotification\"") != NULL))
  19414. {
  19415. isWebsocketSendable = 0;
  19416. }
  19417. pthread_mutex_lock(&lock_send);
  19418. memset(SendBuffer, 0, ARRAY_SIZE(SendBuffer));
  19419. sprintf((char *)SendBuffer, "%s", str);
  19420. SendBufLen = strlen(str);
  19421. pthread_mutex_unlock(&lock_send);
  19422. lws_callback_on_writable(wsi_client);
  19423. //lws_service(context, 0);
  19424. //sleep(1);
  19425. }
  19426. void LWS_SendNow(char *str)
  19427. {
  19428. //=====================================================
  19429. // Check InternetConn 0: disconnected, 1: connected
  19430. //====================================================
  19431. if(GetOcppConnStatus() == 0)
  19432. {
  19433. DEBUG_INFO("offline now !!!\n");
  19434. return;
  19435. }
  19436. // Only disable isWebsocketSendable operation initiated by charger
  19437. if((strstr((char*)str, "\"Authorize\"") != NULL)
  19438. || (strstr((char*)str, "\"BootNotification\"") != NULL)
  19439. || (strstr((char*)str, "\"DataTransfer\"") != NULL)
  19440. || (strstr((char*)str, "\"DiagnosticsStatusNotification\"") != NULL)
  19441. || (strstr((char*)str, "\"FirmwareStatusNotification\"") != NULL)
  19442. || (strstr((char*)str, "\"Heartbeat\"") != NULL)
  19443. || (strstr((char*)str, "\"MeterValues\"") != NULL)
  19444. || (strstr((char*)str, "\"StartTransaction\"") != NULL)
  19445. || (strstr((char*)str, "\"StatusNotification\"") != NULL)
  19446. || (strstr((char*)str, "\"StopTransaction\"") != NULL)
  19447. || (strstr((char*)str, "\"LogStatusNotification\"") != NULL)
  19448. || (strstr((char*)str, "\"SecurityEventNotification\"") != NULL)
  19449. || (strstr((char*)str, "\"SignCertificate\"") != NULL)
  19450. || (strstr((char*)str, "\"SignedFirmwareStatusNotification\"") != NULL))
  19451. {
  19452. isWebsocketSendable = 0;
  19453. }
  19454. pthread_mutex_lock(&lock_send);
  19455. memset(SendBuffer, 0, ARRAY_SIZE(SendBuffer));
  19456. sprintf((char *)SendBuffer, "%s", str);
  19457. SendBufLen = strlen(str);
  19458. pthread_mutex_unlock(&lock_send);
  19459. lws_callback_on_writable(wsi_client);
  19460. lws_service(context, 0);
  19461. //sleep(1);
  19462. }