MessageHandler.c 982 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309331033113312331333143315331633173318331933203321332233233324332533263327332833293330333133323333333433353336333733383339334033413342334333443345334633473348334933503351335233533354335533563357335833593360336133623363336433653366336733683369337033713372337333743375337633773378337933803381338233833384338533863387338833893390339133923393339433953396339733983399340034013402340334043405340634073408340934103411341234133414341534163417341834193420342134223423342434253426342734283429343034313432343334343435343634373438343934403441344234433444344534463447344834493450345134523453345434553456345734583459346034613462346334643465346634673468346934703471347234733474347534763477347834793480348134823483348434853486348734883489349034913492349334943495349634973498349935003501350235033504350535063507350835093510351135123513351435153516351735183519352035213522352335243525352635273528352935303531353235333534353535363537353835393540354135423543354435453546354735483549355035513552355335543555355635573558355935603561356235633564356535663567356835693570357135723573357435753576357735783579358035813582358335843585358635873588358935903591359235933594359535963597359835993600360136023603360436053606360736083609361036113612361336143615361636173618361936203621362236233624362536263627362836293630363136323633363436353636363736383639364036413642364336443645364636473648364936503651365236533654365536563657365836593660366136623663366436653666366736683669367036713672367336743675367636773678367936803681368236833684368536863687368836893690369136923693369436953696369736983699370037013702370337043705370637073708370937103711371237133714371537163717371837193720372137223723372437253726372737283729373037313732373337343735373637373738373937403741374237433744374537463747374837493750375137523753375437553756375737583759376037613762376337643765376637673768376937703771377237733774377537763777377837793780378137823783378437853786378737883789379037913792379337943795379637973798379938003801380238033804380538063807380838093810381138123813381438153816381738183819382038213822382338243825382638273828382938303831383238333834383538363837383838393840384138423843384438453846384738483849385038513852385338543855385638573858385938603861386238633864386538663867386838693870387138723873387438753876387738783879388038813882388338843885388638873888388938903891389238933894389538963897389838993900390139023903390439053906390739083909391039113912391339143915391639173918391939203921392239233924392539263927392839293930393139323933393439353936393739383939394039413942394339443945394639473948394939503951395239533954395539563957395839593960396139623963396439653966396739683969397039713972397339743975397639773978397939803981398239833984398539863987398839893990399139923993399439953996399739983999400040014002400340044005400640074008400940104011401240134014401540164017401840194020402140224023402440254026402740284029403040314032403340344035403640374038403940404041404240434044404540464047404840494050405140524053405440554056405740584059406040614062406340644065406640674068406940704071407240734074407540764077407840794080408140824083408440854086408740884089409040914092409340944095409640974098409941004101410241034104410541064107410841094110411141124113411441154116411741184119412041214122412341244125412641274128412941304131413241334134413541364137413841394140414141424143414441454146414741484149415041514152415341544155415641574158415941604161416241634164416541664167416841694170417141724173417441754176417741784179418041814182418341844185418641874188418941904191419241934194419541964197419841994200420142024203420442054206420742084209421042114212421342144215421642174218421942204221422242234224422542264227422842294230423142324233423442354236423742384239424042414242424342444245424642474248424942504251425242534254425542564257425842594260426142624263426442654266426742684269427042714272427342744275427642774278427942804281428242834284428542864287428842894290429142924293429442954296429742984299430043014302430343044305430643074308430943104311431243134314431543164317431843194320432143224323432443254326432743284329433043314332433343344335433643374338433943404341434243434344434543464347434843494350435143524353435443554356435743584359436043614362436343644365436643674368436943704371437243734374437543764377437843794380438143824383438443854386438743884389439043914392439343944395439643974398439944004401440244034404440544064407440844094410441144124413441444154416441744184419442044214422442344244425442644274428442944304431443244334434443544364437443844394440444144424443444444454446444744484449445044514452445344544455445644574458445944604461446244634464446544664467446844694470447144724473447444754476447744784479448044814482448344844485448644874488448944904491449244934494449544964497449844994500450145024503450445054506450745084509451045114512451345144515451645174518451945204521452245234524452545264527452845294530453145324533453445354536453745384539454045414542454345444545454645474548454945504551455245534554455545564557455845594560456145624563456445654566456745684569457045714572457345744575457645774578457945804581458245834584458545864587458845894590459145924593459445954596459745984599460046014602460346044605460646074608460946104611461246134614461546164617461846194620462146224623462446254626462746284629463046314632463346344635463646374638463946404641464246434644464546464647464846494650465146524653465446554656465746584659466046614662466346644665466646674668466946704671467246734674467546764677467846794680468146824683468446854686468746884689469046914692469346944695469646974698469947004701470247034704470547064707470847094710471147124713471447154716471747184719472047214722472347244725472647274728472947304731473247334734473547364737473847394740474147424743474447454746474747484749475047514752475347544755475647574758475947604761476247634764476547664767476847694770477147724773477447754776477747784779478047814782478347844785478647874788478947904791479247934794479547964797479847994800480148024803480448054806480748084809481048114812481348144815481648174818481948204821482248234824482548264827482848294830483148324833483448354836483748384839484048414842484348444845484648474848484948504851485248534854485548564857485848594860486148624863486448654866486748684869487048714872487348744875487648774878487948804881488248834884488548864887488848894890489148924893489448954896489748984899490049014902490349044905490649074908490949104911491249134914491549164917491849194920492149224923492449254926492749284929493049314932493349344935493649374938493949404941494249434944494549464947494849494950495149524953495449554956495749584959496049614962496349644965496649674968496949704971497249734974497549764977497849794980498149824983498449854986498749884989499049914992499349944995499649974998499950005001500250035004500550065007500850095010501150125013501450155016501750185019502050215022502350245025502650275028502950305031503250335034503550365037503850395040504150425043504450455046504750485049505050515052505350545055505650575058505950605061506250635064506550665067506850695070507150725073507450755076507750785079508050815082508350845085508650875088508950905091509250935094509550965097509850995100510151025103510451055106510751085109511051115112511351145115511651175118511951205121512251235124512551265127512851295130513151325133513451355136513751385139514051415142514351445145514651475148514951505151515251535154515551565157515851595160516151625163516451655166516751685169517051715172517351745175517651775178517951805181518251835184518551865187518851895190519151925193519451955196519751985199520052015202520352045205520652075208520952105211521252135214521552165217521852195220522152225223522452255226522752285229523052315232523352345235523652375238523952405241524252435244524552465247524852495250525152525253525452555256525752585259526052615262526352645265526652675268526952705271527252735274527552765277527852795280528152825283528452855286528752885289529052915292529352945295529652975298529953005301530253035304530553065307530853095310531153125313531453155316531753185319532053215322532353245325532653275328532953305331533253335334533553365337533853395340534153425343534453455346534753485349535053515352535353545355535653575358535953605361536253635364536553665367536853695370537153725373537453755376537753785379538053815382538353845385538653875388538953905391539253935394539553965397539853995400540154025403540454055406540754085409541054115412541354145415541654175418541954205421542254235424542554265427542854295430543154325433543454355436543754385439544054415442544354445445544654475448544954505451545254535454545554565457545854595460546154625463546454655466546754685469547054715472547354745475547654775478547954805481548254835484548554865487548854895490549154925493549454955496549754985499550055015502550355045505550655075508550955105511551255135514551555165517551855195520552155225523552455255526552755285529553055315532553355345535553655375538553955405541554255435544554555465547554855495550555155525553555455555556555755585559556055615562556355645565556655675568556955705571557255735574557555765577557855795580558155825583558455855586558755885589559055915592559355945595559655975598559956005601560256035604560556065607560856095610561156125613561456155616561756185619562056215622562356245625562656275628562956305631563256335634563556365637563856395640564156425643564456455646564756485649565056515652565356545655565656575658565956605661566256635664566556665667566856695670567156725673567456755676567756785679568056815682568356845685568656875688568956905691569256935694569556965697569856995700570157025703570457055706570757085709571057115712571357145715571657175718571957205721572257235724572557265727572857295730573157325733573457355736573757385739574057415742574357445745574657475748574957505751575257535754575557565757575857595760576157625763576457655766576757685769577057715772577357745775577657775778577957805781578257835784578557865787578857895790579157925793579457955796579757985799580058015802580358045805580658075808580958105811581258135814581558165817581858195820582158225823582458255826582758285829583058315832583358345835583658375838583958405841584258435844584558465847584858495850585158525853585458555856585758585859586058615862586358645865586658675868586958705871587258735874587558765877587858795880588158825883588458855886588758885889589058915892589358945895589658975898589959005901590259035904590559065907590859095910591159125913591459155916591759185919592059215922592359245925592659275928592959305931593259335934593559365937593859395940594159425943594459455946594759485949595059515952595359545955595659575958595959605961596259635964596559665967596859695970597159725973597459755976597759785979598059815982598359845985598659875988598959905991599259935994599559965997599859996000600160026003600460056006600760086009601060116012601360146015601660176018601960206021602260236024602560266027602860296030603160326033603460356036603760386039604060416042604360446045604660476048604960506051605260536054605560566057605860596060606160626063606460656066606760686069607060716072607360746075607660776078607960806081608260836084608560866087608860896090609160926093609460956096609760986099610061016102610361046105610661076108610961106111611261136114611561166117611861196120612161226123612461256126612761286129613061316132613361346135613661376138613961406141614261436144614561466147614861496150615161526153615461556156615761586159616061616162616361646165616661676168616961706171617261736174617561766177617861796180618161826183618461856186618761886189619061916192619361946195619661976198619962006201620262036204620562066207620862096210621162126213621462156216621762186219622062216222622362246225622662276228622962306231623262336234623562366237623862396240624162426243624462456246624762486249625062516252625362546255625662576258625962606261626262636264626562666267626862696270627162726273627462756276627762786279628062816282628362846285628662876288628962906291629262936294629562966297629862996300630163026303630463056306630763086309631063116312631363146315631663176318631963206321632263236324632563266327632863296330633163326333633463356336633763386339634063416342634363446345634663476348634963506351635263536354635563566357635863596360636163626363636463656366636763686369637063716372637363746375637663776378637963806381638263836384638563866387638863896390639163926393639463956396639763986399640064016402640364046405640664076408640964106411641264136414641564166417641864196420642164226423642464256426642764286429643064316432643364346435643664376438643964406441644264436444644564466447644864496450645164526453645464556456645764586459646064616462646364646465646664676468646964706471647264736474647564766477647864796480648164826483648464856486648764886489649064916492649364946495649664976498649965006501650265036504650565066507650865096510651165126513651465156516651765186519652065216522652365246525652665276528652965306531653265336534653565366537653865396540654165426543654465456546654765486549655065516552655365546555655665576558655965606561656265636564656565666567656865696570657165726573657465756576657765786579658065816582658365846585658665876588658965906591659265936594659565966597659865996600660166026603660466056606660766086609661066116612661366146615661666176618661966206621662266236624662566266627662866296630663166326633663466356636663766386639664066416642664366446645664666476648664966506651665266536654665566566657665866596660666166626663666466656666666766686669667066716672667366746675667666776678667966806681668266836684668566866687668866896690669166926693669466956696669766986699670067016702670367046705670667076708670967106711671267136714671567166717671867196720672167226723672467256726672767286729673067316732673367346735673667376738673967406741674267436744674567466747674867496750675167526753675467556756675767586759676067616762676367646765676667676768676967706771677267736774677567766777677867796780678167826783678467856786678767886789679067916792679367946795679667976798679968006801680268036804680568066807680868096810681168126813681468156816681768186819682068216822682368246825682668276828682968306831683268336834683568366837683868396840684168426843684468456846684768486849685068516852685368546855685668576858685968606861686268636864686568666867686868696870687168726873687468756876687768786879688068816882688368846885688668876888688968906891689268936894689568966897689868996900690169026903690469056906690769086909691069116912691369146915691669176918691969206921692269236924692569266927692869296930693169326933693469356936693769386939694069416942694369446945694669476948694969506951695269536954695569566957695869596960696169626963696469656966696769686969697069716972697369746975697669776978697969806981698269836984698569866987698869896990699169926993699469956996699769986999700070017002700370047005700670077008700970107011701270137014701570167017701870197020702170227023702470257026702770287029703070317032703370347035703670377038703970407041704270437044704570467047704870497050705170527053705470557056705770587059706070617062706370647065706670677068706970707071707270737074707570767077707870797080708170827083708470857086708770887089709070917092709370947095709670977098709971007101710271037104710571067107710871097110711171127113711471157116711771187119712071217122712371247125712671277128712971307131713271337134713571367137713871397140714171427143714471457146714771487149715071517152715371547155715671577158715971607161716271637164716571667167716871697170717171727173717471757176717771787179718071817182718371847185718671877188718971907191719271937194719571967197719871997200720172027203720472057206720772087209721072117212721372147215721672177218721972207221722272237224722572267227722872297230723172327233723472357236723772387239724072417242724372447245724672477248724972507251725272537254725572567257725872597260726172627263726472657266726772687269727072717272727372747275727672777278727972807281728272837284728572867287728872897290729172927293729472957296729772987299730073017302730373047305730673077308730973107311731273137314731573167317731873197320732173227323732473257326732773287329733073317332733373347335733673377338733973407341734273437344734573467347734873497350735173527353735473557356735773587359736073617362736373647365736673677368736973707371737273737374737573767377737873797380738173827383738473857386738773887389739073917392739373947395739673977398739974007401740274037404740574067407740874097410741174127413741474157416741774187419742074217422742374247425742674277428742974307431743274337434743574367437743874397440744174427443744474457446744774487449745074517452745374547455745674577458745974607461746274637464746574667467746874697470747174727473747474757476747774787479748074817482748374847485748674877488748974907491749274937494749574967497749874997500750175027503750475057506750775087509751075117512751375147515751675177518751975207521752275237524752575267527752875297530753175327533753475357536753775387539754075417542754375447545754675477548754975507551755275537554755575567557755875597560756175627563756475657566756775687569757075717572757375747575757675777578757975807581758275837584758575867587758875897590759175927593759475957596759775987599760076017602760376047605760676077608760976107611761276137614761576167617761876197620762176227623762476257626762776287629763076317632763376347635763676377638763976407641764276437644764576467647764876497650765176527653765476557656765776587659766076617662766376647665766676677668766976707671767276737674767576767677767876797680768176827683768476857686768776887689769076917692769376947695769676977698769977007701770277037704770577067707770877097710771177127713771477157716771777187719772077217722772377247725772677277728772977307731773277337734773577367737773877397740774177427743774477457746774777487749775077517752775377547755775677577758775977607761776277637764776577667767776877697770777177727773777477757776777777787779778077817782778377847785778677877788778977907791779277937794779577967797779877997800780178027803780478057806780778087809781078117812781378147815781678177818781978207821782278237824782578267827782878297830783178327833783478357836783778387839784078417842784378447845784678477848784978507851785278537854785578567857785878597860786178627863786478657866786778687869787078717872787378747875787678777878787978807881788278837884788578867887788878897890789178927893789478957896789778987899790079017902790379047905790679077908790979107911791279137914791579167917791879197920792179227923792479257926792779287929793079317932793379347935793679377938793979407941794279437944794579467947794879497950795179527953795479557956795779587959796079617962796379647965796679677968796979707971797279737974797579767977797879797980798179827983798479857986798779887989799079917992799379947995799679977998799980008001800280038004800580068007800880098010801180128013801480158016801780188019802080218022802380248025802680278028802980308031803280338034803580368037803880398040804180428043804480458046804780488049805080518052805380548055805680578058805980608061806280638064806580668067806880698070807180728073807480758076807780788079808080818082808380848085808680878088808980908091809280938094809580968097809880998100810181028103810481058106810781088109811081118112811381148115811681178118811981208121812281238124812581268127812881298130813181328133813481358136813781388139814081418142814381448145814681478148814981508151815281538154815581568157815881598160816181628163816481658166816781688169817081718172817381748175817681778178817981808181818281838184818581868187818881898190819181928193819481958196819781988199820082018202820382048205820682078208820982108211821282138214821582168217821882198220822182228223822482258226822782288229823082318232823382348235823682378238823982408241824282438244824582468247824882498250825182528253825482558256825782588259826082618262826382648265826682678268826982708271827282738274827582768277827882798280828182828283828482858286828782888289829082918292829382948295829682978298829983008301830283038304830583068307830883098310831183128313831483158316831783188319832083218322832383248325832683278328832983308331833283338334833583368337833883398340834183428343834483458346834783488349835083518352835383548355835683578358835983608361836283638364836583668367836883698370837183728373837483758376837783788379838083818382838383848385838683878388838983908391839283938394839583968397839883998400840184028403840484058406840784088409841084118412841384148415841684178418841984208421842284238424842584268427842884298430843184328433843484358436843784388439844084418442844384448445844684478448844984508451845284538454845584568457845884598460846184628463846484658466846784688469847084718472847384748475847684778478847984808481848284838484848584868487848884898490849184928493849484958496849784988499850085018502850385048505850685078508850985108511851285138514851585168517851885198520852185228523852485258526852785288529853085318532853385348535853685378538853985408541854285438544854585468547854885498550855185528553855485558556855785588559856085618562856385648565856685678568856985708571857285738574857585768577857885798580858185828583858485858586858785888589859085918592859385948595859685978598859986008601860286038604860586068607860886098610861186128613861486158616861786188619862086218622862386248625862686278628862986308631863286338634863586368637863886398640864186428643864486458646864786488649865086518652865386548655865686578658865986608661866286638664866586668667866886698670867186728673867486758676867786788679868086818682868386848685868686878688868986908691869286938694869586968697869886998700870187028703870487058706870787088709871087118712871387148715871687178718871987208721872287238724872587268727872887298730873187328733873487358736873787388739874087418742874387448745874687478748874987508751875287538754875587568757875887598760876187628763876487658766876787688769877087718772877387748775877687778778877987808781878287838784878587868787878887898790879187928793879487958796879787988799880088018802880388048805880688078808880988108811881288138814881588168817881888198820882188228823882488258826882788288829883088318832883388348835883688378838883988408841884288438844884588468847884888498850885188528853885488558856885788588859886088618862886388648865886688678868886988708871887288738874887588768877887888798880888188828883888488858886888788888889889088918892889388948895889688978898889989008901890289038904890589068907890889098910891189128913891489158916891789188919892089218922892389248925892689278928892989308931893289338934893589368937893889398940894189428943894489458946894789488949895089518952895389548955895689578958895989608961896289638964896589668967896889698970897189728973897489758976897789788979898089818982898389848985898689878988898989908991899289938994899589968997899889999000900190029003900490059006900790089009901090119012901390149015901690179018901990209021902290239024902590269027902890299030903190329033903490359036903790389039904090419042904390449045904690479048904990509051905290539054905590569057905890599060906190629063906490659066906790689069907090719072907390749075907690779078907990809081908290839084908590869087908890899090909190929093909490959096909790989099910091019102910391049105910691079108910991109111911291139114911591169117911891199120912191229123912491259126912791289129913091319132913391349135913691379138913991409141914291439144914591469147914891499150915191529153915491559156915791589159916091619162916391649165916691679168916991709171917291739174917591769177917891799180918191829183918491859186918791889189919091919192919391949195919691979198919992009201920292039204920592069207920892099210921192129213921492159216921792189219922092219222922392249225922692279228922992309231923292339234923592369237923892399240924192429243924492459246924792489249925092519252925392549255925692579258925992609261926292639264926592669267926892699270927192729273927492759276927792789279928092819282928392849285928692879288928992909291929292939294929592969297929892999300930193029303930493059306930793089309931093119312931393149315931693179318931993209321932293239324932593269327932893299330933193329333933493359336933793389339934093419342934393449345934693479348934993509351935293539354935593569357935893599360936193629363936493659366936793689369937093719372937393749375937693779378937993809381938293839384938593869387938893899390939193929393939493959396939793989399940094019402940394049405940694079408940994109411941294139414941594169417941894199420942194229423942494259426942794289429943094319432943394349435943694379438943994409441944294439444944594469447944894499450945194529453945494559456945794589459946094619462946394649465946694679468946994709471947294739474947594769477947894799480948194829483948494859486948794889489949094919492949394949495949694979498949995009501950295039504950595069507950895099510951195129513951495159516951795189519952095219522952395249525952695279528952995309531953295339534953595369537953895399540954195429543954495459546954795489549955095519552955395549555955695579558955995609561956295639564956595669567956895699570957195729573957495759576957795789579958095819582958395849585958695879588958995909591959295939594959595969597959895999600960196029603960496059606960796089609961096119612961396149615961696179618961996209621962296239624962596269627962896299630963196329633963496359636963796389639964096419642964396449645964696479648964996509651965296539654965596569657965896599660966196629663966496659666966796689669967096719672967396749675967696779678967996809681968296839684968596869687968896899690969196929693969496959696969796989699970097019702970397049705970697079708970997109711971297139714971597169717971897199720972197229723972497259726972797289729973097319732973397349735973697379738973997409741974297439744974597469747974897499750975197529753975497559756975797589759976097619762976397649765976697679768976997709771977297739774977597769777977897799780978197829783978497859786978797889789979097919792979397949795979697979798979998009801980298039804980598069807980898099810981198129813981498159816981798189819982098219822982398249825982698279828982998309831983298339834983598369837983898399840984198429843984498459846984798489849985098519852985398549855985698579858985998609861986298639864986598669867986898699870987198729873987498759876987798789879988098819882988398849885988698879888988998909891989298939894989598969897989898999900990199029903990499059906990799089909991099119912991399149915991699179918991999209921992299239924992599269927992899299930993199329933993499359936993799389939994099419942994399449945994699479948994999509951995299539954995599569957995899599960996199629963996499659966996799689969997099719972997399749975997699779978997999809981998299839984998599869987998899899990999199929993999499959996999799989999100001000110002100031000410005100061000710008100091001010011100121001310014100151001610017100181001910020100211002210023100241002510026100271002810029100301003110032100331003410035100361003710038100391004010041100421004310044100451004610047100481004910050100511005210053100541005510056100571005810059100601006110062100631006410065100661006710068100691007010071100721007310074100751007610077100781007910080100811008210083100841008510086100871008810089100901009110092100931009410095100961009710098100991010010101101021010310104101051010610107101081010910110101111011210113101141011510116101171011810119101201012110122101231012410125101261012710128101291013010131101321013310134101351013610137101381013910140101411014210143101441014510146101471014810149101501015110152101531015410155101561015710158101591016010161101621016310164101651016610167101681016910170101711017210173101741017510176101771017810179101801018110182101831018410185101861018710188101891019010191101921019310194101951019610197101981019910200102011020210203102041020510206102071020810209102101021110212102131021410215102161021710218102191022010221102221022310224102251022610227102281022910230102311023210233102341023510236102371023810239102401024110242102431024410245102461024710248102491025010251102521025310254102551025610257102581025910260102611026210263102641026510266102671026810269102701027110272102731027410275102761027710278102791028010281102821028310284102851028610287102881028910290102911029210293102941029510296102971029810299103001030110302103031030410305103061030710308103091031010311103121031310314103151031610317103181031910320103211032210323103241032510326103271032810329103301033110332103331033410335103361033710338103391034010341103421034310344103451034610347103481034910350103511035210353103541035510356103571035810359103601036110362103631036410365103661036710368103691037010371103721037310374103751037610377103781037910380103811038210383103841038510386103871038810389103901039110392103931039410395103961039710398103991040010401104021040310404104051040610407104081040910410104111041210413104141041510416104171041810419104201042110422104231042410425104261042710428104291043010431104321043310434104351043610437104381043910440104411044210443104441044510446104471044810449104501045110452104531045410455104561045710458104591046010461104621046310464104651046610467104681046910470104711047210473104741047510476104771047810479104801048110482104831048410485104861048710488104891049010491104921049310494104951049610497104981049910500105011050210503105041050510506105071050810509105101051110512105131051410515105161051710518105191052010521105221052310524105251052610527105281052910530105311053210533105341053510536105371053810539105401054110542105431054410545105461054710548105491055010551105521055310554105551055610557105581055910560105611056210563105641056510566105671056810569105701057110572105731057410575105761057710578105791058010581105821058310584105851058610587105881058910590105911059210593105941059510596105971059810599106001060110602106031060410605106061060710608106091061010611106121061310614106151061610617106181061910620106211062210623106241062510626106271062810629106301063110632106331063410635106361063710638106391064010641106421064310644106451064610647106481064910650106511065210653106541065510656106571065810659106601066110662106631066410665106661066710668106691067010671106721067310674106751067610677106781067910680106811068210683106841068510686106871068810689106901069110692106931069410695106961069710698106991070010701107021070310704107051070610707107081070910710107111071210713107141071510716107171071810719107201072110722107231072410725107261072710728107291073010731107321073310734107351073610737107381073910740107411074210743107441074510746107471074810749107501075110752107531075410755107561075710758107591076010761107621076310764107651076610767107681076910770107711077210773107741077510776107771077810779107801078110782107831078410785107861078710788107891079010791107921079310794107951079610797107981079910800108011080210803108041080510806108071080810809108101081110812108131081410815108161081710818108191082010821108221082310824108251082610827108281082910830108311083210833108341083510836108371083810839108401084110842108431084410845108461084710848108491085010851108521085310854108551085610857108581085910860108611086210863108641086510866108671086810869108701087110872108731087410875108761087710878108791088010881108821088310884108851088610887108881088910890108911089210893108941089510896108971089810899109001090110902109031090410905109061090710908109091091010911109121091310914109151091610917109181091910920109211092210923109241092510926109271092810929109301093110932109331093410935109361093710938109391094010941109421094310944109451094610947109481094910950109511095210953109541095510956109571095810959109601096110962109631096410965109661096710968109691097010971109721097310974109751097610977109781097910980109811098210983109841098510986109871098810989109901099110992109931099410995109961099710998109991100011001110021100311004110051100611007110081100911010110111101211013110141101511016110171101811019110201102111022110231102411025110261102711028110291103011031110321103311034110351103611037110381103911040110411104211043110441104511046110471104811049110501105111052110531105411055110561105711058110591106011061110621106311064110651106611067110681106911070110711107211073110741107511076110771107811079110801108111082110831108411085110861108711088110891109011091110921109311094110951109611097110981109911100111011110211103111041110511106111071110811109111101111111112111131111411115111161111711118111191112011121111221112311124111251112611127111281112911130111311113211133111341113511136111371113811139111401114111142111431114411145111461114711148111491115011151111521115311154111551115611157111581115911160111611116211163111641116511166111671116811169111701117111172111731117411175111761117711178111791118011181111821118311184111851118611187111881118911190111911119211193111941119511196111971119811199112001120111202112031120411205112061120711208112091121011211112121121311214112151121611217112181121911220112211122211223112241122511226112271122811229112301123111232112331123411235112361123711238112391124011241112421124311244112451124611247112481124911250112511125211253112541125511256112571125811259112601126111262112631126411265112661126711268112691127011271112721127311274112751127611277112781127911280112811128211283112841128511286112871128811289112901129111292112931129411295112961129711298112991130011301113021130311304113051130611307113081130911310113111131211313113141131511316113171131811319113201132111322113231132411325113261132711328113291133011331113321133311334113351133611337113381133911340113411134211343113441134511346113471134811349113501135111352113531135411355113561135711358113591136011361113621136311364113651136611367113681136911370113711137211373113741137511376113771137811379113801138111382113831138411385113861138711388113891139011391113921139311394113951139611397113981139911400114011140211403114041140511406114071140811409114101141111412114131141411415114161141711418114191142011421114221142311424114251142611427114281142911430114311143211433114341143511436114371143811439114401144111442114431144411445114461144711448114491145011451114521145311454114551145611457114581145911460114611146211463114641146511466114671146811469114701147111472114731147411475114761147711478114791148011481114821148311484114851148611487114881148911490114911149211493114941149511496114971149811499115001150111502115031150411505115061150711508115091151011511115121151311514115151151611517115181151911520115211152211523115241152511526115271152811529115301153111532115331153411535115361153711538115391154011541115421154311544115451154611547115481154911550115511155211553115541155511556115571155811559115601156111562115631156411565115661156711568115691157011571115721157311574115751157611577115781157911580115811158211583115841158511586115871158811589115901159111592115931159411595115961159711598115991160011601116021160311604116051160611607116081160911610116111161211613116141161511616116171161811619116201162111622116231162411625116261162711628116291163011631116321163311634116351163611637116381163911640116411164211643116441164511646116471164811649116501165111652116531165411655116561165711658116591166011661116621166311664116651166611667116681166911670116711167211673116741167511676116771167811679116801168111682116831168411685116861168711688116891169011691116921169311694116951169611697116981169911700117011170211703117041170511706117071170811709117101171111712117131171411715117161171711718117191172011721117221172311724117251172611727117281172911730117311173211733117341173511736117371173811739117401174111742117431174411745117461174711748117491175011751117521175311754117551175611757117581175911760117611176211763117641176511766117671176811769117701177111772117731177411775117761177711778117791178011781117821178311784117851178611787117881178911790117911179211793117941179511796117971179811799118001180111802118031180411805118061180711808118091181011811118121181311814118151181611817118181181911820118211182211823118241182511826118271182811829118301183111832118331183411835118361183711838118391184011841118421184311844118451184611847118481184911850118511185211853118541185511856118571185811859118601186111862118631186411865118661186711868118691187011871118721187311874118751187611877118781187911880118811188211883118841188511886118871188811889118901189111892118931189411895118961189711898118991190011901119021190311904119051190611907119081190911910119111191211913119141191511916119171191811919119201192111922119231192411925119261192711928119291193011931119321193311934119351193611937119381193911940119411194211943119441194511946119471194811949119501195111952119531195411955119561195711958119591196011961119621196311964119651196611967119681196911970119711197211973119741197511976119771197811979119801198111982119831198411985119861198711988119891199011991119921199311994119951199611997119981199912000120011200212003120041200512006120071200812009120101201112012120131201412015120161201712018120191202012021120221202312024120251202612027120281202912030120311203212033120341203512036120371203812039120401204112042120431204412045120461204712048120491205012051120521205312054120551205612057120581205912060120611206212063120641206512066120671206812069120701207112072120731207412075120761207712078120791208012081120821208312084120851208612087120881208912090120911209212093120941209512096120971209812099121001210112102121031210412105121061210712108121091211012111121121211312114121151211612117121181211912120121211212212123121241212512126121271212812129121301213112132121331213412135121361213712138121391214012141121421214312144121451214612147121481214912150121511215212153121541215512156121571215812159121601216112162121631216412165121661216712168121691217012171121721217312174121751217612177121781217912180121811218212183121841218512186121871218812189121901219112192121931219412195121961219712198121991220012201122021220312204122051220612207122081220912210122111221212213122141221512216122171221812219122201222112222122231222412225122261222712228122291223012231122321223312234122351223612237122381223912240122411224212243122441224512246122471224812249122501225112252122531225412255122561225712258122591226012261122621226312264122651226612267122681226912270122711227212273122741227512276122771227812279122801228112282122831228412285122861228712288122891229012291122921229312294122951229612297122981229912300123011230212303123041230512306123071230812309123101231112312123131231412315123161231712318123191232012321123221232312324123251232612327123281232912330123311233212333123341233512336123371233812339123401234112342123431234412345123461234712348123491235012351123521235312354123551235612357123581235912360123611236212363123641236512366123671236812369123701237112372123731237412375123761237712378123791238012381123821238312384123851238612387123881238912390123911239212393123941239512396123971239812399124001240112402124031240412405124061240712408124091241012411124121241312414124151241612417124181241912420124211242212423124241242512426124271242812429124301243112432124331243412435124361243712438124391244012441124421244312444124451244612447124481244912450124511245212453124541245512456124571245812459124601246112462124631246412465124661246712468124691247012471124721247312474124751247612477124781247912480124811248212483124841248512486124871248812489124901249112492124931249412495124961249712498124991250012501125021250312504125051250612507125081250912510125111251212513125141251512516125171251812519125201252112522125231252412525125261252712528125291253012531125321253312534125351253612537125381253912540125411254212543125441254512546125471254812549125501255112552125531255412555125561255712558125591256012561125621256312564125651256612567125681256912570125711257212573125741257512576125771257812579125801258112582125831258412585125861258712588125891259012591125921259312594125951259612597125981259912600126011260212603126041260512606126071260812609126101261112612126131261412615126161261712618126191262012621126221262312624126251262612627126281262912630126311263212633126341263512636126371263812639126401264112642126431264412645126461264712648126491265012651126521265312654126551265612657126581265912660126611266212663126641266512666126671266812669126701267112672126731267412675126761267712678126791268012681126821268312684126851268612687126881268912690126911269212693126941269512696126971269812699127001270112702127031270412705127061270712708127091271012711127121271312714127151271612717127181271912720127211272212723127241272512726127271272812729127301273112732127331273412735127361273712738127391274012741127421274312744127451274612747127481274912750127511275212753127541275512756127571275812759127601276112762127631276412765127661276712768127691277012771127721277312774127751277612777127781277912780127811278212783127841278512786127871278812789127901279112792127931279412795127961279712798127991280012801128021280312804128051280612807128081280912810128111281212813128141281512816128171281812819128201282112822128231282412825128261282712828128291283012831128321283312834128351283612837128381283912840128411284212843128441284512846128471284812849128501285112852128531285412855128561285712858128591286012861128621286312864128651286612867128681286912870128711287212873128741287512876128771287812879128801288112882128831288412885128861288712888128891289012891128921289312894128951289612897128981289912900129011290212903129041290512906129071290812909129101291112912129131291412915129161291712918129191292012921129221292312924129251292612927129281292912930129311293212933129341293512936129371293812939129401294112942129431294412945129461294712948129491295012951129521295312954129551295612957129581295912960129611296212963129641296512966129671296812969129701297112972129731297412975129761297712978129791298012981129821298312984129851298612987129881298912990129911299212993129941299512996129971299812999130001300113002130031300413005130061300713008130091301013011130121301313014130151301613017130181301913020130211302213023130241302513026130271302813029130301303113032130331303413035130361303713038130391304013041130421304313044130451304613047130481304913050130511305213053130541305513056130571305813059130601306113062130631306413065130661306713068130691307013071130721307313074130751307613077130781307913080130811308213083130841308513086130871308813089130901309113092130931309413095130961309713098130991310013101131021310313104131051310613107131081310913110131111311213113131141311513116131171311813119131201312113122131231312413125131261312713128131291313013131131321313313134131351313613137131381313913140131411314213143131441314513146131471314813149131501315113152131531315413155131561315713158131591316013161131621316313164131651316613167131681316913170131711317213173131741317513176131771317813179131801318113182131831318413185131861318713188131891319013191131921319313194131951319613197131981319913200132011320213203132041320513206132071320813209132101321113212132131321413215132161321713218132191322013221132221322313224132251322613227132281322913230132311323213233132341323513236132371323813239132401324113242132431324413245132461324713248132491325013251132521325313254132551325613257132581325913260132611326213263132641326513266132671326813269132701327113272132731327413275132761327713278132791328013281132821328313284132851328613287132881328913290132911329213293132941329513296132971329813299133001330113302133031330413305133061330713308133091331013311133121331313314133151331613317133181331913320133211332213323133241332513326133271332813329133301333113332133331333413335133361333713338133391334013341133421334313344133451334613347133481334913350133511335213353133541335513356133571335813359133601336113362133631336413365133661336713368133691337013371133721337313374133751337613377133781337913380133811338213383133841338513386133871338813389133901339113392133931339413395133961339713398133991340013401134021340313404134051340613407134081340913410134111341213413134141341513416134171341813419134201342113422134231342413425134261342713428134291343013431134321343313434134351343613437134381343913440134411344213443134441344513446134471344813449134501345113452134531345413455134561345713458134591346013461134621346313464134651346613467134681346913470134711347213473134741347513476134771347813479134801348113482134831348413485134861348713488134891349013491134921349313494134951349613497134981349913500135011350213503135041350513506135071350813509135101351113512135131351413515135161351713518135191352013521135221352313524135251352613527135281352913530135311353213533135341353513536135371353813539135401354113542135431354413545135461354713548135491355013551135521355313554135551355613557135581355913560135611356213563135641356513566135671356813569135701357113572135731357413575135761357713578135791358013581135821358313584135851358613587135881358913590135911359213593135941359513596135971359813599136001360113602136031360413605136061360713608136091361013611136121361313614136151361613617136181361913620136211362213623136241362513626136271362813629136301363113632136331363413635136361363713638136391364013641136421364313644136451364613647136481364913650136511365213653136541365513656136571365813659136601366113662136631366413665136661366713668136691367013671136721367313674136751367613677136781367913680136811368213683136841368513686136871368813689136901369113692136931369413695136961369713698136991370013701137021370313704137051370613707137081370913710137111371213713137141371513716137171371813719137201372113722137231372413725137261372713728137291373013731137321373313734137351373613737137381373913740137411374213743137441374513746137471374813749137501375113752137531375413755137561375713758137591376013761137621376313764137651376613767137681376913770137711377213773137741377513776137771377813779137801378113782137831378413785137861378713788137891379013791137921379313794137951379613797137981379913800138011380213803138041380513806138071380813809138101381113812138131381413815138161381713818138191382013821138221382313824138251382613827138281382913830138311383213833138341383513836138371383813839138401384113842138431384413845138461384713848138491385013851138521385313854138551385613857138581385913860138611386213863138641386513866138671386813869138701387113872138731387413875138761387713878138791388013881138821388313884138851388613887138881388913890138911389213893138941389513896138971389813899139001390113902139031390413905139061390713908139091391013911139121391313914139151391613917139181391913920139211392213923139241392513926139271392813929139301393113932139331393413935139361393713938139391394013941139421394313944139451394613947139481394913950139511395213953139541395513956139571395813959139601396113962139631396413965139661396713968139691397013971139721397313974139751397613977139781397913980139811398213983139841398513986139871398813989139901399113992139931399413995139961399713998139991400014001140021400314004140051400614007140081400914010140111401214013140141401514016140171401814019140201402114022140231402414025140261402714028140291403014031140321403314034140351403614037140381403914040140411404214043140441404514046140471404814049140501405114052140531405414055140561405714058140591406014061140621406314064140651406614067140681406914070140711407214073140741407514076140771407814079140801408114082140831408414085140861408714088140891409014091140921409314094140951409614097140981409914100141011410214103141041410514106141071410814109141101411114112141131411414115141161411714118141191412014121141221412314124141251412614127141281412914130141311413214133141341413514136141371413814139141401414114142141431414414145141461414714148141491415014151141521415314154141551415614157141581415914160141611416214163141641416514166141671416814169141701417114172141731417414175141761417714178141791418014181141821418314184141851418614187141881418914190141911419214193141941419514196141971419814199142001420114202142031420414205142061420714208142091421014211142121421314214142151421614217142181421914220142211422214223142241422514226142271422814229142301423114232142331423414235142361423714238142391424014241142421424314244142451424614247142481424914250142511425214253142541425514256142571425814259142601426114262142631426414265142661426714268142691427014271142721427314274142751427614277142781427914280142811428214283142841428514286142871428814289142901429114292142931429414295142961429714298142991430014301143021430314304143051430614307143081430914310143111431214313143141431514316143171431814319143201432114322143231432414325143261432714328143291433014331143321433314334143351433614337143381433914340143411434214343143441434514346143471434814349143501435114352143531435414355143561435714358143591436014361143621436314364143651436614367143681436914370143711437214373143741437514376143771437814379143801438114382143831438414385143861438714388143891439014391143921439314394143951439614397143981439914400144011440214403144041440514406144071440814409144101441114412144131441414415144161441714418144191442014421144221442314424144251442614427144281442914430144311443214433144341443514436144371443814439144401444114442144431444414445144461444714448144491445014451144521445314454144551445614457144581445914460144611446214463144641446514466144671446814469144701447114472144731447414475144761447714478144791448014481144821448314484144851448614487144881448914490144911449214493144941449514496144971449814499145001450114502145031450414505145061450714508145091451014511145121451314514145151451614517145181451914520145211452214523145241452514526145271452814529145301453114532145331453414535145361453714538145391454014541145421454314544145451454614547145481454914550145511455214553145541455514556145571455814559145601456114562145631456414565145661456714568145691457014571145721457314574145751457614577145781457914580145811458214583145841458514586145871458814589145901459114592145931459414595145961459714598145991460014601146021460314604146051460614607146081460914610146111461214613146141461514616146171461814619146201462114622146231462414625146261462714628146291463014631146321463314634146351463614637146381463914640146411464214643146441464514646146471464814649146501465114652146531465414655146561465714658146591466014661146621466314664146651466614667146681466914670146711467214673146741467514676146771467814679146801468114682146831468414685146861468714688146891469014691146921469314694146951469614697146981469914700147011470214703147041470514706147071470814709147101471114712147131471414715147161471714718147191472014721147221472314724147251472614727147281472914730147311473214733147341473514736147371473814739147401474114742147431474414745147461474714748147491475014751147521475314754147551475614757147581475914760147611476214763147641476514766147671476814769147701477114772147731477414775147761477714778147791478014781147821478314784147851478614787147881478914790147911479214793147941479514796147971479814799148001480114802148031480414805148061480714808148091481014811148121481314814148151481614817148181481914820148211482214823148241482514826148271482814829148301483114832148331483414835148361483714838148391484014841148421484314844148451484614847148481484914850148511485214853148541485514856148571485814859148601486114862148631486414865148661486714868148691487014871148721487314874148751487614877148781487914880148811488214883148841488514886148871488814889148901489114892148931489414895148961489714898148991490014901149021490314904149051490614907149081490914910149111491214913149141491514916149171491814919149201492114922149231492414925149261492714928149291493014931149321493314934149351493614937149381493914940149411494214943149441494514946149471494814949149501495114952149531495414955149561495714958149591496014961149621496314964149651496614967149681496914970149711497214973149741497514976149771497814979149801498114982149831498414985149861498714988149891499014991149921499314994149951499614997149981499915000150011500215003150041500515006150071500815009150101501115012150131501415015150161501715018150191502015021150221502315024150251502615027150281502915030150311503215033150341503515036150371503815039150401504115042150431504415045150461504715048150491505015051150521505315054150551505615057150581505915060150611506215063150641506515066150671506815069150701507115072150731507415075150761507715078150791508015081150821508315084150851508615087150881508915090150911509215093150941509515096150971509815099151001510115102151031510415105151061510715108151091511015111151121511315114151151511615117151181511915120151211512215123151241512515126151271512815129151301513115132151331513415135151361513715138151391514015141151421514315144151451514615147151481514915150151511515215153151541515515156151571515815159151601516115162151631516415165151661516715168151691517015171151721517315174151751517615177151781517915180151811518215183151841518515186151871518815189151901519115192151931519415195151961519715198151991520015201152021520315204152051520615207152081520915210152111521215213152141521515216152171521815219152201522115222152231522415225152261522715228152291523015231152321523315234152351523615237152381523915240152411524215243152441524515246152471524815249152501525115252152531525415255152561525715258152591526015261152621526315264152651526615267152681526915270152711527215273152741527515276152771527815279152801528115282152831528415285152861528715288152891529015291152921529315294152951529615297152981529915300153011530215303153041530515306153071530815309153101531115312153131531415315153161531715318153191532015321153221532315324153251532615327153281532915330153311533215333153341533515336153371533815339153401534115342153431534415345153461534715348153491535015351153521535315354153551535615357153581535915360153611536215363153641536515366153671536815369153701537115372153731537415375153761537715378153791538015381153821538315384153851538615387153881538915390153911539215393153941539515396153971539815399154001540115402154031540415405154061540715408154091541015411154121541315414154151541615417154181541915420154211542215423154241542515426154271542815429154301543115432154331543415435154361543715438154391544015441154421544315444154451544615447154481544915450154511545215453154541545515456154571545815459154601546115462154631546415465154661546715468154691547015471154721547315474154751547615477154781547915480154811548215483154841548515486154871548815489154901549115492154931549415495154961549715498154991550015501155021550315504155051550615507155081550915510155111551215513155141551515516155171551815519155201552115522155231552415525155261552715528155291553015531155321553315534155351553615537155381553915540155411554215543155441554515546155471554815549155501555115552155531555415555155561555715558155591556015561155621556315564155651556615567155681556915570155711557215573155741557515576155771557815579155801558115582155831558415585155861558715588155891559015591155921559315594155951559615597155981559915600156011560215603156041560515606156071560815609156101561115612156131561415615156161561715618156191562015621156221562315624156251562615627156281562915630156311563215633156341563515636156371563815639156401564115642156431564415645156461564715648156491565015651156521565315654156551565615657156581565915660156611566215663156641566515666156671566815669156701567115672156731567415675156761567715678156791568015681156821568315684156851568615687156881568915690156911569215693156941569515696156971569815699157001570115702157031570415705157061570715708157091571015711157121571315714157151571615717157181571915720157211572215723157241572515726157271572815729157301573115732157331573415735157361573715738157391574015741157421574315744157451574615747157481574915750157511575215753157541575515756157571575815759157601576115762157631576415765157661576715768157691577015771157721577315774157751577615777157781577915780157811578215783157841578515786157871578815789157901579115792157931579415795157961579715798157991580015801158021580315804158051580615807158081580915810158111581215813158141581515816158171581815819158201582115822158231582415825158261582715828158291583015831158321583315834158351583615837158381583915840158411584215843158441584515846158471584815849158501585115852158531585415855158561585715858158591586015861158621586315864158651586615867158681586915870158711587215873158741587515876158771587815879158801588115882158831588415885158861588715888158891589015891158921589315894158951589615897158981589915900159011590215903159041590515906159071590815909159101591115912159131591415915159161591715918159191592015921159221592315924159251592615927159281592915930159311593215933159341593515936159371593815939159401594115942159431594415945159461594715948159491595015951159521595315954159551595615957159581595915960159611596215963159641596515966159671596815969159701597115972159731597415975159761597715978159791598015981159821598315984159851598615987159881598915990159911599215993159941599515996159971599815999160001600116002160031600416005160061600716008160091601016011160121601316014160151601616017160181601916020160211602216023160241602516026160271602816029160301603116032160331603416035160361603716038160391604016041160421604316044160451604616047160481604916050160511605216053160541605516056160571605816059160601606116062160631606416065160661606716068160691607016071160721607316074160751607616077160781607916080160811608216083160841608516086160871608816089160901609116092160931609416095160961609716098160991610016101161021610316104161051610616107161081610916110161111611216113161141611516116161171611816119161201612116122161231612416125161261612716128161291613016131161321613316134161351613616137161381613916140161411614216143161441614516146161471614816149161501615116152161531615416155161561615716158161591616016161161621616316164161651616616167161681616916170161711617216173161741617516176161771617816179161801618116182161831618416185161861618716188161891619016191161921619316194161951619616197161981619916200162011620216203162041620516206162071620816209162101621116212162131621416215162161621716218162191622016221162221622316224162251622616227162281622916230162311623216233162341623516236162371623816239162401624116242162431624416245162461624716248162491625016251162521625316254162551625616257162581625916260162611626216263162641626516266162671626816269162701627116272162731627416275162761627716278162791628016281162821628316284162851628616287162881628916290162911629216293162941629516296162971629816299163001630116302163031630416305163061630716308163091631016311163121631316314163151631616317163181631916320163211632216323163241632516326163271632816329163301633116332163331633416335163361633716338163391634016341163421634316344163451634616347163481634916350163511635216353163541635516356163571635816359163601636116362163631636416365163661636716368163691637016371163721637316374163751637616377163781637916380163811638216383163841638516386163871638816389163901639116392163931639416395163961639716398163991640016401164021640316404164051640616407164081640916410164111641216413164141641516416164171641816419164201642116422164231642416425164261642716428164291643016431164321643316434164351643616437164381643916440164411644216443164441644516446164471644816449164501645116452164531645416455164561645716458164591646016461164621646316464164651646616467164681646916470164711647216473164741647516476164771647816479164801648116482164831648416485164861648716488164891649016491164921649316494164951649616497164981649916500165011650216503165041650516506165071650816509165101651116512165131651416515165161651716518165191652016521165221652316524165251652616527165281652916530165311653216533165341653516536165371653816539165401654116542165431654416545165461654716548165491655016551165521655316554165551655616557165581655916560165611656216563165641656516566165671656816569165701657116572165731657416575165761657716578165791658016581165821658316584165851658616587165881658916590165911659216593165941659516596165971659816599166001660116602166031660416605166061660716608166091661016611166121661316614166151661616617166181661916620166211662216623166241662516626166271662816629166301663116632166331663416635166361663716638166391664016641166421664316644166451664616647166481664916650166511665216653166541665516656166571665816659166601666116662166631666416665166661666716668166691667016671166721667316674166751667616677166781667916680166811668216683166841668516686166871668816689166901669116692166931669416695166961669716698166991670016701167021670316704167051670616707167081670916710167111671216713167141671516716167171671816719167201672116722167231672416725167261672716728167291673016731167321673316734167351673616737167381673916740167411674216743167441674516746167471674816749167501675116752167531675416755167561675716758167591676016761167621676316764167651676616767167681676916770167711677216773167741677516776167771677816779167801678116782167831678416785167861678716788167891679016791167921679316794167951679616797167981679916800168011680216803168041680516806168071680816809168101681116812168131681416815168161681716818168191682016821168221682316824168251682616827168281682916830168311683216833168341683516836168371683816839168401684116842168431684416845168461684716848168491685016851168521685316854168551685616857168581685916860168611686216863168641686516866168671686816869168701687116872168731687416875168761687716878168791688016881168821688316884168851688616887168881688916890168911689216893168941689516896168971689816899169001690116902169031690416905169061690716908169091691016911169121691316914169151691616917169181691916920169211692216923169241692516926169271692816929169301693116932169331693416935169361693716938169391694016941169421694316944169451694616947169481694916950169511695216953169541695516956169571695816959169601696116962169631696416965169661696716968169691697016971169721697316974169751697616977169781697916980169811698216983169841698516986169871698816989169901699116992169931699416995169961699716998169991700017001170021700317004170051700617007170081700917010170111701217013170141701517016170171701817019170201702117022170231702417025170261702717028170291703017031170321703317034170351703617037170381703917040170411704217043170441704517046170471704817049170501705117052170531705417055170561705717058170591706017061170621706317064170651706617067170681706917070170711707217073170741707517076170771707817079170801708117082170831708417085170861708717088170891709017091170921709317094170951709617097170981709917100171011710217103171041710517106171071710817109171101711117112171131711417115171161711717118171191712017121171221712317124171251712617127171281712917130171311713217133171341713517136171371713817139171401714117142171431714417145171461714717148171491715017151171521715317154171551715617157171581715917160171611716217163171641716517166171671716817169171701717117172171731717417175171761717717178171791718017181171821718317184171851718617187171881718917190171911719217193171941719517196171971719817199172001720117202172031720417205172061720717208172091721017211172121721317214172151721617217172181721917220172211722217223172241722517226172271722817229172301723117232172331723417235172361723717238172391724017241172421724317244172451724617247172481724917250172511725217253172541725517256172571725817259172601726117262172631726417265172661726717268172691727017271172721727317274172751727617277172781727917280172811728217283172841728517286172871728817289172901729117292172931729417295172961729717298172991730017301173021730317304173051730617307173081730917310173111731217313173141731517316173171731817319173201732117322173231732417325173261732717328173291733017331173321733317334173351733617337173381733917340173411734217343173441734517346173471734817349173501735117352173531735417355173561735717358173591736017361173621736317364173651736617367173681736917370173711737217373173741737517376173771737817379173801738117382173831738417385173861738717388173891739017391173921739317394173951739617397173981739917400174011740217403174041740517406174071740817409174101741117412174131741417415174161741717418174191742017421174221742317424174251742617427174281742917430174311743217433174341743517436174371743817439174401744117442174431744417445174461744717448174491745017451174521745317454174551745617457174581745917460174611746217463174641746517466174671746817469174701747117472174731747417475174761747717478174791748017481174821748317484174851748617487174881748917490174911749217493174941749517496174971749817499175001750117502175031750417505175061750717508175091751017511175121751317514175151751617517175181751917520175211752217523175241752517526175271752817529175301753117532175331753417535175361753717538175391754017541175421754317544175451754617547175481754917550175511755217553175541755517556175571755817559175601756117562175631756417565175661756717568175691757017571175721757317574175751757617577175781757917580175811758217583175841758517586175871758817589175901759117592175931759417595175961759717598175991760017601176021760317604176051760617607176081760917610176111761217613176141761517616176171761817619176201762117622176231762417625176261762717628176291763017631176321763317634176351763617637176381763917640176411764217643176441764517646176471764817649176501765117652176531765417655176561765717658176591766017661176621766317664176651766617667176681766917670176711767217673176741767517676176771767817679176801768117682176831768417685176861768717688176891769017691176921769317694176951769617697176981769917700177011770217703177041770517706177071770817709177101771117712177131771417715177161771717718177191772017721177221772317724177251772617727177281772917730177311773217733177341773517736177371773817739177401774117742177431774417745177461774717748177491775017751177521775317754177551775617757177581775917760177611776217763177641776517766177671776817769177701777117772177731777417775177761777717778177791778017781177821778317784177851778617787177881778917790177911779217793177941779517796177971779817799178001780117802178031780417805178061780717808178091781017811178121781317814178151781617817178181781917820178211782217823178241782517826178271782817829178301783117832178331783417835178361783717838178391784017841178421784317844178451784617847178481784917850178511785217853178541785517856178571785817859178601786117862178631786417865178661786717868178691787017871178721787317874178751787617877178781787917880178811788217883178841788517886178871788817889178901789117892178931789417895178961789717898178991790017901179021790317904179051790617907179081790917910179111791217913179141791517916179171791817919179201792117922179231792417925179261792717928179291793017931179321793317934179351793617937179381793917940179411794217943179441794517946179471794817949179501795117952179531795417955179561795717958179591796017961179621796317964179651796617967179681796917970179711797217973179741797517976179771797817979179801798117982179831798417985179861798717988179891799017991179921799317994179951799617997179981799918000180011800218003180041800518006180071800818009180101801118012180131801418015180161801718018180191802018021180221802318024180251802618027180281802918030180311803218033180341803518036180371803818039180401804118042180431804418045180461804718048180491805018051180521805318054180551805618057180581805918060180611806218063180641806518066180671806818069180701807118072180731807418075180761807718078180791808018081180821808318084180851808618087180881808918090180911809218093180941809518096180971809818099181001810118102181031810418105181061810718108181091811018111181121811318114181151811618117181181811918120181211812218123181241812518126181271812818129181301813118132181331813418135181361813718138181391814018141181421814318144181451814618147181481814918150181511815218153181541815518156181571815818159181601816118162181631816418165181661816718168181691817018171181721817318174181751817618177181781817918180181811818218183181841818518186181871818818189181901819118192181931819418195181961819718198181991820018201182021820318204182051820618207182081820918210182111821218213182141821518216182171821818219182201822118222182231822418225182261822718228182291823018231182321823318234182351823618237182381823918240182411824218243182441824518246182471824818249182501825118252182531825418255182561825718258182591826018261182621826318264182651826618267182681826918270182711827218273182741827518276182771827818279182801828118282182831828418285182861828718288182891829018291182921829318294182951829618297182981829918300183011830218303183041830518306183071830818309183101831118312183131831418315183161831718318183191832018321183221832318324183251832618327183281832918330183311833218333183341833518336183371833818339183401834118342183431834418345183461834718348183491835018351183521835318354183551835618357183581835918360183611836218363183641836518366183671836818369183701837118372183731837418375183761837718378183791838018381183821838318384183851838618387183881838918390183911839218393183941839518396183971839818399184001840118402184031840418405184061840718408184091841018411184121841318414184151841618417184181841918420184211842218423184241842518426184271842818429184301843118432184331843418435184361843718438184391844018441184421844318444184451844618447184481844918450184511845218453184541845518456184571845818459184601846118462184631846418465184661846718468184691847018471184721847318474184751847618477184781847918480184811848218483184841848518486184871848818489184901849118492184931849418495184961849718498184991850018501185021850318504185051850618507185081850918510185111851218513185141851518516185171851818519185201852118522185231852418525185261852718528185291853018531185321853318534185351853618537185381853918540185411854218543185441854518546185471854818549185501855118552185531855418555185561855718558185591856018561185621856318564185651856618567185681856918570185711857218573185741857518576185771857818579185801858118582185831858418585185861858718588185891859018591185921859318594185951859618597185981859918600186011860218603186041860518606186071860818609186101861118612186131861418615186161861718618186191862018621186221862318624186251862618627186281862918630186311863218633186341863518636186371863818639186401864118642186431864418645186461864718648186491865018651186521865318654186551865618657186581865918660186611866218663186641866518666186671866818669186701867118672186731867418675186761867718678186791868018681186821868318684186851868618687186881868918690186911869218693186941869518696186971869818699187001870118702187031870418705187061870718708187091871018711187121871318714187151871618717187181871918720187211872218723187241872518726187271872818729187301873118732187331873418735187361873718738187391874018741187421874318744187451874618747187481874918750187511875218753187541875518756187571875818759187601876118762187631876418765187661876718768187691877018771187721877318774187751877618777187781877918780187811878218783187841878518786187871878818789187901879118792187931879418795187961879718798187991880018801188021880318804188051880618807188081880918810188111881218813188141881518816188171881818819188201882118822188231882418825188261882718828188291883018831188321883318834188351883618837188381883918840188411884218843188441884518846188471884818849188501885118852188531885418855188561885718858188591886018861188621886318864188651886618867188681886918870188711887218873188741887518876188771887818879188801888118882188831888418885188861888718888188891889018891188921889318894188951889618897188981889918900189011890218903189041890518906189071890818909189101891118912189131891418915189161891718918189191892018921189221892318924189251892618927189281892918930189311893218933189341893518936189371893818939189401894118942189431894418945189461894718948189491895018951189521895318954189551895618957189581895918960189611896218963189641896518966189671896818969189701897118972189731897418975189761897718978189791898018981189821898318984189851898618987189881898918990189911899218993189941899518996189971899818999190001900119002190031900419005190061900719008190091901019011190121901319014190151901619017190181901919020190211902219023190241902519026190271902819029190301903119032190331903419035190361903719038190391904019041190421904319044190451904619047190481904919050190511905219053190541905519056190571905819059190601906119062190631906419065190661906719068190691907019071190721907319074190751907619077190781907919080190811908219083190841908519086190871908819089190901909119092190931909419095190961909719098190991910019101191021910319104191051910619107191081910919110191111911219113191141911519116191171911819119191201912119122191231912419125191261912719128191291913019131191321913319134191351913619137191381913919140191411914219143191441914519146191471914819149191501915119152191531915419155191561915719158191591916019161191621916319164191651916619167191681916919170191711917219173191741917519176191771917819179191801918119182191831918419185191861918719188191891919019191191921919319194191951919619197191981919919200192011920219203192041920519206192071920819209192101921119212192131921419215192161921719218192191922019221192221922319224192251922619227192281922919230192311923219233192341923519236192371923819239192401924119242192431924419245192461924719248192491925019251192521925319254192551925619257192581925919260192611926219263192641926519266192671926819269192701927119272192731927419275192761927719278192791928019281192821928319284192851928619287192881928919290192911929219293192941929519296192971929819299193001930119302193031930419305193061930719308193091931019311193121931319314193151931619317193181931919320193211932219323193241932519326193271932819329193301933119332193331933419335193361933719338193391934019341193421934319344193451934619347193481934919350193511935219353193541935519356193571935819359193601936119362193631936419365193661936719368193691937019371193721937319374193751937619377193781937919380193811938219383193841938519386193871938819389193901939119392193931939419395193961939719398193991940019401194021940319404194051940619407194081940919410194111941219413194141941519416194171941819419194201942119422194231942419425194261942719428194291943019431194321943319434194351943619437194381943919440194411944219443194441944519446194471944819449194501945119452194531945419455194561945719458194591946019461194621946319464194651946619467194681946919470194711947219473194741947519476194771947819479194801948119482194831948419485194861948719488194891949019491194921949319494194951949619497194981949919500195011950219503195041950519506195071950819509195101951119512195131951419515195161951719518195191952019521195221952319524195251952619527195281952919530195311953219533195341953519536195371953819539195401954119542195431954419545195461954719548195491955019551195521955319554195551955619557195581955919560195611956219563195641956519566195671956819569195701957119572195731957419575195761957719578195791958019581195821958319584195851958619587195881958919590195911959219593195941959519596195971959819599196001960119602196031960419605196061960719608196091961019611196121961319614196151961619617196181961919620196211962219623196241962519626196271962819629196301963119632196331963419635196361963719638196391964019641196421964319644196451964619647196481964919650196511965219653196541965519656196571965819659196601966119662196631966419665196661966719668196691967019671196721967319674196751967619677196781967919680196811968219683196841968519686196871968819689196901969119692196931969419695196961969719698196991970019701197021970319704197051970619707197081970919710197111971219713197141971519716197171971819719197201972119722197231972419725197261972719728197291973019731197321973319734197351973619737197381973919740197411974219743197441974519746197471974819749197501975119752197531975419755197561975719758197591976019761197621976319764197651976619767197681976919770197711977219773197741977519776197771977819779197801978119782197831978419785197861978719788197891979019791197921979319794197951979619797197981979919800198011980219803198041980519806198071980819809198101981119812198131981419815198161981719818198191982019821198221982319824198251982619827198281982919830198311983219833198341983519836198371983819839198401984119842198431984419845198461984719848198491985019851198521985319854198551985619857198581985919860198611986219863198641986519866198671986819869198701987119872198731987419875198761987719878198791988019881198821988319884198851988619887198881988919890198911989219893198941989519896198971989819899199001990119902199031990419905199061990719908199091991019911199121991319914199151991619917199181991919920199211992219923199241992519926199271992819929199301993119932199331993419935199361993719938199391994019941199421994319944199451994619947199481994919950199511995219953199541995519956199571995819959199601996119962199631996419965199661996719968199691997019971199721997319974199751997619977199781997919980199811998219983199841998519986199871998819989199901999119992199931999419995199961999719998199992000020001200022000320004200052000620007200082000920010200112001220013200142001520016200172001820019200202002120022200232002420025200262002720028200292003020031200322003320034200352003620037200382003920040200412004220043200442004520046200472004820049200502005120052200532005420055200562005720058200592006020061200622006320064200652006620067200682006920070200712007220073200742007520076200772007820079200802008120082200832008420085200862008720088200892009020091200922009320094200952009620097200982009920100201012010220103201042010520106201072010820109201102011120112201132011420115201162011720118201192012020121201222012320124201252012620127201282012920130201312013220133201342013520136201372013820139201402014120142201432014420145201462014720148201492015020151201522015320154201552015620157201582015920160201612016220163201642016520166201672016820169201702017120172201732017420175201762017720178201792018020181201822018320184201852018620187201882018920190201912019220193201942019520196201972019820199202002020120202202032020420205202062020720208202092021020211202122021320214202152021620217202182021920220202212022220223202242022520226202272022820229202302023120232202332023420235202362023720238202392024020241202422024320244202452024620247202482024920250202512025220253202542025520256202572025820259202602026120262202632026420265202662026720268202692027020271202722027320274202752027620277202782027920280202812028220283202842028520286202872028820289202902029120292202932029420295202962029720298202992030020301203022030320304203052030620307203082030920310203112031220313203142031520316203172031820319203202032120322203232032420325203262032720328203292033020331203322033320334203352033620337203382033920340203412034220343203442034520346203472034820349203502035120352203532035420355203562035720358203592036020361203622036320364203652036620367203682036920370203712037220373203742037520376203772037820379203802038120382203832038420385203862038720388203892039020391203922039320394203952039620397203982039920400204012040220403204042040520406204072040820409204102041120412204132041420415204162041720418204192042020421204222042320424204252042620427204282042920430204312043220433204342043520436204372043820439204402044120442204432044420445204462044720448204492045020451204522045320454204552045620457204582045920460204612046220463204642046520466204672046820469204702047120472204732047420475204762047720478204792048020481204822048320484204852048620487204882048920490204912049220493204942049520496204972049820499205002050120502205032050420505205062050720508205092051020511205122051320514205152051620517205182051920520205212052220523205242052520526205272052820529205302053120532205332053420535205362053720538205392054020541205422054320544205452054620547205482054920550205512055220553205542055520556205572055820559205602056120562205632056420565205662056720568205692057020571205722057320574205752057620577205782057920580205812058220583205842058520586205872058820589205902059120592205932059420595205962059720598205992060020601206022060320604206052060620607206082060920610206112061220613206142061520616206172061820619206202062120622206232062420625206262062720628206292063020631206322063320634206352063620637206382063920640206412064220643206442064520646206472064820649206502065120652206532065420655206562065720658206592066020661206622066320664206652066620667206682066920670206712067220673206742067520676206772067820679206802068120682206832068420685206862068720688206892069020691206922069320694206952069620697206982069920700207012070220703207042070520706207072070820709207102071120712207132071420715207162071720718207192072020721207222072320724207252072620727207282072920730207312073220733207342073520736207372073820739207402074120742207432074420745207462074720748207492075020751207522075320754207552075620757207582075920760207612076220763207642076520766207672076820769207702077120772207732077420775207762077720778207792078020781207822078320784207852078620787207882078920790207912079220793207942079520796207972079820799208002080120802208032080420805208062080720808208092081020811208122081320814208152081620817208182081920820208212082220823208242082520826208272082820829208302083120832208332083420835208362083720838208392084020841208422084320844208452084620847208482084920850208512085220853208542085520856208572085820859208602086120862208632086420865208662086720868208692087020871208722087320874208752087620877208782087920880208812088220883208842088520886208872088820889208902089120892208932089420895208962089720898208992090020901209022090320904209052090620907209082090920910209112091220913209142091520916209172091820919209202092120922209232092420925209262092720928209292093020931209322093320934209352093620937209382093920940209412094220943209442094520946209472094820949209502095120952209532095420955209562095720958209592096020961209622096320964209652096620967209682096920970209712097220973209742097520976209772097820979209802098120982209832098420985209862098720988209892099020991209922099320994209952099620997209982099921000210012100221003210042100521006210072100821009210102101121012210132101421015210162101721018210192102021021210222102321024210252102621027210282102921030210312103221033210342103521036210372103821039210402104121042210432104421045210462104721048210492105021051210522105321054210552105621057210582105921060210612106221063210642106521066210672106821069210702107121072210732107421075210762107721078210792108021081210822108321084210852108621087210882108921090210912109221093210942109521096210972109821099211002110121102211032110421105211062110721108211092111021111211122111321114211152111621117211182111921120211212112221123211242112521126211272112821129211302113121132211332113421135211362113721138211392114021141211422114321144211452114621147211482114921150211512115221153211542115521156211572115821159211602116121162211632116421165211662116721168211692117021171211722117321174211752117621177211782117921180211812118221183211842118521186211872118821189211902119121192211932119421195211962119721198211992120021201212022120321204212052120621207212082120921210212112121221213212142121521216212172121821219212202122121222212232122421225212262122721228212292123021231212322123321234212352123621237212382123921240212412124221243212442124521246212472124821249212502125121252212532125421255212562125721258212592126021261212622126321264212652126621267212682126921270212712127221273212742127521276212772127821279212802128121282212832128421285212862128721288212892129021291212922129321294212952129621297212982129921300213012130221303213042130521306213072130821309213102131121312213132131421315213162131721318213192132021321213222132321324213252132621327213282132921330213312133221333213342133521336213372133821339213402134121342213432134421345213462134721348213492135021351213522135321354213552135621357213582135921360213612136221363213642136521366213672136821369213702137121372213732137421375213762137721378213792138021381213822138321384213852138621387213882138921390213912139221393213942139521396213972139821399214002140121402214032140421405214062140721408214092141021411214122141321414214152141621417214182141921420214212142221423214242142521426214272142821429214302143121432214332143421435214362143721438214392144021441214422144321444214452144621447214482144921450214512145221453214542145521456214572145821459214602146121462214632146421465214662146721468214692147021471214722147321474214752147621477214782147921480214812148221483214842148521486214872148821489214902149121492214932149421495214962149721498214992150021501215022150321504215052150621507215082150921510215112151221513215142151521516215172151821519215202152121522215232152421525215262152721528215292153021531215322153321534215352153621537215382153921540215412154221543215442154521546215472154821549215502155121552215532155421555215562155721558215592156021561215622156321564215652156621567215682156921570215712157221573215742157521576215772157821579215802158121582215832158421585215862158721588215892159021591215922159321594215952159621597215982159921600216012160221603216042160521606216072160821609216102161121612216132161421615216162161721618216192162021621216222162321624216252162621627216282162921630216312163221633216342163521636216372163821639216402164121642216432164421645216462164721648216492165021651216522165321654216552165621657216582165921660216612166221663216642166521666216672166821669216702167121672216732167421675216762167721678216792168021681216822168321684216852168621687216882168921690216912169221693216942169521696216972169821699217002170121702217032170421705217062170721708217092171021711217122171321714217152171621717217182171921720217212172221723217242172521726217272172821729217302173121732217332173421735217362173721738217392174021741217422174321744217452174621747217482174921750217512175221753217542175521756217572175821759217602176121762217632176421765217662176721768217692177021771217722177321774217752177621777217782177921780217812178221783217842178521786217872178821789217902179121792217932179421795217962179721798217992180021801218022180321804218052180621807218082180921810218112181221813218142181521816218172181821819218202182121822218232182421825218262182721828218292183021831218322183321834218352183621837218382183921840218412184221843218442184521846218472184821849218502185121852218532185421855218562185721858218592186021861218622186321864218652186621867218682186921870218712187221873218742187521876218772187821879218802188121882218832188421885218862188721888218892189021891218922189321894218952189621897218982189921900219012190221903219042190521906219072190821909219102191121912219132191421915219162191721918219192192021921219222192321924219252192621927219282192921930219312193221933219342193521936219372193821939219402194121942219432194421945219462194721948219492195021951219522195321954219552195621957219582195921960219612196221963219642196521966219672196821969219702197121972219732197421975219762197721978219792198021981219822198321984219852198621987219882198921990219912199221993219942199521996219972199821999220002200122002220032200422005220062200722008220092201022011220122201322014220152201622017220182201922020220212202222023220242202522026220272202822029220302203122032220332203422035220362203722038220392204022041220422204322044220452204622047220482204922050220512205222053220542205522056220572205822059220602206122062220632206422065220662206722068220692207022071220722207322074220752207622077220782207922080220812208222083220842208522086220872208822089220902209122092220932209422095220962209722098220992210022101221022210322104221052210622107221082210922110221112211222113221142211522116221172211822119221202212122122221232212422125221262212722128221292213022131221322213322134221352213622137221382213922140221412214222143221442214522146221472214822149221502215122152221532215422155221562215722158221592216022161221622216322164221652216622167221682216922170221712217222173221742217522176221772217822179221802218122182221832218422185221862218722188221892219022191221922219322194221952219622197221982219922200222012220222203222042220522206222072220822209222102221122212222132221422215222162221722218222192222022221222222222322224222252222622227222282222922230222312223222233222342223522236222372223822239222402224122242222432224422245222462224722248222492225022251222522225322254222552225622257222582225922260222612226222263222642226522266222672226822269222702227122272222732227422275222762227722278222792228022281222822228322284222852228622287222882228922290222912229222293222942229522296222972229822299223002230122302223032230422305223062230722308223092231022311223122231322314223152231622317223182231922320223212232222323223242232522326223272232822329223302233122332223332233422335223362233722338223392234022341223422234322344223452234622347223482234922350223512235222353223542235522356223572235822359223602236122362223632236422365223662236722368223692237022371223722237322374223752237622377223782237922380223812238222383223842238522386223872238822389223902239122392223932239422395223962239722398223992240022401224022240322404224052240622407224082240922410224112241222413224142241522416224172241822419224202242122422224232242422425224262242722428224292243022431224322243322434224352243622437224382243922440224412244222443224442244522446224472244822449224502245122452224532245422455224562245722458224592246022461224622246322464224652246622467224682246922470224712247222473224742247522476224772247822479224802248122482224832248422485224862248722488224892249022491224922249322494224952249622497224982249922500
  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. }clientTime;
  117. typedef union
  118. {
  119. //Operations Initiated by Central System
  120. unsigned char CsMsgValue[CONNECTOR_QUANTITY];
  121. struct
  122. {
  123. //CsMsgValue[0]
  124. unsigned char StatusNotificationReq:1; //bit 0,
  125. unsigned char StatusNotificationConf:1; //bit 1,
  126. unsigned char TriggerMeterValue:1; //bit 2,
  127. unsigned char TriggerStatusNotificationReq:1; //bit 3,
  128. unsigned char isOnCharging:1; //bit 4,
  129. unsigned char :3; //bit5~7
  130. }bits[CONNECTOR_QUANTITY];
  131. }CpinitiateMsg;
  132. CpinitiateMsg cpinitateMsg;
  133. //GetConfiguration Array
  134. struct StructConfigurationKeyItems staticKeyArray[GetConfigurationMaxKeysNUM]={0};
  135. struct StructConfigurationKey staticResponseConfigurationKeyArray[GetConfigurationMaxKeysNUM]={0};
  136. struct StructConfigurationKeyItems staticResponseUnknownKey[10]={0};
  137. struct StructLocalAuthorizationList staticLocalAuthorizationList[1]={0};
  138. static char *ChargePointErrorCodeStr[] = {
  139. MACROSTR(ConnectorLockFailure),
  140. MACROSTR(EVCommunicationError),
  141. MACROSTR(GroundFailure),
  142. MACROSTR(HighTemperature),
  143. MACROSTR(InternalError),
  144. MACROSTR(LocalListConflict),
  145. MACROSTR(NoError),
  146. MACROSTR(OtherError),
  147. MACROSTR(OverCurrentFailure),
  148. MACROSTR(OverVoltage),
  149. MACROSTR(PowerMeterFailure),
  150. MACROSTR(PowerSwitchFailure),
  151. MACROSTR(ReaderFailure),
  152. MACROSTR(ResetFailure),
  153. MACROSTR(UnderVoltage),
  154. MACROSTR(WeakSignal)
  155. };
  156. static char * ChargePointStatusStr[] = {
  157. MACROSTR(Available),
  158. MACROSTR(Preparing),
  159. MACROSTR(Charging),
  160. MACROSTR(SuspendedEVSE),
  161. MACROSTR(SuspendedEV),
  162. MACROSTR(Finishing),
  163. MACROSTR(Reserved),
  164. MACROSTR(Unavailable),
  165. MACROSTR(Faulted)
  166. };
  167. static char *RegistrationStatusStr[] = {
  168. MACROSTR(Accepted),
  169. MACROSTR(Pending),
  170. MACROSTR(Rejected)
  171. };
  172. static char *AvailabilityTypeStr[] = {
  173. MACROSTR(Inoperative),
  174. MACROSTR(Operative)
  175. };
  176. static char *AvailabilityStatusStr[] = {
  177. MACROSTR(Accepted),
  178. MACROSTR(Rejected),
  179. MACROSTR(Scheduled)
  180. };
  181. static char *ConfigurationStatusStr[] = {
  182. MACROSTR(Accepted),
  183. MACROSTR(Rejected),
  184. MACROSTR(RebootRequired),
  185. MACROSTR(NotSupported)
  186. };
  187. static char *ClearCacheStatusStr[] = {
  188. MACROSTR(Accepted),
  189. MACROSTR(Rejected)
  190. };
  191. static char *ChargingProfilePurposeTypeStr[] = {
  192. MACROSTR(ChargePointMaxProfile),
  193. MACROSTR(TxDefaultProfile),
  194. MACROSTR(TxProfile)
  195. };
  196. static char *ChargingProfileStatusStr[] = {
  197. MACROSTR(Accepted),
  198. MACROSTR(Rejected),
  199. MACROSTR(NotSupported)
  200. };
  201. static char *ClearChargingProfileStatusStr[] = {
  202. MACROSTR(Accepted),
  203. MACROSTR(Unknown)
  204. };
  205. static char *GetCompositeScheduleStatusStr[] = {
  206. MACROSTR(Accepted),
  207. MACROSTR(Rejected)
  208. };
  209. static char *UpdateTypeStr[] = {
  210. MACROSTR(Differential),
  211. MACROSTR(Full)
  212. };
  213. static char *UpdateStatusStr[] = {
  214. MACROSTR(Accepted),
  215. MACROSTR(Failed),
  216. MACROSTR(NotSupported),
  217. MACROSTR(VersionMismatch)
  218. };
  219. static char *RemoteStartStopStatusStr[] = {
  220. MACROSTR(Accepted),
  221. MACROSTR(Rejected)
  222. };
  223. static char *ReservationStatusStr[] = {
  224. MACROSTR(Accepted),
  225. MACROSTR(Faulted),
  226. MACROSTR(Occupied),
  227. MACROSTR(Rejected),
  228. MACROSTR(Unavailable)
  229. };
  230. static char *ResetTypeStr[] = {
  231. MACROSTR(Hard),
  232. MACROSTR(Soft)
  233. };
  234. static char *ResetStatusStr[] = {
  235. MACROSTR(Accepted),
  236. MACROSTR(Rejected)
  237. };
  238. static char * DiagnosticsStatusStr[] = {
  239. MACROSTR(Idle),
  240. MACROSTR(Uploaded),
  241. MACROSTR(UploadFailed),
  242. MACROSTR(Uploading)
  243. };
  244. static char * FirmwareStatusStr[] = {
  245. MACROSTR(Downloaded),
  246. MACROSTR(DownloadFailed),
  247. MACROSTR(Downloading),
  248. MACROSTR(Idle),
  249. MACROSTR(InstallationFailed),
  250. MACROSTR(Installing),
  251. MACROSTR(Installed)
  252. };
  253. static char * MessageTriggerStr[] = {
  254. MACROSTR(BootNotification),
  255. MACROSTR(DiagnosticsStatusNotification),
  256. MACROSTR(FirmwareStatusNotification),
  257. MACROSTR(Heartbeat),
  258. MACROSTR(MeterValues),
  259. MACROSTR(StatusNotification)
  260. };
  261. static char * TriggerMessageStatusStr[] = {
  262. MACROSTR(Accepted),
  263. MACROSTR(Rejected),
  264. MACROSTR(NotImplemented)
  265. };
  266. static char * UnlockStatusStr[] = {
  267. MACROSTR(Unlocked),
  268. MACROSTR(UnlockFailed),
  269. MACROSTR(NotSupported)
  270. };
  271. #if 0
  272. static char * StopTransactionReasonStr[] = {
  273. MACROSTR(EmergencyStop),
  274. MACROSTR(EVDisconnected),
  275. MACROSTR(HardReset),
  276. MACROSTR(Local),
  277. MACROSTR(Other),
  278. MACROSTR(PowerLoss),
  279. MACROSTR(Reboot),
  280. MACROSTR(Remote),
  281. MACROSTR(SoftReset),
  282. MACROSTR(UnlockCommand),
  283. MACROSTR(DeAuthorized)
  284. };
  285. #endif
  286. static char * CancelReservationStatusStr[] = {
  287. MACROSTR(Accepted),
  288. MACROSTR(Rejected)
  289. };
  290. static char * ReadingContextStr[] = {
  291. MACROSTR(Interruption.Begin),
  292. MACROSTR(Interruption.End),
  293. MACROSTR(Other),
  294. MACROSTR(Sample.Clock),
  295. MACROSTR(Sample.Periodic),
  296. MACROSTR(Transaction.Begin),
  297. MACROSTR(Transaction.End),
  298. MACROSTR(Trigger)
  299. };
  300. static char * ValueFormatStr[] = {
  301. MACROSTR(Raw),
  302. MACROSTR(SignedData)
  303. };
  304. static char * MeasurandStr[] = {
  305. MACROSTR(Current.Export),
  306. MACROSTR(Current.Import),
  307. MACROSTR(Current.Offered),
  308. MACROSTR(Energy.Active.Export.Register),
  309. MACROSTR(Energy.Active.Import.Register),
  310. MACROSTR(Energy.Reactive.Export.Register),
  311. MACROSTR(Energy.Reactive.Import.Register),
  312. MACROSTR(Energy.Active.Export.Interval),
  313. MACROSTR(Energy.Active.Import.Interval),
  314. MACROSTR(Energy.Reactive.Export.Interval),
  315. MACROSTR(Energy.Reactive.Import.Interval),
  316. MACROSTR(Frequency),
  317. MACROSTR(Power.Active.Export),
  318. MACROSTR(Power.Active.Import),
  319. MACROSTR(Power.Factor),
  320. MACROSTR(Power.Offered),
  321. MACROSTR(Power.Reactive.ExportMACROSTR),
  322. MACROSTR(Power.Reactive.Import),
  323. MACROSTR(RPM),
  324. MACROSTR(SoC),
  325. MACROSTR(Temperature),
  326. MACROSTR(Voltage)
  327. };
  328. static char * LocationStr[] = {
  329. MACROSTR(Body),
  330. MACROSTR(Cable),
  331. MACROSTR(EV),
  332. MACROSTR(Inlet),
  333. MACROSTR(Outlet)
  334. };
  335. static char * PhaseStr[] = {
  336. MACROSTR(L1),
  337. MACROSTR(L2),
  338. MACROSTR(L3),
  339. MACROSTR(N),
  340. MACROSTR(L1-N),
  341. MACROSTR(L2-N),
  342. MACROSTR(L3-N),
  343. MACROSTR(L1-L2),
  344. MACROSTR(L2-L3),
  345. MACROSTR(L3-L1)
  346. };
  347. static char * UnitOfMeasureStr[] = {
  348. MACROSTR(Wh),
  349. MACROSTR(kWh),
  350. MACROSTR(varh),
  351. MACROSTR(kvarh),
  352. MACROSTR(W),
  353. MACROSTR(kW),
  354. MACROSTR(VA),
  355. MACROSTR(kVA),
  356. MACROSTR(var),
  357. MACROSTR(kvar),
  358. MACROSTR(A),
  359. MACROSTR(V),
  360. MACROSTR(Celsius),
  361. MACROSTR(Fahrenheit),
  362. MACROSTR(K),
  363. MACROSTR(Percent)
  364. };
  365. //=========================================
  366. // TTIA routine
  367. //=========================================
  368. int sendTTIAInfo(uint8_t gun_index)
  369. {
  370. static int sn = 0;
  371. int result = FAIL;
  372. struct hostent *server;
  373. int udp_socket_fd;
  374. struct sockaddr_in dest_addr = {0};
  375. uint8_t tx_buf[80] = {0};
  376. uint8_t logBuf[256]= {0};
  377. uint8_t tx_len, tempIndex, socStart, socEnd;
  378. uint16_t PresentChargedEnergy;
  379. struct tm tmStart, tmEnd;
  380. DEBUG_INFO("sendTTIAInfo...\n");
  381. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  382. {
  383. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  384. {
  385. tempIndex = ((gun_index==2) ? 1: 0);
  386. }
  387. else
  388. {
  389. tempIndex = gun_index;
  390. }
  391. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  392. {
  393. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  394. {
  395. socStart = ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].EvBatteryStartSoc;
  396. socEnd = ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].EvBatterySoc;
  397. PresentChargedEnergy = (uint16_t)(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargedEnergy*10);
  398. }
  399. }
  400. }
  401. else if(gunType[gun_index] == GUN_TYPE_CCS)
  402. {
  403. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  404. {
  405. tempIndex = ((gun_index==2) ? 1: 0);
  406. }
  407. else
  408. {
  409. tempIndex = gun_index;
  410. }
  411. for (int index = 0; index < CCS_QUANTITY; index++)
  412. {
  413. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  414. {
  415. socStart = ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].EvBatteryStartSoc;
  416. socEnd = ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].EvBatterySoc;
  417. PresentChargedEnergy = (uint16_t)(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargedEnergy*10);
  418. }
  419. }
  420. }
  421. else if(gunType[gun_index] == GUN_TYPE_GBT)
  422. {
  423. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  424. {
  425. tempIndex = ((gun_index==2) ? 1: 0);
  426. }
  427. else
  428. {
  429. tempIndex = gun_index;
  430. }
  431. for (int index = 0; index < GB_QUANTITY; index++)
  432. {
  433. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  434. {
  435. socStart = ShmSysConfigAndInfo->SysInfo.GbChargingData[index].EvBatteryStartSoc;
  436. socEnd = ShmSysConfigAndInfo->SysInfo.GbChargingData[index].EvBatterySoc;
  437. PresentChargedEnergy = (uint16_t)(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargedEnergy*10);
  438. }
  439. }
  440. }
  441. else if(gunType[gun_index] == GUN_TYPE_DO)
  442. {
  443. tempIndex = gun_index;
  444. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  445. {
  446. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  447. {
  448. socStart = ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.EvBatteryStartSoc;
  449. socEnd = ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.EvBatterySoc;
  450. PresentChargedEnergy = (uint16_t)(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PresentChargedEnergy*10);
  451. }
  452. }
  453. }
  454. else
  455. {
  456. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  457. {
  458. tempIndex = 2;
  459. }
  460. else
  461. {
  462. tempIndex = gun_index;
  463. }
  464. for (int index = 0; index < AC_QUANTITY; index++)
  465. {
  466. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  467. {
  468. socStart = ShmSysConfigAndInfo->SysInfo.AcChargingData[index].EvBatteryStartSoc;
  469. socEnd = ShmSysConfigAndInfo->SysInfo.AcChargingData[index].EvBatterySoc;
  470. PresentChargedEnergy = (uint16_t)(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargedEnergy*10);
  471. }
  472. }// END
  473. }
  474. // Message assembly
  475. sprintf((char*)&tx_buf[0], "APTS"); // Protocol ID
  476. tx_buf[4] = 0x02; // Protocol Version
  477. tx_buf[5] = 0xb0; // Message ID
  478. tx_buf[6] = ShmSysConfigAndInfo->SysConfig.TTIA_Info.busVenderId & 0xff; // CustomerID low byte
  479. tx_buf[7] = (ShmSysConfigAndInfo->SysConfig.TTIA_Info.busVenderId>>8) & 0xff; // CustomerID high byte
  480. tx_buf[8] = 0x00; // CarID low byte
  481. tx_buf[9] = 0x00; // CarID high byte
  482. tx_buf[10] = 0x00; // ID Storage
  483. tx_buf[11] = 0x00; // Driver lowest byte
  484. tx_buf[12] = 0x00; // Driver 2nd byte
  485. tx_buf[13] = 0x00; // Driver 3rd byte
  486. tx_buf[14] = 0x00; // Driver highest byte
  487. tx_buf[15] = sn & 0xff; // Sequence SN low byte
  488. tx_buf[16] = (sn>>8) & 0xff; // Sequence SN high byte
  489. tx_buf[17] = 0x00; // Reserve
  490. tx_buf[18] = 60 & 0xff; // Payload length low byte
  491. tx_buf[19] = (60>>8) & 0xff; // Payload length high byte
  492. // EVSE provider
  493. memcpy((char*)&tx_buf[20], ShmSysConfigAndInfo->SysConfig.TTIA_Info.EquipmentProvider, 15);
  494. // EVSE provider
  495. tx_buf[35] = ShmSysConfigAndInfo->SysConfig.TTIA_Info.TransportationCompanyNo;
  496. // EVSE id
  497. tx_buf[36] = ShmSysConfigAndInfo->SysConfig.TTIA_Info.ChargeBoxId;
  498. // Connector id
  499. tx_buf[37] = gun_index;
  500. // EVSE station
  501. memcpy((char*)&tx_buf[38], ShmSysConfigAndInfo->SysConfig.TTIA_Info.evseStation, 15);
  502. // Vehicle SN
  503. memcpy(&tx_buf[53], &ShmOCPP16Data->StartTransaction[gun_index].IdTag, 8);
  504. // Mileage
  505. tx_buf[61] = 0x00; // lowest byte
  506. tx_buf[62] = 0x00; // 2nd byte
  507. tx_buf[63] = 0x00; // highest byte
  508. // Start date time 6 bytes
  509. 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))
  510. {
  511. struct tm *tmTarget;
  512. struct timeb tbTarget;
  513. tmStart.tm_year -= 1900;
  514. tmStart.tm_mon -= 1;
  515. tmStart.tm_gmtoff = 0;
  516. tbTarget.time = mktime(&tmStart);
  517. tbTarget.timezone = 0;
  518. tbTarget.time += (8*3600);
  519. tmTarget = gmtime(&tbTarget.time);
  520. tx_buf[64] = ((tmTarget->tm_year+1900)-2000);
  521. tx_buf[65] = (tmTarget->tm_mon+1);
  522. tx_buf[66] = tmTarget->tm_mday;
  523. tx_buf[67] = tmTarget->tm_hour;
  524. tx_buf[68] = tmTarget->tm_min;
  525. tx_buf[69] = tmTarget->tm_sec;
  526. }
  527. // Stop date time 6 bytes
  528. 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))
  529. {
  530. struct tm *tmTarget;
  531. struct timeb tbTarget;
  532. tmEnd.tm_year -= 1900;
  533. tmEnd.tm_mon -= 1;
  534. tmEnd.tm_gmtoff = 0;
  535. tbTarget.time = mktime(&tmEnd);
  536. tbTarget.timezone = 0;
  537. tbTarget.time += (8*3600);
  538. tmTarget = gmtime(&tbTarget.time);
  539. tx_buf[70] = ((tmTarget->tm_year+1900)-2000);
  540. tx_buf[71] = (tmTarget->tm_mon+1);
  541. tx_buf[72] = tmTarget->tm_mday;
  542. tx_buf[73] = tmTarget->tm_hour;
  543. tx_buf[74] = tmTarget->tm_min;
  544. tx_buf[75] = tmTarget->tm_sec;
  545. }
  546. // Session energy 2 bytes
  547. tx_buf[76] = PresentChargedEnergy & 0xff;
  548. tx_buf[77] = (PresentChargedEnergy>>8) & 0xff;
  549. // Start SOC 1 byte
  550. tx_buf[78] = socStart;
  551. // Stop SOC 1 byte
  552. tx_buf[79] = socEnd;
  553. // Open socket
  554. udp_socket_fd = socket(AF_INET, SOCK_DGRAM, 0);
  555. if(udp_socket_fd == -1)
  556. {
  557. DEBUG_ERROR("UDP socket create failed!\n");
  558. }
  559. else
  560. {
  561. // Get server DNS entry
  562. server = gethostbyname((char*)ShmSysConfigAndInfo->SysConfig.TTIA_Info.server_addr);
  563. if (server == NULL)
  564. {
  565. DEBUG_ERROR("ERROR, no such host as %s\n", ShmSysConfigAndInfo->SysConfig.TTIA_Info.server_addr);
  566. }
  567. else
  568. {
  569. // Build the server's Internet address
  570. bzero((char *) &dest_addr, sizeof(dest_addr));
  571. dest_addr.sin_family = AF_INET;
  572. bcopy((char *)server->h_addr, (char *)&dest_addr.sin_addr.s_addr, server->h_length);
  573. dest_addr.sin_port = htons(ShmSysConfigAndInfo->SysConfig.TTIA_Info.server_port);
  574. if((tx_len = sendto(udp_socket_fd, tx_buf, ARRAY_SIZE(tx_buf), 0, &dest_addr, sizeof(dest_addr))) >= 0)
  575. {
  576. for(uint8_t idx=0;idx<ARRAY_SIZE(tx_buf);idx++)
  577. {
  578. sprintf((char*)logBuf, "%s %02X", logBuf, tx_buf[idx]);
  579. }
  580. DEBUG_TTIA_INFO("TX raw data length: %d\n", tx_len);
  581. DEBUG_TTIA_INFO("Message raw: %s\n", logBuf);
  582. DEBUG_TTIA_INFO("OCPP Transaction ID: %d\n", ShmOCPP16Data->StopTransaction[gun_index].TransactionId);
  583. DEBUG_TTIA_INFO("TTIA server address: %s\n", ShmSysConfigAndInfo->SysConfig.TTIA_Info.server_addr);
  584. DEBUG_TTIA_INFO("TTIA server port: %d\n", ShmSysConfigAndInfo->SysConfig.TTIA_Info.server_port);
  585. DEBUG_TTIA_INFO("---------- Header ----------\n");
  586. DEBUG_TTIA_INFO("ProtocolID: APTS\n");
  587. DEBUG_TTIA_INFO("ProtocolVer: 0x02\n");
  588. DEBUG_TTIA_INFO("MessageID: 0xB0\n");
  589. DEBUG_TTIA_INFO("CustomerID: 0x%04X\n", ShmSysConfigAndInfo->SysConfig.TTIA_Info.busVenderId);
  590. DEBUG_TTIA_INFO("CarID: 0x0000\n");
  591. DEBUG_TTIA_INFO("IDStorage: 0x00\n");
  592. DEBUG_TTIA_INFO("DriverID: 0x00000000\n");
  593. DEBUG_TTIA_INFO("Sequence: %d\n", sn);
  594. DEBUG_TTIA_INFO("Reserved: 0x00\n");
  595. DEBUG_TTIA_INFO("Len: 0x3C\n");
  596. DEBUG_TTIA_INFO("--------- Payload ---------\n");
  597. DEBUG_TTIA_INFO("EquipmentProvider: %s\n", ShmSysConfigAndInfo->SysConfig.TTIA_Info.EquipmentProvider);
  598. DEBUG_TTIA_INFO("TransportationCompanyNo: %d\n", ShmSysConfigAndInfo->SysConfig.TTIA_Info.TransportationCompanyNo);
  599. DEBUG_TTIA_INFO("ChargeBoxId: %d\n", ShmSysConfigAndInfo->SysConfig.TTIA_Info.ChargeBoxId);
  600. DEBUG_TTIA_INFO("Gun index: %d\n", gun_index);
  601. DEBUG_TTIA_INFO("evseStation: %s\n", ShmSysConfigAndInfo->SysConfig.TTIA_Info.evseStation);
  602. DEBUG_TTIA_INFO("EV vehicle: %s\n", ShmOCPP16Data->StartTransaction[gun_index].IdTag);
  603. DEBUG_TTIA_INFO("EV mileage: 000000\n");
  604. DEBUG_TTIA_INFO("Session start data time: %s\n", ShmOCPP16Data->StartTransaction[gun_index].Timestamp);
  605. DEBUG_TTIA_INFO("Session stop data time: %s\n", ShmOCPP16Data->StopTransaction[gun_index].Timestamp);
  606. DEBUG_TTIA_INFO("Session charged energy (kwh): %f\n", (PresentChargedEnergy/10.0));
  607. DEBUG_TTIA_INFO("Session start SOC: %d\n", socStart);
  608. DEBUG_TTIA_INFO("Session end SOC: %d\n", socEnd);
  609. DEBUG_TTIA_INFO("=========================================\n");
  610. sn++;
  611. result = PASS;
  612. }
  613. else
  614. {
  615. DEBUG_ERROR("UDP sent out fail.\n");
  616. }
  617. }
  618. }
  619. return result;
  620. }
  621. //=========================================
  622. // Save configuration
  623. //=========================================
  624. int runShellCmd(const char*cmd)
  625. {
  626. int result = FAIL;
  627. char buf[256];
  628. FILE *fp;
  629. fp = popen(cmd, "r");
  630. if(fp != NULL)
  631. {
  632. while(fgets(buf, sizeof(buf), fp) != NULL)
  633. {
  634. DEBUG_INFO("%s\n", buf);
  635. }
  636. result = PASS;
  637. }
  638. pclose(fp);
  639. return result;
  640. }
  641. int StoreUsrConfigData(struct SysConfigData *UsrData)
  642. {
  643. int result = PASS;
  644. int fd,wrd;
  645. unsigned int i,Chk;
  646. unsigned char *ptr, *BufTmp;
  647. int MtdBlockSize = 0x300000;
  648. Chk=0;
  649. ptr=(unsigned char *)UsrData;
  650. if((BufTmp=malloc(MtdBlockSize))!=NULL)
  651. {
  652. memset(BufTmp,0,MtdBlockSize);
  653. memcpy(BufTmp,ptr,sizeof(struct SysConfigData));
  654. for(i=ARRAY_SIZE(UsrData->CsuBootLoadFwRev);i<MtdBlockSize-4;i++)
  655. Chk+=*(BufTmp+i);
  656. memcpy(BufTmp+MtdBlockSize-4, &Chk, 4);
  657. // Output configuration to file.
  658. fd = open("/mnt/EvseConfig.bin", O_RDWR|O_CREAT);
  659. if (fd < 0)
  660. {
  661. DEBUG_ERROR("open /mnt/EvseConfig.bin NG\n");
  662. free(BufTmp);
  663. return 0;
  664. }
  665. wrd=write(fd, BufTmp, MtdBlockSize);
  666. close(fd);
  667. if(wrd<MtdBlockSize)
  668. {
  669. DEBUG_ERROR("write /mnt/EvseConfig.bin NG\n");
  670. free(BufTmp);
  671. return 0;
  672. }
  673. DEBUG_INFO("EvseConfig write to file in /mnt OK.\n");
  674. DEBUG_INFO("Erase /dev/mtd10.\n");
  675. runShellCmd("flash_erase /dev/mtd10 0 0");
  676. DEBUG_INFO("Write /dev/mtd10.\n");
  677. runShellCmd("nandwrite -p /dev/mtd10 /mnt/EvseConfig.bin");
  678. DEBUG_INFO("Erase /dev/mtd11.\n");
  679. runShellCmd("flash_erase /dev/mtd11 0 0");
  680. DEBUG_INFO("Write /dev/mtd11.\n");
  681. runShellCmd("nandwrite -p /dev/mtd11 /mnt/EvseConfig.bin");
  682. system("rm -f /mnt/EvseConfig.bin");
  683. DEBUG_INFO("EvseConfig write to flash OK\n");
  684. }
  685. else
  686. {
  687. DEBUG_ERROR("alloc BlockSize NG\r\n");
  688. result = FAIL;
  689. }
  690. if(BufTmp!=NULL)
  691. free(BufTmp);
  692. return result;
  693. }
  694. //=========================================
  695. // Sqlite3 related function
  696. //=========================================
  697. static int selectSqlCount = 0;
  698. static int callback(void *data, int argc, char **argv, char **azColName){
  699. int i;
  700. //printf("%s: ", (const char*)data);
  701. selectSqlCount = argc;
  702. for(i = 0; i<argc; i++){
  703. // printf("%s = %s\n", azColName[i], argv[i] ? argv[i] : "NULL");
  704. }
  705. //printf("\n");
  706. return 0;
  707. }
  708. static int versioncallback(void *data, int argc, char **argv, char **azColName){
  709. //int i;
  710. //printf("%s:\n", (const char*)data);
  711. locallistVersion = (argv[5] ? atoi(argv[5]) : 0);
  712. DEBUG_INFO("Callback query locallistVersion : %d\n", locallistVersion);
  713. return 0;
  714. }
  715. static int IdTagcallback(void *data, int columenCount, char **columnValue, char **columnName){
  716. //printf("%s:\n", (const char*)data);
  717. //idTag
  718. sprintf(idTagAuthorization,"%s", columnValue[1] ? columnValue[1] : "NULL");
  719. sprintf(idTagQuery.idTagstr,"%s", columnValue[1] ? columnValue[1] : "NULL");
  720. //parentIdTag
  721. sprintf(idTagQuery.parentIdTag,"%s", columnValue[2] ? columnValue[2] : "NULL");
  722. //expir_date
  723. sprintf(idTagQuery.expiryDate,"%s", columnValue[3] ? columnValue[3] : "NULL");
  724. //status
  725. sprintf(idTagQuery.idTagstatus,"%s", columnValue[4] ? columnValue[4] : "NULL");
  726. //version
  727. if(columenCount > 5)
  728. idTagQuery.listVersionInt = atoi(columnValue[5]);
  729. //DEBUG_INFO("IdTag=%s\n", idTagAuthorization);
  730. return 0;
  731. }
  732. static int deleteIdTagcallback(void *data, int argc, char **argv, char **azColName)
  733. {
  734. // localversion = argv[5] ? atoi(argv[5]) : 0;
  735. // printf("localversion=%d\n", localversion);
  736. return 0;
  737. }
  738. int sqlite3_exec_callback(void *data, int n_columns, char **col_values, char **col_names)
  739. {
  740. for (int i = 0; i < n_columns; i++)
  741. {
  742. DEBUG_INFO("%s\t", col_values[i]);
  743. }
  744. DEBUG_INFO("\n");
  745. return 0;
  746. }
  747. int OCPP_cleanLocalCache()
  748. {
  749. char * sqlcleanLocalList = "delete from ocpp_auth_cache";
  750. char *errMsg = 0;
  751. int rc =sqlite3_exec(db, sqlcleanLocalList, 0, 0, &errMsg);
  752. if (SQLITE_OK != rc)
  753. {
  754. DEBUG_INFO("SQL error: %s\n",errMsg);
  755. return FALSE;
  756. }
  757. return TRUE;
  758. }
  759. int OCPP_addLocalCache(char *idTag, char *parentTage, char *expiryDate, char *status)
  760. {
  761. int isSuccess = TRUE;
  762. int ret = 0;
  763. //const char* data = "Callback function called";
  764. char sql[300];
  765. char zErrMsg[200];
  766. memset(sql, 0, 300);
  767. memset(zErrMsg, 0, 200);
  768. 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);
  769. //* Execute SQL statement */
  770. ret = sqlite3_exec(db, sql, callback, 0, (char **)&zErrMsg);
  771. if( ret != SQLITE_OK )
  772. {
  773. DEBUG_INFO("SQL error: %s\n", zErrMsg);
  774. isSuccess = FALSE;
  775. }
  776. return isSuccess;
  777. }
  778. void OCPP_getIdTagFromLocalCache(char idTag[])
  779. {
  780. int rc = 0;
  781. char sql[100];
  782. char zErrMsg[100];
  783. memset(sql, 0, 100);
  784. memset(zErrMsg, 0, 100);
  785. memset(idTagAuthorization, 0, ARRAY_SIZE(idTagAuthorization));
  786. memset(&idTagQuery, 0, sizeof(idTagQuery));
  787. sprintf(sql,"select * from ocpp_auth_cache where idtag='%s'", idTag);
  788. /* Execute SQL statement */
  789. rc = sqlite3_exec(db, sql, IdTagcallback, 0, (char **)&zErrMsg);
  790. if( rc != SQLITE_OK )
  791. {
  792. DEBUG_INFO("SQL error: %s\n", zErrMsg);
  793. }
  794. }
  795. void OCPP_getListVerion()
  796. {
  797. int rc = 0;
  798. // const char* data = "Callback function called";
  799. char sql[100];
  800. char zErrMsg[100];
  801. memset(sql, 0, 100);
  802. memset(zErrMsg, 0, 100);
  803. strcpy(sql, "select * from ocpp_auth_local order by version desc, idx desc limit 1");
  804. /* Execute SQL statement */
  805. rc = sqlite3_exec(db, sql, versioncallback, 0, (char **)&zErrMsg);
  806. if( rc != SQLITE_OK )
  807. {
  808. DEBUG_INFO("SQL error: %s\n", zErrMsg);
  809. }
  810. }
  811. void OCPP_get_TableAuthlocalAllData(void)
  812. {
  813. int rc = 0;
  814. char sql[100];
  815. char zErrMsg[100];
  816. memset(sql, 0, 100);
  817. memset(zErrMsg, 0, 100);
  818. sprintf(sql,"select * from ocpp_auth_local ");
  819. /* Execute SQL statement */
  820. rc = sqlite3_exec(db, sql, &sqlite3_exec_callback, 0,(char **)&zErrMsg);
  821. if( rc != SQLITE_OK )
  822. {
  823. DEBUG_INFO("SQL error: %s\n", zErrMsg);
  824. }
  825. //return ver;
  826. }
  827. int OCPP_cleanLocalList()
  828. {
  829. char * sqlcleanLocalList = "delete from ocpp_auth_local";
  830. char *errMsg = 0;
  831. int rc =sqlite3_exec(db, sqlcleanLocalList, 0, 0, &errMsg);
  832. if (SQLITE_OK != rc)
  833. {
  834. DEBUG_INFO("%s\n",errMsg);
  835. return FALSE;
  836. }
  837. return TRUE;
  838. }
  839. int OCPP_addLocalList(int version, char *idTag, char *parentTage, char *expiryDate, char *status)
  840. {
  841. int isSuccess = FALSE;
  842. int ret = 0;
  843. //const char* data = "Callback function called";
  844. char sql[300];
  845. char zErrMsg[200];
  846. memset(sql, 0, 300);
  847. memset(zErrMsg, 0, 200);
  848. 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);
  849. //* Execute SQL statement */
  850. ret = sqlite3_exec(db, sql, callback, 0, (char **)&zErrMsg);
  851. if( ret != SQLITE_OK )
  852. {
  853. DEBUG_INFO("SQL error: %s\n", zErrMsg);
  854. return isSuccess;
  855. }
  856. memset(sql, 0, 300);
  857. sprintf(sql, "UPDATE ocpp_auth_local SET version=%d",version);
  858. ret = sqlite3_exec(db, sql, NULL, NULL, (char **)&zErrMsg);
  859. if( ret != SQLITE_OK )
  860. {
  861. DEBUG_INFO("SQL error: %s\n", zErrMsg);
  862. return isSuccess;
  863. }
  864. isSuccess = TRUE;
  865. return isSuccess;
  866. }
  867. void OCPP_getIdTagFromLocalList(char idTag[])
  868. {
  869. int rc = 0;
  870. // const char* data = "Callback function called";
  871. char sql[100];
  872. char zErrMsg[100];
  873. memset(sql, 0, 100);
  874. memset(zErrMsg, 0, 100);
  875. memset(idTagAuthorization, 0, ARRAY_SIZE(idTagAuthorization));
  876. memset(&idTagQuery, 0, sizeof(idTagQuery));
  877. //DEBUG_INFO("look up card: %s in ocpp_auth_local table", idTag);
  878. sprintf(sql,"select * from ocpp_auth_local where idtag='%s'", idTag);
  879. /* Execute SQL statement */
  880. rc = sqlite3_exec(db, sql, IdTagcallback, 0, (char **)&zErrMsg);
  881. if( rc != SQLITE_OK )
  882. {
  883. DEBUG_INFO("SQL error: %s\n", zErrMsg);
  884. }
  885. //return ver;
  886. }
  887. void OCPP_deleteIdTagFromLocalList(char idTag[])
  888. {
  889. //int ver = 0;
  890. //int isSuccess = FALSE;
  891. int rc = 0;
  892. char sql[100];
  893. char zErrMsg[100];
  894. memset(sql, 0, 100);
  895. memset(zErrMsg, 0, 100);
  896. sprintf(sql,"DELETE from ocpp_auth_local where idtag='%s'; SELECT * from ocpp_auth_local;", idTag);
  897. //* Execute SQL statement */
  898. rc = sqlite3_exec(db, sql, deleteIdTagcallback, 0,(char **)&zErrMsg);
  899. if( rc != SQLITE_OK )
  900. {
  901. DEBUG_INFO("SQL error: %s\n", zErrMsg);
  902. }
  903. }
  904. int getCurrentYear()
  905. {
  906. int result = 0;
  907. time_t CurrentTime;
  908. struct tm *tm;
  909. CurrentTime = time(NULL);
  910. tm=localtime(&CurrentTime);
  911. result = (tm->tm_year + 1900);
  912. return result;
  913. }
  914. int OCPP_insert_transaction_msg(uint8_t isStartTransaction, char *transactionMsg)
  915. {
  916. int result = PASS;
  917. char* errMsg = NULL;
  918. char sqlStr[8192];
  919. sprintf(sqlStr, "insert into ocpp_transaction_record(occurDatetime, message_type, message_content) values(CURRENT_TIMESTAMP, '%s', '%s');", (isStartTransaction?"startTransaction":"stopTransaction"), transactionMsg);
  920. if (sqlite3_exec(db, sqlStr, 0, 0, &errMsg) != SQLITE_OK)
  921. {
  922. result = FAIL;
  923. DEBUG_WARN( "Insert local transaction record error message: %s\n", errMsg);
  924. }
  925. 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));
  926. if (sqlite3_exec(db, sqlStr, 0, 0, &errMsg) != SQLITE_OK)
  927. {
  928. result = FAIL;
  929. DEBUG_WARN( "delete local transaction record error message: %s\n", errMsg);
  930. }
  931. return result;
  932. }
  933. int OCPP_updatePeriodEnergy(uint8_t gun_index)
  934. {
  935. int isSuccess = TRUE;
  936. int tempIndex;
  937. json_object *EnergyDataTransfer = json_object_new_object();
  938. json_object *periodEnergys = json_object_new_object();
  939. char sql[1024];
  940. char zErrMsg[200];
  941. memset(sql, 0, ARRAY_SIZE(sql));
  942. memset(zErrMsg, 0, ARRAY_SIZE(zErrMsg));
  943. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  944. {
  945. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  946. {
  947. tempIndex = ((gun_index==2) ? 1: 0);
  948. }
  949. else
  950. {
  951. tempIndex = gun_index;
  952. }
  953. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  954. {
  955. if ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex))
  956. {
  957. json_object_object_add(EnergyDataTransfer, "txId", json_object_new_int(ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId));
  958. for(uint8_t idxPeriod=0;idxPeriod<ARRAY_SIZE(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].presentChargedEnergyPeriod);idxPeriod++)
  959. {
  960. uint8_t period[3];
  961. sprintf((char*)period, "%d", idxPeriod);
  962. json_object_object_add(periodEnergys, (const char *)period, json_object_new_double(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].presentChargedEnergyPeriod[idxPeriod]));
  963. }
  964. json_object_object_add(EnergyDataTransfer, "periodEnergy", periodEnergys);
  965. } //end of the same index
  966. }//end of for CHAdeMO_QUANTITY
  967. }
  968. else if(gunType[gun_index] == GUN_TYPE_CCS)
  969. {
  970. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  971. {
  972. tempIndex = ((gun_index==2) ? 1: 0);
  973. }
  974. else
  975. {
  976. tempIndex = gun_index;
  977. }
  978. for (int index = 0; index < CCS_QUANTITY; index++)
  979. {
  980. if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  981. {
  982. json_object_object_add(EnergyDataTransfer, "txId", json_object_new_int(ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId));
  983. for(uint8_t idxPeriod=0;idxPeriod<ARRAY_SIZE(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].presentChargedEnergyPeriod);idxPeriod++)
  984. {
  985. uint8_t period[3];
  986. sprintf((char*)period, "%d", idxPeriod);
  987. json_object_object_add(periodEnergys, (const char *)period, json_object_new_double(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].presentChargedEnergyPeriod[idxPeriod]));
  988. }
  989. json_object_object_add(EnergyDataTransfer, "periodEnergy", periodEnergys);
  990. } //end of the same index
  991. } // end of for CCS_QUANTITY
  992. }
  993. else if(gunType[gun_index] == GUN_TYPE_GBT)
  994. {
  995. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  996. {
  997. tempIndex = ((gun_index==2) ? 1: 0);
  998. }
  999. else
  1000. {
  1001. tempIndex = gun_index;
  1002. }
  1003. for (int index = 0; index < GB_QUANTITY; index++)
  1004. {
  1005. if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  1006. {
  1007. json_object_object_add(EnergyDataTransfer, "txId", json_object_new_int(ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId));
  1008. for(uint8_t idxPeriod=0;idxPeriod<ARRAY_SIZE(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].presentChargedEnergyPeriod);idxPeriod++)
  1009. {
  1010. uint8_t period[3];
  1011. sprintf((char*)period, "%d", idxPeriod);
  1012. json_object_object_add(periodEnergys, (const char *)period, json_object_new_double(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].presentChargedEnergyPeriod[idxPeriod]));
  1013. }
  1014. json_object_object_add(EnergyDataTransfer, "periodEnergy", periodEnergys);
  1015. } //end of the same index
  1016. } // end of for GB_QUANTITY
  1017. }
  1018. else if(gunType[gun_index] == GUN_TYPE_DO)
  1019. {
  1020. tempIndex = gun_index;
  1021. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  1022. {
  1023. if(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  1024. {
  1025. json_object_object_add(EnergyDataTransfer, "txId", json_object_new_int(ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId));
  1026. for(uint8_t idxPeriod=0;idxPeriod<ARRAY_SIZE(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.presentChargedEnergyPeriod);idxPeriod++)
  1027. {
  1028. uint8_t period[3];
  1029. sprintf((char*)period, "%d", idxPeriod);
  1030. json_object_object_add(periodEnergys, (const char *)period, json_object_new_double(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.presentChargedEnergyPeriod[idxPeriod]));
  1031. }
  1032. json_object_object_add(EnergyDataTransfer, "periodEnergy", periodEnergys);
  1033. } //end of the same index
  1034. }
  1035. }
  1036. else
  1037. {
  1038. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  1039. {
  1040. tempIndex = 2;
  1041. }
  1042. else
  1043. {
  1044. tempIndex = gun_index;
  1045. }
  1046. for (int index = 0; index < AC_QUANTITY; index++)
  1047. {
  1048. if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  1049. {
  1050. json_object_object_add(EnergyDataTransfer, "txId", json_object_new_int(ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId));
  1051. for(uint8_t idxPeriod=0;idxPeriod<ARRAY_SIZE(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].presentChargedEnergyPeriod);idxPeriod++)
  1052. {
  1053. uint8_t period[3];
  1054. sprintf((char*)period, "%d", idxPeriod);
  1055. json_object_object_add(periodEnergys, (const char *)period, json_object_new_double(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].presentChargedEnergyPeriod[idxPeriod]));
  1056. }
  1057. json_object_object_add(EnergyDataTransfer, "periodEnergy", periodEnergys);
  1058. }//end of the same index
  1059. }//end of for AC_QUANTITY
  1060. }
  1061. 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));
  1062. json_object_put(EnergyDataTransfer);
  1063. //* Execute SQL statement */
  1064. if( sqlite3_exec(db, sql, callback, 0, (char **)&zErrMsg) != SQLITE_OK )
  1065. {
  1066. DEBUG_WARN("SQL error: %s\n", zErrMsg);
  1067. isSuccess = FALSE;
  1068. }
  1069. sprintf(sql, "delete from ocpp_period_energy where (occurDatetime < '%04d-01-01 00:00:00');", (getCurrentYear()-3));
  1070. if (sqlite3_exec(db, sql, 0, 0, (char **)&zErrMsg) != SQLITE_OK)
  1071. {
  1072. DEBUG_WARN( "delete period energy record error message: %s\n", zErrMsg);
  1073. isSuccess = FALSE;
  1074. }
  1075. return isSuccess;
  1076. }
  1077. int OCPP_getPeriodEnergyToDataTransfer(int32_t transactionId)
  1078. {
  1079. int isSuccess = TRUE;
  1080. char sql[512];
  1081. char zErrMsg[200];
  1082. int rows, cols;
  1083. char **resultData;
  1084. sprintf(sql, "select * from ocpp_period_energy where transactionId=%d;", transactionId);
  1085. /* Execute SQL statement */
  1086. if( sqlite3_get_table(db, sql, &resultData, &rows, &cols, (char **)&zErrMsg) != SQLITE_OK)
  1087. {
  1088. DEBUG_WARN("SQL error: %s\n", zErrMsg);
  1089. isSuccess = FALSE;
  1090. }
  1091. else
  1092. {
  1093. if((rows > 0) && (atoi(resultData[4]) > 0))
  1094. {
  1095. sprintf((char*)ShmOCPP16Data->DataTransfer[0].ResponseData, "%s", resultData[7]);
  1096. }
  1097. else
  1098. {
  1099. DEBUG_WARN("There is not match transaction data.\n");
  1100. isSuccess = FALSE;
  1101. }
  1102. }
  1103. return isSuccess;
  1104. }
  1105. 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)
  1106. {
  1107. int result = PASS;
  1108. char* errMsg = NULL;
  1109. char sqlStr[8192];
  1110. 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');",
  1111. txId, creditNo, deductResult, isDonateInvoice, amount, vemData, ROC, RRN, approvalNo, storeId);
  1112. if (sqlite3_exec(db, sqlStr, 0, 0, &errMsg) != SQLITE_OK)
  1113. {
  1114. result = FAIL;
  1115. DEBUG_WARN( "Insert local report_deduct_info error message: %s\n", errMsg);
  1116. }
  1117. sprintf(sqlStr, "delete from report_deduct_info where (idx < (select idx from report_deduct_info order by idx desc limit 1)-5000);");
  1118. if (sqlite3_exec(db, sqlStr, 0, 0, &errMsg) != SQLITE_OK)
  1119. {
  1120. result = FAIL;
  1121. DEBUG_WARN( "delete local report_deduct_info error message: %s\n", errMsg);
  1122. }
  1123. return result;
  1124. }
  1125. int OCPP_update_deduct_info(int txId, char *creditNo)
  1126. {
  1127. int result = PASS;
  1128. char* errMsg = NULL;
  1129. char sqlStr[8192];
  1130. sprintf(sqlStr, "update report_deduct_info set isUploaded='1' where txId='%d' and creditNo='%s';", txId, creditNo);
  1131. if (sqlite3_exec(db, sqlStr, 0, 0, &errMsg) != SQLITE_OK)
  1132. {
  1133. result = FAIL;
  1134. DEBUG_WARN( "Update local report_deduct_info error message: %s\n", errMsg);
  1135. }
  1136. return result;
  1137. }
  1138. int queryDeductCallBack(void *data, int columenCount, char **columnValue, char **columnName)
  1139. {
  1140. sprintf((char*)ShmOCPP16Data->DataTransfer[0].VendorId, "%s", ShmSysConfigAndInfo->SysConfig.chargePointVendor);
  1141. sprintf((char*)ShmOCPP16Data->DataTransfer[0].MessageId,"%s","ID_CreditDeductResult");
  1142. sprintf((char*)ShmOCPP16Data->DataTransfer[0].Data, "{\\\"txId\\\":%d,\\\"creditNo\\\":\\\"%s\\\",\\\"deductResult\\\":%s,\\\"isDonateInvoice\\\":%s,\\\"amount\\\":%s,\\\"approvalNo\\\":\\\"%s\\\"}",
  1143. atoi(columnValue[1]),
  1144. columnValue[2],
  1145. atoi(columnValue[3])==1?"true":"false",
  1146. atoi(columnValue[4])==1?"true":"false",
  1147. columnValue[5],
  1148. columnValue[9]);
  1149. ShmOCPP16Data->CsMsg.bits[0].DataTransferReq = 1;
  1150. return 0;
  1151. }
  1152. void OCPP_query_deduct_info()
  1153. {
  1154. int rc = 0;
  1155. char sql[100];
  1156. char zErrMsg[100];
  1157. sprintf(sql,"select * from report_deduct_info where isUploaded='0' order by idx limit 1");
  1158. /* Execute SQL statement */
  1159. rc = sqlite3_exec(db, sql, queryDeductCallBack, 0, (char **)&zErrMsg);
  1160. if( rc != SQLITE_OK )
  1161. {
  1162. DEBUG_INFO("SQL error: %s\n", zErrMsg);
  1163. }
  1164. }
  1165. void reportReaderStatus(int gun_index)
  1166. {
  1167. struct timeval tmnow;
  1168. struct tm *tm;
  1169. char buf[28];//, usec_buf[6];
  1170. gettimeofday(&tmnow, NULL);
  1171. time_t t;
  1172. t = time(NULL);
  1173. /*UTC time and date*/
  1174. tm = gmtime(&t);
  1175. strftime(buf,28,"%Y-%m-%dT%H:%M:%SZ", tm);
  1176. #if 0 // remove temporally
  1177. strftime(buf,30,"%Y-%m-%dT%H:%M:%S", tm);
  1178. strcat(buf,".");
  1179. sprintf(usec_buf,"%dZ",(int)tmnow.tv_usec);
  1180. strcat(buf,usec_buf);
  1181. #endif
  1182. sprintf((char*)ShmOCPP16Data->DataTransfer[gun_index].VendorId, "%s", ShmSysConfigAndInfo->SysConfig.chargePointVendor);
  1183. sprintf((char*)ShmOCPP16Data->DataTransfer[gun_index].MessageId,"%s","ID_ReaderStatus");
  1184. sprintf((char*)ShmOCPP16Data->DataTransfer[gun_index].Data, "{\\\"connectorId\\\":%d,\\\"readerStatus\\\":%d,\\\"timestamp\\\":\\\"%s\\\",\\\"SerialNo\\\":\\\"%s\\\",\\\"creditNo\\\":\\\"%s\\\",\\\"VEMData\\\":\\\"%s\\\"}",
  1185. (gun_index+1),
  1186. ShmOCPP16Data->TcciCustomData.ReaderStatus[gun_index].readerStatus,
  1187. buf,
  1188. ShmOCPP16Data->TcciCustomData.SerialNo[gun_index],
  1189. ShmOCPP16Data->TcciCustomData.ReaderStatus[gun_index].creditNo,
  1190. ShmOCPP16Data->TcciCustomData.VEMData[gun_index]);
  1191. ShmOCPP16Data->CsMsg.bits[gun_index].DataTransferReq = 1;
  1192. }
  1193. //==========================================
  1194. // Check time passed since today
  1195. //==========================================
  1196. long long DiffTimebWithNow(struct timeb ST)
  1197. {
  1198. //return milli-second
  1199. struct timeb ET;
  1200. long long StartTime,StopTime;
  1201. ftime(&ET);
  1202. StartTime=(long long)ST.time;
  1203. StopTime=(long long)ET.time;
  1204. return ((StopTime-StartTime)*1000) + (ET.millitm-ST.millitm);
  1205. }
  1206. int getTimePassSinceToday(uint8_t gun_index)
  1207. {
  1208. int result = -1;
  1209. static time_t lastTime[4];
  1210. time_t t;
  1211. struct tm *tmStartToday;
  1212. struct timeb tbStartToday;
  1213. t=time(NULL);
  1214. if(difftime(t, lastTime[gun_index])>0)
  1215. {
  1216. tmStartToday=localtime(&t);
  1217. tmStartToday->tm_hour = 0;
  1218. tmStartToday->tm_min = 0;
  1219. tmStartToday->tm_sec = 0;
  1220. tbStartToday.time = mktime(tmStartToday);
  1221. tbStartToday.millitm = 0;
  1222. result = DiffTimebWithNow(tbStartToday)/1000;
  1223. lastTime[gun_index] = t;
  1224. }
  1225. return result;
  1226. }
  1227. void getNowDatetime(uint8_t *data)
  1228. {
  1229. time_t t = time(NULL);
  1230. struct tm tm = *localtime(&t);
  1231. 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);
  1232. }
  1233. int syncDateTimeRTC(uint8_t *data)
  1234. {
  1235. struct ParsingResult
  1236. {
  1237. int result;
  1238. int scanedElement;
  1239. int year;
  1240. int month;
  1241. int mday;
  1242. int hour;
  1243. int min;
  1244. int sec;
  1245. int tz_hour;
  1246. int tz_min;
  1247. float minSec;
  1248. }result;
  1249. struct tm tmOrg;
  1250. struct tm *tmTarget;
  1251. struct timeb tbTarget;
  1252. char buf[128];
  1253. memset(&result, 0x00, sizeof(struct ParsingResult));
  1254. result.result = PASS;
  1255. if(strstr((char*)data, ".") != NULL)
  1256. {
  1257. // Original data with mini second
  1258. if(strstr((char*)data, "Z") != NULL)
  1259. {
  1260. // Original data with Z
  1261. result.scanedElement = sscanf((char*)data, "%d-%d-%dT%d:%d:%d.%fZ",
  1262. &result.year,
  1263. &result.month,
  1264. &result.mday,
  1265. &result.hour,
  1266. &result.min,
  1267. &result.sec,
  1268. &result.minSec);
  1269. }
  1270. else
  1271. {
  1272. // Original data without Z
  1273. result.scanedElement = sscanf((char*)data, "%d-%d-%dT%d:%d:%d.%f%d:%d",
  1274. &result.year,
  1275. &result.month,
  1276. &result.mday,
  1277. &result.hour,
  1278. &result.min,
  1279. &result.sec,
  1280. &result.minSec,
  1281. &result.tz_hour,
  1282. &result.tz_min);
  1283. }
  1284. }
  1285. else
  1286. {
  1287. // Original data without mini second
  1288. if(strstr((char*)data, "Z") != NULL)
  1289. {
  1290. // Original data with Z
  1291. result.scanedElement = sscanf((char*)data, "%d-%d-%dT%d:%d:%dZ",
  1292. &result.year,
  1293. &result.month,
  1294. &result.mday,
  1295. &result.hour,
  1296. &result.min,
  1297. &result.sec);
  1298. }
  1299. else
  1300. {
  1301. // Original data without Z
  1302. result.scanedElement = sscanf((char*)data, "%d-%d-%dT%d:%d:%d%d:%d",
  1303. &result.year,
  1304. &result.month,
  1305. &result.mday,
  1306. &result.hour,
  1307. &result.min,
  1308. &result.sec,
  1309. &result.tz_hour,
  1310. &result.tz_min);
  1311. }
  1312. }
  1313. tmOrg.tm_year = result.year - 1900;
  1314. tmOrg.tm_mon = result.month - 1;
  1315. tmOrg.tm_mday = result.mday;
  1316. tmOrg.tm_hour = result.hour;
  1317. tmOrg.tm_min = result.min;
  1318. tmOrg.tm_sec = result.sec;
  1319. tmOrg.tm_gmtoff = 0;
  1320. tbTarget.time = mktime(&tmOrg);
  1321. tbTarget.timezone = 0;
  1322. tbTarget.time -= (result.tz_hour*3600) + (result.tz_min*60*(result.tz_hour>=0?1:-1));
  1323. tmTarget = gmtime(&tbTarget.time);
  1324. 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);
  1325. //DEBUG_INFO(" org date time: %s\n", data);
  1326. //DEBUG_INFO("parse date time: %s\n", buf);
  1327. system(buf);
  1328. system("/sbin/hwclock -w --systohc");
  1329. if(result.scanedElement < 6)
  1330. result.result = FAIL;
  1331. return result.result;
  1332. }
  1333. //==========================================
  1334. // GetCompositeSchedule logic related function
  1335. //==========================================
  1336. int DiffTimebSec(struct timeb ST, struct timeb ET)
  1337. {
  1338. //return milli-second
  1339. unsigned int StartTime,StopTime;
  1340. StartTime=(unsigned int)ST.time;
  1341. StopTime=(unsigned int)ET.time;
  1342. return (StopTime-StartTime);
  1343. }
  1344. int DiffTimebWithNowSec(struct timeb ST)
  1345. {
  1346. //return milli-second
  1347. struct timeb ET;
  1348. unsigned int StartTime,StopTime;
  1349. ftime(&ET);
  1350. StartTime=(unsigned int)ST.time;
  1351. StopTime=(unsigned int)ET.time;
  1352. return (StopTime-StartTime);
  1353. }
  1354. int getStartStop(uint8_t *start, uint8_t *stop)
  1355. {
  1356. struct ParsingResult
  1357. {
  1358. int result;
  1359. int scanedElement;
  1360. int year;
  1361. int month;
  1362. int mday;
  1363. int hour;
  1364. int min;
  1365. int sec;
  1366. int tz_hour;
  1367. int tz_min;
  1368. float minSec;
  1369. };
  1370. struct ParsingResult parseStart;
  1371. struct ParsingResult parseStop;
  1372. int result = -1;
  1373. struct tm tmStart;
  1374. struct timeb tbStart;
  1375. struct tm tmStop;
  1376. struct timeb tbStop;
  1377. memset(&parseStart, 0x00, sizeof(struct ParsingResult));
  1378. memset(&parseStop, 0x00, sizeof(struct ParsingResult));
  1379. // Scan start & stop date time
  1380. if(strstr((char*)start, ".") != NULL)
  1381. {
  1382. // Original data with mini second
  1383. if(strstr((char*)start, "Z") != NULL)
  1384. {
  1385. // Original data with Z
  1386. parseStart.scanedElement = sscanf((char*)start, "%d-%d-%dT%d:%d:%d.%fZ",
  1387. &parseStart.year,
  1388. &parseStart.month,
  1389. &parseStart.mday,
  1390. &parseStart.hour,
  1391. &parseStart.min,
  1392. &parseStart.sec,
  1393. &parseStart.minSec);
  1394. }
  1395. else
  1396. {
  1397. // Original data without Z
  1398. parseStart.scanedElement = sscanf((char*)start, "%d-%d-%dT%d:%d:%d.%f%d:%d",
  1399. &parseStart.year,
  1400. &parseStart.month,
  1401. &parseStart.mday,
  1402. &parseStart.hour,
  1403. &parseStart.min,
  1404. &parseStart.sec,
  1405. &parseStart.minSec,
  1406. &parseStart.tz_hour,
  1407. &parseStart.tz_min);
  1408. }
  1409. }
  1410. else
  1411. {
  1412. // Original data without mini second
  1413. if(strstr((char*)start, "Z") != NULL)
  1414. {
  1415. // Original data with Z
  1416. parseStart.scanedElement = sscanf((char*)start, "%d-%d-%dT%d:%d:%dZ",
  1417. &parseStart.year,
  1418. &parseStart.month,
  1419. &parseStart.mday,
  1420. &parseStart.hour,
  1421. &parseStart.min,
  1422. &parseStart.sec);
  1423. }
  1424. else
  1425. {
  1426. // Original data without Z
  1427. parseStart.scanedElement = sscanf((char*)start, "%d-%d-%dT%d:%d:%d%d:%d",
  1428. &parseStart.year,
  1429. &parseStart.month,
  1430. &parseStart.mday,
  1431. &parseStart.hour,
  1432. &parseStart.min,
  1433. &parseStart.sec,
  1434. &parseStart.tz_hour,
  1435. &parseStart.tz_min);
  1436. }
  1437. }
  1438. if(strstr((char*)stop, ".") != NULL)
  1439. {
  1440. // Original data with mini second
  1441. if(strstr((char*)stop, "Z") != NULL)
  1442. {
  1443. // Original data with Z
  1444. parseStop.scanedElement = sscanf((char*)stop, "%d-%d-%dT%d:%d:%d.%fZ",
  1445. &parseStop.year,
  1446. &parseStop.month,
  1447. &parseStop.mday,
  1448. &parseStop.hour,
  1449. &parseStop.min,
  1450. &parseStop.sec,
  1451. &parseStop.minSec);
  1452. }
  1453. else
  1454. {
  1455. // Original data without Z
  1456. parseStop.scanedElement = sscanf((char*)stop, "%d-%d-%dT%d:%d:%d.%f%d:%d",
  1457. &parseStop.year,
  1458. &parseStop.month,
  1459. &parseStop.mday,
  1460. &parseStop.hour,
  1461. &parseStop.min,
  1462. &parseStop.sec,
  1463. &parseStop.minSec,
  1464. &parseStop.tz_hour,
  1465. &parseStop.tz_min);
  1466. }
  1467. }
  1468. else
  1469. {
  1470. // Original data without mini second
  1471. if(strstr((char*)stop, "Z") != NULL)
  1472. {
  1473. // Original data with Z
  1474. parseStop.scanedElement = sscanf((char*)stop, "%d-%d-%dT%d:%d:%dZ",
  1475. &parseStop.year,
  1476. &parseStop.month,
  1477. &parseStop.mday,
  1478. &parseStop.hour,
  1479. &parseStop.min,
  1480. &parseStop.sec);
  1481. }
  1482. else
  1483. {
  1484. // Original data without Z
  1485. parseStop.scanedElement = sscanf((char*)stop, "%d-%d-%dT%d:%d:%d%d:%d",
  1486. &parseStop.year,
  1487. &parseStop.month,
  1488. &parseStop.mday,
  1489. &parseStop.hour,
  1490. &parseStop.min,
  1491. &parseStop.sec,
  1492. &parseStop.tz_hour,
  1493. &parseStop.tz_min);
  1494. }
  1495. }
  1496. // Calculate date time difference
  1497. if((parseStart.scanedElement >=6) &&
  1498. (parseStop.scanedElement >=6))
  1499. {
  1500. //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);
  1501. //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);
  1502. tmStart.tm_year = parseStart.year - 1900;
  1503. tmStart.tm_mon = parseStart.month - 1;
  1504. tmStart.tm_mday = parseStart.mday;
  1505. tmStart.tm_hour = parseStart.hour;
  1506. tmStart.tm_min = parseStart.min;
  1507. tmStart.tm_sec = parseStart.sec;
  1508. tmStart.tm_gmtoff = 0;
  1509. tbStart.time = mktime(&tmStart);
  1510. tbStart.timezone = 0;
  1511. tbStart.time -= (parseStart.tz_hour*3600) + (parseStart.tz_min*60*(parseStart.tz_hour>=0?1:-1));
  1512. tmStop.tm_year = parseStop.year - 1900;
  1513. tmStop.tm_mon = parseStop.month - 1;
  1514. tmStop.tm_mday = parseStop.mday;
  1515. tmStop.tm_hour = parseStop.hour;
  1516. tmStop.tm_min = parseStop.min;
  1517. tmStop.tm_sec = parseStop.sec;
  1518. tmStop.tm_gmtoff = 0;
  1519. tbStop.time = mktime(&tmStop);
  1520. tbStop.timezone = 0;
  1521. tbStop.time -= (parseStop.tz_hour*3600) + (parseStop.tz_min*60*(parseStop.tz_hour>=0?1:-1));
  1522. result = DiffTimebSec(tbStart, tbStop);
  1523. //DEBUG_INFO("getStartStop(): %d\n", result);
  1524. }
  1525. else
  1526. {
  1527. DEBUG_WARN("Start or stop date parsing error.\r\n");
  1528. }
  1529. return result;
  1530. }
  1531. int isOvertNow(uint8_t *start)
  1532. {
  1533. int result = NO;
  1534. struct ParsingResult
  1535. {
  1536. int result;
  1537. int scanedElement;
  1538. int year;
  1539. int month;
  1540. int mday;
  1541. int hour;
  1542. int min;
  1543. int sec;
  1544. int tz_hour;
  1545. int tz_min;
  1546. float minSec;
  1547. }parsingResult;
  1548. struct tm tmStart;
  1549. struct timeb tbStart;
  1550. memset(&parsingResult, 0x00, sizeof(struct ParsingResult));
  1551. if(strstr((char*)start, ".") != NULL)
  1552. {
  1553. // Original data with mini second
  1554. if(strstr((char*)start, "Z") != NULL)
  1555. {
  1556. // Original data with Z
  1557. parsingResult.scanedElement = sscanf((char*)start, "%d-%d-%dT%d:%d:%d.%fZ",
  1558. &parsingResult.year,
  1559. &parsingResult.month,
  1560. &parsingResult.mday,
  1561. &parsingResult.hour,
  1562. &parsingResult.min,
  1563. &parsingResult.sec,
  1564. &parsingResult.minSec);
  1565. }
  1566. else
  1567. {
  1568. // Original data without Z
  1569. parsingResult.scanedElement = sscanf((char*)start, "%d-%d-%dT%d:%d:%d.%f%d:%d",
  1570. &parsingResult.year,
  1571. &parsingResult.month,
  1572. &parsingResult.mday,
  1573. &parsingResult.hour,
  1574. &parsingResult.min,
  1575. &parsingResult.sec,
  1576. &parsingResult.minSec,
  1577. &parsingResult.tz_hour,
  1578. &parsingResult.tz_min);
  1579. }
  1580. }
  1581. else
  1582. {
  1583. // Original data without mini second
  1584. if(strstr((char*)start, "Z") != NULL)
  1585. {
  1586. // Original data with Z
  1587. parsingResult.scanedElement = sscanf((char*)start, "%d-%d-%dT%d:%d:%dZ",
  1588. &parsingResult.year,
  1589. &parsingResult.month,
  1590. &parsingResult.mday,
  1591. &parsingResult.hour,
  1592. &parsingResult.min,
  1593. &parsingResult.sec);
  1594. }
  1595. else
  1596. {
  1597. // Original data without Z
  1598. parsingResult.scanedElement = sscanf((char*)start, "%d-%d-%dT%d:%d:%d%d:%d",
  1599. &parsingResult.year,
  1600. &parsingResult.month,
  1601. &parsingResult.mday,
  1602. &parsingResult.hour,
  1603. &parsingResult.min,
  1604. &parsingResult.sec,
  1605. &parsingResult.tz_hour,
  1606. &parsingResult.tz_min);
  1607. }
  1608. }
  1609. if(parsingResult.scanedElement >= 6)
  1610. {
  1611. tmStart.tm_year = parsingResult.year - 1900;
  1612. tmStart.tm_mon = parsingResult.month - 1;
  1613. tmStart.tm_mday = parsingResult.mday;
  1614. tmStart.tm_hour = parsingResult.hour;
  1615. tmStart.tm_min = parsingResult.min;
  1616. tmStart.tm_sec = parsingResult.sec;
  1617. tmStart.tm_gmtoff = 0;
  1618. tbStart.time = mktime(&tmStart);
  1619. tbStart.timezone = 0;
  1620. tbStart.millitm = 0;
  1621. tbStart.time -= (parsingResult.tz_hour*3600) + (parsingResult.tz_min*60*(parsingResult.tz_hour>=0?1:-1));
  1622. if(DiffTimebWithNowSec(tbStart) <= 0)
  1623. result = NO;
  1624. else
  1625. result = YES;
  1626. }
  1627. else
  1628. {
  1629. DEBUG_WARN("Start date parsing error.\n");
  1630. }
  1631. return result;
  1632. }
  1633. int getStartSinceRecurring(uint8_t *start, uint8_t *stop, uint8_t isDaily)
  1634. {
  1635. struct ParsingResult
  1636. {
  1637. int result;
  1638. int scanedElement;
  1639. int year;
  1640. int month;
  1641. int mday;
  1642. int hour;
  1643. int min;
  1644. int sec;
  1645. int tz_hour;
  1646. int tz_min;
  1647. float minSec;
  1648. };
  1649. struct ParsingResult parseStart;
  1650. struct ParsingResult parseStop;
  1651. int result = -1;
  1652. struct tm tmStart;
  1653. struct timeb tbStart;
  1654. struct tm tmStop;
  1655. struct timeb tbStop;
  1656. memset(&parseStart, 0x00, sizeof(struct ParsingResult));
  1657. memset(&parseStop, 0x00, sizeof(struct ParsingResult));
  1658. // Scan start & stop date time
  1659. if(strstr((char*)start, ".") != NULL)
  1660. {
  1661. // Original data with mini second
  1662. if(strstr((char*)start, "Z") != NULL)
  1663. {
  1664. // Original data with Z
  1665. parseStart.scanedElement = sscanf((char*)start, "%d-%d-%dT%d:%d:%d.%fZ",
  1666. &parseStart.year,
  1667. &parseStart.month,
  1668. &parseStart.mday,
  1669. &parseStart.hour,
  1670. &parseStart.min,
  1671. &parseStart.sec,
  1672. &parseStart.minSec);
  1673. }
  1674. else
  1675. {
  1676. // Original data without Z
  1677. parseStart.scanedElement = sscanf((char*)start, "%d-%d-%dT%d:%d:%d.%f%d:%d",
  1678. &parseStart.year,
  1679. &parseStart.month,
  1680. &parseStart.mday,
  1681. &parseStart.hour,
  1682. &parseStart.min,
  1683. &parseStart.sec,
  1684. &parseStart.minSec,
  1685. &parseStart.tz_hour,
  1686. &parseStart.tz_min);
  1687. }
  1688. }
  1689. else
  1690. {
  1691. // Original data without mini second
  1692. if(strstr((char*)start, "Z") != NULL)
  1693. {
  1694. // Original data with Z
  1695. parseStart.scanedElement = sscanf((char*)start, "%d-%d-%dT%d:%d:%dZ",
  1696. &parseStart.year,
  1697. &parseStart.month,
  1698. &parseStart.mday,
  1699. &parseStart.hour,
  1700. &parseStart.min,
  1701. &parseStart.sec);
  1702. }
  1703. else
  1704. {
  1705. // Original data without Z
  1706. parseStart.scanedElement = sscanf((char*)start, "%d-%d-%dT%d:%d:%d%d:%d",
  1707. &parseStart.year,
  1708. &parseStart.month,
  1709. &parseStart.mday,
  1710. &parseStart.hour,
  1711. &parseStart.min,
  1712. &parseStart.sec,
  1713. &parseStart.tz_hour,
  1714. &parseStart.tz_min);
  1715. }
  1716. }
  1717. if(strstr((char*)stop, ".") != NULL)
  1718. {
  1719. // Original data with mini second
  1720. if(strstr((char*)stop, "Z") != NULL)
  1721. {
  1722. // Original data with Z
  1723. parseStop.scanedElement = sscanf((char*)stop, "%d-%d-%dT%d:%d:%d.%fZ",
  1724. &parseStop.year,
  1725. &parseStop.month,
  1726. &parseStop.mday,
  1727. &parseStop.hour,
  1728. &parseStop.min,
  1729. &parseStop.sec,
  1730. &parseStop.minSec);
  1731. }
  1732. else
  1733. {
  1734. // Original data without Z
  1735. parseStop.scanedElement = sscanf((char*)stop, "%d-%d-%dT%d:%d:%d.%f%d:%d",
  1736. &parseStop.year,
  1737. &parseStop.month,
  1738. &parseStop.mday,
  1739. &parseStop.hour,
  1740. &parseStop.min,
  1741. &parseStop.sec,
  1742. &parseStop.minSec,
  1743. &parseStop.tz_hour,
  1744. &parseStop.tz_min);
  1745. }
  1746. }
  1747. else
  1748. {
  1749. // Original data without mini second
  1750. if(strstr((char*)stop, "Z") != NULL)
  1751. {
  1752. // Original data with Z
  1753. parseStop.scanedElement = sscanf((char*)stop, "%d-%d-%dT%d:%d:%dZ",
  1754. &parseStop.year,
  1755. &parseStop.month,
  1756. &parseStop.mday,
  1757. &parseStop.hour,
  1758. &parseStop.min,
  1759. &parseStop.sec);
  1760. }
  1761. else
  1762. {
  1763. // Original data without Z
  1764. parseStop.scanedElement = sscanf((char*)stop, "%d-%d-%dT%d:%d:%d%d:%d",
  1765. &parseStop.year,
  1766. &parseStop.month,
  1767. &parseStop.mday,
  1768. &parseStop.hour,
  1769. &parseStop.min,
  1770. &parseStop.sec,
  1771. &parseStop.tz_hour,
  1772. &parseStop.tz_min);
  1773. }
  1774. }
  1775. // Calculate date time difference
  1776. if((parseStart.scanedElement >=6) &&
  1777. (parseStop.scanedElement >=6))
  1778. {
  1779. //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);
  1780. //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);
  1781. tmStart.tm_year = parseStart.year - 1900;
  1782. tmStart.tm_mon = parseStart.month - 1;
  1783. tmStart.tm_mday = parseStart.mday;
  1784. tmStart.tm_hour = parseStart.hour;
  1785. tmStart.tm_min = parseStart.min;
  1786. tmStart.tm_sec = parseStart.sec;
  1787. tmStart.tm_gmtoff = 0;
  1788. tbStart.time = mktime(&tmStart);
  1789. tbStart.timezone = 0;
  1790. tbStart.time -= (parseStart.tz_hour*3600) + (parseStart.tz_min*60*(parseStart.tz_hour>=0?1:-1));
  1791. tmStop.tm_year = parseStop.year - 1900;
  1792. tmStop.tm_mon = parseStop.month - 1;
  1793. tmStop.tm_mday = parseStop.mday;
  1794. tmStop.tm_hour = parseStop.hour;
  1795. tmStop.tm_min = parseStop.min;
  1796. tmStop.tm_sec = parseStop.sec;
  1797. tmStop.tm_gmtoff = 0;
  1798. tbStop.time = mktime(&tmStop);
  1799. tbStop.timezone = 0;
  1800. tbStop.time -= (parseStop.tz_hour*3600) + (parseStop.tz_min*60*(parseStop.tz_hour>=0?1:-1));
  1801. result = DiffTimebSec(tbStart, tbStop)%(isDaily?86400:604800);
  1802. //DEBUG_INFO("getStartStop(): %d\n", result);
  1803. }
  1804. else
  1805. {
  1806. DEBUG_WARN("Start or stop date parsing error.\r\n");
  1807. }
  1808. return result;
  1809. }
  1810. void checkChargePointMaxProfile(uint32_t durationReq, struct StructChargingProfile *targetCompositeProfile, uint8_t isUnitA)
  1811. {
  1812. FILE *fp;
  1813. char profileFileName[128];
  1814. char *line = NULL;
  1815. size_t len = 0;
  1816. time_t CurrentTime;
  1817. struct tm *tmComposite;
  1818. struct StructChargingProfile maxProfile;
  1819. struct StructChargingProfile compositeProfile;
  1820. uint8_t limitMax=0;
  1821. int compositePeriodIdx = 0;
  1822. //uint8_t isDurationNull = FALSE;
  1823. CurrentTime = time(NULL);
  1824. tmComposite=localtime(&CurrentTime);
  1825. 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);
  1826. if(isUnitA)
  1827. sprintf((char*)compositeProfile.ChargingSchedule.ChargingRateUnit, "A");
  1828. else
  1829. sprintf((char*)compositeProfile.ChargingSchedule.ChargingRateUnit, "W");
  1830. compositeProfile.ChargingSchedule.Duration = durationReq;
  1831. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(compositeProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  1832. {
  1833. compositeProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = -1;
  1834. compositeProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit = -1;
  1835. compositeProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases = 3;
  1836. }
  1837. compositeProfile.ChargingProfileId = 0;
  1838. compositeProfile.StackLevel = 99 ;
  1839. sprintf((char*)compositeProfile.ChargingProfileKind ,"Absolute");
  1840. maxProfile.ChargingProfileId = -1;
  1841. maxProfile.ChargingSchedule.Duration = -1;
  1842. system("rm -f /tmp/*.json");
  1843. system("cp /Storage/OCPP/*.json /tmp 2>/dev/null");
  1844. // Search max profile
  1845. sprintf(profileFileName, "/tmp/ChargePointMaxProfile.json");
  1846. if((access(profileFileName, F_OK))!=-1)
  1847. {
  1848. fp = fopen(profileFileName, "r");
  1849. while(getline(&line, &len, fp) != -1)
  1850. {
  1851. json_object *obj = NULL;
  1852. obj = json_tokener_parse(line);
  1853. if(is_error(obj))
  1854. {
  1855. DEBUG_ERROR("Parse MaxProfile from file error.\n");
  1856. }
  1857. else
  1858. {
  1859. if((json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileId")) != maxProfile.ChargingProfileId) &&
  1860. (json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "stackLevel")) >= maxProfile.StackLevel)
  1861. )
  1862. {
  1863. if((json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom") != NULL) &&
  1864. (json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo") != NULL)
  1865. )
  1866. {
  1867. struct tm tmFrom, tmTo;
  1868. struct timeb tbFrom, tbTo;
  1869. 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) &&
  1870. (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))
  1871. {
  1872. tmFrom.tm_year -= 1900;
  1873. tmFrom.tm_mon -= 1;
  1874. tbFrom.time = mktime(&tmFrom);
  1875. tmTo.tm_year -= 1900;
  1876. tmTo.tm_mon -= 1;
  1877. tbTo.time = mktime(&tmTo);
  1878. if((DiffTimebWithNowSec(tbFrom)>=0) && (DiffTimebWithNowSec(tbTo)<=0))
  1879. {
  1880. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  1881. {
  1882. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = -1;
  1883. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit = -1;
  1884. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases = 3;
  1885. }
  1886. if(maxProfile.ChargingProfileId == -1)
  1887. DEBUG_INFO("MaxProfile found.\n");
  1888. else
  1889. DEBUG_INFO("MaxProfile updated.\n");
  1890. // Required item
  1891. maxProfile.ChargingProfileId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileId"));
  1892. maxProfile.StackLevel = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "stackLevel"));
  1893. sprintf((char*)maxProfile.ChargingProfileKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileKind")));
  1894. if(isUnitA)
  1895. {
  1896. sprintf((char*)maxProfile.ChargingSchedule.ChargingRateUnit, "A");
  1897. 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++)
  1898. {
  1899. 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"));
  1900. 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?
  1901. 3:
  1902. 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")));
  1903. 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")));
  1904. }
  1905. }
  1906. else
  1907. {
  1908. sprintf((char*)maxProfile.ChargingSchedule.ChargingRateUnit, "W");
  1909. 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++)
  1910. {
  1911. 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"));
  1912. 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?
  1913. 3:
  1914. 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")));
  1915. 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));
  1916. }
  1917. }
  1918. // Optional item
  1919. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom") != NULL)
  1920. {
  1921. sprintf((char*)maxProfile.ValidFrom, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom")));
  1922. }
  1923. else
  1924. {
  1925. sprintf((char*)maxProfile.ValidFrom, " ");
  1926. }
  1927. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo") != NULL)
  1928. {
  1929. sprintf((char*)maxProfile.ValidTo, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo")));
  1930. }
  1931. else
  1932. {
  1933. sprintf((char*)maxProfile.ValidTo, " ");
  1934. }
  1935. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "recurrencyKind") != NULL)
  1936. {
  1937. sprintf((char*)maxProfile.RecurrencyKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "recurrencyKind")));
  1938. }
  1939. else
  1940. {
  1941. sprintf((char*)maxProfile.RecurrencyKind, " ");
  1942. }
  1943. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId") != NULL)
  1944. {
  1945. maxProfile.TransactionId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId"));
  1946. }
  1947. else
  1948. {
  1949. maxProfile.TransactionId = -1;
  1950. }
  1951. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration") != NULL)
  1952. {
  1953. maxProfile.ChargingSchedule.Duration = json_object_get_int(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration"));
  1954. }
  1955. else
  1956. {
  1957. maxProfile.ChargingSchedule.Duration = 86400;
  1958. //isDurationNull = TRUE;
  1959. }
  1960. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "startSchedule") != NULL)
  1961. {
  1962. 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")));
  1963. }
  1964. else
  1965. {
  1966. sprintf((char*)maxProfile.ChargingSchedule.StartSchedule, "%s", compositeProfile.ChargingSchedule.StartSchedule);
  1967. }
  1968. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate") != NULL)
  1969. {
  1970. maxProfile.ChargingSchedule.MinChargingRate = json_object_get_double(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate"));
  1971. }
  1972. else
  1973. {
  1974. maxProfile.ChargingSchedule.MinChargingRate = -1;
  1975. }
  1976. }
  1977. }
  1978. }
  1979. else
  1980. {
  1981. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  1982. {
  1983. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = -1;
  1984. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit = -1;
  1985. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases = 3;
  1986. }
  1987. if(maxProfile.ChargingProfileId == -1)
  1988. DEBUG_INFO("MaxProfile found.\n");
  1989. else
  1990. DEBUG_INFO("MaxProfile updated.\n");
  1991. // Required item
  1992. maxProfile.ChargingProfileId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileId"));
  1993. maxProfile.StackLevel = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "stackLevel"));
  1994. sprintf((char*)maxProfile.ChargingProfileKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileKind")));
  1995. if(isUnitA)
  1996. {
  1997. sprintf((char*)maxProfile.ChargingSchedule.ChargingRateUnit, "A");
  1998. 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++)
  1999. {
  2000. 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"));
  2001. 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?
  2002. 3:
  2003. 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")));
  2004. 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")));
  2005. }
  2006. }
  2007. else
  2008. {
  2009. sprintf((char*)maxProfile.ChargingSchedule.ChargingRateUnit, "W");
  2010. 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++)
  2011. {
  2012. 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"));
  2013. 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?
  2014. 3:
  2015. 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")));
  2016. 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));
  2017. }
  2018. }
  2019. // Optional item
  2020. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom") != NULL)
  2021. {
  2022. sprintf((char*)maxProfile.ValidFrom, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom")));
  2023. }
  2024. else
  2025. {
  2026. sprintf((char*)maxProfile.ValidFrom, " ");
  2027. }
  2028. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo") != NULL)
  2029. {
  2030. sprintf((char*)maxProfile.ValidTo, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo")));
  2031. }
  2032. else
  2033. {
  2034. sprintf((char*)maxProfile.ValidTo, " ");
  2035. }
  2036. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "recurrencyKind") != NULL)
  2037. {
  2038. sprintf((char*)maxProfile.RecurrencyKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "recurrencyKind")));
  2039. }
  2040. else
  2041. {
  2042. sprintf((char*)maxProfile.RecurrencyKind, " ");
  2043. }
  2044. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId") != NULL)
  2045. {
  2046. maxProfile.TransactionId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId"));
  2047. }
  2048. else
  2049. {
  2050. maxProfile.TransactionId = -1;
  2051. }
  2052. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration") != NULL)
  2053. {
  2054. maxProfile.ChargingSchedule.Duration = json_object_get_int(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration"));
  2055. }
  2056. else
  2057. {
  2058. maxProfile.ChargingSchedule.Duration = 86400;
  2059. //isDurationNull = TRUE;
  2060. }
  2061. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "startSchedule") != NULL)
  2062. {
  2063. 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")));
  2064. }
  2065. else
  2066. {
  2067. sprintf((char*)maxProfile.ChargingSchedule.StartSchedule, "%s", compositeProfile.ChargingSchedule.StartSchedule);
  2068. }
  2069. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate") != NULL)
  2070. {
  2071. maxProfile.ChargingSchedule.MinChargingRate = json_object_get_double(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate"));
  2072. }
  2073. else
  2074. {
  2075. maxProfile.ChargingSchedule.MinChargingRate = -1;
  2076. }
  2077. }
  2078. }
  2079. }
  2080. json_object_put(obj);
  2081. }
  2082. fclose(fp);
  2083. /*
  2084. if(maxProfile.ChargingProfileId !=-1)
  2085. {
  2086. DEBUG_INFO("Profile ID: %d\n", maxProfile.ChargingProfileId);
  2087. DEBUG_INFO("Profile stackLevel: %d\n", maxProfile.StackLevel);
  2088. DEBUG_INFO("Profile TransactionId: %d\n", maxProfile.TransactionId);
  2089. DEBUG_INFO("Profile valid from: %s\n", maxProfile.ValidFrom);
  2090. DEBUG_INFO("Profile valid to: %s\n", maxProfile.ValidTo);
  2091. DEBUG_INFO("Profile ChargingProfileKind: %s\n", maxProfile.ChargingProfileKind);
  2092. DEBUG_INFO("Profile recurrencyKind: %s\n", maxProfile.RecurrencyKind);
  2093. DEBUG_INFO("Profile start schedule: %s\n", maxProfile.ChargingSchedule.StartSchedule);
  2094. DEBUG_INFO("Profile schedule duration: %d\n", maxProfile.ChargingSchedule.Duration);
  2095. DEBUG_INFO("Profile charging rate unit: %s\n", maxProfile.ChargingSchedule.ChargingRateUnit);
  2096. DEBUG_INFO("Profile charging min rate: %f\n", maxProfile.ChargingSchedule.MinChargingRate);
  2097. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  2098. {
  2099. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod >= 0)
  2100. {
  2101. DEBUG_INFO("Period-%02d startPeriod: %d\n", idxPeriod, maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod);
  2102. DEBUG_INFO("Period-%02d limit: %f\n", idxPeriod, maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit);
  2103. DEBUG_INFO("Period-%02d NumberPhases: %d\n", idxPeriod, maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases);
  2104. }
  2105. }
  2106. }
  2107. else
  2108. DEBUG_INFO("MaxProfile not found.\n");
  2109. DEBUG_INFO("------------------------------------\n");*/
  2110. }
  2111. if(maxProfile.ChargingProfileId != -1)
  2112. {
  2113. if(strstr((char*)maxProfile.ChargingProfileKind, "Absolute") != NULL)
  2114. {
  2115. if((maxProfile.ChargingSchedule.Duration != -1)/* && (isDurationNull)*/)
  2116. {
  2117. maxProfile.ChargingSchedule.Duration = ((maxProfile.ChargingSchedule.Duration-getStartStop(maxProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule))<0?
  2118. 0:
  2119. (maxProfile.ChargingSchedule.Duration-getStartStop(maxProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule)));
  2120. }
  2121. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  2122. {
  2123. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  2124. {
  2125. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = ((maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartStop(maxProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule))<0?
  2126. 0:
  2127. (maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartStop(maxProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule)));
  2128. if(idxPeriod > 0)
  2129. {
  2130. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
  2131. {
  2132. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit = maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit;
  2133. }
  2134. }
  2135. }
  2136. }
  2137. }
  2138. else if(strstr((char*)maxProfile.ChargingProfileKind, "Relative") != NULL)
  2139. {
  2140. if(maxProfile.ChargingSchedule.Duration != -1)
  2141. {
  2142. maxProfile.ChargingSchedule.Duration = maxProfile.ChargingSchedule.Duration;
  2143. }
  2144. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  2145. {
  2146. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  2147. {
  2148. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod;
  2149. if(idxPeriod > 0)
  2150. {
  2151. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
  2152. {
  2153. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit = maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit;
  2154. }
  2155. }
  2156. }
  2157. }
  2158. }
  2159. else
  2160. {
  2161. if(strstr((char*)maxProfile.RecurrencyKind, "Weekly") != NULL)
  2162. {
  2163. if(maxProfile.ChargingSchedule.Duration != -1)
  2164. {
  2165. maxProfile.ChargingSchedule.Duration = ((maxProfile.ChargingSchedule.Duration-getStartSinceRecurring(maxProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule, FALSE))<0?
  2166. 0:
  2167. (maxProfile.ChargingSchedule.Duration-getStartSinceRecurring(maxProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule, FALSE)));
  2168. }
  2169. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  2170. {
  2171. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  2172. {
  2173. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = ((maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceRecurring(maxProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule, FALSE))<0?
  2174. 0:
  2175. (maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceRecurring(maxProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule, FALSE)));
  2176. if(idxPeriod > 0)
  2177. {
  2178. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
  2179. {
  2180. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit = maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit;
  2181. }
  2182. }
  2183. }
  2184. }
  2185. }
  2186. else
  2187. {
  2188. if(maxProfile.ChargingSchedule.Duration != -1)
  2189. {
  2190. maxProfile.ChargingSchedule.Duration = ((maxProfile.ChargingSchedule.Duration-getStartSinceRecurring(maxProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule, TRUE))<0?
  2191. 0:
  2192. (maxProfile.ChargingSchedule.Duration-getStartSinceRecurring(maxProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule, TRUE)));
  2193. }
  2194. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  2195. {
  2196. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  2197. {
  2198. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = ((maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceRecurring(maxProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule, TRUE))<0?
  2199. 0:
  2200. (maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceRecurring(maxProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule, TRUE)));
  2201. if(idxPeriod > 0)
  2202. {
  2203. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
  2204. {
  2205. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit = maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit;
  2206. }
  2207. }
  2208. }
  2209. }
  2210. }
  2211. }
  2212. /*
  2213. DEBUG_INFO("MaxProfile after align.\n");
  2214. DEBUG_INFO("Profile ID: %d\n", maxProfile.ChargingProfileId);
  2215. DEBUG_INFO("Profile stackLevel: %d\n", maxProfile.StackLevel);
  2216. DEBUG_INFO("Profile TransactionId: %d\n", maxProfile.TransactionId);
  2217. DEBUG_INFO("Profile valid from: %s\n", maxProfile.ValidFrom);
  2218. DEBUG_INFO("Profile valid to: %s\n", maxProfile.ValidTo);
  2219. DEBUG_INFO("Profile ChargingProfileKind: %s\n", maxProfile.ChargingProfileKind);
  2220. DEBUG_INFO("Profile RecurrencyKind: %s\n", maxProfile.RecurrencyKind);
  2221. DEBUG_INFO("Profile start schedule: %s\n", compositeProfile->ChargingSchedule.StartSchedule);
  2222. DEBUG_INFO("Profile schedule duration: %d\n", maxProfile.ChargingSchedule.Duration);
  2223. DEBUG_INFO("Profile charging rate unit: %s\n", maxProfile.ChargingSchedule.ChargingRateUnit);
  2224. DEBUG_INFO("Profile charging min rate: %f\n", maxProfile.ChargingSchedule.MinChargingRate);
  2225. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  2226. {
  2227. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod >= 0)
  2228. {
  2229. DEBUG_INFO("Period-%02d startPeriod: %d\n", idxPeriod, maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod);
  2230. DEBUG_INFO("Period-%02d limit: %f\n", idxPeriod, maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit);
  2231. DEBUG_INFO("Period-%02d NumberPhases: %d\n", idxPeriod, maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases);
  2232. }
  2233. }
  2234. DEBUG_INFO("------------------------------------\n");*/
  2235. }
  2236. // Find each profile period quantity
  2237. for(int idx=0;idx<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idx++)
  2238. {
  2239. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idx].Limit != -1)
  2240. limitMax = idx+1;
  2241. }
  2242. if(maxProfile.ChargingProfileId != -1)
  2243. {
  2244. for(int idxMaxPeriod=0;idxMaxPeriod<limitMax;idxMaxPeriod++)
  2245. {
  2246. if((maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].Limit != -1) &&
  2247. (maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].StartPeriod < durationReq) &&
  2248. (maxProfile.ChargingSchedule.Duration > 0))
  2249. {
  2250. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].StartPeriod != compositeProfile.ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].StartPeriod)
  2251. {
  2252. memcpy(&compositeProfile.ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx], &maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod],sizeof(struct StructChargingSchedulePeriod));
  2253. compositePeriodIdx++;
  2254. }
  2255. else
  2256. {
  2257. memcpy(&compositeProfile.ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)], &maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod],sizeof(struct StructChargingSchedulePeriod));
  2258. }
  2259. }
  2260. }
  2261. }
  2262. DEBUG_INFO("ChargePointMaxProfile ready.\n");
  2263. DEBUG_INFO("Schedule start: %s\n", compositeProfile.ChargingSchedule.StartSchedule);
  2264. DEBUG_INFO("Schedule duration: %d\n", compositeProfile.ChargingSchedule.Duration);
  2265. DEBUG_INFO("Rate unit: %s\n", compositeProfile.ChargingSchedule.ChargingRateUnit);
  2266. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(compositeProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  2267. {
  2268. if(compositeProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod >= 0)
  2269. {
  2270. compositeProfile.ChargingProfileId = 1;
  2271. DEBUG_INFO("Period-%02d startPeriod: %d\n", idxPeriod, compositeProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod);
  2272. DEBUG_INFO("Period-%02d limit: %f\n", idxPeriod, compositeProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit);
  2273. DEBUG_INFO("Period-%02d NumberPhases: %d\n", idxPeriod, compositeProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases);
  2274. }
  2275. if(compositeProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit == -1)
  2276. compositeProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit =0;
  2277. if(compositeProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod == -1)
  2278. compositeProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod =0;
  2279. }
  2280. memcpy(targetCompositeProfile, &compositeProfile, sizeof(struct StructChargingProfile));
  2281. if(line)
  2282. free(line);
  2283. }
  2284. void checkCompositeSchedule(uint8_t connectorId, uint32_t durationReq, struct StructChargingProfile *targetCompositeProfile, uint8_t isUnitA)
  2285. {
  2286. FILE *fp;
  2287. char profileFileName[128];
  2288. char *line = NULL;
  2289. size_t len = 0;
  2290. time_t CurrentTime;
  2291. struct tm *tmComposite;
  2292. struct StructChargingProfile maxProfile;
  2293. struct StructChargingProfile defaultTxProfile;
  2294. struct StructChargingProfile txProfile;
  2295. struct StructChargingProfile compositeProfile;
  2296. struct StructChargingSchedulePeriod tmpPeriod;
  2297. uint8_t limitMax=0;
  2298. uint8_t limitDef=0;
  2299. uint8_t limitTx=0;
  2300. int compositePeriodIdx = 0;
  2301. CurrentTime = time(NULL);
  2302. tmComposite=localtime(&CurrentTime);
  2303. 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);
  2304. if(isUnitA)
  2305. sprintf((char*)compositeProfile.ChargingSchedule.ChargingRateUnit, "A");
  2306. else
  2307. sprintf((char*)compositeProfile.ChargingSchedule.ChargingRateUnit, "W");
  2308. compositeProfile.ChargingSchedule.Duration = durationReq;
  2309. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(compositeProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  2310. {
  2311. compositeProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = -1;
  2312. compositeProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit = -1;
  2313. compositeProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases = 3;
  2314. }
  2315. compositeProfile.ChargingProfileId = 0;
  2316. compositeProfile.StackLevel = 99 ;
  2317. sprintf((char*)compositeProfile.ChargingProfileKind ,"Absolute");
  2318. maxProfile.ChargingProfileId = -1;
  2319. defaultTxProfile.ChargingProfileId = -1;
  2320. txProfile.ChargingProfileId = -1;
  2321. maxProfile.ChargingSchedule.Duration = -1;
  2322. defaultTxProfile.ChargingSchedule.Duration = -1;
  2323. txProfile.ChargingSchedule.Duration = -1;
  2324. system("rm -f /tmp/*.json");
  2325. system("cp /Storage/OCPP/*.json /tmp 2>/dev/null");
  2326. /*
  2327. * Search valid charging profile
  2328. */
  2329. //DEBUG_INFO("====================================\n");
  2330. // Search tx profile
  2331. sprintf(profileFileName, "/tmp/TxProfile_%d.json", connectorId);
  2332. if((access(profileFileName, F_OK))!=-1)
  2333. {
  2334. fp = fopen(profileFileName, "r");
  2335. while(getline(&line, &len, fp) != -1)
  2336. {
  2337. json_object *obj = NULL;
  2338. obj = json_tokener_parse(line);
  2339. if(is_error(obj))
  2340. {
  2341. DEBUG_ERROR("Parse txProfile from file error.\n");
  2342. }
  2343. else
  2344. {
  2345. if((json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileId")) != txProfile.ChargingProfileId) &&
  2346. (json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "stackLevel")) >= txProfile.StackLevel)
  2347. )
  2348. {
  2349. if((json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom") != NULL) &&
  2350. (json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo") != NULL)
  2351. )
  2352. {
  2353. struct tm tmFrom, tmTo;
  2354. struct timeb tbFrom, tbTo;
  2355. 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) &&
  2356. (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))
  2357. {
  2358. tmFrom.tm_year -= 1900;
  2359. tmFrom.tm_mon -= 1;
  2360. tbFrom.time = mktime(&tmFrom);
  2361. tmTo.tm_year -= 1900;
  2362. tmTo.tm_mon -= 1;
  2363. tbTo.time = mktime(&tmTo);
  2364. if((DiffTimebWithNowSec(tbFrom)>=0) && (DiffTimebWithNowSec(tbTo)<=0))
  2365. {
  2366. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(txProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  2367. {
  2368. txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = -1;
  2369. txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit = -1;
  2370. txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases = 3;
  2371. }
  2372. if(txProfile.ChargingProfileId == -1)
  2373. DEBUG_INFO("TxProfile found.\n");
  2374. else
  2375. DEBUG_INFO("TxProfile updated.\n");
  2376. // Required item
  2377. txProfile.ChargingProfileId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileId"));
  2378. txProfile.StackLevel = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "stackLevel"));
  2379. sprintf((char*)txProfile.ChargingProfileKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileKind")));
  2380. if(isUnitA)
  2381. {
  2382. sprintf((char*)txProfile.ChargingSchedule.ChargingRateUnit, "A");
  2383. 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++)
  2384. {
  2385. 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"));
  2386. 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?
  2387. 3:
  2388. 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")));
  2389. 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")));
  2390. }
  2391. }
  2392. else
  2393. {
  2394. sprintf((char*)txProfile.ChargingSchedule.ChargingRateUnit, "W");
  2395. 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++)
  2396. {
  2397. 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"));
  2398. 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?
  2399. 3:
  2400. 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")));
  2401. 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));
  2402. }
  2403. }
  2404. // Optional item
  2405. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom") != NULL)
  2406. {
  2407. sprintf((char*)txProfile.ValidFrom, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom")));
  2408. }
  2409. else
  2410. {
  2411. sprintf((char*)txProfile.ValidFrom, " ");
  2412. }
  2413. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo") != NULL)
  2414. {
  2415. sprintf((char*)txProfile.ValidTo, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo")));
  2416. }
  2417. else
  2418. {
  2419. sprintf((char*)txProfile.ValidTo, " ");
  2420. }
  2421. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "recurrencyKind") != NULL)
  2422. {
  2423. sprintf((char*)txProfile.RecurrencyKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "recurrencyKind")));
  2424. }
  2425. else
  2426. {
  2427. sprintf((char*)txProfile.RecurrencyKind, " ");
  2428. }
  2429. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId") != NULL)
  2430. {
  2431. txProfile.TransactionId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId"));
  2432. }
  2433. else
  2434. {
  2435. txProfile.TransactionId = -1;
  2436. }
  2437. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration") != NULL)
  2438. {
  2439. txProfile.ChargingSchedule.Duration = json_object_get_int(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration"));
  2440. }
  2441. else
  2442. {
  2443. txProfile.ChargingSchedule.Duration = 86400;
  2444. }
  2445. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "startSchedule") != NULL)
  2446. {
  2447. 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")));
  2448. }
  2449. else
  2450. {
  2451. 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));
  2452. }
  2453. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate") != NULL)
  2454. {
  2455. txProfile.ChargingSchedule.MinChargingRate = json_object_get_double(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate"));
  2456. }
  2457. else
  2458. {
  2459. txProfile.ChargingSchedule.MinChargingRate = -1;
  2460. }
  2461. }
  2462. }
  2463. }
  2464. else
  2465. {
  2466. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(txProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  2467. {
  2468. txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = -1;
  2469. txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit = -1;
  2470. txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases = 3;
  2471. }
  2472. if(txProfile.ChargingProfileId == -1)
  2473. DEBUG_INFO("TxProfile found.\n");
  2474. else
  2475. DEBUG_INFO("TxProfile updated.\n");
  2476. // Required item
  2477. txProfile.ChargingProfileId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileId"));
  2478. txProfile.StackLevel = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "stackLevel"));
  2479. sprintf((char*)txProfile.ChargingProfileKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileKind")));
  2480. if(isUnitA)
  2481. {
  2482. sprintf((char*)txProfile.ChargingSchedule.ChargingRateUnit, "A");
  2483. 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++)
  2484. {
  2485. 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"));
  2486. 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?
  2487. 3:
  2488. 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")));
  2489. 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")));
  2490. }
  2491. }
  2492. else
  2493. {
  2494. sprintf((char*)txProfile.ChargingSchedule.ChargingRateUnit, "W");
  2495. 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++)
  2496. {
  2497. 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"));
  2498. 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?
  2499. 3:
  2500. 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")));
  2501. 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));
  2502. }
  2503. }
  2504. // Optional item
  2505. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom") != NULL)
  2506. {
  2507. sprintf((char*)txProfile.ValidFrom, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom")));
  2508. }
  2509. else
  2510. {
  2511. sprintf((char*)txProfile.ValidFrom, " ");
  2512. }
  2513. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo") != NULL)
  2514. {
  2515. sprintf((char*)txProfile.ValidTo, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo")));
  2516. }
  2517. else
  2518. {
  2519. sprintf((char*)txProfile.ValidTo, " ");
  2520. }
  2521. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "recurrencyKind") != NULL)
  2522. {
  2523. sprintf((char*)txProfile.RecurrencyKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "recurrencyKind")));
  2524. }
  2525. else
  2526. {
  2527. sprintf((char*)txProfile.RecurrencyKind, " ");
  2528. }
  2529. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId") != NULL)
  2530. {
  2531. txProfile.TransactionId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId"));
  2532. }
  2533. else
  2534. {
  2535. txProfile.TransactionId = -1;
  2536. }
  2537. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration") != NULL)
  2538. {
  2539. txProfile.ChargingSchedule.Duration = json_object_get_int(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration"));
  2540. }
  2541. else
  2542. {
  2543. txProfile.ChargingSchedule.Duration = 86400;
  2544. }
  2545. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "startSchedule") != NULL)
  2546. {
  2547. 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")));
  2548. }
  2549. else
  2550. {
  2551. 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));
  2552. }
  2553. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate") != NULL)
  2554. {
  2555. txProfile.ChargingSchedule.MinChargingRate = json_object_get_double(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate"));
  2556. }
  2557. else
  2558. {
  2559. txProfile.ChargingSchedule.MinChargingRate = -1;
  2560. }
  2561. }
  2562. }
  2563. }
  2564. json_object_put(obj);
  2565. }
  2566. fclose(fp);
  2567. /*
  2568. if(txProfile.ChargingProfileId != -1)
  2569. {
  2570. DEBUG_INFO("Profile ID: %d\n", txProfile.ChargingProfileId);
  2571. DEBUG_INFO("Profile stackLevel: %d\n", txProfile.StackLevel);
  2572. DEBUG_INFO("Profile TransactionId: %d\n", txProfile.TransactionId);
  2573. DEBUG_INFO("Profile valid from: %s\n", txProfile.ValidFrom);
  2574. DEBUG_INFO("Profile valid to: %s\n", txProfile.ValidTo);
  2575. DEBUG_INFO("Profile ChargingProfileKind: %s\n", txProfile.ChargingProfileKind);
  2576. DEBUG_INFO("Profile recurrencyKind: %s\n", txProfile.RecurrencyKind);
  2577. DEBUG_INFO("Profile start schedule: %s\n", txProfile.ChargingSchedule.StartSchedule);
  2578. DEBUG_INFO("Profile schedule duration: %d\n", txProfile.ChargingSchedule.Duration);
  2579. DEBUG_INFO("Profile charging rate unit: %s\n", txProfile.ChargingSchedule.ChargingRateUnit);
  2580. DEBUG_INFO("Profile charging min rate: %f\n", txProfile.ChargingSchedule.MinChargingRate);
  2581. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(txProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  2582. {
  2583. if(txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod >= 0)
  2584. {
  2585. DEBUG_INFO("Period-%02d startPeriod: %d\n", idxPeriod, txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod);
  2586. DEBUG_INFO("Period-%02d limit: %f\n", idxPeriod, txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit);
  2587. DEBUG_INFO("Period-%02d NumberPhases: %d\n", idxPeriod, txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases);
  2588. }
  2589. }
  2590. }
  2591. else
  2592. DEBUG_INFO("TxProfile not found.\n");*/
  2593. }
  2594. // Search default tx profile
  2595. sprintf(profileFileName, "/tmp/TxDefaultProfile_%d.json", connectorId);
  2596. if((access(profileFileName, F_OK))==-1)
  2597. sprintf(profileFileName, "/tmp/TxDefaultProfile_0.json");
  2598. if((access(profileFileName, F_OK))!=-1)
  2599. {
  2600. fp = fopen(profileFileName, "r");
  2601. while(getline(&line, &len, fp) != -1)
  2602. {
  2603. json_object *obj = NULL;
  2604. obj = json_tokener_parse(line);
  2605. if(is_error(obj))
  2606. {
  2607. DEBUG_ERROR("Parse TxDefaultProfile from file error.\n");
  2608. }
  2609. else
  2610. {
  2611. if((json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileId")) != defaultTxProfile.ChargingProfileId) &&
  2612. (json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "stackLevel")) >= defaultTxProfile.StackLevel)
  2613. )
  2614. {
  2615. if((json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom") != NULL) &&
  2616. (json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo") != NULL)
  2617. )
  2618. {
  2619. struct tm tmFrom, tmTo;
  2620. struct timeb tbFrom, tbTo;
  2621. 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) &&
  2622. (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))
  2623. {
  2624. tmFrom.tm_year -= 1900;
  2625. tmFrom.tm_mon -= 1;
  2626. tbFrom.time = mktime(&tmFrom);
  2627. tmTo.tm_year -= 1900;
  2628. tmTo.tm_mon -= 1;
  2629. tbTo.time = mktime(&tmTo);
  2630. if((DiffTimebWithNowSec(tbFrom)>=0) && (DiffTimebWithNowSec(tbTo)<=0))
  2631. {
  2632. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  2633. {
  2634. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = -1;
  2635. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit = -1;
  2636. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases = 3;
  2637. }
  2638. if(defaultTxProfile.ChargingProfileId == -1)
  2639. DEBUG_INFO("TxDefaultProfile found.\n");
  2640. else
  2641. DEBUG_INFO("TxDefaultProfile updated.\n");
  2642. // Required item
  2643. defaultTxProfile.ChargingProfileId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileId"));
  2644. defaultTxProfile.StackLevel = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "stackLevel"));
  2645. sprintf((char*)defaultTxProfile.ChargingProfileKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileKind")));
  2646. if(isUnitA)
  2647. {
  2648. sprintf((char*)defaultTxProfile.ChargingSchedule.ChargingRateUnit, "A");
  2649. 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++)
  2650. {
  2651. 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"));
  2652. 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?
  2653. 3:
  2654. 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")));
  2655. 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")));
  2656. }
  2657. }
  2658. else
  2659. {
  2660. sprintf((char*)defaultTxProfile.ChargingSchedule.ChargingRateUnit, "W");
  2661. 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++)
  2662. {
  2663. 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"));
  2664. 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?
  2665. 3:
  2666. 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")));
  2667. 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));
  2668. }
  2669. }
  2670. // Optional item
  2671. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom") != NULL)
  2672. {
  2673. sprintf((char*)defaultTxProfile.ValidFrom, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom")));
  2674. }
  2675. else
  2676. {
  2677. sprintf((char*)defaultTxProfile.ValidFrom, " ");
  2678. }
  2679. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo") != NULL)
  2680. {
  2681. sprintf((char*)defaultTxProfile.ValidTo, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo")));
  2682. }
  2683. else
  2684. {
  2685. sprintf((char*)defaultTxProfile.ValidTo, " ");
  2686. }
  2687. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "recurrencyKind") != NULL)
  2688. {
  2689. sprintf((char*)defaultTxProfile.RecurrencyKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "recurrencyKind")));
  2690. }
  2691. else
  2692. {
  2693. sprintf((char*)defaultTxProfile.RecurrencyKind, " ");
  2694. }
  2695. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId") != NULL)
  2696. {
  2697. defaultTxProfile.TransactionId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId"));
  2698. }
  2699. else
  2700. {
  2701. defaultTxProfile.TransactionId = -1;
  2702. }
  2703. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration") != NULL)
  2704. {
  2705. defaultTxProfile.ChargingSchedule.Duration = json_object_get_int(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration"));
  2706. }
  2707. else
  2708. {
  2709. defaultTxProfile.ChargingSchedule.Duration = 86400;
  2710. }
  2711. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "startSchedule") != NULL)
  2712. {
  2713. 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")));
  2714. }
  2715. else
  2716. {
  2717. 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));
  2718. }
  2719. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate") != NULL)
  2720. {
  2721. defaultTxProfile.ChargingSchedule.MinChargingRate = json_object_get_double(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate"));
  2722. }
  2723. else
  2724. {
  2725. defaultTxProfile.ChargingSchedule.MinChargingRate = -1;
  2726. }
  2727. }
  2728. }
  2729. }
  2730. else
  2731. {
  2732. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  2733. {
  2734. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = -1;
  2735. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit = -1;
  2736. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases = 3;
  2737. }
  2738. if(defaultTxProfile.ChargingProfileId == -1)
  2739. DEBUG_INFO("TxDefaultProfile found.\n");
  2740. else
  2741. DEBUG_INFO("TxDefaultProfile updated.\n");
  2742. // Required item
  2743. defaultTxProfile.ChargingProfileId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileId"));
  2744. defaultTxProfile.StackLevel = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "stackLevel"));
  2745. sprintf((char*)defaultTxProfile.ChargingProfileKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileKind")));
  2746. if(isUnitA)
  2747. {
  2748. sprintf((char*)defaultTxProfile.ChargingSchedule.ChargingRateUnit, "A");
  2749. 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++)
  2750. {
  2751. 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"));
  2752. 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?
  2753. 3:
  2754. 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")));
  2755. 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")));
  2756. }
  2757. }
  2758. else
  2759. {
  2760. sprintf((char*)defaultTxProfile.ChargingSchedule.ChargingRateUnit, "W");
  2761. 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++)
  2762. {
  2763. 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"));
  2764. 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?
  2765. 3:
  2766. 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")));
  2767. 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));
  2768. }
  2769. }
  2770. // Optional item
  2771. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom") != NULL)
  2772. {
  2773. sprintf((char*)defaultTxProfile.ValidFrom, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom")));
  2774. }
  2775. else
  2776. {
  2777. sprintf((char*)defaultTxProfile.ValidFrom, " ");
  2778. }
  2779. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo") != NULL)
  2780. {
  2781. sprintf((char*)defaultTxProfile.ValidTo, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo")));
  2782. }
  2783. else
  2784. {
  2785. sprintf((char*)defaultTxProfile.ValidTo, " ");
  2786. }
  2787. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "recurrencyKind") != NULL)
  2788. {
  2789. sprintf((char*)defaultTxProfile.RecurrencyKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "recurrencyKind")));
  2790. }
  2791. else
  2792. {
  2793. sprintf((char*)defaultTxProfile.RecurrencyKind, " ");
  2794. }
  2795. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId") != NULL)
  2796. {
  2797. defaultTxProfile.TransactionId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId"));
  2798. }
  2799. else
  2800. {
  2801. defaultTxProfile.TransactionId = -1;
  2802. }
  2803. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration") != NULL)
  2804. {
  2805. defaultTxProfile.ChargingSchedule.Duration = json_object_get_int(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration"));
  2806. }
  2807. else
  2808. {
  2809. defaultTxProfile.ChargingSchedule.Duration = 86400;
  2810. }
  2811. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "startSchedule") != NULL)
  2812. {
  2813. 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")));
  2814. }
  2815. else
  2816. {
  2817. 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));
  2818. }
  2819. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate") != NULL)
  2820. {
  2821. defaultTxProfile.ChargingSchedule.MinChargingRate = json_object_get_double(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate"));
  2822. }
  2823. else
  2824. {
  2825. defaultTxProfile.ChargingSchedule.MinChargingRate = -1;
  2826. }
  2827. }
  2828. }
  2829. }
  2830. json_object_put(obj);
  2831. }
  2832. fclose(fp);
  2833. /*
  2834. if(defaultTxProfile.ChargingProfileId != -1)
  2835. {
  2836. DEBUG_INFO("Profile ID: %d\n", defaultTxProfile.ChargingProfileId);
  2837. DEBUG_INFO("Profile stackLevel: %d\n", defaultTxProfile.StackLevel);
  2838. DEBUG_INFO("Profile TransactionId: %d\n", defaultTxProfile.TransactionId);
  2839. DEBUG_INFO("Profile valid from: %s\n", defaultTxProfile.ValidFrom);
  2840. DEBUG_INFO("Profile valid to: %s\n", defaultTxProfile.ValidTo);
  2841. DEBUG_INFO("Profile ChargingProfileKind: %s\n", defaultTxProfile.ChargingProfileKind);
  2842. DEBUG_INFO("Profile recurrencyKind: %s\n", defaultTxProfile.RecurrencyKind);
  2843. DEBUG_INFO("Profile start schedule: %s\n", defaultTxProfile.ChargingSchedule.StartSchedule);
  2844. DEBUG_INFO("Profile schedule duration: %d\n", defaultTxProfile.ChargingSchedule.Duration);
  2845. DEBUG_INFO("Profile charging rate unit: %s\n", defaultTxProfile.ChargingSchedule.ChargingRateUnit);
  2846. DEBUG_INFO("Profile charging min rate: %f\n", defaultTxProfile.ChargingSchedule.MinChargingRate);
  2847. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  2848. {
  2849. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod >= 0)
  2850. {
  2851. DEBUG_INFO("Period-%02d startPeriod: %d\n", idxPeriod, defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod);
  2852. DEBUG_INFO("Period-%02d limit: %f\n", idxPeriod, defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit);
  2853. DEBUG_INFO("Period-%02d NumberPhases: %d\n", idxPeriod, defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases);
  2854. }
  2855. }
  2856. }
  2857. else
  2858. DEBUG_INFO("TxDefaultProfile not found.\n");
  2859. DEBUG_INFO("------------------------------------\n");*/
  2860. }
  2861. // Search max profile
  2862. sprintf(profileFileName, "/tmp/ChargePointMaxProfile.json");
  2863. if((access(profileFileName, F_OK))!=-1)
  2864. {
  2865. fp = fopen(profileFileName, "r");
  2866. while(getline(&line, &len, fp) != -1)
  2867. {
  2868. json_object *obj = NULL;
  2869. obj = json_tokener_parse(line);
  2870. if(is_error(obj))
  2871. {
  2872. DEBUG_ERROR("Parse MaxProfile from file error.\n");
  2873. }
  2874. else
  2875. {
  2876. if((json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileId")) != maxProfile.ChargingProfileId) &&
  2877. (json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "stackLevel")) >= maxProfile.StackLevel)
  2878. )
  2879. {
  2880. if((json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom") != NULL) &&
  2881. (json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo") != NULL)
  2882. )
  2883. {
  2884. struct tm tmFrom, tmTo;
  2885. struct timeb tbFrom, tbTo;
  2886. 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) &&
  2887. (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))
  2888. {
  2889. tmFrom.tm_year -= 1900;
  2890. tmFrom.tm_mon -= 1;
  2891. tbFrom.time = mktime(&tmFrom);
  2892. tmTo.tm_year -= 1900;
  2893. tmTo.tm_mon -= 1;
  2894. tbTo.time = mktime(&tmTo);
  2895. if((DiffTimebWithNowSec(tbFrom)>=0) && (DiffTimebWithNowSec(tbTo)<=0))
  2896. {
  2897. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  2898. {
  2899. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = -1;
  2900. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit = -1;
  2901. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases = 3;
  2902. }
  2903. if(maxProfile.ChargingProfileId == -1)
  2904. DEBUG_INFO("MaxProfile found.\n");
  2905. else
  2906. DEBUG_INFO("MaxProfile updated.\n");
  2907. // Required item
  2908. maxProfile.ChargingProfileId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileId"));
  2909. maxProfile.StackLevel = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "stackLevel"));
  2910. sprintf((char*)maxProfile.ChargingProfileKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileKind")));
  2911. if(isUnitA)
  2912. {
  2913. sprintf((char*)maxProfile.ChargingSchedule.ChargingRateUnit, "A");
  2914. 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++)
  2915. {
  2916. 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"));
  2917. 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?
  2918. 3:
  2919. 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")));
  2920. 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")));
  2921. }
  2922. }
  2923. else
  2924. {
  2925. sprintf((char*)maxProfile.ChargingSchedule.ChargingRateUnit, "W");
  2926. 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++)
  2927. {
  2928. 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"));
  2929. 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?
  2930. 3:
  2931. 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")));
  2932. 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));
  2933. }
  2934. }
  2935. // Optional item
  2936. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom") != NULL)
  2937. {
  2938. sprintf((char*)maxProfile.ValidFrom, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom")));
  2939. }
  2940. else
  2941. {
  2942. sprintf((char*)maxProfile.ValidFrom, " ");
  2943. }
  2944. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo") != NULL)
  2945. {
  2946. sprintf((char*)maxProfile.ValidTo, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo")));
  2947. }
  2948. else
  2949. {
  2950. sprintf((char*)maxProfile.ValidTo, " ");
  2951. }
  2952. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "recurrencyKind") != NULL)
  2953. {
  2954. sprintf((char*)maxProfile.RecurrencyKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "recurrencyKind")));
  2955. }
  2956. else
  2957. {
  2958. sprintf((char*)maxProfile.RecurrencyKind, " ");
  2959. }
  2960. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId") != NULL)
  2961. {
  2962. maxProfile.TransactionId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId"));
  2963. }
  2964. else
  2965. {
  2966. maxProfile.TransactionId = -1;
  2967. }
  2968. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration") != NULL)
  2969. {
  2970. maxProfile.ChargingSchedule.Duration = json_object_get_int(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration"));
  2971. }
  2972. else
  2973. {
  2974. maxProfile.ChargingSchedule.Duration = 86400;
  2975. }
  2976. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "startSchedule") != NULL)
  2977. {
  2978. 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")));
  2979. }
  2980. else
  2981. {
  2982. 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));
  2983. }
  2984. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate") != NULL)
  2985. {
  2986. maxProfile.ChargingSchedule.MinChargingRate = json_object_get_double(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate"));
  2987. }
  2988. else
  2989. {
  2990. maxProfile.ChargingSchedule.MinChargingRate = -1;
  2991. }
  2992. }
  2993. }
  2994. }
  2995. else
  2996. {
  2997. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  2998. {
  2999. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = -1;
  3000. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit = -1;
  3001. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases = 3;
  3002. }
  3003. if(maxProfile.ChargingProfileId == -1)
  3004. DEBUG_INFO("MaxProfile found.\n");
  3005. else
  3006. DEBUG_INFO("MaxProfile updated.\n");
  3007. // Required item
  3008. maxProfile.ChargingProfileId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileId"));
  3009. maxProfile.StackLevel = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "stackLevel"));
  3010. sprintf((char*)maxProfile.ChargingProfileKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileKind")));
  3011. if(isUnitA)
  3012. {
  3013. sprintf((char*)maxProfile.ChargingSchedule.ChargingRateUnit, "A");
  3014. 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++)
  3015. {
  3016. 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"));
  3017. 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?
  3018. 3:
  3019. 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")));
  3020. 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")));
  3021. }
  3022. }
  3023. else
  3024. {
  3025. sprintf((char*)maxProfile.ChargingSchedule.ChargingRateUnit, "W");
  3026. 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++)
  3027. {
  3028. 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"));
  3029. 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?
  3030. 3:
  3031. 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")));
  3032. 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));
  3033. }
  3034. }
  3035. // Optional item
  3036. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom") != NULL)
  3037. {
  3038. sprintf((char*)maxProfile.ValidFrom, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom")));
  3039. }
  3040. else
  3041. {
  3042. sprintf((char*)maxProfile.ValidFrom, " ");
  3043. }
  3044. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo") != NULL)
  3045. {
  3046. sprintf((char*)maxProfile.ValidTo, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo")));
  3047. }
  3048. else
  3049. {
  3050. sprintf((char*)maxProfile.ValidTo, " ");
  3051. }
  3052. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "recurrencyKind") != NULL)
  3053. {
  3054. sprintf((char*)maxProfile.RecurrencyKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "recurrencyKind")));
  3055. }
  3056. else
  3057. {
  3058. sprintf((char*)maxProfile.RecurrencyKind, " ");
  3059. }
  3060. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId") != NULL)
  3061. {
  3062. maxProfile.TransactionId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId"));
  3063. }
  3064. else
  3065. {
  3066. maxProfile.TransactionId = -1;
  3067. }
  3068. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration") != NULL)
  3069. {
  3070. maxProfile.ChargingSchedule.Duration = json_object_get_int(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration"));
  3071. }
  3072. else
  3073. {
  3074. maxProfile.ChargingSchedule.Duration = 86400;
  3075. }
  3076. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "startSchedule") != NULL)
  3077. {
  3078. 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")));
  3079. }
  3080. else
  3081. {
  3082. 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));
  3083. }
  3084. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate") != NULL)
  3085. {
  3086. maxProfile.ChargingSchedule.MinChargingRate = json_object_get_double(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate"));
  3087. }
  3088. else
  3089. {
  3090. maxProfile.ChargingSchedule.MinChargingRate = -1;
  3091. }
  3092. }
  3093. }
  3094. }
  3095. json_object_put(obj);
  3096. }
  3097. fclose(fp);
  3098. /*
  3099. if(maxProfile.ChargingProfileId !=-1)
  3100. {
  3101. DEBUG_INFO("Profile ID: %d\n", maxProfile.ChargingProfileId);
  3102. DEBUG_INFO("Profile stackLevel: %d\n", maxProfile.StackLevel);
  3103. DEBUG_INFO("Profile TransactionId: %d\n", maxProfile.TransactionId);
  3104. DEBUG_INFO("Profile valid from: %s\n", maxProfile.ValidFrom);
  3105. DEBUG_INFO("Profile valid to: %s\n", maxProfile.ValidTo);
  3106. DEBUG_INFO("Profile ChargingProfileKind: %s\n", maxProfile.ChargingProfileKind);
  3107. DEBUG_INFO("Profile recurrencyKind: %s\n", maxProfile.RecurrencyKind);
  3108. DEBUG_INFO("Profile start schedule: %s\n", maxProfile.ChargingSchedule.StartSchedule);
  3109. DEBUG_INFO("Profile schedule duration: %d\n", maxProfile.ChargingSchedule.Duration);
  3110. DEBUG_INFO("Profile charging rate unit: %s\n", maxProfile.ChargingSchedule.ChargingRateUnit);
  3111. DEBUG_INFO("Profile charging min rate: %f\n", maxProfile.ChargingSchedule.MinChargingRate);
  3112. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  3113. {
  3114. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod >= 0)
  3115. {
  3116. DEBUG_INFO("Period-%02d startPeriod: %d\n", idxPeriod, maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod);
  3117. DEBUG_INFO("Period-%02d limit: %f\n", idxPeriod, maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit);
  3118. DEBUG_INFO("Period-%02d NumberPhases: %d\n", idxPeriod, maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases);
  3119. }
  3120. }
  3121. }
  3122. else
  3123. DEBUG_INFO("MaxProfile not found.\n");
  3124. DEBUG_INFO("------------------------------------\n");*/
  3125. }
  3126. /*
  3127. * Align found profile start schedule & periods
  3128. */
  3129. //DEBUG_INFO("====================================\n");
  3130. /*
  3131. // For local test usage, force modify found profile start schedule info
  3132. 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);
  3133. 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);
  3134. 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);
  3135. */
  3136. if(txProfile.ChargingProfileId != -1)
  3137. {
  3138. if(strstr((char*)txProfile.ChargingProfileKind, "Absolute") != NULL)
  3139. {
  3140. if(txProfile.ChargingSchedule.Duration != -1)
  3141. {
  3142. txProfile.ChargingSchedule.Duration = ((txProfile.ChargingSchedule.Duration-getStartStop(txProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule))<0?
  3143. 0:
  3144. (txProfile.ChargingSchedule.Duration-getStartStop(txProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule)));
  3145. }
  3146. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(txProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  3147. {
  3148. if(txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  3149. {
  3150. txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = ((txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartStop(txProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule))<0?
  3151. 0:
  3152. (txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartStop(txProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule)));
  3153. if(idxPeriod > 0)
  3154. {
  3155. if(txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
  3156. {
  3157. txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit = txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit;
  3158. }
  3159. }
  3160. }
  3161. }
  3162. }
  3163. else if(strstr((char*)txProfile.ChargingProfileKind, "Relative") != NULL)
  3164. {
  3165. if(txProfile.ChargingSchedule.Duration != -1)
  3166. {
  3167. 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?
  3168. 0:
  3169. (txProfile.ChargingSchedule.Duration-getStartStop(ShmOCPP16Data->StartTransaction[(connectorId==0?0:connectorId-1)].Timestamp, compositeProfile.ChargingSchedule.StartSchedule)));
  3170. }
  3171. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(txProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  3172. {
  3173. if(txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  3174. {
  3175. 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?
  3176. 0:
  3177. (txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartStop(ShmOCPP16Data->StartTransaction[(connectorId==0?0:connectorId-1)].Timestamp, compositeProfile.ChargingSchedule.StartSchedule)));
  3178. if(idxPeriod > 0)
  3179. {
  3180. if(txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
  3181. {
  3182. txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit = txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit;
  3183. }
  3184. }
  3185. }
  3186. }
  3187. }
  3188. else
  3189. {
  3190. if(strstr((char*)txProfile.RecurrencyKind, "Weekly") != NULL)
  3191. {
  3192. if(txProfile.ChargingSchedule.Duration != -1)
  3193. {
  3194. txProfile.ChargingSchedule.Duration = ((txProfile.ChargingSchedule.Duration-getStartSinceRecurring(txProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule, FALSE))<0?
  3195. 0:
  3196. (txProfile.ChargingSchedule.Duration-getStartSinceRecurring(txProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule, FALSE)));
  3197. }
  3198. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(txProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  3199. {
  3200. if(txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  3201. {
  3202. txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = ((txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceRecurring(txProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule, FALSE))<0?
  3203. 0:
  3204. (txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceRecurring(txProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule, FALSE)));
  3205. if(idxPeriod > 0)
  3206. {
  3207. if(txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
  3208. {
  3209. txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit = txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit;
  3210. }
  3211. }
  3212. }
  3213. }
  3214. }
  3215. else
  3216. {
  3217. if(txProfile.ChargingSchedule.Duration != -1)
  3218. {
  3219. txProfile.ChargingSchedule.Duration = ((txProfile.ChargingSchedule.Duration-getStartSinceRecurring(txProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule, TRUE))<0?
  3220. 0:
  3221. (txProfile.ChargingSchedule.Duration-getStartSinceRecurring(txProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule, TRUE)));
  3222. }
  3223. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(txProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  3224. {
  3225. if(txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  3226. {
  3227. txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = ((txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceRecurring(txProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule, TRUE))<0?
  3228. 0:
  3229. (txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceRecurring(txProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule, TRUE)));
  3230. if(idxPeriod > 0)
  3231. {
  3232. if(txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
  3233. {
  3234. txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit = txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit;
  3235. }
  3236. }
  3237. }
  3238. }
  3239. }
  3240. }
  3241. /*
  3242. DEBUG_INFO("txProfile after align.\n");
  3243. DEBUG_INFO("Profile ID: %d\n", txProfile.ChargingProfileId);
  3244. DEBUG_INFO("Profile stackLevel: %d\n", txProfile.StackLevel);
  3245. DEBUG_INFO("Profile TransactionId: %d\n", txProfile.TransactionId);
  3246. DEBUG_INFO("Profile valid from: %s\n", txProfile.ValidFrom);
  3247. DEBUG_INFO("Profile valid to: %s\n", txProfile.ValidTo);
  3248. DEBUG_INFO("Profile ChargingProfileKind: %s\n", txProfile.ChargingProfileKind);
  3249. DEBUG_INFO("Profile recurrencyKind: %s\n", txProfile.RecurrencyKind);
  3250. DEBUG_INFO("Profile start schedule: %s\n", compositeProfile.ChargingSchedule.StartSchedule);
  3251. DEBUG_INFO("Profile schedule duration: %d\n", txProfile.ChargingSchedule.Duration);
  3252. DEBUG_INFO("Profile charging rate unit: %s\n", txProfile.ChargingSchedule.ChargingRateUnit);
  3253. DEBUG_INFO("Profile charging min rate: %f\n", txProfile.ChargingSchedule.MinChargingRate);
  3254. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(txProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  3255. {
  3256. if(txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod >= 0)
  3257. {
  3258. DEBUG_INFO("Period-%02d startPeriod: %d\n", idxPeriod, txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod);
  3259. DEBUG_INFO("Period-%02d limit: %f\n", idxPeriod, txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit);
  3260. DEBUG_INFO("Period-%02d NumberPhases: %d\n", idxPeriod, txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases);
  3261. }
  3262. }*/
  3263. }
  3264. if(defaultTxProfile.ChargingProfileId != -1)
  3265. {
  3266. if(strstr((char*)defaultTxProfile.ChargingProfileKind, "Absolute") != NULL)
  3267. {
  3268. if(defaultTxProfile.ChargingSchedule.Duration != -1)
  3269. {
  3270. defaultTxProfile.ChargingSchedule.Duration = ((defaultTxProfile.ChargingSchedule.Duration-getStartStop(defaultTxProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule))<0?
  3271. 0:
  3272. (defaultTxProfile.ChargingSchedule.Duration-getStartStop(defaultTxProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule)));
  3273. }
  3274. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  3275. {
  3276. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  3277. {
  3278. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = ((defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartStop(defaultTxProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule))<0?
  3279. 0:
  3280. (defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartStop(defaultTxProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule)));
  3281. if(idxPeriod > 0)
  3282. {
  3283. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
  3284. {
  3285. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit = defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit;
  3286. }
  3287. }
  3288. }
  3289. }
  3290. }
  3291. else if(strstr((char*)defaultTxProfile.ChargingProfileKind, "Relative") != NULL)
  3292. {
  3293. if(defaultTxProfile.ChargingSchedule.Duration != -1)
  3294. {
  3295. 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?
  3296. 0:
  3297. (defaultTxProfile.ChargingSchedule.Duration-getStartStop(ShmOCPP16Data->StartTransaction[(connectorId==0?0:connectorId-1)].Timestamp, compositeProfile.ChargingSchedule.StartSchedule)));
  3298. }
  3299. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  3300. {
  3301. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  3302. {
  3303. 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?
  3304. 0:
  3305. (defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartStop(ShmOCPP16Data->StartTransaction[(connectorId==0?0:connectorId-1)].Timestamp, compositeProfile.ChargingSchedule.StartSchedule)));
  3306. if(idxPeriod > 0)
  3307. {
  3308. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
  3309. {
  3310. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit = defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit;
  3311. }
  3312. }
  3313. }
  3314. }
  3315. }
  3316. else
  3317. {
  3318. if(strstr((char*)defaultTxProfile.RecurrencyKind, "Weekly") != NULL)
  3319. {
  3320. if(defaultTxProfile.ChargingSchedule.Duration != -1)
  3321. {
  3322. defaultTxProfile.ChargingSchedule.Duration = ((defaultTxProfile.ChargingSchedule.Duration-getStartSinceRecurring(defaultTxProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule, FALSE))<0?
  3323. 0:
  3324. (defaultTxProfile.ChargingSchedule.Duration-getStartSinceRecurring(defaultTxProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule, FALSE)));
  3325. }
  3326. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  3327. {
  3328. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  3329. {
  3330. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = ((defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceRecurring(defaultTxProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule, FALSE))<0?
  3331. 0:
  3332. (defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceRecurring(defaultTxProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule, FALSE)));
  3333. if(idxPeriod > 0)
  3334. {
  3335. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
  3336. {
  3337. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit = defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit;
  3338. }
  3339. }
  3340. }
  3341. }
  3342. }
  3343. else
  3344. {
  3345. if(defaultTxProfile.ChargingSchedule.Duration != -1)
  3346. {
  3347. defaultTxProfile.ChargingSchedule.Duration = ((defaultTxProfile.ChargingSchedule.Duration-getStartSinceRecurring(defaultTxProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule, TRUE))<0?
  3348. 0:
  3349. (defaultTxProfile.ChargingSchedule.Duration-getStartSinceRecurring(defaultTxProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule, TRUE)));
  3350. }
  3351. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  3352. {
  3353. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  3354. {
  3355. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = ((defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceRecurring(defaultTxProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule, TRUE))<0?
  3356. 0:
  3357. (defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceRecurring(defaultTxProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule, TRUE)));
  3358. if(idxPeriod > 0)
  3359. {
  3360. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
  3361. {
  3362. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit = defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit;
  3363. }
  3364. }
  3365. }
  3366. }
  3367. }
  3368. }
  3369. /*
  3370. DEBUG_INFO("defaultTxProfile after align.\n");
  3371. DEBUG_INFO("Profile ID: %d\n", defaultTxProfile.ChargingProfileId);
  3372. DEBUG_INFO("Profile stackLevel: %d\n", defaultTxProfile.StackLevel);
  3373. DEBUG_INFO("Profile TransactionId: %d\n", defaultTxProfile.TransactionId);
  3374. DEBUG_INFO("Profile valid from: %s\n", defaultTxProfile.ValidFrom);
  3375. DEBUG_INFO("Profile valid to: %s\n", defaultTxProfile.ValidTo);
  3376. DEBUG_INFO("Profile ChargingProfileKind: %s\n", defaultTxProfile.ChargingProfileKind);
  3377. DEBUG_INFO("Profile recurrencyKind: %s\n", defaultTxProfile.RecurrencyKind);
  3378. DEBUG_INFO("Profile start schedule: %s\n", compositeProfile.ChargingSchedule.StartSchedule);
  3379. DEBUG_INFO("Profile schedule duration: %d\n", defaultTxProfile.ChargingSchedule.Duration);
  3380. DEBUG_INFO("Profile charging rate unit: %s\n", defaultTxProfile.ChargingSchedule.ChargingRateUnit);
  3381. DEBUG_INFO("Profile charging min rate: %f\n", defaultTxProfile.ChargingSchedule.MinChargingRate);
  3382. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  3383. {
  3384. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod >= 0)
  3385. {
  3386. DEBUG_INFO("Period-%02d startPeriod: %d\n", idxPeriod, defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod);
  3387. DEBUG_INFO("Period-%02d limit: %f\n", idxPeriod, defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit);
  3388. DEBUG_INFO("Period-%02d NumberPhases: %d\n", idxPeriod, defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases);
  3389. }
  3390. }
  3391. DEBUG_INFO("------------------------------------\n");*/
  3392. }
  3393. if(maxProfile.ChargingProfileId != -1)
  3394. {
  3395. if(strstr((char*)maxProfile.ChargingProfileKind, "Absolute") != NULL)
  3396. {
  3397. if(maxProfile.ChargingSchedule.Duration != -1)
  3398. {
  3399. maxProfile.ChargingSchedule.Duration = ((maxProfile.ChargingSchedule.Duration-getStartStop(maxProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule))<0?
  3400. 0:
  3401. (maxProfile.ChargingSchedule.Duration-getStartStop(maxProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule)));
  3402. }
  3403. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  3404. {
  3405. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  3406. {
  3407. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = ((maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartStop(maxProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule))<0?
  3408. 0:
  3409. (maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartStop(maxProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule)));
  3410. if(idxPeriod > 0)
  3411. {
  3412. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
  3413. {
  3414. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit = maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit;
  3415. }
  3416. }
  3417. }
  3418. }
  3419. }
  3420. else if(strstr((char*)maxProfile.ChargingProfileKind, "Relative") != NULL)
  3421. {
  3422. if(maxProfile.ChargingSchedule.Duration != -1)
  3423. {
  3424. 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?
  3425. 0:
  3426. (maxProfile.ChargingSchedule.Duration-getStartStop(ShmOCPP16Data->StartTransaction[(connectorId==0?0:connectorId-1)].Timestamp, compositeProfile.ChargingSchedule.StartSchedule)));
  3427. }
  3428. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  3429. {
  3430. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  3431. {
  3432. 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?
  3433. 0:
  3434. (maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartStop(ShmOCPP16Data->StartTransaction[(connectorId==0?0:connectorId-1)].Timestamp, compositeProfile.ChargingSchedule.StartSchedule)));
  3435. if(idxPeriod > 0)
  3436. {
  3437. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
  3438. {
  3439. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit = maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit;
  3440. }
  3441. }
  3442. }
  3443. }
  3444. }
  3445. else
  3446. {
  3447. if(strstr((char*)maxProfile.RecurrencyKind, "Weekly") != NULL)
  3448. {
  3449. if(maxProfile.ChargingSchedule.Duration != -1)
  3450. {
  3451. maxProfile.ChargingSchedule.Duration = ((maxProfile.ChargingSchedule.Duration-getStartSinceRecurring(maxProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule, FALSE))<0?
  3452. 0:
  3453. (maxProfile.ChargingSchedule.Duration-getStartSinceRecurring(maxProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule, FALSE)));
  3454. }
  3455. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  3456. {
  3457. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  3458. {
  3459. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = ((maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceRecurring(maxProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule, FALSE))<0?
  3460. 0:
  3461. (maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceRecurring(maxProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule, FALSE)));
  3462. if(idxPeriod > 0)
  3463. {
  3464. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
  3465. {
  3466. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit = maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit;
  3467. }
  3468. }
  3469. }
  3470. }
  3471. }
  3472. else
  3473. {
  3474. if(maxProfile.ChargingSchedule.Duration != -1)
  3475. {
  3476. maxProfile.ChargingSchedule.Duration = ((maxProfile.ChargingSchedule.Duration-getStartSinceRecurring(maxProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule, TRUE))<0?
  3477. 0:
  3478. (maxProfile.ChargingSchedule.Duration-getStartSinceRecurring(maxProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule, TRUE)));
  3479. }
  3480. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  3481. {
  3482. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  3483. {
  3484. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = ((maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceRecurring(maxProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule, TRUE))<0?
  3485. 0:
  3486. (maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceRecurring(maxProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule, TRUE)));
  3487. if(idxPeriod > 0)
  3488. {
  3489. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
  3490. {
  3491. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit = maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit;
  3492. }
  3493. }
  3494. }
  3495. }
  3496. }
  3497. }
  3498. /*
  3499. DEBUG_INFO("MaxProfile after align.\n");
  3500. DEBUG_INFO("Profile ID: %d\n", maxProfile.ChargingProfileId);
  3501. DEBUG_INFO("Profile stackLevel: %d\n", maxProfile.StackLevel);
  3502. DEBUG_INFO("Profile TransactionId: %d\n", maxProfile.TransactionId);
  3503. DEBUG_INFO("Profile valid from: %s\n", maxProfile.ValidFrom);
  3504. DEBUG_INFO("Profile valid to: %s\n", maxProfile.ValidTo);
  3505. DEBUG_INFO("Profile ChargingProfileKind: %s\n", maxProfile.ChargingProfileKind);
  3506. DEBUG_INFO("Profile recurrencyKind: %s\n", maxProfile.RecurrencyKind);
  3507. DEBUG_INFO("Profile start schedule: %s\n", compositeProfile.ChargingSchedule.StartSchedule);
  3508. DEBUG_INFO("Profile schedule duration: %d\n", maxProfile.ChargingSchedule.Duration);
  3509. DEBUG_INFO("Profile charging rate unit: %s\n", maxProfile.ChargingSchedule.ChargingRateUnit);
  3510. DEBUG_INFO("Profile charging min rate: %f\n", maxProfile.ChargingSchedule.MinChargingRate);
  3511. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  3512. {
  3513. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod >= 0)
  3514. {
  3515. DEBUG_INFO("Period-%02d startPeriod: %d\n", idxPeriod, maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod);
  3516. DEBUG_INFO("Period-%02d limit: %f\n", idxPeriod, maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit);
  3517. DEBUG_INFO("Period-%02d NumberPhases: %d\n", idxPeriod, maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases);
  3518. }
  3519. }
  3520. DEBUG_INFO("------------------------------------\n");*/
  3521. }
  3522. /*
  3523. * Merge to conposite schedule
  3524. */
  3525. //DEBUG_INFO("====================================\n");
  3526. // Find each profile period quantity
  3527. for(int idx=0;idx<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idx++)
  3528. {
  3529. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idx].Limit != -1)
  3530. limitMax = idx+1;
  3531. }
  3532. for(int idx=0;idx<ARRAY_SIZE(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod);idx++)
  3533. {
  3534. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idx].Limit != -1)
  3535. limitDef = idx+1;
  3536. }
  3537. for(int idx=0;idx<ARRAY_SIZE(txProfile.ChargingSchedule.ChargingSchedulePeriod);idx++)
  3538. {
  3539. if(txProfile.ChargingSchedule.ChargingSchedulePeriod[idx].Limit != -1)
  3540. limitTx = idx+1;
  3541. }
  3542. // TxProfile found, composite schedule based on it
  3543. if(txProfile.ChargingProfileId != -1)
  3544. {
  3545. compositeProfile.ChargingSchedule.Duration = txProfile.ChargingSchedule.Duration;
  3546. for(int idxTxPeriod=0;idxTxPeriod<limitTx;idxTxPeriod++)
  3547. {
  3548. if((txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod].Limit != -1) &&
  3549. (txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod].StartPeriod < durationReq) &&
  3550. (txProfile.ChargingSchedule.Duration > 0))
  3551. {
  3552. if(maxProfile.ChargingProfileId != -1)
  3553. {
  3554. for(int idxMaxPeriod=0;idxMaxPeriod<limitMax;idxMaxPeriod++)
  3555. {
  3556. if((txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod].StartPeriod >= maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].StartPeriod))
  3557. {
  3558. if((maxProfile.ChargingSchedule.Duration > 0))
  3559. {
  3560. tmpPeriod.StartPeriod = txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod].StartPeriod;
  3561. tmpPeriod.NumberPhases = txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod].NumberPhases;
  3562. tmpPeriod.Limit = (txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod].Limit>maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].Limit?maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].Limit:txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod].Limit);
  3563. }
  3564. else
  3565. {
  3566. tmpPeriod.StartPeriod = txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod].StartPeriod;
  3567. tmpPeriod.NumberPhases = txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod].NumberPhases;
  3568. tmpPeriod.Limit = txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod].Limit;
  3569. }
  3570. }
  3571. if(idxMaxPeriod == (limitMax-1))
  3572. {
  3573. if(tmpPeriod.Limit != compositeProfile.ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].Limit)
  3574. {
  3575. if(tmpPeriod.StartPeriod != compositeProfile.ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].StartPeriod)
  3576. {
  3577. memcpy(&compositeProfile.ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx], &tmpPeriod , sizeof(struct StructChargingSchedulePeriod));
  3578. compositePeriodIdx++;
  3579. }
  3580. else
  3581. {
  3582. memcpy(&compositeProfile.ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)], &tmpPeriod , sizeof(struct StructChargingSchedulePeriod));
  3583. }
  3584. }
  3585. }
  3586. }
  3587. }
  3588. else
  3589. {
  3590. if(txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod].StartPeriod != compositeProfile.ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].StartPeriod)
  3591. {
  3592. memcpy(&compositeProfile.ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx], &txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod],sizeof(struct StructChargingSchedulePeriod));
  3593. compositePeriodIdx++;
  3594. }
  3595. else
  3596. {
  3597. memcpy(&compositeProfile.ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)], &txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod],sizeof(struct StructChargingSchedulePeriod));
  3598. }
  3599. }
  3600. }
  3601. if(idxTxPeriod == (limitTx-1))
  3602. {
  3603. if(defaultTxProfile.ChargingProfileId != -1)
  3604. {
  3605. compositeProfile.ChargingSchedule.Duration = (defaultTxProfile.ChargingSchedule.Duration>compositeProfile.ChargingSchedule.Duration)?defaultTxProfile.ChargingSchedule.Duration:compositeProfile.ChargingSchedule.Duration;
  3606. for(int idxDefPeriod=0;idxDefPeriod<limitDef;idxDefPeriod++)
  3607. {
  3608. if((defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].StartPeriod >= (txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod].StartPeriod + (txProfile.ChargingSchedule.Duration-defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].StartPeriod))) &&
  3609. (defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].StartPeriod < durationReq) &&
  3610. (defaultTxProfile.ChargingSchedule.Duration>0))
  3611. {
  3612. if(maxProfile.ChargingProfileId != -1)
  3613. {
  3614. for(int idxMaxPeriod=0;idxMaxPeriod<limitMax;idxMaxPeriod++)
  3615. {
  3616. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].StartPeriod >= maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].StartPeriod)
  3617. {
  3618. if((maxProfile.ChargingSchedule.Duration > 0))
  3619. {
  3620. tmpPeriod.StartPeriod = defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].StartPeriod;
  3621. tmpPeriod.NumberPhases = defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].NumberPhases;
  3622. tmpPeriod.Limit = (defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].Limit>maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].Limit?maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].Limit:defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod].Limit);
  3623. }
  3624. else
  3625. {
  3626. tmpPeriod.StartPeriod = defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].StartPeriod;
  3627. tmpPeriod.NumberPhases = defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].NumberPhases;
  3628. tmpPeriod.Limit = defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].Limit;
  3629. }
  3630. if(tmpPeriod.Limit != compositeProfile.ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].Limit)
  3631. {
  3632. if(tmpPeriod.StartPeriod != compositeProfile.ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].StartPeriod)
  3633. {
  3634. memcpy(&compositeProfile.ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx], &tmpPeriod , sizeof(struct StructChargingSchedulePeriod));
  3635. compositePeriodIdx++;
  3636. }
  3637. else
  3638. {
  3639. memcpy(&compositeProfile.ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)], &tmpPeriod , sizeof(struct StructChargingSchedulePeriod));
  3640. }
  3641. }
  3642. // Delete duplicate period
  3643. if(compositePeriodIdx > 1)
  3644. {
  3645. if(compositeProfile.ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx-1].Limit == compositeProfile.ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx-2].Limit)
  3646. {
  3647. compositeProfile.ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx-1].StartPeriod = -1;
  3648. compositeProfile.ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx-1].Limit = -1;
  3649. compositePeriodIdx -= 1;
  3650. }
  3651. }
  3652. }
  3653. else
  3654. {
  3655. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].StartPeriod != compositeProfile.ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].StartPeriod)
  3656. {
  3657. memcpy(&compositeProfile.ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx], &defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod],sizeof(struct StructChargingSchedulePeriod));
  3658. compositePeriodIdx++;
  3659. }
  3660. else
  3661. {
  3662. memcpy(&compositeProfile.ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)], &defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod],sizeof(struct StructChargingSchedulePeriod));
  3663. }
  3664. break;
  3665. }
  3666. }
  3667. }
  3668. else
  3669. {
  3670. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].StartPeriod != compositeProfile.ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].StartPeriod)
  3671. {
  3672. memcpy(&compositeProfile.ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx], &defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod],sizeof(struct StructChargingSchedulePeriod));
  3673. compositePeriodIdx++;
  3674. }
  3675. else
  3676. {
  3677. memcpy(&compositeProfile.ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)], &defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod],sizeof(struct StructChargingSchedulePeriod));
  3678. }
  3679. }
  3680. }
  3681. }
  3682. }
  3683. }
  3684. }
  3685. }
  3686. // TxProfile not found but defaultTxProfile found, composite schedule based on it
  3687. else if(defaultTxProfile.ChargingProfileId != -1)
  3688. {
  3689. compositeProfile.ChargingSchedule.Duration = defaultTxProfile.ChargingSchedule.Duration;
  3690. for(int idxDefPeriod=0;idxDefPeriod<limitDef;idxDefPeriod++)
  3691. {
  3692. if((defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].Limit != -1) &&
  3693. (defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].StartPeriod < durationReq) &&
  3694. (defaultTxProfile.ChargingSchedule.Duration > 0))
  3695. {
  3696. if(maxProfile.ChargingProfileId != -1)
  3697. {
  3698. for(int idxMaxPeriod=0;idxMaxPeriod<limitMax;idxMaxPeriod++)
  3699. {
  3700. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].StartPeriod >= maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].StartPeriod)
  3701. {
  3702. tmpPeriod.StartPeriod = defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].StartPeriod;
  3703. tmpPeriod.NumberPhases = defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].NumberPhases;
  3704. if((maxProfile.ChargingSchedule.Duration > 0))
  3705. {
  3706. tmpPeriod.Limit = (defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].Limit>maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].Limit?maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].Limit:defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].Limit);
  3707. }
  3708. else
  3709. {
  3710. tmpPeriod.Limit = defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].Limit;
  3711. }
  3712. if(tmpPeriod.Limit != compositeProfile.ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].Limit)
  3713. {
  3714. if(tmpPeriod.StartPeriod != compositeProfile.ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].StartPeriod)
  3715. {
  3716. memcpy(&compositeProfile.ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx], &tmpPeriod , sizeof(struct StructChargingSchedulePeriod));
  3717. compositePeriodIdx++;
  3718. }
  3719. else
  3720. {
  3721. memcpy(&compositeProfile.ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)], &tmpPeriod , sizeof(struct StructChargingSchedulePeriod));
  3722. }
  3723. }
  3724. // Delete duplicate period
  3725. if(compositePeriodIdx > 1)
  3726. {
  3727. if(compositeProfile.ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx-1].Limit == compositeProfile.ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx-2].Limit)
  3728. {
  3729. compositeProfile.ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx-1].StartPeriod = -1;
  3730. compositeProfile.ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx-1].Limit = -1;
  3731. compositePeriodIdx -= 1;
  3732. }
  3733. }
  3734. }
  3735. else
  3736. {
  3737. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].StartPeriod != compositeProfile.ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].StartPeriod)
  3738. {
  3739. memcpy(&compositeProfile.ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx], &defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod],sizeof(struct StructChargingSchedulePeriod));
  3740. compositePeriodIdx++;
  3741. }
  3742. else
  3743. {
  3744. memcpy(&compositeProfile.ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)], &defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod],sizeof(struct StructChargingSchedulePeriod));
  3745. }
  3746. break;
  3747. }
  3748. }
  3749. }
  3750. else
  3751. {
  3752. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].StartPeriod != compositeProfile.ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].StartPeriod)
  3753. {
  3754. memcpy(&compositeProfile.ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx], &defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod],sizeof(struct StructChargingSchedulePeriod));
  3755. compositePeriodIdx++;
  3756. }
  3757. else
  3758. {
  3759. memcpy(&compositeProfile.ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)], &defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod],sizeof(struct StructChargingSchedulePeriod));
  3760. }
  3761. }
  3762. }
  3763. }
  3764. }
  3765. // Fill other period by MaxProfile
  3766. if(maxProfile.ChargingProfileId != -1)
  3767. {
  3768. if(compositePeriodIdx==0)
  3769. {
  3770. compositeProfile.ChargingSchedule.Duration = maxProfile.ChargingSchedule.Duration;
  3771. for(int idxMaxPeriod=0;idxMaxPeriod<limitDef;idxMaxPeriod++)
  3772. {
  3773. if((maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].Limit != -1) &&
  3774. (maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].StartPeriod < durationReq) &&
  3775. (maxProfile.ChargingSchedule.Duration > 0))
  3776. {
  3777. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].StartPeriod != compositeProfile.ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].StartPeriod)
  3778. {
  3779. memcpy(&compositeProfile.ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx], &maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod],sizeof(struct StructChargingSchedulePeriod));
  3780. compositePeriodIdx++;
  3781. }
  3782. else
  3783. {
  3784. memcpy(&compositeProfile.ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)], &maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod],sizeof(struct StructChargingSchedulePeriod));
  3785. }
  3786. }
  3787. }
  3788. }
  3789. else
  3790. {
  3791. int lastCompositePeriodIdx = compositePeriodIdx;
  3792. for(int idxMaxPeriod=0;idxMaxPeriod<limitMax;idxMaxPeriod++)
  3793. {
  3794. if((maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].Limit != -1) &&
  3795. (maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].StartPeriod < durationReq) &&
  3796. (maxProfile.ChargingSchedule.Duration > 0))
  3797. {
  3798. if((maxProfile.ChargingSchedule.Duration >= compositeProfile.ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx-1].StartPeriod))
  3799. {
  3800. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].Limit > compositeProfile.ChargingSchedule.ChargingSchedulePeriod[lastCompositePeriodIdx-1].Limit)
  3801. {
  3802. tmpPeriod.StartPeriod = maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].StartPeriod;
  3803. tmpPeriod.NumberPhases = maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].NumberPhases;
  3804. tmpPeriod.Limit = compositeProfile.ChargingSchedule.ChargingSchedulePeriod[lastCompositePeriodIdx-1].Limit;
  3805. }
  3806. else
  3807. {
  3808. tmpPeriod.StartPeriod = maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].StartPeriod;
  3809. tmpPeriod.NumberPhases = maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].NumberPhases;
  3810. tmpPeriod.Limit = maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].Limit;
  3811. }
  3812. }
  3813. if(tmpPeriod.Limit != -1)
  3814. {
  3815. if(tmpPeriod.Limit != compositeProfile.ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx-1].Limit)
  3816. {
  3817. if(tmpPeriod.StartPeriod != compositeProfile.ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx-1].StartPeriod)
  3818. {
  3819. memcpy(&compositeProfile.ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx], &tmpPeriod , sizeof(struct StructChargingSchedulePeriod));
  3820. compositePeriodIdx++;
  3821. }
  3822. else
  3823. {
  3824. memcpy(&compositeProfile.ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx-1], &tmpPeriod , sizeof(struct StructChargingSchedulePeriod));
  3825. }
  3826. }
  3827. // Delete duplicate period
  3828. if(compositePeriodIdx > 1)
  3829. {
  3830. if(compositeProfile.ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx-1].Limit == compositeProfile.ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx-2].Limit)
  3831. {
  3832. compositeProfile.ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx-1].StartPeriod = -1;
  3833. compositeProfile.ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx-1].Limit = -1;
  3834. compositePeriodIdx -= 1;
  3835. }
  3836. }
  3837. }
  3838. }
  3839. }
  3840. }
  3841. }
  3842. compositeProfile.ChargingSchedule.Duration = durationReq;
  3843. DEBUG_INFO("Connector-%d composite schedule ready.\n", connectorId);
  3844. DEBUG_INFO("Schedule start: %s\n", compositeProfile.ChargingSchedule.StartSchedule);
  3845. DEBUG_INFO("Schedule duration: %d\n", compositeProfile.ChargingSchedule.Duration);
  3846. DEBUG_INFO("Rate unit: %s\n", compositeProfile.ChargingSchedule.ChargingRateUnit);
  3847. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(compositeProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  3848. {
  3849. if(compositeProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod >= 0)
  3850. {
  3851. compositeProfile.ChargingProfileId = 1;
  3852. DEBUG_INFO("Period-%02d startPeriod: %d\n", idxPeriod, compositeProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod);
  3853. DEBUG_INFO("Period-%02d limit: %f\n", idxPeriod, compositeProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit);
  3854. DEBUG_INFO("Period-%02d NumberPhases: %d\n", idxPeriod, compositeProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases);
  3855. }
  3856. if(compositeProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit == -1)
  3857. compositeProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit =0;
  3858. if(compositeProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod == -1)
  3859. compositeProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod =0;
  3860. }
  3861. memcpy(targetCompositeProfile, &compositeProfile, sizeof(struct StructChargingProfile));
  3862. if(line)
  3863. free(line);
  3864. checkChargePointMaxProfile(durationReq, &ShmOCPP16Data->MaxChargingProfile, isUnitA);
  3865. ShmOCPP16Data->CSUMsg.bits[(connectorId==0?0:connectorId-1)].ChargingProfileConf = 1;
  3866. }
  3867. //==========================================
  3868. // Init all share memory
  3869. //==========================================
  3870. int InitShareMemory()
  3871. {
  3872. int result = PASS;
  3873. int MeterSMId;
  3874. //creat ShmSysConfigAndInfo
  3875. if ((MeterSMId = shmget(ShmSysConfigAndInfoKey, sizeof(struct SysConfigAndInfo), 0777)) < 0)
  3876. {
  3877. DEBUG_ERROR("shmget ShmSysConfigAndInfo NG\n");
  3878. result = FAIL;
  3879. }
  3880. else if ((ShmSysConfigAndInfo = shmat(MeterSMId, NULL, 0)) == (void *) -1)
  3881. {
  3882. DEBUG_ERROR("shmat ShmSysConfigAndInfo NG\n");
  3883. result = FAIL;
  3884. }
  3885. else
  3886. {}
  3887. if ((MeterSMId = shmget(ShmStatusCodeKey, sizeof(struct StatusCodeData), 0777)) < 0)
  3888. {
  3889. DEBUG_ERROR("shmget ShmStatusCodeData NG\n");
  3890. result = FAIL;
  3891. }
  3892. else if ((ShmStatusCodeData = shmat(MeterSMId, NULL, 0)) == (void *) -1)
  3893. {
  3894. DEBUG_ERROR("shmat ShmStatusCodeData NG\n");
  3895. result = FAIL;
  3896. }
  3897. else
  3898. {}
  3899. //creat ShmPsuData
  3900. if ((MeterSMId = shmget(ShmPsuKey, sizeof(struct PsuData), 0777)) < 0)
  3901. {
  3902. DEBUG_ERROR("shmget ShmPsuData NG\n");
  3903. result = FAIL;
  3904. }
  3905. else if ((ShmPsuData = shmat(MeterSMId, NULL, 0)) == (void *) -1)
  3906. {
  3907. DEBUG_ERROR("shmat ShmPsuData NG\n");
  3908. result = FAIL;
  3909. }
  3910. else
  3911. {}
  3912. //creat ShmOCPP16Data
  3913. if ((MeterSMId = shmget(ShmOcppModuleKey, sizeof(struct OCPP16Data), 0777)) < 0)
  3914. {
  3915. DEBUG_ERROR("shmget ShmOCPP16Data NG\n");
  3916. result = FAIL;
  3917. }
  3918. else if ((ShmOCPP16Data = shmat(MeterSMId, NULL, 0)) == (void *) -1)
  3919. {
  3920. DEBUG_ERROR("shmat ShmOCPP16Data NG\n");
  3921. result = FAIL;
  3922. }
  3923. else
  3924. {}
  3925. /****************************** For Initial Settings************************************************/
  3926. ShmOCPP16Data->GetConfiguration.ResponseUnknownKey = NULL;
  3927. ShmOCPP16Data->SendLocalList.LocalAuthorizationList = NULL;
  3928. // allocate Configuration memory address
  3929. ShmOCPP16Data->GetConfiguration.Key = staticKeyArray;
  3930. ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey = staticResponseConfigurationKeyArray;
  3931. ShmOCPP16Data->GetConfiguration.ResponseUnknownKey = staticResponseUnknownKey;
  3932. ShmOCPP16Data->SendLocalList.LocalAuthorizationList = staticLocalAuthorizationList;
  3933. sprintf((char*)ShmOCPP16Data->FirmwareStatusNotification.Status, "%s",FirmwareStatusStr[FirmwareStatus_Idle]);
  3934. //offline MeterValue Interval
  3935. TempMeterValueInterval = 0;
  3936. return result;
  3937. }
  3938. int ProcessShareMemory()
  3939. {
  3940. int result = PASS;
  3941. if(InitShareMemory() == FAIL)
  3942. {
  3943. DEBUG_ERROR("InitShareMemory NG\n");
  3944. if(ShmStatusCodeData!=NULL)
  3945. {
  3946. ShmStatusCodeData->AlarmCode.AlarmEvents.bits.FailToCreateShareMemory=1;
  3947. }
  3948. result = FAIL;
  3949. }
  3950. // Model name parsing
  3951. if(RatedCurrentParsing((char*)ShmSysConfigAndInfo->SysConfig.ModelName, &modelnameInfo) != -1)
  3952. {
  3953. DEBUG_INFO("Model name rated power: %d\n", modelnameInfo.ratedPower);
  3954. if((ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D') &&
  3955. ((ShmSysConfigAndInfo->SysConfig.ModelName[1]=='B') ||
  3956. (ShmSysConfigAndInfo->SysConfig.ModelName[1]=='K') ||
  3957. (ShmSysConfigAndInfo->SysConfig.ModelName[1]=='O'))
  3958. ) // 'D' means DC
  3959. {
  3960. // DO series
  3961. for(int gun_index=0; gun_index<GENERAL_GUN_QUANTITY ; gun_index++)
  3962. {
  3963. gunTotalNumber += 1;
  3964. gunType[gun_index] = GUN_TYPE_DO;
  3965. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  3966. {
  3967. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == gun_index)
  3968. {
  3969. periousPeriodicPowerConsumption[gun_index] = ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PowerConsumption;
  3970. periousClockPowerConsumption[gun_index] = ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PowerConsumption;
  3971. DEBUG_INFO("Gun-%02d PowerConsumption: %.3f\n", gun_index, ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PowerConsumption);
  3972. }
  3973. }
  3974. switch(modelnameInfo.ParsingInfo[gun_index].GunType)
  3975. {
  3976. case Gun_Type_Chademo:
  3977. DEBUG_INFO("Gun-%02d type: Cabinet CHAdeMO\n", gun_index);
  3978. break;
  3979. case Gun_Type_CCS_2:
  3980. DEBUG_INFO("Gun-%02d type: Cabinet CCS\n", gun_index);
  3981. break;
  3982. case Gun_Type_GB:
  3983. DEBUG_INFO("Gun-%02d type: Cabinet GBT\n", gun_index);
  3984. break;
  3985. case Gun_Type_AC:
  3986. DEBUG_INFO("Gun-%02d type: Cabinet AC\n", gun_index);
  3987. break;
  3988. default:
  3989. DEBUG_WARN("Gun-%02d type: Cabinet unknown\n", gun_index);
  3990. break;
  3991. }
  3992. }
  3993. }
  3994. else
  3995. {
  3996. for(int gun_index=0;gun_index<modelnameInfo.GetGunCount;gun_index++)
  3997. {
  3998. gunTotalNumber += 1;
  3999. switch(modelnameInfo.ParsingInfo[gun_index].GunType)
  4000. {
  4001. case Gun_Type_Chademo:
  4002. gunType[gun_index] = GUN_TYPE_CHAdeMO;
  4003. DEBUG_INFO("Gun-%02d type: CHAdeMO\n", gun_index);
  4004. for(int index = 0; index < CHAdeMO_QUANTITY; index++)
  4005. {
  4006. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == gun_index)
  4007. {
  4008. periousPeriodicPowerConsumption[gun_index] = ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PowerConsumption;
  4009. periousClockPowerConsumption[gun_index] = ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PowerConsumption;
  4010. DEBUG_INFO("Gun-%02d PowerConsumption: %.3f\n", gun_index, ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PowerConsumption);
  4011. }
  4012. }
  4013. break;
  4014. case Gun_Type_CCS_2:
  4015. gunType[gun_index] = GUN_TYPE_CCS;
  4016. DEBUG_INFO("Gun-%02d type: CCS\n", gun_index);
  4017. for (int index = 0; index < CCS_QUANTITY; index++)
  4018. {
  4019. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == gun_index)
  4020. {
  4021. periousPeriodicPowerConsumption[gun_index] = ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PowerConsumption;
  4022. periousClockPowerConsumption[gun_index] = ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PowerConsumption;
  4023. DEBUG_INFO("Gun-%02d PowerConsumption: %.3f\n", gun_index, ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PowerConsumption);
  4024. }
  4025. }
  4026. break;
  4027. case Gun_Type_GB:
  4028. gunType[gun_index] = GUN_TYPE_GBT;
  4029. DEBUG_INFO("Gun-%02d type: GBT\n", gun_index);
  4030. for (int index = 0; index < GB_QUANTITY; index++)
  4031. {
  4032. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == gun_index)
  4033. {
  4034. periousPeriodicPowerConsumption[gun_index] = ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PowerConsumption;
  4035. periousClockPowerConsumption[gun_index] = ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PowerConsumption;
  4036. DEBUG_INFO("Gun-%02d PowerConsumption: %.3f\n", gun_index, ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PowerConsumption);
  4037. }
  4038. }
  4039. break;
  4040. case Gun_Type_AC:
  4041. gunType[gun_index] = GUN_TYPE_AC;
  4042. DEBUG_INFO("Gun-%02d type: AC\n", gun_index);
  4043. for (int index = 0; index < AC_QUANTITY; index++)
  4044. {
  4045. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == gun_index)
  4046. {
  4047. periousPeriodicPowerConsumption[gun_index] = ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PowerConsumption;
  4048. periousClockPowerConsumption[gun_index] = ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PowerConsumption;
  4049. DEBUG_INFO("Gun-%02d PowerConsumption: %.3f\n", gun_index, ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PowerConsumption);
  4050. }
  4051. }
  4052. break;
  4053. default:
  4054. DEBUG_WARN("Gun-%02d type: Unknown\n", gun_index);
  4055. break;
  4056. }
  4057. }
  4058. }
  4059. }
  4060. else
  4061. {
  4062. DEBUG_ERROR("Model name parsing fail.\n");
  4063. result = FAIL;
  4064. }
  4065. if(result != PASS)sleep(5);
  4066. return result;
  4067. }
  4068. void checkRemoteStart(uint8_t connectorIdInt)
  4069. {
  4070. uint8_t tempIndex;
  4071. int result = PASS;
  4072. char cmdBuf[512];
  4073. //check Transaction active
  4074. if(gunType[connectorIdInt -1] == GUN_TYPE_CHAdeMO)
  4075. {
  4076. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4077. {
  4078. tempIndex = ((connectorIdInt -1) == 2) ? 1: 0;
  4079. }
  4080. else
  4081. {
  4082. tempIndex = connectorIdInt -1;
  4083. }
  4084. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  4085. {
  4086. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  4087. {
  4088. if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ReservationId != -1) &&
  4089. (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ReservationId >= 0) &&
  4090. (strcmp((const char *)ShmOCPP16Data->ReserveNow[index].IdTag, (char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag) == 0))
  4091. {
  4092. //Reserved
  4093. DEBUG_INFO("CHAdeMO connector already reserved and idTag match.\n");
  4094. }
  4095. else if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ReservationId != -1) &&
  4096. (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ReservationId >= 0) &&
  4097. (strcmp((const char *)ShmOCPP16Data->ReserveNow[index].IdTag, (char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag) != 0))
  4098. {
  4099. //Reserved
  4100. DEBUG_INFO("CHAdeMO connector already reserved and idTag does not match.\n");
  4101. result = FAIL;
  4102. goto end;
  4103. }
  4104. else
  4105. {
  4106. if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  4107. && (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_PREPARING ) //S_PRECHARGE
  4108. && (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EV ) //S_PREPARING_FOR_EV
  4109. && (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EVSE )) // S_PREPARING_FOR_EVSE
  4110. {
  4111. DEBUG_WARN("CHAdeMO connector not allow start cause busy.\n");
  4112. result = FAIL;
  4113. goto end;
  4114. }
  4115. }//END FOR ELSE
  4116. }
  4117. }// END FOR CHAdeMO_QUANTITY
  4118. }
  4119. else if(gunType[connectorIdInt -1] == GUN_TYPE_CCS)
  4120. {
  4121. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4122. {
  4123. tempIndex = ((connectorIdInt -1) == 2) ? 1: 0;
  4124. }
  4125. else
  4126. {
  4127. tempIndex = connectorIdInt -1;
  4128. }
  4129. for (int index = 0; index < CCS_QUANTITY; index++)
  4130. {
  4131. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  4132. {
  4133. if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ReservationId != -1) &&
  4134. (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ReservationId >= 0) &&
  4135. (strcmp((const char *)ShmOCPP16Data->ReserveNow[index].IdTag, (char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag) == 0))
  4136. {
  4137. //Reserved
  4138. DEBUG_INFO("CCS connector already reserved and idTag match.\n");
  4139. }
  4140. else if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ReservationId != -1) &&
  4141. (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ReservationId >= 0) &&
  4142. (strcmp((const char *)ShmOCPP16Data->ReserveNow[index].IdTag, (char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag) != 0))
  4143. {
  4144. //Reserved
  4145. DEBUG_INFO("CCS connector already reserved and idTag does not match.\n");
  4146. result = FAIL;
  4147. goto end;
  4148. }
  4149. else
  4150. {
  4151. if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  4152. && (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_PREPARING) //S_PRECHARGE
  4153. && (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EV) //S_PREPARING_FOR_EV
  4154. && (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EVSE)) // S_PREPARING_FOR_EVSE
  4155. {
  4156. DEBUG_WARN("CCS connector not allow start cause busy.\n.");
  4157. result = FAIL;
  4158. goto end;
  4159. }
  4160. }// END FOR ELSE
  4161. }
  4162. }// END FOR CCS_QUANTITY
  4163. }
  4164. else if(gunType[connectorIdInt -1] == GUN_TYPE_GBT)
  4165. {
  4166. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4167. {
  4168. tempIndex = ((connectorIdInt -1) == 2) ? 1: 0;
  4169. }
  4170. else
  4171. {
  4172. tempIndex = connectorIdInt -1;
  4173. }
  4174. for (int index = 0; index < GB_QUANTITY; index++)
  4175. {
  4176. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex )
  4177. {
  4178. if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ReservationId != -1) &&
  4179. (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ReservationId >= 0) &&
  4180. (strcmp((const char *)ShmOCPP16Data->ReserveNow[index].IdTag, (char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag) == 0))
  4181. {
  4182. //Reserved
  4183. DEBUG_INFO("GBT connector already reserved and idTag match.\n");
  4184. }
  4185. else if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ReservationId != -1) &&
  4186. (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ReservationId >= 0) &&
  4187. (strcmp((const char *)ShmOCPP16Data->ReserveNow[index].IdTag, (char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag) != 0))
  4188. {
  4189. //Reserved
  4190. DEBUG_INFO("GBT connector already reserved and idTag does not match.\n");
  4191. result = FAIL;
  4192. goto end;
  4193. }
  4194. else
  4195. {
  4196. if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  4197. && (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_PREPARING) //S_PRECHARGE
  4198. && (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EV) //S_PREPARING_FOR_EV
  4199. && (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EVSE)) // S_PREPARING_FOR_EVSE
  4200. {
  4201. DEBUG_WARN("GBT connector not allow start cause busy.\n");
  4202. result = FAIL;
  4203. goto end;
  4204. }
  4205. }// END FOR ELSE
  4206. }
  4207. } // END FOR GB_QUANTITY
  4208. }
  4209. else if(gunType[connectorIdInt -1] == GUN_TYPE_DO)
  4210. {
  4211. tempIndex = connectorIdInt -1;
  4212. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  4213. {
  4214. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex )
  4215. {
  4216. if((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.ReservationId != -1) &&
  4217. (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.ReservationId >= 0) &&
  4218. (strcmp((const char *)ShmOCPP16Data->ReserveNow[index].IdTag, (char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag) == 0))
  4219. {
  4220. //Reserved
  4221. DEBUG_INFO("Dispenser connector already reserved and idTag match.\n");
  4222. }
  4223. else if((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.ReservationId != -1) &&
  4224. (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.ReservationId >= 0) &&
  4225. (strcmp((const char *)ShmOCPP16Data->ReserveNow[index].IdTag, (char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag) != 0))
  4226. {
  4227. //Reserved
  4228. DEBUG_INFO("Dispenser connector already reserved and idTag does not match.\n");
  4229. result = FAIL;
  4230. goto end;
  4231. }
  4232. else
  4233. {
  4234. if((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus != SYS_MODE_IDLE) //S_IDLE
  4235. && (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus != SYS_MODE_PREPARING) //S_PRECHARGE
  4236. && (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus != SYS_MODE_PREPARE_FOR_EV) //S_PREPARING_FOR_EV
  4237. && (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus != SYS_MODE_PREPARE_FOR_EVSE)) // S_PREPARING_FOR_EVSE
  4238. {
  4239. DEBUG_WARN("Dispenser connector not allow start cause busy.\n");
  4240. result = FAIL;
  4241. goto end;
  4242. }
  4243. }// END FOR ELSE
  4244. }
  4245. } // END FOR GB_QUANTITY
  4246. }
  4247. else
  4248. {
  4249. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D') // 'D' means DC
  4250. {
  4251. tempIndex = 2;
  4252. }
  4253. else
  4254. {
  4255. tempIndex = connectorIdInt -1;
  4256. }
  4257. for (int index = 0; index < AC_QUANTITY; index++)
  4258. {
  4259. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex )
  4260. {
  4261. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].ReservationId != -1) &&
  4262. (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].ReservationId >= 0) &&
  4263. (strcmp((const char *)ShmOCPP16Data->ReserveNow[index].IdTag, (char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag) == 0))
  4264. {
  4265. //Reserved
  4266. DEBUG_INFO("AC connector already reserved and idTag match.\n");
  4267. }
  4268. else if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].ReservationId != -1) &&
  4269. (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].ReservationId >= 0) &&
  4270. (strcmp((const char *)ShmOCPP16Data->ReserveNow[index].IdTag, (char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag) != 0))
  4271. {
  4272. //Reserved
  4273. DEBUG_INFO("AC connector already reserved and idTag does not match.\n");
  4274. result = FAIL;
  4275. goto end;
  4276. }
  4277. else
  4278. {
  4279. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  4280. && (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_PREPARING) //S_PRECHARGE
  4281. && (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EV) //S_PREPARING_FOR_EV
  4282. && (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EVSE)) // S_PREPARING_FOR_EVSE
  4283. {
  4284. DEBUG_WARN("AC connector not allow start cause busy.\n");
  4285. result = FAIL;
  4286. goto end;
  4287. }
  4288. }//END FOR ELSE
  4289. }
  4290. }// END FOR AC_QUANTITY
  4291. }
  4292. if(ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingProfileId > -1)
  4293. {
  4294. if(strcmp((char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingProfilePurpose, ChargingProfilePurposeTypeStr[TxProfile]) == 0)
  4295. {
  4296. if((access("/Storage/OCPP/TxProfile_Tmp.json", F_OK))!=-1)
  4297. {
  4298. sprintf(cmdBuf, "mv /Storage/OCPP/TxProfile_Tmp.json /Storage/OCPP/TxProfile_%d.json", connectorIdInt);
  4299. system(cmdBuf);
  4300. }
  4301. }
  4302. else
  4303. {
  4304. DEBUG_WARN("Profile purpose not TxProfile.\n.");
  4305. result = FAIL;
  4306. }
  4307. }
  4308. end:
  4309. if(result == PASS)
  4310. {
  4311. ShmOCPP16Data->CsMsg.bits[connectorIdInt -1].RemoteStartTransactionReq = 1;
  4312. memset((char *)ShmOCPP16Data->StartTransaction[connectorIdInt -1].IdTag, 0, 20);
  4313. strcpy((char *)ShmOCPP16Data->StartTransaction[connectorIdInt -1].IdTag, (char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag);
  4314. memset((char *)ShmOCPP16Data->StopTransaction[connectorIdInt -1].IdTag, 0, 20);
  4315. strcpy((char *)ShmOCPP16Data->StopTransaction[connectorIdInt -1].IdTag, (char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag);
  4316. }
  4317. }
  4318. void CheckSystemValue(void)
  4319. {
  4320. char filenmae[100]={0};
  4321. char str[100]={0};
  4322. int tempIndex = 0;
  4323. //===============================
  4324. // send Heartbeat
  4325. //===============================
  4326. if((server_sign == TRUE) && (getDiffSecNow(clientTime.Heartbeat) >= (HeartBeatWaitTime + HeartBeatWithNOResponse)))
  4327. {
  4328. //parameter for test
  4329. sendHeartbeatRequest(0);
  4330. //===========================
  4331. // Reset Waiting Time
  4332. //===========================
  4333. HeartBeatWithNOResponse += 1;
  4334. }
  4335. //===============================
  4336. // Credit deduct report
  4337. //===============================
  4338. if(ShmOCPP16Data->TcciCustomData.ReportCreditDeductReq)
  4339. {
  4340. OCPP_insert_deduct_info(ShmOCPP16Data->TcciCustomData.DeductInfo.txId, (char*)ShmOCPP16Data->TcciCustomData.DeductInfo.creditNo,
  4341. ShmOCPP16Data->TcciCustomData.DeductInfo.deductResult, ShmOCPP16Data->TcciCustomData.DeductInfo.isDonateInvoice,
  4342. ShmOCPP16Data->TcciCustomData.DeductInfo.amount, (char*)ShmOCPP16Data->TcciCustomData.DeductInfo.vemData,
  4343. (char*)ShmOCPP16Data->TcciCustomData.DeductInfo.ROC,(char*)ShmOCPP16Data->TcciCustomData.DeductInfo.RRN,
  4344. (char*)ShmOCPP16Data->TcciCustomData.DeductInfo.approvalNo,(char*)ShmOCPP16Data->TcciCustomData.DeductInfo.storeId);
  4345. ShmOCPP16Data->TcciCustomData.ReportCreditDeductReq = FALSE;
  4346. }
  4347. if(getDiffSecNow(clientTime.TcciQueryDeduct) > 5)
  4348. {
  4349. OCPP_query_deduct_info();
  4350. refreshStartTimer(&clientTime.TcciQueryDeduct);
  4351. }
  4352. for(int gun_index=0;gun_index < gunTotalNumber;gun_index++)
  4353. {
  4354. // ClockAlign MeterValue
  4355. if((server_sign == TRUE) && ((atoi((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemData) > 0)?((getTimePassSinceToday(gun_index)%(atoi((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemData)))==0):FALSE))
  4356. {
  4357. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  4358. {
  4359. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4360. {
  4361. tempIndex = ((gun_index==2) ? 1: 0);
  4362. }
  4363. else
  4364. {
  4365. tempIndex = gun_index;
  4366. }
  4367. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  4368. {
  4369. // 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault
  4370. if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  4371. {
  4372. reqClockAlignMeter[gun_index] = 1;
  4373. }
  4374. }// End for CHAdeMO
  4375. }
  4376. else if(gunType[gun_index] == GUN_TYPE_CCS)
  4377. {
  4378. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4379. {
  4380. tempIndex = ((gun_index==2) ? 1: 0);
  4381. }
  4382. else
  4383. {
  4384. tempIndex = gun_index;
  4385. }
  4386. for (int index = 0; index < CCS_QUANTITY; index++)
  4387. {
  4388. // 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault
  4389. if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  4390. {
  4391. reqClockAlignMeter[gun_index] = 1;
  4392. }
  4393. } // End for CCS
  4394. }
  4395. else if(gunType[gun_index] == GUN_TYPE_GBT)
  4396. {
  4397. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4398. {
  4399. tempIndex = ((gun_index==2) ? 1: 0);
  4400. }
  4401. else
  4402. {
  4403. tempIndex = gun_index;
  4404. }
  4405. for (int index = 0; index < GB_QUANTITY; index++)
  4406. {
  4407. // 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault
  4408. if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  4409. {
  4410. reqClockAlignMeter[gun_index] = 1;
  4411. }
  4412. }// End for GB
  4413. }
  4414. else if(gunType[gun_index] == GUN_TYPE_DO)
  4415. {
  4416. tempIndex = gun_index;
  4417. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  4418. {
  4419. // 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault
  4420. if(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  4421. {
  4422. reqClockAlignMeter[gun_index] = 1;
  4423. }
  4424. }
  4425. }
  4426. else
  4427. {
  4428. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  4429. {
  4430. tempIndex = 2;
  4431. }
  4432. else
  4433. {
  4434. tempIndex = gun_index;
  4435. }
  4436. for (int index = 0; index < AC_QUANTITY; index++)
  4437. {
  4438. // 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault
  4439. if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  4440. {
  4441. reqClockAlignMeter[gun_index] = 1;
  4442. }
  4443. }//End for AC
  4444. }
  4445. }
  4446. }
  4447. for(int gun_index=0;gun_index < gunTotalNumber ;gun_index++)
  4448. {
  4449. //==========================================
  4450. // Check remote start without connector id
  4451. //==========================================
  4452. if(ShmOCPP16Data->MsMsg.bits.isRemoteStartWaitReq)
  4453. {
  4454. int connectorIdInt = -1;
  4455. for(uint8_t gun_index=0;gun_index<gunTotalNumber;gun_index++)
  4456. {
  4457. if(!cpinitateMsg.bits[gun_index].isOnCharging && (strstr((char*)ShmOCPP16Data->StatusNotification[gun_index].Status, "Preparing") != NULL))
  4458. {
  4459. connectorIdInt = (gun_index+1);
  4460. DEBUG_INFO("Detect connector-%02d connected ready to start.\n", connectorIdInt);
  4461. checkRemoteStart(connectorIdInt);
  4462. ShmOCPP16Data->MsMsg.bits.isRemoteStartWaitReq = 0;
  4463. break;
  4464. }
  4465. }
  4466. if(getDiffSecNow(clientTime.RemoteStartWait) > atoi((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemData))
  4467. {
  4468. DEBUG_WARN("Remote start request without connector id wait link over %s seconds.\n", ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemData);
  4469. ShmOCPP16Data->MsMsg.bits.isRemoteStartWaitReq = 0;
  4470. }
  4471. }
  4472. //==========================================
  4473. // csu trigger DataTransferReq
  4474. //==========================================
  4475. if(isWebsocketSendable && (server_sign == TRUE) && (ShmOCPP16Data->CsMsg.bits[gun_index].DataTransferReq == 1))
  4476. {
  4477. sendDataTransferRequest(gun_index);
  4478. ShmOCPP16Data->CsMsg.bits[gun_index].DataTransferReq = 0;
  4479. }
  4480. //==========================================
  4481. // CSU Trigger Authorize Request
  4482. //==========================================
  4483. if(isWebsocketSendable && (server_sign == TRUE) && (ShmOCPP16Data->SpMsg.bits.AuthorizeReq == 1)&&(authorizeRetryTimes < 3))
  4484. {
  4485. sendAuthorizeRequest(0);
  4486. authorizeRetryTimes = authorizeRetryTimes + 1;
  4487. if(authorizeRetryTimes < 3)
  4488. ShmOCPP16Data->SpMsg.bits.AuthorizeReq = 0;
  4489. }
  4490. else if((server_sign == TRUE) && (ShmOCPP16Data->SpMsg.bits.AuthorizeReq == 1) && (authorizeRetryTimes >= 3))
  4491. {
  4492. authorizeRetryTimes = 0;
  4493. SetOcppConnStatus(FALSE);
  4494. server_sign = FALSE;
  4495. }
  4496. 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))
  4497. {
  4498. sendAuthorizeRequest(0);
  4499. }
  4500. //==========================================
  4501. // Charger start transaction
  4502. //==========================================
  4503. if(/*(server_sign == TRUE) &&*/ (ShmOCPP16Data->CpMsg.bits[gun_index].StartTransactionReq == 1))
  4504. {
  4505. ShmOCPP16Data->CpMsg.bits[gun_index].StartTransactionReq = 0;
  4506. sendStartTransactionRequest(gun_index);
  4507. refreshStartTimer(&clientTime.StartTransaction);
  4508. refreshStartTimer(&clientTime.MeterValues[gun_index]);
  4509. storeTempStopTransaction(gun_index);
  4510. }
  4511. //==========================================
  4512. // Charger stop transaction
  4513. //==========================================
  4514. if(/*(server_sign == TRUE) &&*/ ((ShmOCPP16Data->CpMsg.bits[gun_index].StopTransactionReq == 1)))
  4515. {
  4516. ShmOCPP16Data->CpMsg.bits[gun_index].StopTransactionReq = 0;
  4517. sendStopTransactionRequest(gun_index);
  4518. OCPP_updatePeriodEnergy(gun_index);
  4519. if(ShmSysConfigAndInfo->SysConfig.TTIA_Info.isEnableTTIA && (gunType[gun_index] != GUN_TYPE_AC) )sendTTIAInfo(gun_index);
  4520. refreshStartTimer(&clientTime.StopTransaction);
  4521. memset(&ShmOCPP16Data->SessionTarget[gun_index], 0x00, sizeof(struct StructSessionTarget));
  4522. }
  4523. //==========================================
  4524. // Charger status report
  4525. //==========================================
  4526. //--- Check Mode Change ---//
  4527. // J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DCcc
  4528. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  4529. {
  4530. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4531. {
  4532. tempIndex = ((gun_index==2) ? 1: 0);
  4533. }
  4534. else
  4535. {
  4536. tempIndex = gun_index;
  4537. }
  4538. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  4539. {
  4540. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  4541. {
  4542. if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != ChademoPreviousSystemStatus[index]) || (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ConnectorPlugIn != ChademoPreviousConnectorPlugIn[index]) )
  4543. {
  4544. // Sent unplug message for California pricing logic
  4545. if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_COMPLETE) && (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ConnectorPlugIn == 0) && !interLock.isSentUnplug[gun_index])
  4546. {
  4547. uint8_t ts[36];
  4548. getNowDatetime(ts);
  4549. sprintf((char*)ShmOCPP16Data->DataTransfer[gun_index].VendorId, "org.openchargealliance.costmsg");
  4550. sprintf((char*)ShmOCPP16Data->DataTransfer[gun_index].MessageId, "ConnectorUnplugged");
  4551. if(strcmp((char*)dmsVersion, "2.0")==0)
  4552. sprintf((char*)ShmOCPP16Data->DataTransfer[gun_index].Data, "{\\\"transactionId\\\":%d,\\\"timestamp\\\":\\\"%s\\\"}", ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId, ts);
  4553. else
  4554. sprintf((char*)ShmOCPP16Data->DataTransfer[gun_index].Data, "{\\\"idTx\\\":%d,\\\"timestamp\\\":\\\"%s\\\"}", ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId, ts);
  4555. sendUnplugByDataTransferRequest(gun_index);
  4556. interLock.isSentUnplug[gun_index] = 1;
  4557. }
  4558. else if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_IDLE))
  4559. {
  4560. interLock.isSentUnplug[gun_index] = 0;
  4561. }
  4562. ChademoPreviousSystemStatus[index] = ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus;
  4563. ChademoPreviousConnectorPlugIn[index] = ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ConnectorPlugIn;
  4564. cpinitateMsg.bits[gun_index].StatusNotificationReq = 1;
  4565. if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex) && ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_COMPLETE) || (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus <= SYS_MODE_IDLE))) // complete
  4566. {
  4567. sprintf(filenmae,"/Storage/OCPP/TxProfile_%d.json",(gun_index+1));
  4568. if((access(filenmae,F_OK))!=-1)
  4569. {
  4570. DEBUG_INFO("TxProfile exist. OCPP will delete TX Charging Profile\n");
  4571. sprintf(str,"rm -f %s",filenmae);
  4572. system(str);
  4573. }
  4574. }
  4575. }
  4576. cpinitateMsg.bits[gun_index].isOnCharging = ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_TERMINATING)?1:0);
  4577. #if 1 // for TempStopTransaction
  4578. if(((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_BOOTING) || (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_IDLE)) &&
  4579. (ShmOCPP16Data->CpMsg.bits[gun_index].StopTransactionReq == 0))
  4580. {
  4581. checkTempStopTransaction(gun_index);
  4582. }
  4583. #endif
  4584. }
  4585. }
  4586. }
  4587. else if(gunType[gun_index] == GUN_TYPE_CCS)
  4588. {
  4589. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4590. {
  4591. tempIndex = ((gun_index==2) ? 1: 0);
  4592. }
  4593. else
  4594. {
  4595. tempIndex = gun_index;
  4596. }
  4597. for (int index = 0; index < CCS_QUANTITY; index++)
  4598. {
  4599. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  4600. {
  4601. 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]*/ )
  4602. {
  4603. // Sent unplug message for California pricing logic
  4604. if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_COMPLETE) && (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ConnectorPlugIn == 0) && !interLock.isSentUnplug[gun_index])
  4605. {
  4606. uint8_t ts[36];
  4607. getNowDatetime(ts);
  4608. sprintf((char*)ShmOCPP16Data->DataTransfer[gun_index].VendorId, "org.openchargealliance.costmsg");
  4609. sprintf((char*)ShmOCPP16Data->DataTransfer[gun_index].MessageId, "ConnectorUnplugged");
  4610. if(strcmp((char*)dmsVersion, "2.0")==0)
  4611. sprintf((char*)ShmOCPP16Data->DataTransfer[gun_index].Data, "{\\\"transactionId\\\":%d,\\\"timestamp\\\":\\\"%s\\\"}", ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId, ts);
  4612. else
  4613. sprintf((char*)ShmOCPP16Data->DataTransfer[gun_index].Data, "{\\\"idTx\\\":%d,\\\"timestamp\\\":\\\"%s\\\"}", ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId, ts);
  4614. sendUnplugByDataTransferRequest(gun_index);
  4615. interLock.isSentUnplug[gun_index] = 1;
  4616. }
  4617. else if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_IDLE))
  4618. {
  4619. interLock.isSentUnplug[gun_index] = 0;
  4620. }
  4621. CcsPreviousSystemStatus[index] = ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus;
  4622. CcsPreviousConnectorPlugIn[index] = ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ConnectorPlugIn;
  4623. cpinitateMsg.bits[gun_index].StatusNotificationReq = 1;
  4624. if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex) && ((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_COMPLETE) || (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus <= SYS_MODE_IDLE))) // complete
  4625. {
  4626. sprintf(filenmae,"/Storage/OCPP/TxProfile_%d.json",(gun_index+1));
  4627. if((access(filenmae,F_OK))!=-1)
  4628. {
  4629. DEBUG_INFO("TxProfile exist. OCPP will delete TX Charging Profile\n");
  4630. sprintf(str,"rm -f %s",filenmae);
  4631. system(str);
  4632. }
  4633. }
  4634. }
  4635. cpinitateMsg.bits[gun_index].isOnCharging = ((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_TERMINATING)?1:0);
  4636. #if 1 // for TempStopTransaction
  4637. if(((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_BOOTING) || (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_IDLE)) &&
  4638. (ShmOCPP16Data->CpMsg.bits[gun_index].StopTransactionReq == 0))
  4639. {
  4640. checkTempStopTransaction(gun_index);
  4641. }
  4642. #endif
  4643. }
  4644. }
  4645. }
  4646. else if(gunType[gun_index] == GUN_TYPE_GBT)
  4647. {
  4648. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4649. {
  4650. tempIndex = ((gun_index==2) ? 1: 0);
  4651. }
  4652. else
  4653. {
  4654. tempIndex = gun_index;
  4655. }
  4656. for (int index = 0; index < GB_QUANTITY; index++)
  4657. {
  4658. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  4659. {
  4660. if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != GbPreviousSystemStatus[index]) || (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ConnectorPlugIn != GbPreviousConnectorPlugIn[index]) )
  4661. {
  4662. // Sent unplug message for California pricing logic
  4663. if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_COMPLETE) && (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ConnectorPlugIn == 0) && !interLock.isSentUnplug[gun_index])
  4664. {
  4665. uint8_t ts[36];
  4666. getNowDatetime(ts);
  4667. sprintf((char*)ShmOCPP16Data->DataTransfer[gun_index].VendorId, "org.openchargealliance.costmsg");
  4668. sprintf((char*)ShmOCPP16Data->DataTransfer[gun_index].MessageId, "ConnectorUnplugged");
  4669. if(strcmp((char*)dmsVersion, "2.0")==0)
  4670. sprintf((char*)ShmOCPP16Data->DataTransfer[gun_index].Data, "{\\\"transactionId\\\":%d,\\\"timestamp\\\":\\\"%s\\\"}", ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId, ts);
  4671. else
  4672. sprintf((char*)ShmOCPP16Data->DataTransfer[gun_index].Data, "{\\\"idTx\\\":%d,\\\"timestamp\\\":\\\"%s\\\"}", ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId, ts);
  4673. sendUnplugByDataTransferRequest(gun_index);
  4674. interLock.isSentUnplug[gun_index] = 1;
  4675. }
  4676. else if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_IDLE))
  4677. {
  4678. interLock.isSentUnplug[gun_index] = 0;
  4679. }
  4680. GbPreviousSystemStatus[index] = ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus;
  4681. GbPreviousConnectorPlugIn[index] = ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ConnectorPlugIn;
  4682. cpinitateMsg.bits[gun_index].StatusNotificationReq = 1;
  4683. if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex) && ((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_COMPLETE) || (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus <= SYS_MODE_IDLE))) // complete
  4684. {
  4685. sprintf(filenmae,"/Storage/OCPP/TxProfile_%d.json",(gun_index+1));
  4686. if((access(filenmae,F_OK))!=-1)
  4687. {
  4688. DEBUG_INFO("TxProfile exist. OCPP will delete TX Charging Profile\n");
  4689. sprintf(str,"rm -f %s",filenmae);
  4690. system(str);
  4691. }
  4692. }
  4693. }
  4694. cpinitateMsg.bits[gun_index].isOnCharging = ((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_TERMINATING)?1:0);
  4695. #if 1 // for TempStopTransaction
  4696. if(((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_BOOTING) || (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_IDLE)) &&
  4697. (ShmOCPP16Data->CpMsg.bits[gun_index].StopTransactionReq == 0))
  4698. {
  4699. checkTempStopTransaction(gun_index);
  4700. }
  4701. #endif
  4702. }
  4703. }
  4704. }
  4705. else if(gunType[gun_index] == GUN_TYPE_DO)
  4706. {
  4707. tempIndex = gun_index;
  4708. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  4709. {
  4710. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  4711. {
  4712. if((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus != DoPreviousSystemStatus[index]) || (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.ConnectorPlugIn != DoPreviousConnectorPlugIn[index]) )
  4713. {
  4714. // Sent unplug message for California pricing logic
  4715. if((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_COMPLETE) && (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.ConnectorPlugIn == 0) && !interLock.isSentUnplug[gun_index])
  4716. {
  4717. uint8_t ts[36];
  4718. getNowDatetime(ts);
  4719. sprintf((char*)ShmOCPP16Data->DataTransfer[gun_index].VendorId, "org.openchargealliance.costmsg");
  4720. sprintf((char*)ShmOCPP16Data->DataTransfer[gun_index].MessageId, "ConnectorUnplugged");
  4721. if(strcmp((char*)dmsVersion, "2.0")==0)
  4722. sprintf((char*)ShmOCPP16Data->DataTransfer[gun_index].Data, "{\\\"transactionId\\\":%d,\\\"timestamp\\\":\\\"%s\\\"}", ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId, ts);
  4723. else
  4724. sprintf((char*)ShmOCPP16Data->DataTransfer[gun_index].Data, "{\\\"idTx\\\":%d,\\\"timestamp\\\":\\\"%s\\\"}", ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId, ts);
  4725. sendUnplugByDataTransferRequest(gun_index);
  4726. interLock.isSentUnplug[gun_index] = 1;
  4727. }
  4728. else if((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_IDLE))
  4729. {
  4730. interLock.isSentUnplug[gun_index] = 0;
  4731. }
  4732. DoPreviousSystemStatus[index] = ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus;
  4733. DoPreviousConnectorPlugIn[index] = ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.ConnectorPlugIn;
  4734. cpinitateMsg.bits[gun_index].StatusNotificationReq = 1;
  4735. 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
  4736. {
  4737. sprintf(filenmae,"/Storage/OCPP/TxProfile_%d.json",(gun_index+1));
  4738. if((access(filenmae,F_OK))!=-1)
  4739. {
  4740. DEBUG_INFO("TxProfile exist. OCPP will delete TX Charging Profile\n");
  4741. sprintf(str,"rm -f %s",filenmae);
  4742. system(str);
  4743. }
  4744. }
  4745. }
  4746. 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);
  4747. #if 1 // for TempStopTransaction
  4748. if(((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_BOOTING) || (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_IDLE)) &&
  4749. (ShmOCPP16Data->CpMsg.bits[gun_index].StopTransactionReq == 0))
  4750. {
  4751. checkTempStopTransaction(gun_index);
  4752. }
  4753. #endif
  4754. }
  4755. }
  4756. }
  4757. else
  4758. {
  4759. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  4760. {
  4761. tempIndex = 2;
  4762. }
  4763. else
  4764. {
  4765. tempIndex = gun_index;
  4766. }
  4767. for (int index = 0; index < AC_QUANTITY; index++)
  4768. {
  4769. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  4770. {
  4771. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != AcPreviousSystemStatus[index]) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PilotState != AcPreviousConnectorPlugIn[index]) )
  4772. {
  4773. // Sent unplug message for California pricing logic
  4774. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_COMPLETE) && (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PilotState == CP_STATE_A) && !interLock.isSentUnplug[gun_index])
  4775. {
  4776. uint8_t ts[36];
  4777. getNowDatetime(ts);
  4778. sprintf((char*)ShmOCPP16Data->DataTransfer[gun_index].VendorId, "org.openchargealliance.costmsg");
  4779. sprintf((char*)ShmOCPP16Data->DataTransfer[gun_index].MessageId, "ConnectorUnplugged");
  4780. if(strcmp((char*)dmsVersion, "2.0")==0)
  4781. sprintf((char*)ShmOCPP16Data->DataTransfer[gun_index].Data, "{\\\"transactionId\\\":%d,\\\"timestamp\\\":\\\"%s\\\"}", ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId, ts);
  4782. else
  4783. sprintf((char*)ShmOCPP16Data->DataTransfer[gun_index].Data, "{\\\"idTx\\\":%d,\\\"timestamp\\\":\\\"%s\\\"}", ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId, ts);
  4784. sendUnplugByDataTransferRequest(gun_index);
  4785. interLock.isSentUnplug[gun_index] = 1;
  4786. }
  4787. else if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_IDLE))
  4788. {
  4789. interLock.isSentUnplug[gun_index] = 0;
  4790. }
  4791. AcPreviousSystemStatus[index] = ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus;
  4792. AcPreviousConnectorPlugIn[index] = ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PilotState;
  4793. cpinitateMsg.bits[gun_index].StatusNotificationReq = 1;
  4794. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex) && ((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_COMPLETE) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus <= SYS_MODE_IDLE))) // complete
  4795. {
  4796. sprintf(filenmae,"/Storage/OCPP/TxProfile_%d.json",(gun_index+1));
  4797. if((access(filenmae,F_OK))!=-1)
  4798. {
  4799. DEBUG_INFO("TxProfile exist. OCPP will delete TX Charging Profile\n");
  4800. sprintf(str,"rm -f %s",filenmae);
  4801. system(str);
  4802. }
  4803. }
  4804. }
  4805. cpinitateMsg.bits[gun_index].isOnCharging = ((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_TERMINATING)?1:0);
  4806. #if 1 // for TempStopTransaction
  4807. if(((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_BOOTING) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_IDLE)) &&
  4808. (ShmOCPP16Data->CpMsg.bits[gun_index].StopTransactionReq == 0))
  4809. {
  4810. checkTempStopTransaction(gun_index);
  4811. }
  4812. #endif
  4813. }
  4814. }// END
  4815. }
  4816. if(isWebsocketSendable && (server_sign == TRUE) && (getDiffSecNow(clientTime.StatusNotification[gun_index]) >= 1) &&
  4817. (
  4818. (cpinitateMsg.bits[gun_index].StatusNotificationReq == 1) || (cpinitateMsg.bits[gun_index].TriggerStatusNotificationReq == 1) ||
  4819. ((strcmp((const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StatusNotificationPeriodically].ItemData, "TRUE") == 0) && (getDiffSecNow(clientTime.StatusNotification[gun_index]) >= atoi((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[StatusNotificationInterval].ItemData)))
  4820. )
  4821. )
  4822. {
  4823. sendStatusNotificationRequest(gun_index);
  4824. refreshStartTimer(&clientTime.StatusNotification[gun_index]);
  4825. }
  4826. //==============================================
  4827. // TCCI reader status report
  4828. //==============================================
  4829. if(isWebsocketSendable && (server_sign == TRUE) && (ShmOCPP16Data->TcciCustomData.ReaderStatus[gun_index].ReportReaderStatusReq == 1))
  4830. {
  4831. reportReaderStatus(gun_index);
  4832. //ShmOCPP16Data->TcciCustomData.ReaderStatus[gun_index].ReportReaderStatusReq = 0;
  4833. }
  4834. //==============================================
  4835. // CSU Trigger Smart Charging Profile
  4836. //==============================================
  4837. if(ShmOCPP16Data->CSUMsg.bits[gun_index].ChargingProfileReq == 1)
  4838. {
  4839. checkCompositeSchedule(gun_index+1, 86400, &ShmOCPP16Data->SmartChargingProfile[gun_index], TRUE);
  4840. ShmOCPP16Data->CSUMsg.bits[gun_index].ChargingProfileReq = 0;
  4841. }
  4842. //==============================================
  4843. // Meter report
  4844. //==============================================
  4845. // Trigger MeterValue
  4846. if(isWebsocketSendable && (server_sign == TRUE) && cpinitateMsg.bits[gun_index].TriggerMeterValue)
  4847. {
  4848. sendMeterValuesRequest(gun_index, ReadingContext_Trigger);
  4849. cpinitateMsg.bits[gun_index].TriggerMeterValue = 0;
  4850. }
  4851. // Clock-aligned Meter value
  4852. if(isWebsocketSendable && (reqClockAlignMeter[gun_index] == 1))
  4853. {
  4854. sendMeterValuesRequest(gun_index, ReadingContext_Sample_Clock);
  4855. reqClockAlignMeter[gun_index] = 0;
  4856. }
  4857. // Sample period MeterValue
  4858. 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))))
  4859. {
  4860. //check Transaction active
  4861. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  4862. {
  4863. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4864. {
  4865. tempIndex = ((gun_index==2) ? 1: 0);
  4866. }
  4867. else
  4868. {
  4869. tempIndex = gun_index;
  4870. }
  4871. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  4872. {
  4873. // 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault
  4874. if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  4875. {
  4876. if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_CHARGING)
  4877. {
  4878. reqSampleMeter[gun_index] = 1;
  4879. }
  4880. }
  4881. }// End for CHAdeMO
  4882. }
  4883. else if(gunType[gun_index] == GUN_TYPE_CCS)
  4884. {
  4885. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4886. {
  4887. tempIndex = ((gun_index==2) ? 1: 0);
  4888. }
  4889. else
  4890. {
  4891. tempIndex = gun_index;
  4892. }
  4893. for (int index = 0; index < CCS_QUANTITY; index++)
  4894. {
  4895. // 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault
  4896. if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  4897. {
  4898. if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_CHARGING)
  4899. {
  4900. reqSampleMeter[gun_index] = 1;
  4901. }
  4902. }
  4903. } // End for CCS
  4904. }
  4905. else if(gunType[gun_index] == GUN_TYPE_GBT)
  4906. {
  4907. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4908. {
  4909. tempIndex = ((gun_index==2) ? 1: 0);
  4910. }
  4911. else
  4912. {
  4913. tempIndex = gun_index;
  4914. }
  4915. for (int index = 0; index < GB_QUANTITY; index++)
  4916. {
  4917. // 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault
  4918. if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  4919. {
  4920. if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_CHARGING)
  4921. {
  4922. reqSampleMeter[gun_index] = 1;
  4923. }
  4924. }
  4925. }// End for GB
  4926. }
  4927. else if(gunType[gun_index] == GUN_TYPE_DO)
  4928. {
  4929. tempIndex = gun_index;
  4930. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  4931. {
  4932. // 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault
  4933. if(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  4934. {
  4935. if(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_CHARGING)
  4936. {
  4937. reqSampleMeter[gun_index] = 1;
  4938. }
  4939. }
  4940. }
  4941. }
  4942. else
  4943. {
  4944. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  4945. {
  4946. tempIndex = 2;
  4947. }
  4948. else
  4949. {
  4950. tempIndex = gun_index;
  4951. }
  4952. for (int index = 0; index < AC_QUANTITY; index++)
  4953. {
  4954. // 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault
  4955. if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  4956. {
  4957. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_TERMINATING))
  4958. {
  4959. reqSampleMeter[gun_index] = 1;
  4960. }
  4961. }
  4962. }//End for AC
  4963. }
  4964. if(reqSampleMeter[gun_index] == 1)
  4965. {
  4966. if(atoi((const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemData)>0)
  4967. sendMeterValuesRequest(gun_index, ReadingContext_Sample_Periodic);
  4968. storeTempStopTransaction(gun_index);
  4969. reqSampleMeter[gun_index] = 0;
  4970. }
  4971. refreshStartTimer(&clientTime.MeterValues[gun_index]);
  4972. }
  4973. //==============================================
  4974. // Check Connector reserved
  4975. //==============================================
  4976. //===============================
  4977. // Check if Reserve is expired
  4978. //===============================
  4979. if((server_sign == TRUE) && (ShmOCPP16Data->ReserveNow[gun_index].ExpiryDate[0] != 0))
  4980. {
  4981. if(isOvertNow(ShmOCPP16Data->ReserveNow[gun_index].ExpiryDate))
  4982. {
  4983. DEBUG_INFO("reserve expired.\n");
  4984. memset(ShmOCPP16Data->ReserveNow[gun_index].ExpiryDate,0,ARRAY_SIZE(ShmOCPP16Data->ReserveNow[gun_index].ExpiryDate));
  4985. }
  4986. }//END OF Check if Reserve is expired
  4987. //==========================================
  4988. // csu trigger FirmwareStatusNotificationReq
  4989. //==========================================
  4990. if(isWebsocketSendable && (server_sign == TRUE) && (ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationReq == 1))
  4991. {
  4992. sendFirmwareStatusNotificationRequest((char *)ShmOCPP16Data->FirmwareStatusNotification.Status);
  4993. }
  4994. //==========================================
  4995. // csu trigger DiagnosticsStatusNotificationReq
  4996. //==========================================
  4997. if(isWebsocketSendable && (server_sign == TRUE) && (ShmOCPP16Data->SpMsg.bits.DiagnosticsStatusNotificationReq == 1))
  4998. {
  4999. sendDiagnosticsStatusNotificationRequest((char *)ShmOCPP16Data->DiagnosticsStatusNotification.Status);
  5000. }
  5001. //==========================================
  5002. // csu trigger CancelReservationConf
  5003. //==========================================
  5004. if(isWebsocketSendable && (server_sign == TRUE) && (ShmOCPP16Data->CsMsg.bits[gun_index].CancelReservationConf == 1))
  5005. {
  5006. sendCancelReservationConfirmation((char *)ShmOCPP16Data->CancelReservation[gun_index].guid,(char *)ShmOCPP16Data->CancelReservation[gun_index].ResponseStatus);
  5007. ShmOCPP16Data->CsMsg.bits[gun_index].CancelReservationConf = 0;
  5008. }
  5009. //==========================================
  5010. // csu trigger ChangeAvailabilityConf
  5011. //==========================================
  5012. if(isWebsocketSendable && (server_sign == TRUE) && (ShmOCPP16Data->CsMsg.bits[gun_index].ChangeAvailabilityConf == 1))
  5013. {
  5014. //sendChangeAvailabilityConfirmation(,(char *)ShmOCPP16Data->ChangeAvailability[gun_index].ResponseStatus);
  5015. }
  5016. //==========================================
  5017. // csu trigger UnlockConnectorConf
  5018. //==========================================
  5019. if(isWebsocketSendable && (server_sign == TRUE) && (ShmOCPP16Data->CsMsg.bits[gun_index].UnlockConnectorConf == 1))
  5020. {
  5021. sendUnlockConnectorConfirmation((char *)ShmOCPP16Data->UnlockConnector[gun_index].guid, (char *)ShmOCPP16Data->UnlockConnector[gun_index].ResponseStatus);
  5022. ShmOCPP16Data->CsMsg.bits[gun_index].UnlockConnectorConf = 0;
  5023. }
  5024. //==========================================
  5025. // csu trigger ReserveNowConf
  5026. //==========================================
  5027. if(isWebsocketSendable && (server_sign == TRUE) && (ShmOCPP16Data->CsMsg.bits[gun_index].ReserveNowConf == 1))
  5028. {
  5029. sendReserveNowTransactionConfirmation((char *)ShmOCPP16Data->ReserveNow[gun_index].guid, (char *)ShmOCPP16Data->ReserveNow[gun_index].ResponseStatus);
  5030. ShmOCPP16Data->CsMsg.bits[gun_index].ReserveNowConf = 0;
  5031. }
  5032. if(isWebsocketSendable && (server_sign == TRUE) && (ShmOCPP16Data->SpMsg.bits.SignCertificateReq == 1) && (access("/Storage/OCPP/certCP.csr",F_OK) != -1))
  5033. {
  5034. sendSignCertificateRequest();
  5035. }
  5036. }
  5037. }
  5038. //==========================================
  5039. // send request routine
  5040. //==========================================
  5041. int sendAuthorizeRequest(int gun_index)
  5042. {
  5043. mtrace();
  5044. int result = FAIL;
  5045. char message[100]={0};
  5046. char guid[37];
  5047. char tempdata[65]={0};
  5048. DEBUG_INFO("sendAuthorizeRequest...\n");
  5049. memset(&(ShmOCPP16Data->Authorize.ResponseIdTagInfo),0,sizeof(struct StructIdTagInfo));
  5050. //Local Authorize
  5051. if((strcmp((const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemData , "TRUE")==0) &&(ShmOCPP16Data->OcppConnStatus == 0))
  5052. {
  5053. DEBUG_INFO("Allow OfflineTx UnknownId Pass.\n");
  5054. strcpy((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.ExpiryDate, "");
  5055. strcpy((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.ParentIdTag, "");
  5056. strcpy((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.Status, "Accepted");
  5057. result = PASS;
  5058. ShmOCPP16Data->SpMsg.bits.AuthorizeReq = 0;
  5059. ShmOCPP16Data->SpMsg.bits.AuthorizeConf = 1; // inform csu
  5060. authorizeRetryTimes = 0;
  5061. return result;
  5062. }
  5063. 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))||
  5064. ((strcmp((const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemData, "TRUE") == 0)&&(strcmp((const char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "TRUE") == 0)))
  5065. {
  5066. // Query from cache
  5067. DEBUG_INFO("Authorize from cache.\n");
  5068. OCPP_getIdTagFromLocalCache((char *)ShmSysConfigAndInfo->SysConfig.UserId);
  5069. // Query from list
  5070. if((strcmp(idTagQuery.idTagstr,"") == 0) || (strcmp(idTagQuery.idTagstatus,"Accepted") != 0) )
  5071. {
  5072. DEBUG_INFO("Authorize from list.\n");
  5073. OCPP_getIdTagFromLocalList((char *)ShmSysConfigAndInfo->SysConfig.UserId);
  5074. }
  5075. if((strcmp(idTagQuery.idTagstr,"") == 0) || (strcmp(idTagQuery.idTagstatus,"Accepted") != 0) )
  5076. {
  5077. if(strcmp(idTagQuery.idTagstr,"") == 0)
  5078. {
  5079. DEBUG_INFO("Local Authorization Fail, Card %s is not in local cache and list.\n", ShmSysConfigAndInfo->SysConfig.UserId);
  5080. }
  5081. else if(strcmp(idTagQuery.idTagstatus,"Accepted") != 0)
  5082. {
  5083. DEBUG_INFO("Local Authorization Fail, Card %s is not Accepted.\n", idTagQuery.idTagstr);
  5084. }
  5085. if(!GetOcppConnStatus())
  5086. {
  5087. DEBUG_INFO("off-line Local Authorization Fail.\n");
  5088. strcpy((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.ExpiryDate, idTagQuery.expiryDate);
  5089. strcpy((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.ParentIdTag, idTagQuery.parentIdTag);
  5090. strcpy((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.Status, "Invalid");
  5091. DEBUG_INFO("ShmOCPP16Data->Authorize.ResponseIdTagInfo.Status: %s \n", ShmOCPP16Data->Authorize.ResponseIdTagInfo.Status);
  5092. ShmOCPP16Data->SpMsg.bits.AuthorizeReq = 0;
  5093. ShmOCPP16Data->SpMsg.bits.AuthorizeConf = 1; // inform csu
  5094. authorizeRetryTimes = 0;
  5095. return result;
  5096. }
  5097. }
  5098. else
  5099. {
  5100. DEBUG_INFO("off-line Local Authorization get result !!!!\n");
  5101. strcpy((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.ExpiryDate, idTagQuery.expiryDate);
  5102. strcpy((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.ParentIdTag, idTagQuery.parentIdTag);
  5103. if(isOvertNow((uint8_t*)&idTagQuery.expiryDate[0]))
  5104. sprintf((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.Status, "Expired");
  5105. else
  5106. strcpy((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.Status, idTagQuery.idTagstatus);
  5107. DEBUG_INFO("ShmOCPP16Data->Authorize.ResponseIdTagInfo.Status: %s \n", ShmOCPP16Data->Authorize.ResponseIdTagInfo.Status);
  5108. result = PASS;
  5109. ShmOCPP16Data->SpMsg.bits.AuthorizeReq = 0;
  5110. ShmOCPP16Data->SpMsg.bits.AuthorizeConf = 1; // inform csu
  5111. authorizeRetryTimes = 0;
  5112. return result;
  5113. }
  5114. }
  5115. //initialize struct Authorize
  5116. memset(&(ShmOCPP16Data->Authorize), 0 , sizeof(struct StructAuthorize));
  5117. //get data from shared memory
  5118. strcpy((char *)ShmOCPP16Data->Authorize.IdTag, (const char *)ShmSysConfigAndInfo->SysConfig.UserId);
  5119. random_uuid(guid);
  5120. sprintf(message,"[%d,\"%s\",\"Authorize\",{\"idTag\":\"%s\"}]",MESSAGE_TYPE_CALL, guid, ShmOCPP16Data->Authorize.IdTag);
  5121. LWS_Send(message);
  5122. sprintf(tempdata, "Authorize,%d", gun_index);
  5123. if(hashmap_operation(HASH_OP_ADD, guid, tempdata) == 1)
  5124. {
  5125. result = PASS;
  5126. DEBUG_INFO("Authorize mapItem pass\n");
  5127. }
  5128. ShmOCPP16Data->SpMsg.bits.AuthorizeReq = 0;
  5129. return result;
  5130. }
  5131. int sendBootNotificationRequest(void)
  5132. {
  5133. mtrace();
  5134. int result = FAIL;
  5135. char message[500]={0}, payload[700]={0};
  5136. char guid[37]={0};
  5137. char tempdata[65]={0};
  5138. // Fill BootNotification fields
  5139. strcpy((char *)ShmOCPP16Data->BootNotification.CbSN,(const char *)ShmOCPP16Data->ChargeBoxId);
  5140. strcpy((char *)ShmOCPP16Data->BootNotification.CpModel,(const char *)ShmSysConfigAndInfo->SysConfig.ModelName);
  5141. strcpy((char *)ShmOCPP16Data->BootNotification.CpSN,(const char *)ShmSysConfigAndInfo->SysConfig.SerialNumber);
  5142. strcpy((char *)ShmOCPP16Data->BootNotification.CpVendor,(const char *)ShmSysConfigAndInfo->SysConfig.chargePointVendor);
  5143. strcpy((char *)ShmOCPP16Data->BootNotification.CpFwVersion,(const char *)ShmSysConfigAndInfo->SysInfo.CsuRootFsFwRev);
  5144. strcpy((char *)ShmOCPP16Data->BootNotification.CpIccid,(const char *)ShmSysConfigAndInfo->SysConfig.TelecomInterface.TelcomSimIccid);
  5145. strcpy((char *)ShmOCPP16Data->BootNotification.CpImsi,(const char *)ShmSysConfigAndInfo->SysConfig.TelecomInterface.TelcomSimImsi);
  5146. sprintf(payload, "{\"chargeBoxSerialNumber\":\"%s\",\"chargePointModel\":\"%s\",\"chargePointSerialNumber\":\"%s\",\"chargePointVendor\":\"%s\",\"firmwareVersion\":\"%s\",\"iccid\":\"%s\",\"imsi\":\"%s\"} ",
  5147. ShmOCPP16Data->ChargeBoxId
  5148. ,ShmSysConfigAndInfo->SysConfig.ModelName
  5149. ,ShmSysConfigAndInfo->SysConfig.SerialNumber
  5150. ,ShmSysConfigAndInfo->SysConfig.chargePointVendor
  5151. ,ShmOCPP16Data->BootNotification.CpFwVersion
  5152. ,ShmOCPP16Data->BootNotification.CpIccid
  5153. ,ShmOCPP16Data->BootNotification.CpImsi);
  5154. random_uuid(guid);
  5155. sprintf(message,"[%d,\"%s\",\"%s\",%s]",MESSAGE_TYPE_CALL, guid, "BootNotification", payload);
  5156. LWS_Send(message);
  5157. sprintf(tempdata, "BootNotification,0");
  5158. 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*/)
  5159. {
  5160. result = PASS;
  5161. }
  5162. memset(queuedata, 0, ARRAY_SIZE(queuedata));
  5163. strcpy(queuedata,message);
  5164. return result;
  5165. }
  5166. int sendDataTransferRequest(int gun_index)
  5167. {
  5168. mtrace();
  5169. char message[1000]={0};
  5170. char guid[37]={0};
  5171. char tempdata[65]={0};
  5172. int result = FAIL;
  5173. random_uuid(guid);
  5174. sprintf(message,"[%d,\"%s\",\"DataTransfer\",{\"vendorId\":\"%s\",\"messageId\":\"%s\",\"data\":\"%s\"}]",
  5175. MESSAGE_TYPE_CALL,
  5176. guid,
  5177. ShmOCPP16Data->DataTransfer[gun_index].VendorId,
  5178. ShmOCPP16Data->DataTransfer[gun_index].MessageId,
  5179. ShmOCPP16Data->DataTransfer[gun_index].Data);
  5180. LWS_Send(message);
  5181. sprintf(tempdata, "DataTransfer,%d", (gun_index + 1));
  5182. if(hashmap_operation(HASH_OP_ADD, guid, tempdata) == 1)
  5183. {
  5184. result = PASS;
  5185. DEBUG_INFO("DataTransfer mapItem pass\n");
  5186. }
  5187. return result;
  5188. }
  5189. int sendUnplugByDataTransferRequest(int gun_index)
  5190. {
  5191. mtrace();
  5192. char message[1000]={0};
  5193. char guid[37]={0};
  5194. char tempdata[65]={0};
  5195. int result = FAIL;
  5196. random_uuid(guid);
  5197. sprintf(message,"%d,[%d,\"%s\",\"DataTransfer\",{\"vendorId\":\"%s\",\"messageId\":\"%s\",\"data\":\"%s\"}]",
  5198. (gun_index+1),
  5199. MESSAGE_TYPE_CALL,
  5200. guid,
  5201. ShmOCPP16Data->DataTransfer[gun_index].VendorId,
  5202. ShmOCPP16Data->DataTransfer[gun_index].MessageId,
  5203. ShmOCPP16Data->DataTransfer[gun_index].Data);
  5204. sprintf(tempdata, "DataTransfer,%d", (gun_index + 1));
  5205. if(hashmap_operation(HASH_OP_ADD, guid, tempdata) == 1)
  5206. {
  5207. result = PASS;
  5208. DEBUG_INFO("DataTransfer mapItem pass\n");
  5209. }
  5210. queue_operation(QUEUE_OPERATION_ADD, guid, message);
  5211. return result;
  5212. }
  5213. int sendDiagnosticsStatusNotificationRequest(char *status)
  5214. {
  5215. mtrace();
  5216. int result = FAIL;
  5217. char message[110]={0};
  5218. char guid[37]={0};
  5219. char tempdata[65]={0};
  5220. //[ 2, "9f7bced1-b8b1-40ec-b3bb-2e15630e3cdc", "DiagnosticsStatusNotification", { "status": "Idle" } ]
  5221. DEBUG_INFO("sendDiagnosticsStatusNotificationRequest...\n");
  5222. sprintf((char *)ShmOCPP16Data->DiagnosticsStatusNotification.Status,"%s",(const char *)status);
  5223. random_uuid(guid);
  5224. sprintf(message,"[%d,\"%s\",\"DiagnosticsStatusNotification\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALL, guid,status);
  5225. LWS_SendNow(message);
  5226. sprintf(tempdata, "DiagnosticsStatusNotification,%d", 0);
  5227. if(hashmap_operation(HASH_OP_ADD, guid, tempdata) == 1)
  5228. {
  5229. result = PASS;
  5230. //DEBUG_INFO("DiagnosticsStatusNotification mapItem pass\n");
  5231. }
  5232. //#ifdef SystemLogMessage
  5233. //DEBUG_INFO(">>>>>DiagnosticsStatusNotification request\n");
  5234. //DEBUG_INFO("Message: %s\n", SendBuffer);
  5235. //DEBUG_INFO("After push hash length: %d\n", hashmapForMessageLength()/*hashmap_length(hashMap)*/);
  5236. //#endif
  5237. ShmOCPP16Data->SpMsg.bits.DiagnosticsStatusNotificationReq = 0;
  5238. ShmOCPP16Data->SpMsg.bits.DiagnosticsStatusNotificationConf = 0;
  5239. //record status
  5240. if(strcmp(status,"Idle")==0)
  5241. {
  5242. DiagnosticsStatusNotificationStatus = DIAGNOSTIC_STATUS_IDLE;
  5243. }
  5244. else if(strcmp(status,"Uploaded")==0)
  5245. {
  5246. DiagnosticsStatusNotificationStatus = DIAGNOSTIC_STATUS_UPLOADED;
  5247. }
  5248. else if(strcmp(status,"UploadFailed")==0)
  5249. {
  5250. DiagnosticsStatusNotificationStatus = DIAGNOSTIC_STATUS_UPLOAD_FAIL;
  5251. }
  5252. else if(strcmp(status,"Uploading")==0)
  5253. {
  5254. DiagnosticsStatusNotificationStatus = DIAGNOSTIC_STATUS_UPLOADING;
  5255. }
  5256. return result;
  5257. }
  5258. int sendFirmwareStatusNotificationRequest(char *status)
  5259. {
  5260. mtrace();
  5261. int result = FAIL;
  5262. char message[110]={0};
  5263. char guid[37]={0};
  5264. char tempdata[65]={0};
  5265. // [ 2, "eb841424-ae56-42b0-8c84-d5296018c33c", "FirmwareStatusNotification", { "status": "Downloaded" } ]
  5266. DEBUG_INFO("sendFirmwareStatusNotificationRequest \n");
  5267. sprintf((char *)ShmOCPP16Data->FirmwareStatusNotification.Status, "%s", (const char *)status);
  5268. random_uuid(guid);
  5269. sprintf(message,"[%d,\"%s\",\"FirmwareStatusNotification\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALL, guid, status);
  5270. LWS_SendNow(message);
  5271. sprintf(tempdata, "FirmwareStatusNotification,%d", 0);
  5272. 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*/)
  5273. {
  5274. result = PASS;
  5275. DEBUG_INFO("FirmwareStatusNotification mapItem pass\n");
  5276. }
  5277. //#ifdef SystemLogMessage
  5278. //DEBUG_INFO(">>>>>FirmwareStatusNotification request\n");
  5279. //DEBUG_INFO("Message: %s\n", SendBuffer);
  5280. //#endif
  5281. ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationReq = 0;
  5282. ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationConf = 0;
  5283. //record status
  5284. if(strcmp(status,"Downloaded")==0)
  5285. {
  5286. FirmwareStatusNotificationStatus = FIRMWARE_STATUS_DOWNLOADED;
  5287. }
  5288. else if(strcmp(status,"DownloadFailed")==0)
  5289. {
  5290. FirmwareStatusNotificationStatus = FIRMWARE_STATUS_DOWNLOAD_FAILED;
  5291. }
  5292. else if(strcmp(status,"Downloading")==0)
  5293. {
  5294. FirmwareStatusNotificationStatus = FIRMWARE_STATUS_DOWNLOADING;
  5295. }
  5296. else if(strcmp(status,"Idle")==0)
  5297. {
  5298. FirmwareStatusNotificationStatus = FIRMWARE_STATUS_IDLE;
  5299. }
  5300. else if(strcmp(status,"InstallationFailed")==0)
  5301. {
  5302. FirmwareStatusNotificationStatus = FIRMWARE_STATUS_INSTALLATION_FAILED;
  5303. }
  5304. else if(strcmp(status,"Installing")==0)
  5305. {
  5306. FirmwareStatusNotificationStatus = FIRMWARE_STATUS_INSTALLING;
  5307. }
  5308. else if(strcmp(status,"Installed")==0)
  5309. {
  5310. FirmwareStatusNotificationStatus = FIRMWARE_STATUS_INSTALLED;
  5311. }
  5312. return result;
  5313. }
  5314. int sendHeartbeatRequest(int gun_index)
  5315. {
  5316. mtrace();
  5317. int result = FAIL;
  5318. char message[80]={0};
  5319. char guid[37]={0};
  5320. char tempdata[65]={0};
  5321. random_uuid(guid);
  5322. sprintf(message, "[%d,\"%s\",\"Heartbeat\",{ }]"
  5323. , MESSAGE_TYPE_CALL
  5324. , guid );
  5325. LWS_Send(message);
  5326. sprintf(tempdata, "Heartbeat,%d", 0);
  5327. 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*/)
  5328. {
  5329. result = PASS;
  5330. }
  5331. return result;
  5332. }
  5333. int sendStartTransactionRequest(int gun_index)
  5334. {
  5335. mtrace();
  5336. int result = FAIL;
  5337. char message[250]={0};
  5338. char guid[37]={0};
  5339. struct timeval tmnow;
  5340. struct tm *tm;
  5341. char buf[28];//, usec_buf[6];
  5342. char tempdata[65]={0};
  5343. int tempIndex = 0;
  5344. DEBUG_INFO("sendStartTransactionRequest...\n");
  5345. gettimeofday(&tmnow, NULL);
  5346. time_t t;
  5347. t = time(NULL);
  5348. /*UTC time and date*/
  5349. tm = gmtime(&t);
  5350. strftime(buf,28,"%Y-%m-%dT%H:%M:%SZ", tm);
  5351. #if 0 // remove temporally
  5352. strftime(buf,30,"%Y-%m-%dT%H:%M:%S", tm);
  5353. strcat(buf,".");
  5354. sprintf(usec_buf,"%dZ",(int)tmnow.tv_usec);
  5355. strcat(buf,usec_buf);
  5356. #endif
  5357. ShmOCPP16Data->StartTransaction[gun_index].ConnectorId = gun_index +1 ; // gun start from 1~
  5358. strcpy((char *)ShmOCPP16Data->StartTransaction[gun_index].Timestamp, buf);
  5359. //strcpy((char *)ShmOCPP16Data->StartTransaction[gun_index].IdTag, (const char *)ShmSysConfigAndInfo->SysConfig.UserId);
  5360. // clear StartTransaction Response
  5361. strcpy((char *)ShmOCPP16Data->StartTransaction[gun_index].ResponseIdTagInfo.ExpiryDate, "");
  5362. strcpy((char *)ShmOCPP16Data->StartTransaction[gun_index].ResponseIdTagInfo.ParentIdTag, "");
  5363. strcpy((char *)ShmOCPP16Data->StartTransaction[gun_index].ResponseIdTagInfo.Status, "");
  5364. ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId = 0;
  5365. refreshStartTimer(&clientTime.MeterValues[gun_index]);
  5366. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DCcc
  5367. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  5368. {
  5369. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  5370. {
  5371. tempIndex = ((gun_index==2) ? 1: 0);
  5372. }
  5373. else
  5374. {
  5375. tempIndex = gun_index;
  5376. }
  5377. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  5378. {
  5379. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  5380. {
  5381. ShmOCPP16Data->StartTransaction[gun_index].MeterStart = (int)(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PowerConsumption*1000);
  5382. ShmOCPP16Data->StartTransaction[gun_index].ReservationId = ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ReservationId;
  5383. }
  5384. }
  5385. }
  5386. else if(gunType[gun_index] == GUN_TYPE_CCS)
  5387. {
  5388. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  5389. {
  5390. tempIndex = ((gun_index==2) ? 1: 0);
  5391. }
  5392. else
  5393. {
  5394. tempIndex = gun_index;
  5395. }
  5396. for (int index = 0; index < CCS_QUANTITY; index++)
  5397. {
  5398. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  5399. {
  5400. ShmOCPP16Data->StartTransaction[gun_index].MeterStart = (int)(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PowerConsumption*1000);
  5401. ShmOCPP16Data->StartTransaction[gun_index].ReservationId = ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ReservationId;
  5402. }
  5403. }
  5404. }
  5405. else if(gunType[gun_index] == GUN_TYPE_GBT)
  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 < GB_QUANTITY; index++)
  5416. {
  5417. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  5418. {
  5419. ShmOCPP16Data->StartTransaction[gun_index].MeterStart = (int)(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PowerConsumption*1000);
  5420. ShmOCPP16Data->StartTransaction[gun_index].ReservationId = ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ReservationId;
  5421. }
  5422. }
  5423. }
  5424. else if(gunType[gun_index] == GUN_TYPE_DO)
  5425. {
  5426. tempIndex = gun_index;
  5427. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  5428. {
  5429. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  5430. {
  5431. ShmOCPP16Data->StartTransaction[gun_index].MeterStart = (int)(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PowerConsumption*1000);
  5432. ShmOCPP16Data->StartTransaction[gun_index].ReservationId = ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.ReservationId;
  5433. }
  5434. }
  5435. }
  5436. else
  5437. {
  5438. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  5439. {
  5440. tempIndex = 2;
  5441. }
  5442. else
  5443. {
  5444. tempIndex = gun_index;
  5445. }
  5446. for (int index = 0; index < AC_QUANTITY; index++)
  5447. {
  5448. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  5449. {
  5450. ShmOCPP16Data->StartTransaction[gun_index].MeterStart = (int)(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PowerConsumption*1000);
  5451. ShmOCPP16Data->StartTransaction[gun_index].ReservationId = ShmSysConfigAndInfo->SysInfo.AcChargingData[index].ReservationId;
  5452. }
  5453. }
  5454. }
  5455. random_uuid(guid);
  5456. if(ShmOCPP16Data->StartTransaction[gun_index].ReservationId == -1) // No Reservation
  5457. {
  5458. sprintf(message, "%d,[%d,\"%s\",\"StartTransaction\",{\"connectorId\":%d,\"idTag\":\"%s\",\"meterStart\":%d,\"timestamp\":\"%s\"}]"
  5459. , gun_index +1
  5460. , MESSAGE_TYPE_CALL
  5461. , guid
  5462. , ShmOCPP16Data->StartTransaction[gun_index].ConnectorId
  5463. , ShmOCPP16Data->StartTransaction[gun_index].IdTag
  5464. , ShmOCPP16Data->StartTransaction[gun_index].MeterStart
  5465. , ShmOCPP16Data->StartTransaction[gun_index].Timestamp );
  5466. }
  5467. else
  5468. {
  5469. sprintf(message, "%d,[%d,\"%s\",\"StartTransaction\",{\"connectorId\":%d,\"idTag\":\"%s\",\"meterStart\":%d,\"reservationId\":%d,\"timestamp\":\"%s\"}]"
  5470. , gun_index +1
  5471. , MESSAGE_TYPE_CALL
  5472. , guid
  5473. , ShmOCPP16Data->StartTransaction[gun_index].ConnectorId
  5474. , ShmOCPP16Data->StartTransaction[gun_index].IdTag
  5475. , ShmOCPP16Data->StartTransaction[gun_index].MeterStart
  5476. , ShmOCPP16Data->StartTransaction[gun_index].ReservationId
  5477. , ShmOCPP16Data->StartTransaction[gun_index].Timestamp );
  5478. }
  5479. #if 1
  5480. sprintf(tempdata, "StartTransaction,%d", (gun_index));
  5481. 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*/)
  5482. {
  5483. result = PASS;
  5484. }
  5485. #endif
  5486. strcpy(queuedata, message);
  5487. queue_operation(QUEUE_OPERATION_ADD, guid, queuedata );//addq(guid, queuedata); ---> remove temporally
  5488. OCPP_insert_transaction_msg(YES, queuedata);
  5489. return result;
  5490. }
  5491. int sendStatusNotificationRequest(int gun_index)
  5492. {
  5493. mtrace();
  5494. int result = FAIL;
  5495. char message[600]={0};
  5496. char guid[37];
  5497. int currentStatus = 0;
  5498. struct timeval tmnow;
  5499. struct tm *tm;
  5500. char buf[28];//, usec_buf[6];
  5501. char tempdata[65]={0};
  5502. int tempIndex = 0;
  5503. uint8_t isStateChanged = TRUE;
  5504. uint8_t isContentIllegal = TRUE;
  5505. DEBUG_INFO("sendStatusNotificationRequest...\n");
  5506. gettimeofday(&tmnow, NULL);
  5507. time_t t;
  5508. t = time(NULL);
  5509. /*UTC time and date*/
  5510. tm = gmtime(&t);
  5511. strftime(buf,28,"%Y-%m-%dT%H:%M:%SZ", tm);
  5512. #if 0 // remove temporally
  5513. strftime(buf,30,"%Y-%m-%dT%H:%M:%S", tm);
  5514. strcat(buf,".");
  5515. sprintf(usec_buf,"%dZ",(int)tmnow.tv_usec);
  5516. strcat(buf,usec_buf);
  5517. #endif
  5518. //printf("%s",buf);
  5519. ShmOCPP16Data->StatusNotification[gun_index].ConnectorId = (gun_index + 1);
  5520. //strcpy(ShmOCPP16Data->StatusNotification[gun_index].ErrorCode, "NoError"); --- CSU Setting
  5521. // it's option
  5522. //strcpy((char *)ShmOCPP16Data->StatusNotification[gun_index].Info, "");
  5523. /*
  5524. enum _SYSTEM_STATUS
  5525. {
  5526. S_BOOTING = 0,
  5527. S_IDLE, = 1
  5528. S_AUTHORIZING, =2
  5529. S_REASSIGN_CHECK, =3
  5530. S_REASSIGN, =4
  5531. S_PRECHARGE, =5
  5532. S_PREPARING_FOR_EV, =6
  5533. S_PREPARING_FOR_EVSE, =7
  5534. S_CHARGING, =8
  5535. S_TERMINATING, =9
  5536. S_COMPLETE, =10
  5537. S_ALARM, =11
  5538. S_FAULT =12
  5539. }
  5540. */
  5541. //check Transaction active
  5542. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DCcc
  5543. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  5544. {
  5545. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  5546. {
  5547. tempIndex = ((gun_index==2) ? 1: 0);
  5548. }
  5549. else
  5550. {
  5551. tempIndex = gun_index;
  5552. }
  5553. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  5554. {
  5555. if ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex))
  5556. {
  5557. if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_IDLE)//S_IDLE
  5558. {
  5559. if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ConnectorPlugIn == 1) // //0: unplug, 1: Plug-in
  5560. {
  5561. currentStatus = Preparing; //OCPP Status: Preparing
  5562. }
  5563. else
  5564. {
  5565. currentStatus = Available; //OCPP Status: Available
  5566. }
  5567. }
  5568. else if ( ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus >= SYS_MODE_AUTHORIZING)&&( ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus <= SYS_MODE_PREPARE_FOR_EVSE)) ||
  5569. ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus >= SYS_MODE_CCS_PRECHARGE_STEP0) && ( ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus <= SYS_MODE_CCS_PRECHARGE_STEP1) )
  5570. ) //S_PRECHARGE
  5571. {
  5572. currentStatus = Preparing; //OCPP Status: Preparing
  5573. }
  5574. else if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_CHARGING) //S_CHARGING
  5575. {
  5576. currentStatus = Charging; //OCPP Status: Charging
  5577. }
  5578. else if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_COMPLETE) //S_COMPLETE
  5579. {
  5580. currentStatus = Finishing; //OCPP Status: Finishing
  5581. }
  5582. else if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_TERMINATING) // S_TERMINATING ---> SuspendedEV
  5583. {
  5584. currentStatus = SuspendedEV; //OCPP Status: SuspendedEV
  5585. }
  5586. 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
  5587. {
  5588. currentStatus = Unavailable; //OCPP Status: Unavailable
  5589. }
  5590. else if ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_FAULT) || (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_ALARM)) //S_ALARM,S_FAULT ---> Faulted
  5591. {
  5592. currentStatus = Faulted; //OCPP Status: Faulted
  5593. }
  5594. else if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_RESERVATION) // ---> Reserved
  5595. {
  5596. currentStatus = Reserved; //OCPP Status: Reserved
  5597. }
  5598. } //end of the same index
  5599. }//end of for CHAdeMO_QUANTITY
  5600. }
  5601. else if(gunType[gun_index] == GUN_TYPE_CCS)
  5602. {
  5603. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  5604. {
  5605. tempIndex = ((gun_index==2) ? 1: 0);
  5606. }
  5607. else
  5608. {
  5609. tempIndex = gun_index;
  5610. }
  5611. for (int index = 0; index < CCS_QUANTITY; index++)
  5612. {
  5613. if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  5614. {
  5615. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_IDLE) //S_IDLE
  5616. {
  5617. if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ConnectorPlugIn == 1) //0: unplug, 1: Plug-in
  5618. {
  5619. currentStatus = Preparing; //OCPP Status: Preparing
  5620. }
  5621. else
  5622. {
  5623. currentStatus = Available; //OCPP Status: Available
  5624. }
  5625. }
  5626. else if ( ((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus >= SYS_MODE_AUTHORIZING)&&( ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus <= SYS_MODE_PREPARE_FOR_EVSE)) ||
  5627. ((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus >= SYS_MODE_CCS_PRECHARGE_STEP0) && ( ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus <= SYS_MODE_CCS_PRECHARGE_STEP1) )
  5628. ) //S_PRECHARGE
  5629. {
  5630. currentStatus = Preparing; //OCPP Status: Preparing
  5631. }
  5632. else if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_CHARGING) //S_CHARGING
  5633. {
  5634. currentStatus = Charging; //OCPP Status: Charging
  5635. }
  5636. else if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_COMPLETE) //S_COMPLETE
  5637. {
  5638. currentStatus = Finishing; //OCPP Status: Finishing
  5639. }
  5640. else if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_TERMINATING) //S_TERMINATING ---> SuspendedEV
  5641. {
  5642. currentStatus = SuspendedEV; //OCPP Status: SuspendedEV
  5643. }
  5644. 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
  5645. {
  5646. currentStatus = Unavailable; //OCPP Status : Unavailable
  5647. }
  5648. else if ((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_FAULT) || (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_ALARM)) //S_ALARM ,S_FAULT ---> Faulted
  5649. {
  5650. currentStatus = Faulted; //OCPP Status: Faulted
  5651. }
  5652. else if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_RESERVATION) // ---> Reserved
  5653. {
  5654. currentStatus = Reserved; //OCPP Status: Reserved
  5655. }
  5656. } //end of the same index
  5657. } // end of for CCS_QUANTITY
  5658. }
  5659. else if(gunType[gun_index] == GUN_TYPE_GBT)
  5660. {
  5661. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  5662. {
  5663. tempIndex = ((gun_index==2) ? 1: 0);
  5664. }
  5665. else
  5666. {
  5667. tempIndex = gun_index;
  5668. }
  5669. for (int index = 0; index < GB_QUANTITY; index++)
  5670. {
  5671. if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  5672. {
  5673. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_IDLE) //S_IDLE
  5674. {
  5675. if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ConnectorPlugIn == 1) // //0: unplug, 1: Plug-in
  5676. {
  5677. currentStatus = Preparing; //OCPP Status: Preparing
  5678. }
  5679. else
  5680. {
  5681. currentStatus = Available; //OCPP Status: Available
  5682. }
  5683. }
  5684. else if ( ((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus >= SYS_MODE_AUTHORIZING)&&( ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus <= SYS_MODE_PREPARE_FOR_EVSE)) ||
  5685. ((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus >= SYS_MODE_CCS_PRECHARGE_STEP0) && ( ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus <= SYS_MODE_CCS_PRECHARGE_STEP1) )
  5686. ) //S_PRECHARGE
  5687. {
  5688. currentStatus = Preparing; //OCPP Status: Preparing
  5689. }
  5690. else if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_CHARGING) //S_CHARGING
  5691. {
  5692. currentStatus = Charging; //OCPP Status: Charging
  5693. }
  5694. else if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_COMPLETE) //S_COMPLETE
  5695. {
  5696. currentStatus = Finishing; //OCPP Status: Finishing
  5697. }
  5698. else if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_TERMINATING) // S_TERMINATING ---> SuspendedEV
  5699. {
  5700. currentStatus = SuspendedEV; //OCPP Status: SuspendedEV
  5701. }
  5702. 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
  5703. {
  5704. currentStatus = Unavailable; //OCPP Status: Unavailable
  5705. }
  5706. else if ((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_FAULT) || (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_ALARM)) //S_ALARM ,S_FAULT ---> Faulted
  5707. {
  5708. currentStatus = Faulted; //OCPP Status: Faulted
  5709. }
  5710. else if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_RESERVATION) // ---> Reserved
  5711. {
  5712. currentStatus = Reserved; //OCPP Status: Reserved
  5713. }
  5714. } //end of the same index
  5715. } // end of for GB_QUANTITY
  5716. }
  5717. else if(gunType[gun_index] == GUN_TYPE_DO)
  5718. {
  5719. tempIndex = gun_index;
  5720. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  5721. {
  5722. if(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  5723. {
  5724. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_IDLE) //S_IDLE
  5725. {
  5726. if(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.ConnectorPlugIn == 1) // //0: unplug, 1: Plug-in
  5727. {
  5728. currentStatus = Preparing; //OCPP Status: Preparing
  5729. }
  5730. else
  5731. {
  5732. currentStatus = Available; //OCPP Status: Available
  5733. }
  5734. }
  5735. else if ( ((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus >= SYS_MODE_AUTHORIZING) && (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus <= SYS_MODE_PREPARE_FOR_EVSE)) ||
  5736. ((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus >= SYS_MODE_CCS_PRECHARGE_STEP0) && (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus <= SYS_MODE_CCS_PRECHARGE_STEP1) )
  5737. ) //S_PRECHARGE
  5738. {
  5739. currentStatus = Preparing; //OCPP Status: Preparing
  5740. }
  5741. else if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_CHARGING) //S_CHARGING
  5742. {
  5743. currentStatus = Charging; //OCPP Status: Charging
  5744. }
  5745. else if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_COMPLETE) //S_COMPLETE
  5746. {
  5747. currentStatus = Finishing; //OCPP Status: Finishing
  5748. }
  5749. else if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_TERMINATING) // S_TERMINATING ---> SuspendedEV
  5750. {
  5751. currentStatus = SuspendedEV; //OCPP Status: SuspendedEV
  5752. }
  5753. 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
  5754. {
  5755. currentStatus = Unavailable; //OCPP Status: Unavailable
  5756. }
  5757. 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
  5758. {
  5759. currentStatus = Faulted; //OCPP Status: Faulted
  5760. }
  5761. else if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_RESERVATION) // ---> Reserved
  5762. {
  5763. currentStatus = Reserved; //OCPP Status: Reserved
  5764. }
  5765. } //end of the same index
  5766. }
  5767. }
  5768. else
  5769. {
  5770. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  5771. {
  5772. tempIndex = 2;
  5773. }
  5774. else
  5775. {
  5776. tempIndex = gun_index;
  5777. }
  5778. for (int index = 0; index < AC_QUANTITY; index++)
  5779. {
  5780. if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  5781. {
  5782. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_IDLE) //SYS_MODE_IDLE
  5783. {
  5784. 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))
  5785. {
  5786. currentStatus = Preparing; //OCPP Status: Preparing
  5787. }
  5788. else
  5789. {
  5790. currentStatus = Available; //OCPP Status: Available
  5791. }
  5792. }
  5793. else if ((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_AUTHORIZING) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_PREPARING)) //SYS_MODE_PREPARING
  5794. {
  5795. currentStatus = Preparing; //OCPP Status: Preparing
  5796. }
  5797. else if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_CHARGING) //SYS_MODE_CHARGING
  5798. {
  5799. currentStatus = Charging; //OCPP Status: Charging
  5800. }
  5801. else if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_COMPLETE) //SYS_MODE_COMPLETE
  5802. {
  5803. currentStatus = Finishing; //OCPP Status: Finishing
  5804. }
  5805. else if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_TERMINATING) // S_TERMINATING ---> SuspendedEV
  5806. {
  5807. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PilotState == CP_STATE_B))
  5808. currentStatus = SuspendedEV; //OCPP Status: SuspendedEV
  5809. else
  5810. currentStatus = SuspendedEVSE; //OCPP Status: SuspendedEVSE
  5811. }
  5812. 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
  5813. {
  5814. currentStatus = Unavailable; //OCPP Status: Unavailable
  5815. }
  5816. else if ((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_FAULT) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_ALARM)) //S_ALARM,S_FAULT ---> Faulted
  5817. {
  5818. currentStatus = Faulted; //OCPP Status: Faulted
  5819. }
  5820. else if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_RESERVATION) // ---> Reserved
  5821. {
  5822. currentStatus = Reserved; //OCPP Status: Reserved
  5823. }
  5824. }//end of the same index
  5825. }//end of for AC_QUANTITY
  5826. }
  5827. //it's option
  5828. if(((strstr((char *)ShmOCPP16Data->StatusNotification[gun_index].Status, ChargePointStatusStr[currentStatus]) != NULL) || (((currentStatus == SuspendedEV) || (currentStatus == SuspendedEVSE)) && ShmOCPP16Data->CsMsg.bits[gun_index].RemoteStopTransactionReq)) &&
  5829. !cpinitateMsg.bits[gun_index].TriggerStatusNotificationReq &&
  5830. (strcmp((const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StatusNotificationPeriodically].ItemData, "TRUE") != 0))
  5831. {
  5832. isStateChanged = FALSE;
  5833. }
  5834. cpinitateMsg.bits[gun_index].TriggerStatusNotificationReq = 0;
  5835. strcpy((char *)ShmOCPP16Data->StatusNotification[gun_index].Timestamp, buf);
  5836. strcpy((char *)ShmOCPP16Data->StatusNotification[gun_index].VendorId, (char*)ShmSysConfigAndInfo->SysConfig.chargePointVendor);
  5837. strcpy((char *)ShmOCPP16Data->StatusNotification[gun_index].Status, ChargePointStatusStr[currentStatus]);
  5838. isContentIllegal = TRUE;
  5839. for(int index = 0; index < ARRAY_SIZE(ChargePointErrorCodeStr); index++)
  5840. {
  5841. if(strcmp((char *)ShmOCPP16Data->StatusNotification[gun_index].ErrorCode, ChargePointErrorCodeStr[index])==0)
  5842. {
  5843. isContentIllegal = FALSE;
  5844. break;
  5845. }
  5846. }
  5847. if(isContentIllegal)
  5848. {
  5849. //DEBUG_WARN("Detect illegal ErrorCode: %s \n",(char *)ShmOCPP16Data->StatusNotification[gun_index].ErrorCode);
  5850. strcpy((char *)ShmOCPP16Data->StatusNotification[gun_index].ErrorCode, ChargePointErrorCodeStr[6]);
  5851. }
  5852. random_uuid(guid);
  5853. sprintf(message, "[%d,\"%s\",\"StatusNotification\",{\"connectorId\":%d,\"errorCode\":\"%s\",\"info\":\"%s\",\"status\":\"%s\",\"timestamp\":\"%s\",\"vendorId\":\"%s\",\"vendorErrorCode\":\"%s\"}]"
  5854. , MESSAGE_TYPE_CALL
  5855. , guid
  5856. , ShmOCPP16Data->StatusNotification[gun_index].ConnectorId
  5857. , ShmOCPP16Data->StatusNotification[gun_index].ErrorCode
  5858. , ShmOCPP16Data->StatusNotification[gun_index].Info
  5859. , ShmOCPP16Data->StatusNotification[gun_index].Status
  5860. , ShmOCPP16Data->StatusNotification[gun_index].Timestamp
  5861. , ShmOCPP16Data->StatusNotification[gun_index].VendorId
  5862. , ShmOCPP16Data->StatusNotification[gun_index].VendorErrorCode);
  5863. if((server_sign == TRUE) && isStateChanged)
  5864. {
  5865. cpinitateMsg.bits[gun_index].StatusNotificationReq = 0;
  5866. cpinitateMsg.bits[gun_index].TriggerStatusNotificationReq = 0;
  5867. LWS_Send(message);
  5868. sprintf(tempdata, "StatusNotification,%d", (gun_index));
  5869. 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*/)
  5870. {
  5871. //DEBUG_ERROR("statusNotification mapitem pass");
  5872. result = PASS;
  5873. }
  5874. }
  5875. else
  5876. {
  5877. cpinitateMsg.bits[gun_index].StatusNotificationReq = 0;
  5878. cpinitateMsg.bits[gun_index].TriggerStatusNotificationReq = 0;
  5879. result = PASS;
  5880. }
  5881. return result;
  5882. }
  5883. int sendStopTransactionRequest(int gun_index)
  5884. {
  5885. mtrace();
  5886. int result = FAIL;
  5887. //char message[1500]={0};
  5888. char guid[37]={0};
  5889. char tempdata[65]={0};
  5890. int tempIndex = 0;
  5891. char TempStopTransaction[256];
  5892. sprintf(TempStopTransaction, "/Storage/OCPP/TempStopTransaction_%d", (gun_index+1));
  5893. //int idx_sample=0;
  5894. DEBUG_INFO("sendStopTransactionRequest \n");
  5895. memset(queuedata, 0, ARRAY_SIZE(queuedata));
  5896. memset(&ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0], 0, ARRAY_SIZE(ShmOCPP16Data->StopTransaction[gun_index].TransactionData));
  5897. //=========================== ENERGY_ACTIVE_IMPORT_REGISTER =======================================
  5898. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DCcc
  5899. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  5900. {
  5901. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  5902. {
  5903. tempIndex = ((gun_index==2) ? 1: 0);
  5904. }
  5905. else
  5906. {
  5907. tempIndex = gun_index;
  5908. }
  5909. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  5910. {
  5911. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  5912. {
  5913. ShmOCPP16Data->StopTransaction[gun_index].MeterStop = (int)(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PowerConsumption*1000);
  5914. }
  5915. }// END OF CHAdeMO_QUANTITY
  5916. }
  5917. else if(gunType[gun_index] == GUN_TYPE_CCS)
  5918. {
  5919. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  5920. {
  5921. tempIndex = ((gun_index==2) ? 1: 0);
  5922. }
  5923. else
  5924. {
  5925. tempIndex = gun_index;
  5926. }
  5927. for (int index = 0; index < CCS_QUANTITY; index++)
  5928. {
  5929. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  5930. {
  5931. ShmOCPP16Data->StopTransaction[gun_index].MeterStop = (int)(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PowerConsumption*1000);
  5932. }
  5933. }// END OF CCS_QUANTITY
  5934. }
  5935. else if(gunType[gun_index] == GUN_TYPE_GBT)
  5936. {
  5937. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  5938. {
  5939. tempIndex = ((gun_index==2) ? 1: 0);
  5940. }
  5941. else
  5942. {
  5943. tempIndex = gun_index;
  5944. }
  5945. for (int index = 0; index < GB_QUANTITY; index++)
  5946. {
  5947. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  5948. {
  5949. ShmOCPP16Data->StopTransaction[gun_index].MeterStop = (int)(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PowerConsumption*1000);
  5950. }
  5951. }// END OF GB_QUANTITY
  5952. }
  5953. else if(gunType[gun_index] == GUN_TYPE_DO)
  5954. {
  5955. tempIndex = gun_index;
  5956. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  5957. {
  5958. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  5959. {
  5960. ShmOCPP16Data->StopTransaction[gun_index].MeterStop = (int)(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PowerConsumption*1000);
  5961. }
  5962. }// END OF GB_QUANTITY
  5963. }
  5964. else
  5965. {
  5966. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  5967. {
  5968. tempIndex = 2;
  5969. }
  5970. else
  5971. {
  5972. tempIndex = gun_index;
  5973. }
  5974. for (int index = 0; index < AC_QUANTITY; index++)
  5975. {
  5976. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  5977. {
  5978. ShmOCPP16Data->StopTransaction[gun_index].MeterStop = (int)(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PowerConsumption*1000);
  5979. }
  5980. }// END OF AC_QUANTITY
  5981. }
  5982. //====================================== Stop Transaction Time =====================================================
  5983. struct timeval tmnow;
  5984. struct tm *tm;
  5985. char buf[28];//, usec_buf[6];
  5986. gettimeofday(&tmnow, NULL);
  5987. time_t t;
  5988. t = time(NULL);
  5989. /*UTC time and date*/
  5990. tm = gmtime(&t);
  5991. strftime(buf,28,"%Y-%m-%dT%H:%M:%SZ", tm);
  5992. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].Timestamp,buf);
  5993. ShmOCPP16Data->StopTransaction[gun_index].TransactionId = ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId;
  5994. random_uuid(guid);
  5995. /***********************************transactionData******************************************************/
  5996. memset(ShmOCPP16Data->StopTransaction[gun_index].TransactionData, 0, sizeof(struct StructMeterValue));
  5997. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].TimeStamp, buf);
  5998. //=================================
  5999. // Transaction_Begin
  6000. //=================================
  6001. //=================================
  6002. // Transaction_End
  6003. //=================================
  6004. // ================================= Current.Import L1 ===============================================
  6005. if(strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Current.Import") != NULL)
  6006. {
  6007. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G : GBT DC
  6008. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  6009. {
  6010. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  6011. {
  6012. tempIndex = ((gun_index==2) ? 1: 0);
  6013. }
  6014. else
  6015. {
  6016. tempIndex = gun_index;
  6017. }
  6018. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  6019. {
  6020. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  6021. {
  6022. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargingCurrent );// PresentChargingCurrent is 0~6553.5 amp
  6023. }
  6024. }// End of for CHAdeMO_QUANTITY
  6025. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase,PhaseStr[L3_N]);
  6026. }
  6027. else if(gunType[gun_index] == GUN_TYPE_CCS)
  6028. {
  6029. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  6030. {
  6031. tempIndex = ((gun_index==2) ? 1: 0);
  6032. }
  6033. else
  6034. {
  6035. tempIndex = gun_index;
  6036. }
  6037. for (int index = 0; index < CCS_QUANTITY; index++)
  6038. {
  6039. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  6040. {
  6041. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargingCurrent );// PresentChargingCurrent is 0~6553.5 amp
  6042. }
  6043. }// End of for CCS_QUANTITY
  6044. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase,PhaseStr[L3_N]);
  6045. }
  6046. else if(gunType[gun_index] == GUN_TYPE_GBT)
  6047. {
  6048. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  6049. {
  6050. tempIndex = ((gun_index==2) ? 1: 0);
  6051. }
  6052. else
  6053. {
  6054. tempIndex = gun_index;
  6055. }
  6056. for (int index = 0; index < GB_QUANTITY; index++)
  6057. {
  6058. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  6059. {
  6060. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingCurrent );// PresentChargingCurrent is 0~6553.5 amp
  6061. }
  6062. }// End of for GB_QUANTITY
  6063. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase,PhaseStr[L3_N]);
  6064. }
  6065. else if(gunType[gun_index] == GUN_TYPE_DO)
  6066. {
  6067. tempIndex = gun_index;
  6068. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  6069. {
  6070. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  6071. {
  6072. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PresentChargingCurrent );// PresentChargingCurrent is 0~6553.5 amp
  6073. }
  6074. }
  6075. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase,PhaseStr[L3_N]);
  6076. }
  6077. else
  6078. {
  6079. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  6080. {
  6081. tempIndex = 2;
  6082. }
  6083. else
  6084. {
  6085. tempIndex = gun_index;
  6086. }
  6087. for (int index = 0; index < AC_QUANTITY; index++)
  6088. {
  6089. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  6090. {
  6091. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingCurrent );// 0~6553.5 amp for EVSE
  6092. }
  6093. }// End of for AC_QUANTITY
  6094. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase,PhaseStr[L1_N]);
  6095. }
  6096. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  6097. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Format,ValueFormatStr[Raw]);
  6098. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Measurand,MeasurandStr[Current_Import]);
  6099. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Location,LocationStr[Location_Outlet]);
  6100. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Unit,UnitOfMeasureStr[UnitOfMeasure_A]);
  6101. }
  6102. // ================================= Energy.Active.Import.Interval ==============================================
  6103. if(strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Energy.Active.Import.Interval") != NULL)
  6104. {
  6105. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  6106. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  6107. {
  6108. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  6109. {
  6110. tempIndex = ((gun_index==2) ? 1: 0);
  6111. }
  6112. else
  6113. {
  6114. tempIndex = gun_index;
  6115. }
  6116. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  6117. {
  6118. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  6119. {
  6120. 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
  6121. periousPeriodicPowerConsumption[gun_index] = ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PowerConsumption;
  6122. }
  6123. }// END OF CHAdeMO_QUANTITY
  6124. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase,PhaseStr[L3_N]);
  6125. }
  6126. else if(gunType[gun_index] == GUN_TYPE_CCS)
  6127. {
  6128. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  6129. {
  6130. tempIndex = ((gun_index==2) ? 1: 0);
  6131. }
  6132. else
  6133. {
  6134. tempIndex = gun_index;
  6135. }
  6136. for (int index = 0; index < CCS_QUANTITY; index++)
  6137. {
  6138. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  6139. {
  6140. 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
  6141. periousPeriodicPowerConsumption[gun_index] = ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PowerConsumption;
  6142. }
  6143. }// END OF CCS_QUANTITY
  6144. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase,PhaseStr[L3_N]);
  6145. }
  6146. else if(gunType[gun_index] == GUN_TYPE_GBT)
  6147. {
  6148. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  6149. {
  6150. tempIndex = ((gun_index==2) ? 1: 0);
  6151. }
  6152. else
  6153. {
  6154. tempIndex = gun_index;
  6155. }
  6156. for (int index = 0; index < GB_QUANTITY; index++)
  6157. {
  6158. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  6159. {
  6160. 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
  6161. periousPeriodicPowerConsumption[gun_index] = ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PowerConsumption;
  6162. }
  6163. }// END OF GB_QUANTITY
  6164. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase,PhaseStr[L3_N]);
  6165. }
  6166. else if(gunType[gun_index] == GUN_TYPE_DO)
  6167. {
  6168. tempIndex = gun_index;
  6169. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  6170. {
  6171. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  6172. {
  6173. 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
  6174. periousPeriodicPowerConsumption[gun_index] = ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PowerConsumption;
  6175. }
  6176. }
  6177. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase,PhaseStr[L3_N]);
  6178. }
  6179. else
  6180. {
  6181. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  6182. {
  6183. tempIndex = 2;
  6184. }
  6185. else
  6186. {
  6187. tempIndex = gun_index;
  6188. }
  6189. for (int index = 0; index < AC_QUANTITY; index++)
  6190. {
  6191. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  6192. {
  6193. 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
  6194. periousPeriodicPowerConsumption[gun_index] = ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PowerConsumption;
  6195. }
  6196. }// END OF AC_QUANTITY
  6197. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase,PhaseStr[L1_N]);
  6198. }
  6199. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  6200. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Format,ValueFormatStr[Raw]);
  6201. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Measurand,MeasurandStr[Energy_Active_Import_Interval]);
  6202. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Location,LocationStr[Location_Outlet]);
  6203. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Unit,UnitOfMeasureStr[UnitOfMeasure_kWh]);
  6204. }
  6205. //=================================== Power.Active.Import ==================================================
  6206. if(strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Power.Active.Import") != NULL)
  6207. {
  6208. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  6209. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  6210. {
  6211. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  6212. {
  6213. tempIndex = ((gun_index==2) ? 1: 0);
  6214. }
  6215. else
  6216. {
  6217. tempIndex = gun_index;
  6218. }
  6219. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  6220. {
  6221. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  6222. {
  6223. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargingPower );// PresentChargingPower is 0~6553.5 kW
  6224. }
  6225. } // End for CHAdeMO_QUANTITY
  6226. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase,PhaseStr[L3_N]);
  6227. }
  6228. else if(gunType[gun_index] == GUN_TYPE_CCS)
  6229. {
  6230. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  6231. {
  6232. tempIndex = ((gun_index==2) ? 1: 0);
  6233. }
  6234. else
  6235. {
  6236. tempIndex = gun_index;
  6237. }
  6238. for (int index = 0; index < CCS_QUANTITY; index++)
  6239. {
  6240. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  6241. {
  6242. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargingPower );// PresentChargingPower is 0~6553.5 kW
  6243. }
  6244. } // END for CCS_QUANTITY
  6245. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase,PhaseStr[L3_N]);
  6246. }
  6247. else if(gunType[gun_index] == GUN_TYPE_GBT)
  6248. {
  6249. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  6250. {
  6251. tempIndex = ((gun_index==2) ? 1: 0);
  6252. }
  6253. else
  6254. {
  6255. tempIndex = gun_index;
  6256. }
  6257. for (int index = 0; index < GB_QUANTITY; index++)
  6258. {
  6259. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  6260. {
  6261. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingPower );// PresentChargingPower is 0~6553.5 kW
  6262. }
  6263. }// END for GB_QUANTITY
  6264. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase,PhaseStr[L3_N]);
  6265. }
  6266. else if(gunType[gun_index] == GUN_TYPE_DO)
  6267. {
  6268. tempIndex = gun_index;
  6269. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  6270. {
  6271. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  6272. {
  6273. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PresentChargingPower );// PresentChargingPower is 0~6553.5 kW
  6274. }
  6275. }
  6276. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase,PhaseStr[L3_N]);
  6277. }
  6278. else
  6279. {
  6280. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  6281. {
  6282. tempIndex = 2;
  6283. }
  6284. else
  6285. {
  6286. tempIndex = gun_index;
  6287. }
  6288. for (int index = 0; index < AC_QUANTITY; index++)
  6289. {
  6290. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  6291. {
  6292. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingPower );// PresentChargingPower is 0~6553.5 kW
  6293. }
  6294. } // END for AC_QUANTITY
  6295. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase,PhaseStr[L1_N]);
  6296. }
  6297. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  6298. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Format,ValueFormatStr[Raw]);
  6299. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Measurand,MeasurandStr[Power_Active_Import]);
  6300. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Location,LocationStr[Location_Outlet]);
  6301. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Unit,UnitOfMeasureStr[UnitOfMeasure_kW/*UnitOfMeasure_kWh*/]);
  6302. }
  6303. //============================ Voltage L1 ====================================
  6304. if(strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Voltage") != NULL)
  6305. {
  6306. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  6307. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  6308. {
  6309. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  6310. {
  6311. tempIndex = ((gun_index==2) ? 1: 0);
  6312. }
  6313. else
  6314. {
  6315. tempIndex = gun_index;
  6316. }
  6317. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  6318. {
  6319. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  6320. {
  6321. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargingVoltage );// PresentChargingVoltage is 0~6553.5 volt
  6322. }
  6323. } // END OF FOR CHAdeMO_QUANTITY
  6324. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase,PhaseStr[L3_N]);
  6325. }
  6326. else if(gunType[gun_index] == GUN_TYPE_CCS)
  6327. {
  6328. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  6329. {
  6330. tempIndex = ((gun_index==2) ? 1: 0);
  6331. }
  6332. else
  6333. {
  6334. tempIndex = gun_index;
  6335. }
  6336. for (int index = 0; index < CCS_QUANTITY; index++)
  6337. {
  6338. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  6339. {
  6340. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargingVoltage );// PresentChargingVoltage is 0~6553.5 volt
  6341. }
  6342. } // END OF FOR CCS_QUANTITY
  6343. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase,PhaseStr[L3_N]);
  6344. }
  6345. else if(gunType[gun_index] == GUN_TYPE_GBT)
  6346. {
  6347. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  6348. {
  6349. tempIndex = ((gun_index==2) ? 1: 0);
  6350. }
  6351. else
  6352. {
  6353. tempIndex = gun_index;
  6354. }
  6355. for (int index = 0; index < GB_QUANTITY; index++)
  6356. {
  6357. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  6358. {
  6359. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingVoltage );// PresentChargingVoltage is 0~6553.5 volt
  6360. }
  6361. } // END OF FOR GB_QUANTITY
  6362. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase,PhaseStr[L3_N]);
  6363. }
  6364. else if(gunType[gun_index] == GUN_TYPE_DO)
  6365. {
  6366. tempIndex = gun_index;
  6367. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  6368. {
  6369. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  6370. {
  6371. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PresentChargingVoltage );// PresentChargingVoltage is 0~6553.5 volt
  6372. }
  6373. }
  6374. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase,PhaseStr[L3_N]);
  6375. }
  6376. else
  6377. {
  6378. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  6379. {
  6380. tempIndex = 2;
  6381. }
  6382. else
  6383. {
  6384. tempIndex = gun_index;
  6385. }
  6386. for (int index = 0; index < AC_QUANTITY; index++)
  6387. {
  6388. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  6389. {
  6390. 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
  6391. }
  6392. } // END OF FOR AC_QUANTITY
  6393. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase,PhaseStr[L1_N]);
  6394. }
  6395. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  6396. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Format,ValueFormatStr[Raw]);
  6397. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Measurand,MeasurandStr[Voltage]);
  6398. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Location,LocationStr[Location_Outlet]);
  6399. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Unit,UnitOfMeasureStr[UnitOfMeasure_V]);
  6400. }
  6401. //====================== End SoC ================================
  6402. if(strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, MeasurandStr[SoC]) != NULL)
  6403. {
  6404. //J : CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  6405. 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))
  6406. {
  6407. if((ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0') && (gunType[gun_index] != GUN_TYPE_DO))
  6408. {
  6409. tempIndex = ((gun_index==2) ? 1: 0);
  6410. }
  6411. else
  6412. {
  6413. tempIndex = gun_index;
  6414. }
  6415. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  6416. {
  6417. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  6418. {
  6419. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  6420. {
  6421. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].EvBatterySoc );// 0~100%
  6422. }
  6423. }
  6424. }
  6425. else if(gunType[gun_index] == GUN_TYPE_CCS)
  6426. {
  6427. for (int index = 0; index < CCS_QUANTITY; index++)
  6428. {
  6429. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  6430. {
  6431. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].EvBatterySoc );// 0~100%
  6432. }
  6433. }
  6434. }
  6435. else if(gunType[gun_index] == GUN_TYPE_GBT)
  6436. {
  6437. for (int index = 0; index < GB_QUANTITY; index++)
  6438. {
  6439. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  6440. {
  6441. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].EvBatterySoc );// 0~100%
  6442. }
  6443. }
  6444. }
  6445. else if(gunType[gun_index] == GUN_TYPE_DO)
  6446. {
  6447. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  6448. {
  6449. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  6450. {
  6451. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.EvBatterySoc );// 0~100%
  6452. }
  6453. }
  6454. }
  6455. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  6456. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Format,ValueFormatStr[Raw]);
  6457. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Measurand,MeasurandStr[SoC/*Energy_Reactive_Export_Register*/]);
  6458. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Phase,PhaseStr[L3_N]);
  6459. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Location,LocationStr[Location_EV]);
  6460. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Unit,UnitOfMeasureStr[UnitOfMeasure_Percent/*UnitOfMeasure_kWh*/]);
  6461. } // END FOR DC CASE
  6462. }
  6463. // ================================= Current.Import L2 ===============================================
  6464. if(strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Current.Import") != NULL)
  6465. {
  6466. // AC 3 phse L2 current
  6467. if((gunType[gun_index] == GUN_TYPE_AC) && ((ShmSysConfigAndInfo->SysConfig.ModelName[2]=='Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='W') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='D')))
  6468. {
  6469. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  6470. {
  6471. tempIndex = 2;
  6472. }
  6473. else
  6474. {
  6475. tempIndex = gun_index;
  6476. }
  6477. for (int index = 0; index < AC_QUANTITY; index++)
  6478. {
  6479. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  6480. {
  6481. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingCurrentL2 );// 0~6553.5 amp for EVSE
  6482. }
  6483. }// End of for AC_QUANTITY
  6484. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Phase,PhaseStr[L2_N]);
  6485. }
  6486. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  6487. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Format,ValueFormatStr[Raw]);
  6488. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Measurand,MeasurandStr[Current_Import]);
  6489. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Location,LocationStr[Location_Outlet]);
  6490. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Unit,UnitOfMeasureStr[UnitOfMeasure_A]);
  6491. }
  6492. // ================================= Current.Import L3 ===============================================
  6493. if(strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Current.Import") != NULL)
  6494. {
  6495. // AC 3 phse L3 current
  6496. if((gunType[gun_index] == GUN_TYPE_AC) && ((ShmSysConfigAndInfo->SysConfig.ModelName[2]=='Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='W') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='D')))
  6497. {
  6498. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  6499. {
  6500. tempIndex = 2;
  6501. }
  6502. else
  6503. {
  6504. tempIndex = gun_index;
  6505. }
  6506. for (int index = 0; index < AC_QUANTITY; index++)
  6507. {
  6508. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  6509. {
  6510. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingCurrentL3 );// 0~6553.5 amp for EVSE
  6511. }
  6512. }// End of for AC_QUANTITY
  6513. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Phase,PhaseStr[L3_N]);
  6514. }
  6515. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  6516. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Format,ValueFormatStr[Raw]);
  6517. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Measurand,MeasurandStr[Current_Import]);
  6518. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Location,LocationStr[Location_Outlet]);
  6519. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Unit,UnitOfMeasureStr[UnitOfMeasure_A]);
  6520. }
  6521. //============================ Voltage L2 ====================================
  6522. if(strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Voltage") != NULL)
  6523. {
  6524. // AC 3 phse L2 voltage
  6525. if((gunType[gun_index] == GUN_TYPE_AC) && ((ShmSysConfigAndInfo->SysConfig.ModelName[2]=='Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='W') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='D')))
  6526. {
  6527. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  6528. {
  6529. tempIndex = 2;
  6530. }
  6531. else
  6532. {
  6533. tempIndex = gun_index;
  6534. }
  6535. for (int index = 0; index < AC_QUANTITY; index++)
  6536. {
  6537. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  6538. {
  6539. 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
  6540. }
  6541. } // END OF FOR AC_QUANTITY
  6542. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Phase,PhaseStr[L2_N]);
  6543. }
  6544. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  6545. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Format,ValueFormatStr[Raw]);
  6546. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Measurand,MeasurandStr[Voltage]);
  6547. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Location,LocationStr[Location_Outlet]);
  6548. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Unit,UnitOfMeasureStr[UnitOfMeasure_V]);
  6549. }
  6550. //============================ Voltage L3 ====================================
  6551. if(strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Voltage") != NULL)
  6552. {
  6553. // AC 3 phse L3 voltage
  6554. if((gunType[gun_index] == GUN_TYPE_AC) && ((ShmSysConfigAndInfo->SysConfig.ModelName[2]=='Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='W') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='D')))
  6555. {
  6556. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  6557. {
  6558. tempIndex = 2;
  6559. }
  6560. else
  6561. {
  6562. tempIndex = gun_index;
  6563. }
  6564. for (int index = 0; index < AC_QUANTITY; index++)
  6565. {
  6566. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  6567. {
  6568. 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
  6569. }
  6570. } // END OF FOR AC_QUANTITY
  6571. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Phase,PhaseStr[L3_N]);
  6572. }
  6573. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  6574. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Format,ValueFormatStr[Raw]);
  6575. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Measurand,MeasurandStr[Voltage]);
  6576. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Location,LocationStr[Location_Outlet]);
  6577. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Unit,UnitOfMeasureStr[UnitOfMeasure_V]);
  6578. }
  6579. //====================== Start SoC ================================
  6580. if(strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, MeasurandStr[SoC]) != NULL)
  6581. {
  6582. //J : CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  6583. 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))
  6584. {
  6585. if((ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0') && (gunType[gun_index] != GUN_TYPE_DO))
  6586. {
  6587. tempIndex = ((gun_index==2) ? 1: 0);
  6588. }
  6589. else
  6590. {
  6591. tempIndex = gun_index;
  6592. }
  6593. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  6594. {
  6595. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  6596. {
  6597. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  6598. {
  6599. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].EvBatteryStartSoc );// 0~100%
  6600. }
  6601. }
  6602. }
  6603. else if(gunType[gun_index] == GUN_TYPE_CCS)
  6604. {
  6605. for (int index = 0; index < CCS_QUANTITY; index++)
  6606. {
  6607. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  6608. {
  6609. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].EvBatteryStartSoc );// 0~100%
  6610. }
  6611. }
  6612. }
  6613. else if(gunType[gun_index] == GUN_TYPE_GBT)
  6614. {
  6615. for (int index = 0; index < GB_QUANTITY; index++)
  6616. {
  6617. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  6618. {
  6619. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].EvBatteryStartSoc );// 0~100%
  6620. }
  6621. }
  6622. }
  6623. else if(gunType[gun_index] == GUN_TYPE_DO)
  6624. {
  6625. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  6626. {
  6627. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  6628. {
  6629. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.EvBatteryStartSoc );// 0~100%
  6630. }
  6631. }
  6632. }
  6633. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Context,ReadingContextStr[ReadingContext_Transaction_Begin]);
  6634. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Format,ValueFormatStr[Raw]);
  6635. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Measurand,MeasurandStr[SoC/*Energy_Reactive_Export_Register*/]);
  6636. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Phase,PhaseStr[L3_N]);
  6637. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Location,LocationStr[Location_EV]);
  6638. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Unit,UnitOfMeasureStr[UnitOfMeasure_Percent/*UnitOfMeasure_kWh*/]);
  6639. } // END FOR DC CASE
  6640. }
  6641. //================================================ Message create ====================================================
  6642. json_object *StopTransaction = json_object_new_object();
  6643. json_object *transactionDatas = json_object_new_array();
  6644. json_object *sampledValues = json_object_new_array();
  6645. if(strlen((char*)ShmOCPP16Data->StopTransaction[gun_index].IdTag) > 0)
  6646. json_object_object_add(StopTransaction, "idTag", json_object_new_string((char*)ShmOCPP16Data->StopTransaction[gun_index].IdTag));
  6647. json_object_object_add(StopTransaction, "meterStop", json_object_new_int(ShmOCPP16Data->StopTransaction[gun_index].MeterStop));
  6648. json_object_object_add(StopTransaction, "transactionId", json_object_new_int(ShmOCPP16Data->StopTransaction[gun_index].TransactionId));
  6649. json_object_object_add(StopTransaction, "timestamp", json_object_new_string((char*)ShmOCPP16Data->StopTransaction[gun_index].Timestamp));
  6650. if(strlen((char*)ShmOCPP16Data->StopTransaction[gun_index].StopReason) > 0)
  6651. json_object_object_add(StopTransaction, "reason", json_object_new_string((char*)ShmOCPP16Data->StopTransaction[gun_index].StopReason));
  6652. for(int idxTrans = 0;idxTrans<ARRAY_SIZE(ShmOCPP16Data->StopTransaction[gun_index].TransactionData);idxTrans++)
  6653. {
  6654. json_object *transactionData = json_object_new_object();
  6655. json_object_object_add(transactionData, "timestamp", json_object_new_string((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].TimeStamp));
  6656. for(int idx=0;idx<ARRAY_SIZE(ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue);idx++)
  6657. {
  6658. if(strlen((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Value) > 0)
  6659. {
  6660. json_object *sampledValue = json_object_new_object();
  6661. json_object_object_add(sampledValue, "value", json_object_new_string((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Value));
  6662. if(strlen((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Context) > 0)
  6663. json_object_object_add(sampledValue, "context", json_object_new_string((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Context));
  6664. if(strlen((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Format) > 0)
  6665. json_object_object_add(sampledValue, "format", json_object_new_string((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Format));
  6666. if(strlen((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Measurand) > 0)
  6667. json_object_object_add(sampledValue, "measurand", json_object_new_string((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Measurand));
  6668. if(strlen((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Phase) > 0)
  6669. json_object_object_add(sampledValue, "phase", json_object_new_string((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Phase));
  6670. if(strlen((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Location) > 0)
  6671. json_object_object_add(sampledValue, "location", json_object_new_string((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Location));
  6672. if(strlen((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Unit) > 0)
  6673. json_object_object_add(sampledValue, "unit", json_object_new_string((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Unit));
  6674. json_object_array_add(sampledValues, sampledValue);
  6675. }
  6676. }
  6677. json_object_object_add(transactionData, "sampledValue", sampledValues);
  6678. json_object_array_add(transactionDatas, transactionData);
  6679. }
  6680. json_object_object_add(StopTransaction, "transactionData", transactionDatas);
  6681. sprintf(queuedata, "%d,[%d,\"%s\",\"StopTransaction\",%s]",(gun_index+1)
  6682. ,MESSAGE_TYPE_CALL
  6683. ,guid
  6684. ,json_object_to_json_string_ext(StopTransaction, JSON_C_TO_STRING_PLAIN));
  6685. json_object_put(StopTransaction);
  6686. #if 1 // for TempStopTransaction
  6687. //Delete TempStopTransaction
  6688. if((access(TempStopTransaction,F_OK))!=-1)
  6689. {
  6690. remove(TempStopTransaction); // remove file "TempStopTransaction"
  6691. }
  6692. #endif
  6693. #if 1
  6694. sprintf(tempdata, "StopTransaction,%d", (gun_index));
  6695. if(hashmap_operation(HASH_OP_ADD, guid, tempdata) == 1)
  6696. {
  6697. result = PASS;
  6698. //DEBUG_INFO("StopTransaction mapitem pass\n");
  6699. }
  6700. #endif
  6701. queue_operation(QUEUE_OPERATION_ADD, guid, queuedata );//addq(guid, queuedata); ---> remove temporally
  6702. OCPP_insert_transaction_msg(NO, queuedata);
  6703. //----------------------------replace queue StopTransaction TransactionId ---------------------------//
  6704. //int gettransactionId = GetTransactionId(gun_index+1, ShmOCPP16Data->StopTransaction[gun_index].IdTag);
  6705. int gettransactionId = GetTransactionId(gun_index+1, ShmOCPP16Data->StartTransaction[gun_index].IdTag, TRUE);
  6706. if((ShmOCPP16Data->StopTransaction[gun_index].TransactionId != 0) && (gettransactionId != 0))
  6707. {
  6708. SetTransactionIdZero(ShmOCPP16Data->StopTransaction[gun_index].TransactionId);
  6709. }
  6710. //for test
  6711. //ShmOCPP16Data->CpMsg.bits[gun_index].StopTransactionReq = 0;
  6712. return result;
  6713. }
  6714. int sendMeterValuesRequest(int gun_index, ReadingContext dataType)
  6715. {
  6716. mtrace();
  6717. int result = FAIL;
  6718. char guid[37]={0};
  6719. char tempdata[65]={0};
  6720. int tempIndex = 0;
  6721. DEBUG_INFO("sendMeterValuesRequest ...\n");
  6722. memset(queuedata, 0, ARRAY_SIZE(queuedata));
  6723. memset(&ShmOCPP16Data->MeterValues[gun_index], 0, sizeof(struct StructMeterValues));
  6724. //set value
  6725. ShmOCPP16Data->MeterValues[gun_index].ConnectorId = gun_index + 1; // gun start from 1~
  6726. ShmOCPP16Data->MeterValues[gun_index].TransactionId = (cpinitateMsg.bits[gun_index].isOnCharging?
  6727. ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId :
  6728. -1);
  6729. random_uuid(guid);
  6730. //UTC Date time
  6731. struct timeval tmnow;
  6732. struct tm *tm;
  6733. char buf[28];//, usec_buf[6];
  6734. gettimeofday(&tmnow, NULL);
  6735. time_t t;
  6736. t = time(NULL);
  6737. /*UTC time and date*/
  6738. tm = gmtime(&t);
  6739. if(dataType == ReadingContext_Sample_Clock)
  6740. {
  6741. struct tm *tmTarget;
  6742. struct timeb tbTarget;
  6743. tbTarget.time = mktime(tm);
  6744. tbTarget.time -= (atoi((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemData));
  6745. tmTarget = gmtime(&tbTarget.time);
  6746. strftime(buf,28,"%Y-%m-%dT%H:%M:%SZ", tmTarget);
  6747. }
  6748. else
  6749. {
  6750. strftime(buf,28,"%Y-%m-%dT%H:%M:%SZ", tm);
  6751. }
  6752. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].TimeStamp, buf);
  6753. //DEBUG_INFO("ShmSysConfigAndInfo->SysConfig.ModelName[0]=%c\n", ShmSysConfigAndInfo->SysConfig.ModelName[0]);
  6754. //********************************(1)Current.Import L1************************************************/
  6755. if(((dataType == ReadingContext_Sample_Clock) && (strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, MeasurandStr[Current_Import]) != NULL)) ||
  6756. ((dataType == ReadingContext_Sample_Periodic) && (strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, MeasurandStr[Current_Import]) != NULL)) ||
  6757. (dataType == ReadingContext_Trigger))
  6758. {
  6759. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  6760. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  6761. {
  6762. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  6763. {
  6764. tempIndex = ((gun_index==2) ? 1: 0);
  6765. }
  6766. else
  6767. {
  6768. tempIndex = gun_index;
  6769. }
  6770. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  6771. {
  6772. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  6773. {
  6774. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargingCurrent );
  6775. }
  6776. }
  6777. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Phase, PhaseStr[L3_N]);
  6778. }
  6779. else if(gunType[gun_index] == GUN_TYPE_CCS)
  6780. {
  6781. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  6782. {
  6783. tempIndex = ((gun_index==2) ? 1: 0);
  6784. }
  6785. else
  6786. {
  6787. tempIndex = gun_index;
  6788. }
  6789. for (int index = 0; index < CCS_QUANTITY; index++)
  6790. {
  6791. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  6792. {
  6793. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargingCurrent );
  6794. }
  6795. }
  6796. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Phase, PhaseStr[L3_N]);
  6797. }
  6798. else if(gunType[gun_index] == GUN_TYPE_GBT)
  6799. {
  6800. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  6801. {
  6802. tempIndex = ((gun_index==2) ? 1: 0);
  6803. }
  6804. else
  6805. {
  6806. tempIndex = gun_index;
  6807. }
  6808. for (int index = 0; index < GB_QUANTITY; index++)
  6809. {
  6810. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  6811. {
  6812. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingCurrent );
  6813. }
  6814. }
  6815. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Phase, PhaseStr[L3_N]);
  6816. }
  6817. else if(gunType[gun_index] == GUN_TYPE_DO)
  6818. {
  6819. tempIndex = gun_index;
  6820. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  6821. {
  6822. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  6823. {
  6824. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PresentChargingCurrent );
  6825. }
  6826. }
  6827. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Phase, PhaseStr[L3_N]);
  6828. }
  6829. else
  6830. {
  6831. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  6832. {
  6833. tempIndex = 2;
  6834. }
  6835. else
  6836. {
  6837. tempIndex = gun_index;
  6838. }
  6839. for (int index = 0; index < AC_QUANTITY; index++)
  6840. {
  6841. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  6842. {
  6843. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingCurrent );
  6844. }
  6845. }
  6846. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Phase, PhaseStr[L1_N]);
  6847. }
  6848. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Context, ReadingContextStr[dataType]);
  6849. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Format, ValueFormatStr[Raw]);
  6850. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Measurand, MeasurandStr[Current_Import]);
  6851. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Location, LocationStr[Location_Outlet]);
  6852. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Unit,UnitOfMeasureStr[UnitOfMeasure_A]);
  6853. }
  6854. //********************************(2)Energy.Active.Import.Register ************************************************/
  6855. if(((dataType == ReadingContext_Sample_Clock) && (strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, MeasurandStr[Energy_Active_Import_Register]) != NULL)) ||
  6856. ((dataType == ReadingContext_Sample_Periodic) && (strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, MeasurandStr[Energy_Active_Import_Register]) != NULL)) ||
  6857. (dataType == ReadingContext_Trigger))
  6858. {
  6859. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  6860. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  6861. {
  6862. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  6863. {
  6864. tempIndex = ((gun_index==2) ? 1: 0);
  6865. }
  6866. else
  6867. {
  6868. tempIndex = gun_index;
  6869. }
  6870. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  6871. {
  6872. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  6873. {
  6874. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PowerConsumption );
  6875. }
  6876. }
  6877. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Phase, PhaseStr[L3_N]);
  6878. }
  6879. else if(gunType[gun_index] == GUN_TYPE_CCS)
  6880. {
  6881. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  6882. {
  6883. tempIndex = ((gun_index==2) ? 1: 0);
  6884. }
  6885. else
  6886. {
  6887. tempIndex = gun_index;
  6888. }
  6889. for (int index = 0; index < CCS_QUANTITY; index++)
  6890. {
  6891. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  6892. {
  6893. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PowerConsumption );
  6894. }
  6895. }
  6896. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Phase, PhaseStr[L3_N]);
  6897. }
  6898. else if(gunType[gun_index] == GUN_TYPE_GBT)
  6899. {
  6900. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  6901. {
  6902. tempIndex = ((gun_index==2) ? 1: 0);
  6903. }
  6904. else
  6905. {
  6906. tempIndex = gun_index;
  6907. }
  6908. for (int index = 0; index < GB_QUANTITY; index++)
  6909. {
  6910. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  6911. {
  6912. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PowerConsumption );
  6913. }
  6914. }
  6915. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Phase, PhaseStr[L3_N]);
  6916. }
  6917. else if(gunType[gun_index] == GUN_TYPE_DO)
  6918. {
  6919. tempIndex = gun_index;
  6920. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  6921. {
  6922. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  6923. {
  6924. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PowerConsumption );
  6925. }
  6926. }
  6927. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Phase, PhaseStr[L3_N]);
  6928. }
  6929. else
  6930. {
  6931. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  6932. {
  6933. tempIndex = 2;
  6934. }
  6935. else
  6936. {
  6937. tempIndex = gun_index;
  6938. }
  6939. for (int index = 0; index < AC_QUANTITY; index++)
  6940. {
  6941. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  6942. {
  6943. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PowerConsumption );
  6944. }
  6945. }
  6946. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Phase, PhaseStr[L1_N]);
  6947. }
  6948. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Context, ReadingContextStr[dataType]);
  6949. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Format, ValueFormatStr[Raw]);
  6950. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Measurand, MeasurandStr[Energy_Active_Import_Register]);
  6951. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Location, LocationStr[Location_Outlet]);
  6952. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Unit,UnitOfMeasureStr[UnitOfMeasure_kWh]);
  6953. }
  6954. //****************************************************(3)Energy.Active.Import.Interval*********************************************/
  6955. if(((dataType == ReadingContext_Sample_Clock) && (strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, MeasurandStr[Energy_Active_Import_Interval]) != NULL)) ||
  6956. ((dataType == ReadingContext_Sample_Periodic) && (strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, MeasurandStr[Energy_Active_Import_Interval]) != NULL)) ||
  6957. (dataType == ReadingContext_Trigger))
  6958. {
  6959. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  6960. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  6961. {
  6962. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  6963. {
  6964. tempIndex = ((gun_index==2) ? 1: 0);
  6965. }
  6966. else
  6967. {
  6968. tempIndex = gun_index;
  6969. }
  6970. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  6971. {
  6972. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  6973. {
  6974. if(dataType == ReadingContext_Sample_Clock)
  6975. {
  6976. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Value, "%.3f" ,(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PowerConsumption - periousClockPowerConsumption[gun_index]));
  6977. periousClockPowerConsumption[gun_index] = ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PowerConsumption;
  6978. }
  6979. else if(dataType == ReadingContext_Sample_Periodic)
  6980. {
  6981. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Value, "%.3f" ,(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PowerConsumption - periousPeriodicPowerConsumption[gun_index]));
  6982. periousPeriodicPowerConsumption[gun_index] = ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PowerConsumption;
  6983. }
  6984. else
  6985. {
  6986. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Value, "0.000");
  6987. }
  6988. }
  6989. } // END OF FOR CHAdeMO_QUANTITY
  6990. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Phase, PhaseStr[L3_N]);
  6991. }
  6992. else if(gunType[gun_index] == GUN_TYPE_CCS)
  6993. {
  6994. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  6995. {
  6996. tempIndex = ((gun_index==2) ? 1: 0);
  6997. }
  6998. else
  6999. {
  7000. tempIndex = gun_index;
  7001. }
  7002. for (int index = 0; index < CCS_QUANTITY; index++)
  7003. {
  7004. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  7005. {
  7006. if(dataType == ReadingContext_Sample_Clock)
  7007. {
  7008. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Value, "%.3f" ,(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PowerConsumption - periousClockPowerConsumption[gun_index]));
  7009. periousClockPowerConsumption[gun_index] = ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PowerConsumption;
  7010. }
  7011. else if(dataType == ReadingContext_Sample_Periodic)
  7012. {
  7013. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Value, "%.3f" ,(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PowerConsumption - periousPeriodicPowerConsumption[gun_index]));
  7014. periousPeriodicPowerConsumption[gun_index] = ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PowerConsumption;
  7015. }
  7016. else
  7017. {
  7018. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Value, "0.000");
  7019. }
  7020. }
  7021. } // END OF CCS_QUANTITY
  7022. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Phase, PhaseStr[L3_N]);
  7023. }
  7024. else if(gunType[gun_index] == GUN_TYPE_GBT)
  7025. {
  7026. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  7027. {
  7028. tempIndex = ((gun_index==2) ? 1: 0);
  7029. }
  7030. else
  7031. {
  7032. tempIndex = gun_index;
  7033. }
  7034. for (int index = 0; index < GB_QUANTITY; index++)
  7035. {
  7036. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  7037. {
  7038. if(dataType == ReadingContext_Sample_Clock)
  7039. {
  7040. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Value, "%.3f" ,(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PowerConsumption - periousClockPowerConsumption[gun_index]));
  7041. periousClockPowerConsumption[gun_index] = ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PowerConsumption;
  7042. }
  7043. else if(dataType == ReadingContext_Sample_Periodic)
  7044. {
  7045. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Value, "%.3f" ,(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PowerConsumption - periousPeriodicPowerConsumption[gun_index]));
  7046. periousPeriodicPowerConsumption[gun_index] = ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PowerConsumption;
  7047. }
  7048. else
  7049. {
  7050. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Value, "0.000");
  7051. }
  7052. }
  7053. } // END OF GB_QUANTITY
  7054. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Phase, PhaseStr[L3_N]);
  7055. }
  7056. else if(gunType[gun_index] == GUN_TYPE_DO)
  7057. {
  7058. tempIndex = gun_index;
  7059. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  7060. {
  7061. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  7062. {
  7063. if(dataType == ReadingContext_Sample_Clock)
  7064. {
  7065. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Value, "%.3f" ,(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PowerConsumption - periousClockPowerConsumption[gun_index]));
  7066. periousClockPowerConsumption[gun_index] = ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PowerConsumption;
  7067. }
  7068. else if(dataType == ReadingContext_Sample_Periodic)
  7069. {
  7070. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Value, "%.3f" ,(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PowerConsumption - periousPeriodicPowerConsumption[gun_index]));
  7071. periousPeriodicPowerConsumption[gun_index] = ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PowerConsumption;
  7072. }
  7073. else
  7074. {
  7075. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Value, "0.000");
  7076. }
  7077. }
  7078. }
  7079. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Phase, PhaseStr[L3_N]);
  7080. }
  7081. else
  7082. {
  7083. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  7084. {
  7085. tempIndex = 2;
  7086. }
  7087. else
  7088. {
  7089. tempIndex = gun_index;
  7090. }
  7091. for (int index = 0; index < AC_QUANTITY; index++)
  7092. {
  7093. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  7094. {
  7095. if(dataType == ReadingContext_Sample_Clock)
  7096. {
  7097. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Value, "%.3f" ,(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PowerConsumption - periousClockPowerConsumption[gun_index]));
  7098. periousClockPowerConsumption[gun_index] = ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PowerConsumption;
  7099. }
  7100. else if(dataType == ReadingContext_Sample_Periodic)
  7101. {
  7102. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Value, "%.3f" ,(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PowerConsumption - periousPeriodicPowerConsumption[gun_index]));
  7103. periousPeriodicPowerConsumption[gun_index] = ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PowerConsumption;
  7104. }
  7105. else
  7106. {
  7107. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Value, "0.000");
  7108. }
  7109. }
  7110. }
  7111. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Phase, PhaseStr[L1_N]);
  7112. }
  7113. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Context, ReadingContextStr[dataType]);
  7114. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Format, ValueFormatStr[Raw]);
  7115. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Measurand, MeasurandStr[Energy_Active_Import_Interval]);
  7116. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Location, LocationStr[Location_Outlet]);
  7117. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Unit,UnitOfMeasureStr[UnitOfMeasure_kWh]);
  7118. }
  7119. //********************************(4)Power.Active.Import************************************************/
  7120. if(((dataType == ReadingContext_Sample_Clock) && (strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, MeasurandStr[Power_Active_Import]) != NULL)) ||
  7121. ((dataType == ReadingContext_Sample_Periodic) && (strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, MeasurandStr[Power_Active_Import]) != NULL)) ||
  7122. (dataType == ReadingContext_Trigger))
  7123. {
  7124. //J : CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  7125. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  7126. {
  7127. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  7128. {
  7129. tempIndex = ((gun_index==2) ? 1: 0);
  7130. }
  7131. else
  7132. {
  7133. tempIndex = gun_index;
  7134. }
  7135. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  7136. {
  7137. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  7138. {
  7139. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Value, "%.1f" , ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargingPower);
  7140. }
  7141. } // END OF FOR
  7142. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Phase, PhaseStr[L3_N]);
  7143. }
  7144. else if(gunType[gun_index] == GUN_TYPE_CCS)
  7145. {
  7146. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  7147. {
  7148. tempIndex = ((gun_index==2) ? 1: 0);
  7149. }
  7150. else
  7151. {
  7152. tempIndex = gun_index;
  7153. }
  7154. for (int index = 0; index < CCS_QUANTITY; index++)
  7155. {
  7156. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  7157. {
  7158. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Value, "%.1f" , ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargingPower);
  7159. }
  7160. }
  7161. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Phase, PhaseStr[L3_N]);
  7162. }
  7163. else if(gunType[gun_index] == GUN_TYPE_GBT)
  7164. {
  7165. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  7166. {
  7167. tempIndex = ((gun_index==2) ? 1: 0);
  7168. }
  7169. else
  7170. {
  7171. tempIndex = gun_index;
  7172. }
  7173. for (int index = 0; index < GB_QUANTITY; index++)
  7174. {
  7175. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  7176. {
  7177. //ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingPower = 100.0;
  7178. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Value, "%.1f" , ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingPower);
  7179. }
  7180. }
  7181. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Phase, PhaseStr[L3_N]);
  7182. }
  7183. else if(gunType[gun_index] == GUN_TYPE_DO)
  7184. {
  7185. tempIndex = gun_index;
  7186. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  7187. {
  7188. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  7189. {
  7190. //ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingPower = 100.0;
  7191. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Value, "%.1f" , ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PresentChargingPower);
  7192. }
  7193. }
  7194. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Phase, PhaseStr[L3_N]);
  7195. }
  7196. else
  7197. {
  7198. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  7199. {
  7200. tempIndex = 2;
  7201. }
  7202. else
  7203. {
  7204. tempIndex = gun_index;
  7205. }
  7206. for (int index = 0; index < AC_QUANTITY; index++)
  7207. {
  7208. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  7209. {
  7210. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Value, "%.1f" , ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingPower);
  7211. }
  7212. }
  7213. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Phase, PhaseStr[L1_N]);
  7214. }
  7215. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Context, ReadingContextStr[dataType]);
  7216. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Format, ValueFormatStr[Raw]);
  7217. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Measurand, MeasurandStr[Power_Active_Import]);
  7218. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Location, LocationStr[Location_Outlet]);
  7219. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Unit,UnitOfMeasureStr[UnitOfMeasure_kW]);
  7220. }
  7221. //***********************************************(5)VOLTAGE L1******************************************************/
  7222. if(((dataType == ReadingContext_Sample_Clock) && (strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, MeasurandStr[Voltage]) != NULL)) ||
  7223. ((dataType == ReadingContext_Sample_Periodic) && (strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, MeasurandStr[Voltage]) != NULL)) ||
  7224. (dataType == ReadingContext_Trigger))
  7225. {
  7226. //J : CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  7227. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  7228. {
  7229. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  7230. {
  7231. tempIndex = ((gun_index==2) ? 1: 0);
  7232. }
  7233. else
  7234. {
  7235. tempIndex = gun_index;
  7236. }
  7237. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  7238. {
  7239. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  7240. {
  7241. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargingVoltage );
  7242. }
  7243. }
  7244. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Phase, PhaseStr[L3_N]);
  7245. }
  7246. else if(gunType[gun_index] == GUN_TYPE_CCS)
  7247. {
  7248. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  7249. {
  7250. tempIndex = ((gun_index==2) ? 1: 0);
  7251. }
  7252. else
  7253. {
  7254. tempIndex = gun_index;
  7255. }
  7256. for (int index = 0; index < CCS_QUANTITY; index++)
  7257. {
  7258. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  7259. {
  7260. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargingVoltage );
  7261. }
  7262. }
  7263. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Phase, PhaseStr[L3_N]);
  7264. }
  7265. else if(gunType[gun_index] == GUN_TYPE_GBT)
  7266. {
  7267. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  7268. {
  7269. tempIndex = ((gun_index==2) ? 1: 0);
  7270. }
  7271. else
  7272. {
  7273. tempIndex = gun_index;
  7274. }
  7275. for (int index = 0; index < GB_QUANTITY; index++)
  7276. {
  7277. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  7278. {
  7279. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingVoltage );
  7280. }
  7281. }
  7282. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Phase, PhaseStr[L3_N]);
  7283. }
  7284. else if(gunType[gun_index] == GUN_TYPE_DO)
  7285. {
  7286. tempIndex = gun_index;
  7287. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  7288. {
  7289. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  7290. {
  7291. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PresentChargingVoltage );
  7292. }
  7293. }
  7294. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Phase, PhaseStr[L3_N]);
  7295. }
  7296. else
  7297. {
  7298. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  7299. {
  7300. tempIndex = 2;
  7301. }
  7302. else
  7303. {
  7304. tempIndex = gun_index;
  7305. }
  7306. for (int index = 0; index < AC_QUANTITY; index++)
  7307. {
  7308. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  7309. {
  7310. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingVoltage );
  7311. }
  7312. }
  7313. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Phase, PhaseStr[L1_N]);
  7314. }
  7315. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Context, ReadingContextStr[dataType]);
  7316. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Format, ValueFormatStr[Raw]);
  7317. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Measurand, MeasurandStr[Voltage]);
  7318. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Location, LocationStr[Location_Outlet]);
  7319. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Unit,UnitOfMeasureStr[UnitOfMeasure_V]);
  7320. }
  7321. //***********************************************(6)SOC******************************************************/
  7322. if(((dataType == ReadingContext_Sample_Clock) && (strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, MeasurandStr[SoC]) != NULL)) ||
  7323. ((dataType == ReadingContext_Sample_Periodic) && (strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, MeasurandStr[SoC]) != NULL)) ||
  7324. (dataType == ReadingContext_Trigger))
  7325. {
  7326. 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))
  7327. {
  7328. //idx_sample=5;
  7329. //sampledValue = NULL;
  7330. if((ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0') && (gunType[gun_index] != GUN_TYPE_DO))
  7331. {
  7332. tempIndex = ((gun_index==2) ? 1: 0);
  7333. }
  7334. else
  7335. {
  7336. tempIndex = gun_index;
  7337. }
  7338. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  7339. {
  7340. //tempIndex = ((gun_index==2) ? 1: 0);
  7341. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  7342. {
  7343. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  7344. {
  7345. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].EvBatterySoc );
  7346. }
  7347. }
  7348. }
  7349. else if(gunType[gun_index] == GUN_TYPE_CCS)
  7350. {
  7351. //tempIndex = ((gun_index==2) ? 1: 0);
  7352. for (int index = 0; index < CCS_QUANTITY; index++)
  7353. {
  7354. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  7355. {
  7356. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].EvBatterySoc );
  7357. }
  7358. }
  7359. }
  7360. else if(gunType[gun_index] == GUN_TYPE_GBT)
  7361. {
  7362. //tempIndex = ((gun_index==2) ? 1: 0);
  7363. for (int index = 0; index < GB_QUANTITY; index++)
  7364. {
  7365. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  7366. {
  7367. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].EvBatterySoc );
  7368. }
  7369. }
  7370. }
  7371. else if(gunType[gun_index] == GUN_TYPE_DO)
  7372. {
  7373. //tempIndex = ((gun_index==2) ? 1: 0);
  7374. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  7375. {
  7376. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  7377. {
  7378. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.EvBatterySoc );
  7379. }
  7380. }
  7381. }
  7382. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[5].Context, ReadingContextStr[dataType]);
  7383. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[5].Format, ValueFormatStr[Raw]);
  7384. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[5].Measurand, MeasurandStr[SoC]);
  7385. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[5].Phase, PhaseStr[L3_N]);
  7386. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[5].Location, LocationStr[Location_EV]);
  7387. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[5].Unit,UnitOfMeasureStr[UnitOfMeasure_Percent]);
  7388. }
  7389. }
  7390. //********************************(7)Current.Import L2************************************************/
  7391. if(((dataType == ReadingContext_Sample_Clock) && (strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, MeasurandStr[Current_Import]) != NULL)) ||
  7392. ((dataType == ReadingContext_Sample_Periodic) && (strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, MeasurandStr[Current_Import]) != NULL)) ||
  7393. (dataType == ReadingContext_Trigger))
  7394. {
  7395. // Only for AC 3 phase
  7396. if((gunType[gun_index] == GUN_TYPE_AC) && ((ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'W') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='D')))
  7397. {
  7398. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  7399. {
  7400. tempIndex = 2;
  7401. }
  7402. else
  7403. {
  7404. tempIndex = gun_index;
  7405. }
  7406. for (int index = 0; index < AC_QUANTITY; index++)
  7407. {
  7408. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  7409. {
  7410. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[6].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingCurrentL2);
  7411. }
  7412. }
  7413. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[6].Phase, PhaseStr[L2_N]);
  7414. }
  7415. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[6].Context, ReadingContextStr[dataType]);
  7416. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[6].Format, ValueFormatStr[Raw]);
  7417. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[6].Measurand, MeasurandStr[Current_Import]);
  7418. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[6].Location, LocationStr[Location_Outlet]);
  7419. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[6].Unit,UnitOfMeasureStr[UnitOfMeasure_A]);
  7420. }
  7421. //********************************(8)Current.Import L3************************************************/
  7422. if(((dataType == ReadingContext_Sample_Clock) && (strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, MeasurandStr[Current_Import]) != NULL)) ||
  7423. ((dataType == ReadingContext_Sample_Periodic) && (strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, MeasurandStr[Current_Import]) != NULL)) ||
  7424. (dataType == ReadingContext_Trigger))
  7425. {
  7426. // Only for AC 3 phase
  7427. if((gunType[gun_index] == GUN_TYPE_AC) && ((ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'W') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='D')))
  7428. {
  7429. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  7430. {
  7431. tempIndex = 2;
  7432. }
  7433. else
  7434. {
  7435. tempIndex = gun_index;
  7436. }
  7437. for (int index = 0; index < AC_QUANTITY; index++)
  7438. {
  7439. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  7440. {
  7441. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[7].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingCurrentL3);
  7442. }
  7443. }
  7444. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[7].Phase, PhaseStr[L3_N]);
  7445. }
  7446. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[7].Context, ReadingContextStr[dataType]);
  7447. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[7].Format, ValueFormatStr[Raw]);
  7448. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[7].Measurand, MeasurandStr[Current_Import]);
  7449. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[7].Location, LocationStr[Location_Outlet]);
  7450. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[7].Unit,UnitOfMeasureStr[UnitOfMeasure_A]);
  7451. }
  7452. //***********************************************(9)VOLTAGE L2******************************************************/
  7453. if(((dataType == ReadingContext_Sample_Clock) && (strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, MeasurandStr[Voltage]) != NULL)) ||
  7454. ((dataType == ReadingContext_Sample_Periodic) && (strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, MeasurandStr[Voltage]) != NULL)) ||
  7455. (dataType == ReadingContext_Trigger))
  7456. {
  7457. if((gunType[gun_index] == GUN_TYPE_AC) && ((ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'W') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='D')))
  7458. {
  7459. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  7460. {
  7461. tempIndex = 2;
  7462. }
  7463. else
  7464. {
  7465. tempIndex = gun_index;
  7466. }
  7467. for (int index = 0; index < AC_QUANTITY; index++)
  7468. {
  7469. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  7470. {
  7471. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[8].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingVoltageL2);
  7472. }
  7473. }
  7474. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[8].Phase, PhaseStr[L2_N]);
  7475. }
  7476. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[8].Context, ReadingContextStr[dataType]);
  7477. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[8].Format, ValueFormatStr[Raw]);
  7478. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[8].Measurand, MeasurandStr[Voltage]);
  7479. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[8].Location, LocationStr[Location_Outlet]);
  7480. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[8].Unit,UnitOfMeasureStr[UnitOfMeasure_V]);
  7481. }
  7482. //***********************************************(10)VOLTAGE L3******************************************************/
  7483. if(((dataType == ReadingContext_Sample_Clock) && (strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, MeasurandStr[Voltage]) != NULL)) ||
  7484. ((dataType == ReadingContext_Sample_Periodic) && (strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, MeasurandStr[Voltage]) != NULL)) ||
  7485. (dataType == ReadingContext_Trigger))
  7486. {
  7487. if((gunType[gun_index] == GUN_TYPE_AC) && ((ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'W') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='D')))
  7488. {
  7489. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  7490. {
  7491. tempIndex = 2;
  7492. }
  7493. else
  7494. {
  7495. tempIndex = gun_index;
  7496. }
  7497. for (int index = 0; index < AC_QUANTITY; index++)
  7498. {
  7499. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  7500. {
  7501. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[9].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingVoltageL3);
  7502. }
  7503. }
  7504. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[9].Phase, PhaseStr[L3_N]);
  7505. }
  7506. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[9].Context, ReadingContextStr[dataType]);
  7507. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[9].Format, ValueFormatStr[Raw]);
  7508. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[9].Measurand, MeasurandStr[Voltage]);
  7509. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[9].Location, LocationStr[Location_Outlet]);
  7510. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[9].Unit,UnitOfMeasureStr[UnitOfMeasure_V]);
  7511. }
  7512. //***********************************************(11)Current.Offered******************************************************/
  7513. if(((dataType == ReadingContext_Sample_Clock) && (strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, MeasurandStr[Current_Offered]) != NULL)) ||
  7514. ((dataType == ReadingContext_Sample_Periodic) && (strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, MeasurandStr[Current_Offered]) != NULL)) ||
  7515. (dataType == ReadingContext_Trigger))
  7516. {
  7517. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  7518. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  7519. {
  7520. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  7521. {
  7522. tempIndex = ((gun_index==2) ? 1: 0);
  7523. }
  7524. else
  7525. {
  7526. tempIndex = gun_index;
  7527. }
  7528. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  7529. {
  7530. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  7531. {
  7532. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[10].Value, "%d", (uint16_t) (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].CurrentOffered/10));
  7533. }
  7534. } // END OF FOR CHAdeMO_QUANTITY
  7535. }
  7536. else if(gunType[gun_index] == GUN_TYPE_CCS)
  7537. {
  7538. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  7539. {
  7540. tempIndex = ((gun_index==2) ? 1: 0);
  7541. }
  7542. else
  7543. {
  7544. tempIndex = gun_index;
  7545. }
  7546. for (int index = 0; index < CCS_QUANTITY; index++)
  7547. {
  7548. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  7549. {
  7550. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[10].Value, "%d", (uint16_t) (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].CurrentOffered/10));
  7551. }
  7552. } // END OF CCS_QUANTITY
  7553. }
  7554. else if(gunType[gun_index] == GUN_TYPE_GBT)
  7555. {
  7556. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  7557. {
  7558. tempIndex = ((gun_index==2) ? 1: 0);
  7559. }
  7560. else
  7561. {
  7562. tempIndex = gun_index;
  7563. }
  7564. for (int index = 0; index < GB_QUANTITY; index++)
  7565. {
  7566. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  7567. {
  7568. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[10].Value, "%d", (uint16_t) (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].CurrentOffered/10));
  7569. }
  7570. } // END OF GB_QUANTITY
  7571. }
  7572. else if(gunType[gun_index] == GUN_TYPE_DO)
  7573. {
  7574. tempIndex = gun_index;
  7575. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  7576. {
  7577. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  7578. {
  7579. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[10].Value, "%d", (uint16_t) (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.CurrentOffered/10));
  7580. }
  7581. }
  7582. }
  7583. else
  7584. {
  7585. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  7586. {
  7587. tempIndex = 2;
  7588. }
  7589. else
  7590. {
  7591. tempIndex = gun_index;
  7592. }
  7593. for (int index = 0; index < AC_QUANTITY; index++)
  7594. {
  7595. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  7596. {
  7597. uint16_t currentOffer;
  7598. if(ShmSysConfigAndInfo->SysConfig.MaxChargingCurrent == 0)
  7599. {
  7600. currentOffer = ShmSysConfigAndInfo->SysConfig.RatingCurrent;
  7601. }
  7602. else
  7603. {
  7604. currentOffer = ((ShmSysConfigAndInfo->SysConfig.MaxChargingCurrent>ShmSysConfigAndInfo->SysConfig.RatingCurrent)?ShmSysConfigAndInfo->SysConfig.RatingCurrent:ShmSysConfigAndInfo->SysConfig.MaxChargingCurrent);
  7605. }
  7606. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[10].Value, "%d", currentOffer);
  7607. }
  7608. }
  7609. }
  7610. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[10].Context, ReadingContextStr[dataType]);
  7611. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[10].Format, ValueFormatStr[Raw]);
  7612. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[10].Measurand, MeasurandStr[Current_Offered]);
  7613. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[10].Location, LocationStr[Location_Outlet]);
  7614. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[10].Unit,UnitOfMeasureStr[UnitOfMeasure_A]);
  7615. }
  7616. //***********************************************(12)Power.Offered******************************************************/
  7617. if(((dataType == ReadingContext_Sample_Clock) && (strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, MeasurandStr[Power_Offered]) != NULL) && (gunType[gun_index] != GUN_TYPE_AC)) ||
  7618. ((dataType == ReadingContext_Sample_Periodic) && (strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, MeasurandStr[Power_Offered]) != NULL) && (gunType[gun_index] != GUN_TYPE_AC)) ||
  7619. ((dataType == ReadingContext_Trigger) && (gunType[gun_index] != GUN_TYPE_AC)))
  7620. {
  7621. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  7622. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  7623. {
  7624. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  7625. {
  7626. tempIndex = ((gun_index==2) ? 1: 0);
  7627. }
  7628. else
  7629. {
  7630. tempIndex = gun_index;
  7631. }
  7632. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  7633. {
  7634. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  7635. {
  7636. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[11].Value, "%d", (uint32_t) (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PowerOffered*100));
  7637. }
  7638. } // END OF FOR CHAdeMO_QUANTITY
  7639. }
  7640. else if(gunType[gun_index] == GUN_TYPE_CCS)
  7641. {
  7642. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  7643. {
  7644. tempIndex = ((gun_index==2) ? 1: 0);
  7645. }
  7646. else
  7647. {
  7648. tempIndex = gun_index;
  7649. }
  7650. for (int index = 0; index < CCS_QUANTITY; index++)
  7651. {
  7652. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  7653. {
  7654. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[11].Value, "%d", (uint32_t) (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PowerOffered*100));
  7655. }
  7656. } // END OF CCS_QUANTITY
  7657. }
  7658. else if(gunType[gun_index] == GUN_TYPE_GBT)
  7659. {
  7660. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  7661. {
  7662. tempIndex = ((gun_index==2) ? 1: 0);
  7663. }
  7664. else
  7665. {
  7666. tempIndex = gun_index;
  7667. }
  7668. for (int index = 0; index < GB_QUANTITY; index++)
  7669. {
  7670. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  7671. {
  7672. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[11].Value, "%d", (uint32_t) (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PowerOffered*100));
  7673. }
  7674. } // END OF GB_QUANTITY
  7675. }
  7676. else if(gunType[gun_index] == GUN_TYPE_DO)
  7677. {
  7678. tempIndex = gun_index;
  7679. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  7680. {
  7681. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  7682. {
  7683. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[11].Value, "%d", (uint32_t) (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PowerOffered*100));
  7684. }
  7685. }
  7686. }
  7687. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[11].Context, ReadingContextStr[dataType]);
  7688. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[11].Format, ValueFormatStr[Raw]);
  7689. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[11].Measurand, MeasurandStr[Power_Offered]);
  7690. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[11].Location, LocationStr[Location_Outlet]);
  7691. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[11].Unit,UnitOfMeasureStr[UnitOfMeasure_W]);
  7692. }
  7693. // Message create ====================================================================================================
  7694. if(TRUE)
  7695. {
  7696. json_object *MeterValueReq = json_object_new_object();
  7697. json_object *MeterValues = json_object_new_array();
  7698. json_object *sampledValues = json_object_new_array();
  7699. json_object_object_add(MeterValueReq, "connectorId", json_object_new_int(ShmOCPP16Data->MeterValues[gun_index].ConnectorId));
  7700. if(ShmOCPP16Data->MeterValues[gun_index].TransactionId != -1)
  7701. json_object_object_add(MeterValueReq, "transactionId", json_object_new_int(ShmOCPP16Data->MeterValues[gun_index].TransactionId));
  7702. for(uint8_t idxMeter=0;idxMeter<ARRAY_SIZE(ShmOCPP16Data->MeterValues[gun_index].MeterValue);idxMeter++)
  7703. {
  7704. json_object *MeterValue = json_object_new_object();
  7705. for(int idxSample=0;idxSample<ARRAY_SIZE(ShmOCPP16Data->MeterValues[gun_index].MeterValue[idxMeter].SampledValue);idxSample++)
  7706. {
  7707. if(strlen((char*)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Value) > 0)
  7708. {
  7709. json_object *sampledValue = json_object_new_object();
  7710. json_object_object_add(sampledValue, "value", json_object_new_string((char*)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Value));
  7711. if(strlen((char*)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Context) > 0)
  7712. json_object_object_add(sampledValue, "context", json_object_new_string((char*)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Context));
  7713. if(strlen((char*)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Format) > 0)
  7714. json_object_object_add(sampledValue, "format", json_object_new_string((char*)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Format));
  7715. if(strlen((char*)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Measurand) > 0)
  7716. json_object_object_add(sampledValue, "measurand", json_object_new_string((char*)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Measurand));
  7717. if(strlen((char*)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Phase) > 0)
  7718. json_object_object_add(sampledValue, "phase", json_object_new_string((char*)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Phase));
  7719. if(strlen((char*)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Location) > 0)
  7720. json_object_object_add(sampledValue, "location", json_object_new_string((char*)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Location));
  7721. if(strlen((char*)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Unit) > 0)
  7722. json_object_object_add(sampledValue, "unit", json_object_new_string((char*)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Unit));
  7723. json_object_array_add(sampledValues, sampledValue);
  7724. }
  7725. }
  7726. json_object_object_add(MeterValue, "timestamp", json_object_new_string((char*)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idxMeter].TimeStamp));
  7727. json_object_object_add(MeterValue, "sampledValue", sampledValues);
  7728. json_object_array_add(MeterValues, MeterValue);
  7729. }
  7730. json_object_object_add(MeterValueReq, "meterValue", MeterValues);
  7731. sprintf(queuedata,"%d,[%d,\"%s\",\"MeterValues\",%s]"
  7732. ,gun_index + 1
  7733. ,MESSAGE_TYPE_CALL
  7734. ,guid
  7735. ,json_object_to_json_string_ext(MeterValueReq, JSON_C_TO_STRING_PLAIN));
  7736. json_object_put(MeterValueReq);
  7737. }
  7738. // Put request guid to hash map
  7739. sprintf(tempdata, "MeterValues,%d", (gun_index));
  7740. 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*/)
  7741. {
  7742. result = PASS;
  7743. //DEBUG_INFO("MeterValues mapitem pass\n");
  7744. }
  7745. if((dataType != ReadingContext_Trigger) &&
  7746. (dataType != ReadingContext_Sample_Clock) &&
  7747. ((ShmOCPP16Data->MeterValues[gun_index].TransactionId > 0) || (strstr((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[QueueOffLineMeterValues].ItemData, "TRUE"))))
  7748. queue_operation(QUEUE_OPERATION_ADD, guid, queuedata );
  7749. else
  7750. {
  7751. if(FirstHeartBeat)
  7752. LWS_Send(queuedata +2);
  7753. }
  7754. return result;
  7755. }
  7756. int sendLogStatusNotificationRequest(char *status)
  7757. {
  7758. mtrace();
  7759. int result = PASS;
  7760. char message[4096]={0};
  7761. char guid[37]={0};
  7762. char tempdata[128]={0};
  7763. json_object *LogStatusNotification = json_object_new_object();
  7764. DEBUG_INFO("sendLogStatusNotificationRequest...\n");
  7765. ShmOCPP16Data->LogStatusNotification.requestId = ShmOCPP16Data->GetLog.requestId;
  7766. sprintf((char *)ShmOCPP16Data->LogStatusNotification.status,"%s",(const char *)status);
  7767. json_object_object_add(LogStatusNotification, "status", json_object_new_string((char*)ShmOCPP16Data->LogStatusNotification.status));
  7768. json_object_object_add(LogStatusNotification, "requestId", json_object_new_int(ShmOCPP16Data->LogStatusNotification.requestId));
  7769. random_uuid(guid);
  7770. sprintf(message,"[%d,\"%s\",\"LogStatusNotification\",%s]",MESSAGE_TYPE_CALL, guid, json_object_to_json_string_ext(LogStatusNotification, JSON_C_TO_STRING_PLAIN));
  7771. json_object_put(LogStatusNotification);
  7772. LWS_Send(message);
  7773. sprintf(tempdata, "LogStatusNotification,%d", 0);
  7774. if(hashmap_operation(HASH_OP_ADD, guid, tempdata) == PASS)
  7775. {
  7776. result = PASS;
  7777. }
  7778. ShmOCPP16Data->SpMsg.bits.LogStatusNotificationReq = 0;
  7779. ShmOCPP16Data->SpMsg.bits.LogStatusNotificationConf = 0;
  7780. return result;
  7781. }
  7782. int sendSecurityEventNotificationRequest()
  7783. {
  7784. mtrace();
  7785. int result = PASS;
  7786. char message[4096]={0};
  7787. char guid[37]={0};
  7788. char tempdata[128]={0};
  7789. json_object *SecurityEventNotification = json_object_new_object();
  7790. DEBUG_INFO("sendSecurityEventNotificationRequest...\n");
  7791. json_object_object_add(SecurityEventNotification, "type", json_object_new_string((char*)ShmOCPP16Data->SecurityEventNotification.type));
  7792. json_object_object_add(SecurityEventNotification, "timestamp", json_object_new_string((char*)ShmOCPP16Data->SecurityEventNotification.timestamp));
  7793. json_object_object_add(SecurityEventNotification, "techInfo", json_object_new_string((char*)ShmOCPP16Data->SecurityEventNotification.techInfo));
  7794. random_uuid(guid);
  7795. sprintf(message,"[%d,\"%s\",\"%s\",%s]",MESSAGE_TYPE_CALL, guid, "SecurityEventNotification", json_object_to_json_string_ext(SecurityEventNotification, JSON_C_TO_STRING_PLAIN));
  7796. json_object_put(SecurityEventNotification);
  7797. LWS_Send(message);
  7798. sprintf(tempdata, "SecurityEventNotification,0");
  7799. if(hashmap_operation(HASH_OP_ADD, guid, tempdata) == PASS)
  7800. {
  7801. result = PASS;
  7802. }
  7803. ShmOCPP16Data->SpMsg.bits.SecurityEventNotificationReq = 0;
  7804. ShmOCPP16Data->SpMsg.bits.SecurityEventNotificationConf = 0;
  7805. return result;
  7806. }
  7807. int sendSignCertificateRequest()
  7808. {
  7809. mtrace();
  7810. int result = PASS;
  7811. char message[4096]={0};
  7812. char guid[37]={0};
  7813. char tempdata[128]={0};
  7814. json_object *SignCertificate = json_object_new_object();
  7815. DEBUG_INFO("sendSignCertificateRequest...\n");
  7816. // Read csr file content
  7817. memset(ShmOCPP16Data->SignCertificate.csr, 0x00, ARRAY_SIZE(ShmOCPP16Data->SignCertificate.csr));
  7818. FILE *fp=fopen("/Storage/OCPP/certCP.csr","r");
  7819. char *line = NULL;
  7820. size_t len = 0;
  7821. while(getline(&line, &len, fp) != -1)
  7822. {
  7823. if((strstr(line, "BEGIN CERTIFICATE REQUEST") == NULL) && (strstr(line, "END CERTIFICATE REQUEST") == NULL))
  7824. {
  7825. memcpy(&ShmOCPP16Data->SignCertificate.csr[strlen((char*)ShmOCPP16Data->SignCertificate.csr)], line, (strlen(line)-1));
  7826. }
  7827. }
  7828. fclose(fp);
  7829. json_object_object_add(SignCertificate, "csr", json_object_new_string((char*)ShmOCPP16Data->SignCertificate.csr));
  7830. random_uuid(guid);
  7831. sprintf(message,"[%d,\"%s\",\"%s\",%s]",MESSAGE_TYPE_CALL, guid, "SignCertificate", json_object_to_json_string_ext(SignCertificate, JSON_C_TO_STRING_PLAIN));
  7832. json_object_put(SignCertificate);
  7833. LWS_Send(message);
  7834. sprintf(tempdata, "SignCertificate,0");
  7835. if(hashmap_operation(HASH_OP_ADD, guid, tempdata) == PASS)
  7836. {
  7837. result = PASS;
  7838. }
  7839. ShmOCPP16Data->SpMsg.bits.SignCertificateReq = 0;
  7840. ShmOCPP16Data->SpMsg.bits.SignCertificateConf = 0;
  7841. return result;
  7842. }
  7843. int sendSignedFirmwareStatusNotificationRequest(char *status)
  7844. {
  7845. mtrace();
  7846. int result = PASS;
  7847. char message[110]={0};
  7848. char guid[37]={0};
  7849. char tempdata[65]={0};
  7850. json_object *FirmwareStatusNotification = json_object_new_object();
  7851. DEBUG_INFO("sendSignedFirmwareStatusNotificationRequest...\n");
  7852. sprintf((char *)ShmOCPP16Data->SignedFirmwareStatusNotification.status , "%s", (const char *)status);
  7853. ShmOCPP16Data->SignedFirmwareStatusNotification.requestId = ShmOCPP16Data->SignedUpdateFirmware.requestId;
  7854. json_object_object_add(FirmwareStatusNotification, "status", json_object_new_string((char*)ShmOCPP16Data->SignedFirmwareStatusNotification.status));
  7855. json_object_object_add(FirmwareStatusNotification, "requestId", json_object_new_int(ShmOCPP16Data->SignedFirmwareStatusNotification.requestId));
  7856. random_uuid(guid);
  7857. sprintf(message,"[%d,\"%s\",\"FirmwareStatusNotification\",%s]",MESSAGE_TYPE_CALL, guid, json_object_to_json_string_ext(FirmwareStatusNotification, JSON_C_TO_STRING_PLAIN));
  7858. json_object_put(FirmwareStatusNotification);
  7859. LWS_Send(message);
  7860. sprintf(tempdata, "FirmwareStatusNotification,%d", 0);
  7861. if(hashmap_operation(HASH_OP_ADD, guid, tempdata) == PASS)
  7862. {
  7863. result = PASS;
  7864. }
  7865. ShmOCPP16Data->SpMsg.bits.SignedFirmwareStatusNotificationReq = 0;
  7866. ShmOCPP16Data->SpMsg.bits.SignedFirmwareStatusNotificationConf = 0;
  7867. return result;
  7868. }
  7869. //==========================================
  7870. // send confirm routine
  7871. //==========================================
  7872. int sendCancelReservationConfirmation(char *uuid,char *payload)
  7873. {
  7874. mtrace();
  7875. int result = FAIL;
  7876. char message[100]={0};
  7877. DEBUG_INFO("sendCancelReservationConfirmation...\n");
  7878. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT,uuid, payload);
  7879. LWS_Send(message);
  7880. result = TRUE;
  7881. return result;
  7882. }
  7883. int sendChangeAvailabilityConfirmation(char *uuid,char *payload)
  7884. {
  7885. mtrace();
  7886. int result = FAIL;
  7887. char message[100]={0};
  7888. DEBUG_INFO("sendChangeAvailabilityConfirmation...\n");
  7889. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT,uuid, payload);
  7890. LWS_Send(message);
  7891. result = TRUE;
  7892. return result;
  7893. }
  7894. int sendChangeConfigurationConfirmation(char *uuid,char *payload)
  7895. {
  7896. mtrace();
  7897. int result = FAIL;
  7898. char message[100]={0};
  7899. DEBUG_INFO("sendChangeConfigurationConfirmation...\n");
  7900. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT,uuid, payload);
  7901. LWS_Send(message);
  7902. result = TRUE;
  7903. return result;
  7904. }
  7905. int sendClearCacheConfirmation(char *uuid,char *payload)
  7906. {
  7907. mtrace();
  7908. int result = FAIL;
  7909. char message[500]={0};
  7910. DEBUG_INFO("sendClearCacheConfirmation...\n");
  7911. sprintf(message,"[%d,\"%s\",{\"%s\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, "status", payload);
  7912. LWS_Send(message);
  7913. return result;
  7914. }
  7915. int sendClearChargingProfileConfirmation(char *uuid,char *payload)
  7916. {
  7917. mtrace();
  7918. int result = FAIL;
  7919. char message[500]={0};
  7920. DEBUG_INFO("sendClearChargingProfileConfirmation...\n");
  7921. sprintf(message,"[%d,\"%s\",{\"%s\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, "status", payload);
  7922. LWS_Send(message);
  7923. return result;
  7924. }
  7925. int sendDataTransferConfirmation(char *uuid,char *payload)
  7926. {
  7927. mtrace();
  7928. char statusStr[20]={0};
  7929. char dataStr[10]={0};
  7930. char sstr[20]={0};
  7931. int c = 0;
  7932. char *loc;
  7933. int result = FAIL;
  7934. DEBUG_INFO("sendDataTransferConfirmation...\n");
  7935. /**********************status**************************/
  7936. loc = strstr(payload, "status");
  7937. memset(sstr ,0, ARRAY_SIZE(sstr) );
  7938. c = 0;
  7939. while (loc[3+strlen("status")+c] != '\"')
  7940. {
  7941. sstr[c] = loc[3+strlen("status")+c];
  7942. c++;
  7943. }
  7944. sstr[c] = '\0';
  7945. strcpy(statusStr, sstr);
  7946. /**********************data**************************/
  7947. loc = strstr(payload, "data");
  7948. memset(sstr ,0, ARRAY_SIZE(sstr) );
  7949. c = 0;
  7950. while (loc[3+strlen("data")+c] != '\"')
  7951. {
  7952. sstr[c] = loc[3+strlen("data")+c];
  7953. c++;
  7954. }
  7955. sstr[c] = '\0';
  7956. strcpy(dataStr, sstr);
  7957. return result;
  7958. }
  7959. int sendGetCompositeScheduleConfirmation(char *uuid, char *payload, int connectorIdInt, int nPeriod)
  7960. {
  7961. mtrace();
  7962. int result = FAIL;
  7963. char message[1000]={0};
  7964. int CompositeScheduleIndex = 0;
  7965. DEBUG_INFO("sendGetCompositeScheduleConfirmation...\n");
  7966. CompositeScheduleIndex = (connectorIdInt > 0) ?(connectorIdInt -1) : 0;
  7967. if(nPeriod == 0)
  7968. {
  7969. if(strcmp((const char *)ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.StartSchedule,"")==0)
  7970. {
  7971. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\",\"connectorId\":%d}]"
  7972. ,MESSAGE_TYPE_CALLRESULT
  7973. ,uuid
  7974. ,payload
  7975. ,connectorIdInt);
  7976. }
  7977. else
  7978. {
  7979. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\",\"connectorId\":%d,\"scheduleStart\":\"%s\",\"chargingSchedule\":{\"duration\":%d,\"startSchedule\":\"%s\",\"chargingRateUnit\":\"%s\",\"chargingSchedulePeriod\":[{\"startPeriod\":0,\"limit\":%d}]}}]"
  7980. ,MESSAGE_TYPE_CALLRESULT
  7981. ,uuid
  7982. ,payload
  7983. ,connectorIdInt
  7984. ,ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.StartSchedule
  7985. ,ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.Duration
  7986. ,ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.StartSchedule
  7987. ,ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.ChargingRateUnit
  7988. ,ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.ChargingRateUnit[0]=='W'?modelnameInfo.ratedPower:(ShmSysConfigAndInfo->SysConfig.MaxChargingCurrent==0?ShmSysConfigAndInfo->SysConfig.RatingCurrent:ShmSysConfigAndInfo->SysConfig.MaxChargingCurrent));
  7989. }
  7990. }
  7991. else
  7992. {
  7993. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\",\"connectorId\":%d,\"scheduleStart\":\"%s\",\"chargingSchedule\":{\"duration\":%d,\"startSchedule\":\"%s\",\"chargingRateUnit\":\"%s\",\"chargingSchedulePeriod\":["
  7994. ,MESSAGE_TYPE_CALLRESULT
  7995. ,uuid
  7996. ,payload
  7997. ,connectorIdInt
  7998. ,ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.StartSchedule
  7999. ,ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.Duration
  8000. ,ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.StartSchedule
  8001. ,ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.ChargingRateUnit);
  8002. for(int idx_sample=0;idx_sample< nPeriod;idx_sample++)
  8003. {
  8004. if (idx_sample == 0)
  8005. {
  8006. sprintf(message + strlen(message), "{\"startPeriod\":%d,\"limit\":%.1f,\"numberPhases\":%d}"
  8007. , ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[idx_sample].StartPeriod
  8008. , ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[idx_sample].Limit
  8009. , ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[idx_sample].NumberPhases );
  8010. }
  8011. else
  8012. {
  8013. sprintf(message + strlen(message), ",{\"startPeriod\":%d,\"limit\":%.1f,\"numberPhases\":%d}"
  8014. , ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[idx_sample].StartPeriod
  8015. , ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[idx_sample].Limit
  8016. , ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[idx_sample].NumberPhases );
  8017. }
  8018. }
  8019. sprintf(message + strlen(message), "]}}]");
  8020. }
  8021. LWS_Send(message);
  8022. result = TRUE;
  8023. return result;
  8024. }
  8025. int sendGetConfigurationConfirmation(char *uuid)
  8026. {
  8027. mtrace();
  8028. int result = FAIL;
  8029. int MaxKeySupported = 0;
  8030. int sentConfigurationNumber= 0;
  8031. int sentunConfigurationNumber= 0;
  8032. char message[1024*10]={0};
  8033. DEBUG_INFO("sendGetConfigurationConfirmation...\n");
  8034. MaxKeySupported = atoi((const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemData);
  8035. sprintf(message,"[%d,\"%s\",{\"configurationKey\":["
  8036. ,MESSAGE_TYPE_CALLRESULT
  8037. ,uuid );
  8038. //configuration key
  8039. for(int idx_sample=0;idx_sample< MaxKeySupported/*43*/;idx_sample++)
  8040. {
  8041. if(strcmp((const char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[idx_sample].Key, "")!= 0)
  8042. {
  8043. if (sentConfigurationNumber == 0)
  8044. {
  8045. sprintf(message + strlen(message), "{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}"
  8046. , ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[idx_sample].Key
  8047. , atoi((const char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[idx_sample].ReadOnly) == 1 ? "true":"false"
  8048. , ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[idx_sample].Value );
  8049. }
  8050. else
  8051. {
  8052. sprintf(message + strlen(message), ", {\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}"
  8053. , ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[idx_sample].Key
  8054. , atoi((const char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[idx_sample].ReadOnly) == 1 ? "true":"false"
  8055. , ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[idx_sample].Value );
  8056. }
  8057. sentConfigurationNumber = sentConfigurationNumber + 1;
  8058. }
  8059. }
  8060. sprintf(message + strlen(message), "]");
  8061. if(UnknownKeynum != 0)
  8062. {
  8063. sprintf(message + strlen(message), ",\"unknownKey\":[");
  8064. //unkown key
  8065. for(int idx_sample=0;idx_sample< UnknownKeynum ;idx_sample++)
  8066. {
  8067. // json_object *jstring1 = json_object_new_string((const char *)((ShmOCPP16Data->GetConfiguration.ResponseUnknownKey + idx_sample)->Item));
  8068. DEBUG_INFO("unkown key:%s\n", ShmOCPP16Data->GetConfiguration.ResponseUnknownKey[idx_sample].Item);
  8069. if(sentunConfigurationNumber == 0)
  8070. {
  8071. sprintf(message + strlen(message), "\"%s\""
  8072. , ShmOCPP16Data->GetConfiguration.ResponseUnknownKey[idx_sample].Item );
  8073. }
  8074. else
  8075. {
  8076. sprintf(message + strlen(message), ",\"%s\""
  8077. , ShmOCPP16Data->GetConfiguration.ResponseUnknownKey[idx_sample].Item );
  8078. }
  8079. sentunConfigurationNumber = sentunConfigurationNumber + 1;
  8080. }
  8081. sprintf(message + strlen(message), "]");
  8082. }
  8083. sprintf(message + strlen(message), "}]");
  8084. LWS_Send(message);
  8085. return result;
  8086. }
  8087. int sendGetDiagnosticsConfirmation(char *uuid,char *payload)
  8088. {
  8089. mtrace();
  8090. int result = FAIL;
  8091. char message[400]={0};
  8092. DEBUG_INFO("sendGetDiagnosticsConfirmation...\n");
  8093. if(strcmp(payload,"")==0)
  8094. {
  8095. sprintf(message,"[%d,\"%s\",{}]",MESSAGE_TYPE_CALLRESULT, uuid);
  8096. }
  8097. else
  8098. {
  8099. sprintf(message,"[%d,\"%s\",{\"fileName\":\"%s\"}]", MESSAGE_TYPE_CALLRESULT, uuid, payload);
  8100. }
  8101. LWS_Send(message);
  8102. result = TRUE;
  8103. return result;
  8104. }
  8105. int sendGetLocalListVersionConfirmation(char *uuid,char *payload)
  8106. {
  8107. mtrace();
  8108. int result = FAIL;
  8109. char message[80]={0};
  8110. DEBUG_INFO("sendGetLocalListVersionConfirmation...\n");
  8111. sprintf(message,"[%d,\"%s\",{\"listVersion\":%d}]",MESSAGE_TYPE_CALLRESULT, uuid, ShmOCPP16Data->GetLocalListVersion.ResponseListVersion);
  8112. LWS_Send(message);
  8113. result = TRUE;
  8114. return result;
  8115. }
  8116. int sendRemoteStartConfirmation(char *uuid,char *payload)
  8117. {
  8118. mtrace();
  8119. int result = FAIL;
  8120. char message[80]={0};
  8121. DEBUG_INFO("sendRemoteStartConfirmation...\n");
  8122. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, payload);
  8123. LWS_Send(message);
  8124. result = TRUE;
  8125. return result;
  8126. }
  8127. int sendRemoteStopTransactionConfirmation(char *uuid,char *payload)
  8128. {
  8129. mtrace();
  8130. int result = FAIL;
  8131. char message[80]={0};
  8132. DEBUG_INFO("sendRemoteStopTransactionConfirmation...\n");
  8133. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, payload);
  8134. LWS_Send(message);
  8135. result = TRUE;
  8136. return result;
  8137. }
  8138. int sendReserveNowTransactionConfirmation(char *uuid,char *payload)
  8139. {
  8140. mtrace();
  8141. int result = FAIL;
  8142. char message[80]={0};
  8143. // [3,"287d837d-809e-41ea-8385-fdab7f72a01c",{"status":"Accepted"}]
  8144. DEBUG_INFO("sendReserveNowTransactionConfirmation...\n");
  8145. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, payload);
  8146. LWS_Send(message);
  8147. result = TRUE;
  8148. return result;
  8149. }
  8150. int sendResetConfirmation(char *uuid,char *payload)
  8151. {
  8152. mtrace();
  8153. int result = FAIL;
  8154. //[ 3, "6f88d461-4d17-462c-a69b-1f7a8c5b12df", { "status": 0 } ]
  8155. char message[80]={0};
  8156. ShmOCPP16Data->MsMsg.bits.ResetConf = 0;
  8157. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, payload);
  8158. LWS_Send(message);
  8159. result = TRUE;
  8160. return result;
  8161. }
  8162. int sendSendLocalListConfirmation(char *uuid,char *payload)
  8163. {
  8164. mtrace();
  8165. int result = FAIL;
  8166. char message[500]={0};
  8167. // [ 3, "1571284266109", { "status": "Accepted" } ]
  8168. sprintf(message,"[%d,\"%s\",{\"%s\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, "status", payload);
  8169. LWS_Send(message);
  8170. result = TRUE;
  8171. return result;
  8172. }
  8173. int sendSetChargingProfileConfirmation(char *uuid,char *payload)
  8174. {
  8175. mtrace();
  8176. int result = FAIL;
  8177. //[3,"5748585f-8524-4fa6-9b4f-4a7eca750b90",{"status":"NotSupported"}]
  8178. char message[80]={0};
  8179. DEBUG_INFO("sendSetChargingProfileConfirmation...\n");
  8180. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, payload);
  8181. LWS_Send(message);
  8182. result = TRUE;
  8183. return result;
  8184. }
  8185. int sendTriggerMessageConfirmation(char *uuid,char *payload)
  8186. {
  8187. mtrace();
  8188. int result = FAIL;
  8189. char message[80]={0};
  8190. DEBUG_INFO("sendTriggerMessageConfirmation...\n");
  8191. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, payload);
  8192. LWS_Send(message);
  8193. result = TRUE;
  8194. return result;
  8195. }
  8196. int sendUnlockConnectorConfirmation(char *uuid,char *payload)
  8197. {
  8198. mtrace();
  8199. int result = FAIL;
  8200. char message[80]={0};
  8201. //[ 3, "ba1cbd49-2a76-493a-8f76-fa23e7606532", { "status": "Unlocked" } ]
  8202. DEBUG_INFO("sendUnlockConnectorConfirmation...\n");
  8203. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, payload);
  8204. LWS_Send(message);
  8205. result = TRUE;
  8206. return result;
  8207. }
  8208. int sendUpdateFirmwareConfirmation(char *uuid)
  8209. {
  8210. mtrace();
  8211. int result = FAIL;
  8212. char message[60]={0};
  8213. //[ 3, "ba1cbd49-2a76-493a-8f76-fa23e7606532", { "status": "Unlocked" } ]
  8214. DEBUG_INFO("sendUpdateFirmwareConfirmation...\n");
  8215. sprintf(message,"[%d,\"%s\",{}]",MESSAGE_TYPE_CALLRESULT, uuid);
  8216. LWS_Send(message);
  8217. result = TRUE;
  8218. return result;
  8219. }
  8220. int sendCertificateSignedConfirmation(char *uuid)
  8221. {
  8222. mtrace();
  8223. int result = PASS;
  8224. char message[4096]={0};
  8225. json_object *CertificateSigned = json_object_new_object();
  8226. DEBUG_INFO("sendCertificateSignedConfirmation...\n");
  8227. json_object_object_add(CertificateSigned, "status", json_object_new_string((char*)ShmOCPP16Data->CertificateSigned.Response_status));
  8228. sprintf(message,"[%d,\"%s\",%s]"
  8229. ,MESSAGE_TYPE_CALLRESULT
  8230. ,uuid
  8231. ,json_object_to_json_string_ext(CertificateSigned, JSON_C_TO_STRING_PLAIN));
  8232. json_object_put(CertificateSigned);
  8233. LWS_Send(message);
  8234. return result;
  8235. }
  8236. int sendDeleteCertificateConfirmation(char *uuid)
  8237. {
  8238. mtrace();
  8239. int result = PASS;
  8240. char message[4096]={0};
  8241. json_object *DeleteCertificate = json_object_new_object();
  8242. DEBUG_INFO("sendDeleteCertificateConfirmation...\n");
  8243. json_object_object_add(DeleteCertificate, "status", json_object_new_string((char*)ShmOCPP16Data->DeleteCertificate.Response_status));
  8244. sprintf(message,"[%d,\"%s\",%s]"
  8245. ,MESSAGE_TYPE_CALLRESULT
  8246. ,uuid
  8247. ,json_object_to_json_string_ext(DeleteCertificate, JSON_C_TO_STRING_PLAIN));
  8248. json_object_put(DeleteCertificate);
  8249. LWS_Send(message);
  8250. return result;
  8251. }
  8252. int sendExtendedTriggerMessageConfirmation(char *uuid)
  8253. {
  8254. mtrace();
  8255. int result = PASS;
  8256. char message[4096]={0};
  8257. json_object *ExtendedTriggerMessage = json_object_new_object();
  8258. DEBUG_INFO("sendExtendedTriggerMessageConfirmation...\n");
  8259. json_object_object_add(ExtendedTriggerMessage, "status", json_object_new_string((char*)ShmOCPP16Data->ExtendedTriggerMessage.Response_status));
  8260. sprintf(message,"[%d,\"%s\",%s]"
  8261. ,MESSAGE_TYPE_CALLRESULT
  8262. ,uuid
  8263. ,json_object_to_json_string_ext(ExtendedTriggerMessage, JSON_C_TO_STRING_PLAIN));
  8264. json_object_put(ExtendedTriggerMessage);
  8265. LWS_Send(message);
  8266. return result;
  8267. }
  8268. int sendGetInstalledCertificateIdsConfirmation(char *uuid)
  8269. {
  8270. mtrace();
  8271. int result = PASS;
  8272. char message[4096]={0};
  8273. json_object *GetInstalledCertificateIds = json_object_new_object();
  8274. json_object *certificateHashDataDatas = json_object_new_array();
  8275. DEBUG_INFO("sendGetInstalledCertificateIdsConfirmation...\n");
  8276. json_object_object_add(GetInstalledCertificateIds, "status", json_object_new_string((char*)ShmOCPP16Data->GetInstalledCertificateIds.Response_status));
  8277. if(strlen((char*)ShmOCPP16Data->GetInstalledCertificateIds.Response_certificateHashData[0].hashAlgorithm) > 0)
  8278. {
  8279. for(int idx=0;idx<ARRAY_SIZE(ShmOCPP16Data->GetInstalledCertificateIds.Response_certificateHashData);idx++)
  8280. {
  8281. json_object *certificateHashData = json_object_new_object();
  8282. json_object_object_add(certificateHashData, "hashAlgorithm", json_object_new_string((char*)ShmOCPP16Data->GetInstalledCertificateIds.Response_certificateHashData[idx].hashAlgorithm));
  8283. json_object_object_add(certificateHashData, "issuerNameHash", json_object_new_string((char*)ShmOCPP16Data->GetInstalledCertificateIds.Response_certificateHashData[idx].issuerNameHash));
  8284. json_object_object_add(certificateHashData, "issuerKeyHash", json_object_new_string((char*)ShmOCPP16Data->GetInstalledCertificateIds.Response_certificateHashData[idx].issuerKeyHash));
  8285. json_object_object_add(certificateHashData, "serialNumber", json_object_new_string((char*)ShmOCPP16Data->GetInstalledCertificateIds.Response_certificateHashData[idx].serialNumber));
  8286. json_object_array_add(certificateHashDataDatas, certificateHashData);
  8287. }
  8288. json_object_object_add(GetInstalledCertificateIds , "certificateHashData", certificateHashDataDatas);
  8289. }
  8290. else
  8291. {
  8292. json_object_put(certificateHashDataDatas);
  8293. }
  8294. sprintf(message,"[%d,\"%s\",%s]"
  8295. ,MESSAGE_TYPE_CALLRESULT
  8296. ,uuid
  8297. ,json_object_to_json_string_ext(GetInstalledCertificateIds, JSON_C_TO_STRING_PLAIN));
  8298. json_object_put(GetInstalledCertificateIds);
  8299. LWS_Send(message);
  8300. return result;
  8301. }
  8302. int sendGetLogConfirmation(char *uuid)
  8303. {
  8304. mtrace();
  8305. int result = PASS;
  8306. char message[4096]={0};
  8307. json_object *GetLog = json_object_new_object();
  8308. DEBUG_INFO("sendGetLogConfirmation...\n");
  8309. json_object_object_add(GetLog, "status", json_object_new_string((char*)ShmOCPP16Data->GetLog.Response_status));
  8310. if(strlen((char*)ShmOCPP16Data->GetLog.Response_filename) > 0)
  8311. json_object_object_add(GetLog, "filename", json_object_new_string((char*)ShmOCPP16Data->GetLog.Response_filename));
  8312. sprintf(message,"[%d,\"%s\",%s]"
  8313. ,MESSAGE_TYPE_CALLRESULT
  8314. ,uuid
  8315. ,json_object_to_json_string_ext(GetLog, JSON_C_TO_STRING_PLAIN));
  8316. json_object_put(GetLog);
  8317. LWS_Send(message);
  8318. return result;
  8319. }
  8320. int sendInstallCertificateConfirmation(char *uuid)
  8321. {
  8322. mtrace();
  8323. int result = PASS;
  8324. char message[4096]={0};
  8325. json_object *InstallCertificate = json_object_new_object();
  8326. DEBUG_INFO("sendInstallCertificateConfirmation...\n");
  8327. json_object_object_add(InstallCertificate, "status", json_object_new_string((char*)ShmOCPP16Data->InstallCertificate.Response_status));
  8328. sprintf(message,"[%d,\"%s\",%s]"
  8329. ,MESSAGE_TYPE_CALLRESULT
  8330. ,uuid
  8331. ,json_object_to_json_string_ext(InstallCertificate, JSON_C_TO_STRING_PLAIN));
  8332. json_object_put(InstallCertificate);
  8333. LWS_Send(message);
  8334. return result;
  8335. }
  8336. int sendSignedUpdateFirmwareConfirmation(char *uuid)
  8337. {
  8338. mtrace();
  8339. int result = PASS;
  8340. char message[4096]={0};
  8341. json_object *SignedUpdateFirmware = json_object_new_object();
  8342. DEBUG_INFO("sendSignedUpdateFirmwareConfirmation...\n");
  8343. json_object_object_add(SignedUpdateFirmware, "status", json_object_new_string((char*)ShmOCPP16Data->SignedUpdateFirmware.Response_status));
  8344. sprintf(message,"[%d,\"%s\",%s]"
  8345. ,MESSAGE_TYPE_CALLRESULT
  8346. ,uuid
  8347. ,json_object_to_json_string_ext(SignedUpdateFirmware, JSON_C_TO_STRING_PLAIN));
  8348. json_object_put(SignedUpdateFirmware);
  8349. LWS_Send(message);
  8350. return result;
  8351. }
  8352. int sendUnknownConfirmation(char *uuid)
  8353. {
  8354. mtrace();
  8355. int result = PASS;
  8356. char message[256]={0};
  8357. DEBUG_INFO("sendUnknownConfirmation...\n");
  8358. sprintf(message,"[%d,\"%s\",\"NotImplemented\",\"Requested Action is not known by receiver\",{}]", MESSAGE_TYPE_CALLERROR, uuid);
  8359. LWS_Send(message);
  8360. return result;
  8361. }
  8362. //==========================================
  8363. // Handle server request routine Start
  8364. //==========================================
  8365. int handleCancelReservationRequest(char *uuid, char *payload)
  8366. {
  8367. mtrace();
  8368. int result = FAIL;
  8369. int gunNO = 0;
  8370. int reservationIdInt = -1;
  8371. char comfirmstr[20];
  8372. DEBUG_INFO("handleCancelReservationRequest...\n");
  8373. json_object *CancelReservation;
  8374. CancelReservation = json_tokener_parse(payload);
  8375. if(!is_error(CancelReservation))
  8376. {
  8377. // Required data
  8378. if(json_object_object_get(CancelReservation, "reservationId") != NULL)
  8379. reservationIdInt = json_object_get_int(json_object_object_get(CancelReservation, "reservationId"));
  8380. }
  8381. json_object_put(CancelReservation);
  8382. DEBUG_INFO("reservationIdInt = %d\n", reservationIdInt);
  8383. memset(comfirmstr, 0, ARRAY_SIZE(comfirmstr));
  8384. sprintf(comfirmstr, "%s", CancelReservationStatusStr[CancelReservationStatus_Rejected]);
  8385. if(reservationIdInt != -1)
  8386. {
  8387. //0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault, 8: Reserved, 9: maintain
  8388. //check Transaction active
  8389. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  8390. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  8391. {
  8392. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ReservationId == reservationIdInt)
  8393. {
  8394. sprintf(comfirmstr, "%s", CancelReservationStatusStr[CancelReservationStatus_Accepted] );
  8395. sprintf((char *)ShmOCPP16Data->CancelReservation[ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index].ResponseStatus, "%s", comfirmstr );
  8396. if(gunType[2] == GUN_TYPE_CHAdeMO)
  8397. {
  8398. gunNO = ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index + 1;
  8399. }
  8400. else
  8401. {
  8402. gunNO = ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index;
  8403. }
  8404. ShmOCPP16Data->CsMsg.bits[gunNO].CancelReservationReq = 1;
  8405. goto end;
  8406. }
  8407. }
  8408. for (int index = 0; index < CCS_QUANTITY; index++)
  8409. {
  8410. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ReservationId == reservationIdInt)
  8411. {
  8412. sprintf(comfirmstr, "%s", CancelReservationStatusStr[CancelReservationStatus_Accepted] );
  8413. sprintf((char *)ShmOCPP16Data->CancelReservation[ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index].ResponseStatus, "%s", comfirmstr );
  8414. if(gunType[2] == GUN_TYPE_CCS)
  8415. {
  8416. gunNO = ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index + 1;
  8417. }
  8418. else
  8419. {
  8420. gunNO = ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index;
  8421. }
  8422. ShmOCPP16Data->CsMsg.bits[gunNO].CancelReservationReq = 1;
  8423. goto end;
  8424. }
  8425. }
  8426. for (int index = 0; index < GB_QUANTITY; index++)
  8427. {
  8428. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ReservationId == reservationIdInt)
  8429. {
  8430. sprintf(comfirmstr, "%s", CancelReservationStatusStr[CancelReservationStatus_Accepted] );
  8431. sprintf((char *)ShmOCPP16Data->CancelReservation[ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index].ResponseStatus, "%s", comfirmstr );
  8432. if(gunType[2] == GUN_TYPE_GBT)
  8433. {
  8434. gunNO = ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index + 1;
  8435. }
  8436. else
  8437. {
  8438. gunNO = ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index;
  8439. }
  8440. ShmOCPP16Data->CsMsg.bits[gunNO].CancelReservationReq = 1;
  8441. goto end;
  8442. }
  8443. }
  8444. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  8445. {
  8446. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.ReservationId == reservationIdInt)
  8447. {
  8448. sprintf(comfirmstr, "%s", CancelReservationStatusStr[CancelReservationStatus_Accepted] );
  8449. sprintf((char *)ShmOCPP16Data->CancelReservation[ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index].ResponseStatus, "%s", comfirmstr );
  8450. gunNO = ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index;
  8451. ShmOCPP16Data->CsMsg.bits[gunNO].CancelReservationReq = 1;
  8452. goto end;
  8453. }
  8454. }
  8455. for (int index = 0; index < AC_QUANTITY; index++)
  8456. {
  8457. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].ReservationId == reservationIdInt)
  8458. {
  8459. sprintf(comfirmstr, "%s", CancelReservationStatusStr[CancelReservationStatus_Accepted] );
  8460. sprintf((char *)ShmOCPP16Data->CancelReservation[ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index].ResponseStatus, "%s", comfirmstr );
  8461. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  8462. {
  8463. gunNO = 1; //ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index ;
  8464. }
  8465. else
  8466. {
  8467. gunNO = ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index;
  8468. }
  8469. ShmOCPP16Data->CsMsg.bits[gunNO].CancelReservationReq = 1;
  8470. goto end;
  8471. }
  8472. }
  8473. }
  8474. //The reservationId does NOT match the reservationId
  8475. sendCancelReservationConfirmation(uuid, comfirmstr);
  8476. end:
  8477. // Fill in ocpp packet uuid
  8478. strcpy((char *)ShmOCPP16Data->CancelReservation[gunNO].guid, uuid);
  8479. return result;
  8480. }
  8481. int handleChangeAvailabilityRequest(char *uuid, char *payload)
  8482. {
  8483. mtrace();
  8484. int result = FAIL;
  8485. int gunIndex = -1;
  8486. char typeStr[16]={0};
  8487. char comfirmstr[20];
  8488. int specificId = FALSE;
  8489. DEBUG_INFO("handleChangeAvailabilityRequest...\n");
  8490. json_object *ChangeAvailability;
  8491. ChangeAvailability = json_tokener_parse(payload);
  8492. if(!is_error(ChangeAvailability))
  8493. {
  8494. // Required data
  8495. if((json_object_object_get(ChangeAvailability, "connectorId") != NULL) && (json_object_get_type(json_object_object_get(ChangeAvailability, "connectorId")) == json_type_int))
  8496. gunIndex = json_object_get_int(json_object_object_get(ChangeAvailability, "connectorId"));
  8497. if(json_object_object_get(ChangeAvailability, "type") != NULL)
  8498. sprintf((char*)typeStr, "%s", json_object_get_string(json_object_object_get(ChangeAvailability, "type")));
  8499. }
  8500. json_object_put(ChangeAvailability);
  8501. if((gunIndex > 0) && (gunIndex <= gunTotalNumber))
  8502. {
  8503. ShmOCPP16Data->ChangeAvailability[gunIndex - 1].ConnectorId= gunIndex;
  8504. sprintf((char *)ShmOCPP16Data->ChangeAvailability[gunIndex - 1].Type, "%s", typeStr);
  8505. }
  8506. else if(gunIndex == 0)
  8507. {
  8508. for(int i=0; i < gunTotalNumber; i++)
  8509. {
  8510. ShmOCPP16Data->ChangeAvailability[i].ConnectorId= gunIndex;
  8511. sprintf((char *)ShmOCPP16Data->ChangeAvailability[i].Type, "%s", typeStr);
  8512. }
  8513. }
  8514. memset(comfirmstr, 0, ARRAY_SIZE(comfirmstr));
  8515. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  8516. if((gunIndex == 0) || ((gunIndex > 0) && (gunIndex <= gunTotalNumber)))
  8517. {
  8518. specificId = TRUE;
  8519. }
  8520. if(specificId == FALSE)
  8521. goto end;
  8522. if(strcmp((const char *)typeStr, AvailabilityTypeStr[Inoperative]) == 0)
  8523. {
  8524. //----------------------gunIndex is 0 ------------------------------------------------//
  8525. if(gunIndex == 0)
  8526. {
  8527. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D') // 'D' means DC
  8528. {
  8529. for(int i=0; i < gunTotalNumber; i++)
  8530. {
  8531. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  8532. {
  8533. if ((gunType[i] == GUN_TYPE_CHAdeMO)&&(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == i))
  8534. {
  8535. if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_RESERVATION) // S_PRECHARGE
  8536. {
  8537. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  8538. goto end;
  8539. }
  8540. else if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_AUTHORIZING) ||
  8541. (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_PREPARING) ||
  8542. (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_CHARGING) ||
  8543. (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_TERMINATING) ||
  8544. (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_COMPLETE)) // S_CHARGING
  8545. {
  8546. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  8547. goto end;
  8548. }
  8549. }
  8550. }//END FOR CHAdeMO_QUANTITY
  8551. for (int index = 0; index < CCS_QUANTITY; index++)
  8552. {
  8553. if ((gunType[i] == GUN_TYPE_CCS)&&(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == i))
  8554. {
  8555. if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_RESERVATION)// S_PRECHARGE
  8556. {
  8557. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  8558. goto end;
  8559. }
  8560. else if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_AUTHORIZING) ||
  8561. (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_PREPARING) ||
  8562. (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_CHARGING) ||
  8563. (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_TERMINATING) ||
  8564. (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_COMPLETE)) // S_CHARGING
  8565. {
  8566. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  8567. goto end;
  8568. }
  8569. }
  8570. }//END FOR CCS_QUANTITY
  8571. for (int index = 0; index < GB_QUANTITY; index++)
  8572. {
  8573. if ((gunType[i] == GUN_TYPE_GBT)&&(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == i))
  8574. {
  8575. if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_RESERVATION) // S_PRECHARGE
  8576. {
  8577. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  8578. goto end;
  8579. }
  8580. else if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_AUTHORIZING) ||
  8581. (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_PREPARING) ||
  8582. (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_CHARGING) ||
  8583. (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_TERMINATING) ||
  8584. (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_COMPLETE)) // S_CHARGING
  8585. {
  8586. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  8587. goto end;
  8588. }
  8589. }
  8590. }// END FOR GB_QUANTITY
  8591. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  8592. {
  8593. if ((gunType[i] == GUN_TYPE_DO)&&(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == i))
  8594. {
  8595. if(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_RESERVATION) // S_PRECHARGE
  8596. {
  8597. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  8598. goto end;
  8599. }
  8600. else if((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_AUTHORIZING) ||
  8601. (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_PREPARING) ||
  8602. (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_CHARGING) ||
  8603. (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_TERMINATING) ||
  8604. (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_COMPLETE)) // S_CHARGING
  8605. {
  8606. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  8607. goto end;
  8608. }
  8609. }
  8610. }// END FOR GENERAL_GUN_QUANTITY
  8611. for (int index = 0; index < AC_QUANTITY; index++)
  8612. {
  8613. if ((gunType[i] == GUN_TYPE_AC)&&(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == i))
  8614. {
  8615. if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_RESERVATION) // S_PRECHARGE
  8616. {
  8617. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  8618. goto end;
  8619. }
  8620. else if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_AUTHORIZING) ||
  8621. (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_PREPARING) ||
  8622. (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_CHARGING) ||
  8623. (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_TERMINATING) ||
  8624. (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_COMPLETE)) // S_CHARGING
  8625. {
  8626. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  8627. goto end;
  8628. }
  8629. }
  8630. }//END FOR AC_QUANTITY
  8631. }// END FOR gunTotalNumber
  8632. }
  8633. else if (ShmSysConfigAndInfo->SysConfig.ModelName[0]=='A') //'A' means AC
  8634. {
  8635. for(int i=0; i < gunTotalNumber; i++)
  8636. {
  8637. if(ShmSysConfigAndInfo->SysInfo.AcChargingData[i].SystemStatus == SYS_MODE_RESERVATION) // S_PRECHARGE
  8638. {
  8639. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  8640. goto end;
  8641. }
  8642. else if((ShmSysConfigAndInfo->SysInfo.AcChargingData[i].SystemStatus == SYS_MODE_AUTHORIZING) ||
  8643. (ShmSysConfigAndInfo->SysInfo.AcChargingData[i].SystemStatus == SYS_MODE_PREPARING) ||
  8644. (ShmSysConfigAndInfo->SysInfo.AcChargingData[i].SystemStatus == SYS_MODE_CHARGING) ||
  8645. (ShmSysConfigAndInfo->SysInfo.AcChargingData[i].SystemStatus == SYS_MODE_TERMINATING) ||
  8646. (ShmSysConfigAndInfo->SysInfo.AcChargingData[i].SystemStatus == SYS_MODE_COMPLETE)) // S_CHARGING
  8647. {
  8648. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  8649. goto end;
  8650. }
  8651. }
  8652. }
  8653. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  8654. goto end;
  8655. }
  8656. //----------------------gunIndex is not 0 ------------------------------------------------//
  8657. //check Transaction active
  8658. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  8659. {
  8660. if ((gunIndex > 0)&&(gunType[gunIndex-1] == GUN_TYPE_CHAdeMO))
  8661. {
  8662. if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_RESERVATION) ) // S_PRECHARGE
  8663. {
  8664. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  8665. goto end;
  8666. }
  8667. else if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_AUTHORIZING) ||
  8668. (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_PREPARING) ||
  8669. (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_CHARGING) ||
  8670. (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_TERMINATING) ||
  8671. (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_COMPLETE)) // S_CHARGING
  8672. {
  8673. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  8674. goto end;
  8675. }
  8676. else
  8677. {
  8678. DEBUG_INFO("ShmSysConfigAndInfo->SysInfo.ChademoChargingData[%d].SystemStatus = %d\n",index, ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus);
  8679. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  8680. goto end;
  8681. }
  8682. }
  8683. }//END FOR CHAdeMO_QUANTITY
  8684. for (int index = 0; index < CCS_QUANTITY; index++)
  8685. {
  8686. if ((gunIndex > 0)&&(gunType[gunIndex - 1] == GUN_TYPE_CCS))
  8687. {
  8688. if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_RESERVATION) )// S_PRECHARGE
  8689. {
  8690. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  8691. goto end;
  8692. }
  8693. else if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_AUTHORIZING) ||
  8694. (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_PREPARING) ||
  8695. (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_CHARGING) ||
  8696. (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_TERMINATING) ||
  8697. (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_COMPLETE)) // S_CHARGING
  8698. {
  8699. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  8700. goto end;
  8701. }
  8702. else
  8703. {
  8704. DEBUG_INFO("ShmSysConfigAndInfo->SysInfo.CcsChargingData[%d].SystemStatus=%d\n",index, ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus);
  8705. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  8706. goto end;
  8707. }
  8708. }
  8709. }//END FOR CCS_QUANTITY
  8710. for (int index = 0; index < GB_QUANTITY; index++)
  8711. {
  8712. if ((gunIndex > 0)&&(gunType[gunIndex-1] == GUN_TYPE_GBT))
  8713. {
  8714. if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_RESERVATION)) // S_PRECHARGE
  8715. {
  8716. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  8717. goto end;
  8718. }
  8719. else if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_AUTHORIZING) ||
  8720. (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_PREPARING) ||
  8721. (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_CHARGING) ||
  8722. (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_TERMINATING) ||
  8723. (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_COMPLETE)) // S_CHARGING
  8724. {
  8725. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  8726. goto end;
  8727. }
  8728. else
  8729. {
  8730. DEBUG_INFO("ShmSysConfigAndInfo->SysInfo.GbChargingData[%d].SystemStatus=%d\n",index,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus);
  8731. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  8732. goto end;
  8733. }
  8734. }
  8735. }// END FOR GB_QUANTITY
  8736. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  8737. {
  8738. if ((gunIndex > 0)&&(gunType[gunIndex-1] == GUN_TYPE_DO))
  8739. {
  8740. if((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_RESERVATION)) // S_PRECHARGE
  8741. {
  8742. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  8743. goto end;
  8744. }
  8745. else if((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_AUTHORIZING) ||
  8746. (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_PREPARING) ||
  8747. (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_CHARGING) ||
  8748. (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_TERMINATING) ||
  8749. (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_COMPLETE)) // S_CHARGING
  8750. {
  8751. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  8752. goto end;
  8753. }
  8754. else
  8755. {
  8756. DEBUG_INFO("ShmSysConfigAndInfo->SysInfo.GbChargingData[%d].SystemStatus=%d\n",index,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus);
  8757. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  8758. goto end;
  8759. }
  8760. }
  8761. }// END FOR GENERAL_GUN_QUANTITY
  8762. for (int index = 0; index < AC_QUANTITY; index++)
  8763. {
  8764. if ((gunIndex > 0)&&(gunType[gunIndex-1] ==GUN_TYPE_AC))
  8765. {
  8766. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_RESERVATION)) // S_PRECHARGE
  8767. {
  8768. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  8769. goto end;
  8770. }
  8771. else if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_AUTHORIZING) ||
  8772. (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_PREPARING) ||
  8773. (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_CHARGING) ||
  8774. (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_TERMINATING) ||
  8775. (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_COMPLETE)) // S_CHARGING
  8776. {
  8777. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  8778. goto end;
  8779. }
  8780. else
  8781. {
  8782. DEBUG_INFO("ShmSysConfigAndInfo->SysInfo.AcChargingData[%d].SystemStatus=%d\n",index, ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus);
  8783. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  8784. goto end;
  8785. }
  8786. }
  8787. }//END FOR AC_QUANTITY
  8788. }//END FOR AvailabilityTypeStr[Inoperative]
  8789. if(strcmp((const char *)typeStr, AvailabilityTypeStr[Operative]) == 0)
  8790. {
  8791. //----------------------gunIndex is 0 ------------------------------------------------//
  8792. if(gunIndex == 0)
  8793. {
  8794. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D') // 'D' means DC
  8795. {
  8796. for(int i=0; i < gunTotalNumber; i++)
  8797. {
  8798. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  8799. {
  8800. 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
  8801. {
  8802. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  8803. goto end;
  8804. }
  8805. }//END FOR CHAdeMO_QUANTITY
  8806. for (int index = 0; index < CCS_QUANTITY; index++)
  8807. {
  8808. 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
  8809. {
  8810. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  8811. goto end;
  8812. }
  8813. }//END FOR CCS_QUANTITY
  8814. for (int index = 0; index < GB_QUANTITY; index++)
  8815. {
  8816. 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
  8817. {
  8818. //ShmOCPP16Data->CsMsg.bits[gunIndex - 1].ChangeAvailabilityReq = 1;
  8819. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  8820. goto end;
  8821. }
  8822. }// END FOR GB_QUANTITY
  8823. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  8824. {
  8825. 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
  8826. {
  8827. //ShmOCPP16Data->CsMsg.bits[gunIndex - 1].ChangeAvailabilityReq = 1;
  8828. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  8829. goto end;
  8830. }
  8831. }// END FOR GENERAL_GUN_QUANTITY
  8832. for (int index = 0; index < AC_QUANTITY; index++)
  8833. {
  8834. 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
  8835. {
  8836. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  8837. goto end;
  8838. }
  8839. }//END FOR CHAdeMO_QUANTITY
  8840. }// END FOR gunTotalNumber
  8841. }
  8842. else if (ShmSysConfigAndInfo->SysConfig.ModelName[0]=='A') //'A' means AC
  8843. {
  8844. for(int i=0; i < gunTotalNumber; i++)
  8845. {
  8846. for (int index = 0; index < AC_QUANTITY; index++)
  8847. {
  8848. 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
  8849. {
  8850. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  8851. goto end;
  8852. }
  8853. }//END FOR CHAdeMO_QUANTITY
  8854. } // END FOR gunTotalNumber
  8855. }
  8856. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  8857. goto end;
  8858. }
  8859. //----------------------gunIndex is not 0 ------------------------------------------------//
  8860. //check Transaction active
  8861. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  8862. {
  8863. if (((gunIndex > 0)&&(gunType[gunIndex-1] == GUN_TYPE_CHAdeMO) ) &&(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_FAULT)) //S_FAULT
  8864. {
  8865. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  8866. goto end;
  8867. }
  8868. }//END FOR CHAdeMO_QUANTITY
  8869. for (int index = 0; index < CCS_QUANTITY; index++)
  8870. {
  8871. if ((((gunIndex > 0)&&(gunType[gunIndex - 1] == GUN_TYPE_CCS)) )&&(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_FAULT)) //S_FAULT
  8872. {
  8873. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  8874. goto end;
  8875. }
  8876. }//END FOR CCS_QUANTITY
  8877. for (int index = 0; index < GB_QUANTITY; index++)
  8878. {
  8879. if (((gunIndex > 0)&&(gunType[gunIndex-1] == GUN_TYPE_GBT))&&(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_FAULT)) //S_FAULT
  8880. {
  8881. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  8882. goto end;
  8883. }
  8884. }// END FOR GB_QUANTITY
  8885. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  8886. {
  8887. if (((gunIndex > 0)&&(gunType[gunIndex-1] == GUN_TYPE_DO))&&(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus != SYS_MODE_FAULT)) //S_FAULT
  8888. {
  8889. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  8890. goto end;
  8891. }
  8892. }// END FOR GENERAL_GUN_QUANTITY
  8893. for (int index = 0; index < AC_QUANTITY; index++)
  8894. {
  8895. if (((gunIndex > 0)&&(gunType[gunIndex-1] == GUN_TYPE_AC)) &&(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_FAULT)) //S_FAULT
  8896. {
  8897. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  8898. goto end;
  8899. }
  8900. }//END FOR AC_QUANTITY
  8901. }//END FOR AvailabilityTypeStr[Operative]
  8902. end:
  8903. if((gunIndex != 0) && (gunIndex <= gunTotalNumber))
  8904. {
  8905. sprintf((char *)ShmOCPP16Data->ChangeAvailability[gunIndex - 1].ResponseStatus, "%s", comfirmstr );
  8906. }
  8907. else
  8908. {
  8909. sprintf((char *)ShmOCPP16Data->ChangeAvailability[0].ResponseStatus, "%s", comfirmstr );
  8910. }
  8911. if((gunIndex != 0) && (gunIndex <= gunTotalNumber))
  8912. {
  8913. if(strstr(comfirmstr, AvailabilityStatusStr[Rejected]) == NULL)
  8914. ShmOCPP16Data->CsMsg.bits[gunIndex - 1].ChangeAvailabilityReq = 1;
  8915. }
  8916. else if(gunIndex == 0)
  8917. {
  8918. if(strstr(comfirmstr, AvailabilityStatusStr[Rejected]) == NULL)
  8919. {
  8920. for(int i=0; i < gunTotalNumber/*(CHAdeMO_QUANTITY+ CCS_QUANTITY + GB_QUANTITY)*/; i++)
  8921. ShmOCPP16Data->CsMsg.bits[i].ChangeAvailabilityReq = 1;
  8922. }
  8923. }
  8924. sendChangeAvailabilityConfirmation(uuid, comfirmstr);
  8925. system("/bin/fsync -d /dev/mtdblock13;/bin/sync &");
  8926. return result;
  8927. }
  8928. int handleChangeConfigurationRequest(char *uuid, char *payload)
  8929. {
  8930. mtrace();
  8931. int valueInvalid = NO;
  8932. int result = FAIL;
  8933. char keystr[40]={0};
  8934. char valuestr[501]={0}; //value should be limited in 500 bytes
  8935. char comfirmstr[20]={0};
  8936. DEBUG_INFO("handleChangeConfigurationRequest...\n");
  8937. json_object *ChangeConfiguration;
  8938. ChangeConfiguration = json_tokener_parse(payload);
  8939. if(!is_error(ChangeConfiguration))
  8940. {
  8941. // Required data
  8942. if(json_object_object_get(ChangeConfiguration, "key") != NULL)
  8943. sprintf((char*)keystr, "%s", json_object_get_string(json_object_object_get(ChangeConfiguration, "key")));
  8944. if((json_object_object_get(ChangeConfiguration, "value") != NULL) && (strlen(json_object_get_string(json_object_object_get(ChangeConfiguration, "value"))) < ARRAY_SIZE(valuestr)))
  8945. {
  8946. sprintf((char*)valuestr, "%s", json_object_get_string(json_object_object_get(ChangeConfiguration, "value")));
  8947. }
  8948. else
  8949. {
  8950. valueInvalid = YES;
  8951. DEBUG_ERROR("The ChangeConfiguration value is NULL or OVER SIZE.\n");
  8952. }
  8953. }
  8954. json_object_put(ChangeConfiguration);
  8955. if((uuid==NULL) || (payload ==NULL) || (valueInvalid==YES))
  8956. {
  8957. DEBUG_ERROR("Payload is null or value is invalid.\n");
  8958. sprintf(comfirmstr, "%s", ConfigurationStatusStr[ConfigurationStatus_Rejected] );
  8959. }
  8960. else
  8961. {
  8962. int status = setKeyValue(keystr, valuestr);
  8963. switch(status)
  8964. {
  8965. case ConfigurationStatus_Accepted:
  8966. sprintf(comfirmstr, "%s", ConfigurationStatusStr[ConfigurationStatus_Accepted]);
  8967. ShmOCPP16Data->MsMsg.bits.ChangeConfigurationReq = 1;
  8968. StoreConfigurationTable();
  8969. break;
  8970. case RebootRequired:
  8971. sprintf(comfirmstr, "%s", ConfigurationStatusStr[RebootRequired]);
  8972. StoreConfigurationTable();
  8973. break;
  8974. case NotSupported:
  8975. sprintf(comfirmstr, "%s", ConfigurationStatusStr[NotSupported] );
  8976. break;
  8977. case ConfigurationStatus_Rejected:
  8978. default:
  8979. sprintf(comfirmstr, "%s", ConfigurationStatusStr[ConfigurationStatus_Rejected] );
  8980. break;
  8981. }
  8982. }
  8983. sendChangeConfigurationConfirmation(uuid, comfirmstr);
  8984. ShmOCPP16Data->MsMsg.bits.ChangeConfigurationConf = 1;
  8985. if(((strcmp(keystr,"AuthorizationKey")==0) || (strcmp(keystr,"SecurityProfile")==0) || (strcmp(keystr,"OcppServer")==0) || (strcmp(keystr,"MaintainServer")==0)) && (strcmp(comfirmstr,"Accepted")==0))
  8986. {
  8987. StoreUsrConfigData(&ShmSysConfigAndInfo->SysConfig);
  8988. SetOcppConnStatus(FALSE);
  8989. }
  8990. if(((strcmp(keystr,"FreeVend")==0) || (strcmp(keystr,"isEnableLocalPowerSharing")==0) || (strcmp(keystr,"PowerSharingServerIP")==0)) && (strcmp(comfirmstr,"Accepted")==0))
  8991. {
  8992. StoreUsrConfigData(&ShmSysConfigAndInfo->SysConfig);
  8993. }
  8994. return result;
  8995. }
  8996. int handleClearCacheRequest(char *uuid, char *payload)
  8997. {
  8998. mtrace();
  8999. int result = FAIL;
  9000. char comfirmstr[20];
  9001. char rmFileCmd[100]={0};
  9002. struct stat stats;
  9003. DEBUG_INFO("handleClearCacheRequest...\n");
  9004. stat("/Storage/OCPP", &stats);
  9005. // Check for directory existence
  9006. if (S_ISDIR(stats.st_mode) == 1)
  9007. {}
  9008. else
  9009. {
  9010. DEBUG_INFO("\n OCPP directory not exist, create dir \n");
  9011. sprintf(rmFileCmd,"mkdir -p %s","/Storage/OCPP");
  9012. system(rmFileCmd);
  9013. }
  9014. if(OCPP_cleanLocalCache())
  9015. {
  9016. sprintf(comfirmstr, "%s", ClearCacheStatusStr[ClearCacheStatus_Accepted] );
  9017. }
  9018. else
  9019. {
  9020. sprintf(comfirmstr, "%s", ClearCacheStatusStr[ClearCacheStatus_Rejected] );
  9021. }
  9022. sendClearCacheConfirmation(uuid, comfirmstr);
  9023. system("/bin/fsync -d /dev/mtdblock13;/bin/sync &");
  9024. return result;
  9025. }
  9026. int handleClearChargingProfileRequest(char *uuid, char *payload)
  9027. {
  9028. mtrace();
  9029. int result = FAIL;
  9030. int resultRename;
  9031. int connectorIdInt, chargingProfileIdInt, stackLevelInt;
  9032. char chargingProfilePurposeStr[26]={0};
  9033. int tempconnectorIdInt, tempchargingProfileIdInt, tempstackLevelInt;
  9034. char tempchargingProfilePurposeStr[26]={0};
  9035. char str[100]={0};
  9036. char fname[200]={0};
  9037. char comfirmstr[20]={0};
  9038. char word[1600]={0};
  9039. int clearflag = FALSE;
  9040. int chargingProfileIdIsNULL = FALSE;
  9041. int connectorIsNULL = FALSE;
  9042. int chargingProfilePurposeIsNULL = FALSE;
  9043. int stackLevelIsNULL = FALSE;
  9044. //int GotoEnd = FALSE;
  9045. FILE *fptr1, *fptr2;
  9046. char temp[] = "/Storage/OCPP/ClearChargingProfiletemp.json"; // Create temp file
  9047. int n_chargingProfile=0;
  9048. int isEmptyFile = FALSE;
  9049. char sLineWord[1600]={0};
  9050. char chargingProfiles[10][100]={0};
  9051. int ChargeProfileCount = 0;
  9052. int ch;
  9053. connectorIdInt = chargingProfileIdInt = stackLevelInt = 0;
  9054. DEBUG_INFO("handleClearChargingProfileRequest...\n");
  9055. json_object *ClearChargingProfile;
  9056. ClearChargingProfile = json_tokener_parse(payload);
  9057. if(!is_error(ClearChargingProfile))
  9058. {
  9059. // Optional data
  9060. if(json_object_object_get(ClearChargingProfile, "id") != NULL)
  9061. chargingProfileIdInt = json_object_get_int(json_object_object_get(ClearChargingProfile, "id"));
  9062. else
  9063. chargingProfileIdIsNULL = TRUE;
  9064. if(json_object_object_get(ClearChargingProfile, "connectorId") != NULL)
  9065. connectorIdInt = json_object_get_int(json_object_object_get(ClearChargingProfile, "connectorId"));
  9066. else
  9067. connectorIsNULL = TRUE;
  9068. if(json_object_object_get(ClearChargingProfile, "chargingProfilePurpose") != NULL)
  9069. sprintf((char*)chargingProfilePurposeStr, "%s", json_object_get_string(json_object_object_get(ClearChargingProfile, "chargingProfilePurpose")));
  9070. else
  9071. chargingProfilePurposeIsNULL = TRUE;
  9072. if(json_object_object_get(ClearChargingProfile, "stackLevel") != NULL)
  9073. stackLevelInt = json_object_get_int(json_object_object_get(ClearChargingProfile, "stackLevel"));
  9074. else
  9075. stackLevelIsNULL = TRUE;
  9076. }
  9077. json_object_put(ClearChargingProfile);
  9078. if(connectorIsNULL == FALSE)
  9079. {
  9080. switch(connectorIdInt)
  9081. {
  9082. case 0:
  9083. if(chargingProfilePurposeIsNULL == TRUE)
  9084. {
  9085. int l = 0;
  9086. strcpy(fname, ChargePointMaxProfile_JSON);
  9087. if((access(fname,F_OK))!=-1)
  9088. {
  9089. strcpy(chargingProfiles[l], fname);
  9090. l = l + 1;
  9091. }
  9092. strcpy(fname, TxDefaultProfile_0_JSON);
  9093. if((access(fname,F_OK))!=-1)
  9094. {
  9095. strcpy(chargingProfiles[l], fname);
  9096. l = l + 1;
  9097. }
  9098. ChargeProfileCount = l;
  9099. }
  9100. else if((chargingProfilePurposeIsNULL == FALSE)&&(strcmp(chargingProfilePurposeStr,"ChargePointMaxProfile")==0))
  9101. {
  9102. strcpy(fname, ChargePointMaxProfile_JSON);
  9103. if((access(fname,F_OK))!=-1)
  9104. {
  9105. strcpy(chargingProfiles[0], fname);
  9106. ChargeProfileCount = 1;
  9107. }
  9108. }
  9109. else if((chargingProfilePurposeIsNULL == FALSE)&&(strcmp(chargingProfilePurposeStr,"TxDefaultProfile")==0))
  9110. {
  9111. strcpy(fname, TxDefaultProfile_0_JSON);
  9112. if((access(fname,F_OK))!=-1)
  9113. {
  9114. strcpy(chargingProfiles[0], fname);
  9115. ChargeProfileCount = 1;
  9116. }
  9117. }
  9118. break;
  9119. default:
  9120. if(chargingProfilePurposeIsNULL == TRUE)
  9121. {
  9122. int m = 0;
  9123. memset(fname, 0, ARRAY_SIZE(fname));
  9124. sprintf(fname, "/Storage/OCPP/TxDefaultProfile_%d.json", connectorIdInt);
  9125. if((access(fname,F_OK))!=-1)
  9126. {
  9127. strcpy(chargingProfiles[m], fname);
  9128. m = m + 1;
  9129. }
  9130. memset(fname, 0, ARRAY_SIZE(fname));
  9131. sprintf(fname, "/Storage/OCPP/TxProfile_%d.json", connectorIdInt);
  9132. if((access(fname,F_OK))!=-1)
  9133. {
  9134. strcpy(chargingProfiles[m], fname);
  9135. m = m + 1;
  9136. }
  9137. ChargeProfileCount = m;
  9138. }
  9139. else if((chargingProfilePurposeIsNULL == FALSE)&&(strcmp(chargingProfilePurposeStr,"TxDefaultProfile")==0))
  9140. {
  9141. //strcpy(fname, TxDefaultProfile_1_JSON);
  9142. sprintf(fname, "/Storage/OCPP/TxDefaultProfile_%d.json", connectorIdInt);
  9143. if((access(fname,F_OK))!=-1)
  9144. {
  9145. strcpy(chargingProfiles[0], fname);
  9146. ChargeProfileCount = 1;
  9147. }
  9148. }
  9149. else if((chargingProfilePurposeIsNULL == FALSE)&&(strcmp(chargingProfilePurposeStr,"TxProfile")==0))
  9150. {
  9151. sprintf(fname, "/Storage/OCPP/TxProfile_%d.json", connectorIdInt);
  9152. if((access(fname,F_OK))!=-1)
  9153. {
  9154. strcpy(chargingProfiles[0], fname);
  9155. ChargeProfileCount = 1;
  9156. }
  9157. //strcpy(fname, TxProfile_1_JSON);
  9158. }
  9159. //strcpy(fname, ChargePointMaxProfile_JSON );
  9160. break;
  9161. }
  9162. }
  9163. else // Check all Charging Profiles
  9164. {
  9165. int i = 0;
  9166. char fnametemp[200]={0};
  9167. ChargeProfileCount = 0;
  9168. //Check ChargePointMaxProfile.json exit
  9169. if((access("/Storage/OCPP/ChargePointMaxProfile.json",F_OK))!=-1)
  9170. {
  9171. strcpy(chargingProfiles[i], "/Storage/OCPP/ChargePointMaxProfile.json");
  9172. i = i + 1;
  9173. }
  9174. //Check TxDefaultProfile_0.json exit
  9175. if((access("/Storage/OCPP/TxDefaultProfile_0.json",F_OK))!=-1)
  9176. {
  9177. strcpy(chargingProfiles[i], "/Storage/OCPP/TxDefaultProfile_0.json");
  9178. i = i + 1;
  9179. }
  9180. //Check TxDefaultProfile_%d.json
  9181. for(int j=1; j <= gunTotalNumber; j++)
  9182. {
  9183. memset(fnametemp, 0, ARRAY_SIZE(fnametemp));
  9184. sprintf(fnametemp, "/Storage/OCPP/TxDefaultProfile_%d.json", j);
  9185. if((access(fnametemp,F_OK))!=-1)
  9186. {
  9187. strcpy(chargingProfiles[i], fnametemp);
  9188. i = i + 1;
  9189. }
  9190. }
  9191. //Check TxProfile_%d.json
  9192. for(int j=1; j <= gunTotalNumber; j++)
  9193. {
  9194. memset(fnametemp, 0, ARRAY_SIZE(fnametemp));
  9195. sprintf(fnametemp, "/Storage/OCPP/TxProfile_%d.json", j);
  9196. if((access(fnametemp,F_OK))!=-1)
  9197. {
  9198. strcpy(chargingProfiles[i], fnametemp);
  9199. i = i + 1;
  9200. }
  9201. }
  9202. ChargeProfileCount = i;
  9203. }// End connectorIsNULL is TRUE
  9204. if(ChargeProfileCount == 0)
  9205. {
  9206. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Unknown] );
  9207. goto end;
  9208. }
  9209. if(connectorIsNULL == FALSE && (connectorIdInt != 0) && ( (connectorIdInt-1) > gunTotalNumber) )
  9210. {
  9211. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Unknown] );
  9212. goto end;
  9213. }
  9214. if((connectorIsNULL == FALSE) && (connectorIdInt == 0) )
  9215. {
  9216. memset(str, 0, ARRAY_SIZE(str));
  9217. // clear temp file
  9218. sprintf(str,"rm -f %s",temp);
  9219. system(str);
  9220. for(int k=0; k < ChargeProfileCount; k++)
  9221. {
  9222. memset(str, 0, ARRAY_SIZE(str));
  9223. //clear file in C
  9224. sprintf(str,"rm -f %s",chargingProfiles[k]);
  9225. system(str);
  9226. }
  9227. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Accepted] );
  9228. goto end;
  9229. }
  9230. else if(connectorIsNULL == TRUE)
  9231. {
  9232. for(int k=0; k < ChargeProfileCount; k++)
  9233. {
  9234. fptr1 = fopen(chargingProfiles[k], "r");
  9235. fptr2 = fopen("/Storage/OCPP/ClearChargingProfiletemp.json", "w+");
  9236. //Check Charging Profile Count
  9237. while(fscanf(fptr1, "%s", word) != EOF)
  9238. {
  9239. //DEBUG_INFO("word=%s\n",word);
  9240. if(strstr(word, "chargingProfileId")!= NULL)
  9241. {
  9242. //DEBUG_INFO("test chargingProfileId \n");
  9243. n_chargingProfile = n_chargingProfile + 1;
  9244. //DEBUG_INFO("chargingProfileId Found\n");
  9245. }
  9246. }
  9247. rewind(fptr1);
  9248. //search Charging Profile Element
  9249. //int i= 0;
  9250. while ( fgets( sLineWord, sizeof sLineWord, fptr1 ) != NULL )
  9251. {
  9252. json_object *tmpProfilee;
  9253. tmpProfilee = json_tokener_parse(sLineWord);
  9254. if(!is_error(tmpProfilee))
  9255. {
  9256. if(json_object_object_get(tmpProfilee, "connectorId") != NULL)
  9257. {
  9258. tempconnectorIdInt = json_object_get_int(json_object_object_get(tmpProfilee, "connectorId"));
  9259. DEBUG_INFO("file's gun number: %d\n", tempconnectorIdInt);
  9260. }
  9261. if(json_object_object_get(json_object_object_get(tmpProfilee, "csChargingProfiles"), "chargingProfileId") != NULL)
  9262. {
  9263. tempchargingProfileIdInt = json_object_get_int(json_object_object_get(json_object_object_get(tmpProfilee, "csChargingProfiles"), "chargingProfileId"));
  9264. DEBUG_INFO("file's chargingProfileId: %d\n", tempchargingProfileIdInt);
  9265. }
  9266. if(json_object_object_get(json_object_object_get(tmpProfilee, "csChargingProfiles"), "stackLevel") != NULL)
  9267. {
  9268. tempstackLevelInt = json_object_get_int(json_object_object_get(json_object_object_get(tmpProfilee, "csChargingProfiles"), "stackLevel"));
  9269. DEBUG_INFO("file's stackLevel: %d\n", tempstackLevelInt);
  9270. }
  9271. if(json_object_object_get(json_object_object_get(tmpProfilee, "csChargingProfiles"), "chargingProfilePurpose") != NULL)
  9272. {
  9273. sprintf((char*)tempchargingProfilePurposeStr, "%s", json_object_get_string(json_object_object_get(json_object_object_get(tmpProfilee, "csChargingProfiles"), "chargingProfilePurpose")));
  9274. DEBUG_INFO("file's chargingProfilePurpose: %s\n", tempchargingProfilePurposeStr);
  9275. }
  9276. }
  9277. json_object_put(tmpProfilee);
  9278. if((chargingProfileIdIsNULL == FALSE)&&(tempchargingProfileIdInt == chargingProfileIdInt))
  9279. {
  9280. //------- not write to fptr2-------//
  9281. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Accepted] );
  9282. //clearflag = TRUE;
  9283. }
  9284. else if((chargingProfilePurposeIsNULL == FALSE)&&(strcmp(tempchargingProfilePurposeStr, chargingProfilePurposeStr) == 0))
  9285. {
  9286. //------- not write to fptr2-------//
  9287. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Accepted] );
  9288. }
  9289. else if((stackLevelIsNULL == FALSE) &&(tempstackLevelInt == stackLevelInt))
  9290. {
  9291. //------- not write to fptr2-------//
  9292. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Accepted] );
  9293. }
  9294. else if(chargingProfileIdIsNULL && chargingProfilePurposeIsNULL && stackLevelIsNULL)
  9295. {
  9296. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Accepted] );
  9297. }
  9298. else
  9299. {
  9300. fprintf(fptr2, sLineWord);//writing data into file
  9301. }
  9302. memset(sLineWord, 0, ARRAY_SIZE(sLineWord));
  9303. } //End of while ( fgets( sLineWord, sizeof sLineWord, fptr1 ) != NULL )
  9304. if(clearflag == TRUE)
  9305. {
  9306. fclose(fptr1);
  9307. fclose(fptr2);
  9308. sprintf(str,"rm -f %s",chargingProfiles[k]);
  9309. system(str);
  9310. // clear temp file
  9311. sprintf(str,"rm -f %s",temp);
  9312. system(str);
  9313. }
  9314. else
  9315. {
  9316. fclose(fptr1);
  9317. fclose(fptr2);
  9318. memset(str, 0, ARRAY_SIZE(str));
  9319. sprintf(str,"rm -f %s",chargingProfiles[k]);
  9320. system(str);
  9321. resultRename = rename(temp, chargingProfiles[k]);
  9322. if(resultRename == 0)
  9323. {
  9324. DEBUG_INFO("File ChargingProfile renamed successfully\n");
  9325. }
  9326. else
  9327. {
  9328. DEBUG_INFO("Error: unable to rename the ChargingProfile file\n");
  9329. }
  9330. if(comfirmstr[0]== 0)
  9331. {
  9332. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Unknown] );
  9333. }
  9334. //Check chargingProfile is empty file
  9335. /*------ Read the file ----------------*/
  9336. fptr1=fopen(chargingProfiles[k],"r");
  9337. ch=fgetc(fptr1);
  9338. rewind(fptr1);
  9339. memset(sLineWord, 0, ARRAY_SIZE(sLineWord));
  9340. if(ch!=EOF)
  9341. {
  9342. while (fgets( sLineWord, sizeof sLineWord, fptr1) != NULL)
  9343. {
  9344. str[strlen(sLineWord) - 1] = '\0'; // eat the newline fgets() stores
  9345. if(sLineWord[0]=='\0')
  9346. {
  9347. isEmptyFile = TRUE;
  9348. break;
  9349. }
  9350. else
  9351. {
  9352. isEmptyFile = FALSE;
  9353. break;
  9354. }
  9355. }
  9356. }
  9357. else
  9358. isEmptyFile = TRUE;
  9359. fclose(fptr1);
  9360. if(isEmptyFile == TRUE)
  9361. {
  9362. memset(str, 0, ARRAY_SIZE(str));
  9363. sprintf(str,"rm -f %s",chargingProfiles[k]);
  9364. system(str);
  9365. }
  9366. }
  9367. }// End of while(int k=0; k < ChargePointCount; k++)
  9368. }
  9369. else if((connectorIsNULL == FALSE) && (connectorIdInt != 0) )
  9370. {
  9371. DEBUG_INFO("ChargeProfileCount = %d\n", ChargeProfileCount);
  9372. for(int k=0; k < ChargeProfileCount; k++)
  9373. {
  9374. fptr1 = fopen(chargingProfiles[k], "r");
  9375. fptr2 = fopen(temp, "w+");
  9376. //Check Charging Profile Count
  9377. while(fscanf(fptr1, "%s", word) != EOF)
  9378. {
  9379. //DEBUG_INFO("word=%s\n",word);
  9380. if(strstr(word, "chargingProfileId")!= NULL)
  9381. {
  9382. n_chargingProfile = n_chargingProfile + 1;
  9383. }
  9384. }
  9385. rewind(fptr1);
  9386. //search Charging Profile Element
  9387. //int i= 0;
  9388. while ( fgets( sLineWord, sizeof sLineWord, fptr1 ) != NULL )
  9389. {
  9390. json_object *tmpProfilee;
  9391. tmpProfilee = json_tokener_parse(sLineWord);
  9392. if(!is_error(tmpProfilee))
  9393. {
  9394. if(json_object_object_get(tmpProfilee, "connectorId") != NULL)
  9395. {
  9396. tempconnectorIdInt = json_object_get_int(json_object_object_get(tmpProfilee, "connectorId"));
  9397. DEBUG_INFO("file's gun number: %d\n", tempconnectorIdInt);
  9398. }
  9399. if(json_object_object_get(json_object_object_get(tmpProfilee, "csChargingProfiles"), "chargingProfileId") != NULL)
  9400. {
  9401. tempchargingProfileIdInt = json_object_get_int(json_object_object_get(json_object_object_get(tmpProfilee, "csChargingProfiles"), "chargingProfileId"));
  9402. DEBUG_INFO("file's chargingProfileId: %d\n", tempchargingProfileIdInt);
  9403. }
  9404. if(json_object_object_get(json_object_object_get(tmpProfilee, "csChargingProfiles"), "stackLevel") != NULL)
  9405. {
  9406. tempstackLevelInt = json_object_get_int(json_object_object_get(json_object_object_get(tmpProfilee, "csChargingProfiles"), "stackLevel"));
  9407. DEBUG_INFO("file's stackLevel: %d\n", tempstackLevelInt);
  9408. }
  9409. if(json_object_object_get(json_object_object_get(tmpProfilee, "csChargingProfiles"), "chargingProfilePurpose") != NULL)
  9410. {
  9411. sprintf((char*)tempchargingProfilePurposeStr, "%s", json_object_get_string(json_object_object_get(json_object_object_get(tmpProfilee, "csChargingProfiles"), "chargingProfilePurpose")));
  9412. DEBUG_INFO("file's chargingProfilePurpose: %s\n", tempchargingProfilePurposeStr);
  9413. }
  9414. }
  9415. json_object_put(tmpProfilee);
  9416. if((chargingProfileIdIsNULL == FALSE)&&(tempchargingProfileIdInt == chargingProfileIdInt))
  9417. {
  9418. //------- not write to fptr2-------//
  9419. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Accepted] );
  9420. //clearflag = TRUE;
  9421. }
  9422. else if((stackLevelIsNULL == FALSE) &&(tempstackLevelInt == stackLevelInt))
  9423. {
  9424. //------- not write to fptr2-------//
  9425. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Accepted] );
  9426. }
  9427. else if(stackLevelIsNULL == TRUE)
  9428. {
  9429. //Clear Whole File
  9430. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Accepted] );
  9431. clearflag = TRUE;
  9432. break;
  9433. }
  9434. else
  9435. {
  9436. fprintf(fptr2, sLineWord);//writing data into file
  9437. }
  9438. memset(sLineWord, 0, ARRAY_SIZE(sLineWord));
  9439. }
  9440. if(clearflag == TRUE)
  9441. {
  9442. fclose(fptr1);
  9443. fclose(fptr2);
  9444. sprintf(str,"rm -f %s",chargingProfiles[k]);
  9445. system(str);
  9446. // clear temp file
  9447. sprintf(str,"rm -f %s",temp);
  9448. system(str);
  9449. }
  9450. else
  9451. {
  9452. fclose(fptr1);
  9453. fclose(fptr2);
  9454. sprintf(str,"rm -f %s",chargingProfiles[k]);
  9455. system(str);
  9456. resultRename = rename(temp, chargingProfiles[k]);
  9457. if(resultRename == 0)
  9458. {
  9459. DEBUG_INFO("File ChargingProfile renamed successfully");
  9460. }
  9461. else
  9462. {
  9463. DEBUG_INFO("Error: unable to rename the ChargingProfile file");
  9464. }
  9465. if(comfirmstr[0]== 0)
  9466. {
  9467. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Unknown] );
  9468. }
  9469. //Check chargingProfile is empty file
  9470. /*------ Read the file ----------------*/
  9471. fptr1=fopen(chargingProfiles[k],"r");
  9472. ch=fgetc(fptr1);
  9473. rewind(fptr1);
  9474. memset(sLineWord, 0, ARRAY_SIZE(sLineWord));
  9475. if(ch!=EOF)
  9476. {
  9477. while (fgets( sLineWord, sizeof sLineWord, fptr1) != NULL)
  9478. {
  9479. str[strlen(sLineWord) - 1] = '\0'; // eat the newline fgets() stores
  9480. if(sLineWord[0]=='\0')
  9481. {
  9482. isEmptyFile = TRUE;
  9483. break;
  9484. }
  9485. else
  9486. {
  9487. isEmptyFile = FALSE;
  9488. break;
  9489. }
  9490. }
  9491. }
  9492. else
  9493. isEmptyFile = TRUE;
  9494. fclose(fptr1);
  9495. if(isEmptyFile == TRUE)
  9496. {
  9497. memset(str, 0, ARRAY_SIZE(str));
  9498. sprintf(str,"rm -f %s",chargingProfiles[k]);
  9499. system(str);
  9500. }
  9501. /*------- End of reading ---------------*/
  9502. }
  9503. } // while(int k=0; k < ChargeProfileCount; k++)
  9504. }// (connectorIsNULL == FALSE) && (connectorIdInt != 0)
  9505. end:
  9506. if(strcmp(comfirmstr, ClearChargingProfileStatusStr[ClearChargingProfileStatus_Accepted]) == 0)
  9507. {
  9508. if(connectorIdInt == 0)
  9509. {
  9510. for(uint8_t idx=0;idx<gunTotalNumber;idx++)
  9511. {
  9512. checkCompositeSchedule((idx+1), 86400, &ShmOCPP16Data->SmartChargingProfile[idx], TRUE);
  9513. }
  9514. }
  9515. else
  9516. checkCompositeSchedule(connectorIdInt, 86400, &ShmOCPP16Data->SmartChargingProfile[connectorIdInt-1], TRUE);
  9517. }
  9518. sendClearChargingProfileConfirmation(uuid, comfirmstr);
  9519. system("/bin/fsync -d /dev/mtdblock13;/bin/sync &");
  9520. return result;
  9521. }
  9522. void createFirmwareVersionByDataTransfer(void)
  9523. {
  9524. json_object *FirmwareDataTransfer = json_object_new_object();
  9525. // AC & DC model
  9526. json_object_object_add(FirmwareDataTransfer, "CsuBootLoadFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.CsuBootLoadFwRev));
  9527. json_object_object_add(FirmwareDataTransfer, "CsuKernelFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.CsuKernelFwRev));
  9528. json_object_object_add(FirmwareDataTransfer, "CsuRootFsFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.CsuRootFsFwRev));
  9529. json_object_object_add(FirmwareDataTransfer, "CsuPrimFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.CsuPrimFwRev));
  9530. // DC model
  9531. if((ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D'))
  9532. {
  9533. if((gunType[1] != GUN_TYPE_UNKNOWN) ||
  9534. (gunType[2] != GUN_TYPE_UNKNOWN) ||
  9535. (gunType[3] != GUN_TYPE_UNKNOWN))
  9536. {
  9537. json_object_object_add(FirmwareDataTransfer, "Connector2FwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.Connector2FwRev));
  9538. }
  9539. if((ShmSysConfigAndInfo->SysConfig.ModelName[1]!='B') && (ShmSysConfigAndInfo->SysConfig.ModelName[1]!='K') && (ShmSysConfigAndInfo->SysConfig.ModelName[1]!='O'))
  9540. {
  9541. // DS DM DW
  9542. json_object_object_add(FirmwareDataTransfer, "FanModuleFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.FanModuleFwRev));
  9543. json_object_object_add(FirmwareDataTransfer, "RelayModuleFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.RelayModuleFwRev));
  9544. json_object_object_add(FirmwareDataTransfer, "LedModuleFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.LedModuleFwRev));
  9545. json_object_object_add(FirmwareDataTransfer, "Connector1FwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.Connector1FwRev));
  9546. json_object_object_add(FirmwareDataTransfer, "PsuPrimFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.PsuPrimFwRev));
  9547. json_object_object_add(FirmwareDataTransfer, "PsuSecFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.PsuSecFwRev));
  9548. }
  9549. else
  9550. {
  9551. json_object_object_add(FirmwareDataTransfer, "FanModuleFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.FanModuleFwRev));
  9552. json_object_object_add(FirmwareDataTransfer, "RelayModuleFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.RelayModuleFwRev));
  9553. json_object_object_add(FirmwareDataTransfer, "PsuPrimFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.PsuPrimFwRev));
  9554. json_object_object_add(FirmwareDataTransfer, "PsuSecFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.PsuSecFwRev));
  9555. json_object_object_add(FirmwareDataTransfer, "DD0_CsuBootLoadFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[0].CsuBootLoadFwRev));
  9556. json_object_object_add(FirmwareDataTransfer, "DD0_CsuKernelFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[0].CsuKernelFwRev));
  9557. json_object_object_add(FirmwareDataTransfer, "DD0_CsuRootFsFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[0].CsuRootFsFwRev));
  9558. json_object_object_add(FirmwareDataTransfer, "DD0_CsuPrimFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[0].CsuPrimFwRev));
  9559. json_object_object_add(FirmwareDataTransfer, "DD0_FanModuleFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[0].FanModuleFwRev));
  9560. json_object_object_add(FirmwareDataTransfer, "DD0_RelayModuleFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[0].RelayModuleFwRev));
  9561. json_object_object_add(FirmwareDataTransfer, "DD0_LedModuleFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[0].LedModuleFwRev));
  9562. json_object_object_add(FirmwareDataTransfer, "DD0_Connector1FwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[0].Connector1FwRev));
  9563. json_object_object_add(FirmwareDataTransfer, "DD0_Connector2FwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[0].Connector2FwRev));
  9564. if(strlen((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].CsuBootLoadFwRev) > 0)
  9565. json_object_object_add(FirmwareDataTransfer, "DD1_CsuBootLoadFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].CsuBootLoadFwRev));
  9566. if(strlen((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].CsuKernelFwRev) > 0)
  9567. json_object_object_add(FirmwareDataTransfer, "DD1_CsuKernelFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].CsuKernelFwRev));
  9568. if(strlen((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].CsuRootFsFwRev) > 0)
  9569. json_object_object_add(FirmwareDataTransfer, "DD1_CsuRootFsFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].CsuRootFsFwRev));
  9570. if(strlen((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].CsuPrimFwRev) > 0)
  9571. json_object_object_add(FirmwareDataTransfer, "DD1_CsuPrimFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].CsuPrimFwRev));
  9572. if(strlen((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].FanModuleFwRev) > 0)
  9573. json_object_object_add(FirmwareDataTransfer, "DD1_FanModuleFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].FanModuleFwRev));
  9574. if(strlen((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].RelayModuleFwRev) > 0)
  9575. json_object_object_add(FirmwareDataTransfer, "DD1_RelayModuleFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].RelayModuleFwRev));
  9576. if(strlen((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].LedModuleFwRev) > 0)
  9577. json_object_object_add(FirmwareDataTransfer, "DD1_LedModuleFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].LedModuleFwRev));
  9578. if(strlen((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].Connector1FwRev) > 0)
  9579. json_object_object_add(FirmwareDataTransfer, "DD1_Connector1FwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].Connector1FwRev));
  9580. if(strlen((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].Connector2FwRev) > 0)
  9581. json_object_object_add(FirmwareDataTransfer, "D11_Connector2FwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].Connector2FwRev));
  9582. }
  9583. }
  9584. // 4G model
  9585. if((ShmSysConfigAndInfo->SysConfig.ModelName[10]=='T')||(ShmSysConfigAndInfo->SysConfig.ModelName[10]=='D'))
  9586. {
  9587. json_object_object_add(FirmwareDataTransfer, "TelcomModemFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysConfig.TelecomInterface.TelcomSoftwareVer));
  9588. }
  9589. sprintf((char*)ShmOCPP16Data->DataTransfer[0].ResponseData, json_object_to_json_string_ext(FirmwareDataTransfer, JSON_C_TO_STRING_PLAIN));
  9590. json_object_put(FirmwareDataTransfer);
  9591. }
  9592. int handleDataTransferRequest(char *uuid, char *payload)
  9593. {
  9594. mtrace();
  9595. json_object *response = json_object_new_object();
  9596. int result = FAIL;
  9597. char tempvendorId[255]={0};
  9598. char tempmessageId[50]={0};
  9599. char tempdata[1024]={0};
  9600. char message[2048]={0};
  9601. DEBUG_INFO("handleDataTransferRequest...\n");
  9602. if((uuid != NULL) && (payload != NULL))
  9603. {
  9604. json_object *DataTransfer;
  9605. DataTransfer = json_tokener_parse(payload);
  9606. if(!is_error(DataTransfer))
  9607. {
  9608. // Required data
  9609. if(json_object_object_get(DataTransfer, "vendorId") != NULL)
  9610. sprintf((char*)tempvendorId, "%s", json_object_get_string(json_object_object_get(DataTransfer, "vendorId")));
  9611. // Optional data
  9612. if(json_object_object_get(DataTransfer, "messageId") != NULL)
  9613. sprintf((char*)tempmessageId, "%s", json_object_get_string(json_object_object_get(DataTransfer, "messageId")));
  9614. if(json_object_object_get(DataTransfer, "data") != NULL)
  9615. sprintf((char*)tempdata, "%s", json_object_get_string(json_object_object_get(DataTransfer, "data")));
  9616. result = PASS;
  9617. }
  9618. json_object_put(DataTransfer);
  9619. if(strstr(tempmessageId, "ID_FirmwareVersion") != NULL)
  9620. {
  9621. // Send all moudle firmware version on EVSE
  9622. createFirmwareVersionByDataTransfer();
  9623. json_object_object_add(response, "status", json_object_new_string("Accepted"));
  9624. json_object_object_add(response, "data", json_object_new_string((char*)ShmOCPP16Data->DataTransfer[0].ResponseData));
  9625. sprintf(message,"[%d,\"%s\",%s]",MESSAGE_TYPE_CALLRESULT, uuid, json_object_to_json_string_ext(response, JSON_C_TO_STRING_PLAIN));
  9626. json_object_put(response);
  9627. }
  9628. else if(strstr(tempmessageId, "ID_Tmate") != NULL)
  9629. {
  9630. system("/usr/bin/run_tmate_restart.sh &");
  9631. json_object_object_add(response, "status", json_object_new_string("Accepted"));
  9632. sprintf(message,"[%d,\"%s\",%s]",MESSAGE_TYPE_CALLRESULT, uuid, json_object_to_json_string_ext(response, JSON_C_TO_STRING_PLAIN));
  9633. json_object_put(response);
  9634. }
  9635. else if(strstr(tempmessageId, "ID_ChargingPreference") != NULL)
  9636. {
  9637. json_object *data;
  9638. data = json_tokener_parse(tempdata);
  9639. if(!is_error(data))
  9640. {
  9641. 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))
  9642. {
  9643. DEBUG_INFO("ChargeingPreference connector id: %d\n", json_object_get_int(json_object_object_get(data, "ConnectorId")));
  9644. memset(&ShmOCPP16Data->SessionTarget[json_object_get_int(json_object_object_get(data, "ConnectorId"))], 0x00, sizeof(struct StructSessionTarget));
  9645. if(json_object_object_get(data, "SOC") != NULL)
  9646. {
  9647. ShmOCPP16Data->SessionTarget[json_object_get_int(json_object_object_get(data, "ConnectorId"))-1].targetSoc = json_object_get_int(json_object_object_get(data, "SOC"));
  9648. DEBUG_INFO("ChargeingPreference target soc: %d\n", json_object_get_int(json_object_object_get(data, "SOC")));
  9649. }
  9650. if(json_object_object_get(data, "Energy") != NULL)
  9651. {
  9652. ShmOCPP16Data->SessionTarget[json_object_get_int(json_object_object_get(data, "ConnectorId"))-1].targetEnergy = json_object_get_int(json_object_object_get(data, "Energy"));
  9653. DEBUG_INFO("ChargeingPreference target energy: %d KWH\n", json_object_get_int(json_object_object_get(data, "Energy")));
  9654. }
  9655. if(json_object_object_get(data, "Duration") != NULL)
  9656. {
  9657. ShmOCPP16Data->SessionTarget[json_object_get_int(json_object_object_get(data, "ConnectorId"))-1].targetDuration = json_object_get_int(json_object_object_get(data, "Duration"));
  9658. DEBUG_INFO("ChargeingPreference target duration: %d minutes\n", json_object_get_int(json_object_object_get(data, "Duration")));
  9659. }
  9660. json_object_object_add(response, "status", json_object_new_string("Accepted"));
  9661. }
  9662. else
  9663. {
  9664. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  9665. json_object_object_add(response, "data", json_object_new_string("Connector id must > 0."));
  9666. }
  9667. }
  9668. else
  9669. {
  9670. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  9671. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  9672. }
  9673. json_object_put(data);
  9674. sprintf(message,"[%d,\"%s\",%s]",MESSAGE_TYPE_CALLRESULT, uuid, json_object_to_json_string_ext(response, JSON_C_TO_STRING_PLAIN));
  9675. json_object_put(response);
  9676. }
  9677. else if(strstr(tempmessageId, "SetLEDBar") != NULL)
  9678. {
  9679. json_object *data;
  9680. data = json_tokener_parse(tempdata);
  9681. if(!is_error(data))
  9682. {
  9683. ShmSysConfigAndInfo->SysConfig.LedInfo.Intensity = json_object_get_int(json_object_object_get(data, "Intensity"));
  9684. ShmSysConfigAndInfo->SysConfig.LedInfo.Red[0] = json_object_get_int(json_object_object_get(json_object_object_get(data, "Idle"), "R"));
  9685. ShmSysConfigAndInfo->SysConfig.LedInfo.Green[0]= json_object_get_int(json_object_object_get(json_object_object_get(data, "Idle"), "G"));
  9686. ShmSysConfigAndInfo->SysConfig.LedInfo.Blue[0] = json_object_get_int(json_object_object_get(json_object_object_get(data, "Idle"), "B"));
  9687. ShmSysConfigAndInfo->SysConfig.LedInfo.Red[1] = json_object_get_int(json_object_object_get(json_object_object_get(data, "Charging"), "R"));
  9688. ShmSysConfigAndInfo->SysConfig.LedInfo.Green[1]= json_object_get_int(json_object_object_get(json_object_object_get(data, "Charging"), "G"));
  9689. ShmSysConfigAndInfo->SysConfig.LedInfo.Blue[1] = json_object_get_int(json_object_object_get(json_object_object_get(data, "Charging"), "B"));
  9690. ShmSysConfigAndInfo->SysConfig.LedInfo.Red[2] = json_object_get_int(json_object_object_get(json_object_object_get(data, "Fault"), "R"));
  9691. ShmSysConfigAndInfo->SysConfig.LedInfo.Green[2]= json_object_get_int(json_object_object_get(json_object_object_get(data, "Fault"), "G"));
  9692. ShmSysConfigAndInfo->SysConfig.LedInfo.Blue[2] = json_object_get_int(json_object_object_get(json_object_object_get(data, "Fault"), "B"));
  9693. json_object_object_add(response, "status", json_object_new_string("Accepted"));
  9694. }
  9695. else
  9696. {
  9697. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  9698. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  9699. }
  9700. json_object_put(data);
  9701. sprintf(message,"[%d,\"%s\",%s]",MESSAGE_TYPE_CALLRESULT, uuid, json_object_to_json_string_ext(response, JSON_C_TO_STRING_PLAIN));
  9702. json_object_put(response);
  9703. }
  9704. else if(strstr(tempmessageId, "SetUserPrice") != NULL)
  9705. {
  9706. json_object *data;
  9707. data = json_tokener_parse(tempdata);
  9708. if(!is_error(data))
  9709. {
  9710. memset(&ShmOCPP16Data->Cost.SetUserPrice, 0x00, sizeof(struct StrcutSetUserPrice));
  9711. json_object_object_add(response, "status", json_object_new_string("Accepted"));
  9712. if(json_object_object_get(data, "idToken") != NULL)
  9713. {
  9714. sprintf((char*)ShmOCPP16Data->Cost.SetUserPrice.idToken, "%s", json_object_get_string(json_object_object_get(data, "idToken")));
  9715. DEBUG_INFO("idToken: %s\n", json_object_get_string(json_object_object_get(data, "idToken")));
  9716. }
  9717. else
  9718. {
  9719. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  9720. json_object_object_add(response, "data", json_object_new_string("idToken not found."));
  9721. }
  9722. if(json_object_object_get(data, "price") != NULL) //v1.0
  9723. {
  9724. sprintf((char*)ShmOCPP16Data->Cost.SetUserPrice.price, "%s", json_object_get_string(json_object_object_get(data, "price")));
  9725. DEBUG_INFO("price: %s\n", json_object_get_string(json_object_object_get(data, "price")));
  9726. }
  9727. else if(json_object_object_get(data, "priceText") != NULL) //v2.0
  9728. {
  9729. sprintf((char*)ShmOCPP16Data->Cost.SetUserPrice.price, "%s", json_object_get_string(json_object_object_get(data, "priceText")));
  9730. DEBUG_INFO("priceText: %s\n", json_object_get_string(json_object_object_get(data, "priceText")));
  9731. }
  9732. else
  9733. {
  9734. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  9735. json_object_object_add(response, "data", json_object_new_string("price or priceText not found."));
  9736. }
  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, "RunningCost") != NULL)
  9748. {
  9749. json_object *data;
  9750. data = json_tokener_parse(tempdata);
  9751. if(!is_error(data))
  9752. {
  9753. json_object_object_add(response, "status", json_object_new_string("Accepted"));
  9754. if(json_object_object_get(data, "txId") != NULL)
  9755. {
  9756. // California pricing V1.0
  9757. DEBUG_INFO("California pricing V1.0\n");
  9758. DEBUG_INFO("txId: %d\n", json_object_get_int(json_object_object_get(data, "txId")));
  9759. sprintf((char*)dmsVersion, "1.0");
  9760. for(int idx = 0;idx<gunTotalNumber;idx++)
  9761. {
  9762. if(ShmOCPP16Data->StartTransaction[idx].ResponseTransactionId == json_object_get_int(json_object_object_get(data, "txId")))
  9763. {
  9764. memset(&ShmOCPP16Data->Cost.RunningCost[idx], 0x00, sizeof(struct StrcutRunningCost));
  9765. ShmOCPP16Data->Cost.RunningCost[idx].txId = json_object_get_int(json_object_object_get(data, "txId"));
  9766. if(json_object_object_get(data, "description") != NULL)
  9767. {
  9768. DEBUG_INFO("description: %s\n", json_object_get_string(json_object_object_get(data, "description")));
  9769. sprintf((char*)ShmOCPP16Data->Cost.RunningCost[idx].description, "%s", json_object_get_string(json_object_object_get(data, "description")));
  9770. }
  9771. else
  9772. {
  9773. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  9774. json_object_object_add(response, "data", json_object_new_string("description not found."));
  9775. }
  9776. }
  9777. }
  9778. }
  9779. else if(json_object_object_get(data, "transactionId") != NULL)
  9780. {
  9781. // California pricing V2.0
  9782. DEBUG_INFO("California pricing V2.0\n");
  9783. DEBUG_INFO("transactionId: %d\n", json_object_get_int(json_object_object_get(data, "transactionId")));
  9784. sprintf((char*)dmsVersion, "2.0");
  9785. for(int idx=0;idx<gunTotalNumber;idx++)
  9786. {
  9787. if(ShmOCPP16Data->StartTransaction[idx].ResponseTransactionId == json_object_get_int(json_object_object_get(data, "transactionId")))
  9788. {
  9789. ShmOCPP16Data->Cost.RunningCost[idx].txId = json_object_get_int(json_object_object_get(data, "transactionId"));
  9790. if(json_object_object_get(data, "timestamp") != NULL)
  9791. {
  9792. DEBUG_INFO("timestamp: %s\n", json_object_get_string(json_object_object_get(data, "timestamp")));
  9793. sprintf((char*)ShmOCPP16Data->Cost.RunningCost[idx].timestamp, "%s", json_object_get_string(json_object_object_get(data, "timestamp")));
  9794. }
  9795. else
  9796. {
  9797. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  9798. json_object_object_add(response, "data", json_object_new_string("timestamp not found."));
  9799. }
  9800. if(json_object_object_get(data, "meterValue") != NULL)
  9801. {
  9802. DEBUG_INFO("meterValue: %d\n", json_object_get_int(json_object_object_get(data, "meterValue")));
  9803. ShmOCPP16Data->Cost.RunningCost[idx].meterValue = json_object_get_int(json_object_object_get(data, "meterValue"));
  9804. }
  9805. else
  9806. {
  9807. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  9808. json_object_object_add(response, "data", json_object_new_string("meterValue not found."));
  9809. }
  9810. if(json_object_object_get(data, "cost") != NULL)
  9811. {
  9812. DEBUG_INFO("cost: %f\n", json_object_get_double(json_object_object_get(data, "cost")));
  9813. ShmOCPP16Data->Cost.RunningCost[idx].cost = json_object_get_double(json_object_object_get(data, "cost"));
  9814. }
  9815. else
  9816. {
  9817. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  9818. json_object_object_add(response, "data", json_object_new_string("cost not found."));
  9819. }
  9820. if(json_object_object_get(data, "state") != NULL)
  9821. {
  9822. DEBUG_INFO("state: %s\n", json_object_get_string(json_object_object_get(data, "state")));
  9823. sprintf((char*)ShmOCPP16Data->Cost.RunningCost[idx].state, "%s", json_object_get_string(json_object_object_get(data, "state")));
  9824. }
  9825. else
  9826. {
  9827. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  9828. json_object_object_add(response, "data", json_object_new_string("state not found."));
  9829. }
  9830. if(json_object_object_get(data, "chargingPrice") != NULL)
  9831. {
  9832. if(json_object_object_get(json_object_object_get(data, "chargingPrice"), "kWhPrice") != NULL)
  9833. {
  9834. DEBUG_INFO("chargingPrice-kWhPrice: %f\n", json_object_get_double(json_object_object_get(json_object_object_get(data, "chargingPrice"), "kWhPrice")));
  9835. ShmOCPP16Data->Cost.RunningCost[idx].chargingPrice.kWhPrice = json_object_get_double(json_object_object_get(json_object_object_get(data, "chargingPrice"), "kWhPrice"));
  9836. }
  9837. if(json_object_object_get(json_object_object_get(data, "chargingPrice"), "hourPrice") != NULL)
  9838. {
  9839. DEBUG_INFO("chargingPrice-hourPrice: %f\n", json_object_get_double(json_object_object_get(json_object_object_get(data, "chargingPrice"), "hourPrice")));
  9840. ShmOCPP16Data->Cost.RunningCost[idx].chargingPrice.hourPrice = json_object_get_double(json_object_object_get(json_object_object_get(data, "chargingPrice"), "hourPrice"));
  9841. }
  9842. if(json_object_object_get(json_object_object_get(data, "chargingPrice"), "flatFee") != NULL)
  9843. {
  9844. DEBUG_INFO("chargingPrice-flatFee: %f\n", json_object_get_double(json_object_object_get(json_object_object_get(data, "chargingPrice"), "flatFee")));
  9845. ShmOCPP16Data->Cost.RunningCost[idx].chargingPrice.flatFee = json_object_get_double(json_object_object_get(json_object_object_get(data, "chargingPrice"), "flatFee"));
  9846. }
  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("chargingPrice not found."));
  9852. }
  9853. if(json_object_object_get(data, "idlePrice") != NULL)
  9854. {
  9855. if(json_object_object_get(json_object_object_get(data, "idlePrice"), "graceMinutes") != NULL)
  9856. {
  9857. DEBUG_INFO("idlePrice-graceMinutes: %d\n", json_object_get_int(json_object_object_get(json_object_object_get(data, "idlePrice"), "graceMinutes")));
  9858. ShmOCPP16Data->Cost.RunningCost[idx].idlePrice.graceMinutes = json_object_get_int(json_object_object_get(json_object_object_get(data, "idlePrice"), "graceMinutes"));
  9859. }
  9860. if(json_object_object_get(json_object_object_get(data, "idlePrice"), "hourPrice") != NULL)
  9861. {
  9862. DEBUG_INFO("idlePrice-hourPrice: %f\n", json_object_get_double(json_object_object_get(json_object_object_get(data, "idlePrice"), "hourPrice")));
  9863. ShmOCPP16Data->Cost.RunningCost[idx].idlePrice.hourPrice = json_object_get_double(json_object_object_get(json_object_object_get(data, "idlePrice"), "hourPrice"));
  9864. }
  9865. }
  9866. if(json_object_object_get(data, "nextPeriod") != NULL)
  9867. {
  9868. if(json_object_object_get(json_object_object_get(data, "nextPeriod"), "atTime") != NULL)
  9869. {
  9870. DEBUG_INFO("nextPeriod-atTime: %s\n", json_object_get_string(json_object_object_get(json_object_object_get(data, "nextPeriod"), "atTime")));
  9871. sprintf((char*)ShmOCPP16Data->Cost.RunningCost[idx].nextPeriod.atTime, "%s", json_object_get_string(json_object_object_get(json_object_object_get(data, "nextPeriod"), "atTime")));
  9872. }
  9873. else
  9874. {
  9875. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  9876. json_object_object_add(response, "data", json_object_new_string("atTime not found."));
  9877. }
  9878. if(json_object_object_get(json_object_object_get(data, "nextPeriod"), "chargingPrice") != NULL)
  9879. {
  9880. if(json_object_object_get(json_object_object_get(json_object_object_get(data, "nextPeriod"), "chargingPrice"), "kWhPrice") != NULL)
  9881. {
  9882. 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")));
  9883. 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"));
  9884. }
  9885. if(json_object_object_get(json_object_object_get(json_object_object_get(data, "nextPeriod"), "chargingPrice"), "hourPrice") != NULL)
  9886. {
  9887. 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")));
  9888. 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"));
  9889. }
  9890. if(json_object_object_get(json_object_object_get(json_object_object_get(data, "nextPeriod"), "chargingPrice"), "flatFee") != NULL)
  9891. {
  9892. 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")));
  9893. 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"));
  9894. }
  9895. }
  9896. else
  9897. {
  9898. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  9899. json_object_object_add(response, "data", json_object_new_string("chargingPrice not found."));
  9900. }
  9901. if(json_object_object_get(json_object_object_get(data, "nextPeriod"), "idlePrice") != NULL)
  9902. {
  9903. if(json_object_object_get(json_object_object_get(json_object_object_get(data, "nextPeriod"), "idlePrice"), "graceMinutes") != NULL)
  9904. {
  9905. 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")));
  9906. 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"));
  9907. }
  9908. if(json_object_object_get(json_object_object_get(json_object_object_get(data, "nextPeriod"), "idlePrice"), "hourPrice") != NULL)
  9909. {
  9910. 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")));
  9911. 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"));
  9912. }
  9913. }
  9914. }
  9915. if(json_object_object_get(data, "triggerMeterValue") != NULL)
  9916. {
  9917. if(json_object_object_get(json_object_object_get(data, "triggerMeterValue"), "atTime") != NULL)
  9918. {
  9919. DEBUG_INFO("triggerMeterValue-atTime: %s\n", json_object_get_string(json_object_object_get(json_object_object_get(data, "triggerMeterValue"), "atTime")));
  9920. sprintf((char*)ShmOCPP16Data->Cost.RunningCost[idx].triggerMeterValue.atTime, "%s", json_object_get_string(json_object_object_get(json_object_object_get(data, "triggerMeterValue"), "atTime")));
  9921. }
  9922. if(json_object_object_get(json_object_object_get(data, "triggerMeterValue"), "atEnergykWh") != NULL)
  9923. {
  9924. DEBUG_INFO("triggerMeterValue-atEnergykWh: %f\n", json_object_get_double(json_object_object_get(json_object_object_get(data, "triggerMeterValue"), "atEnergykWh")));
  9925. ShmOCPP16Data->Cost.RunningCost[idx].triggerMeterValue.atEnergykWh = json_object_get_double(json_object_object_get(json_object_object_get(data, "triggerMeterValue"), "atEnergykWh"));
  9926. }
  9927. if(json_object_object_get(json_object_object_get(data, "triggerMeterValue"), "atPowerkW") != NULL)
  9928. {
  9929. DEBUG_INFO("triggerMeterValue-atPowerkW: %f\n", json_object_get_double(json_object_object_get(json_object_object_get(data, "triggerMeterValue"), "atPowerkW")));
  9930. ShmOCPP16Data->Cost.RunningCost[idx].triggerMeterValue.atPowerkW = json_object_get_double(json_object_object_get(json_object_object_get(data, "triggerMeterValue"), "atPowerkW"));
  9931. }
  9932. if(json_object_object_get(json_object_object_get(data, "triggerMeterValue"), "atCPStatus") != NULL)
  9933. {
  9934. DEBUG_INFO("triggerMeterValue-atCPStatus: %s\n", json_object_get_string(json_object_object_get(json_object_object_get(data, "triggerMeterValue"), "atCPStatus")));
  9935. sprintf((char*)ShmOCPP16Data->Cost.RunningCost[idx].triggerMeterValue.atCPStatus, "%s", json_object_get_string(json_object_object_get(json_object_object_get(data, "triggerMeterValue"), "atCPStatus")));
  9936. }
  9937. }
  9938. }
  9939. }
  9940. }
  9941. else
  9942. {
  9943. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  9944. json_object_object_add(response, "data", json_object_new_string("txId or transactionId not found."));
  9945. }
  9946. }
  9947. else
  9948. {
  9949. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  9950. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  9951. }
  9952. json_object_put(data);
  9953. sprintf(message,"[%d,\"%s\",%s]",MESSAGE_TYPE_CALLRESULT, uuid, json_object_to_json_string_ext(response, JSON_C_TO_STRING_PLAIN));
  9954. json_object_put(response);
  9955. }
  9956. else if(strstr(tempmessageId, "FinalCost") != NULL)
  9957. {
  9958. json_object *data;
  9959. data = json_tokener_parse(tempdata);
  9960. if(!is_error(data))
  9961. {
  9962. json_object_object_add(response, "status", json_object_new_string("Accepted"));
  9963. if(json_object_object_get(data, "txId") != NULL)
  9964. {
  9965. DEBUG_INFO("v1.0 txId: %d\n", json_object_get_int(json_object_object_get(data, "txId")));
  9966. for(int idx = 0;idx<gunTotalNumber;idx++)
  9967. {
  9968. if(ShmOCPP16Data->StartTransaction[idx].ResponseTransactionId == json_object_get_int(json_object_object_get(data, "txId")))
  9969. {
  9970. memset(&ShmOCPP16Data->Cost.FinalCost[idx], 0x00, sizeof(struct StrcutFinalCost));
  9971. ShmOCPP16Data->Cost.FinalCost[idx].txId = json_object_get_int(json_object_object_get(data, "txId"));
  9972. if(json_object_object_get(data, "description") != NULL)
  9973. {
  9974. DEBUG_INFO("description: %s\n", json_object_get_string(json_object_object_get(data, "description")));
  9975. sprintf((char*)ShmOCPP16Data->Cost.FinalCost[idx].description, "%s", json_object_get_string(json_object_object_get(data, "description")));
  9976. }
  9977. else
  9978. {
  9979. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  9980. json_object_object_add(response, "data", json_object_new_string("description not found."));
  9981. }
  9982. }
  9983. }
  9984. }
  9985. else if(json_object_object_get(data, "transactionId") != NULL)
  9986. {
  9987. DEBUG_INFO("v2.0 transactionId: %d\n", json_object_get_int(json_object_object_get(data, "transactionId")));
  9988. for(int idx = 0;idx<gunTotalNumber;idx++)
  9989. {
  9990. if(ShmOCPP16Data->StartTransaction[idx].ResponseTransactionId == json_object_get_int(json_object_object_get(data, "transactionId")))
  9991. {
  9992. memset(&ShmOCPP16Data->Cost.FinalCost[idx], 0x00, sizeof(struct StrcutFinalCost));
  9993. ShmOCPP16Data->Cost.FinalCost[idx].txId = json_object_get_int(json_object_object_get(data, "transactionId"));
  9994. if(json_object_object_get(data, "cost") != NULL)
  9995. {
  9996. DEBUG_INFO("cost: %s\n", json_object_get_string(json_object_object_get(data, "cost")));
  9997. ShmOCPP16Data->Cost.FinalCost[idx].cost = json_object_get_double(json_object_object_get(data, "cost"));
  9998. }
  9999. else
  10000. {
  10001. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  10002. json_object_object_add(response, "data", json_object_new_string("cost not found."));
  10003. }
  10004. if(json_object_object_get(data, "priceText") != NULL)
  10005. {
  10006. DEBUG_INFO("priceText: %s\n", json_object_get_string(json_object_object_get(data, "priceText")));
  10007. sprintf((char*)ShmOCPP16Data->Cost.FinalCost[idx].priceText, "%s", json_object_get_string(json_object_object_get(data, "priceText")));
  10008. }
  10009. else
  10010. {
  10011. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  10012. json_object_object_add(response, "data", json_object_new_string("priceText not found."));
  10013. }
  10014. if(json_object_object_get(data, "qrCodeText") != NULL)
  10015. {
  10016. DEBUG_INFO(": %s\n", json_object_get_string(json_object_object_get(data, "qrCodeText")));
  10017. sprintf((char*)ShmOCPP16Data->Cost.FinalCost[idx].qrCodeText, "%s", json_object_get_string(json_object_object_get(data, "qrCodeText")));
  10018. }
  10019. }
  10020. }
  10021. }
  10022. else
  10023. {
  10024. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  10025. json_object_object_add(response, "data", json_object_new_string("txId or transactionId not found."));
  10026. }
  10027. }
  10028. else
  10029. {
  10030. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  10031. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  10032. }
  10033. json_object_put(data);
  10034. sprintf(message,"[%d,\"%s\",%s]",MESSAGE_TYPE_CALLRESULT, uuid, json_object_to_json_string_ext(response, JSON_C_TO_STRING_PLAIN));
  10035. json_object_put(response);
  10036. }
  10037. else if(strstr(tempmessageId, "ID_ConfigQR") != NULL)
  10038. {
  10039. json_object *data;
  10040. data = json_tokener_parse(tempdata);
  10041. if(!is_error(data))
  10042. {
  10043. json_object_object_add(response, "status", json_object_new_string("Accepted"));
  10044. if(json_object_object_get(data, "Content_Type") != NULL)
  10045. {
  10046. 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))
  10047. {
  10048. ShmSysConfigAndInfo->SysConfig.QRCodeMadeMode = json_object_get_int(json_object_object_get(data, "Content_Type"));
  10049. if(json_object_object_get(data, "Customization_Conent") != NULL)
  10050. {
  10051. sprintf((char*)ShmSysConfigAndInfo->SysConfig.QRCodeContent, "%s", json_object_get_string(json_object_object_get(data, "Customization_Conent")));
  10052. }
  10053. }
  10054. else
  10055. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  10056. }
  10057. StoreUsrConfigData(&ShmSysConfigAndInfo->SysConfig);
  10058. }
  10059. else
  10060. {
  10061. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  10062. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  10063. }
  10064. json_object_put(data);
  10065. sprintf(message,"[%d,\"%s\",%s]",MESSAGE_TYPE_CALLRESULT, uuid, json_object_to_json_string_ext(response, JSON_C_TO_STRING_PLAIN));
  10066. json_object_put(response);
  10067. }
  10068. else if(strstr(tempmessageId, "ID_LineStatusPage") != NULL)
  10069. {
  10070. json_object *data;
  10071. data = json_tokener_parse(tempdata);
  10072. if(!is_error(data))
  10073. {
  10074. json_object_object_add(response, "status", json_object_new_string("Accepted"));
  10075. if(json_object_object_get(data, "ConnectorId") != NULL)
  10076. {
  10077. ShmSysConfigAndInfo->SysInfo.LcdOveride.connectorId = json_object_get_int(json_object_object_get(data, "ConnectorId"));
  10078. }
  10079. if(json_object_object_get(data, "SerialNo") != NULL)
  10080. {
  10081. sprintf((char *)ShmOCPP16Data->TcciCustomData.SerialNo[(ShmSysConfigAndInfo->SysInfo.LcdOveride.connectorId-1)], "%s", json_object_get_string(json_object_object_get(data,"SerialNo")));
  10082. }
  10083. if(json_object_object_get(data, "Page_Index") != NULL)
  10084. {
  10085. ShmSysConfigAndInfo->SysInfo.LcdOveride.page_index = json_object_get_int(json_object_object_get(data, "Page_Index"));
  10086. }
  10087. if(json_object_object_get(data, "Duration") != NULL)
  10088. {
  10089. ShmSysConfigAndInfo->SysInfo.LcdOveride.duration = json_object_get_int(json_object_object_get(data, "Duration"));
  10090. }
  10091. ShmSysConfigAndInfo->SysInfo.LcdOveride.isOverideReq = 1;
  10092. }
  10093. else
  10094. {
  10095. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  10096. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  10097. }
  10098. json_object_put(data);
  10099. sprintf(message,"[%d,\"%s\",%s]",MESSAGE_TYPE_CALLRESULT, uuid, json_object_to_json_string_ext(response, JSON_C_TO_STRING_PLAIN));
  10100. json_object_put(response);
  10101. }
  10102. else if(strstr(tempmessageId, "ID_CpConfiguration") != NULL)
  10103. {
  10104. json_object *data;
  10105. data = json_tokener_parse(tempdata);
  10106. if(!is_error(data))
  10107. {
  10108. json_object_object_add(response, "status", json_object_new_string("Accepted"));
  10109. if(json_object_object_get(data, "MaxChargingCurrent") != NULL)
  10110. {
  10111. if(json_object_get_int(json_object_object_get(data, "MaxChargingCurrent")) >= 0)
  10112. ShmSysConfigAndInfo->SysConfig.MaxChargingCurrent = json_object_get_int(json_object_object_get(data, "MaxChargingCurrent"));
  10113. else
  10114. {
  10115. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  10116. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  10117. }
  10118. }
  10119. if(json_object_object_get(data, "MaxChargingDuration") != NULL)
  10120. {
  10121. if(json_object_get_int(json_object_object_get(data, "MaxChargingDuration")) >= 0)
  10122. ShmSysConfigAndInfo->SysConfig.MaxChargingDuration = json_object_get_int(json_object_object_get(data, "MaxChargingDuration"));
  10123. else
  10124. {
  10125. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  10126. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  10127. }
  10128. }
  10129. if(json_object_object_get(data, "MaxChargingEnergy") != NULL)
  10130. {
  10131. if(json_object_get_int(json_object_object_get(data, "MaxChargingEnergy")) >= 0)
  10132. ShmSysConfigAndInfo->SysConfig.MaxChargingEnergy = json_object_get_int(json_object_object_get(data, "MaxChargingEnergy"));
  10133. else
  10134. {
  10135. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  10136. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  10137. }
  10138. }
  10139. if(json_object_object_get(data, "MaxChargingPower") != NULL)
  10140. {
  10141. if(json_object_get_int(json_object_object_get(data, "MaxChargingPower")) >= 0)
  10142. ShmSysConfigAndInfo->SysConfig.MaxChargingPower = json_object_get_int(json_object_object_get(data, "MaxChargingPower"));
  10143. else
  10144. {
  10145. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  10146. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  10147. }
  10148. }
  10149. if(json_object_object_get(data, "OfflineMaxChargeEnergy") != NULL)
  10150. {
  10151. if(json_object_get_int(json_object_object_get(data, "OfflineMaxChargeEnergy")) >= 0)
  10152. ShmSysConfigAndInfo->SysConfig.OfflineMaxChargeEnergy = json_object_get_int(json_object_object_get(data, "OfflineMaxChargeEnergy"));
  10153. else
  10154. {
  10155. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  10156. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  10157. }
  10158. }
  10159. if(json_object_object_get(data, "OfflinePolicy") != NULL)
  10160. {
  10161. if((json_object_get_int(json_object_object_get(data, "OfflinePolicy")) == 0) ||
  10162. (json_object_get_int(json_object_object_get(data, "OfflinePolicy")) == 2) ||
  10163. (json_object_get_int(json_object_object_get(data, "OfflinePolicy")) == 3))
  10164. ShmSysConfigAndInfo->SysConfig.OfflinePolicy = json_object_get_int(json_object_object_get(data, "OfflinePolicy"));
  10165. else
  10166. {
  10167. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  10168. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  10169. }
  10170. }
  10171. if(json_object_object_get(data, "isAuthentication") != NULL)
  10172. {
  10173. switch(json_object_get_int(json_object_object_get(data, "isAuthentication")))
  10174. {
  10175. case 0:
  10176. case 1:
  10177. ShmSysConfigAndInfo->SysConfig.AuthorisationMode = json_object_get_int(json_object_object_get(data, "isAuthentication"))^1;
  10178. break;
  10179. default:
  10180. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  10181. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  10182. break;
  10183. }
  10184. }
  10185. if(strstr(json_object_get_string(json_object_object_get(response, "status")), "Accepted") != NULL)
  10186. StoreUsrConfigData(&ShmSysConfigAndInfo->SysConfig);
  10187. }
  10188. else
  10189. {
  10190. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  10191. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  10192. }
  10193. json_object_put(data);
  10194. sprintf(message,"[%d,\"%s\",%s]",MESSAGE_TYPE_CALLRESULT, uuid, json_object_to_json_string_ext(response, JSON_C_TO_STRING_PLAIN));
  10195. json_object_put(response);
  10196. }
  10197. else if(strstr(tempmessageId, "ID_TxEnergy") != NULL)
  10198. {
  10199. json_object *data;
  10200. data = json_tokener_parse(tempdata);
  10201. if(!is_error(data))
  10202. {
  10203. if((json_object_object_get(data, "ConnectorId") != NULL) && (json_object_object_get(data, "txId") != NULL))
  10204. {
  10205. if(OCPP_getPeriodEnergyToDataTransfer(json_object_get_int(json_object_object_get(data, "txId"))) == PASS)
  10206. {
  10207. json_object_object_add(response, "status", json_object_new_string("Accepted"));
  10208. json_object_object_add(response, "data", json_object_new_string((char*)ShmOCPP16Data->DataTransfer[0].ResponseData));
  10209. }
  10210. else
  10211. {
  10212. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  10213. json_object_object_add(response, "data", json_object_new_string("Present charged energy data can not get."));
  10214. }
  10215. }
  10216. else
  10217. {
  10218. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  10219. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  10220. }
  10221. }
  10222. else
  10223. {
  10224. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  10225. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  10226. }
  10227. sprintf(message,"[%d,\"%s\",%s]",MESSAGE_TYPE_CALLRESULT, uuid, json_object_to_json_string_ext(response, JSON_C_TO_STRING_PLAIN));
  10228. json_object_put(response);
  10229. }
  10230. else if(strstr(tempmessageId, "ID_Station_Location") != NULL)
  10231. {
  10232. json_object *data;
  10233. data = json_tokener_parse(tempdata);
  10234. if(!is_error(data))
  10235. {
  10236. json_object_object_add(response, "status", json_object_new_string("Accepted"));
  10237. if(json_object_object_get(data, "stationName") != NULL)
  10238. {
  10239. sprintf((char *)ShmOCPP16Data->TcciCustomData.ChargerInfo.station_name, "%s", json_object_get_string(json_object_object_get(data,"stationName")));
  10240. }
  10241. else
  10242. {
  10243. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  10244. json_object_object_add(response, "data", json_object_new_string("station_name data can not get."));
  10245. }
  10246. if(strcmp(json_object_get_string(json_object_object_get(response,"status")),"Accepted")==0)
  10247. {
  10248. ShmOCPP16Data->TcciCustomData.ChargerInfoReq = 1;
  10249. DEBUG_INFO("<<< ID_Station_Location:{station_name:%s}\n",
  10250. ShmOCPP16Data->TcciCustomData.ChargerInfo.station_name);
  10251. }
  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("charger_info content got something wrong."));
  10257. }
  10258. sprintf(message,"[%d,\"%s\",%s]",MESSAGE_TYPE_CALLRESULT, uuid, json_object_to_json_string_ext(response, JSON_C_TO_STRING_PLAIN));
  10259. json_object_put(response);
  10260. }
  10261. else if(strstr(tempmessageId, "ID_Weather_Info") != NULL)
  10262. {
  10263. json_object *data;
  10264. data = json_tokener_parse(tempdata);
  10265. if(!is_error(data))
  10266. {
  10267. json_object_object_add(response, "status", json_object_new_string("Accepted"));
  10268. if(json_object_object_get(data, "weatherId") != NULL)
  10269. {
  10270. ShmOCPP16Data->TcciCustomData.WeatherInfo.weatherId = json_object_get_int(json_object_object_get(data, "weatherId"));
  10271. }
  10272. else
  10273. {
  10274. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  10275. json_object_object_add(response, "data", json_object_new_string("weather data can not get."));
  10276. }
  10277. if(json_object_object_get(data, "Temperature") != NULL)
  10278. {
  10279. ShmOCPP16Data->TcciCustomData.WeatherInfo.temperature = json_object_get_double(json_object_object_get(data,"Temperature"));
  10280. }
  10281. else
  10282. {
  10283. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  10284. json_object_object_add(response, "data", json_object_new_string("temperature data can not get."));
  10285. }
  10286. if(strcmp(json_object_get_string(json_object_object_get(response,"status")),"Accepted")==0)
  10287. {
  10288. ShmOCPP16Data->TcciCustomData.WeatherInfoReq = 1;
  10289. DEBUG_INFO("<<< ID_Weather_Info:{weather:%d, temperature:%.1f}\n",
  10290. ShmOCPP16Data->TcciCustomData.WeatherInfo.weatherId,
  10291. ShmOCPP16Data->TcciCustomData.WeatherInfo.temperature
  10292. );
  10293. }
  10294. }
  10295. else
  10296. {
  10297. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  10298. json_object_object_add(response, "data", json_object_new_string("weather_info content got something wrong."));
  10299. }
  10300. sprintf(message,"[%d,\"%s\",%s]",MESSAGE_TYPE_CALLRESULT, uuid, json_object_to_json_string_ext(response, JSON_C_TO_STRING_PLAIN));
  10301. json_object_put(response);
  10302. }
  10303. else if(strstr(tempmessageId, "ID_TriggerCreditReader") != NULL)
  10304. {
  10305. json_object *data;
  10306. data = json_tokener_parse(tempdata);
  10307. if(!is_error(data))
  10308. {
  10309. json_object_object_add(response, "status", json_object_new_string("Accepted"));
  10310. if(json_object_get_int(json_object_object_get(data, "ConnectorId")) > 0)
  10311. {
  10312. ShmOCPP16Data->TcciCustomData.TriggerReaderReq[json_object_get_int(json_object_object_get(data, "ConnectorId")) -1] = TRUE;
  10313. DEBUG_INFO("<<< ID_TriggerCreditReader:{ConnectorId: %d}\n", json_object_get_int(json_object_object_get(data, "ConnectorId")));
  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("ConnectorId does not valid."));
  10319. }
  10320. }
  10321. else
  10322. {
  10323. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  10324. json_object_object_add(response, "data", json_object_new_string("charger_info content got something wrong."));
  10325. }
  10326. sprintf(message,"[%d,\"%s\",%s]",MESSAGE_TYPE_CALLRESULT, uuid, json_object_to_json_string_ext(response, JSON_C_TO_STRING_PLAIN));
  10327. json_object_put(response);
  10328. }
  10329. else if(strstr(tempmessageId, "ID_GetTxUserInfo") != NULL)
  10330. {
  10331. json_object *data;
  10332. data = json_tokener_parse(tempdata);
  10333. if(!is_error(data))
  10334. {
  10335. if((json_object_object_get(data, "ConnectorId") != NULL) && (json_object_object_get(data, "txId") != NULL))
  10336. {
  10337. int gun_index = json_object_get_int(json_object_object_get(data, "ConnectorId"))-1;
  10338. json_object_object_add(response, "status", json_object_new_string("Accepted"));
  10339. if(gun_index < gunTotalNumber)
  10340. {
  10341. if(ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId == json_object_get_int(json_object_object_get(data, "txId")))
  10342. {
  10343. json_object *responsedata = json_object_new_object();
  10344. json_object_object_add(responsedata, "txId", json_object_new_int(ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId));
  10345. json_object_object_add(responsedata, "ConnectorId", json_object_new_int(gun_index+1));
  10346. json_object_object_add(responsedata, "SerialNo", json_object_new_string((char*)ShmOCPP16Data->TcciCustomData.SerialNo[gun_index]));
  10347. json_object_object_add(responsedata, "StartTime", json_object_new_string((char*)ShmOCPP16Data->StartTransaction[gun_index].Timestamp));
  10348. json_object_object_add(responsedata, "VEMData", json_object_new_string((char*)ShmOCPP16Data->TcciCustomData.VEMData[gun_index]));
  10349. json_object_object_add(response, "data", json_object_new_string(json_object_to_json_string_ext(responsedata, JSON_C_TO_STRING_PLAIN)));
  10350. }
  10351. else
  10352. {
  10353. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  10354. json_object_object_add(response, "data", json_object_new_string("txId doesn't match the current transactionId."));
  10355. }
  10356. }
  10357. else
  10358. {
  10359. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  10360. json_object_object_add(response, "data", json_object_new_string("ConnectorId is invalid."));
  10361. }
  10362. }
  10363. else
  10364. {
  10365. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  10366. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  10367. }
  10368. }
  10369. else
  10370. {
  10371. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  10372. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  10373. }
  10374. sprintf(message,"[%d,\"%s\",%s]",MESSAGE_TYPE_CALLRESULT, uuid, json_object_to_json_string_ext(response, JSON_C_TO_STRING_PLAIN));
  10375. json_object_put(response);
  10376. }
  10377. else
  10378. {
  10379. // Can not find valid message id
  10380. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\",\"data\":\"vendorId-%s messageId-%s data-%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, "UnknownMessageId", tempvendorId, tempmessageId, tempdata);
  10381. }
  10382. }
  10383. else
  10384. {
  10385. // Payload is null
  10386. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\",\"data\":\"{}\"}]",MESSAGE_TYPE_CALLRESULT, uuid, "UnknownMessageId");
  10387. }
  10388. LWS_Send(message);
  10389. return result;
  10390. }
  10391. int handleGetCompositeScheduleRequest(char *uuid, char *payload)
  10392. {
  10393. mtrace();
  10394. int result = FAIL;
  10395. int connectorIdInt, durationInt;
  10396. char chargingRateUnitStr[4]={0};
  10397. char comfirmstr[20];
  10398. int confirmPeriods = 0;
  10399. DEBUG_INFO("handleGetCompositeScheduleRequest...\n");
  10400. json_object *GetCompositeSchedule;
  10401. GetCompositeSchedule = json_tokener_parse(payload);
  10402. if(!is_error(GetCompositeSchedule))
  10403. {
  10404. // Required data
  10405. if(json_object_object_get(GetCompositeSchedule, "connectorId") != NULL)
  10406. connectorIdInt = json_object_get_int(json_object_object_get(GetCompositeSchedule, "connectorId"));
  10407. else
  10408. connectorIdInt = -1;
  10409. if(json_object_object_get(GetCompositeSchedule, "duration"))
  10410. durationInt = json_object_get_int(json_object_object_get(GetCompositeSchedule, "duration"));
  10411. else
  10412. durationInt = 86400;
  10413. // Optional data
  10414. if(json_object_object_get(GetCompositeSchedule, "chargingRateUnit") != NULL)
  10415. sprintf((char*)chargingRateUnitStr, "%s", json_object_get_string(json_object_object_get(GetCompositeSchedule, "chargingRateUnit")));
  10416. }
  10417. json_object_put(GetCompositeSchedule);
  10418. memset(ShmOCPP16Data->GetCompositeSchedule, 0, sizeof(struct StructChargingSchedulePeriod)*gunTotalNumber);
  10419. if((connectorIdInt == 0) ||
  10420. ((connectorIdInt > 0) && ((connectorIdInt -1) < gunTotalNumber)))
  10421. {
  10422. int gun_index = (connectorIdInt==0?0:connectorIdInt-1);
  10423. struct StructChargingProfile tmpProfile[1];
  10424. if(strstr(chargingRateUnitStr, "W") != NULL)
  10425. checkCompositeSchedule(connectorIdInt, durationInt, &tmpProfile[0], FALSE);
  10426. else
  10427. checkCompositeSchedule(connectorIdInt, durationInt, &tmpProfile[0], TRUE);
  10428. for(int idx=0;idx<ARRAY_SIZE(ShmOCPP16Data->GetCompositeSchedule[gun_index].ResponseChargingSchedule.ChargingSchedulePeriod);idx++)
  10429. {
  10430. DEBUG_INFO("Smart Period-%02d start: %d\n", idx, tmpProfile[0].ChargingSchedule.ChargingSchedulePeriod[idx].StartPeriod);
  10431. DEBUG_INFO("Smart Period-%02d limit: %f\n", idx, tmpProfile[0].ChargingSchedule.ChargingSchedulePeriod[idx].Limit);
  10432. }
  10433. ShmOCPP16Data->GetCompositeSchedule[gun_index].ResponseConnectorId = connectorIdInt;
  10434. memcpy(&ShmOCPP16Data->GetCompositeSchedule[gun_index].ResponseChargingSchedule, &tmpProfile[0].ChargingSchedule, sizeof(struct StructChargingSchedule));
  10435. memcpy(&ShmOCPP16Data->GetCompositeSchedule[gun_index].ResponseScheduleStart ,&tmpProfile[0].ChargingSchedule.StartSchedule, ARRAY_SIZE(tmpProfile[0].ChargingSchedule.StartSchedule));
  10436. for(int idx=0;idx<ARRAY_SIZE(ShmOCPP16Data->GetCompositeSchedule[gun_index].ResponseChargingSchedule.ChargingSchedulePeriod);idx++)
  10437. {
  10438. DEBUG_INFO("Composite Period-%02d start: %d\n", idx, ShmOCPP16Data->GetCompositeSchedule[gun_index].ResponseChargingSchedule.ChargingSchedulePeriod[idx].StartPeriod);
  10439. DEBUG_INFO("Composite Period-%02d limit: %f\n", idx, ShmOCPP16Data->GetCompositeSchedule[gun_index].ResponseChargingSchedule.ChargingSchedulePeriod[idx].Limit);
  10440. if((ShmOCPP16Data->GetCompositeSchedule[gun_index].ResponseChargingSchedule.ChargingSchedulePeriod[idx].StartPeriod==0) &&
  10441. (ShmOCPP16Data->GetCompositeSchedule[gun_index].ResponseChargingSchedule.ChargingSchedulePeriod[idx].Limit==0) &&
  10442. (idx<(ARRAY_SIZE(ShmOCPP16Data->GetCompositeSchedule[gun_index].ResponseChargingSchedule.ChargingSchedulePeriod)-1)?(ShmOCPP16Data->GetCompositeSchedule[gun_index].ResponseChargingSchedule.ChargingSchedulePeriod[idx+1].StartPeriod==0):TRUE))
  10443. {
  10444. confirmPeriods = idx;
  10445. break;
  10446. }
  10447. }
  10448. if((confirmPeriods == 0) && (tmpProfile[0].ChargingProfileId > 0))
  10449. {
  10450. confirmPeriods += 1;
  10451. }
  10452. sprintf(comfirmstr, "%s", GetCompositeScheduleStatusStr[GetCompositeScheduleStatus_Accepted] );
  10453. }
  10454. else
  10455. {
  10456. sprintf(comfirmstr, "%s", GetCompositeScheduleStatusStr[GetCompositeScheduleStatus_Rejected] );
  10457. }
  10458. sendGetCompositeScheduleConfirmation(uuid, comfirmstr, connectorIdInt, confirmPeriods);
  10459. return result;
  10460. }
  10461. int handleGetConfigurationRequest(char *uuid, char *payload)
  10462. {
  10463. mtrace();
  10464. int result = FAIL;
  10465. int MaxKeySupported = 0;
  10466. int n_keys = 0;
  10467. char requestKey[GetConfigurationMaxKeysNUM][50]={0};
  10468. DEBUG_INFO("handleGetConfigurationRequest...\n");
  10469. json_object *GetConfiguration;
  10470. GetConfiguration = json_tokener_parse(payload);
  10471. if(!is_error(GetConfiguration))
  10472. {
  10473. // Optional data
  10474. if(json_object_object_get(GetConfiguration, "key") != NULL)
  10475. {
  10476. for(int idx=0;idx<json_object_array_length(json_object_object_get(GetConfiguration, "key"));idx++)
  10477. {
  10478. sprintf((char*)requestKey[idx], "%s", json_object_get_string(json_object_array_get_idx(json_object_object_get(GetConfiguration, "key"), idx)));
  10479. n_keys = idx + 1;
  10480. }
  10481. }
  10482. }
  10483. json_object_put(GetConfiguration);
  10484. UnknownKeynum = 0;
  10485. memset( (void *)unknownkey, 0, sizeof(unknownkey));
  10486. MaxKeySupported = GetConfigurationMaxKeysNUM;
  10487. memset(ShmOCPP16Data->GetConfiguration.Key, 0 ,sizeof(struct StructConfigurationKeyItems)*MaxKeySupported);
  10488. memset(ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey, 0, sizeof(struct StructConfigurationKey)*MaxKeySupported);
  10489. if(n_keys != 0)
  10490. {
  10491. for(int i=0;i<n_keys;i++)
  10492. {
  10493. getKeyValue(requestKey[i]);
  10494. }
  10495. }
  10496. else
  10497. {
  10498. DEBUG_INFO("There is no key in Message, get all configuration\n");
  10499. getKeyValue("");
  10500. }
  10501. processUnkownKey();
  10502. sendGetConfigurationConfirmation(uuid);
  10503. return result;
  10504. }
  10505. static char fnamePlusPath[100]={0};
  10506. static char fnamePWithNoPath[60]={0};
  10507. void checkUploadLog(void)
  10508. {
  10509. FILE *fp;
  10510. /* Open the command for reading. */
  10511. fp = popen("find /mnt/ -type f -name \"*.zip\" |xargs ls -t", "r");
  10512. if (fp == NULL) {
  10513. DEBUG_WARN("Failed to run command\n" );
  10514. exit(1);
  10515. }
  10516. int ftppathlen = 0;
  10517. memset(fnamePlusPath, 0, ARRAY_SIZE(fnamePlusPath));
  10518. int i = 0;
  10519. /* Read the output a line at a time - output it. */
  10520. while (fgets(fnamePlusPath, sizeof(fnamePlusPath), fp) != NULL) {
  10521. if(i==0)
  10522. {
  10523. ftppathlen = strlen(fnamePlusPath);
  10524. DEBUG_INFO("%s\n", fnamePlusPath);
  10525. fnamePlusPath[ftppathlen]='\0';
  10526. break;
  10527. }
  10528. i= i+1;
  10529. }
  10530. /* close */
  10531. pclose(fp);
  10532. for(int k=0; k< ARRAY_SIZE(fnamePlusPath); k++)
  10533. {
  10534. if((fnamePlusPath[k]=='\n') || (fnamePlusPath[k]=='\r'))
  10535. {
  10536. fnamePlusPath[k]='\0';
  10537. }
  10538. }
  10539. i=1;
  10540. //char fname[60]={0};
  10541. while(i < ftppathlen)
  10542. {
  10543. int len=ftppathlen-i;
  10544. if(fnamePlusPath[len]== 47) // '/' ascll code: 47
  10545. {
  10546. DEBUG_INFO("compare '/' all right\n");
  10547. break;
  10548. }
  10549. i=i+1;
  10550. }
  10551. memset(fnamePWithNoPath, 0, ARRAY_SIZE(fnamePWithNoPath));
  10552. strncpy(fnamePWithNoPath, fnamePlusPath+(ftppathlen-i+1), i+1);
  10553. fnamePWithNoPath[i+1] = '\0';
  10554. for(int j=0; j< ARRAY_SIZE(fnamePWithNoPath); j++)
  10555. {
  10556. if((fnamePWithNoPath[j]=='\n') || (fnamePWithNoPath[j]=='r'))
  10557. {
  10558. fnamePWithNoPath[j]='\0';
  10559. }
  10560. }
  10561. FILE* fp1 = fopen(fnamePlusPath, "r");
  10562. if (fp1)
  10563. {
  10564. DEBUG_INFO("testfuc : fnamePlusPath=%s exist.\n", fnamePlusPath);
  10565. // file exists
  10566. fclose(fp1);
  10567. }
  10568. else
  10569. {
  10570. // file doesn't exist
  10571. DEBUG_WARN("testfuc : fnamePlusPath=%s not exist!\n", fnamePlusPath);
  10572. }
  10573. }
  10574. int handleGetDiagnosticsRequest(char *uuid, char *payload)
  10575. {
  10576. mtrace();
  10577. int result = FAIL;
  10578. time_t CurrentTime;
  10579. struct tm *tm;
  10580. pthread_t th_Status;
  10581. CurrentTime = time(NULL);
  10582. tm = localtime(&CurrentTime);
  10583. memset(ShmOCPP16Data->GetDiagnostics.ResponseFileName, 0x00, ARRAY_SIZE(ShmOCPP16Data->GetDiagnostics.ResponseFileName));
  10584. 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);
  10585. sendGetDiagnosticsConfirmation(uuid, (char*)ShmOCPP16Data->GetDiagnostics.ResponseFileName);
  10586. if(!interLock.isGetDiagnosticGoing)
  10587. {
  10588. interLock.isGetDiagnosticGoing = 1;
  10589. pthread_create(&th_Status, NULL, GetDiagnosticsProcess, stringtrimspace(payload));
  10590. sleep(1);
  10591. }
  10592. else
  10593. DEBUG_WARN("Other GetDiagnostic request on going.\n");
  10594. return result;
  10595. }
  10596. void* GetDiagnosticsProcess(void* data)
  10597. {
  10598. pthread_detach(pthread_self());
  10599. mtrace();
  10600. int retriesInt=0, retryIntervalInt=0;
  10601. char locationstr[1024]={0}, startTimestr[30]={0}, stopTimestr[30]={0} ;
  10602. 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};
  10603. int port=0;
  10604. int isSuccess = FALSE;
  10605. char cmdBuf[2048];
  10606. struct tm *tmNow;
  10607. time_t CurrentTime;
  10608. struct tm tmStart;
  10609. struct tm tmStop;
  10610. CurrentTime = time(NULL);
  10611. tmNow=localtime(&CurrentTime);
  10612. uint16_t targetYear, targetMonth;
  10613. json_object *GetDiagnostics;
  10614. DEBUG_INFO("GetDiagnosticsProcess...\n");
  10615. GetDiagnostics = json_tokener_parse(data);
  10616. if(!is_error(GetDiagnostics))
  10617. {
  10618. // Required data
  10619. if(json_object_object_get(GetDiagnostics, "location") != NULL)
  10620. sprintf(locationstr, "%s", json_object_get_string(json_object_object_get(GetDiagnostics, "location")));
  10621. // Optional data
  10622. if(json_object_object_get(GetDiagnostics, "retries") != NULL)
  10623. retriesInt = json_object_get_int(json_object_object_get(GetDiagnostics, "retries"));
  10624. else
  10625. retriesInt = 3; // If this field is not present, it is left to Charge Point to decide how many times it wants to retry.
  10626. if(json_object_object_get(GetDiagnostics, "retryInterval") != NULL)
  10627. retryIntervalInt = json_object_get_int(json_object_object_get(GetDiagnostics, "retryInterval"));
  10628. else
  10629. retryIntervalInt = 30;
  10630. if(json_object_object_get(GetDiagnostics, "startTime") != NULL)
  10631. sprintf(startTimestr, "%s", json_object_get_string(json_object_object_get(GetDiagnostics, "startTime")));
  10632. if(json_object_object_get(GetDiagnostics, "stopTime") != NULL)
  10633. sprintf(stopTimestr, "%s", json_object_get_string(json_object_object_get(GetDiagnostics, "stopTime")));
  10634. }
  10635. json_object_put(GetDiagnostics);
  10636. // Pack log to compress file
  10637. 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) &&
  10638. (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))
  10639. {
  10640. // Pack system log
  10641. memset(cmdBuf, 0x00, ARRAY_SIZE(cmdBuf));
  10642. sprintf(cmdBuf, "exec zip -9 --password %04d%02d%s /mnt/system.zip", tmNow->tm_year+1900, tmNow->tm_mon+1, ShmSysConfigAndInfo->SysConfig.SerialNumber);
  10643. targetYear = tmStart.tm_year;
  10644. targetMonth = tmStart.tm_mon;
  10645. do
  10646. {
  10647. sprintf(cmdBuf, "%s /Storage/SystemLog/*%04d*%02d*", cmdBuf, targetYear, targetMonth);
  10648. sprintf(cmdBuf, "%s /Storage/OCPP/*%04d*%02d*SystemLog*", cmdBuf, targetYear, targetMonth);
  10649. if(targetMonth+1>=13)
  10650. {
  10651. targetYear += 1;
  10652. targetMonth = 1;
  10653. }
  10654. else
  10655. {
  10656. targetMonth += 1;
  10657. }
  10658. }while((targetYear < (tmNow->tm_year+1900)) ||
  10659. ((targetYear <= (tmNow->tm_year+1900)) && (targetMonth <= (tmNow->tm_mon+1))));
  10660. sprintf(cmdBuf, "%s /Storage/CCS*.zip", cmdBuf);
  10661. sprintf(cmdBuf, "%s /Storage/OCPP/*.db", cmdBuf);
  10662. system(cmdBuf);
  10663. // Pack charging & event log
  10664. memset(cmdBuf, 0x00, ARRAY_SIZE(cmdBuf));
  10665. sprintf(cmdBuf, "exec zip -9 /mnt/charging_event.zip");
  10666. targetYear = tmStart.tm_year;
  10667. targetMonth = tmStart.tm_mon;
  10668. do
  10669. {
  10670. sprintf(cmdBuf, "%s /Storage/EventLog/*%04d*%02d*", cmdBuf, targetYear, targetMonth);
  10671. sprintf(cmdBuf, "%s /Storage/OCPP/*%04d*%02d*OcppMessageLog*", cmdBuf, targetYear, targetMonth);
  10672. if(targetMonth+1>=13)
  10673. {
  10674. targetYear += 1;
  10675. targetMonth = 1;
  10676. }
  10677. else
  10678. {
  10679. targetMonth += 1;
  10680. }
  10681. }while((targetYear < (tmNow->tm_year+1900)) ||
  10682. ((targetYear <= (tmNow->tm_year+1900)) && (targetMonth <= (tmNow->tm_mon+1))));
  10683. sprintf(cmdBuf, "%s /Storage/ChargeLog/*.db", cmdBuf);
  10684. sprintf(cmdBuf, "%s /Storage/EventLog/*.db", cmdBuf);
  10685. system(cmdBuf);
  10686. // Combine log file
  10687. system("exec zip -9 /mnt/log.zip /mnt/system.zip /mnt/charging_event.zip");
  10688. system("exec rm -f /mnt/system.zip /mnt/charging_event.zip");
  10689. }
  10690. else
  10691. {
  10692. system("exec /root/logPackTools 'log' 6");
  10693. }
  10694. sprintf(cmdBuf, "mv /mnt/log.zip /mnt/%s", ShmOCPP16Data->GetDiagnostics.ResponseFileName);
  10695. system(cmdBuf);
  10696. checkUploadLog();
  10697. //****************location*******************/
  10698. if(strcmp(locationstr,"")==0)
  10699. {
  10700. DEBUG_INFO("location is <Empty>!\n");
  10701. sprintf((char*)ShmOCPP16Data->DiagnosticsStatusNotification.Status, "%s", DiagnosticsStatusStr[DiagnosticsStatus_UploadFailed]);
  10702. ShmOCPP16Data->SpMsg.bits.DiagnosticsStatusNotificationReq = 1;
  10703. goto end;
  10704. }
  10705. memset(protocol, 0, ARRAY_SIZE(protocol));
  10706. memset(user, 0, ARRAY_SIZE(user) );
  10707. memset(password, 0, ARRAY_SIZE(password));
  10708. memset(host, 0, ARRAY_SIZE(host));
  10709. memset(path, 0, ARRAY_SIZE(path));
  10710. memset(ftppath, 0, ARRAY_SIZE(ftppath));
  10711. memset(host1, 0, ARRAY_SIZE(host1));
  10712. memset(path1, 0, ARRAY_SIZE(path1));
  10713. /*location: ftp://user:password@host:port/path*/
  10714. //DEBUG_INFO("fnamePlusPath =%s\n",fnamePlusPath);
  10715. if((access(fnamePlusPath,F_OK))!=-1)
  10716. {
  10717. DEBUG_INFO("fnamePlusPath exist.\n");
  10718. }
  10719. else
  10720. {
  10721. DEBUG_INFO("fnamePlusPath not exist!\n");
  10722. sprintf((char*)ShmOCPP16Data->DiagnosticsStatusNotification.Status, "%s", DiagnosticsStatusStr[DiagnosticsStatus_UploadFailed]);
  10723. ShmOCPP16Data->SpMsg.bits.DiagnosticsStatusNotificationReq = 1;
  10724. goto end;
  10725. }
  10726. if(strchr(locationstr,'@')==NULL)
  10727. {
  10728. sscanf(locationstr,
  10729. "%[^:]:%*2[/]%[^:]:%i/%[a-zA-Z0-9._/-]",
  10730. protocol, host, &port, path);
  10731. strcpy(user,"anonymous");
  10732. strcpy(password,"");
  10733. }
  10734. else
  10735. {
  10736. //DEBUG_INFO("pch=%s\n", pch);
  10737. sscanf(locationstr,"%[^:]:%*2[/]%[^:]:%[^@]@%[^:]:%i/%199[^\n]",
  10738. protocol, user, password, host, &port, path);
  10739. }
  10740. if((strcmp(protocol,"ftp")!=0)&&(strcmp(protocol,"http")!=0)&&(strcmp(protocol,"https")!=0))
  10741. {
  10742. DEBUG_INFO("protocol is not ftp/http ! \n");
  10743. sprintf((char*)ShmOCPP16Data->DiagnosticsStatusNotification.Status, "%s", DiagnosticsStatusStr[DiagnosticsStatus_UploadFailed]);
  10744. ShmOCPP16Data->SpMsg.bits.DiagnosticsStatusNotificationReq = 1;
  10745. goto end;
  10746. }
  10747. if(strncmp(locationstr,"http", 4) == 0)
  10748. {
  10749. sscanf(locationstr,"%[^:]:%*2[/]%[^/]/%199[^\n]", protocol, host, path);
  10750. sprintf(ftppath,"/%s", path);
  10751. do
  10752. {
  10753. sprintf((char*)ShmOCPP16Data->DiagnosticsStatusNotification.Status, "%s", DiagnosticsStatusStr[DiagnosticsStatus_Uploading]);
  10754. ShmOCPP16Data->SpMsg.bits.DiagnosticsStatusNotificationReq = 1;
  10755. sleep(3);
  10756. isSuccess = httpUploadFile(host, ftppath, fnamePlusPath, locationstr);
  10757. if(!isSuccess)
  10758. {
  10759. DEBUG_INFO("Diagnostics fail.\n");
  10760. sprintf((char*)ShmOCPP16Data->DiagnosticsStatusNotification.Status, "%s", DiagnosticsStatusStr[DiagnosticsStatus_UploadFailed]);
  10761. ShmOCPP16Data->SpMsg.bits.DiagnosticsStatusNotificationReq = 1;
  10762. sleep(retryIntervalInt);
  10763. }
  10764. else
  10765. {
  10766. DEBUG_INFO("sendDiagnosticsStatusNotificationRequest Uploaded\n");
  10767. sprintf((char*)ShmOCPP16Data->DiagnosticsStatusNotification.Status, "%s", DiagnosticsStatusStr[DiagnosticsStatus_Uploaded]);
  10768. ShmOCPP16Data->SpMsg.bits.DiagnosticsStatusNotificationReq = 1;
  10769. }
  10770. retriesInt--;
  10771. }while((isSuccess == 0)&&(retriesInt >= 0));
  10772. }
  10773. else
  10774. {
  10775. sscanf(host,"%[^/]%s",host1, path1);
  10776. if(strlen(path) > 0)
  10777. sprintf(ftppath,"/%s", path);
  10778. else
  10779. sprintf(ftppath,"/%s", path1);
  10780. int ftppathlen=strlen(ftppath);
  10781. int i=1;
  10782. char filenametemp[50];
  10783. while(i < ftppathlen)
  10784. {
  10785. int len=ftppathlen-i;
  10786. if(ftppath[len]== 47) // '/' ascll code: 47
  10787. {
  10788. DEBUG_INFO("find '/' all right\n");
  10789. break;
  10790. }
  10791. i=i+1;
  10792. }
  10793. memset(filenametemp, 0, ARRAY_SIZE(filenametemp));
  10794. strncpy(filenametemp, ftppath+(ftppathlen-i+1), i+1);
  10795. filenametemp[i+1] = 0;
  10796. if(port == 0)
  10797. port = 21;
  10798. do
  10799. {
  10800. sprintf((char*)ShmOCPP16Data->DiagnosticsStatusNotification.Status, "%s", DiagnosticsStatusStr[DiagnosticsStatus_Uploading]);
  10801. ShmOCPP16Data->SpMsg.bits.DiagnosticsStatusNotificationReq = 1;
  10802. sleep(3);
  10803. isSuccess = ftpUploadFile(host1, user, password, port, ftppath, fnamePlusPath, fnamePWithNoPath);
  10804. if(!isSuccess)
  10805. {
  10806. DEBUG_INFO("Diagnostics fail.\n");
  10807. sprintf((char*)ShmOCPP16Data->DiagnosticsStatusNotification.Status, "%s", DiagnosticsStatusStr[DiagnosticsStatus_UploadFailed]);
  10808. ShmOCPP16Data->SpMsg.bits.DiagnosticsStatusNotificationReq = 1;
  10809. sleep(retryIntervalInt);
  10810. }
  10811. else
  10812. {
  10813. DEBUG_INFO("sendDiagnosticsStatusNotificationRequest Uploaded\n");
  10814. sprintf((char*)ShmOCPP16Data->DiagnosticsStatusNotification.Status, "%s", DiagnosticsStatusStr[DiagnosticsStatus_Uploaded]);
  10815. ShmOCPP16Data->SpMsg.bits.DiagnosticsStatusNotificationReq = 1;
  10816. }
  10817. retriesInt--;
  10818. }while((!isSuccess)&&(retriesInt >= 0));
  10819. }
  10820. end:
  10821. system("rm -f /mnt/*");
  10822. sleep(5);
  10823. sprintf((char*)ShmOCPP16Data->DiagnosticsStatusNotification.Status, "%s", DiagnosticsStatusStr[DiagnosticsStatus_Idle]);
  10824. ShmOCPP16Data->SpMsg.bits.DiagnosticsStatusNotificationReq = 1;
  10825. interLock.isGetDiagnosticGoing = 0;
  10826. pthread_exit(NULL);
  10827. }
  10828. int handleGetLocalListVersionRequest(char *uuid, char *payload)
  10829. {
  10830. mtrace();
  10831. int result = FAIL;
  10832. DEBUG_INFO("handle GetLocalListVersionRequest\n");
  10833. if(strcmp((const char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "FALSE") == 0)
  10834. {
  10835. DEBUG_INFO("LocalAuthListEnabled is FALSE \n");
  10836. locallistVersion = -1;
  10837. }
  10838. else
  10839. {
  10840. DEBUG_INFO("handle GetLocalListVersionRequest OCPP_getListVerion \n");
  10841. locallistVersion = 0;
  10842. OCPP_getListVerion();
  10843. }
  10844. //from db.OCPP_getListVerion
  10845. ShmOCPP16Data->GetLocalListVersion.ResponseListVersion = locallistVersion;
  10846. //ShmOCPP16Data->MsMsg.bits.GetLocalListVersionReq = 1;
  10847. sendGetLocalListVersionConfirmation(uuid,"");
  10848. //ShmOCPP16Data->MsMsg.bits.GetLocalListVersionConf = 1;
  10849. return result;
  10850. }
  10851. int handleRemoteStartRequestOrg(char *uuid, char *payload)
  10852. {
  10853. mtrace();
  10854. int result = FAIL;
  10855. int connectorIdInt=-1;
  10856. int tempIndex = 0;
  10857. int connectorIdIsNULL, chargingProfileIsNULL;
  10858. char comfirmstr[20]={0};
  10859. char cmdBuf[512];
  10860. json_object *RemoteStartTransaction;
  10861. FILE *fp;
  10862. DEBUG_INFO("handleRemoteStartRequest ...\n");
  10863. if(server_pending == TRUE)
  10864. {
  10865. return 0;
  10866. }
  10867. connectorIdIsNULL = chargingProfileIsNULL= FALSE;
  10868. RemoteStartTransaction = json_tokener_parse(payload);
  10869. if(!is_error(RemoteStartTransaction))
  10870. {
  10871. if(json_object_object_get(RemoteStartTransaction, "connectorId") != NULL)
  10872. {
  10873. connectorIdInt = json_object_get_int(json_object_object_get(RemoteStartTransaction, "connectorId"));
  10874. }
  10875. else
  10876. {
  10877. connectorIdIsNULL = TRUE;
  10878. for(uint8_t gun_index=0;gun_index<gunTotalNumber;gun_index++)
  10879. {
  10880. if(!cpinitateMsg.bits[gun_index].isOnCharging && (strstr((char*)ShmOCPP16Data->StatusNotification[gun_index].Status, "Preparing") != NULL))
  10881. {
  10882. connectorIdIsNULL = FALSE;
  10883. connectorIdInt = (gun_index+1);
  10884. DEBUG_INFO("Remote start without connectorId but detect connector-%02d connected ready to start.\n", connectorIdInt);
  10885. break;
  10886. }
  10887. }
  10888. }
  10889. if((connectorIdInt <= gunTotalNumber) && (connectorIdInt > 0))
  10890. {
  10891. memset(&ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1], 0x00, sizeof(struct StructRemoteStartTransaction));
  10892. // Required data
  10893. sprintf((char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag, "%s", json_object_get_string(json_object_object_get(RemoteStartTransaction, "idTag")));
  10894. // Optional data
  10895. if(json_object_object_get(RemoteStartTransaction, "chargingProfile") != NULL)
  10896. {
  10897. ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingProfileId = json_object_get_int(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingProfileId"));
  10898. ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.StackLevel = json_object_get_int(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "stackLevel"));
  10899. sprintf((char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingProfilePurpose, "%s", json_object_get_string(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingProfilePurpose")));
  10900. sprintf((char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingProfileKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingProfileKind")));
  10901. if(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "transactionId") != NULL)
  10902. ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.TransactionId = json_object_get_int(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "transactionId"));
  10903. if(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "recurrencyKind") != NULL)
  10904. sprintf((char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.RecurrencyKind , "%s", json_object_get_string(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "recurrencyKind")));
  10905. if(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "validFrom") != NULL)
  10906. sprintf((char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ValidFrom , "%s", json_object_get_string(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "validFrom")));
  10907. if(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "validTo") != NULL)
  10908. sprintf((char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ValidTo , "%s", json_object_get_string(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "validTo")));
  10909. if(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingSchedule") != NULL)
  10910. {
  10911. 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")));
  10912. if(json_object_object_get(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingSchedule"), "duration") != NULL)
  10913. 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"));
  10914. if(json_object_object_get(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingSchedule"), "minChargingRate") != NULL)
  10915. 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"));
  10916. if(json_object_object_get(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingSchedule"), "startSchedule") != NULL)
  10917. 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")));
  10918. if(json_object_object_get(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingSchedule"), "chargingSchedulePeriod") != NULL)
  10919. {
  10920. 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++)
  10921. {
  10922. 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"));
  10923. 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"));
  10924. 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)
  10925. 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"));
  10926. }
  10927. }
  10928. }
  10929. }
  10930. else
  10931. {
  10932. chargingProfileIsNULL = TRUE;
  10933. }
  10934. }
  10935. }
  10936. else
  10937. {
  10938. connectorIdIsNULL = TRUE;
  10939. }
  10940. if(connectorIdIsNULL == TRUE) // Number of the connector on which to start the transaction. connectorId SHALL be > 0
  10941. {
  10942. DEBUG_WARN("Connector id is NULL\n.");
  10943. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  10944. goto end;
  10945. }
  10946. /*
  10947. enum _SYSTEM_STATUS
  10948. {
  10949. S_BOOTING = 0,
  10950. S_IDLE, = 1
  10951. S_AUTHORIZING, = 2
  10952. S_REASSIGN_CHECK, = 3
  10953. S_REASSIGN, = 4
  10954. S_PRECHARGE, = 5
  10955. S_PREPARING_FOR_EV, = 6
  10956. S_PREPARING_FOR_EVSE, = 7
  10957. S_CHARGING, = 8
  10958. S_TERMINATING, = 9
  10959. S_COMPLETE, = 10
  10960. S_ALARM, = 11
  10961. S_FAULT = 12
  10962. }
  10963. */
  10964. if((connectorIdIsNULL == FALSE)&&(connectorIdInt > 0) && (connectorIdInt <= gunTotalNumber))
  10965. {
  10966. //check Transaction active
  10967. if(gunType[connectorIdInt -1] == GUN_TYPE_CHAdeMO)
  10968. {
  10969. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  10970. {
  10971. tempIndex = ((connectorIdInt -1) == 2) ? 1: 0;
  10972. }
  10973. else
  10974. {
  10975. tempIndex = connectorIdInt -1;
  10976. }
  10977. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  10978. {
  10979. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex )
  10980. {
  10981. if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ReservationId != -1)&&(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ReservationId >= 0)&&(strcmp((const char *)ShmOCPP16Data->ReserveNow[index].IdTag, (char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag) == 0))
  10982. {
  10983. //Reserved
  10984. DEBUG_INFO("Reserved now !!!The idTag matches the idTag of Reservation!!!\n");
  10985. }
  10986. else if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ReservationId != -1)&&(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ReservationId >= 0)&&(strcmp((const char *)ShmOCPP16Data->ReserveNow[index].IdTag, (char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag) != 0))
  10987. {
  10988. //Reserved
  10989. DEBUG_INFO("Reserved now !!! The idTag does NOT match the idTag of Reservation!!! Reject it!!!\n");
  10990. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  10991. goto end;
  10992. }
  10993. else
  10994. {
  10995. if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  10996. && (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_PREPARING ) //S_PRECHARGE
  10997. && (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EV ) //S_PREPARING_FOR_EV
  10998. && (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EVSE )) // S_PREPARING_FOR_EVSE
  10999. {
  11000. DEBUG_WARN("CHAdeMO connector not allow start\n.");
  11001. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  11002. goto end;
  11003. }
  11004. }//END FOR ELSE
  11005. }
  11006. }// END FOR CHAdeMO_QUANTITY
  11007. }
  11008. else if(gunType[connectorIdInt -1] == GUN_TYPE_CCS)
  11009. {
  11010. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  11011. {
  11012. tempIndex = ((connectorIdInt -1) == 2) ? 1: 0;
  11013. }
  11014. else
  11015. {
  11016. tempIndex = connectorIdInt -1;
  11017. }
  11018. for (int index = 0; index < CCS_QUANTITY; index++)
  11019. {
  11020. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  11021. {
  11022. if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ReservationId != -1)&&(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ReservationId >= 0)&&(strcmp((const char *)ShmOCPP16Data->ReserveNow[index].IdTag, (char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag) == 0))
  11023. {
  11024. //Reserved
  11025. DEBUG_INFO("Reserved now !!!The idTag matches the idTag of Reservation!!!\n");
  11026. }
  11027. else if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ReservationId != -1)&&(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ReservationId >= 0)&&(strcmp((const char *)ShmOCPP16Data->ReserveNow[index].IdTag, (char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag) != 0))
  11028. {
  11029. //Reserved
  11030. DEBUG_INFO("Reserved now !!! The idTag does NOT match the idTag of Reservation!!! Reject it!!!\n");
  11031. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  11032. goto end;
  11033. }
  11034. else
  11035. {
  11036. if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  11037. && (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_PREPARING) //S_PRECHARGE
  11038. && (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EV) //S_PREPARING_FOR_EV
  11039. && (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EVSE)) // S_PREPARING_FOR_EVSE
  11040. {
  11041. DEBUG_WARN("CCS connector not allow start\n.");
  11042. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  11043. goto end;
  11044. }
  11045. }// END FOR ELSE
  11046. }
  11047. }// END FOR CCS_QUANTITY
  11048. }
  11049. else if(gunType[connectorIdInt -1] == GUN_TYPE_GBT)
  11050. {
  11051. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  11052. {
  11053. tempIndex = ((connectorIdInt -1) == 2) ? 1: 0;
  11054. }
  11055. else
  11056. {
  11057. tempIndex = connectorIdInt -1;
  11058. }
  11059. for (int index = 0; index < GB_QUANTITY; index++)
  11060. {
  11061. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex )
  11062. {
  11063. if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ReservationId != -1)&&(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ReservationId >= 0)&&(strcmp((const char *)ShmOCPP16Data->ReserveNow[index].IdTag, (char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag) == 0))
  11064. {
  11065. //Reserved
  11066. DEBUG_INFO("Reserved now !!!The idTag matches the idTag of Reservation!!!\n");
  11067. }
  11068. else if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ReservationId != -1)&&(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ReservationId >= 0)&&(strcmp((const char *)ShmOCPP16Data->ReserveNow[index].IdTag, (char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag) != 0))
  11069. {
  11070. //Reserved
  11071. DEBUG_INFO("Reserved now !!! The idTag does NOT match the idTag of Reservation!!! Reject it!!!\n");
  11072. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  11073. goto end;
  11074. }
  11075. else
  11076. {
  11077. if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  11078. && (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_PREPARING) //S_PRECHARGE
  11079. && (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EV) //S_PREPARING_FOR_EV
  11080. && (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EVSE)) // S_PREPARING_FOR_EVSE
  11081. {
  11082. DEBUG_WARN("GB connector not allow start\n.");
  11083. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  11084. goto end;
  11085. }
  11086. }// END FOR ELSE
  11087. }
  11088. } // END FOR GB_QUANTITY
  11089. }
  11090. else if(gunType[connectorIdInt -1] == GUN_TYPE_DO)
  11091. {
  11092. tempIndex = connectorIdInt -1;
  11093. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  11094. {
  11095. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex )
  11096. {
  11097. if((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.ReservationId != -1)&&(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.ReservationId >= 0)&&(strcmp((const char *)ShmOCPP16Data->ReserveNow[index].IdTag, (char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag) == 0))
  11098. {
  11099. //Reserved
  11100. DEBUG_INFO("Reserved now !!!The idTag matches the idTag of Reservation!!!\n");
  11101. }
  11102. else if((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.ReservationId != -1)&&(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.ReservationId >= 0)&&(strcmp((const char *)ShmOCPP16Data->ReserveNow[index].IdTag, (char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag) != 0))
  11103. {
  11104. //Reserved
  11105. DEBUG_INFO("Reserved now !!! The idTag does NOT match the idTag of Reservation!!! Reject it!!!\n");
  11106. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  11107. goto end;
  11108. }
  11109. else
  11110. {
  11111. if((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus != SYS_MODE_IDLE) //S_IDLE
  11112. && (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus != SYS_MODE_PREPARING) //S_PRECHARGE
  11113. && (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus != SYS_MODE_PREPARE_FOR_EV) //S_PREPARING_FOR_EV
  11114. && (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus != SYS_MODE_PREPARE_FOR_EVSE)) // S_PREPARING_FOR_EVSE
  11115. {
  11116. DEBUG_WARN("GB connector not allow start\n.");
  11117. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  11118. goto end;
  11119. }
  11120. }// END FOR ELSE
  11121. }
  11122. } // END FOR GB_QUANTITY
  11123. }
  11124. else
  11125. {
  11126. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D') // 'D' means DC
  11127. {
  11128. tempIndex = 2;
  11129. }
  11130. else
  11131. {
  11132. tempIndex = connectorIdInt -1;
  11133. }
  11134. for (int index = 0; index < AC_QUANTITY; index++)
  11135. {
  11136. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex )
  11137. {
  11138. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].ReservationId != -1)&&(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].ReservationId >= 0)&&(strcmp((const char *)ShmOCPP16Data->ReserveNow[index].IdTag, (char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag) == 0))
  11139. {
  11140. //Reserved
  11141. DEBUG_INFO("Reserved now !!!The idTag matches the idTag of Reservation!!!\n");
  11142. }
  11143. else if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].ReservationId != -1)&&(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].ReservationId >= 0)&&(strcmp((const char *)ShmOCPP16Data->ReserveNow[index].IdTag, (char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag) != 0))
  11144. {
  11145. //Reserved
  11146. DEBUG_INFO("Reserved now !!! The idTag does NOT match the idTag of Reservation!!! Reject it!!!\n");
  11147. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  11148. goto end;
  11149. }
  11150. else
  11151. {
  11152. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  11153. && (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_PREPARING) //S_PRECHARGE
  11154. && (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EV) //S_PREPARING_FOR_EV
  11155. && (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EVSE)) // S_PREPARING_FOR_EVSE
  11156. {
  11157. DEBUG_WARN("AC connector not allow start\n.");
  11158. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  11159. goto end;
  11160. }
  11161. }//END FOR ELSE
  11162. }
  11163. }// END FOR AC_QUANTITY
  11164. }
  11165. if(chargingProfileIsNULL == FALSE)
  11166. {
  11167. if(strcmp((char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingProfilePurpose, ChargingProfilePurposeTypeStr[TxProfile]) == 0)
  11168. {
  11169. ShmOCPP16Data->CsMsg.bits[connectorIdInt -1].RemoteStartTransactionReq = 1;
  11170. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Accepted]);
  11171. //memset idTag
  11172. memset((char *)ShmOCPP16Data->StartTransaction[connectorIdInt -1].IdTag,0, 20);
  11173. strcpy((char *)ShmOCPP16Data->StartTransaction[connectorIdInt -1].IdTag, (char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag);
  11174. memset((char *)ShmOCPP16Data->StopTransaction[connectorIdInt -1].IdTag,0, 20);
  11175. strcpy((char *)ShmOCPP16Data->StopTransaction[connectorIdInt -1].IdTag, (char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag);
  11176. // Save profile to file
  11177. sprintf(cmdBuf, "rm -f /Storage/OCPP/TxProfile_%d.json", connectorIdInt);
  11178. system(cmdBuf);
  11179. sprintf(cmdBuf, "/Storage/OCPP/TxProfile_%d.json", connectorIdInt);
  11180. fp = fopen(cmdBuf, "w");
  11181. 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));
  11182. fclose(fp);
  11183. }
  11184. else
  11185. {
  11186. DEBUG_WARN("Carging profile purpose not TxProfile.\n.");
  11187. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  11188. }
  11189. }
  11190. else
  11191. {
  11192. ShmOCPP16Data->CsMsg.bits[connectorIdInt -1].RemoteStartTransactionReq = 1;
  11193. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Accepted]);
  11194. //memset idTag
  11195. memset((char *)ShmOCPP16Data->StartTransaction[connectorIdInt -1].IdTag,0, 20);
  11196. strcpy((char *)ShmOCPP16Data->StartTransaction[connectorIdInt -1].IdTag, (char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag);
  11197. memset((char *)ShmOCPP16Data->StopTransaction[connectorIdInt -1].IdTag,0, 20);
  11198. strcpy((char *)ShmOCPP16Data->StopTransaction[connectorIdInt -1].IdTag, (char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag);
  11199. }
  11200. }
  11201. else
  11202. {
  11203. DEBUG_WARN("Connector id over\n.");
  11204. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  11205. //sprintf((char *)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ResponseStatus, "%s" ,comfirmstr);
  11206. }
  11207. end:
  11208. json_object_put(RemoteStartTransaction);
  11209. if((connectorIdIsNULL == FALSE) && (connectorIdInt <= gunTotalNumber))
  11210. {
  11211. ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ConnectorId = connectorIdInt;
  11212. sprintf((char *)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ResponseStatus, "%s" ,comfirmstr);
  11213. }
  11214. //OCPP send RemoteStartConfirmation by first.
  11215. sendRemoteStartConfirmation(uuid, comfirmstr);
  11216. return result;
  11217. }
  11218. int handleRemoteStartRequest(char *uuid, char *payload)
  11219. {
  11220. mtrace();
  11221. int result = PASS;
  11222. int connectorIdInt=-1;
  11223. int tempIndex = 0;
  11224. char comfirmstr[20]={0};
  11225. char cmdBuf[512];
  11226. json_object *RemoteStartTransaction;
  11227. FILE *fp;
  11228. DEBUG_INFO("handleRemoteStartRequest ...\n");
  11229. if(server_pending == TRUE)
  11230. {
  11231. result = FAIL;
  11232. }
  11233. RemoteStartTransaction = json_tokener_parse(payload);
  11234. if(!is_error(RemoteStartTransaction))
  11235. {
  11236. if(json_object_object_get(RemoteStartTransaction, "connectorId") != NULL)
  11237. {
  11238. connectorIdInt = json_object_get_int(json_object_object_get(RemoteStartTransaction, "connectorId"));
  11239. }
  11240. else
  11241. {
  11242. for(uint8_t gun_index=0;gun_index<gunTotalNumber;gun_index++)
  11243. {
  11244. if(!cpinitateMsg.bits[gun_index].isOnCharging && (strstr((char*)ShmOCPP16Data->StatusNotification[gun_index].Status, "Preparing") != NULL))
  11245. {
  11246. connectorIdInt = (gun_index+1);
  11247. DEBUG_INFO("Remote start without connectorId but detect connector-%02d connected ready to start.\n", connectorIdInt);
  11248. break;
  11249. }
  11250. }
  11251. }
  11252. if(connectorIdInt == 0)
  11253. {
  11254. DEBUG_WARN("Connector id shall not equal 0.\n");
  11255. result = FAIL;
  11256. }
  11257. else if(connectorIdInt == -1)
  11258. {
  11259. DEBUG_INFO("Connector id does not specific.\n");
  11260. for(uint8_t gun_index=0;gun_index<gunTotalNumber;gun_index++)
  11261. {
  11262. memset(&ShmOCPP16Data->RemoteStartTransaction[gun_index], 0x00, sizeof(struct StructRemoteStartTransaction));
  11263. // Required data
  11264. sprintf((char*)ShmOCPP16Data->RemoteStartTransaction[gun_index].IdTag, "%s", json_object_get_string(json_object_object_get(RemoteStartTransaction, "idTag")));
  11265. // Optional data
  11266. if(json_object_object_get(RemoteStartTransaction, "chargingProfile") != NULL)
  11267. {
  11268. ShmOCPP16Data->RemoteStartTransaction[gun_index].ChargingProfile.ChargingProfileId = json_object_get_int(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingProfileId"));
  11269. ShmOCPP16Data->RemoteStartTransaction[gun_index].ChargingProfile.StackLevel = json_object_get_int(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "stackLevel"));
  11270. sprintf((char*)ShmOCPP16Data->RemoteStartTransaction[gun_index].ChargingProfile.ChargingProfilePurpose, "%s", json_object_get_string(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingProfilePurpose")));
  11271. sprintf((char*)ShmOCPP16Data->RemoteStartTransaction[gun_index].ChargingProfile.ChargingProfileKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingProfileKind")));
  11272. if(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "transactionId") != NULL)
  11273. ShmOCPP16Data->RemoteStartTransaction[gun_index].ChargingProfile.TransactionId = json_object_get_int(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "transactionId"));
  11274. if(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "recurrencyKind") != NULL)
  11275. sprintf((char*)ShmOCPP16Data->RemoteStartTransaction[gun_index].ChargingProfile.RecurrencyKind , "%s", json_object_get_string(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "recurrencyKind")));
  11276. if(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "validFrom") != NULL)
  11277. sprintf((char*)ShmOCPP16Data->RemoteStartTransaction[gun_index].ChargingProfile.ValidFrom , "%s", json_object_get_string(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "validFrom")));
  11278. if(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "validTo") != NULL)
  11279. sprintf((char*)ShmOCPP16Data->RemoteStartTransaction[gun_index].ChargingProfile.ValidTo , "%s", json_object_get_string(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "validTo")));
  11280. if(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingSchedule") != NULL)
  11281. {
  11282. 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")));
  11283. if(json_object_object_get(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingSchedule"), "duration") != NULL)
  11284. 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"));
  11285. if(json_object_object_get(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingSchedule"), "minChargingRate") != NULL)
  11286. 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"));
  11287. if(json_object_object_get(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingSchedule"), "startSchedule") != NULL)
  11288. 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")));
  11289. if(json_object_object_get(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingSchedule"), "chargingSchedulePeriod") != NULL)
  11290. {
  11291. 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++)
  11292. {
  11293. 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"));
  11294. 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"));
  11295. 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)
  11296. 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"));
  11297. }
  11298. }
  11299. }
  11300. }
  11301. else
  11302. {
  11303. ShmOCPP16Data->RemoteStartTransaction[gun_index].ChargingProfile.ChargingProfileId = -1;
  11304. }
  11305. }
  11306. }
  11307. else if(((0 < connectorIdInt) && (connectorIdInt <= gunTotalNumber)))
  11308. {
  11309. DEBUG_INFO("Connector id: %d\n", connectorIdInt);
  11310. memset(&ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1], 0x00, sizeof(struct StructRemoteStartTransaction));
  11311. // Required data
  11312. sprintf((char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag, "%s", json_object_get_string(json_object_object_get(RemoteStartTransaction, "idTag")));
  11313. // Optional data
  11314. if(json_object_object_get(RemoteStartTransaction, "chargingProfile") != NULL)
  11315. {
  11316. ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingProfileId = json_object_get_int(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingProfileId"));
  11317. ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.StackLevel = json_object_get_int(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "stackLevel"));
  11318. sprintf((char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingProfilePurpose, "%s", json_object_get_string(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingProfilePurpose")));
  11319. sprintf((char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingProfileKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingProfileKind")));
  11320. if(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "transactionId") != NULL)
  11321. ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.TransactionId = json_object_get_int(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "transactionId"));
  11322. if(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "recurrencyKind") != NULL)
  11323. sprintf((char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.RecurrencyKind , "%s", json_object_get_string(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "recurrencyKind")));
  11324. if(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "validFrom") != NULL)
  11325. sprintf((char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ValidFrom , "%s", json_object_get_string(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "validFrom")));
  11326. if(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "validTo") != NULL)
  11327. sprintf((char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ValidTo , "%s", json_object_get_string(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "validTo")));
  11328. if(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingSchedule") != NULL)
  11329. {
  11330. 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")));
  11331. if(json_object_object_get(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingSchedule"), "duration") != NULL)
  11332. 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"));
  11333. if(json_object_object_get(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingSchedule"), "minChargingRate") != NULL)
  11334. 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"));
  11335. if(json_object_object_get(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingSchedule"), "startSchedule") != NULL)
  11336. 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")));
  11337. if(json_object_object_get(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingSchedule"), "chargingSchedulePeriod") != NULL)
  11338. {
  11339. 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++)
  11340. {
  11341. 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"));
  11342. 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"));
  11343. 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)
  11344. 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"));
  11345. }
  11346. }
  11347. }
  11348. }
  11349. else
  11350. {
  11351. ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingProfileId = -1;
  11352. }
  11353. }
  11354. else
  11355. {
  11356. DEBUG_WARN("Connector id is over maximun value.\n");
  11357. result = FAIL;
  11358. }
  11359. }
  11360. if(result == PASS)
  11361. {
  11362. if(connectorIdInt > 0)
  11363. {
  11364. //check Transaction active
  11365. if(gunType[connectorIdInt -1] == GUN_TYPE_CHAdeMO)
  11366. {
  11367. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  11368. {
  11369. tempIndex = ((connectorIdInt -1) == 2) ? 1: 0;
  11370. }
  11371. else
  11372. {
  11373. tempIndex = connectorIdInt -1;
  11374. }
  11375. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  11376. {
  11377. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  11378. {
  11379. if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ReservationId != -1) &&
  11380. (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ReservationId >= 0) &&
  11381. (strcmp((const char *)ShmOCPP16Data->ReserveNow[index].IdTag, (char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag) == 0))
  11382. {
  11383. //Reserved
  11384. DEBUG_INFO("CHAdeMO connector already reserved and idTag match.\n");
  11385. }
  11386. else if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ReservationId != -1) &&
  11387. (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ReservationId >= 0) &&
  11388. (strcmp((const char *)ShmOCPP16Data->ReserveNow[index].IdTag, (char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag) != 0))
  11389. {
  11390. //Reserved
  11391. DEBUG_INFO("CHAdeMO connector already reserved and idTag does not match.\n");
  11392. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  11393. goto end;
  11394. }
  11395. else
  11396. {
  11397. if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  11398. && (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_PREPARING ) //S_PRECHARGE
  11399. && (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EV ) //S_PREPARING_FOR_EV
  11400. && (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EVSE )) // S_PREPARING_FOR_EVSE
  11401. {
  11402. DEBUG_WARN("CHAdeMO connector not allow start cause busy.\n");
  11403. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  11404. goto end;
  11405. }
  11406. }//END FOR ELSE
  11407. }
  11408. }// END FOR CHAdeMO_QUANTITY
  11409. }
  11410. else if(gunType[connectorIdInt -1] == GUN_TYPE_CCS)
  11411. {
  11412. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  11413. {
  11414. tempIndex = ((connectorIdInt -1) == 2) ? 1: 0;
  11415. }
  11416. else
  11417. {
  11418. tempIndex = connectorIdInt -1;
  11419. }
  11420. for (int index = 0; index < CCS_QUANTITY; index++)
  11421. {
  11422. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  11423. {
  11424. if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ReservationId != -1) &&
  11425. (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ReservationId >= 0) &&
  11426. (strcmp((const char *)ShmOCPP16Data->ReserveNow[index].IdTag, (char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag) == 0))
  11427. {
  11428. //Reserved
  11429. DEBUG_INFO("CCS connector already reserved and idTag match.\n");
  11430. }
  11431. else if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ReservationId != -1) &&
  11432. (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ReservationId >= 0) &&
  11433. (strcmp((const char *)ShmOCPP16Data->ReserveNow[index].IdTag, (char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag) != 0))
  11434. {
  11435. //Reserved
  11436. DEBUG_INFO("CCS connector already reserved and idTag does not match.\n");
  11437. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  11438. goto end;
  11439. }
  11440. else
  11441. {
  11442. if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  11443. && (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_PREPARING) //S_PRECHARGE
  11444. && (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EV) //S_PREPARING_FOR_EV
  11445. && (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EVSE)) // S_PREPARING_FOR_EVSE
  11446. {
  11447. DEBUG_WARN("CCS connector not allow start cause busy.\n");
  11448. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  11449. goto end;
  11450. }
  11451. }// END FOR ELSE
  11452. }
  11453. }// END FOR CCS_QUANTITY
  11454. }
  11455. else if(gunType[connectorIdInt -1] == GUN_TYPE_GBT)
  11456. {
  11457. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  11458. {
  11459. tempIndex = ((connectorIdInt -1) == 2) ? 1: 0;
  11460. }
  11461. else
  11462. {
  11463. tempIndex = connectorIdInt -1;
  11464. }
  11465. for (int index = 0; index < GB_QUANTITY; index++)
  11466. {
  11467. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex )
  11468. {
  11469. if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ReservationId != -1) &&
  11470. (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ReservationId >= 0) &&
  11471. (strcmp((const char *)ShmOCPP16Data->ReserveNow[index].IdTag, (char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag) == 0))
  11472. {
  11473. //Reserved
  11474. DEBUG_INFO("GBT connector already reserved and idTag match.\n");
  11475. }
  11476. else if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ReservationId != -1) &&
  11477. (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ReservationId >= 0) &&
  11478. (strcmp((const char *)ShmOCPP16Data->ReserveNow[index].IdTag, (char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag) != 0))
  11479. {
  11480. //Reserved
  11481. DEBUG_INFO("GBT connector already reserved and idTag does not match.\n");
  11482. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  11483. goto end;
  11484. }
  11485. else
  11486. {
  11487. if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  11488. && (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_PREPARING) //S_PRECHARGE
  11489. && (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EV) //S_PREPARING_FOR_EV
  11490. && (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EVSE)) // S_PREPARING_FOR_EVSE
  11491. {
  11492. DEBUG_WARN("GBT connector not allow start cause busy.\n");
  11493. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  11494. goto end;
  11495. }
  11496. }// END FOR ELSE
  11497. }
  11498. } // END FOR GB_QUANTITY
  11499. }
  11500. else if(gunType[connectorIdInt -1] == GUN_TYPE_DO)
  11501. {
  11502. tempIndex = connectorIdInt -1;
  11503. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  11504. {
  11505. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex )
  11506. {
  11507. if((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.ReservationId != -1) &&
  11508. (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.ReservationId >= 0) &&
  11509. (strcmp((const char *)ShmOCPP16Data->ReserveNow[index].IdTag, (char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag) == 0))
  11510. {
  11511. //Reserved
  11512. DEBUG_INFO("Dispenser connector already reserved and idTag match.\n");
  11513. }
  11514. else if((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.ReservationId != -1) &&
  11515. (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.ReservationId >= 0) &&
  11516. (strcmp((const char *)ShmOCPP16Data->ReserveNow[index].IdTag, (char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag) != 0))
  11517. {
  11518. //Reserved
  11519. DEBUG_INFO("Dispenser connector already reserved and idTag does not match.\n");
  11520. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  11521. goto end;
  11522. }
  11523. else
  11524. {
  11525. if((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus != SYS_MODE_IDLE) //S_IDLE
  11526. && (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus != SYS_MODE_PREPARING) //S_PRECHARGE
  11527. && (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus != SYS_MODE_PREPARE_FOR_EV) //S_PREPARING_FOR_EV
  11528. && (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus != SYS_MODE_PREPARE_FOR_EVSE)) // S_PREPARING_FOR_EVSE
  11529. {
  11530. DEBUG_WARN("Dispenser connector not allow start cause busy.\n");
  11531. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  11532. goto end;
  11533. }
  11534. }// END FOR ELSE
  11535. }
  11536. } // END FOR GB_QUANTITY
  11537. }
  11538. else
  11539. {
  11540. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D') // 'D' means DC
  11541. {
  11542. tempIndex = 2;
  11543. }
  11544. else
  11545. {
  11546. tempIndex = connectorIdInt -1;
  11547. }
  11548. for (int index = 0; index < AC_QUANTITY; index++)
  11549. {
  11550. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex )
  11551. {
  11552. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].ReservationId != -1) &&
  11553. (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].ReservationId >= 0) &&
  11554. (strcmp((const char *)ShmOCPP16Data->ReserveNow[index].IdTag, (char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag) == 0))
  11555. {
  11556. //Reserved
  11557. DEBUG_INFO("AC connector already reserved and idTag match.\n");
  11558. }
  11559. else if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].ReservationId != -1) &&
  11560. (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].ReservationId >= 0) &&
  11561. (strcmp((const char *)ShmOCPP16Data->ReserveNow[index].IdTag, (char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag) != 0))
  11562. {
  11563. //Reserved
  11564. DEBUG_INFO("AC connector already reserved and idTag does not match.\n");
  11565. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  11566. goto end;
  11567. }
  11568. else
  11569. {
  11570. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  11571. && (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_PREPARING) //S_PRECHARGE
  11572. && (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EV) //S_PREPARING_FOR_EV
  11573. && (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EVSE)) // S_PREPARING_FOR_EVSE
  11574. {
  11575. DEBUG_WARN("AC connector not allow start cause busy.\n");
  11576. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  11577. goto end;
  11578. }
  11579. }//END FOR ELSE
  11580. }
  11581. }// END FOR AC_QUANTITY
  11582. }
  11583. if(ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingProfileId > -1)
  11584. {
  11585. if(strcmp((char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingProfilePurpose, ChargingProfilePurposeTypeStr[TxProfile]) == 0)
  11586. {
  11587. // Save profile to file
  11588. sprintf(cmdBuf, "rm -f /Storage/OCPP/TxProfile_%d.json", connectorIdInt);
  11589. system(cmdBuf);
  11590. sprintf(cmdBuf, "/Storage/OCPP/TxProfile_%d.json", connectorIdInt);
  11591. fp = fopen(cmdBuf, "w");
  11592. 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));
  11593. fclose(fp);
  11594. }
  11595. else
  11596. {
  11597. DEBUG_WARN("Profile purpose not TxProfile.\n");
  11598. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  11599. goto end;
  11600. }
  11601. }
  11602. ShmOCPP16Data->CsMsg.bits[connectorIdInt -1].RemoteStartTransactionReq = 1;
  11603. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Accepted]);
  11604. memset((char *)ShmOCPP16Data->StartTransaction[connectorIdInt -1].IdTag,0, 20);
  11605. strcpy((char *)ShmOCPP16Data->StartTransaction[connectorIdInt -1].IdTag, (char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag);
  11606. memset((char *)ShmOCPP16Data->StopTransaction[connectorIdInt -1].IdTag,0, 20);
  11607. strcpy((char *)ShmOCPP16Data->StopTransaction[connectorIdInt -1].IdTag, (char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag);
  11608. }
  11609. else
  11610. {
  11611. uint8_t isHasIdleConnector = FALSE;
  11612. for(uint8_t gun_index=0;gun_index<gunTotalNumber;gun_index++)
  11613. {
  11614. if(!cpinitateMsg.bits[gun_index].isOnCharging)
  11615. {
  11616. isHasIdleConnector = TRUE;
  11617. break;
  11618. }
  11619. }
  11620. if(isHasIdleConnector == TRUE)
  11621. {
  11622. DEBUG_INFO("Start wait connector link to EV in %s seconds.\n", ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemData);
  11623. if(ShmOCPP16Data->RemoteStartTransaction[0].ChargingProfile.ChargingProfileId > -1)
  11624. {
  11625. if(strcmp((char*)ShmOCPP16Data->RemoteStartTransaction[0].ChargingProfile.ChargingProfilePurpose, ChargingProfilePurposeTypeStr[TxProfile]) == 0)
  11626. {
  11627. // Save profile to file
  11628. sprintf(cmdBuf, "rm -f /Storage/OCPP/TxProfile_Tmp.json");
  11629. system(cmdBuf);
  11630. sprintf(cmdBuf, "/Storage/OCPP/TxProfile_Tmp.json");
  11631. fp = fopen(cmdBuf, "w");
  11632. fprintf(fp, "{\"connectorId\":0,\"csChargingProfiles\":%s}\n", json_object_to_json_string_ext(json_object_object_get(RemoteStartTransaction, "chargingProfile"), JSON_C_TO_STRING_PLAIN));
  11633. fclose(fp);
  11634. refreshStartTimer(&clientTime.RemoteStartWait);
  11635. ShmOCPP16Data->MsMsg.bits.isRemoteStartWaitReq = 1;
  11636. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Accepted]);
  11637. }
  11638. else
  11639. {
  11640. DEBUG_WARN("Profile purpose not TxProfile.\n");
  11641. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  11642. }
  11643. }
  11644. else
  11645. {
  11646. refreshStartTimer(&clientTime.RemoteStartWait);
  11647. ShmOCPP16Data->MsMsg.bits.isRemoteStartWaitReq = 1;
  11648. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Accepted]);
  11649. }
  11650. }
  11651. else
  11652. {
  11653. DEBUG_INFO("There is not any connector is idle.\n");
  11654. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  11655. }
  11656. }
  11657. }
  11658. else
  11659. {
  11660. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  11661. }
  11662. end:
  11663. json_object_put(RemoteStartTransaction);
  11664. sendRemoteStartConfirmation(uuid, comfirmstr);
  11665. return result;
  11666. }
  11667. int handleRemoteStopTransactionRequest(char *uuid, char *payload)
  11668. {
  11669. mtrace();
  11670. int result = FAIL;
  11671. int match = FALSE;
  11672. int GunNO = 0;
  11673. int tempIndex = 0;
  11674. int transactionIdInt=0;
  11675. int transactionIdIsNULL= TRUE;
  11676. char comfirmstr[20];
  11677. json_object *RemoteStopTransaction;
  11678. //[2,"ff522854-0dea-436e-87ba-23a229269994","RemoteStopTransaction",{"transactionId":1373618380}]
  11679. DEBUG_INFO("handleRemoteStopTransactionRequest...\n");
  11680. if(server_pending == TRUE)
  11681. {
  11682. return 0;
  11683. }
  11684. RemoteStopTransaction = json_tokener_parse(payload);
  11685. if(!is_error(RemoteStopTransaction))
  11686. {
  11687. if(json_object_object_get(RemoteStopTransaction, "transactionId") != NULL)
  11688. {
  11689. transactionIdInt = json_object_get_int(json_object_object_get(RemoteStopTransaction, "transactionId"));
  11690. transactionIdIsNULL = FALSE;
  11691. }
  11692. }
  11693. json_object_put(RemoteStopTransaction);
  11694. if(transactionIdIsNULL == FALSE)
  11695. {
  11696. for(int gun_index=0;gun_index < gunTotalNumber;gun_index++)
  11697. {
  11698. if(ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId == transactionIdInt)
  11699. {
  11700. //check Transaction active
  11701. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  11702. {
  11703. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  11704. {
  11705. tempIndex = ((gun_index==2) ? 1: 0);
  11706. }
  11707. else
  11708. {
  11709. tempIndex = gun_index;
  11710. }
  11711. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  11712. {
  11713. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  11714. {
  11715. if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_TERMINATING)) // SYS_MODE_CHARGING, SYS_MODE_TERMINATING
  11716. {
  11717. match = TRUE;
  11718. GunNO = gun_index;
  11719. }
  11720. }
  11721. }// END FOR CHAdeMO_QUANTITY
  11722. }
  11723. else if(gunType[gun_index] == GUN_TYPE_CCS)
  11724. {
  11725. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  11726. {
  11727. tempIndex = ((gun_index==2) ? 1: 0);
  11728. }
  11729. else
  11730. {
  11731. tempIndex = gun_index;
  11732. }
  11733. for (int index = 0; index < CCS_QUANTITY; index++)
  11734. {
  11735. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  11736. {
  11737. if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_TERMINATING) ) // SYS_MODE_CHARGING, SYS_MODE_TERMINATING
  11738. {
  11739. match = TRUE;
  11740. GunNO = gun_index;
  11741. }
  11742. }
  11743. }// END FOR CCS_QUANTITY
  11744. }
  11745. else if(gunType[gun_index] == GUN_TYPE_GBT)
  11746. {
  11747. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  11748. {
  11749. tempIndex = ((gun_index==2) ? 1: 0);
  11750. }
  11751. else
  11752. {
  11753. tempIndex = gun_index;
  11754. }
  11755. for (int index = 0; index < GB_QUANTITY; index++)
  11756. {
  11757. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  11758. {
  11759. if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_TERMINATING)) // SYS_MODE_CHARGING, SYS_MODE_TERMINATING
  11760. {
  11761. match = TRUE;
  11762. GunNO = gun_index;
  11763. }
  11764. }
  11765. }// END FOR GB_QUANTITY
  11766. }
  11767. else if(gunType[gun_index] == GUN_TYPE_DO)
  11768. {
  11769. tempIndex = gun_index;
  11770. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  11771. {
  11772. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  11773. {
  11774. 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
  11775. {
  11776. match = TRUE;
  11777. GunNO = gun_index;
  11778. }
  11779. }
  11780. }// END FOR GB_QUANTITY
  11781. }
  11782. else
  11783. {
  11784. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D') // 'D' means DC
  11785. {
  11786. tempIndex = 2;
  11787. }
  11788. else
  11789. {
  11790. tempIndex = gun_index;
  11791. }
  11792. for (int index = 0; index < AC_QUANTITY; index++)
  11793. {
  11794. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  11795. {
  11796. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_TERMINATING)) // SYS_MODE_CHARGING, SYS_MODE_TERMINATING
  11797. {
  11798. match = TRUE;
  11799. GunNO = gun_index;
  11800. }
  11801. }
  11802. }// END FOR CHAdeMO_QUANTITY
  11803. } // END FOR AC ELSE
  11804. }// CHECK IF ResponseTransactionId == transactionIdInt
  11805. }//END FOR
  11806. if( match == TRUE)
  11807. {
  11808. ShmOCPP16Data->CsMsg.bits[GunNO].RemoteStopTransactionReq = 1; // inform csu of StopTransaction
  11809. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Accepted]);
  11810. sprintf((char *)ShmOCPP16Data->RemoteStopTransaction[GunNO].ResponseStatus, "%s" ,comfirmstr);
  11811. }
  11812. else
  11813. {
  11814. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  11815. }
  11816. }
  11817. else
  11818. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  11819. sendRemoteStopTransactionConfirmation(uuid, comfirmstr);
  11820. return result;
  11821. }
  11822. int handleReserveNowTransactionRequest(char *uuid, char *payload)
  11823. {
  11824. mtrace();
  11825. int result = FAIL;
  11826. int connectorIdInt=0, reservationIdInt=0;
  11827. int tempIndex = 0;
  11828. char expiryDatestr[30]={0}, idTagstr[21]={0},parentIdTagstr[21]={0};
  11829. char comfirmstr[20]={0};
  11830. char sstr[180]={ 0 },sstrtemp[200]={ 0 };
  11831. int c = 0;
  11832. char *loc;
  11833. //char *ptr;
  11834. DEBUG_INFO("handleReserveNowTransactionRequest ...\n");
  11835. strcpy(sstrtemp, stringtrimspace(payload));
  11836. //***(1)connectorId ****/
  11837. c=0;
  11838. loc = strstr(sstrtemp, "connectorId");
  11839. memset(sstr ,0, ARRAY_SIZE(sstr) );
  11840. while ((loc != NULL) &&(loc[strlen("connectorId")+2+c] != ',') && (loc[strlen("connectorId")+2+c] != '}'))
  11841. {
  11842. sstr[c] = loc[strlen("connectorId")+2+c];
  11843. //printf("i=%d sstr=%c\n",c, sstr[c]);
  11844. c++;
  11845. }
  11846. sstr[c] = '\0';
  11847. connectorIdInt = atoi(sstr);
  11848. //***(2)expiryDate ****/
  11849. loc = strstr(sstrtemp, "expiryDate");
  11850. memset(sstr ,0, ARRAY_SIZE(sstr) );
  11851. c = 0;
  11852. while ((loc != NULL) &&(loc[3+strlen("expiryDate")+c] != '\"'))
  11853. {
  11854. sstr[c] = loc[3+strlen("expiryDate")+c];
  11855. c++;
  11856. }
  11857. sstr[c] = '\0';
  11858. strcpy(expiryDatestr, sstr);
  11859. //***(3)idTag ****/
  11860. loc = strstr(sstrtemp, "idTag");
  11861. memset(sstr ,0, ARRAY_SIZE(sstr) );
  11862. c = 0;
  11863. while ((loc != NULL) &&(loc[3+strlen("idTag")+c] != '\"'))
  11864. {
  11865. sstr[c] = loc[3+strlen("idTag")+c];
  11866. c++;
  11867. }
  11868. sstr[c] = '\0';
  11869. strcpy(idTagstr, sstr);
  11870. //***(4)parentIdTag ****/
  11871. loc = strstr(sstrtemp, "parentIdTag");
  11872. memset(sstr ,0, ARRAY_SIZE(sstr) );
  11873. c = 0;
  11874. if(loc == NULL)
  11875. {
  11876. strcpy(parentIdTagstr, "");
  11877. }
  11878. else
  11879. {
  11880. while ((loc != NULL) &&(loc[3+strlen("parentIdTag")+c] != '\"'))
  11881. {
  11882. sstr[c] = loc[3+strlen("parentIdTag")+c];
  11883. c++;
  11884. }
  11885. sstr[c] = '\0';
  11886. strcpy(parentIdTagstr, sstr);
  11887. }
  11888. //***(5)reservationId ****/
  11889. c=0;
  11890. loc = strstr(sstrtemp, "reservationId");
  11891. memset(sstr ,0, ARRAY_SIZE(sstr) );
  11892. while ((loc != NULL) &&((loc[strlen("reservationId")+2+c] != '}') && (loc[strlen("reservationId")+2+c] != ',')))
  11893. {
  11894. sstr[c] = loc[strlen("reservationId")+2+c];
  11895. //printf("i=%d sstr=%c\n",c, sstr[c]);
  11896. c++;
  11897. }
  11898. sstr[c] = '\0';
  11899. reservationIdInt = atoi(sstr);
  11900. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  11901. /*
  11902. enum SYSTEM_STATUS
  11903. {
  11904. SYS_MODE_BOOTING = 0,
  11905. SYS_MODE_IDLE = 1,
  11906. SYS_MODE_AUTHORIZING = 2,
  11907. SYS_MODE_MODE_REASSIGN_CHECK = 3,
  11908. SYS_MODE_REASSIGN = 4,
  11909. SYS_MODE_PREPARING = 5,
  11910. SYS_MODE_PREPARE_FOR_EV = 6,
  11911. SYS_MODE_PREPARE_FOR_EVSE = 7,
  11912. SYS_MODE_CHARGING = 8,
  11913. SYS_MODE_TERMINATING = 9,
  11914. SYS_MODE_COMPLETE = 10,
  11915. SYS_MODE_ALARM = 11,
  11916. SYS_MODE_FAULT = 12,
  11917. SYS_MODE_RESERVATION = 13,
  11918. SYS_MODE_BOOKING = 14,
  11919. SYS_MODE_MAINTAIN = 15,
  11920. SYS_MODE_DEBUG = 16,
  11921. SYS_MODE_CCS_PRECHARGE_STEP0 = 17,
  11922. SYS_MODE_CCS_PRECHARGE_STEP1 = 18,
  11923. SYS_MODE_UPDATE = 19
  11924. };
  11925. */
  11926. if((connectorIdInt == 0) &&(strcmp((const char *)ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemData, "FALSE") == 0)) //For OCTT Test case
  11927. {
  11928. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  11929. goto end;
  11930. }
  11931. if((connectorIdInt > 0) && ((connectorIdInt -1) <= gunTotalNumber))
  11932. {
  11933. //check Transaction active
  11934. if(gunType[connectorIdInt -1] == GUN_TYPE_CHAdeMO)
  11935. {
  11936. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  11937. {
  11938. tempIndex = (((connectorIdInt -1)==2) ? 1: 0);
  11939. }
  11940. else
  11941. {
  11942. tempIndex = connectorIdInt -1;
  11943. }
  11944. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  11945. {
  11946. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  11947. {
  11948. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ReservationId)
  11949. {
  11950. if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_FAULT)&&(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_ALARM)) //S_FAULT
  11951. {
  11952. if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_IDLE) //S_IDLE
  11953. {
  11954. if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ConnectorPlugIn == 1) || (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].InProgress == 1))
  11955. {
  11956. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  11957. }
  11958. else
  11959. {
  11960. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  11961. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  11962. }
  11963. }
  11964. 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'))
  11965. {
  11966. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  11967. }
  11968. else if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_PREPARING) || (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_RESERVATION) ) //S_PRECHARGE
  11969. {
  11970. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  11971. }
  11972. else
  11973. {
  11974. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  11975. }
  11976. }
  11977. 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
  11978. {
  11979. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  11980. }
  11981. }
  11982. else
  11983. {
  11984. //replace reservation
  11985. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  11986. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  11987. }
  11988. }
  11989. } // END FOR CHAdeMO_QUANTITY
  11990. }
  11991. else if(gunType[connectorIdInt -1] == GUN_TYPE_CCS)
  11992. {
  11993. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  11994. {
  11995. tempIndex = (((connectorIdInt -1)==2) ? 1: 0);
  11996. }
  11997. else
  11998. {
  11999. tempIndex = connectorIdInt -1;
  12000. }
  12001. for (int index = 0; index < CCS_QUANTITY; index++)
  12002. {
  12003. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  12004. {
  12005. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ReservationId)
  12006. {
  12007. //SystemStatus: 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault, 8: Reserved, 9: maintain
  12008. if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_FAULT)&&(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_ALARM)) //S_FAULT
  12009. {
  12010. if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_IDLE) //S_IDLE
  12011. {
  12012. if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ConnectorPlugIn == 1) || (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].InProgress == 1))
  12013. {
  12014. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  12015. }
  12016. else
  12017. {
  12018. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  12019. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  12020. }
  12021. }
  12022. 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'))
  12023. {
  12024. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  12025. }
  12026. else if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_PREPARING) || (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_RESERVATION)) //S_PRECHARGE
  12027. {
  12028. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  12029. }
  12030. else
  12031. {
  12032. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  12033. }
  12034. }
  12035. 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
  12036. {
  12037. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  12038. }
  12039. }
  12040. else
  12041. {
  12042. //replace reservation
  12043. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  12044. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  12045. }
  12046. }
  12047. } // END FOR CCS_QUANTITY
  12048. }
  12049. else if(gunType[connectorIdInt -1] == GUN_TYPE_GBT)
  12050. {
  12051. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  12052. {
  12053. tempIndex = (((connectorIdInt -1)==2) ? 1: 0);
  12054. }
  12055. else
  12056. {
  12057. tempIndex = connectorIdInt -1;
  12058. }
  12059. for (int index = 0; index < GB_QUANTITY; index++)
  12060. {
  12061. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  12062. {
  12063. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ReservationId)
  12064. {
  12065. //SystemStatus: 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault, 8: Reserved, 9: maintain
  12066. if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_FAULT)&&(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_ALARM)) //SYS_MODE_FAULT, SYS_MODE_ALARM
  12067. {
  12068. if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_IDLE) //S_IDLE
  12069. {
  12070. if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ConnectorPlugIn == 1) || (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].InProgress == 1))
  12071. {
  12072. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  12073. }
  12074. else
  12075. {
  12076. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  12077. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  12078. }
  12079. }
  12080. 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'))
  12081. {
  12082. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  12083. }
  12084. else if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_PREPARING) || (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_RESERVATION) ) //S_PRECHARGE
  12085. {
  12086. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  12087. }
  12088. else
  12089. {
  12090. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  12091. }
  12092. }
  12093. 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
  12094. {
  12095. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  12096. }
  12097. }
  12098. else
  12099. {
  12100. //replace reservation
  12101. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  12102. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  12103. }
  12104. }
  12105. }// END FOR GB_QUANTITY
  12106. }
  12107. else if(gunType[connectorIdInt -1] == GUN_TYPE_DO)
  12108. {
  12109. tempIndex = connectorIdInt -1;
  12110. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  12111. {
  12112. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  12113. {
  12114. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.ReservationId)
  12115. {
  12116. //SystemStatus: 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault, 8: Reserved, 9: maintain
  12117. 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
  12118. {
  12119. if(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_IDLE) //S_IDLE
  12120. {
  12121. if((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.ConnectorPlugIn == 1) || (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.InProgress == 1))
  12122. {
  12123. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  12124. }
  12125. else
  12126. {
  12127. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  12128. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  12129. }
  12130. }
  12131. 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'))
  12132. {
  12133. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  12134. }
  12135. else if((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_PREPARING) || (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_RESERVATION) ) //S_PRECHARGE
  12136. {
  12137. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  12138. }
  12139. else
  12140. {
  12141. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  12142. }
  12143. }
  12144. 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
  12145. {
  12146. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  12147. }
  12148. }
  12149. else
  12150. {
  12151. //replace reservation
  12152. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  12153. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  12154. }
  12155. }
  12156. }// END FOR GB_QUANTITY
  12157. }
  12158. else
  12159. {
  12160. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D') // 'D' means DC
  12161. {
  12162. tempIndex = 2;
  12163. }
  12164. else
  12165. {
  12166. tempIndex = (connectorIdInt -1);
  12167. }
  12168. for (int index = 0; index < AC_QUANTITY; index++)
  12169. {
  12170. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  12171. {
  12172. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.AcChargingData[index].ReservationId)
  12173. {
  12174. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_FAULT)&&(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_ALARM)) //SYS_MODE_FAULT, SYS_MODE_ALARM
  12175. {
  12176. if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_IDLE) //S_IDLE
  12177. {
  12178. 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))
  12179. {
  12180. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  12181. }
  12182. else
  12183. {
  12184. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  12185. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  12186. }
  12187. }
  12188. 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'))
  12189. {
  12190. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  12191. }
  12192. else if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_PREPARING) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_RESERVATION) ) //S_PRECHARGE
  12193. {
  12194. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  12195. }
  12196. else
  12197. {
  12198. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  12199. }
  12200. }
  12201. 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
  12202. {
  12203. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  12204. }
  12205. }
  12206. else
  12207. {
  12208. //replace reservation
  12209. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  12210. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  12211. }
  12212. }
  12213. } // END FOR AC_QUANTITY
  12214. }
  12215. sprintf((char *)ShmOCPP16Data->ReserveNow[connectorIdInt-1].ResponseStatus, "%s" ,comfirmstr);
  12216. }
  12217. else if(connectorIdInt == 0)
  12218. {
  12219. //check Transaction active
  12220. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  12221. {
  12222. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ReservationId)
  12223. {
  12224. 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'))
  12225. {
  12226. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  12227. goto end;
  12228. }
  12229. else if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_PREPARING) //S_PRECHARGE
  12230. {
  12231. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  12232. goto end;
  12233. }
  12234. 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
  12235. {
  12236. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  12237. goto end;
  12238. }
  12239. else if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  12240. {
  12241. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  12242. goto end;
  12243. }
  12244. }
  12245. }// END FOR CHAdeMO_QUANTITY
  12246. for (int index = 0; index < CCS_QUANTITY; index++)
  12247. {
  12248. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ReservationId)
  12249. {
  12250. 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'))
  12251. {
  12252. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  12253. goto end;
  12254. }
  12255. else if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_PREPARING) //SYS_MODE_PREPARING
  12256. {
  12257. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  12258. goto end;
  12259. }
  12260. 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
  12261. {
  12262. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  12263. goto end;
  12264. }
  12265. else if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  12266. {
  12267. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  12268. goto end;
  12269. }
  12270. }
  12271. } // END FOR CCS_QUANTITY
  12272. for (int index = 0; index < GB_QUANTITY; index++)
  12273. {
  12274. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ReservationId)
  12275. {
  12276. 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'))
  12277. {
  12278. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  12279. goto end;
  12280. }
  12281. else if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_PREPARING) //S_PRECHARGE
  12282. {
  12283. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  12284. goto end;
  12285. }
  12286. 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
  12287. {
  12288. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  12289. goto end;
  12290. }
  12291. else if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  12292. {
  12293. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  12294. goto end;
  12295. }
  12296. }
  12297. } // END FOR GB_QUANTITY
  12298. for (int index = 0; index < AC_QUANTITY; index++)
  12299. {
  12300. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.AcChargingData[index].ReservationId)
  12301. {
  12302. 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'))
  12303. {
  12304. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  12305. goto end;
  12306. }
  12307. else if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_PREPARING) //S_PRECHARGE
  12308. {
  12309. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  12310. goto end;
  12311. }
  12312. 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
  12313. {
  12314. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  12315. goto end;
  12316. }
  12317. if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_IDLE) //S_IDLE
  12318. {
  12319. 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))
  12320. {
  12321. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  12322. goto end;
  12323. }
  12324. }
  12325. else if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  12326. {
  12327. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  12328. goto end;
  12329. }
  12330. }
  12331. }// END FOR AC_QUANTITY
  12332. //The connectorId is 0
  12333. ShmOCPP16Data->CsMsg.bits[0].ReserveNowReq = 1;
  12334. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  12335. sprintf((char *)ShmOCPP16Data->ReserveNow[0].ResponseStatus, "%s" ,comfirmstr);
  12336. ShmOCPP16Data->ReserveNow[0].ConnectorId = connectorIdInt;
  12337. sprintf((char *)ShmOCPP16Data->ReserveNow[0].ExpiryDate, "%s" , expiryDatestr);
  12338. sprintf((char *)ShmOCPP16Data->ReserveNow[0].IdTag, "%s" , idTagstr);
  12339. sprintf((char *)ShmOCPP16Data->ReserveNow[0].ParentIdTag, "%s" , parentIdTagstr);
  12340. ShmOCPP16Data->ReserveNow[0].ReservationId = reservationIdInt;
  12341. strcpy((char *)ShmOCPP16Data->ReserveNow[0].guid, uuid);
  12342. result = TRUE;
  12343. return result;
  12344. }
  12345. else
  12346. {
  12347. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  12348. sprintf((char *)ShmOCPP16Data->ReserveNow[connectorIdInt-1].ResponseStatus, "%s" ,comfirmstr);
  12349. }
  12350. if(strcmp(comfirmstr,"Accepted") == 0)
  12351. {
  12352. ShmOCPP16Data->ReserveNow[connectorIdInt-1].ConnectorId = connectorIdInt;
  12353. sprintf((char *)ShmOCPP16Data->ReserveNow[connectorIdInt-1].ExpiryDate, "%s" , expiryDatestr);
  12354. sprintf((char *)ShmOCPP16Data->ReserveNow[connectorIdInt-1].IdTag, "%s" , idTagstr);
  12355. sprintf((char *)ShmOCPP16Data->ReserveNow[connectorIdInt-1].ParentIdTag, "%s" , parentIdTagstr);
  12356. ShmOCPP16Data->ReserveNow[connectorIdInt-1].ReservationId = reservationIdInt;
  12357. strcpy((char *)ShmOCPP16Data->ReserveNow[connectorIdInt-1].guid, uuid);
  12358. result = TRUE;
  12359. return result;
  12360. }
  12361. end:
  12362. sendReserveNowTransactionConfirmation(uuid,comfirmstr);
  12363. //ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].ReserveNowConf = 1;
  12364. return result;
  12365. }
  12366. int handleResetRequest(char *uuid, char *payload)
  12367. {
  12368. mtrace();
  12369. int result = FAIL;
  12370. char sstr[10]={0},sstrtemp[30]={ 0 };
  12371. char typestr[10]={0};
  12372. char comfirmstr[20]={0};
  12373. int c = 0;
  12374. char *loc;
  12375. DEBUG_INFO("handleResetRequest...\n");
  12376. strcpy(sstrtemp, stringtrimspace(payload));
  12377. loc = strstr(sstrtemp, "type");
  12378. memset(sstr ,0, ARRAY_SIZE(sstr) );
  12379. c = 0;
  12380. while (loc[3+strlen("type")+c] != '\"')
  12381. {
  12382. sstr[c] = loc[3+strlen("type")+c];
  12383. c++;
  12384. }
  12385. sstr[c] = '\0';
  12386. strcpy(typestr,sstr);
  12387. sprintf((char *)ShmOCPP16Data->Reset.Type, "%s" ,typestr);
  12388. if((strcmp(typestr, ResetTypeStr[Hard])==0) || (strcmp(typestr, ResetTypeStr[Soft])==0))
  12389. {
  12390. ShmOCPP16Data->MsMsg.bits.ResetReq = 1;
  12391. strcpy((char *)ShmOCPP16Data->Reset.guid, uuid);
  12392. strcpy(comfirmstr, ResetStatusStr[ResetStatus_Accepted]);
  12393. sprintf((char *)ShmOCPP16Data->Reset.ResponseStatus, "%s" ,comfirmstr);
  12394. }
  12395. else
  12396. {
  12397. strcpy(comfirmstr, ResetStatusStr[ResetStatus_Rejected]);
  12398. sprintf((char *)ShmOCPP16Data->Reset.ResponseStatus, "%s" ,comfirmstr);
  12399. result = PASS;
  12400. }
  12401. sendResetConfirmation(uuid, comfirmstr);
  12402. return result;
  12403. }
  12404. int handleSendLocalListRequest(char *uuid, char *payload)
  12405. {
  12406. mtrace();
  12407. int result = FAIL;
  12408. char comfirmstr[20];
  12409. int checkState_Faulted = FALSE;
  12410. json_object *SendLocalList;
  12411. DEBUG_INFO("handleSendLocalListRequest...\n");
  12412. if(strcmp((const char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "FALSE") == 0) //For OCTT Test case
  12413. {
  12414. strcpy(comfirmstr, UpdateStatusStr[UpdateStatus_NotSupported]);
  12415. goto end;
  12416. }
  12417. //check Charge Point state
  12418. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  12419. {
  12420. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_FAULT) //S_FAULT ---> Faulted
  12421. {
  12422. checkState_Faulted = TRUE; //OCPP Status: Faulted
  12423. }
  12424. }
  12425. for (int index = 0; index < CCS_QUANTITY; index++)
  12426. {
  12427. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_FAULT) //S_FAULT ---> Faulted
  12428. {
  12429. checkState_Faulted = TRUE; //OCPP Status
  12430. }
  12431. }
  12432. for (int index = 0; index < GB_QUANTITY; index++)
  12433. {
  12434. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_FAULT) //S_FAULT ---> Faulted
  12435. {
  12436. checkState_Faulted = TRUE; //OCPP Status: Faulted
  12437. }
  12438. }
  12439. //check Charge Point state
  12440. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  12441. {
  12442. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_FAULT) //S_FAULT ---> Faulted
  12443. {
  12444. checkState_Faulted = TRUE; //OCPP Status: Faulted
  12445. }
  12446. }
  12447. //check Charge Point state
  12448. for (int index = 0; index < AC_QUANTITY; index++)
  12449. {
  12450. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_FAULT) //S_FAULT ---> Faulted
  12451. {
  12452. checkState_Faulted = TRUE; //OCPP Status: Faulted
  12453. }
  12454. }
  12455. if(checkState_Faulted == TRUE)
  12456. {
  12457. strcpy(comfirmstr, UpdateStatusStr[UpdateStatus_Failed]);
  12458. goto end;
  12459. }
  12460. // Parsing payload
  12461. SendLocalList = json_tokener_parse(payload);
  12462. if(!is_error(SendLocalList))
  12463. {
  12464. // Required data
  12465. ShmOCPP16Data->SendLocalList.ListVersion = json_object_get_int(json_object_object_get(SendLocalList, "listVersion"));
  12466. sprintf((char*)ShmOCPP16Data->SendLocalList.UpdateType, "%s", json_object_get_string(json_object_object_get(SendLocalList, "updateType")));
  12467. // Optional data
  12468. if(json_object_object_get(SendLocalList, "localAuthorizationList") != NULL)
  12469. {
  12470. //Check UpdateType
  12471. if(strcmp((char*)ShmOCPP16Data->SendLocalList.UpdateType, UpdateTypeStr[Full]) == 0)
  12472. {
  12473. //Local list full update
  12474. DEBUG_INFO("Local list full update.\n");
  12475. locallistVersion = 0;
  12476. OCPP_getListVerion();
  12477. /*if(ShmOCPP16Data->SendLocalList.ListVersion < locallistVersion)
  12478. {
  12479. strcpy(comfirmstr, UpdateStatusStr[UpdateStatus_Failed]);
  12480. goto end;
  12481. }*/
  12482. OCPP_cleanLocalList();
  12483. }
  12484. else if(strcmp((char*)ShmOCPP16Data->SendLocalList.UpdateType, UpdateTypeStr[Differential]) == 0)
  12485. {
  12486. //Local list different update
  12487. DEBUG_INFO("Local list different update.\n");
  12488. locallistVersion = 0;
  12489. OCPP_getListVerion();
  12490. if(ShmOCPP16Data->SendLocalList.ListVersion < locallistVersion)
  12491. {
  12492. strcpy(comfirmstr, UpdateStatusStr[UpdateStatus_VersionMismatch]);
  12493. goto end;
  12494. }
  12495. }
  12496. else
  12497. {
  12498. strcpy(comfirmstr, UpdateStatusStr[UpdateStatus_NotSupported]);
  12499. goto end;
  12500. }
  12501. memset(ShmOCPP16Data->SendLocalList.LocalAuthorizationList, 0 , sizeof(struct StructLocalAuthorizationList)*1);
  12502. for(int idx=0;idx<json_object_array_length(json_object_object_get(SendLocalList, "localAuthorizationList"));idx++)
  12503. {
  12504. 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")));
  12505. if(json_object_object_get(json_object_array_get_idx(json_object_object_get(SendLocalList, "localAuthorizationList"), idx), "idTagInfo") != NULL)
  12506. {
  12507. 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")));
  12508. if(json_object_object_get(json_object_object_get(json_object_array_get_idx(json_object_object_get(SendLocalList, "localAuthorizationList"), idx), "idTagInfo"), "expiryDate") != NULL)
  12509. 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")));
  12510. if(json_object_object_get(json_object_object_get(json_object_array_get_idx(json_object_object_get(SendLocalList, "localAuthorizationList"), idx), "idTagInfo"), "parentIdTag") != NULL)
  12511. 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")));
  12512. }
  12513. // Add to db
  12514. if(strcmp((char*)ShmOCPP16Data->SendLocalList.UpdateType, UpdateTypeStr[Full]) == 0)
  12515. {
  12516. //Local list full update
  12517. DEBUG_INFO("Local list full update item: %d, listVer: %d, %s, %s, %s, %s.\n",
  12518. idx,
  12519. ShmOCPP16Data->SendLocalList.ListVersion,
  12520. ShmOCPP16Data->SendLocalList.LocalAuthorizationList[0].IdTag,
  12521. ShmOCPP16Data->SendLocalList.LocalAuthorizationList[0].IdTagInfo.ParentIdTag,
  12522. ShmOCPP16Data->SendLocalList.LocalAuthorizationList[0].IdTagInfo.ExpiryDate,
  12523. ShmOCPP16Data->SendLocalList.LocalAuthorizationList[0].IdTagInfo.Status);
  12524. // update list
  12525. OCPP_addLocalList(ShmOCPP16Data->SendLocalList.ListVersion,
  12526. (char*)ShmOCPP16Data->SendLocalList.LocalAuthorizationList[0].IdTag,
  12527. (char*)ShmOCPP16Data->SendLocalList.LocalAuthorizationList[0].IdTagInfo.ParentIdTag,
  12528. (char*)ShmOCPP16Data->SendLocalList.LocalAuthorizationList[0].IdTagInfo.ExpiryDate,
  12529. (char*)ShmOCPP16Data->SendLocalList.LocalAuthorizationList[0].IdTagInfo.Status);
  12530. }
  12531. else if(strcmp((char*)ShmOCPP16Data->SendLocalList.UpdateType, UpdateTypeStr[Differential]) == 0)
  12532. {
  12533. DEBUG_INFO("Local list diff update item: %d,listVer: %d, %s, %s, %s, %s.\n",
  12534. idx,
  12535. ShmOCPP16Data->SendLocalList.ListVersion,
  12536. ShmOCPP16Data->SendLocalList.LocalAuthorizationList[0].IdTag,
  12537. ShmOCPP16Data->SendLocalList.LocalAuthorizationList[0].IdTagInfo.ParentIdTag,
  12538. ShmOCPP16Data->SendLocalList.LocalAuthorizationList[0].IdTagInfo.ExpiryDate,
  12539. ShmOCPP16Data->SendLocalList.LocalAuthorizationList[0].IdTagInfo.Status);
  12540. OCPP_addLocalList(ShmOCPP16Data->SendLocalList.ListVersion,
  12541. (char*)ShmOCPP16Data->SendLocalList.LocalAuthorizationList[0].IdTag,
  12542. (char*)ShmOCPP16Data->SendLocalList.LocalAuthorizationList[0].IdTagInfo.ParentIdTag,
  12543. (char*)ShmOCPP16Data->SendLocalList.LocalAuthorizationList[0].IdTagInfo.ExpiryDate,
  12544. (char*)ShmOCPP16Data->SendLocalList.LocalAuthorizationList[0].IdTagInfo.Status);
  12545. }
  12546. }
  12547. }
  12548. else
  12549. {
  12550. //Check UpdateType
  12551. if(strcmp((char*)ShmOCPP16Data->SendLocalList.UpdateType, UpdateTypeStr[Full]) == 0)
  12552. {
  12553. //Local list full update
  12554. DEBUG_INFO("If no (empty) localAuthorizationList is given and the updateType is Full, all identifications are removed from the list. \n");
  12555. OCPP_cleanLocalList();
  12556. strcpy(comfirmstr, UpdateStatusStr[UpdateStatus_Accepted]);
  12557. goto end;
  12558. }
  12559. if(strcmp((char*)ShmOCPP16Data->SendLocalList.UpdateType, UpdateTypeStr[Differential]) == 0)
  12560. {
  12561. //Local list different update
  12562. DEBUG_INFO("Requesting a Differential update without (empty) localAuthorizationList will have no effect on the list\n");
  12563. strcpy(comfirmstr, UpdateStatusStr[UpdateStatus_Accepted]);
  12564. goto end;
  12565. }
  12566. }
  12567. result = PASS;
  12568. }
  12569. strcpy(comfirmstr, UpdateStatusStr[UpdateStatus_Accepted]);
  12570. end:
  12571. json_object_put(SendLocalList);
  12572. sendSendLocalListConfirmation(uuid, comfirmstr);
  12573. return result;
  12574. }
  12575. int handleSetChargingProfileRequest(char *uuid, char *payload)
  12576. {
  12577. mtrace();
  12578. int result = FAIL;
  12579. struct StructSetChargingProfile SetProfileReq = {0};
  12580. int tempchargingProfileIdInt;
  12581. int tempstackLevelInt;
  12582. int chargingSchedulePeriodCount = 0;
  12583. char comfirmstr[20]={0};
  12584. char tempfile[] = "/Storage/OCPP/SetChargingProfiletemp.json";
  12585. char rmFileCmd[128]={0};
  12586. int profileQuantity = 0;
  12587. int replaceableProfileCnt = 0;
  12588. json_object *SetChargingProfile;
  12589. DEBUG_INFO("handleSetChargingProfileRequest\n");
  12590. SetChargingProfile = json_tokener_parse(payload);
  12591. if(!is_error(SetChargingProfile))
  12592. {
  12593. if(json_object_object_get(SetChargingProfile, "connectorId") != NULL)
  12594. {
  12595. SetProfileReq.ConnectorId = json_object_get_int(json_object_object_get(SetChargingProfile, "connectorId"));
  12596. }
  12597. if(json_object_object_get(SetChargingProfile, "csChargingProfiles") != NULL)
  12598. {
  12599. if(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingProfileId") != NULL)
  12600. {
  12601. SetProfileReq.ChargingProfile.ChargingProfileId = json_object_get_int(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingProfileId"));
  12602. }
  12603. else
  12604. {
  12605. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  12606. DEBUG_WARN("Cannot find chargingProfileId field.");
  12607. goto end;
  12608. }
  12609. if(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "stackLevel") != NULL)
  12610. {
  12611. SetProfileReq.ChargingProfile.StackLevel = json_object_get_int(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "stackLevel"));
  12612. }
  12613. else
  12614. {
  12615. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  12616. DEBUG_WARN("Cannot find stackLevel field.");
  12617. goto end;
  12618. }
  12619. if(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingProfilePurpose") != NULL)
  12620. {
  12621. strcpy((char*)SetProfileReq.ChargingProfile.ChargingProfilePurpose, json_object_get_string(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingProfilePurpose")));
  12622. }
  12623. else
  12624. {
  12625. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  12626. DEBUG_WARN("Cannot find chargingProfilePurpose field.");
  12627. goto end;
  12628. }
  12629. if(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingProfileKind") != NULL)
  12630. {
  12631. strcpy((char*)SetProfileReq.ChargingProfile.ChargingProfileKind, json_object_get_string(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingProfileKind")));
  12632. }
  12633. else
  12634. {
  12635. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  12636. DEBUG_WARN("Cannot find chargingProfileKind field.");
  12637. goto end;
  12638. }
  12639. if(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "transactionId") != NULL)
  12640. {
  12641. SetProfileReq.ChargingProfile.TransactionId = json_object_get_int(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "transactionId"));
  12642. }
  12643. if(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "recurrencyKind") != NULL)
  12644. {
  12645. strcpy((char*)SetProfileReq.ChargingProfile.RecurrencyKind, json_object_get_string(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "recurrencyKind")));
  12646. }
  12647. if(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "validFrom") != NULL)
  12648. {
  12649. strcpy((char*)SetProfileReq.ChargingProfile.ValidFrom, json_object_get_string(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "validFrom")));
  12650. }
  12651. if(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "validTo") != NULL)
  12652. {
  12653. strcpy((char*)SetProfileReq.ChargingProfile.ValidTo, json_object_get_string(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "validTo")));
  12654. }
  12655. if(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingSchedule") != NULL)
  12656. {
  12657. if(json_object_object_get(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingSchedule"), "chargingRateUnit") != NULL)
  12658. {
  12659. 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")));
  12660. }
  12661. else
  12662. {
  12663. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  12664. DEBUG_WARN("Cannot find chargingRateUnit field.");
  12665. goto end;
  12666. }
  12667. if(json_object_object_get(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingSchedule"), "duration") != NULL)
  12668. {
  12669. SetProfileReq.ChargingProfile.ChargingSchedule.Duration = json_object_get_int(json_object_object_get(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingSchedule"), "duration"));
  12670. }
  12671. if(json_object_object_get(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingSchedule"), "minChargingRate") != NULL)
  12672. {
  12673. SetProfileReq.ChargingProfile.ChargingSchedule.MinChargingRate = json_object_get_double(json_object_object_get(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingSchedule"), "minChargingRate"));
  12674. }
  12675. if(json_object_object_get(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingSchedule"), "startSchedule") != NULL)
  12676. {
  12677. 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")));
  12678. }
  12679. if(json_object_object_get(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod") != NULL)
  12680. {
  12681. chargingSchedulePeriodCount = json_object_array_length(json_object_object_get(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"));
  12682. if(chargingSchedulePeriodCount <= 10)
  12683. {
  12684. 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++)
  12685. {
  12686. 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)
  12687. {
  12688. 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"));
  12689. }
  12690. else
  12691. {
  12692. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  12693. DEBUG_WARN("Cannot find startPeriod field.");
  12694. goto end;
  12695. }
  12696. 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)
  12697. {
  12698. 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"));
  12699. }
  12700. else
  12701. {
  12702. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  12703. DEBUG_WARN("Cannot find limit field.");
  12704. goto end;
  12705. }
  12706. 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)
  12707. {
  12708. 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"));
  12709. }
  12710. }
  12711. }
  12712. }
  12713. else
  12714. {
  12715. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  12716. DEBUG_WARN("Cannot find chargingSchedulePeriod field.");
  12717. goto end;
  12718. }
  12719. }
  12720. else
  12721. {
  12722. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  12723. DEBUG_WARN("Cannot find chargingSchedule field.");
  12724. goto end;
  12725. }
  12726. }
  12727. }
  12728. // Profile periods quantity check
  12729. if( chargingSchedulePeriodCount > atoi((const char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemData))
  12730. {
  12731. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  12732. DEBUG_WARN("Profile period is over limit %s. \n", ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemData);
  12733. goto end;
  12734. }
  12735. // Check invalid limit
  12736. if((strcmp((char*)SetProfileReq.ChargingProfile.ChargingProfilePurpose, ChargingProfilePurposeTypeStr[ChargePointMaxProfile]) != 0) ||
  12737. ((strcmp((char*)SetProfileReq.ChargingProfile.ChargingProfilePurpose, ChargingProfilePurposeTypeStr[ChargePointMaxProfile]) == 0) && (ShmSysConfigAndInfo->SysConfig.isEnableLocalPowerSharing != 1)))
  12738. {
  12739. if(ShmSysConfigAndInfo->SysConfig.ModelName[0] == 'A')
  12740. {
  12741. for(uint8_t idxPeriod=0;idxPeriod<chargingSchedulePeriodCount;idxPeriod++)
  12742. {
  12743. 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)))) ||
  12744. (SetProfileReq.ChargingProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit > (SetProfileReq.ChargingProfile.ChargingSchedule.ChargingRateUnit[0]=='W'?modelnameInfo.ratedPower:ShmSysConfigAndInfo->SysConfig.RatingCurrent)))
  12745. {
  12746. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  12747. DEBUG_WARN("Profile period-%02d is invalid limit: %.2f %s with phase %d.\n", idxPeriod,
  12748. SetProfileReq.ChargingProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit,
  12749. SetProfileReq.ChargingProfile.ChargingSchedule.ChargingRateUnit,
  12750. (SetProfileReq.ChargingProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases==0?3:SetProfileReq.ChargingProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases));
  12751. goto end;
  12752. }
  12753. }
  12754. }
  12755. else
  12756. {
  12757. for(uint8_t idxPeriod=0;idxPeriod<chargingSchedulePeriodCount;idxPeriod++)
  12758. {
  12759. 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) ||
  12760. (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)))
  12761. {
  12762. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  12763. DEBUG_WARN("Profile period-%02d is invalid limit: %.2f %s with phase %d.\n", idxPeriod,
  12764. SetProfileReq.ChargingProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit,
  12765. SetProfileReq.ChargingProfile.ChargingSchedule.ChargingRateUnit,
  12766. (SetProfileReq.ChargingProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases==0?3:SetProfileReq.ChargingProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases));
  12767. goto end;
  12768. }
  12769. }
  12770. }
  12771. }
  12772. // Profile purpose info check
  12773. if(strcmp((char*)SetProfileReq.ChargingProfile.ChargingProfilePurpose, ChargingProfilePurposeTypeStr[ChargePointMaxProfile]) == 0)
  12774. {
  12775. FILE *fp;
  12776. DEBUG_INFO("Profile purpose is ChargePointMaxProfile.\n");
  12777. if(SetProfileReq.ConnectorId != 0)
  12778. {
  12779. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  12780. DEBUG_WARN("Profile connector id is not 0.\n");
  12781. goto end;
  12782. }
  12783. fp = fopen(ChargePointMaxProfile_JSON, "r");
  12784. if (!fp)
  12785. {
  12786. DEBUG_INFO("%s does not create.\n", ChargePointMaxProfile_JSON);
  12787. fp = fopen(ChargePointMaxProfile_JSON, "w+");
  12788. }
  12789. else
  12790. {
  12791. char *line = NULL;
  12792. size_t len = 0;
  12793. while(getline(&line, &len, fp) != -1)
  12794. {
  12795. json_object *obj = NULL;
  12796. obj = json_tokener_parse(line);
  12797. if(is_error(obj))
  12798. {
  12799. DEBUG_ERROR("Parse txProfile from file error.\n");
  12800. }
  12801. else
  12802. {
  12803. if((json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileId")) != SetProfileReq.ChargingProfile.ChargingProfileId) &&
  12804. (json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "stackLevel")) != SetProfileReq.ChargingProfile.StackLevel))
  12805. {
  12806. profileQuantity += 1;
  12807. }
  12808. else
  12809. replaceableProfileCnt += 1;
  12810. }
  12811. }
  12812. }
  12813. fclose(fp);
  12814. }
  12815. else if(strcmp((char*)SetProfileReq.ChargingProfile.ChargingProfilePurpose, ChargingProfilePurposeTypeStr[TxDefaultProfile]) == 0)
  12816. {
  12817. FILE *fp;
  12818. char filename[128]={0};
  12819. int tmpProfileQuantity;
  12820. DEBUG_INFO("Profile purpose is TxDefaultProfile.\n");
  12821. if((SetProfileReq.ConnectorId != 0) && (SetProfileReq.ConnectorId > gunTotalNumber))
  12822. {
  12823. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  12824. DEBUG_WARN("Profile connector id is over max gun number.\n");
  12825. goto end;
  12826. }
  12827. if(SetProfileReq.ConnectorId == 0)
  12828. {
  12829. for(int idxCon=1;idxCon<=gunTotalNumber;idxCon++)
  12830. {
  12831. tmpProfileQuantity = 0;
  12832. memset(filename, 0, ARRAY_SIZE(filename));
  12833. sprintf(filename, "/Storage/OCPP/TxDefaultProfile_%d.json", idxCon);
  12834. fp = fopen(filename, "r");
  12835. if (!fp)
  12836. {
  12837. DEBUG_INFO("%s does not create.\n", filename);
  12838. fp = fopen(filename, "w+");
  12839. }
  12840. else
  12841. {
  12842. char *line = NULL;
  12843. size_t len = 0;
  12844. while(getline(&line, &len, fp) != -1)
  12845. {
  12846. json_object *obj = NULL;
  12847. obj = json_tokener_parse(line);
  12848. if(is_error(obj))
  12849. {
  12850. DEBUG_ERROR("Parse txProfile from file error.\n");
  12851. }
  12852. else
  12853. {
  12854. if((json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileId")) != SetProfileReq.ChargingProfile.ChargingProfileId) &&
  12855. (json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "stackLevel")) != SetProfileReq.ChargingProfile.StackLevel))
  12856. {
  12857. tmpProfileQuantity += 1;
  12858. }
  12859. else
  12860. replaceableProfileCnt += 1;
  12861. }
  12862. }
  12863. }
  12864. fclose(fp);
  12865. profileQuantity = (profileQuantity < tmpProfileQuantity) ? tmpProfileQuantity : profileQuantity;
  12866. }
  12867. }
  12868. else
  12869. {
  12870. memset(filename, 0, ARRAY_SIZE(filename));
  12871. sprintf(filename, "/Storage/OCPP/TxDefaultProfile_%d.json", SetProfileReq.ConnectorId);
  12872. fp = fopen(filename, "r");
  12873. if (!fp)
  12874. {
  12875. DEBUG_INFO("%s does not create.\n", filename);
  12876. fp = fopen(filename, "w+");
  12877. }
  12878. else
  12879. {
  12880. char *line = NULL;
  12881. size_t len = 0;
  12882. while(getline(&line, &len, fp) != -1)
  12883. {
  12884. json_object *obj = NULL;
  12885. obj = json_tokener_parse(line);
  12886. if(is_error(obj))
  12887. {
  12888. DEBUG_ERROR("Parse txProfile from file error.\n");
  12889. }
  12890. else
  12891. {
  12892. if((json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileId")) != SetProfileReq.ChargingProfile.ChargingProfileId) &&
  12893. (json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "stackLevel")) != SetProfileReq.ChargingProfile.StackLevel))
  12894. {
  12895. profileQuantity += 1;
  12896. }
  12897. else
  12898. replaceableProfileCnt += 1;
  12899. }
  12900. }
  12901. }
  12902. fclose(fp);
  12903. }
  12904. }
  12905. else if(strcmp((char*)SetProfileReq.ChargingProfile.ChargingProfilePurpose, ChargingProfilePurposeTypeStr[TxProfile]) == 0)
  12906. {
  12907. int isMatchTransactiodId= FALSE;
  12908. FILE *fp;
  12909. char filename[128]={0};
  12910. DEBUG_INFO("Profile purposeStr is TxProfile.\n");
  12911. //---TxProfile SHALL only be set at Charge Point ConnectorId > 0. ---//
  12912. if(SetProfileReq.ConnectorId == 0)
  12913. {
  12914. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  12915. DEBUG_WARN("Profile connector id is 0.\n");
  12916. goto end;
  12917. }
  12918. int tempIndex = 0;
  12919. //check Transaction active
  12920. if(gunType[SetProfileReq.ConnectorId -1] == GUN_TYPE_CHAdeMO)
  12921. {
  12922. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  12923. {
  12924. tempIndex = (((SetProfileReq.ConnectorId -1)==2) ? 1: 0);
  12925. }
  12926. else
  12927. {
  12928. tempIndex = SetProfileReq.ConnectorId -1;
  12929. }
  12930. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  12931. {
  12932. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  12933. {
  12934. if((SYS_MODE_PREPARING <= ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus) && (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus <= SYS_MODE_TERMINATING)) // S_CHARGING
  12935. {
  12936. if(SetProfileReq.ChargingProfile.TransactionId == ShmOCPP16Data->StartTransaction[SetProfileReq.ConnectorId -1].ResponseTransactionId)
  12937. {
  12938. isMatchTransactiodId = TRUE;
  12939. break;
  12940. }
  12941. }
  12942. }
  12943. }
  12944. }
  12945. else if(gunType[SetProfileReq.ConnectorId -1] == GUN_TYPE_CCS)
  12946. {
  12947. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  12948. {
  12949. tempIndex = (((SetProfileReq.ConnectorId -1)==2) ? 1: 0);
  12950. }
  12951. else
  12952. {
  12953. tempIndex = SetProfileReq.ConnectorId -1;
  12954. }
  12955. for (int index = 0; index < CCS_QUANTITY; index++)
  12956. {
  12957. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  12958. {
  12959. if(((SYS_MODE_PREPARING <= ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus) && (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus <= SYS_MODE_TERMINATING)) ||
  12960. ((SYS_MODE_CCS_PRECHARGE_STEP0 <= ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus) && (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus <= SYS_MODE_CCS_PRECHARGE_STEP1))) // S_CHARGING
  12961. {
  12962. if(SetProfileReq.ChargingProfile.TransactionId == ShmOCPP16Data->StartTransaction[SetProfileReq.ConnectorId -1].ResponseTransactionId)
  12963. {
  12964. isMatchTransactiodId = TRUE;
  12965. break;
  12966. }
  12967. }
  12968. }
  12969. }
  12970. }
  12971. else if(gunType[SetProfileReq.ConnectorId -1] == GUN_TYPE_GBT)
  12972. {
  12973. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  12974. {
  12975. tempIndex = (((SetProfileReq.ConnectorId -1)==2) ? 1: 0);
  12976. }
  12977. else
  12978. {
  12979. tempIndex = SetProfileReq.ConnectorId -1;
  12980. }
  12981. for (int index = 0; index < GB_QUANTITY; index++)
  12982. {
  12983. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  12984. {
  12985. if((SYS_MODE_PREPARING <= ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus) && (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus <= SYS_MODE_TERMINATING)) // S_CHARGING
  12986. {
  12987. if(SetProfileReq.ChargingProfile.TransactionId == ShmOCPP16Data->StartTransaction[SetProfileReq.ConnectorId -1].ResponseTransactionId)
  12988. {
  12989. isMatchTransactiodId = TRUE;
  12990. break;
  12991. }
  12992. }
  12993. }
  12994. }
  12995. }
  12996. else if(gunType[SetProfileReq.ConnectorId -1] == GUN_TYPE_DO)
  12997. {
  12998. tempIndex = SetProfileReq.ConnectorId -1;
  12999. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  13000. {
  13001. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  13002. {
  13003. if(((SYS_MODE_PREPARING <= ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus) && (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus <= SYS_MODE_TERMINATING)) ||
  13004. ((SYS_MODE_CCS_PRECHARGE_STEP0 <= ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus) && (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus <= SYS_MODE_CCS_PRECHARGE_STEP1))) // S_CHARGING
  13005. {
  13006. if(SetProfileReq.ChargingProfile.TransactionId == ShmOCPP16Data->StartTransaction[SetProfileReq.ConnectorId -1].ResponseTransactionId)
  13007. {
  13008. isMatchTransactiodId = TRUE;
  13009. break;
  13010. }
  13011. }
  13012. }
  13013. }
  13014. }
  13015. else
  13016. {
  13017. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D') // 'D' means DC
  13018. {
  13019. tempIndex = 2;
  13020. }
  13021. else
  13022. {
  13023. tempIndex = (SetProfileReq.ConnectorId -1);
  13024. }
  13025. for (int index = 0; index < AC_QUANTITY; index++)
  13026. {
  13027. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  13028. {
  13029. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_TERMINATING)) // S_CHARGING
  13030. {
  13031. if(SetProfileReq.ChargingProfile.TransactionId == ShmOCPP16Data->StartTransaction[SetProfileReq.ConnectorId -1].ResponseTransactionId)
  13032. {
  13033. isMatchTransactiodId = TRUE;
  13034. break;
  13035. }
  13036. }
  13037. }
  13038. }
  13039. }
  13040. //check Transaction active
  13041. if(isMatchTransactiodId == FALSE)
  13042. {
  13043. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  13044. DEBUG_WARN("Tx profile transaction id is not match.\n");
  13045. goto end;
  13046. }
  13047. if((SetProfileReq.ConnectorId != 0) && (SetProfileReq.ConnectorId > gunTotalNumber))
  13048. {
  13049. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  13050. DEBUG_WARN("Connector id is over max gun number.\n");
  13051. goto end;
  13052. }
  13053. sprintf(filename, "/Storage/OCPP/TxProfile_%d.json", SetProfileReq.ConnectorId);
  13054. fp = fopen(filename, "r");
  13055. if (!fp)
  13056. {
  13057. DEBUG_INFO("%s does not create.\n", filename);
  13058. fp = fopen(filename, "w+");
  13059. }
  13060. else
  13061. {
  13062. char *line = NULL;
  13063. size_t len = 0;
  13064. while(getline(&line, &len, fp) != -1)
  13065. {
  13066. json_object *obj = NULL;
  13067. obj = json_tokener_parse(line);
  13068. if(is_error(obj))
  13069. {
  13070. DEBUG_ERROR("Parse txProfile from file error.\n");
  13071. }
  13072. else
  13073. {
  13074. if((json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileId")) != SetProfileReq.ChargingProfile.ChargingProfileId) &&
  13075. (json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "stackLevel")) != SetProfileReq.ChargingProfile.StackLevel))
  13076. {
  13077. profileQuantity += 1;
  13078. }
  13079. else
  13080. replaceableProfileCnt += 1;
  13081. }
  13082. }
  13083. }
  13084. fclose(fp);
  13085. }
  13086. // Check ChargeProfileMaxStackLevel
  13087. DEBUG_INFO("%s profile quantity: %d\n", SetProfileReq.ChargingProfile.ChargingProfilePurpose, profileQuantity);
  13088. if(profileQuantity >= atoi((const char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemData))
  13089. {
  13090. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  13091. DEBUG_WARN("Purpose profile quantify is over stack limit %s.\n", ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemData);
  13092. goto end;
  13093. }
  13094. //------------------------------Start: Check Configuration Key "MaxChargingProfilesInstalled" Logic---------------------------------------//
  13095. {
  13096. FILE *fp;
  13097. char dataLine[4096]={0};
  13098. char fnametemp[128]={0};
  13099. int tmpProfileQuantity;
  13100. //Check ChargePointMaxProfile.json exit
  13101. profileQuantity = 0;
  13102. if((access("/Storage/OCPP/ChargePointMaxProfile.json",F_OK))!=-1)
  13103. {
  13104. fp = fopen("/Storage/OCPP/ChargePointMaxProfile.json", "r");
  13105. //Check Charging Profile Count
  13106. tmpProfileQuantity = 0;
  13107. while(fscanf(fp, "%s", dataLine) != EOF)
  13108. {
  13109. if(strstr(dataLine, "chargingProfileId")!= NULL)
  13110. {
  13111. profileQuantity += 1;
  13112. tmpProfileQuantity += 1;
  13113. }
  13114. memset(dataLine, 0, ARRAY_SIZE(dataLine));
  13115. }
  13116. fclose(fp);
  13117. DEBUG_INFO("ChargePointMaxProfile.json has %d charging Profile\n", tmpProfileQuantity);
  13118. }
  13119. //Check TxDefaultProfile_%d.json
  13120. for(int idxCon=1; idxCon <= gunTotalNumber; idxCon++)
  13121. {
  13122. memset(fnametemp, 0, ARRAY_SIZE(fnametemp));
  13123. sprintf(fnametemp, "/Storage/OCPP/TxDefaultProfile_%d.json", idxCon);
  13124. if((access(fnametemp,F_OK))!=-1)
  13125. {
  13126. fp = fopen(fnametemp, "r");
  13127. //Check Charging Profile Count
  13128. tmpProfileQuantity = 0;
  13129. while(fscanf(fp, "%s", dataLine) != EOF)
  13130. {
  13131. //DEBUG_INFO("word=%s\n",word);
  13132. if(strstr(dataLine, "chargingProfileId")!= NULL)
  13133. {
  13134. profileQuantity += 1;
  13135. tmpProfileQuantity += 1;
  13136. }
  13137. memset(dataLine, 0, ARRAY_SIZE(dataLine));
  13138. }
  13139. fclose(fp);
  13140. DEBUG_INFO("%s has %d charging Profile\n",fnametemp, tmpProfileQuantity);
  13141. }
  13142. }
  13143. //Check TxProfile_%d.json
  13144. for(int idxCon=1; idxCon <= gunTotalNumber; idxCon++)
  13145. {
  13146. memset(fnametemp, 0, ARRAY_SIZE(fnametemp));
  13147. sprintf(fnametemp, "/Storage/OCPP/TxProfile_%d.json", idxCon);
  13148. if((access(fnametemp,F_OK))!=-1)
  13149. {
  13150. fp = fopen(fnametemp, "r");
  13151. //Check Charging Profile Count
  13152. tmpProfileQuantity = 0;
  13153. while(fscanf(fp, "%s", dataLine) != EOF)
  13154. {
  13155. if(strstr(dataLine, "chargingProfileId")!= NULL)
  13156. {
  13157. profileQuantity += 1;
  13158. tmpProfileQuantity += 1;
  13159. }
  13160. memset(dataLine, 0, ARRAY_SIZE(dataLine));
  13161. }
  13162. fclose(fp);
  13163. DEBUG_INFO("%s has %d charging Profile\n",fnametemp, tmpProfileQuantity);
  13164. }
  13165. }
  13166. DEBUG_INFO("All purpose profile quantity: %d\n", profileQuantity);
  13167. DEBUG_INFO("Replaceable profile quantity: %d\n", replaceableProfileCnt);
  13168. // To check total Profile quantity
  13169. if((SetProfileReq.ConnectorId > 0) || (strcmp((char*)SetProfileReq.ChargingProfile.ChargingProfilePurpose, ChargingProfilePurposeTypeStr[ChargePointMaxProfile]) == 0))
  13170. {
  13171. if((profileQuantity-replaceableProfileCnt) >= atoi((const char*)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemData))
  13172. {
  13173. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected]);
  13174. DEBUG_WARN("Total profile quantify is over installed limit %s.\n", ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemData);
  13175. goto end;
  13176. }
  13177. }
  13178. else
  13179. {
  13180. if((profileQuantity+gunTotalNumber-replaceableProfileCnt) > atoi((const char*)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemData))
  13181. {
  13182. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected]);
  13183. DEBUG_WARN("Total profile quantify is over installed limit %s.\n", ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemData);
  13184. goto end;
  13185. }
  13186. }
  13187. }
  13188. //------------------------------End: Check Configuration Key "MaxChargingProfilesInstalled" Logic---------------------------------------//
  13189. //**********************************Write to File********************************************************/
  13190. {
  13191. FILE *infile;
  13192. FILE *outfile;
  13193. char dataLine[4096]={0};
  13194. char filename[128]={0};
  13195. int chkChar=0;
  13196. for(int idxCon=1; idxCon <= (SetProfileReq.ConnectorId==0?gunTotalNumber:1); idxCon++)
  13197. {
  13198. if(strcmp((char*)SetProfileReq.ChargingProfile.ChargingProfilePurpose, ChargingProfilePurposeTypeStr[ChargePointMaxProfile]) == 0)
  13199. {
  13200. sprintf(filename, "%s", ChargePointMaxProfile_JSON);
  13201. }
  13202. else if(strcmp((char*)SetProfileReq.ChargingProfile.ChargingProfilePurpose, ChargingProfilePurposeTypeStr[TxDefaultProfile]) == 0)
  13203. {
  13204. if(SetProfileReq.ConnectorId==0)
  13205. sprintf(filename, "/Storage/OCPP/TxDefaultProfile_%d.json", idxCon);
  13206. else
  13207. sprintf(filename, "/Storage/OCPP/TxDefaultProfile_%d.json", SetProfileReq.ConnectorId);
  13208. }
  13209. else
  13210. {
  13211. sprintf(filename, "/Storage/OCPP/TxProfile_%d.json", SetProfileReq.ConnectorId);
  13212. }
  13213. infile = fopen (filename, "r");
  13214. outfile = fopen (tempfile, "w");
  13215. chkChar = fgetc(infile);
  13216. rewind(infile);
  13217. if(chkChar == EOF)
  13218. {
  13219. // Profile is empty
  13220. if((strcmp((char*)SetProfileReq.ChargingProfile.ChargingProfilePurpose, ChargingProfilePurposeTypeStr[TxDefaultProfile]) == 0) && (SetProfileReq.ConnectorId==0))
  13221. json_object_object_add(SetChargingProfile, "connectorId", json_object_new_int(idxCon));
  13222. fprintf(outfile,"%s\n",json_object_to_json_string_ext(SetChargingProfile, JSON_C_TO_STRING_PLAIN));
  13223. fclose(infile);
  13224. fclose(outfile);
  13225. sprintf(rmFileCmd,"rm -f %s",filename);
  13226. system(rmFileCmd);
  13227. rename(tempfile, filename);
  13228. }
  13229. else
  13230. {
  13231. // Profile is not empty
  13232. int ChargingProfileAdded = FALSE;
  13233. while (fgets(dataLine, ARRAY_SIZE(dataLine), infile) != NULL)
  13234. {
  13235. dataLine[strlen(dataLine) - 1] = '\0'; // eat the newline fgets() stores
  13236. json_object *tmpChargingProfile;
  13237. tmpChargingProfile = json_tokener_parse(dataLine);
  13238. if(!is_error(SetChargingProfile))
  13239. {
  13240. if(json_object_object_get(tmpChargingProfile, "csChargingProfiles") != NULL)
  13241. {
  13242. if(json_object_object_get(json_object_object_get(tmpChargingProfile, "csChargingProfiles"), "chargingProfileId") != NULL)
  13243. {
  13244. tempchargingProfileIdInt = json_object_get_int(json_object_object_get(json_object_object_get(tmpChargingProfile, "csChargingProfiles"), "chargingProfileId"));
  13245. }
  13246. if(json_object_object_get(json_object_object_get(tmpChargingProfile, "csChargingProfiles"), "stackLevel") != NULL)
  13247. {
  13248. tempstackLevelInt = json_object_get_int(json_object_object_get(json_object_object_get(tmpChargingProfile, "csChargingProfiles"), "stackLevel"));
  13249. }
  13250. }
  13251. }
  13252. json_object_put(tmpChargingProfile);
  13253. if((tempchargingProfileIdInt == SetProfileReq.ChargingProfile.ChargingProfileId))
  13254. {
  13255. if(ChargingProfileAdded == FALSE)
  13256. {
  13257. if((strcmp((char*)SetProfileReq.ChargingProfile.ChargingProfilePurpose, ChargingProfilePurposeTypeStr[TxDefaultProfile]) == 0) && (SetProfileReq.ConnectorId==0))
  13258. json_object_object_add(SetChargingProfile, "connectorId", json_object_new_int(idxCon));
  13259. fprintf(outfile,"%s\n",json_object_to_json_string_ext(SetChargingProfile, JSON_C_TO_STRING_PLAIN));
  13260. ChargingProfileAdded = TRUE;
  13261. }
  13262. }
  13263. else if(tempstackLevelInt == SetProfileReq.ChargingProfile.StackLevel)
  13264. {
  13265. if(ChargingProfileAdded == FALSE)
  13266. {
  13267. if((strcmp((char*)SetProfileReq.ChargingProfile.ChargingProfilePurpose, ChargingProfilePurposeTypeStr[TxDefaultProfile]) == 0) && (SetProfileReq.ConnectorId==0))
  13268. json_object_object_add(SetChargingProfile, "connectorId", json_object_new_int(idxCon));
  13269. fprintf(outfile,"%s\n",json_object_to_json_string_ext(SetChargingProfile, JSON_C_TO_STRING_PLAIN));
  13270. ChargingProfileAdded = TRUE;
  13271. }
  13272. }
  13273. else
  13274. {
  13275. fprintf(outfile,"%s\n",dataLine);
  13276. if(ChargingProfileAdded == FALSE)
  13277. {
  13278. if((strcmp((char*)SetProfileReq.ChargingProfile.ChargingProfilePurpose, ChargingProfilePurposeTypeStr[TxDefaultProfile]) == 0) && (SetProfileReq.ConnectorId==0))
  13279. json_object_object_add(SetChargingProfile, "connectorId", json_object_new_int(idxCon));
  13280. fprintf(outfile,"%s\n",json_object_to_json_string_ext(SetChargingProfile, JSON_C_TO_STRING_PLAIN));
  13281. ChargingProfileAdded = TRUE;
  13282. }
  13283. }
  13284. } // end of while loop
  13285. fclose(infile);
  13286. fclose(outfile);
  13287. sprintf(rmFileCmd,"rm -f %s",filename);
  13288. system(rmFileCmd);
  13289. rename(tempfile, filename);
  13290. }
  13291. }
  13292. sleep(1);
  13293. result = TRUE;
  13294. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Accepted] );
  13295. }
  13296. end:
  13297. json_object_put(SetChargingProfile);
  13298. if(strcmp(comfirmstr, ChargingProfileStatusStr[ChargingProfileStatus_Accepted]) == 0)
  13299. {
  13300. if(SetProfileReq.ConnectorId == 0)
  13301. {
  13302. for(uint8_t idx=0;idx<gunTotalNumber;idx++)
  13303. {
  13304. checkCompositeSchedule((idx+1), 86400, &ShmOCPP16Data->SmartChargingProfile[idx], TRUE);
  13305. }
  13306. }
  13307. else
  13308. checkCompositeSchedule(SetProfileReq.ConnectorId, 86400, &ShmOCPP16Data->SmartChargingProfile[SetProfileReq.ConnectorId-1], TRUE);
  13309. }
  13310. sendSetChargingProfileConfirmation(uuid, comfirmstr);
  13311. system("/bin/fsync -d /dev/mtdblock13;/bin/sync &");
  13312. return result;
  13313. }
  13314. int handleTriggerMessageRequest(char *uuid, char *payload)
  13315. {
  13316. mtrace();
  13317. int result = FAIL;
  13318. int connectorIdIsNULL = FALSE;
  13319. int connectorIdInt =0;
  13320. char sstr[40]={0},sstrtemp[100]={ 0 };
  13321. char requestedMessagestr[40]={0};
  13322. char comfirmstr[20]={0};
  13323. int c = 0;
  13324. char *loc;
  13325. DEBUG_INFO("handleTriggerMessageRequest\n");
  13326. //[2,"266e23f4-27a4-41cf-84cb-aadf56b9523f","TriggerMessage",{"requestedMessage":"DiagnosticsStatusNotification","connectorId":1}]
  13327. strcpy(sstrtemp, stringtrimspace(payload));
  13328. c = 0;
  13329. loc = strstr(sstrtemp, "requestedMessage");
  13330. while (loc[3+strlen("requestedMessage")+c] != '\"')
  13331. {
  13332. sstr[c] = loc[3+strlen("requestedMessage")+c];
  13333. c++;
  13334. }
  13335. sstr[c] = '\0';
  13336. strcpy(requestedMessagestr, sstr);
  13337. c = 0;
  13338. loc = strstr(sstrtemp, "connectorId");
  13339. if(loc == NULL)
  13340. {
  13341. connectorIdIsNULL = TRUE;
  13342. }
  13343. else
  13344. {
  13345. memset(sstr ,0, ARRAY_SIZE(sstr) );
  13346. while ((loc[strlen("connectorId")+2+c] != ',')&&(loc[strlen("connectorId")+2+c] != '}'))
  13347. {
  13348. sstr[c] = loc[strlen("connectorId")+2+c];
  13349. //printf("i=%d sstr=%c\n",c, sstr[c]);
  13350. c++;
  13351. }
  13352. sstr[c] = '\0';
  13353. connectorIdInt = atoi(sstr);
  13354. }
  13355. if((connectorIdIsNULL == TRUE) || ((connectorIdIsNULL == FALSE) && ((connectorIdInt > 0) && (connectorIdInt <= gunTotalNumber /*(CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY)*/ ))) )
  13356. {
  13357. sprintf((char *)ShmOCPP16Data->TriggerMessage[connectorIdInt -1].RequestedMessage, "%s" ,requestedMessagestr);
  13358. ShmOCPP16Data->TriggerMessage[connectorIdInt -1].ConnectorId = connectorIdInt;
  13359. if((strcmp(requestedMessagestr, MessageTriggerStr[FirmwareStatusNotification]) != 0) &&
  13360. (strcmp(requestedMessagestr, MessageTriggerStr[DiagnosticsStatusNotification]) != 0) &&
  13361. (strcmp(requestedMessagestr, MessageTriggerStr[BootNotification]) != 0 ) &&
  13362. (strcmp(requestedMessagestr, MessageTriggerStr[Heartbeat]) != 0) &&
  13363. (strcmp(requestedMessagestr, MessageTriggerStr[MeterValues]) != 0) &&
  13364. (strcmp(requestedMessagestr, MessageTriggerStr[StatusNotification]) != 0 ))
  13365. {
  13366. sprintf(comfirmstr, "%s",TriggerMessageStatusStr[TriggerMessageStatus_NotImplemented] );
  13367. sendTriggerMessageConfirmation(uuid,comfirmstr);
  13368. return TRUE;
  13369. }
  13370. else
  13371. {
  13372. sprintf(comfirmstr, "%s",TriggerMessageStatusStr[TriggerMessageStatus_Accepted] );
  13373. sendTriggerMessageConfirmation(uuid,comfirmstr);
  13374. }
  13375. }
  13376. else if(connectorIdIsNULL == FALSE && ((connectorIdInt <= 0) || (connectorIdInt > gunTotalNumber /*(CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY)*/) ))
  13377. {
  13378. sprintf(comfirmstr, "%s",TriggerMessageStatusStr[TriggerMessageStatus_Rejected] );
  13379. sendTriggerMessageConfirmation(uuid,comfirmstr);
  13380. return TRUE;
  13381. }
  13382. //==========================
  13383. // Trigger message
  13384. //==========================
  13385. if( strcmp(requestedMessagestr, MessageTriggerStr[FirmwareStatusNotification]) == 0)
  13386. {
  13387. if((strlen((char*)ShmOCPP16Data->FirmwareStatusNotification.Status) == 0) ||
  13388. ((FirmwareStatusNotificationStatus != FIRMWARE_STATUS_DOWNLOADING) && (FirmwareStatusNotificationStatus != FIRMWARE_STATUS_DOWNLOADED) && (FirmwareStatusNotificationStatus != FIRMWARE_STATUS_IDLE) && (FirmwareStatusNotificationStatus != FIRMWARE_STATUS_INSTALLING)))
  13389. {
  13390. FirmwareStatusNotificationStatus = FIRMWARE_STATUS_IDLE;
  13391. sprintf((char*)ShmOCPP16Data->FirmwareStatusNotification.Status, "%s", FirmwareStatusStr[FirmwareStatus_Idle]);
  13392. }
  13393. ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationReq = 1;
  13394. }
  13395. else if(strcmp(requestedMessagestr, MessageTriggerStr[DiagnosticsStatusNotification]) == 0 )
  13396. {
  13397. if(strlen((char*)ShmOCPP16Data->DiagnosticsStatusNotification.Status) == 0)
  13398. sprintf((char*)ShmOCPP16Data->DiagnosticsStatusNotification.Status, "%s", DiagnosticsStatusStr[DiagnosticsStatus_Idle]);
  13399. ShmOCPP16Data->SpMsg.bits.DiagnosticsStatusNotificationReq = 1;
  13400. }
  13401. else if(strcmp(requestedMessagestr, MessageTriggerStr[BootNotification]) == 0 )
  13402. {
  13403. //sendBootNotificationRequest();
  13404. server_sign = FALSE;
  13405. }
  13406. else if(strcmp(requestedMessagestr, MessageTriggerStr[Heartbeat]) == 0 )
  13407. {
  13408. refreshStartTimer(&clientTime.Heartbeat);
  13409. clientTime.Heartbeat.tv_sec -= ShmOCPP16Data->BootNotification.ResponseHeartbeatInterval;
  13410. }
  13411. else if (strcmp(requestedMessagestr, MessageTriggerStr[MeterValues]) == 0 )
  13412. {
  13413. if(connectorIdIsNULL == FALSE)
  13414. {
  13415. if((connectorIdInt > 0) && ((connectorIdInt -1) < gunTotalNumber))
  13416. {
  13417. //sendMeterValuesRequest((connectorIdInt -1), ReadingContext_Trigger);
  13418. cpinitateMsg.bits[connectorIdInt -1].TriggerMeterValue = 1;
  13419. }
  13420. }
  13421. else
  13422. {
  13423. for(int idx=0;idx< gunTotalNumber;idx++)
  13424. {
  13425. //sendMeterValuesRequest(idx, ReadingContext_Trigger);
  13426. cpinitateMsg.bits[idx].TriggerMeterValue = 1;
  13427. }
  13428. }
  13429. }
  13430. else if(strcmp(requestedMessagestr, MessageTriggerStr[StatusNotification]) == 0 )
  13431. {
  13432. if(connectorIdIsNULL == FALSE)
  13433. {
  13434. if((connectorIdInt > 0) && ((connectorIdInt-1) < gunTotalNumber))
  13435. {
  13436. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].TriggerMessageReq = 1;
  13437. cpinitateMsg.bits[connectorIdInt-1].TriggerStatusNotificationReq = 1;
  13438. //clientTime.StatusNotification[connectorIdInt-1] = time((time_t*)NULL);
  13439. }
  13440. }
  13441. else
  13442. {
  13443. for(int idx=0;idx< gunTotalNumber;idx++)
  13444. {
  13445. ShmOCPP16Data->CsMsg.bits[idx].TriggerMessageReq = 1;
  13446. cpinitateMsg.bits[idx].TriggerStatusNotificationReq = 1;
  13447. //clientTime.StatusNotification[idx] = time((time_t*)NULL);
  13448. }
  13449. }
  13450. }
  13451. return result;
  13452. }
  13453. int handleUnlockConnectorRequest(char *uuid, char *payload)
  13454. {
  13455. mtrace();
  13456. int result = FAIL;
  13457. int connectorIdInt =0;
  13458. char comfirmstr[20]={0};
  13459. int tempIndex = 0;
  13460. json_object *UnlockConnector;
  13461. //[2,"ba1cbd49-2a76-493a-8f76-fa23e7606532","UnlockConnector",{"connectorId":1}]
  13462. DEBUG_INFO("handleUnlockConnectorRequest ...\n");
  13463. UnlockConnector = json_tokener_parse(payload);
  13464. if(!is_error(UnlockConnector))
  13465. {
  13466. if(json_object_object_get(UnlockConnector, "connectorId") != NULL)
  13467. {
  13468. connectorIdInt = json_object_get_int(json_object_object_get(UnlockConnector, "connectorId"));
  13469. }
  13470. }
  13471. json_object_put(UnlockConnector);
  13472. DEBUG_INFO("Unlock connectorIdInt = %d\n",connectorIdInt);
  13473. if(gunTotalNumber == 0)
  13474. {
  13475. sprintf(comfirmstr, "%s", UnlockStatusStr[UnlockStatus_NotSupported] );
  13476. goto end;
  13477. }
  13478. else if((connectorIdInt > gunTotalNumber/*CHAdeMO_QUANTITY+ CCS_QUANTITY + GB_QUANTITY*/) || (connectorIdInt <= 0))
  13479. {
  13480. //sprintf(comfirmstr, "%s", UnlockStatusStr[UnlockStatus_NotSupported] );
  13481. sprintf(comfirmstr, "%s", UnlockStatusStr[UnlockStatus_NotSupported] );
  13482. goto end;
  13483. }
  13484. else
  13485. {
  13486. //check Transaction active
  13487. if(gunType[connectorIdInt-1] == GUN_TYPE_CHAdeMO)
  13488. {
  13489. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  13490. {
  13491. tempIndex = (((connectorIdInt -1)==2) ? 1: 0);
  13492. }
  13493. else
  13494. {
  13495. tempIndex = connectorIdInt -1;
  13496. }
  13497. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  13498. {
  13499. if ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex ))
  13500. {
  13501. //stop Transaction
  13502. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].UnlockConnectorReq = 1;
  13503. }
  13504. }
  13505. }
  13506. else if(gunType[connectorIdInt-1] == GUN_TYPE_CCS)
  13507. {
  13508. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  13509. {
  13510. tempIndex = (((connectorIdInt -1)==2) ? 1: 0);
  13511. }
  13512. else
  13513. {
  13514. tempIndex = connectorIdInt -1;
  13515. }
  13516. for (int index = 0; index < CCS_QUANTITY; index++)
  13517. {
  13518. if ((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex ))
  13519. {
  13520. //stop Transaction
  13521. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].UnlockConnectorReq = 1;
  13522. }
  13523. }
  13524. }
  13525. else if(gunType[connectorIdInt-1] == GUN_TYPE_GBT)
  13526. {
  13527. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  13528. {
  13529. tempIndex = (((connectorIdInt -1)==2) ? 1: 0);
  13530. }
  13531. else
  13532. {
  13533. tempIndex = connectorIdInt -1;
  13534. }
  13535. for (int index = 0; index < GB_QUANTITY; index++)
  13536. {
  13537. if ((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex ))
  13538. {
  13539. //stop Transaction
  13540. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].UnlockConnectorReq = 1;
  13541. }
  13542. }
  13543. }
  13544. else if(gunType[connectorIdInt-1] == GUN_TYPE_DO)
  13545. {
  13546. tempIndex = connectorIdInt -1;
  13547. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  13548. {
  13549. if ((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex ))
  13550. {
  13551. //stop Transaction
  13552. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].UnlockConnectorReq = 1;
  13553. }
  13554. }
  13555. }
  13556. else
  13557. {
  13558. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  13559. {
  13560. tempIndex = 2;
  13561. }
  13562. else
  13563. {
  13564. tempIndex = connectorIdInt-1;
  13565. }
  13566. for (int index = 0; index < AC_QUANTITY; index++)
  13567. {
  13568. if ((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex ))
  13569. {
  13570. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].UnlockConnectorReq = 1;
  13571. }
  13572. }
  13573. }
  13574. ShmOCPP16Data->UnlockConnector[connectorIdInt-1].ConnectorId = connectorIdInt;
  13575. strcpy((char *)ShmOCPP16Data->UnlockConnector[connectorIdInt-1].guid, uuid);
  13576. result = TRUE;
  13577. return result;
  13578. }
  13579. end:
  13580. //json_object_put(obj); --- remove temporally
  13581. sendUnlockConnectorConfirmation(uuid, comfirmstr);
  13582. return result;
  13583. }
  13584. static char UpdateFirmwarepayloadData[300]={0};
  13585. int handleUpdateFirmwareRequest(char *uuid, char *payload)
  13586. {
  13587. mtrace();
  13588. int result = FAIL;
  13589. pthread_t t;
  13590. sendUpdateFirmwareConfirmation(uuid);
  13591. memset(UpdateFirmwarepayloadData, 0, 300);
  13592. strcpy(UpdateFirmwarepayloadData, stringtrimspace(payload));
  13593. if(!interLock.isUpdateFirmwareGoing)
  13594. {
  13595. interLock.isUpdateFirmwareGoing = 1;
  13596. pthread_create(&t, NULL, UpdateFirmwareProcess, stringtrimspace(payload));
  13597. sleep(1);
  13598. }
  13599. else
  13600. DEBUG_WARN("Other UpdateFirmware request on going.\n");
  13601. ShmOCPP16Data->MsMsg.bits.UpdateFirmwareConf =1;
  13602. return result;
  13603. }
  13604. void *UpdateFirmwareProcess(void *data)
  13605. {
  13606. pthread_detach(pthread_self());
  13607. mtrace();
  13608. int retriesInt =0, retryIntervalInt=0;
  13609. char protocol[10], user[64],password[64],host[128], path[512], ftppath[512],host1[128],path1[512];
  13610. int port=0;
  13611. char locationstr[1024]={0}, retrieveDatestr[36]={0};
  13612. int isSuccess = 0;
  13613. char ftpbuf[1024];
  13614. char temp[1024];
  13615. char * pch;
  13616. DEBUG_INFO("handleUpdateFirmwareRequest ...\n");
  13617. json_object *UpdateFirmware;
  13618. UpdateFirmware = json_tokener_parse(UpdateFirmwarepayloadData);
  13619. if(!is_error(UpdateFirmware))
  13620. {
  13621. // Required data
  13622. if(json_object_object_get(UpdateFirmware, "location") != NULL)
  13623. sprintf((char*)locationstr, "%s", json_object_get_string(json_object_object_get(UpdateFirmware, "location")));
  13624. if(json_object_object_get(UpdateFirmware, "retrieveDate") != NULL)
  13625. sprintf((char*)retrieveDatestr, "%s", json_object_get_string(json_object_object_get(UpdateFirmware, "retrieveDate")));
  13626. // Optional data
  13627. if(json_object_object_get(UpdateFirmware, "retries"))
  13628. {
  13629. retriesInt = json_object_get_int(json_object_object_get(UpdateFirmware, "retries"));
  13630. }
  13631. if(json_object_object_get(UpdateFirmware, "retryInterval"))
  13632. {
  13633. retryIntervalInt = json_object_get_int(json_object_object_get(UpdateFirmware, "retryInterval"));
  13634. }
  13635. }
  13636. json_object_put(UpdateFirmware);
  13637. memset(ftppath, 0, ARRAY_SIZE(ftppath));
  13638. memset(path, 0, ARRAY_SIZE(path));
  13639. // Wait retrieveData
  13640. if(strlen(retrieveDatestr) > 10)
  13641. {
  13642. do
  13643. {
  13644. sleep(1);
  13645. }while(!isOvertNow((uint8_t*)retrieveDatestr));
  13646. }
  13647. // Ready to download
  13648. system("rm -f /mnt/*");
  13649. if(strncmp(locationstr,"http", 4) == 0)
  13650. {
  13651. sscanf(locationstr,"%[^:]:%*2[/]%[^/]/%199[^\n]", protocol, host, path);
  13652. sprintf(ftppath,"/%s", path);
  13653. DEBUG_INFO("locationstr: %s\n", locationstr);
  13654. DEBUG_INFO("protocol: %s\n",protocol);
  13655. DEBUG_INFO("host: %s\n",host);
  13656. DEBUG_INFO("path: %s\n",path);
  13657. DEBUG_INFO("ftppath: %s\n",ftppath);
  13658. int ftppathlen=strlen(ftppath);
  13659. int i=1;
  13660. char filenametemp[50];
  13661. while(i < ftppathlen)
  13662. {
  13663. int len=ftppathlen-i;
  13664. if(ftppath[len]== 47) // '/' ascll code: 47
  13665. {
  13666. DEBUG_INFO("compare '/' all right\n");
  13667. break;
  13668. }
  13669. i=i+1;
  13670. }
  13671. memset(filenametemp, 0, ARRAY_SIZE(filenametemp));
  13672. strncpy(filenametemp, ftppath+(ftppathlen-i+1), i+1);
  13673. filenametemp[i+1] = 0;
  13674. do
  13675. {
  13676. sprintf((char*)ShmOCPP16Data->FirmwareStatusNotification.Status, "%s",FirmwareStatusStr[FirmwareStatus_Downloading]);
  13677. ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationReq = 1;
  13678. sleep(1);
  13679. isSuccess = httpDownLoadFile(host, ftppath, filenametemp, locationstr);
  13680. if(!isSuccess)
  13681. {
  13682. sprintf((char*)ShmOCPP16Data->FirmwareStatusNotification.Status, "%s",FirmwareStatusStr[FirmwareStatus_DownloadFailed]);
  13683. ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationReq = 1;
  13684. if(retriesInt>0)sleep(retryIntervalInt);else sleep(1);
  13685. sprintf((char*)ShmOCPP16Data->FirmwareStatusNotification.Status, "%s",FirmwareStatusStr[FirmwareStatus_Idle]);
  13686. ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationReq = 1;
  13687. }
  13688. else
  13689. {
  13690. sprintf((char*)ShmOCPP16Data->FirmwareStatusNotification.Status, "%s",FirmwareStatusStr[FirmwareStatus_Downloaded]);
  13691. ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationReq = 1;
  13692. }
  13693. retriesInt--;
  13694. }while((isSuccess == 0)&&(retriesInt >= 0));
  13695. }
  13696. else if(strncmp(locationstr,"sftp", 4) == 0) // sftp
  13697. {
  13698. memset(ftpbuf, 0, ARRAY_SIZE(ftpbuf));
  13699. memset(temp, 0, ARRAY_SIZE(temp));
  13700. //DEBUG_INFO("locationstr=%s\n",locationstr);
  13701. strcpy(ftpbuf, locationstr);
  13702. int ftppathlen=strlen(ftpbuf);
  13703. int i=1;
  13704. char filenametemp[50];
  13705. while(i < ftppathlen)
  13706. {
  13707. int len=ftppathlen-i;
  13708. if(ftpbuf[len]== 47) // '/' ascii code: 47
  13709. {
  13710. DEBUG_INFO(" compare '/' all right\n");
  13711. break;
  13712. }
  13713. i=i+1;
  13714. }
  13715. memset(filenametemp, 0, ARRAY_SIZE(filenametemp));
  13716. strncpy(filenametemp, ftpbuf+(ftppathlen-i+1), i+1);
  13717. filenametemp[i+1] = 0;
  13718. strncpy(temp, ftpbuf, ftppathlen-i+1);
  13719. pch=strchr(temp,'@');
  13720. if(pch==NULL)
  13721. {
  13722. sscanf(temp,"%[^:]:%*2[/]%[^:]:%i/%[a-zA-Z0-9._/-]",
  13723. protocol, host, &port, path);
  13724. strcpy(user,"anonymous");
  13725. strcpy(password,"");
  13726. }
  13727. else
  13728. {
  13729. sscanf(temp,"%[^:]:%*2[/]%[^@]@%[^:]:%i/%199[^\n]",
  13730. protocol, user, host, &port, path);
  13731. }
  13732. sscanf(host,"%[^/]%s",host1, path1);
  13733. sprintf(ftppath,"%s:/%s", host,path);
  13734. if(port == 0)
  13735. {
  13736. port = 21;
  13737. }
  13738. do
  13739. {
  13740. sprintf((char*)ShmOCPP16Data->FirmwareStatusNotification.Status, "%s",FirmwareStatusStr[FirmwareStatus_Downloading]);
  13741. ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationReq = 1;
  13742. sleep(1);
  13743. isSuccess = sftpDownLoadFile(host1, user, port, ftppath, filenametemp, locationstr);
  13744. if(!isSuccess)
  13745. {
  13746. //BulldogUtil.sleepMs(interval*1000);
  13747. DEBUG_INFO("Update firmware request and download file fail.\n");
  13748. sprintf((char*)ShmOCPP16Data->FirmwareStatusNotification.Status, "%s",FirmwareStatusStr[FirmwareStatus_DownloadFailed]);
  13749. ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationReq = 1;
  13750. if(retriesInt>0)sleep(retryIntervalInt);else sleep(1);
  13751. sprintf((char*)ShmOCPP16Data->FirmwareStatusNotification.Status, "%s",FirmwareStatusStr[FirmwareStatus_Idle]);
  13752. ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationReq = 1;
  13753. }
  13754. else
  13755. {
  13756. sprintf((char*)ShmOCPP16Data->FirmwareStatusNotification.Status, "%s",FirmwareStatusStr[FirmwareStatus_Downloaded]);
  13757. ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationReq = 1;
  13758. }
  13759. retriesInt--;
  13760. }while((!isSuccess)&&(retriesInt >= 0));
  13761. }
  13762. else if(strncmp(locationstr,"ftp", 3) == 0) // ftp
  13763. {
  13764. memset(ftpbuf, 0, ARRAY_SIZE(ftpbuf));
  13765. memset(temp, 0, ARRAY_SIZE(temp));
  13766. //DEBUG_INFO("locationstr=%s\n",locationstr);
  13767. strcpy(ftpbuf, locationstr/*"ftp://ipc_ui:pht2016@ftp.phihong.com.tw/DC/log/DemoDC1_2018-07-13_185011_PSULog.zip"*/ );
  13768. int ftppathlen=strlen(ftpbuf);
  13769. int i=1;
  13770. char filenametemp[50];
  13771. while(i < ftppathlen)
  13772. {
  13773. int len=ftppathlen-i;
  13774. if(ftpbuf[len]== 47) // '/' ascll code: 47
  13775. {
  13776. DEBUG_INFO(" compare '/' all right\n");
  13777. break;
  13778. }
  13779. i=i+1;
  13780. }
  13781. memset(filenametemp, 0, ARRAY_SIZE(filenametemp));
  13782. strncpy(filenametemp, ftpbuf+(ftppathlen-i+1), i+1);
  13783. filenametemp[i+1] = 0;
  13784. strncpy(temp, ftpbuf, ftppathlen-i+1);
  13785. pch=strchr(temp,'@');
  13786. if(pch==NULL)
  13787. {
  13788. sscanf(temp,"%[^:]:%*2[/]%[^:]:%i/%[a-zA-Z0-9._/-]",
  13789. protocol, host, &port, path);
  13790. strcpy(user,"anonymous");
  13791. strcpy(password,"");
  13792. }
  13793. else
  13794. {
  13795. sscanf(temp,"%[^:]:%*2[/]%[^:]:%[^@]@%[^:]:%i/%199[^\n]",
  13796. protocol, user, password, host, &port, path);
  13797. }
  13798. sscanf(host,"%[^/]%s",host1, path1);
  13799. sprintf(ftppath,"%s", path1);
  13800. //DEBUG_INFO("protocol =%s\n",protocol);
  13801. //DEBUG_INFO("user =%s\n",user);
  13802. //DEBUG_INFO("password =%s\n",password);
  13803. //DEBUG_INFO("host1 =%s\n",host1);
  13804. //DEBUG_INFO("port =%d\n",port);
  13805. //DEBUG_INFO("path1 =%s\n",path1);
  13806. //DEBUG_INFO("ftppath=%s\n",ftppath);
  13807. //ftpFile(host, user, password, port, ftppath, fname);
  13808. //download firmware pthred
  13809. if(port == 0)
  13810. {
  13811. port = 21;
  13812. }
  13813. do
  13814. {
  13815. sprintf((char*)ShmOCPP16Data->FirmwareStatusNotification.Status, "%s",FirmwareStatusStr[FirmwareStatus_Downloading]);
  13816. ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationReq = 1;
  13817. sleep(1);
  13818. isSuccess = ftpDownLoadFile(host1, user, password, port, ftppath, filenametemp, locationstr);
  13819. if(!isSuccess)
  13820. {
  13821. //BulldogUtil.sleepMs(interval*1000);
  13822. DEBUG_INFO("Update firmware request and download file fail.\n");
  13823. sprintf((char*)ShmOCPP16Data->FirmwareStatusNotification.Status, "%s",FirmwareStatusStr[FirmwareStatus_DownloadFailed]);
  13824. ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationReq = 1;
  13825. if(retriesInt>0)sleep(retryIntervalInt);else sleep(1);
  13826. sprintf((char*)ShmOCPP16Data->FirmwareStatusNotification.Status, "%s",FirmwareStatusStr[FirmwareStatus_Idle]);
  13827. ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationReq = 1;
  13828. }
  13829. else
  13830. {
  13831. sprintf((char*)ShmOCPP16Data->FirmwareStatusNotification.Status, "%s",FirmwareStatusStr[FirmwareStatus_Downloaded]);
  13832. ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationReq = 1;
  13833. }
  13834. retriesInt--;
  13835. }while((!isSuccess)&&(retriesInt >= 0));
  13836. }
  13837. else
  13838. {
  13839. sprintf((char*)ShmOCPP16Data->FirmwareStatusNotification.Status, "%s",FirmwareStatusStr[FirmwareStatus_DownloadFailed]);
  13840. ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationReq = 1;
  13841. sleep(1);
  13842. sprintf((char*)ShmOCPP16Data->FirmwareStatusNotification.Status, "%s",FirmwareStatusStr[FirmwareStatus_Idle]);
  13843. ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationReq = 1;
  13844. }
  13845. if(strstr((char*)ShmOCPP16Data->FirmwareStatusNotification.Status, FirmwareStatusStr[FirmwareStatus_Downloaded]) != NULL)ShmOCPP16Data->MsMsg.bits.UpdateFirmwareReq = 1;
  13846. interLock.isUpdateFirmwareGoing = 0;
  13847. pthread_exit(NULL);
  13848. }
  13849. int handleCertificateSignedRequest(char *uuid, char *payload)
  13850. {
  13851. mtrace();
  13852. int result = PASS;
  13853. json_object *CertificateSigned;
  13854. DEBUG_INFO("handleCertificateSignedRequest...\n");
  13855. CertificateSigned = json_tokener_parse(payload);
  13856. if(!is_error(CertificateSigned))
  13857. {
  13858. sprintf((char*)ShmOCPP16Data->CertificateSigned.certificateChain, "%s", json_object_get_string(json_object_object_get(CertificateSigned, "certificateChain")));
  13859. }
  13860. json_object_put(CertificateSigned);
  13861. FILE *fp = fopen("/Storage/OCPP/certCP.crt", "w");
  13862. fprintf(fp, "%s", ShmOCPP16Data->CertificateSigned.certificateChain);
  13863. fclose(fp);
  13864. system("/bin/fsync -d /dev/mtdblock13;/bin/sync &");
  13865. ShmOCPP16Data->MsMsg.bits.CertificateSignedReq = 1;
  13866. sprintf((char*)ShmOCPP16Data->CertificateSigned.Response_status, "Accepted");
  13867. sendCertificateSignedConfirmation(uuid);
  13868. return result;
  13869. }
  13870. int handleDeleteCertificateRequest(char *uuid, char *payload)
  13871. {
  13872. mtrace();
  13873. int result = PASS;
  13874. json_object *DeleteCertificate;
  13875. DEBUG_INFO("handleDeleteCertificateRequest...\n");
  13876. DeleteCertificate = json_tokener_parse(payload);
  13877. if(!is_error(DeleteCertificate))
  13878. {
  13879. sprintf((char*)ShmOCPP16Data->DeleteCertificate.certificateHashData.hashAlgorithm, "%s", json_object_get_string(json_object_object_get(json_object_object_get(DeleteCertificate, "certificateHashData"), "hashAlgorithm")));
  13880. sprintf((char*)ShmOCPP16Data->DeleteCertificate.certificateHashData.issuerNameHash, "%s", json_object_get_string(json_object_object_get(json_object_object_get(DeleteCertificate, "certificateHashData"), "issuerNameHash")));
  13881. sprintf((char*)ShmOCPP16Data->DeleteCertificate.certificateHashData.issuerKeyHash, "%s", json_object_get_string(json_object_object_get(json_object_object_get(DeleteCertificate, "certificateHashData"), "issuerKeyHash")));
  13882. sprintf((char*)ShmOCPP16Data->DeleteCertificate.certificateHashData.serialNumber, "%s", json_object_get_string(json_object_object_get(json_object_object_get(DeleteCertificate, "certificateHashData"), "serialNumber")));
  13883. }
  13884. json_object_put(DeleteCertificate);
  13885. /*
  13886. * TODO: Delete certificateSigned process
  13887. */
  13888. ShmOCPP16Data->MsMsg.bits.DeleteCertificateReq = 1;
  13889. DEBUG_INFO("hashAlgorithm: %s\n", ShmOCPP16Data->DeleteCertificate.certificateHashData.hashAlgorithm);
  13890. DEBUG_INFO("issuerNameHash: %s\n", ShmOCPP16Data->DeleteCertificate.certificateHashData.issuerNameHash);
  13891. DEBUG_INFO("issuerKeyHash: %s\n", ShmOCPP16Data->DeleteCertificate.certificateHashData.issuerKeyHash);
  13892. DEBUG_INFO("serialNumber: %s\n", ShmOCPP16Data->DeleteCertificate.certificateHashData.serialNumber);
  13893. sprintf((char*)ShmOCPP16Data->DeleteCertificate.Response_status, "NotFound");
  13894. sendDeleteCertificateConfirmation(uuid);
  13895. return result;
  13896. }
  13897. int handleExtendedTriggerMessageRequest(char *uuid, char *payload)
  13898. {
  13899. mtrace();
  13900. int result = PASS;
  13901. json_object *ExtendedTriggerMessage;
  13902. DEBUG_INFO("handleExtendedTriggerMessageRequest...\n");
  13903. ExtendedTriggerMessage = json_tokener_parse(payload);
  13904. if(!is_error(ExtendedTriggerMessage))
  13905. {
  13906. sprintf((char*)ShmOCPP16Data->ExtendedTriggerMessage.requestedMessage, "%s", json_object_get_string(json_object_object_get(ExtendedTriggerMessage, "requestedMessage")));
  13907. if(json_object_object_get(ExtendedTriggerMessage, "connectorId") != NULL)
  13908. {
  13909. ShmOCPP16Data->ExtendedTriggerMessage.connectorId = json_object_get_int(json_object_object_get(ExtendedTriggerMessage, "connectorId"));
  13910. }
  13911. else
  13912. {
  13913. ShmOCPP16Data->ExtendedTriggerMessage.connectorId = -1;
  13914. }
  13915. }
  13916. json_object_put(ExtendedTriggerMessage);
  13917. DEBUG_INFO("requestedMessage: %s\n", ShmOCPP16Data->ExtendedTriggerMessage.requestedMessage);
  13918. DEBUG_INFO("connectorIdInt: %d\n", ShmOCPP16Data->ExtendedTriggerMessage.connectorId);
  13919. if((ShmOCPP16Data->ExtendedTriggerMessage.connectorId == 0) || (ShmOCPP16Data->ExtendedTriggerMessage.connectorId > gunTotalNumber))
  13920. {
  13921. sprintf((char*)ShmOCPP16Data->ExtendedTriggerMessage.Response_status, TriggerMessageStatusStr[TriggerMessageStatus_Rejected]);
  13922. }
  13923. else
  13924. {
  13925. if((strcmp((char*)ShmOCPP16Data->ExtendedTriggerMessage.requestedMessage, MessageTriggerStr[BootNotification]) != 0 ) &&
  13926. (strcmp((char*)ShmOCPP16Data->ExtendedTriggerMessage.requestedMessage, "LogStatusNotification") != 0) &&
  13927. (strcmp((char*)ShmOCPP16Data->ExtendedTriggerMessage.requestedMessage, MessageTriggerStr[FirmwareStatusNotification]) != 0) &&
  13928. (strcmp((char*)ShmOCPP16Data->ExtendedTriggerMessage.requestedMessage, MessageTriggerStr[Heartbeat]) != 0) &&
  13929. (strcmp((char*)ShmOCPP16Data->ExtendedTriggerMessage.requestedMessage, MessageTriggerStr[MeterValues]) != 0) &&
  13930. (strcmp((char*)ShmOCPP16Data->ExtendedTriggerMessage.requestedMessage, "SignChargePointCertificate") != 0 ) &&
  13931. (strcmp((char*)ShmOCPP16Data->ExtendedTriggerMessage.requestedMessage, MessageTriggerStr[StatusNotification]) != 0 ))
  13932. {
  13933. sprintf((char*)ShmOCPP16Data->ExtendedTriggerMessage.Response_status, "%s",TriggerMessageStatusStr[TriggerMessageStatus_NotImplemented] );
  13934. }
  13935. else
  13936. {
  13937. sprintf((char*)ShmOCPP16Data->ExtendedTriggerMessage.Response_status, "%s",TriggerMessageStatusStr[TriggerMessageStatus_Accepted] );
  13938. }
  13939. }
  13940. sendExtendedTriggerMessageConfirmation(uuid);
  13941. //==========================
  13942. // Trigger message
  13943. //==========================
  13944. if(strcmp((char*)ShmOCPP16Data->ExtendedTriggerMessage.requestedMessage, MessageTriggerStr[BootNotification]) == 0 )
  13945. {
  13946. //sendBootNotificationRequest();
  13947. server_sign = FALSE;
  13948. }
  13949. else if( strcmp((char*)ShmOCPP16Data->ExtendedTriggerMessage.requestedMessage, "LogStatusNotification") == 0)
  13950. {
  13951. ShmOCPP16Data->SpMsg.bits.LogStatusNotificationReq = 1;
  13952. }
  13953. else if( strcmp((char*)ShmOCPP16Data->ExtendedTriggerMessage.requestedMessage, MessageTriggerStr[FirmwareStatusNotification]) == 0)
  13954. {
  13955. if((strlen((char*)ShmOCPP16Data->FirmwareStatusNotification.Status) == 0) ||
  13956. ((FirmwareStatusNotificationStatus != FIRMWARE_STATUS_DOWNLOADING) && (FirmwareStatusNotificationStatus != FIRMWARE_STATUS_DOWNLOADED) && (FirmwareStatusNotificationStatus != FIRMWARE_STATUS_IDLE) && (FirmwareStatusNotificationStatus != FIRMWARE_STATUS_INSTALLING)))
  13957. {
  13958. FirmwareStatusNotificationStatus = FIRMWARE_STATUS_IDLE;
  13959. sprintf((char*)ShmOCPP16Data->FirmwareStatusNotification.Status, "%s", FirmwareStatusStr[FirmwareStatus_Idle]);
  13960. }
  13961. ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationReq = 1;
  13962. }
  13963. else if(strcmp((char*)ShmOCPP16Data->ExtendedTriggerMessage.requestedMessage, MessageTriggerStr[Heartbeat]) == 0 )
  13964. {
  13965. refreshStartTimer(&clientTime.Heartbeat);
  13966. clientTime.Heartbeat.tv_sec -= ShmOCPP16Data->BootNotification.ResponseHeartbeatInterval;
  13967. }
  13968. else if (strcmp((char*)ShmOCPP16Data->ExtendedTriggerMessage.requestedMessage, MessageTriggerStr[MeterValues]) == 0 )
  13969. {
  13970. if((ShmOCPP16Data->ExtendedTriggerMessage.connectorId > 0) && (ShmOCPP16Data->ExtendedTriggerMessage.connectorId <= gunTotalNumber))
  13971. {
  13972. cpinitateMsg.bits[ShmOCPP16Data->ExtendedTriggerMessage.connectorId-1].TriggerMeterValue = 1;
  13973. }
  13974. else
  13975. {
  13976. for(int idx=0;idx< gunTotalNumber;idx++)
  13977. {
  13978. //sendMeterValuesRequest(idx, ReadingContext_Trigger);
  13979. cpinitateMsg.bits[idx].TriggerMeterValue = 1;
  13980. }
  13981. }
  13982. }
  13983. else if(strcmp((char*)ShmOCPP16Data->ExtendedTriggerMessage.requestedMessage, "SignChargePointCertificate") == 0 )
  13984. {
  13985. ShmOCPP16Data->SpMsg.bits.SignCertificateReq = 1;
  13986. if(access("/Storage/OCPP/certCP.csr",F_OK) == -1)
  13987. {
  13988. 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\" &");
  13989. }
  13990. }
  13991. else if(strcmp((char*)ShmOCPP16Data->ExtendedTriggerMessage.requestedMessage, MessageTriggerStr[StatusNotification]) == 0 )
  13992. {
  13993. if((ShmOCPP16Data->ExtendedTriggerMessage.connectorId > 0) && (ShmOCPP16Data->ExtendedTriggerMessage.connectorId <= gunTotalNumber))
  13994. {
  13995. cpinitateMsg.bits[ShmOCPP16Data->ExtendedTriggerMessage.connectorId -1].StatusNotificationReq = 1;
  13996. }
  13997. else
  13998. {
  13999. for(int idx=0;idx< gunTotalNumber;idx++)
  14000. cpinitateMsg.bits[idx].StatusNotificationReq = 1;
  14001. }
  14002. }
  14003. return result;
  14004. }
  14005. int handleGetInstalledCertificateIdsRequest(char *uuid, char *payload)
  14006. {
  14007. mtrace();
  14008. int result = PASS;
  14009. json_object *GetInstalledCertificateIds;
  14010. DEBUG_INFO("handleGetInstalledCertificateIdsRequest...\n");
  14011. GetInstalledCertificateIds = json_tokener_parse(payload);
  14012. if(!is_error(GetInstalledCertificateIds))
  14013. {
  14014. sprintf((char*)ShmOCPP16Data->GetInstalledCertificateIds.certificateType, "%s", json_object_get_string(json_object_object_get(GetInstalledCertificateIds, "certificateType")));
  14015. }
  14016. json_object_put(GetInstalledCertificateIds);
  14017. /*
  14018. * TODO: Return installed certificate process
  14019. */
  14020. ShmOCPP16Data->MsMsg.bits.GetInstalledCertificateIdsReq = 1;
  14021. DEBUG_INFO("requestedMessage: %s\n", (char*)ShmOCPP16Data->GetInstalledCertificateIds.certificateType);
  14022. memset(ShmOCPP16Data->GetInstalledCertificateIds.Response_certificateHashData, 0x00, ARRAY_SIZE(ShmOCPP16Data->GetInstalledCertificateIds.Response_certificateHashData)*sizeof(struct CertificateHashDataType));
  14023. sprintf((char*)ShmOCPP16Data->GetInstalledCertificateIds.Response_status, "NotFound");
  14024. sendGetInstalledCertificateIdsConfirmation(uuid);
  14025. return result;
  14026. }
  14027. int handleGetLogRequest(char *uuid, char *payload)
  14028. {
  14029. mtrace();
  14030. int result = PASS;
  14031. json_object *GetLog;
  14032. DEBUG_INFO("handleGetLogRequest...\n");
  14033. GetLog = json_tokener_parse(payload);
  14034. if(!is_error(GetLog))
  14035. {
  14036. sprintf((char*)ShmOCPP16Data->GetLog.logType, "%s", json_object_get_string(json_object_object_get(GetLog, "logType")));
  14037. ShmOCPP16Data->GetLog.requestId = json_object_get_int(json_object_object_get(GetLog, "requestId"));
  14038. if(json_object_object_get(GetLog, "retries") != NULL)
  14039. {
  14040. ShmOCPP16Data->GetLog.retries = json_object_get_int(json_object_object_get(GetLog, "retries"));
  14041. }
  14042. if(json_object_object_get(GetLog, "retryInterval") != NULL)
  14043. {
  14044. ShmOCPP16Data->GetLog.retryInterval = json_object_get_int(json_object_object_get(GetLog, "retryInterval"));
  14045. }
  14046. sprintf((char*)ShmOCPP16Data->GetLog.log.remoteLocation, "%s", json_object_get_string(json_object_object_get(json_object_object_get(GetLog, "log"), "remoteLocation")));
  14047. if(json_object_object_get(json_object_object_get(GetLog, "log"), "oldestTimestamp") != NULL)
  14048. {
  14049. sprintf((char*)ShmOCPP16Data->GetLog.log.oldestTimestamp, "%s", json_object_get_string(json_object_object_get(json_object_object_get(GetLog, "log"), "oldestTimestamp")));
  14050. }
  14051. if(json_object_object_get(json_object_object_get(GetLog, "log"), "latestTimestamp") != NULL)
  14052. {
  14053. sprintf((char*)ShmOCPP16Data->GetLog.log.latestTimestamp, "%s", json_object_get_string(json_object_object_get(json_object_object_get(GetLog, "log"), "latestTimestamp")));
  14054. }
  14055. }
  14056. json_object_put(GetLog);
  14057. /*
  14058. * TODO: Upload log process
  14059. */
  14060. ShmOCPP16Data->MsMsg.bits.GetLogReq = 1;
  14061. DEBUG_INFO("logType: %s\n", ShmOCPP16Data->GetLog.logType);
  14062. DEBUG_INFO("requestId: %d\n", ShmOCPP16Data->GetLog.requestId);
  14063. DEBUG_INFO("retries: %d\n", ShmOCPP16Data->GetLog.retries);
  14064. DEBUG_INFO("retryInterval: %d\n", ShmOCPP16Data->GetLog.retryInterval);
  14065. DEBUG_INFO("remoteLocation: %s\n", ShmOCPP16Data->GetLog.log.remoteLocation);
  14066. DEBUG_INFO("oldestTimestamp: %s\n", ShmOCPP16Data->GetLog.log.oldestTimestamp);
  14067. DEBUG_INFO("latestTimestamp: %s\n", ShmOCPP16Data->GetLog.log.latestTimestamp);
  14068. sprintf((char*)ShmOCPP16Data->GetLog.Response_status, "Rejected");
  14069. sendGetLogConfirmation(uuid);
  14070. return result;
  14071. }
  14072. int handleInstallCertificateRequest(char *uuid, char *payload)
  14073. {
  14074. mtrace();
  14075. int result = PASS;
  14076. json_object *InstallCertificate;
  14077. DEBUG_INFO("handleInstallCertificateRequest...\n");
  14078. InstallCertificate = json_tokener_parse(payload);
  14079. if(!is_error(InstallCertificate))
  14080. {
  14081. sprintf((char*)ShmOCPP16Data->InstallCertificate.certificateType, "%s", json_object_get_string(json_object_object_get(InstallCertificate, "certificateType")));
  14082. sprintf((char*)ShmOCPP16Data->InstallCertificate.certificate, "%s", json_object_get_string(json_object_object_get(InstallCertificate, "certificate")));
  14083. /*
  14084. * TODO: Install certificate process
  14085. */
  14086. ShmOCPP16Data->MsMsg.bits.InstallCertificateReq = 1;
  14087. DEBUG_INFO("certificateType: %s\n", (char*)ShmOCPP16Data->InstallCertificate.certificateType);
  14088. DEBUG_INFO("certificate: %s\n", (char*)ShmOCPP16Data->InstallCertificate.certificate);
  14089. sprintf((char*)ShmOCPP16Data->InstallCertificate.Response_status, "Rejected");
  14090. sendInstallCertificateConfirmation(uuid);
  14091. }
  14092. json_object_put(InstallCertificate);
  14093. return result;
  14094. }
  14095. int handleSignedUpdateFirmwareRequest(char *uuid, char *payload)
  14096. {
  14097. mtrace();
  14098. int result = PASS;
  14099. json_object *SignedUpdateFirmware;
  14100. DEBUG_INFO("handleSignedUpdateFirmwareRequest...\n");
  14101. SignedUpdateFirmware = json_tokener_parse(payload);
  14102. if(!is_error(SignedUpdateFirmware))
  14103. {
  14104. if(json_object_object_get(SignedUpdateFirmware, "retries") != NULL)
  14105. {
  14106. ShmOCPP16Data->SignedUpdateFirmware.retries = json_object_get_int(json_object_object_get(SignedUpdateFirmware, "retries"));
  14107. }
  14108. if(json_object_object_get(SignedUpdateFirmware, "retryInterval") != NULL)
  14109. {
  14110. ShmOCPP16Data->SignedUpdateFirmware.retryInterval = json_object_get_int(json_object_object_get(SignedUpdateFirmware, "retryInterval"));
  14111. }
  14112. ShmOCPP16Data->SignedUpdateFirmware.requestId = json_object_get_int(json_object_object_get(SignedUpdateFirmware, "requestId"));
  14113. sprintf((char*)ShmOCPP16Data->SignedUpdateFirmware.firmware.location, "%s", json_object_get_string(json_object_object_get(json_object_object_get(SignedUpdateFirmware, "firmware"), "location")));
  14114. sprintf((char*)ShmOCPP16Data->SignedUpdateFirmware.firmware.retrieveDateTime, "%s", json_object_get_string(json_object_object_get(json_object_object_get(SignedUpdateFirmware, "firmware"), "retrieveDateTime")));
  14115. if(json_object_object_get(json_object_object_get(SignedUpdateFirmware, "firmware"), "installDateTime") != NULL)
  14116. {
  14117. sprintf((char*)ShmOCPP16Data->SignedUpdateFirmware.firmware.installDateTime, "%s", json_object_get_string(json_object_object_get(json_object_object_get(SignedUpdateFirmware, "firmware"), "installDateTime")));
  14118. }
  14119. sprintf((char*)ShmOCPP16Data->SignedUpdateFirmware.firmware.signingCertificate, "%s", json_object_get_string(json_object_object_get(json_object_object_get(SignedUpdateFirmware, "firmware"), "signingCertificate")));
  14120. sprintf((char*)ShmOCPP16Data->SignedUpdateFirmware.firmware.signature, "%s", json_object_get_string(json_object_object_get(json_object_object_get(SignedUpdateFirmware, "firmware"), "signature")));
  14121. }
  14122. json_object_put(SignedUpdateFirmware);
  14123. /*
  14124. * TODO: Upgrade firmware process
  14125. */
  14126. ShmOCPP16Data->MsMsg.bits.SignedUpdateFirmwareReq = 1;
  14127. DEBUG_INFO("retries: %d\n", ShmOCPP16Data->SignedUpdateFirmware.retries);
  14128. DEBUG_INFO("retryInterval: %d\n", ShmOCPP16Data->SignedUpdateFirmware.retryInterval);
  14129. DEBUG_INFO("requestId: %d\n", ShmOCPP16Data->SignedUpdateFirmware.requestId);
  14130. DEBUG_INFO("location: %s\n", ShmOCPP16Data->SignedUpdateFirmware.firmware.location);
  14131. DEBUG_INFO("retrieveDateTime: %s\n", ShmOCPP16Data->SignedUpdateFirmware.firmware.retrieveDateTime);
  14132. DEBUG_INFO("installDateTime: %s\n", ShmOCPP16Data->SignedUpdateFirmware.firmware.installDateTime);
  14133. DEBUG_INFO("signingCertificate: %s\n", ShmOCPP16Data->SignedUpdateFirmware.firmware.signingCertificate);
  14134. DEBUG_INFO("signature: %s\n", ShmOCPP16Data->SignedUpdateFirmware.firmware.signature);
  14135. sprintf((char*)ShmOCPP16Data->SignedUpdateFirmware.Response_status, "Rejected");
  14136. sendInstallCertificateConfirmation(uuid);
  14137. return result;
  14138. }
  14139. int handleUnknownRequest(char *uuid, char *payload)
  14140. {
  14141. mtrace();
  14142. int result = PASS;
  14143. DEBUG_INFO("handleUnknownRequest...\n");
  14144. sendUnknownConfirmation(uuid);
  14145. result = PASS;
  14146. return result;
  14147. }
  14148. //==========================================
  14149. // Handle server response routine
  14150. //==========================================
  14151. void handleAuthorizeResponse(char *payload, int gun_index)
  14152. {
  14153. mtrace();
  14154. char expiryDatestr[36]={0};
  14155. char parentIdTagstr[21]={0};
  14156. char statusstr[20]={0};
  14157. int expiryDateISNULL=FALSE;
  14158. int parentIdTagISNULL=FALSE;
  14159. DEBUG_INFO("handleAuthorizeResponse...\n");
  14160. json_object *Authorize;
  14161. Authorize = json_tokener_parse(payload);
  14162. if(!is_error(Authorize))
  14163. {
  14164. if(json_object_object_get(Authorize, "idTagInfo") != NULL)
  14165. {
  14166. // Required data
  14167. sprintf((char *)statusstr, "%s", json_object_get_string(json_object_object_get(json_object_object_get(Authorize,"idTagInfo"), "status")));
  14168. // Optional data
  14169. if(json_object_object_get(json_object_object_get(Authorize,"idTagInfo"), "expiryDate") != NULL)
  14170. sprintf((char *)expiryDatestr, "%s", json_object_get_string(json_object_object_get(json_object_object_get(Authorize,"idTagInfo"), "expiryDate")));
  14171. if(json_object_object_get(json_object_object_get(Authorize,"idTagInfo"), "parentIdTag") != NULL)
  14172. sprintf((char *)parentIdTagstr, "%s", json_object_get_string(json_object_object_get(json_object_object_get(Authorize,"idTagInfo"), "parentIdTag")));
  14173. }
  14174. }
  14175. json_object_put(Authorize);
  14176. if(expiryDateISNULL == FALSE)
  14177. strcpy((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.ExpiryDate, expiryDatestr);
  14178. if(parentIdTagISNULL == FALSE)
  14179. strcpy((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.ParentIdTag, parentIdTagstr);
  14180. strcpy((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.Status, statusstr);
  14181. //Update idTag information to authorization cache if supproted
  14182. if((strcmp((const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemData, "TRUE") == 0) && (ShmOCPP16Data->Authorize.ResponseIdTagInfo.ParentIdTag != NULL) && (ShmOCPP16Data->Authorize.ResponseIdTagInfo.ExpiryDate != NULL) )
  14183. {
  14184. OCPP_addLocalCache((char*)ShmOCPP16Data->Authorize.IdTag, parentIdTagstr, expiryDatestr, statusstr);
  14185. }
  14186. ShmOCPP16Data->SpMsg.bits.AuthorizeReq = 0;
  14187. ShmOCPP16Data->SpMsg.bits.AuthorizeConf = 1; // inform csu
  14188. authorizeRetryTimes = 0;
  14189. }
  14190. void handleBootNotificationResponse(char *payload, int gun_index)
  14191. {
  14192. mtrace();
  14193. char statusStr[12]={0};
  14194. char currentTimeStr[30]={0};
  14195. int intervalInt = 0;
  14196. DEBUG_INFO("handleBootNotificationResponse...\n");
  14197. json_object *BootNotification;
  14198. BootNotification = json_tokener_parse(payload);
  14199. if(!is_error(BootNotification))
  14200. {
  14201. // Required data
  14202. sprintf((char *)currentTimeStr, "%s", json_object_get_string(json_object_object_get(BootNotification,"currentTime")));
  14203. intervalInt = json_object_get_int(json_object_object_get(BootNotification,"interval"));
  14204. sprintf((char *)statusStr, "%s", json_object_get_string(json_object_object_get(BootNotification,"status")));
  14205. }
  14206. json_object_put(BootNotification);
  14207. ShmOCPP16Data->BootNotification.ResponseHeartbeatInterval = intervalInt;
  14208. BootNotificationInterval = intervalInt;
  14209. //write back to ShmOCPP16Data->BootNotification
  14210. strcpy((char *)ShmOCPP16Data->BootNotification.ResponseCurrentTime, currentTimeStr);
  14211. ShmOCPP16Data->BootNotification.ResponseHeartbeatInterval = intervalInt;
  14212. strcpy((char *)ShmOCPP16Data->BootNotification.ResponseStatus, statusStr);
  14213. if((strcmp(statusStr, RegistrationStatusStr[RegistrationStatus_Accepted]) == 0 ))
  14214. {
  14215. BootNotificationInterval = 0;
  14216. if((intervalInt == 0) || (intervalInt >= 10))
  14217. {
  14218. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemData, "%d", intervalInt);
  14219. HeartBeatWaitTime = intervalInt;
  14220. DEBUG_INFO("BootNotificationResponse setting interval to %d...\n",intervalInt);
  14221. }
  14222. server_sign = TRUE;
  14223. server_pending =FALSE;
  14224. }
  14225. else if(strcmp(statusStr, RegistrationStatusStr[RegistrationStatus_Pending]) == 0)
  14226. {
  14227. server_pending = TRUE;
  14228. }
  14229. syncDateTimeRTC(ShmOCPP16Data->BootNotification.ResponseCurrentTime);
  14230. srand(time(NULL));
  14231. refreshStartTimer(&clientTime.Heartbeat);
  14232. clientTime.Heartbeat.tv_sec -= (ShmOCPP16Data->BootNotification.ResponseHeartbeatInterval-((rand()%8)+3));
  14233. SetOcppConnStatus(TRUE);
  14234. ShmOCPP16Data->SpMsg.bits.BootNotificationConf = 1;
  14235. }
  14236. void handleDataTransferResponse(char *payload, int gun_index)
  14237. {
  14238. json_object *DataTransfer = json_tokener_parse(payload);
  14239. if(!is_error(DataTransfer))
  14240. {
  14241. // Required data
  14242. DEBUG_INFO("Status: %s.\n", json_object_get_string(json_object_object_get(DataTransfer, "status")));
  14243. // Optional data
  14244. if(json_object_object_get(DataTransfer, "data") != NULL)
  14245. {
  14246. DEBUG_INFO("Data: %s\n", json_object_get_string(json_object_object_get(DataTransfer, "data")));
  14247. json_object *Data = json_tokener_parse(json_object_get_string(json_object_object_get(DataTransfer, "data")));
  14248. if(!is_error(Data))
  14249. {
  14250. if(json_object_object_get(Data, "msgId") != NULL)
  14251. {
  14252. if(strstr(json_object_get_string(json_object_object_get(Data, "msgId")), "ID_CreditDeductResult") != NULL)
  14253. {
  14254. 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")));
  14255. }
  14256. if(strstr(json_object_get_string(json_object_object_get(Data, "msgId")), "ID_ReaderStatus") != NULL)
  14257. {
  14258. if(json_object_object_get(Data, "ConnectorId") != NULL)
  14259. ShmOCPP16Data->TcciCustomData.ReaderStatus[json_object_get_int(json_object_object_get(Data, "ConnectorId"))-1].ReportReaderStatusReq = 0;
  14260. }
  14261. }
  14262. }
  14263. json_object_put(Data);
  14264. }
  14265. }
  14266. json_object_put(DataTransfer);
  14267. }
  14268. void handleDiagnosticsStatusNotificationResponse(char *payload, int gun_index)
  14269. {
  14270. DEBUG_INFO("handleDiagnosticsStatusNotificationResponse ...\n");
  14271. //struct json_object *obj;
  14272. // obj = json_tokener_parse(payload);
  14273. ShmOCPP16Data->SpMsg.bits.DiagnosticsStatusNotificationReq = 0;
  14274. ShmOCPP16Data->SpMsg.bits.DiagnosticsStatusNotificationConf = 1;
  14275. //No fields are defined.
  14276. }
  14277. void handleFirmwareStatusNotificationResponse(char *payload, int gun_index)
  14278. {
  14279. DEBUG_INFO("handleFirmwareStatusNotificationResponse ...\n");
  14280. //struct json_object *obj;
  14281. // obj = json_tokener_parse(payload);
  14282. ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationReq = 0;
  14283. ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationConf = 1;
  14284. //No fields are defined.
  14285. }
  14286. void handleHeartbeatResponse(char *payload, int gun_index)
  14287. {
  14288. mtrace();
  14289. DEBUG_INFO("handleHeartbeatResponse...\n");
  14290. json_object *Heartbeat;
  14291. Heartbeat = json_tokener_parse(payload);
  14292. if(!is_error(Heartbeat))
  14293. {
  14294. // Required data
  14295. sprintf((char *)ShmOCPP16Data->Heartbeat.ResponseCurrentTime, "%s", json_object_get_string(json_object_object_get(Heartbeat,"currentTime")));
  14296. }
  14297. json_object_put(Heartbeat);
  14298. if(FirstHeartBeat == 0)
  14299. {
  14300. FirstHeartBeat = 1;
  14301. DEBUG_INFO("FirstHeartBeat \n");
  14302. }
  14303. HeartBeatWithNOResponse = 0;
  14304. refreshStartTimer(&clientTime.Heartbeat);
  14305. syncDateTimeRTC(ShmOCPP16Data->Heartbeat.ResponseCurrentTime);
  14306. }
  14307. void handleMeterValuesResponse(char *payload, int gun_index)
  14308. {
  14309. mtrace();
  14310. DEBUG_INFO("handleMeterValuesResponse...\n");
  14311. isQueueSendable = 1;
  14312. }
  14313. void handleStartTransactionResponse(char *payload, int gun_index)
  14314. {
  14315. mtrace();
  14316. //int transactionIdInt = 0;
  14317. FILE *outfile;
  14318. char data[100]={0};
  14319. DEBUG_INFO("handleStartTransactionResponse...\n");
  14320. json_object *StartTransaction;
  14321. StartTransaction = json_tokener_parse(payload);
  14322. if(!is_error(StartTransaction))
  14323. {
  14324. // Required data
  14325. sprintf((char *)ShmOCPP16Data->StartTransaction[gun_index].ResponseIdTagInfo.Status, "%s", json_object_get_string(json_object_object_get(json_object_object_get(StartTransaction,"idTagInfo"), "status")));
  14326. ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId = json_object_get_int(json_object_object_get(StartTransaction,"transactionId"));
  14327. // Optional data
  14328. if(json_object_object_get(json_object_object_get(StartTransaction,"idTagInfo"), "expiryDate") != NULL)
  14329. sprintf((char *)ShmOCPP16Data->StartTransaction[gun_index].ResponseIdTagInfo.ExpiryDate, "%s", json_object_get_string(json_object_object_get(json_object_object_get(StartTransaction,"idTagInfo"), "expiryDate")));
  14330. if(json_object_object_get(json_object_object_get(StartTransaction,"idTagInfo"), "parentIdTag") != NULL)
  14331. sprintf((char *)ShmOCPP16Data->StartTransaction[gun_index].ResponseIdTagInfo.ParentIdTag, "%s", json_object_get_string(json_object_object_get(json_object_object_get(StartTransaction,"idTagInfo"), "parentIdTag")));
  14332. }
  14333. json_object_put(StartTransaction);
  14334. isQueueSendable = 1;
  14335. ShmOCPP16Data->CpMsg.bits[gun_index].StartTransactionConf = 1;
  14336. ShmOCPP16Data->CpMsg.bits[gun_index].StartTransactionReq = 0;
  14337. //-----------Start : write to the Queue TransactionId file -----------------//
  14338. if((access("/Storage/OCPP/QueueTransactionId",F_OK))!=-1)
  14339. {}
  14340. else
  14341. {
  14342. FILE *log = fopen("/Storage/OCPP/QueueTransactionId", "w+");
  14343. if(log == NULL)
  14344. {
  14345. DEBUG_INFO("Can't Create File QueueTransactionId \n");
  14346. return ;
  14347. }
  14348. else
  14349. {
  14350. fclose(log);
  14351. }
  14352. }
  14353. // open file for writing
  14354. //-------------Start: write to the Queue TransactionId file------------------------------------------//
  14355. if((ShmOCPP16Data->StartTransaction[gun_index].ConnectorId !=0)&&(strcmp((const char *)ShmOCPP16Data->StartTransaction[gun_index].IdTag,"")!=0)&&(ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId !=0))
  14356. {
  14357. outfile = fopen ("/Storage/OCPP/QueueTransactionId", "a");
  14358. sprintf(data,"%d,%s,%d\n", ShmOCPP16Data->StartTransaction[gun_index].ConnectorId , ShmOCPP16Data->StartTransaction[gun_index].IdTag, ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId); // GunIndex, idtag, TransactionId
  14359. fputs(data, outfile);
  14360. fclose (outfile);
  14361. }
  14362. DEBUG_INFO("idTagInfo-expiryDate: %s\n", ShmOCPP16Data->StartTransaction[gun_index].ResponseIdTagInfo.ExpiryDate);
  14363. DEBUG_INFO("idTagInfo-parentIdTag: %s\n", ShmOCPP16Data->StartTransaction[gun_index].ResponseIdTagInfo.ParentIdTag);
  14364. DEBUG_INFO("idTagInfo-status: %s\n", ShmOCPP16Data->StartTransaction[gun_index].ResponseIdTagInfo.Status);
  14365. DEBUG_INFO("transactionId: %d\n", ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId);
  14366. system("/bin/fsync -d /dev/mtdblock13;/bin/sync &");
  14367. }
  14368. void handleStatusNotificationResponse(char *payload, int gun_index)
  14369. {
  14370. mtrace();
  14371. DEBUG_INFO("handleStatusNotificationResponse...\n");
  14372. //cpinitateMsg.bits[gun_index].TriggerStatusNotificationReq = 0;
  14373. //cpinitateMsg.bits[gun_index].StatusNotificationReq = 0;
  14374. cpinitateMsg.bits[gun_index].StatusNotificationConf = 1;
  14375. }
  14376. void handleStopTransactionnResponse(char *payload, int gun_index)
  14377. {
  14378. mtrace();
  14379. DEBUG_INFO("handleStopTransactionnResponse...\n");
  14380. json_object *StopTransaction;
  14381. StopTransaction = json_tokener_parse(payload);
  14382. if(!is_error(StopTransaction))
  14383. {
  14384. // Optional data
  14385. if(json_object_object_get(StopTransaction, "idTagInfo") != NULL)
  14386. {
  14387. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].ResponseIdTagInfo.Status, "%s", json_object_get_string(json_object_object_get(json_object_object_get(StopTransaction,"idTagInfo"), "status")));
  14388. if(json_object_object_get(json_object_object_get(StopTransaction,"idTagInfo"), "expiryDate") != NULL)
  14389. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].ResponseIdTagInfo.ExpiryDate, "%s", json_object_get_string(json_object_object_get(json_object_object_get(StopTransaction,"idTagInfo"), "expiryDate")));
  14390. if(json_object_object_get(json_object_object_get(StopTransaction,"idTagInfo"), "parentIdTag") != NULL)
  14391. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].ResponseIdTagInfo.ParentIdTag, "%s", json_object_get_string(json_object_object_get(json_object_object_get(StopTransaction,"idTagInfo"), "parentIdTag")));
  14392. }
  14393. }
  14394. json_object_put(StopTransaction);
  14395. isQueueSendable = 1;
  14396. ShmOCPP16Data->CpMsg.bits[gun_index].StopTransactionConf = 1;
  14397. ShmOCPP16Data->CpMsg.bits[gun_index].StopTransactionReq = 0;
  14398. DEBUG_INFO("idTagInfo-expiryDate: %s\n", ShmOCPP16Data->StopTransaction[gun_index].ResponseIdTagInfo.ExpiryDate);
  14399. DEBUG_INFO("idTagInfo-parentIdTag: %s\n", ShmOCPP16Data->StopTransaction[gun_index].ResponseIdTagInfo.ParentIdTag);
  14400. DEBUG_INFO("idTagInfo-status: %s\n", ShmOCPP16Data->StopTransaction[gun_index].ResponseIdTagInfo.Status);
  14401. SetTransactionIdZero(queueOpInfo.stopTransactionId);
  14402. }
  14403. void handleLogStatusNotificationResponse(char *payload, int gun_index)
  14404. {
  14405. mtrace();
  14406. DEBUG_INFO("handleLogStatusNotificationResponse...\n");
  14407. ShmOCPP16Data->SpMsg.bits.LogStatusNotificationConf = 1;
  14408. }
  14409. void handleSecurityEventNotificationResponse(char *payload, int gun_index)
  14410. {
  14411. mtrace();
  14412. DEBUG_INFO("handleSecurityEventNotificationResponse...\n");
  14413. ShmOCPP16Data->SpMsg.bits.SecurityEventNotificationConf = 1;
  14414. }
  14415. void handleSignCertificateResponse(char *payload, int gun_index)
  14416. {
  14417. mtrace();
  14418. DEBUG_INFO("handleSignCertificateResponse...\n");
  14419. json_object *SignCertificate;
  14420. SignCertificate = json_tokener_parse(payload);
  14421. if(!is_error(SignCertificate))
  14422. {
  14423. sprintf((char*)ShmOCPP16Data->SignCertificate.Response_status, "%s", json_object_get_string(json_object_object_get(SignCertificate, "status")));
  14424. DEBUG_INFO("status: %s\n", ShmOCPP16Data->SignCertificate.Response_status);
  14425. }
  14426. json_object_put(SignCertificate);
  14427. ShmOCPP16Data->SpMsg.bits.SignCertificateConf = 1;
  14428. }
  14429. void handleSignedFirmwareStatusNotificationResponse(char *payload, int gun_index)
  14430. {
  14431. mtrace();
  14432. DEBUG_INFO("handleSignedFirmwareStatusNotificationResponse...\n");
  14433. ShmOCPP16Data->SpMsg.bits.SignedFirmwareStatusNotificationConf = 1;
  14434. }
  14435. //==========================================
  14436. // Handle Error routine
  14437. //==========================================
  14438. void handleError(char *id, char *errorCode, char *errorDescription,char *payload)
  14439. {
  14440. mtrace();
  14441. #ifdef SystemLogMessage
  14442. DEBUG_INFO("errorCode: %s\n", errorCode);
  14443. DEBUG_INFO("errorDescription: %s\n", errorDescription);
  14444. DEBUG_INFO("errorDetails: %s\n", payload);
  14445. #endif
  14446. }
  14447. //===============================================
  14448. // Common routine
  14449. //===============================================
  14450. int initialConfigurationTable(void)
  14451. {
  14452. //clock_t start_t, end_t, total_t;
  14453. FILE *fp;
  14454. FILE *outfile;
  14455. char str[512]={0};
  14456. char sstr[256]={0};
  14457. int c = 0;
  14458. char *loc;
  14459. int confVersion = 16;
  14460. DEBUG_INFO("initialConfigurationTable...version: %d\n", confVersion);
  14461. //start_t = clock();
  14462. //printf("Starting of the program, start_t = %ld\n", start_t);
  14463. memset(&(ShmOCPP16Data->ConfigurationTable), 0, sizeof(struct OCPP16ConfigurationTable) );
  14464. // Check configuration file size is correct
  14465. if((access("/Storage/OCPP/OCPPConfiguration",F_OK))!=-1)
  14466. {
  14467. struct stat st;
  14468. stat("/Storage/OCPP/OCPPConfiguration", &st);
  14469. if(st.st_size < 3100)
  14470. {
  14471. system("rm -f /Storage/OCPP/OCPPConfiguration");
  14472. DEBUG_INFO("OCPPConfiguration file size: %d is smaller than 3100 bytes, restore to default value.\n", st.st_size);
  14473. }
  14474. }
  14475. if((access("/Storage/OCPP/OCPPConfiguration",F_OK))==-1)
  14476. {
  14477. outfile = fopen("/Storage/OCPP/OCPPConfiguration" , "w+");
  14478. if(outfile == NULL)
  14479. {
  14480. DEBUG_INFO("Error opening file\n");
  14481. return FALSE;
  14482. }
  14483. /*Core Profile*/
  14484. //AllowOfflineTxForUnknownId
  14485. ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemAccessibility = 1;
  14486. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemName, "AllowOfflineTxForUnknownId");
  14487. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemData, "FALSE" );
  14488. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","AllowOfflineTxForUnknownId", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemData);
  14489. //AuthorizationCacheEnabled
  14490. ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemAccessibility = 1;
  14491. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemName, "AuthorizationCacheEnabled");
  14492. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemData, "FALSE" );
  14493. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","AuthorizationCacheEnabled", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemData);
  14494. //AuthorizeRemoteTxRequests
  14495. ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemAccessibility = 0;
  14496. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemName, "AuthorizeRemoteTxRequests");
  14497. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemData, "FALSE" );
  14498. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","AuthorizeRemoteTxRequests", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemData);
  14499. //BlinkRepeat
  14500. ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemAccessibility = 1;
  14501. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemName, "BlinkRepeat");
  14502. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemData, "0" );
  14503. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","BlinkRepeat", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemData);
  14504. //ClockAlignedDataInterval
  14505. ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemAccessibility = 1;
  14506. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemName, "ClockAlignedDataInterval");
  14507. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemData, "0" );
  14508. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ClockAlignedDataInterval", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemData);
  14509. //ConnectionTimeOut
  14510. ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemAccessibility = 1;
  14511. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemName, "ConnectionTimeOut");
  14512. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemData, "180" );
  14513. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ConnectionTimeOut", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemData);
  14514. //GetConfigurationMaxKeys
  14515. ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemAccessibility =0;
  14516. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemName, "GetConfigurationMaxKeys");
  14517. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemData, "%d", _GetConfiguration_CNT);
  14518. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","GetConfigurationMaxKeys", "true", ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemData);
  14519. // HeartbeatInterval
  14520. ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemAccessibility = 1;
  14521. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemName, "HeartbeatInterval");
  14522. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemData, "20" );
  14523. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","HeartbeatInterval", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemData);
  14524. // LightIntensity
  14525. ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemAccessibility = 1;
  14526. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemName, "LightIntensity");
  14527. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemData, "0" );
  14528. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LightIntensity", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemData);
  14529. // LocalAuthorizeOffline
  14530. ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemAccessibility = 1;
  14531. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemName, "LocalAuthorizeOffline");
  14532. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemData, "TRUE" );
  14533. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LocalAuthorizeOffline", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemData);
  14534. // LocalPreAuthorize
  14535. ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemAccessibility = 1;
  14536. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemName, "LocalPreAuthorize");
  14537. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemData, "FALSE" );
  14538. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LocalPreAuthorize", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemData);
  14539. // MaxEnergyOnInvalidId
  14540. ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemAccessibility = 1;
  14541. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemName, "MaxEnergyOnInvalidId");
  14542. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemData, "0" );
  14543. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MaxEnergyOnInvalidId", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemData);
  14544. // MeterValuesAlignedData
  14545. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemAccessibility = 1;
  14546. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemName, "MeterValuesAlignedData");
  14547. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  14548. 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" );
  14549. else
  14550. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, "Current.Import,Energy.Active.Import.Register,Energy.Active.Import.Interval,Power.Active.Import,Voltage,Current.Offered" );
  14551. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValuesAlignedData", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData);
  14552. // MeterValuesAlignedDataMaxLength
  14553. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemAccessibility = 0;
  14554. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemName, "MeterValuesAlignedDataMaxLength");
  14555. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  14556. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemData, "8" );
  14557. else
  14558. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemData, "10" );
  14559. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValuesAlignedDataMaxLength", "true", ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemData);
  14560. // MeterValuesSampledData
  14561. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemAccessibility = 1;
  14562. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemName, "MeterValuesSampledData");
  14563. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  14564. 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" );
  14565. else
  14566. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, "Current.Import,Energy.Active.Import.Register,Energy.Active.Import.Interval,Power.Active.Import,Voltage,Current.Offered" );
  14567. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValuesSampledData", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData);
  14568. // MeterValuesSampledDataMaxLength
  14569. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemAccessibility = 0;
  14570. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemName, "MeterValuesSampledDataMaxLength");
  14571. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  14572. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemData, "8" );
  14573. else
  14574. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemData, "10" );
  14575. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValuesSampledDataMaxLength", "true", ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemData);
  14576. // MeterValueSampleInterval
  14577. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemAccessibility = 1;
  14578. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemName, "MeterValueSampleInterval");
  14579. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemData, "30" );
  14580. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValueSampleInterval", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemData);
  14581. // MinimumStatusDuration
  14582. ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemAccessibility = 1;
  14583. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemName, "MinimumStatusDuration");
  14584. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemData, "120" );
  14585. server_cycle_Status = atoi((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemData); //StatusNotification cycle
  14586. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MinimumStatusDuration", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemData);
  14587. // NumberOfConnectors
  14588. ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemAccessibility = 0;
  14589. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemName, "NumberOfConnectors");
  14590. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  14591. {
  14592. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData, "%d", (CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY));
  14593. }
  14594. else
  14595. {
  14596. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData, "%d", AC_QUANTITY);
  14597. }
  14598. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","NumberOfConnectors", "true", ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData);
  14599. // ResetRetries
  14600. ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemAccessibility = 1;
  14601. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemName, "ResetRetries");
  14602. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemData, "3" );
  14603. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ResetRetries", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemData);
  14604. // ConnectorPhaseRotation
  14605. ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemAccessibility = 1;
  14606. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemName, "ConnectorPhaseRotation");
  14607. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "NotApplicable" );
  14608. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ConnectorPhaseRotation", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData);
  14609. // ConnectorPhaseRotationMaxLength
  14610. ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemAccessibility = 0;
  14611. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemName, "ConnectorPhaseRotationMaxLength");
  14612. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemData, "1" );
  14613. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ConnectorPhaseRotationMaxLength", "true", ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemData);
  14614. // StopTransactionOnEVSideDisconnect
  14615. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemAccessibility = 0;
  14616. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemName, "StopTransactionOnEVSideDisconnect");
  14617. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemData, "TRUE" );
  14618. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTransactionOnEVSideDisconnect", "true", ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemData);
  14619. // StopTransactionOnInvalidId
  14620. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemAccessibility = 1; //1;
  14621. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemName, "StopTransactionOnInvalidId");
  14622. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemData, "FALSE" );
  14623. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTransactionOnInvalidId", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemData);
  14624. // StopTxnAlignedData
  14625. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemAccessibility = 0;
  14626. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemName, "StopTxnAlignedData");
  14627. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemData, "" );
  14628. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTxnAlignedData", "true", ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemData);
  14629. // StopTxnAlignedDataMaxLength
  14630. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemAccessibility = 0;
  14631. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemName, "StopTxnAlignedDataMaxLength");
  14632. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemData, "0" );
  14633. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTxnAlignedDataMaxLength", "true", ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemData);
  14634. // StopTxnSampledData
  14635. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemAccessibility = 1;
  14636. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemName, "StopTxnSampledData");
  14637. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  14638. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Current.Import,Energy.Active.Import.Interval,Power.Active.Import,Voltage,SoC" );
  14639. else
  14640. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Current.Import,Energy.Active.Import.Interval,Power.Active.Import,Voltage" );
  14641. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTxnSampledData", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData);
  14642. // StopTxnSampledDataMaxLength
  14643. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemAccessibility = 0;
  14644. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemName, "StopTxnSampledDataMaxLength");
  14645. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  14646. {
  14647. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemData, "%d", 7);
  14648. }
  14649. else
  14650. {
  14651. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemData, "%d", 9);
  14652. }
  14653. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTxnSampledDataMaxLength", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemData);
  14654. // SupportedFeatureProfiles
  14655. ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemAccessibility = 0;
  14656. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemName, "SupportedFeatureProfiles");
  14657. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemData, "Core,FirmwareManagement,LocalAuthListManagement,Reservation,SmartCharging,RemoteTrigger" );
  14658. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","SupportedFeatureProfiles", "true", ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemData);
  14659. // SupportedFeatureProfilesMaxLength
  14660. ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemAccessibility = 0;
  14661. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemName, "SupportedFeatureProfilesMaxLength");
  14662. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemData, "6" );
  14663. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","SupportedFeatureProfilesMaxLength", "true", ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemData);
  14664. // TransactionMessageAttempts
  14665. ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemAccessibility = 1;
  14666. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemName, "TransactionMessageAttempts");
  14667. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData, "3" );
  14668. TransactionMessageAttemptsValue = atoi((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData);
  14669. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","TransactionMessageAttempts", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData);
  14670. // TransactionMessageRetryInterval
  14671. ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemAccessibility = 1;
  14672. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemName, "TransactionMessageRetryInterval");
  14673. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData, "60" );
  14674. TransactionMessageRetryIntervalValue = atoi((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData);
  14675. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","TransactionMessageRetryInterval", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData);
  14676. // UnlockConnectorOnEVSideDisconnect
  14677. ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemAccessibility = 0;
  14678. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemName, "UnlockConnectorOnEVSideDisconnect");
  14679. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemData, "TRUE" );
  14680. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","UnlockConnectorOnEVSideDisconnect", "true", ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemData);
  14681. // WebSocketPingInterval
  14682. ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemAccessibility = 1;
  14683. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemName, "WebSocketPingInterval");
  14684. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemData, "30" );
  14685. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","WebSocketPingInterval", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemData);
  14686. // QueueOffLineMeterValues
  14687. ShmOCPP16Data->ConfigurationTable.CoreProfile[QueueOffLineMeterValues].ItemAccessibility = 1;
  14688. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[QueueOffLineMeterValues].ItemName, "QueueOffLineMeterValues");
  14689. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[QueueOffLineMeterValues].ItemData, "FALSE" );
  14690. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","QueueOffLineMeterValues", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[QueueOffLineMeterValues].ItemData);
  14691. // AuthorizationKey
  14692. ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationKey].ItemAccessibility = 1;
  14693. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationKey].ItemName, "AuthorizationKey");
  14694. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationKey].ItemData, (char*)ShmSysConfigAndInfo->SysConfig.OcppSecurityPassword);
  14695. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","AuthorizationKey", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationKey].ItemData);
  14696. // SecurityProfile
  14697. ShmOCPP16Data->ConfigurationTable.CoreProfile[SecurityProfile].ItemAccessibility = 1;
  14698. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SecurityProfile].ItemName, "SecurityProfile");
  14699. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SecurityProfile].ItemData, "%d", ShmSysConfigAndInfo->SysConfig.OcppSecurityProfile);
  14700. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","SecurityProfile", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[SecurityProfile].ItemData);
  14701. // DefaultPrice
  14702. ShmOCPP16Data->ConfigurationTable.CoreProfile[DefaultPrice].ItemAccessibility = 1;
  14703. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[DefaultPrice].ItemName, "DefaultPrice");
  14704. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[DefaultPrice].ItemData, "" );
  14705. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","DefaultPrice", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[DefaultPrice].ItemData);
  14706. // CustomDisplayCostAndPrice
  14707. ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemAccessibility = 1;
  14708. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemName, "CustomDisplayCostAndPrice");
  14709. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemData, "FALSE" );
  14710. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","CustomDisplayCostAndPrice", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemData);
  14711. // CustomIdleFeeAfterStop
  14712. ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemAccessibility = 1;
  14713. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemName, "CustomIdleFeeAfterStop");
  14714. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemData, "FALSE" );
  14715. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","CustomIdleFeeAfterStop", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemData);
  14716. // TimeOffset
  14717. ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffset].ItemAccessibility = 1;
  14718. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffset].ItemName, "TimeOffset");
  14719. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffset].ItemData, "+00:00" );
  14720. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","TimeOffset", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffset].ItemData);
  14721. // NextTimeOffsetTransitionDateTime
  14722. ShmOCPP16Data->ConfigurationTable.CoreProfile[NextTimeOffsetTransitionDateTime].ItemAccessibility = 1;
  14723. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NextTimeOffsetTransitionDateTime].ItemName, "NextTimeOffsetTransitionDateTime");
  14724. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NextTimeOffsetTransitionDateTime].ItemData, " " );
  14725. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","NextTimeOffsetTransitionDateTime", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[NextTimeOffsetTransitionDateTime].ItemData);
  14726. // TimeOffsetNextTransition
  14727. ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffsetNextTransition].ItemAccessibility = 1;
  14728. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffsetNextTransition].ItemName, "TimeOffsetNextTransition");
  14729. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffsetNextTransition].ItemData, "+00:00" );
  14730. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","TimeOffsetNextTransition", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffsetNextTransition].ItemData);
  14731. // SystemUptimeSec
  14732. ShmOCPP16Data->ConfigurationTable.CoreProfile[SystemUptimeSec].ItemAccessibility = 1;
  14733. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SystemUptimeSec].ItemName, "SystemUptimeSec");
  14734. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SystemUptimeSec].ItemData, "0" );
  14735. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","SystemUptimeSec", "true", ShmOCPP16Data->ConfigurationTable.CoreProfile[SystemUptimeSec].ItemData);
  14736. // FreeVend
  14737. ShmOCPP16Data->ConfigurationTable.CoreProfile[FreeVend].ItemAccessibility = 1;
  14738. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[FreeVend].ItemName, "FreeVend");
  14739. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[FreeVend].ItemData, (ShmSysConfigAndInfo->SysConfig.AuthorisationMode?"TRUE":"FALSE") );
  14740. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","FreeVend", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[FreeVend].ItemData);
  14741. // FreeVendIdtag
  14742. ShmOCPP16Data->ConfigurationTable.CoreProfile[FreeVendIdtag].ItemAccessibility = 1;
  14743. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[FreeVendIdtag].ItemName, "FreeVendIdtag");
  14744. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[FreeVendIdtag].ItemData, "FreeVendIdtag" );
  14745. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","FreeVendIdtag", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[FreeVendIdtag].ItemData);
  14746. // OcppServer
  14747. ShmOCPP16Data->ConfigurationTable.CoreProfile[OcppServer].ItemAccessibility = 1;
  14748. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[OcppServer].ItemName, "OcppServer");
  14749. memcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[OcppServer].ItemData, (char*)ShmSysConfigAndInfo->SysConfig.OcppServerURL, 500);
  14750. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","OcppServer", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[OcppServer].ItemData);
  14751. // MaintainServer
  14752. ShmOCPP16Data->ConfigurationTable.CoreProfile[MaintainServer].ItemAccessibility = 1;
  14753. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MaintainServer].ItemName, "MaintainServer");
  14754. memcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MaintainServer].ItemData, (char*)ShmSysConfigAndInfo->SysConfig.MaintainServerURL, 500);
  14755. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MaintainServer", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[MaintainServer].ItemData);
  14756. // StatusNotificationPeriodically
  14757. ShmOCPP16Data->ConfigurationTable.CoreProfile[StatusNotificationPeriodically].ItemAccessibility = 1;
  14758. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StatusNotificationPeriodically].ItemName, "StatusNotificationPeriodically");
  14759. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StatusNotificationPeriodically].ItemData, "FALSE" );
  14760. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StatusNotificationPeriodically", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[StatusNotificationPeriodically].ItemData);
  14761. // StatusNotificationInterval
  14762. ShmOCPP16Data->ConfigurationTable.CoreProfile[StatusNotificationInterval].ItemAccessibility = 1;
  14763. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StatusNotificationInterval].ItemName, "StatusNotificationInterval");
  14764. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StatusNotificationInterval].ItemData, "120" );
  14765. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StatusNotificationInterval", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[StatusNotificationInterval].ItemData);
  14766. // PreAuthAmount
  14767. ShmOCPP16Data->ConfigurationTable.CoreProfile[PreAuthAmount].ItemAccessibility = 1;
  14768. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[PreAuthAmount].ItemName, "PreAuthAmount");
  14769. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[PreAuthAmount].ItemData, "888" );
  14770. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","PreAuthAmount", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[PreAuthAmount].ItemData);
  14771. // isEnableLocalPowerSharing
  14772. ShmOCPP16Data->ConfigurationTable.CoreProfile[isEnableLocalPowerSharing].ItemAccessibility = 1;
  14773. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[isEnableLocalPowerSharing].ItemName, "isEnableLocalPowerSharing");
  14774. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[isEnableLocalPowerSharing].ItemData, "%d", ShmSysConfigAndInfo->SysConfig.isEnableLocalPowerSharing);
  14775. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","isEnableLocalPowerSharing", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[isEnableLocalPowerSharing].ItemData);
  14776. // PowerSharingServerIP
  14777. ShmOCPP16Data->ConfigurationTable.CoreProfile[PowerSharingServerIP].ItemAccessibility = 1;
  14778. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[PowerSharingServerIP].ItemName, "PowerSharingServerIP");
  14779. memcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[PowerSharingServerIP].ItemData, (char*)ShmSysConfigAndInfo->SysConfig.PowerSharingServerIP, 500);
  14780. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","PowerSharingServerIP", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[PowerSharingServerIP].ItemData);
  14781. // EVCCID_PREFIX
  14782. ShmOCPP16Data->ConfigurationTable.CoreProfile[EVCCID_PREFIX].ItemAccessibility = 1;
  14783. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[EVCCID_PREFIX].ItemName, "EVCCID_PREFIX");
  14784. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[EVCCID_PREFIX].ItemData, "" );
  14785. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","EVCCID_PREFIX", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[EVCCID_PREFIX].ItemData);
  14786. // OffLineMaxChargingPower
  14787. ShmOCPP16Data->ConfigurationTable.CoreProfile[OffLineMaxChargingPower].ItemAccessibility = 1;
  14788. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[OffLineMaxChargingPower].ItemName, "OffLineMaxChargingPower");
  14789. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[OffLineMaxChargingPower].ItemData, "0" );
  14790. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","OffLineMaxChargingPower", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[OffLineMaxChargingPower].ItemData);
  14791. // Configuration Version
  14792. ShmOCPP16Data->ConfigurationTable.CoreProfile[ConfigurationVersion].ItemAccessibility = 0;
  14793. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConfigurationVersion].ItemName, "ConfigurationVersion");
  14794. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConfigurationVersion].ItemData, "%d", confVersion);
  14795. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ConfigurationVersion", "true", ShmOCPP16Data->ConfigurationTable.CoreProfile[ConfigurationVersion].ItemData);
  14796. //* Local Auth List Management Profile*/
  14797. #if 0
  14798. //For OCTT Test Case
  14799. ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemAccessibility = 1;
  14800. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemName, "LocalAuthorizationListEnabled");
  14801. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "TRUE" );
  14802. #endif
  14803. #if 1
  14804. //LocalAuthListEnabled
  14805. ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemAccessibility = 1;
  14806. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemName, "LocalAuthListEnabled");
  14807. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "TRUE" );
  14808. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LocalAuthListEnabled", "false", ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData);
  14809. #endif
  14810. //LocalAuthListMaxLength
  14811. ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemAccessibility = 0;
  14812. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemName, "LocalAuthListMaxLength");
  14813. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemData, "100000" );
  14814. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LocalAuthListMaxLength", "true", ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemData);
  14815. //SendLocalListMaxLength
  14816. ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemAccessibility = 0;
  14817. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemName, "SendLocalListMaxLength");
  14818. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemData, "500" );
  14819. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","SendLocalListMaxLength", "true", ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemData);
  14820. //ReserveConnectorZeroSupported
  14821. ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemAccessibility = 0;
  14822. strcpy((char *)ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemName, "ReserveConnectorZeroSupported");
  14823. strcpy((char *)ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemData, "FALSE" );
  14824. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ReserveConnectorZeroSupported", "true", ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemData);
  14825. //* Smart Charging Profile */
  14826. //ChargeProfileMaxStackLevel
  14827. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemAccessibility = 0;
  14828. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemName, "ChargeProfileMaxStackLevel");
  14829. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemData, "8" );
  14830. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ChargeProfileMaxStackLevel", "true", ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemData);
  14831. // ChargingScheduleAllowedChargingRateUnit
  14832. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemAccessibility = 0;
  14833. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemName, "ChargingScheduleAllowedChargingRateUnit");
  14834. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemData, "Current,Power" );
  14835. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ChargingScheduleAllowedChargingRateUnit", "true", ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemData);
  14836. // ChargingScheduleMaxPeriods
  14837. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemAccessibility = 0;
  14838. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemName, "ChargingScheduleMaxPeriods");
  14839. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemData, "10" );
  14840. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ChargingScheduleMaxPeriods", "true", ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemData);
  14841. // ConnectorSwitch3to1PhaseSupported
  14842. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemAccessibility = 0;
  14843. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemName, "ConnectorSwitch3to1PhaseSupported");
  14844. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemData, "FALSE" );
  14845. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ConnectorSwitch3to1PhaseSupported", "true", ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemData);
  14846. // MaxChargingProfilesInstalled
  14847. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemAccessibility = 0;
  14848. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemName, "MaxChargingProfilesInstalled");
  14849. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemData, "50" );
  14850. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MaxChargingProfilesInstalled", "true", ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemData);
  14851. fclose(outfile);
  14852. }
  14853. else
  14854. {
  14855. //DEBUG_INFO("../Storage/OCPP/OCPPConfiguration EXit\n");
  14856. char keystr[60]={0};
  14857. char readonlystr[10]={0};
  14858. char valuestr[256]={0};
  14859. fp = fopen("/Storage/OCPP/OCPPConfiguration" , "r");
  14860. if(fp == NULL) {
  14861. DEBUG_INFO("Error opening file");
  14862. return FALSE;
  14863. }
  14864. while( fgets (str, ARRAY_SIZE(str), fp)!=NULL )
  14865. {
  14866. //DEBUG_INFO("Get Configuration \n");
  14867. if(strlen(str) > 0)
  14868. {
  14869. str[strlen(str) - 1] = '\0'; // eat the newline fgets() stores
  14870. //*************************key*********************************/
  14871. if(strstr(str, "key") != NULL)
  14872. {
  14873. loc = strstr(str, "key");
  14874. c = 0;
  14875. memset(sstr ,0, ARRAY_SIZE(sstr) );
  14876. while ((loc[strlen("key")+3+c] != '\"') && (c < (ARRAY_SIZE(sstr)-1)))
  14877. {
  14878. sstr[c] = loc[strlen("key")+3+c];
  14879. c++;
  14880. }
  14881. sstr[c] = '\0';
  14882. strcpy(keystr,sstr);
  14883. }
  14884. //*************************readonly*********************************/
  14885. if(strstr(str, "readonly") != NULL)
  14886. {
  14887. loc = strstr(str, "readonly");
  14888. c = 0;
  14889. memset(sstr ,0, ARRAY_SIZE(sstr) );
  14890. while ((loc[strlen("readonly")+2+c] != ',') && (c < (ARRAY_SIZE(sstr)-1)))
  14891. {
  14892. sstr[c] = loc[strlen("readonly")+2+c];
  14893. c++;
  14894. }
  14895. sstr[c] = '\0';
  14896. strcpy(readonlystr,sstr);
  14897. }
  14898. //*************************value*********************************/
  14899. if(strstr(str, "value") != NULL)
  14900. {
  14901. loc = strstr(str, "value");
  14902. c = 0;
  14903. memset(sstr ,0, ARRAY_SIZE(sstr) );
  14904. while ((loc[strlen("value")+3+c] != '\"') && (c < (ARRAY_SIZE(sstr)-1)))
  14905. {
  14906. sstr[c] = loc[strlen("value")+3+c];
  14907. c++;
  14908. }
  14909. sstr[c] = '\0';
  14910. strcpy(valuestr,sstr);
  14911. }
  14912. // DEBUG_INFO("keystr=%s\n",keystr);
  14913. // DEBUG_INFO("readonlystr=%s\n",readonlystr);
  14914. // DEBUG_INFO("valuestr=%s\n",valuestr);
  14915. if(strcmp(keystr, "AllowOfflineTxForUnknownId") == 0)
  14916. {
  14917. //Charger.AllowOfflineTxForUnknownId = (value.toLowerCase().equals("true")?true:false);
  14918. ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14919. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemData, "%s", valuestr );
  14920. // DEBUG_INFO("AllowOfflineTxForUnknownId setting\n");
  14921. // DEBUG_INFO("AllowOfflineTxForUnknownId setting\n");
  14922. }
  14923. if(strcmp(keystr, "AuthorizationCacheEnabled") == 0)
  14924. {
  14925. //Charger.AuthorizationCacheEnabled = (value.toLowerCase().equals("true")?true:false);
  14926. ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14927. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemData, "%s", valuestr );
  14928. }
  14929. if(strcmp(keystr, "AuthorizeRemoteTxRequests") == 0)
  14930. {
  14931. ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14932. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemData, "%s", valuestr );
  14933. }
  14934. if(strcmp(keystr, "BlinkRepeat") == 0)
  14935. {
  14936. //Charger.BlinkRepeat = Integer.parseInt(value);
  14937. ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14938. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemData, "%d", atoi(valuestr) );
  14939. }
  14940. if(strcmp(keystr, "ClockAlignedDataInterval") == 0)
  14941. {
  14942. ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14943. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemData, "%d", atoi(valuestr) );
  14944. }
  14945. if(strcmp(keystr, "ConnectionTimeOut") == 0 )
  14946. {
  14947. ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14948. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemData, "%d", atoi(valuestr));
  14949. }
  14950. if(strcmp(keystr, "GetConfigurationMaxKeys") == 0)
  14951. {
  14952. ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14953. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemData, "%d", (atoi(valuestr)!=GetConfigurationMaxKeysNUM?GetConfigurationMaxKeysNUM:atoi(valuestr)));
  14954. }
  14955. if(strcmp(keystr, "HeartbeatInterval") == 0)
  14956. {
  14957. ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14958. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemData, "%d", atoi(valuestr));
  14959. HeartBeatWaitTime = atoi(valuestr);
  14960. }
  14961. if(strcmp(keystr, "LightIntensity") == 0)
  14962. {
  14963. ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14964. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemData, "%d", atoi(valuestr));
  14965. }
  14966. if(strcmp(keystr, "LocalAuthorizeOffline") == 0)
  14967. {
  14968. ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14969. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemData, "%s", valuestr );
  14970. }
  14971. if(strcmp(keystr, "LocalPreAuthorize") == 0)
  14972. {
  14973. ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14974. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemData, "%s", valuestr );
  14975. }
  14976. if(strcmp(keystr, "MaxEnergyOnInvalidId") == 0)
  14977. {
  14978. ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14979. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemData, "%d", atoi(valuestr) );
  14980. }
  14981. if(strcmp(keystr, "MeterValuesAlignedData") == 0)
  14982. {
  14983. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14984. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, "%s", valuestr );
  14985. }
  14986. if(strcmp(keystr, "MeterValuesAlignedDataMaxLength") == 0)
  14987. {
  14988. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14989. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemData, "%d", atoi(valuestr));
  14990. }
  14991. if(strcmp(keystr, "MeterValuesSampledData") == 0 )
  14992. {
  14993. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14994. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, "%s", valuestr );
  14995. }
  14996. if(strcmp(keystr, "MeterValuesSampledDataMaxLength") == 0)
  14997. {
  14998. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14999. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemData, "%d", atoi(valuestr));
  15000. }
  15001. if(strcmp(keystr, "MeterValueSampleInterval") == 0)
  15002. {
  15003. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  15004. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemData, "%d", atoi(valuestr));
  15005. }
  15006. if(strcmp(keystr, "MinimumStatusDuration") == 0)
  15007. {
  15008. ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  15009. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemData, "%d", atoi(valuestr) );
  15010. server_cycle_Status = atoi(valuestr); //StatusNotification cycle
  15011. }
  15012. if(strcmp(keystr, "NumberOfConnectors") == 0)
  15013. {
  15014. ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  15015. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData, "%d", atoi(valuestr) );
  15016. }
  15017. if(strcmp(keystr, "ResetRetries") == 0)
  15018. {
  15019. ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  15020. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemData, "%d", atoi(valuestr) );
  15021. }
  15022. if(strcmp(keystr, "ConnectorPhaseRotation") == 0)
  15023. {
  15024. ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  15025. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "%s", valuestr );
  15026. }
  15027. if(strcmp(keystr, "ConnectorPhaseRotationMaxLength") == 0)
  15028. {
  15029. ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  15030. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemData, "%d", atoi(valuestr) );
  15031. }
  15032. if(strcmp(keystr, "StopTransactionOnEVSideDisconnect") == 0)
  15033. {
  15034. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  15035. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemData, "%s", valuestr );
  15036. }
  15037. if(strcmp(keystr, "StopTransactionOnInvalidId") == 0)
  15038. {
  15039. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  15040. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemData, "%s", valuestr );
  15041. }
  15042. if(strcmp(keystr, "StopTxnAlignedData") == 0)
  15043. {
  15044. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  15045. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemData, "%s", valuestr );
  15046. }
  15047. if(strcmp(keystr, "StopTxnAlignedDataMaxLength") == 0)
  15048. {
  15049. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  15050. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemData, "%d", atoi(valuestr) );
  15051. }
  15052. if(strcmp(keystr, "StopTxnSampledData") == 0)
  15053. {
  15054. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  15055. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "%s", valuestr );
  15056. }
  15057. if(strcmp(keystr, "StopTxnSampledDataMaxLength") == 0)
  15058. {
  15059. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  15060. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemData, "%d", atoi(valuestr) );
  15061. }
  15062. if(strcmp(keystr, "SupportedFeatureProfiles") == 0)
  15063. {
  15064. ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  15065. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemData, "%s", valuestr );
  15066. }
  15067. if(strcmp(keystr, "SupportedFeatureProfilesMaxLength") == 0)
  15068. {
  15069. ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  15070. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemData, "%d", atoi(valuestr) );
  15071. }
  15072. if(strcmp(keystr, "TransactionMessageAttempts") == 0)
  15073. {
  15074. ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  15075. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData, "%d", atoi(valuestr) );
  15076. TransactionMessageAttemptsValue = atoi(valuestr);
  15077. }
  15078. if(strcmp(keystr, "TransactionMessageRetryInterval") == 0)
  15079. {
  15080. ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemAccessibility= (strcmp(readonlystr, "true")==0) ? 0 : 1;
  15081. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData, "%d", atoi(valuestr) );
  15082. TransactionMessageRetryIntervalValue = atoi(valuestr);
  15083. }
  15084. if(strcmp(keystr, "UnlockConnectorOnEVSideDisconnect") == 0)
  15085. {
  15086. ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  15087. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemData, "%s", valuestr );
  15088. }
  15089. if(strcmp(keystr, "WebSocketPingInterval") == 0)
  15090. {
  15091. ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  15092. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemData, "%d", atoi(valuestr) );
  15093. }
  15094. if(strcmp(keystr, "QueueOffLineMeterValues") == 0)
  15095. {
  15096. ShmOCPP16Data->ConfigurationTable.CoreProfile[QueueOffLineMeterValues].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  15097. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[QueueOffLineMeterValues].ItemData, "%s", valuestr);
  15098. }
  15099. if(strcmp(keystr, "AuthorizationKey") == 0)
  15100. {
  15101. ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationKey].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  15102. //sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationKey].ItemData, "%s", valuestr);
  15103. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationKey].ItemData, "%s", ShmSysConfigAndInfo->SysConfig.OcppSecurityPassword);
  15104. }
  15105. if(strcmp(keystr, "SecurityProfile") == 0)
  15106. {
  15107. ShmOCPP16Data->ConfigurationTable.CoreProfile[SecurityProfile].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  15108. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SecurityProfile].ItemData, "%d", ShmSysConfigAndInfo->SysConfig.OcppSecurityProfile);
  15109. }
  15110. if(strcmp(keystr, "DefaultPrice") == 0)
  15111. {
  15112. ShmOCPP16Data->ConfigurationTable.CoreProfile[DefaultPrice].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  15113. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[DefaultPrice].ItemData, "%s", valuestr);
  15114. }
  15115. if(strcmp(keystr, "CustomDisplayCostAndPrice") == 0)
  15116. {
  15117. ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  15118. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemData, "%s", valuestr);
  15119. }
  15120. if(strcmp(keystr, "CustomIdleFeeAfterStop") == 0)
  15121. {
  15122. ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  15123. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemData, "%s", valuestr);
  15124. }
  15125. if(strcmp(keystr, "TimeOffset") == 0)
  15126. {
  15127. ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffset].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  15128. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffset].ItemData, "%s", valuestr);
  15129. }
  15130. if(strcmp(keystr, "NextTimeOffsetTransitionDateTime") == 0)
  15131. {
  15132. ShmOCPP16Data->ConfigurationTable.CoreProfile[NextTimeOffsetTransitionDateTime].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  15133. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NextTimeOffsetTransitionDateTime].ItemData, "%s", valuestr);
  15134. }
  15135. if(strcmp(keystr, "TimeOffsetNextTransition") == 0)
  15136. {
  15137. ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffsetNextTransition].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  15138. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffsetNextTransition].ItemData, "%s", valuestr);
  15139. }
  15140. if(strcmp(keystr, "SystemUptimeSec") == 0)
  15141. {
  15142. ShmOCPP16Data->ConfigurationTable.CoreProfile[SystemUptimeSec].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  15143. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SystemUptimeSec].ItemData, "%s", valuestr);
  15144. }
  15145. if(strcmp(keystr, "FreeVend") == 0)
  15146. {
  15147. ShmOCPP16Data->ConfigurationTable.CoreProfile[FreeVend].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  15148. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[FreeVend].ItemData, "%s", (ShmSysConfigAndInfo->SysConfig.AuthorisationMode ? "TRUE" : "FALSE"));
  15149. }
  15150. if(strcmp(keystr, "FreeVendIdtag") == 0)
  15151. {
  15152. ShmOCPP16Data->ConfigurationTable.CoreProfile[FreeVendIdtag].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  15153. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[FreeVendIdtag].ItemData, "%s", valuestr);
  15154. }
  15155. if(strcmp(keystr, "OcppServer") == 0)
  15156. {
  15157. ShmOCPP16Data->ConfigurationTable.CoreProfile[OcppServer].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  15158. memcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[OcppServer].ItemData, (char *)ShmSysConfigAndInfo->SysConfig.OcppServerURL, 500);
  15159. }
  15160. if(strcmp(keystr, "MaintainServer") == 0)
  15161. {
  15162. ShmOCPP16Data->ConfigurationTable.CoreProfile[MaintainServer].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  15163. memcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MaintainServer].ItemData, (char *)ShmSysConfigAndInfo->SysConfig.MaintainServerURL,500);
  15164. }
  15165. if(strcmp(keystr, "StatusNotificationPeriodically") == 0)
  15166. {
  15167. ShmOCPP16Data->ConfigurationTable.CoreProfile[StatusNotificationPeriodically].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  15168. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StatusNotificationPeriodically].ItemData, "%s", valuestr);
  15169. }
  15170. if(strcmp(keystr, "StatusNotificationInterval") == 0)
  15171. {
  15172. ShmOCPP16Data->ConfigurationTable.CoreProfile[StatusNotificationInterval].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  15173. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StatusNotificationInterval].ItemData, "%d", atoi(valuestr));
  15174. }
  15175. if(strcmp(keystr, "PreAuthAmount") == 0)
  15176. {
  15177. ShmOCPP16Data->ConfigurationTable.CoreProfile[PreAuthAmount].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  15178. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[PreAuthAmount].ItemData, "%.2f", atof(valuestr));
  15179. }
  15180. if(strcmp(keystr, "isEnableLocalPowerSharing") == 0)
  15181. {
  15182. ShmOCPP16Data->ConfigurationTable.CoreProfile[isEnableLocalPowerSharing].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  15183. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[isEnableLocalPowerSharing].ItemData, "%d", ShmSysConfigAndInfo->SysConfig.isEnableLocalPowerSharing);
  15184. }
  15185. if(strcmp(keystr, "PowerSharingServerIP") == 0)
  15186. {
  15187. ShmOCPP16Data->ConfigurationTable.CoreProfile[PowerSharingServerIP].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  15188. memcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[PowerSharingServerIP].ItemData, (char *)ShmSysConfigAndInfo->SysConfig.PowerSharingServerIP,500);
  15189. }
  15190. if(strcmp(keystr, "EVCCID_PREFIX") == 0)
  15191. {
  15192. ShmOCPP16Data->ConfigurationTable.CoreProfile[EVCCID_PREFIX].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  15193. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[EVCCID_PREFIX].ItemData, "%s", valuestr);
  15194. }
  15195. if(strcmp(keystr, "OffLineMaxChargingPower") == 0)
  15196. {
  15197. ShmOCPP16Data->ConfigurationTable.CoreProfile[OffLineMaxChargingPower].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  15198. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[OffLineMaxChargingPower].ItemData, "%s", valuestr);
  15199. }
  15200. if(strcmp(keystr, "ConfigurationVersion") == 0)
  15201. {
  15202. ShmOCPP16Data->ConfigurationTable.CoreProfile[ConfigurationVersion].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  15203. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConfigurationVersion].ItemData, "%d", atoi(valuestr));
  15204. }
  15205. if(strcmp(keystr, "LocalAuthListEnabled") == 0)
  15206. {
  15207. ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  15208. sprintf((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "%s", valuestr );
  15209. }
  15210. if(strcmp(keystr, "LocalAuthListMaxLength") == 0)
  15211. {
  15212. ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  15213. sprintf((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemData, "%d", atoi(valuestr) );
  15214. }
  15215. if(strcmp(keystr, "SendLocalListMaxLength") == 0)
  15216. {
  15217. ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  15218. sprintf((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemData, "%d", atoi(valuestr) );
  15219. }
  15220. if(strcmp(keystr, "ReserveConnectorZeroSupported") == 0)
  15221. {
  15222. ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  15223. sprintf((char *)ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemData, "%s", valuestr );
  15224. }
  15225. if(strcmp(keystr, "ChargeProfileMaxStackLevel") == 0)
  15226. {
  15227. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  15228. sprintf((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemData, "%d", atoi(valuestr) );
  15229. }
  15230. if(strcmp(keystr, "ChargingScheduleAllowedChargingRateUnit") == 0)
  15231. {
  15232. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  15233. sprintf((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemData, "%s", valuestr );
  15234. }
  15235. if(strcmp(keystr, "ChargingScheduleMaxPeriods") == 0)
  15236. {
  15237. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  15238. sprintf((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemData, "%d", atoi(valuestr) );
  15239. }
  15240. if(strcmp(keystr, "ConnectorSwitch3to1PhaseSupported") == 0)
  15241. {
  15242. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  15243. sprintf((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemData, "%s", valuestr);
  15244. }
  15245. if(strcmp(keystr, "MaxChargingProfilesInstalled") == 0)
  15246. {
  15247. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  15248. sprintf((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemData, "%d", atoi(valuestr) );
  15249. }
  15250. }
  15251. }
  15252. fclose(fp);
  15253. }
  15254. if(atoi((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConfigurationVersion].ItemData) == confVersion)
  15255. {
  15256. return PASS;
  15257. }
  15258. else
  15259. {
  15260. return FAIL;
  15261. }
  15262. }
  15263. void StoreConfigurationTable(void)
  15264. {
  15265. FILE *outfile;
  15266. outfile = fopen("/Storage/OCPP/OCPPConfiguration" , "w+");
  15267. if(outfile == NULL)
  15268. {
  15269. DEBUG_INFO("Error opening file");
  15270. return ;
  15271. }
  15272. /*Core Profile*/
  15273. //AllowOfflineTxForUnknownId
  15274. /*
  15275. ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemAccessibility = 1;
  15276. printf("AllowoddlineTXForUnknownId type: %d \n", ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemAccessibility);
  15277. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemName, "AllowOfflineTxForUnknownId");
  15278. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemData, "TRUE" );
  15279. */
  15280. //DEBUG_INFO("data=%s\n",data);
  15281. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","AllowOfflineTxForUnknownId", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemData);
  15282. //AuthorizationCacheEnabled
  15283. /*
  15284. ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemAccessibility = 1;
  15285. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemName, "AuthorizationCacheEnabled");
  15286. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemData, "FALSE" );
  15287. */
  15288. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","AuthorizationCacheEnabled", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemData);
  15289. //AuthorizeRemoteTxRequests
  15290. /*
  15291. ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemAccessibility = 0;
  15292. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemName, "AuthorizeRemoteTxRequests");
  15293. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemData, "TRUE" );
  15294. */
  15295. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","AuthorizeRemoteTxRequests", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemData);
  15296. //BlinkRepeat
  15297. /*
  15298. ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemAccessibility = 1;
  15299. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemName, "BlinkRepeat");
  15300. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemData, "0" );
  15301. */
  15302. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","BlinkRepeat", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemData);
  15303. //ClockAlignedDataInterval
  15304. /*
  15305. ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemAccessibility = 1;
  15306. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemName, "ClockAlignedDataInterval");
  15307. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemData, "0" );
  15308. */
  15309. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ClockAlignedDataInterval", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemData);
  15310. //ConnectionTimeOut
  15311. /*
  15312. ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemAccessibility = 1;
  15313. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemName, "ConnectionTimeOut");
  15314. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemData, "180" );
  15315. */
  15316. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ConnectionTimeOut", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemData);
  15317. //GetConfigurationMaxKeys
  15318. /*
  15319. ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemAccessibility =0;
  15320. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemName, "GetConfigurationMaxKeys");
  15321. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemData, "43" );
  15322. */
  15323. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","GetConfigurationMaxKeys", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemData);
  15324. // HeartbeatInterval
  15325. /*
  15326. ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemAccessibility = 1;
  15327. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemName, "HeartbeatInterval");
  15328. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemData, "10" );
  15329. */
  15330. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","HeartbeatInterval", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemData);
  15331. // LightIntensity
  15332. /*
  15333. ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemAccessibility = 1;
  15334. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemName, "LightIntensity");
  15335. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemData, "0" );
  15336. */
  15337. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LightIntensity", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemData);
  15338. // LocalAuthorizeOffline
  15339. /*
  15340. ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemAccessibility = 0;
  15341. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemName, "LocalAuthorizeOffline");
  15342. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemData, "TRUE" );
  15343. */
  15344. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LocalAuthorizeOffline", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemData);
  15345. // LocalPreAuthorize
  15346. /*
  15347. ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemAccessibility = 0;
  15348. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemName, "LocalPreAuthorize");
  15349. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemData, "FALSE" );
  15350. */
  15351. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LocalPreAuthorize", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemData);
  15352. // MaxEnergyOnInvalidId
  15353. /*
  15354. ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemAccessibility = 1;
  15355. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemName, "MaxEnergyOnInvalidId");
  15356. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemData, "0" );
  15357. */
  15358. //ShmSysConfigAndInfo->SysConfig.OfflineMaxChargeEnergy = 0;
  15359. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MaxEnergyOnInvalidId", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemData);
  15360. // MeterValuesAlignedData
  15361. /*
  15362. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemAccessibility = 1;
  15363. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemName, "MeterValuesAlignedData");
  15364. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, "Current.Export,Energy.Active.Export.Interval,Power.Active.Export,Voltage,SOC" );
  15365. */
  15366. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValuesAlignedData", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData);
  15367. // MeterValuesAlignedDataMaxLength
  15368. /*
  15369. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemAccessibility = 0;
  15370. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemName, "MeterValuesAlignedDataMaxLength");
  15371. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemData, "5" );
  15372. */
  15373. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValuesAlignedDataMaxLength", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemData);
  15374. // MeterValuesSampledData
  15375. /*
  15376. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemAccessibility = 1;
  15377. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemName, "MeterValuesSampledData");
  15378. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, "Current.Export,Energy.Active.Export.Interval,Power.Active.Export,Voltage,SOC" );
  15379. */
  15380. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValuesSampledData", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData);
  15381. // MeterValuesSampledDataMaxLength
  15382. /*
  15383. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemAccessibility = 0;
  15384. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemName, "MeterValuesSampledDataMaxLength");
  15385. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemData, "5" );
  15386. */
  15387. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValuesSampledDataMaxLength", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemData);
  15388. // MeterValueSampleInterval
  15389. /*
  15390. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemAccessibility = 1;
  15391. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemName, "MeterValueSampleInterval");
  15392. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemData, "10" );
  15393. */
  15394. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValueSampleInterval", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemData);
  15395. // MinimumStatusDuration
  15396. /*
  15397. ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemAccessibility = 1;
  15398. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemName, "MinimumStatusDuration");
  15399. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemData, "0" );
  15400. */
  15401. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MinimumStatusDuration", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemData);
  15402. // NumberOfConnectors
  15403. /*
  15404. ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemAccessibility = 0;
  15405. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemName, "NumberOfConnectors");
  15406. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  15407. {
  15408. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData, "%d", (CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY));
  15409. }
  15410. else
  15411. {
  15412. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData, "%d", AC_QUANTITY);
  15413. }
  15414. */
  15415. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","NumberOfConnectors", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData);
  15416. // ResetRetries
  15417. /*
  15418. ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemAccessibility = 1;
  15419. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemName, "ResetRetries");
  15420. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemData, "3" );
  15421. */
  15422. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ResetRetries", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemData);
  15423. // ConnectorPhaseRotation
  15424. /*
  15425. ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemAccessibility = 1;
  15426. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemName, "ConnectorPhaseRotation");
  15427. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "NotApplicable" );
  15428. */
  15429. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ConnectorPhaseRotation", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData);
  15430. // ConnectorPhaseRotationMaxLength
  15431. /*
  15432. ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemAccessibility = 0;
  15433. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemName, "ConnectorPhaseRotationMaxLength");
  15434. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemData, "1" );
  15435. */
  15436. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ConnectorPhaseRotationMaxLength", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemData);
  15437. // StopTransactionOnEVSideDisconnect
  15438. /*
  15439. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemAccessibility = 0;
  15440. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemName, "StopTransactionOnEVSideDisconnect");
  15441. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemData, "TRUE" );
  15442. */
  15443. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTransactionOnEVSideDisconnect", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemData);
  15444. // StopTransactionOnInvalidId
  15445. /*
  15446. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemAccessibility = 0;
  15447. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemName, "StopTransactionOnInvalidId");
  15448. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemData, "FALSE" );
  15449. */
  15450. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTransactionOnInvalidId", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemData);
  15451. // StopTxnAlignedData
  15452. /*
  15453. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemAccessibility = 1;
  15454. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemName, "StopTxnAlignedData");
  15455. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemData, "Energy.Active.Import.Register" );
  15456. */
  15457. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTxnAlignedData", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemData);
  15458. // StopTxnAlignedDataMaxLength
  15459. /*
  15460. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemAccessibility = 0;
  15461. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemName, "StopTxnAlignedDataMaxLength");
  15462. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemData, "0" );
  15463. */
  15464. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTxnAlignedDataMaxLength", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemData);
  15465. // StopTxnSampledData
  15466. /*
  15467. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemAccessibility = 1;
  15468. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemName, "StopTxnSampledData");
  15469. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Energy.Active.Import.Register" );
  15470. */
  15471. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTxnSampledData", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData);
  15472. // StopTxnSampledDataMaxLength
  15473. /*
  15474. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemAccessibility = 0;
  15475. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemName, "StopTxnSampledDataMaxLength");
  15476. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemData, "0" );
  15477. */
  15478. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTxnSampledDataMaxLength", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemData);
  15479. // SupportedFeatureProfiles
  15480. /*
  15481. ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemAccessibility = 0;
  15482. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemName, "SupportedFeatureProfiles");
  15483. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemData, "Core,FirmwareManagement,LocalAuthListManagement,Reservation,SmartCharging,RemoteTrigger" );
  15484. */
  15485. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","SupportedFeatureProfiles", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemData);
  15486. // SupportedFeatureProfilesMaxLength
  15487. /*
  15488. ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemAccessibility = 0;
  15489. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemName, "SupportedFeatureProfilesMaxLength");
  15490. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemData, "6" );
  15491. */
  15492. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","SupportedFeatureProfilesMaxLength", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemData);
  15493. // TransactionMessageAttempts
  15494. /*
  15495. ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemAccessibility = 1;
  15496. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemName, "TransactionMessageAttempts");
  15497. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData, "3" );
  15498. */
  15499. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","TransactionMessageAttempts", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData);
  15500. // TransactionMessageRetryInterval
  15501. /*
  15502. ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemAccessibility = 1;
  15503. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemName, "TransactionMessageRetryInterval");
  15504. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData, "60" );
  15505. */
  15506. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","TransactionMessageRetryInterval", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData);
  15507. // UnlockConnectorOnEVSideDisconnect
  15508. /*
  15509. ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemAccessibility = 0;
  15510. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemName, "UnlockConnectorOnEVSideDisconnect");
  15511. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemData, "TRUE" );
  15512. */
  15513. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","UnlockConnectorOnEVSideDisconnect", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemData);
  15514. // WebSocketPingInterval
  15515. /*
  15516. ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemAccessibility = 1;
  15517. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemName, "WebSocketPingInterval");
  15518. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemData, "30" );
  15519. */
  15520. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","WebSocketPingInterval", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemData);
  15521. // QueueOffLineMeterValues
  15522. /*
  15523. ShmOCPP16Data->ConfigurationTable.CoreProfile[QueueOffLineMeterValues].ItemAccessibility = 0;
  15524. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[QueueOffLineMeterValues].ItemName, "QueueOffLineMeterValues");
  15525. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[QueueOffLineMeterValues].ItemData, "TRUE" );
  15526. */
  15527. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","QueueOffLineMeterValues", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[QueueOffLineMeterValues].ItemData);
  15528. // AuthorizationKey
  15529. /*
  15530. ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationKey].ItemAccessibility = 1;
  15531. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationKey].ItemName, "AuthorizationKey");
  15532. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationKey].ItemData, "0" );
  15533. */
  15534. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","AuthorizationKey", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationKey].ItemData);
  15535. // SecurityProfile
  15536. /*
  15537. ShmOCPP16Data->ConfigurationTable.CoreProfile[SecurityProfile].ItemAccessibility = 1;
  15538. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SecurityProfile].ItemName, "SecurityProfile");
  15539. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SecurityProfile].ItemData, "30" );
  15540. */
  15541. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","SecurityProfile", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SecurityProfile].ItemData);
  15542. // DefaultPrice
  15543. /*
  15544. ShmOCPP16Data->ConfigurationTable.CoreProfile[DefaultPrice].ItemAccessibility = 1;
  15545. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[DefaultPrice].ItemName, "DefaultPrice");
  15546. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[DefaultPrice].ItemData, "" );
  15547. */
  15548. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","DefaultPrice", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[DefaultPrice].ItemData);
  15549. // CustomDisplayCostAndPrice
  15550. /*
  15551. ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemAccessibility = 1;
  15552. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemName, "CustomDisplayCostAndPrice");
  15553. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemData, "FALSE" );
  15554. */
  15555. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","CustomDisplayCostAndPrice", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemData);
  15556. // CustomIdleFeeAfterStop
  15557. /*
  15558. ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemAccessibility = 1;
  15559. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemName, "CustomIdleFeeAfterStop");
  15560. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemData, "FALSE" );
  15561. */
  15562. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","CustomIdleFeeAfterStop", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemData);
  15563. // TimeOffset
  15564. /*
  15565. ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffset].ItemAccessibility = 1;
  15566. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffset].ItemName, "TimeOffset");
  15567. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffset].ItemData, "FALSE" );
  15568. */
  15569. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","TimeOffset", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffset].ItemData);
  15570. // NextTimeOffsetTransitionDateTime
  15571. /*
  15572. ShmOCPP16Data->ConfigurationTable.CoreProfile[NextTimeOffsetTransitionDateTime].ItemAccessibility = 1;
  15573. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NextTimeOffsetTransitionDateTime].ItemName, "NextTimeOffsetTransitionDateTime");
  15574. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NextTimeOffsetTransitionDateTime].ItemData, "FALSE" );
  15575. */
  15576. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","NextTimeOffsetTransitionDateTime", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NextTimeOffsetTransitionDateTime].ItemData);
  15577. // TimeOffsetNextTransition
  15578. /*
  15579. ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffsetNextTransition].ItemAccessibility = 1;
  15580. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffsetNextTransition].ItemName, "TimeOffsetNextTransition");
  15581. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffsetNextTransition].ItemData, "FALSE" );
  15582. */
  15583. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","TimeOffsetNextTransition", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffsetNextTransition].ItemData);
  15584. // SystemUptimeSec
  15585. /*
  15586. ShmOCPP16Data->ConfigurationTable.CoreProfile[SystemUptimeSec].ItemAccessibility = 1;
  15587. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SystemUptimeSec].ItemName, "SystemUptimeSec");
  15588. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SystemUptimeSec].ItemData, "0" );
  15589. */
  15590. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","SystemUptimeSec", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SystemUptimeSec].ItemData);
  15591. // FreeVend
  15592. /*
  15593. ShmOCPP16Data->ConfigurationTable.CoreProfile[FreeVend].ItemAccessibility = 1;
  15594. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[FreeVend].ItemName, "FreeVend");
  15595. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[FreeVend].ItemData, "FALSE" );
  15596. */
  15597. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","FreeVend", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[FreeVend].ItemData);
  15598. // FreeVendIdtag
  15599. /*
  15600. ShmOCPP16Data->ConfigurationTable.CoreProfile[FreeVendIdtag].ItemAccessibility = 1;
  15601. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[FreeVendIdtag].ItemName, "FreeVendIdtag");
  15602. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[FreeVendIdtag].ItemData, "FreeVendIdtag" );
  15603. */
  15604. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","FreeVendIdtag", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[FreeVendIdtag].ItemData);
  15605. // OcppServer
  15606. /*
  15607. ShmOCPP16Data->ConfigurationTable.CoreProfile[OcppServer].ItemAccessibility = 1;
  15608. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[OcppServer].ItemName, "OcppServer");
  15609. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[OcppServer].ItemData, "FALSE" );
  15610. */
  15611. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","OcppServer", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[OcppServer].ItemData);
  15612. // MaintainServer
  15613. /*
  15614. ShmOCPP16Data->ConfigurationTable.CoreProfile[MaintainServer].ItemAccessibility = 1;
  15615. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MaintainServer].ItemName, "MaintainServer");
  15616. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MaintainServer].ItemData, "FALSE" );
  15617. */
  15618. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MaintainServer", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MaintainServer].ItemData);
  15619. // StatusNotificationPeriodically
  15620. /*
  15621. ShmOCPP16Data->ConfigurationTable.CoreProfile[StatusNotificationPeriodically].ItemAccessibility =0;
  15622. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StatusNotificationPeriodically].ItemName, "StatusNotificationPeriodically");
  15623. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StatusNotificationPeriodically].ItemData, "FALSE" );
  15624. */
  15625. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StatusNotificationPeriodically", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StatusNotificationPeriodically].ItemData);
  15626. // StatusNotificationInterval
  15627. /*
  15628. ShmOCPP16Data->ConfigurationTable.CoreProfile[StatusNotificationInterval].ItemAccessibility = 1;
  15629. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StatusNotificationInterval].ItemName, "StatusNotificationInterval");
  15630. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StatusNotificationInterval].ItemData, "120" );
  15631. */
  15632. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StatusNotificationInterval", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StatusNotificationInterval].ItemData);
  15633. // PreAuthAmount
  15634. /*
  15635. ShmOCPP16Data->ConfigurationTable.CoreProfile[PreAuthAmount].ItemAccessibility = 1;
  15636. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[PreAuthAmount].ItemName, "PreAuthAmount");
  15637. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[PreAuthAmount].ItemData, "120" );
  15638. */
  15639. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","PreAuthAmount", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[PreAuthAmount].ItemData);
  15640. // isEnableLocalPowerSharing
  15641. /*
  15642. ShmOCPP16Data->ConfigurationTable.CoreProfile[isEnableLocalPowerSharing].ItemAccessibility = 1;
  15643. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[isEnableLocalPowerSharing].ItemName, "isEnableLocalPowerSharing");
  15644. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[isEnableLocalPowerSharing].ItemData, "0" );
  15645. */
  15646. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","isEnableLocalPowerSharing", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[isEnableLocalPowerSharing].ItemData);
  15647. // PowerSharingServerIP
  15648. /*
  15649. ShmOCPP16Data->ConfigurationTable.CoreProfile[PowerSharingServerIP].ItemAccessibility = 1;
  15650. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[PowerSharingServerIP].ItemName, "PowerSharingServerIP");
  15651. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[PowerSharingServerIP].ItemData, "" );
  15652. */
  15653. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","PowerSharingServerIP", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[PowerSharingServerIP].ItemData);
  15654. // EVCCID_PREFIX
  15655. /*
  15656. ShmOCPP16Data->ConfigurationTable.CoreProfile[EVCCID_PREFIX].ItemAccessibility = 1;
  15657. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[EVCCID_PREFIX].ItemName, "EVCCID_PREFIX");
  15658. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[EVCCID_PREFIX].ItemData, "" );
  15659. */
  15660. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","EVCCID_PREFIX", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[EVCCID_PREFIX].ItemData);
  15661. // OffLineMaxChargingPower
  15662. /*
  15663. ShmOCPP16Data->ConfigurationTable.CoreProfile[OffLineMaxChargingPower].ItemAccessibility = 1;
  15664. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[OffLineMaxChargingPower].ItemName, "OffLineMaxChargingPower");
  15665. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[OffLineMaxChargingPower].ItemData, "" );
  15666. */
  15667. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","OffLineMaxChargingPower", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[OffLineMaxChargingPower].ItemData);
  15668. // ConfigurationVersion
  15669. /*
  15670. ShmOCPP16Data->ConfigurationTable.CoreProfile[ConfigurationVersion].ItemAccessibility = 1;
  15671. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConfigurationVersion].ItemName, "ConfigurationVersion");
  15672. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConfigurationVersion].ItemData, "1" );
  15673. */
  15674. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ConfigurationVersion", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConfigurationVersion].ItemData);
  15675. //* Local Auth List Management Profile*/
  15676. //LocalAuthListEnabled
  15677. /*
  15678. ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemAccessibility = 1;
  15679. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemName, "LocalAuthListEnabled");
  15680. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "TRUE" );
  15681. */
  15682. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LocalAuthListEnabled", "false", (char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData);
  15683. //LocalAuthListMaxLength
  15684. /*
  15685. ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemAccessibility = 0;
  15686. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemName, "LocalAuthListMaxLength");
  15687. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemData, "500" );
  15688. */
  15689. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LocalAuthListMaxLength", "true", (char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemData);
  15690. //SendLocalListMaxLength
  15691. /*
  15692. ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemAccessibility = 0;
  15693. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemName, "SendLocalListMaxLength");
  15694. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemData, "500" );
  15695. */
  15696. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","SendLocalListMaxLength", "true", (char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemData);
  15697. //ReserveConnectorZeroSupported
  15698. /*
  15699. ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemAccessibility = 0;
  15700. strcpy((char *)ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemName, "ReserveConnectorZeroSupported");
  15701. strcpy((char *)ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemData, "FALSE" );
  15702. */
  15703. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ReserveConnectorZeroSupported", "true", (char *)ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemData);
  15704. //* Smart Charging Profile */
  15705. //ChargeProfileMaxStackLevel
  15706. /*
  15707. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemAccessibility = 0;
  15708. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemName, "ChargeProfileMaxStackLevel");
  15709. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemData, "3" );
  15710. */
  15711. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ChargeProfileMaxStackLevel", "true", (char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemData);
  15712. // ChargingScheduleAllowedChargingRateUnit
  15713. /*
  15714. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemAccessibility = 0;
  15715. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemName, "ChargingScheduleAllowedChargingRateUnit");
  15716. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemData, "Current" );
  15717. */
  15718. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ChargingScheduleAllowedChargingRateUnit", "true", (char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemData);
  15719. // ChargingScheduleMaxPeriods
  15720. /*
  15721. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemAccessibility = 0;
  15722. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemName, "ChargingScheduleMaxPeriods");
  15723. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemData, "10" );
  15724. */
  15725. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ChargingScheduleMaxPeriods", "true", (char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemData);
  15726. // ConnectorSwitch3to1PhaseSupported
  15727. /*
  15728. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemAccessibility = 0;
  15729. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemName, "ConnectorSwitch3to1PhaseSupported");
  15730. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemData, "TRUE" );
  15731. */
  15732. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ConnectorSwitch3to1PhaseSupported", "true", (char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemData);
  15733. // MaxChargingProfilesInstalled
  15734. /*
  15735. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemAccessibility = 0;
  15736. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemName, "MaxChargingProfilesInstalled");
  15737. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemData, "10" );
  15738. */
  15739. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MaxChargingProfilesInstalled", "true", (char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemData);
  15740. fclose(outfile);
  15741. system("/bin/fsync -d /dev/mtdblock13;/bin/sync &");
  15742. }
  15743. void getKeyValue(char *keyReq)
  15744. {
  15745. int isEmpty = FALSE;
  15746. int isKnowKey = FALSE;
  15747. DEBUG_INFO("keyReq = %s\n", keyReq);
  15748. if((keyReq == NULL) || (strlen(keyReq) == 0))
  15749. isEmpty = TRUE;
  15750. if(isEmpty || strcmp(keyReq, "AllowOfflineTxForUnknownId") == 0)
  15751. {
  15752. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_AllowOfflineTxForUnknownId].Item, "AllowOfflineTxForUnknownId");
  15753. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AllowOfflineTxForUnknownId].Key, "AllowOfflineTxForUnknownId");
  15754. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemAccessibility == 1)
  15755. {
  15756. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AllowOfflineTxForUnknownId].ReadOnly, "0"/*"FALSE"*/);
  15757. }
  15758. else
  15759. {
  15760. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AllowOfflineTxForUnknownId].ReadOnly, "1"/*"TRUE"*/);
  15761. }
  15762. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AllowOfflineTxForUnknownId].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemData );
  15763. isKnowKey = TRUE;
  15764. }
  15765. if(isEmpty || strcmp(keyReq, "AuthorizationCacheEnabled") == 0 )
  15766. {
  15767. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_AuthorizationCacheEnabled].Item, "AuthorizationCacheEnabled");
  15768. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizationCacheEnabled].Key, "AuthorizationCacheEnabled");
  15769. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemAccessibility == 1)
  15770. {
  15771. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizationCacheEnabled].ReadOnly, "0"/*"FALSE"*/);
  15772. }
  15773. else
  15774. {
  15775. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizationCacheEnabled].ReadOnly, "1"/*"TRUE"*/);
  15776. }
  15777. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizationCacheEnabled].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemData );
  15778. isKnowKey = TRUE;
  15779. }
  15780. if(isEmpty || strcmp(keyReq, "AuthorizeRemoteTxRequests") == 0 )
  15781. {
  15782. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_AuthorizeRemoteTxRequests].Item, "AuthorizeRemoteTxRequests");
  15783. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizeRemoteTxRequests].Key, "AuthorizeRemoteTxRequests");
  15784. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemAccessibility == 1)
  15785. {
  15786. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizeRemoteTxRequests].ReadOnly, "0"/*"FALSE"*/);
  15787. }
  15788. else
  15789. {
  15790. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizeRemoteTxRequests].ReadOnly, "1"/*"TRUE"*/);
  15791. }
  15792. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizeRemoteTxRequests].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemData );
  15793. isKnowKey = TRUE;
  15794. }
  15795. if(isEmpty || strcmp(keyReq, "BlinkRepeat") == 0 )
  15796. {
  15797. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_BlinkRepeat].Item, "BlinkRepeat");
  15798. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_BlinkRepeat].Key, "BlinkRepeat");
  15799. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemAccessibility == 1)
  15800. {
  15801. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_BlinkRepeat].ReadOnly, "0"/*"FALSE"*/);
  15802. }
  15803. else
  15804. {
  15805. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_BlinkRepeat].ReadOnly, "1"/*"TRUE"*/);
  15806. }
  15807. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_BlinkRepeat].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemData );
  15808. isKnowKey = TRUE;
  15809. }
  15810. if(isEmpty || strcmp(keyReq, "ClockAlignedDataInterval") == 0 )
  15811. {
  15812. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_ClockAlignedDataInterval].Item, "ClockAlignedDataInterval");
  15813. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ClockAlignedDataInterval].Key, "ClockAlignedDataInterval");
  15814. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemAccessibility == 1)
  15815. {
  15816. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ClockAlignedDataInterval].ReadOnly, "0"/*"FALSE"*/);
  15817. }
  15818. else
  15819. {
  15820. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ClockAlignedDataInterval].ReadOnly, "1"/*"TRUE"*/);
  15821. }
  15822. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ClockAlignedDataInterval].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemData );
  15823. isKnowKey = TRUE;
  15824. }
  15825. if(isEmpty || strcmp(keyReq, "ConnectionTimeOut") == 0 )
  15826. {
  15827. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_ConnectionTimeOut].Item, "ConnectionTimeOut");
  15828. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectionTimeOut].Key, "ConnectionTimeOut");
  15829. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemAccessibility == 1)
  15830. {
  15831. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectionTimeOut].ReadOnly, "0"/*"FALSE"*/);
  15832. }
  15833. else
  15834. {
  15835. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectionTimeOut].ReadOnly, "1"/*"TRUE"*/);
  15836. }
  15837. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectionTimeOut].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemData );
  15838. isKnowKey = TRUE;
  15839. }
  15840. if(isEmpty || strcmp(keyReq, "GetConfigurationMaxKeys") == 0 )
  15841. {
  15842. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_GetConfigurationMaxKeys].Item, "GetConfigurationMaxKeys");
  15843. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_GetConfigurationMaxKeys].Key, "GetConfigurationMaxKeys");
  15844. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemAccessibility == 1)
  15845. {
  15846. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_GetConfigurationMaxKeys].ReadOnly, "0"/*"FALSE"*/);
  15847. }
  15848. else
  15849. {
  15850. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_GetConfigurationMaxKeys].ReadOnly, "1"/*"TRUE"*/);
  15851. }
  15852. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_GetConfigurationMaxKeys].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemData );
  15853. isKnowKey = TRUE;
  15854. }
  15855. if(isEmpty || strcmp(keyReq, "HeartbeatInterval") == 0 )
  15856. {
  15857. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_HeartbeatInterval].Item, "HeartbeatInterval");
  15858. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_HeartbeatInterval].Key, "HeartbeatInterval");
  15859. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemAccessibility == 1)
  15860. {
  15861. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_HeartbeatInterval].ReadOnly, "0"/*"FALSE"*/);
  15862. }
  15863. else
  15864. {
  15865. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_HeartbeatInterval].ReadOnly, "1"/*"TRUE"*/);
  15866. }
  15867. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_HeartbeatInterval].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemData );
  15868. isKnowKey = TRUE;
  15869. }
  15870. if(isEmpty || strcmp(keyReq, "LightIntensity") == 0 )
  15871. {
  15872. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_LightIntensity].Item, "LightIntensity");
  15873. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LightIntensity].Key, "LightIntensity");
  15874. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemAccessibility == 1)
  15875. {
  15876. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LightIntensity].ReadOnly, "0"/*"FALSE"*/);
  15877. }
  15878. else
  15879. {
  15880. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LightIntensity].ReadOnly, "1"/*"TRUE"*/);
  15881. }
  15882. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LightIntensity].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemData );
  15883. isKnowKey = TRUE;
  15884. }
  15885. if(isEmpty || strcmp(keyReq, "LocalAuthorizeOffline") == 0 )
  15886. {
  15887. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_LocalAuthorizeOffline].Item, "LocalAuthorizeOffline");
  15888. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthorizeOffline].Key, "LocalAuthorizeOffline");
  15889. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemAccessibility == 1)
  15890. {
  15891. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthorizeOffline].ReadOnly, "0"/*"FALSE"*/);
  15892. }
  15893. else
  15894. {
  15895. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthorizeOffline].ReadOnly, "1"/*"TRUE"*/);
  15896. }
  15897. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthorizeOffline].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemData );
  15898. isKnowKey = TRUE;
  15899. }
  15900. if(isEmpty || strcmp(keyReq, "LocalPreAuthorize") == 0 )
  15901. {
  15902. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_LocalPreAuthorize].Item, "LocalPreAuthorize");
  15903. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalPreAuthorize].Key, "LocalPreAuthorize");
  15904. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemAccessibility == 1)
  15905. {
  15906. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalPreAuthorize].ReadOnly, "0"/*"FALSE"*/);
  15907. }
  15908. else
  15909. {
  15910. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalPreAuthorize].ReadOnly, "1"/*"TRUE"*/);
  15911. }
  15912. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalPreAuthorize].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemData );
  15913. isKnowKey = TRUE;
  15914. }
  15915. if(isEmpty || strcmp(keyReq, "MaxEnergyOnInvalidId") == 0 )
  15916. {
  15917. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_MaxEnergyOnInvalidId].Item, "MaxEnergyOnInvalidId");
  15918. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaxEnergyOnInvalidId].Key, "MaxEnergyOnInvalidId");
  15919. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemAccessibility == 1)
  15920. {
  15921. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaxEnergyOnInvalidId].ReadOnly, "0"/*"FALSE"*/);
  15922. }
  15923. else
  15924. {
  15925. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaxEnergyOnInvalidId].ReadOnly, "1"/*"TRUE"*/);
  15926. }
  15927. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaxEnergyOnInvalidId].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemData );
  15928. isKnowKey = TRUE;
  15929. }
  15930. if(isEmpty || strcmp(keyReq, "MeterValuesAlignedData") == 0 )
  15931. {
  15932. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_MeterValuesAlignedData].Item, "MeterValuesAlignedData");
  15933. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesAlignedData].Key, "MeterValuesAlignedData");
  15934. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemAccessibility == 1)
  15935. {
  15936. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesAlignedData].ReadOnly, "0"/*"FALSE"*/);
  15937. }
  15938. else
  15939. {
  15940. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesAlignedData].ReadOnly, "1"/*"TRUE"*/);
  15941. }
  15942. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesAlignedData].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData );
  15943. isKnowKey = TRUE;
  15944. }
  15945. if(isEmpty || strcmp(keyReq, "MeterValuesAlignedDataMaxLength") == 0 )
  15946. {
  15947. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_MeterValuesAlignedDataMaxLength].Item, "MeterValuesAlignedDataMaxLength");
  15948. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesAlignedDataMaxLength].Key, "MeterValuesAlignedDataMaxLength");
  15949. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemAccessibility == 1)
  15950. {
  15951. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesAlignedDataMaxLength].ReadOnly, "0"/*"FALSE"*/);
  15952. }
  15953. else
  15954. {
  15955. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesAlignedDataMaxLength].ReadOnly, "1"/*"TRUE"*/);
  15956. }
  15957. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesAlignedDataMaxLength].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemData );
  15958. isKnowKey = TRUE;
  15959. }
  15960. if(isEmpty || strcmp(keyReq, "MeterValuesSampledData") == 0 )
  15961. {
  15962. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_MeterValuesSampledData].Item, "MeterValuesSampledData");
  15963. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesSampledData].Key, "MeterValuesSampledData");
  15964. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemAccessibility == 1)
  15965. {
  15966. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesSampledData].ReadOnly, "0"/*"FALSE"*/);
  15967. }
  15968. else
  15969. {
  15970. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesSampledData].ReadOnly, "1"/*"TRUE"*/);
  15971. }
  15972. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesSampledData].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData );
  15973. isKnowKey = TRUE;
  15974. }
  15975. if(isEmpty || strcmp(keyReq, "MeterValuesSampledDataMaxLength") == 0 )
  15976. {
  15977. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_MeterValuesSampledDataMaxLength].Item, "MeterValuesSampledDataMaxLength");
  15978. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesSampledDataMaxLength].Key, "MeterValuesSampledDataMaxLength");
  15979. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemAccessibility == 1)
  15980. {
  15981. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesSampledDataMaxLength].ReadOnly, "0"/*"FALSE"*/);
  15982. }
  15983. else
  15984. {
  15985. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesSampledDataMaxLength].ReadOnly, "1"/*"TRUE"*/);
  15986. }
  15987. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesSampledDataMaxLength].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemData );
  15988. isKnowKey = TRUE;
  15989. }
  15990. if(isEmpty || strcmp(keyReq, "MeterValueSampleInterval") == 0 )
  15991. {
  15992. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_MeterValueSampleInterval].Item, "MeterValueSampleInterval");
  15993. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValueSampleInterval].Key, "MeterValueSampleInterval");
  15994. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemAccessibility == 1)
  15995. {
  15996. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValueSampleInterval].ReadOnly, "0"/*"FALSE"*/);
  15997. }
  15998. else
  15999. {
  16000. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValueSampleInterval].ReadOnly, "1"/*"TRUE"*/);
  16001. }
  16002. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValueSampleInterval].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemData );
  16003. isKnowKey = TRUE;
  16004. }
  16005. if(isEmpty || strcmp(keyReq, "MinimumStatusDuration") == 0 )
  16006. {
  16007. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_MinimumStatusDuration].Item, "MinimumStatusDuration");
  16008. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MinimumStatusDuration].Key, "MinimumStatusDuration");
  16009. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemAccessibility == 1)
  16010. {
  16011. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MinimumStatusDuration].ReadOnly, "0"/*"FALSE"*/);
  16012. }
  16013. else
  16014. {
  16015. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MinimumStatusDuration].ReadOnly, "1"/*"TRUE"*/);
  16016. }
  16017. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MinimumStatusDuration].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[17].ItemData );
  16018. isKnowKey = TRUE;
  16019. }
  16020. if(isEmpty || strcmp(keyReq, "NumberOfConnectors") == 0 )
  16021. {
  16022. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_NumberOfConnectors].Item, "NumberOfConnectors");
  16023. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_NumberOfConnectors].Key, "NumberOfConnectors");
  16024. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemAccessibility == 1)
  16025. {
  16026. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_NumberOfConnectors].ReadOnly, "0"/*"FALSE"*/);
  16027. }
  16028. else
  16029. {
  16030. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_NumberOfConnectors].ReadOnly, "1"/*"TRUE"*/);
  16031. }
  16032. sprintf((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData, "%d", gunTotalNumber);
  16033. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_NumberOfConnectors].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData );
  16034. isKnowKey = TRUE;
  16035. }
  16036. if(isEmpty || strcmp(keyReq, "ResetRetries") == 0 )
  16037. {
  16038. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_ResetRetries].Item, "ResetRetries");
  16039. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ResetRetries].Key, "ResetRetries");
  16040. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemAccessibility == 1)
  16041. {
  16042. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ResetRetries].ReadOnly, "0"/*"FALSE"*/);
  16043. }
  16044. else
  16045. {
  16046. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ResetRetries].ReadOnly, "1"/*"TRUE"*/);
  16047. }
  16048. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ResetRetries].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemData );
  16049. isKnowKey = TRUE;
  16050. }
  16051. if(isEmpty || strcmp(keyReq, "ConnectorPhaseRotation") == 0 )
  16052. {
  16053. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_ConnectorPhaseRotation].Item, "ConnectorPhaseRotation");
  16054. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorPhaseRotation].Key, "ConnectorPhaseRotation");
  16055. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemAccessibility == 1)
  16056. {
  16057. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorPhaseRotation].ReadOnly, "0"/*"FALSE"*/);
  16058. }
  16059. else
  16060. {
  16061. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorPhaseRotation].ReadOnly, "1"/*"TRUE"*/);
  16062. }
  16063. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorPhaseRotation].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData );
  16064. isKnowKey = TRUE;
  16065. }
  16066. if(isEmpty || strcmp(keyReq, "ConnectorPhaseRotationMaxLength") == 0 )
  16067. {
  16068. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_ConnectorPhaseRotationMaxLength].Item, "ConnectorPhaseRotationMaxLength");
  16069. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorPhaseRotationMaxLength].Key, "ConnectorPhaseRotationMaxLength");
  16070. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemAccessibility == 1)
  16071. {
  16072. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorPhaseRotationMaxLength].ReadOnly, "0"/*"FALSE"*/);
  16073. }
  16074. else
  16075. {
  16076. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorPhaseRotationMaxLength].ReadOnly, "1"/*"TRUE"*/);
  16077. }
  16078. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorPhaseRotationMaxLength].Value,(const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemData );
  16079. isKnowKey = TRUE;
  16080. }
  16081. if(isEmpty || strcmp(keyReq, "StopTransactionOnEVSideDisconnect") == 0 )
  16082. {
  16083. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_StopTransactionOnEVSideDisconnect].Item, "StopTransactionOnEVSideDisconnect");
  16084. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTransactionOnEVSideDisconnect].Key, "StopTransactionOnEVSideDisconnect");
  16085. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemAccessibility == 1)
  16086. {
  16087. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTransactionOnEVSideDisconnect].ReadOnly, "0"/*"FALSE"*/);
  16088. }
  16089. else
  16090. {
  16091. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTransactionOnEVSideDisconnect].ReadOnly, "1"/*"TRUE"*/);
  16092. }
  16093. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTransactionOnEVSideDisconnect].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemData );
  16094. isKnowKey = TRUE;
  16095. }
  16096. if(isEmpty || strcmp(keyReq, "StopTransactionOnInvalidId") == 0 )
  16097. {
  16098. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_StopTransactionOnInvalidId].Item, "StopTransactionOnInvalidId");
  16099. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTransactionOnInvalidId].Key, "StopTransactionOnInvalidId");
  16100. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemAccessibility == 1)
  16101. {
  16102. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTransactionOnInvalidId].ReadOnly, "0"/*"FALSE"*/);
  16103. }
  16104. else
  16105. {
  16106. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTransactionOnInvalidId].ReadOnly, "1"/*"TRUE"*/);
  16107. }
  16108. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTransactionOnInvalidId].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemData );
  16109. isKnowKey = TRUE;
  16110. }
  16111. if(isEmpty || strcmp(keyReq, "StopTxnAlignedData") == 0 )
  16112. {
  16113. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_StopTxnAlignedData].Item, "StopTxnAlignedData");
  16114. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnAlignedData].Key, "StopTxnAlignedData");
  16115. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemAccessibility == 1)
  16116. {
  16117. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnAlignedData].ReadOnly, "0"/*"FALSE"*/);
  16118. }
  16119. else
  16120. {
  16121. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnAlignedData].ReadOnly, "1"/*"TRUE"*/);
  16122. }
  16123. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnAlignedData].Value,(const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemData );
  16124. isKnowKey = TRUE;
  16125. }
  16126. if(isEmpty || strcmp(keyReq, "StopTxnAlignedDataMaxLength") == 0 )
  16127. {
  16128. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_StopTxnAlignedDataMaxLength].Item, "StopTxnAlignedDataMaxLength");
  16129. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnAlignedDataMaxLength].Key, "StopTxnAlignedDataMaxLength");
  16130. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemAccessibility == 1)
  16131. {
  16132. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnAlignedDataMaxLength].ReadOnly, "0"/*"FALSE"*/);
  16133. }
  16134. else
  16135. {
  16136. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnAlignedDataMaxLength].ReadOnly, "1"/*"TRUE"*/);
  16137. }
  16138. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnAlignedDataMaxLength].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemData );
  16139. isKnowKey = TRUE;
  16140. }
  16141. if(isEmpty || strcmp(keyReq, "StopTxnSampledData") == 0 )
  16142. {
  16143. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_StopTxnSampledData].Item, "StopTxnSampledData");
  16144. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnSampledData].Key, "StopTxnSampledData");
  16145. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemAccessibility == 1)
  16146. {
  16147. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnSampledData].ReadOnly, "0"/*"FALSE"*/);
  16148. }
  16149. else
  16150. {
  16151. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnSampledData].ReadOnly, "1"/*"TRUE"*/);
  16152. }
  16153. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnSampledData].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData );
  16154. isKnowKey = TRUE;
  16155. }
  16156. if(isEmpty || strcmp(keyReq, "StopTxnSampledDataMaxLength") == 0 )
  16157. {
  16158. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_StopTxnSampledDataMaxLength].Item, "StopTxnSampledDataMaxLength");
  16159. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnSampledDataMaxLength].Key, "StopTxnSampledDataMaxLength");
  16160. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemAccessibility == 1)
  16161. {
  16162. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnSampledDataMaxLength].ReadOnly, "0"/*"FALSE"*/);
  16163. }
  16164. else
  16165. {
  16166. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnSampledDataMaxLength].ReadOnly, "1"/*"TRUE"*/);
  16167. }
  16168. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnSampledDataMaxLength].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemData );
  16169. isKnowKey = TRUE;
  16170. }
  16171. if(isEmpty || strcmp(keyReq, "SupportedFeatureProfiles") == 0 )
  16172. {
  16173. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_SupportedFeatureProfiles].Item, "SupportedFeatureProfiles");
  16174. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SupportedFeatureProfiles].Key, "SupportedFeatureProfiles");
  16175. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemAccessibility == 1)
  16176. {
  16177. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SupportedFeatureProfiles].ReadOnly, "0"/*"FALSE"*/);
  16178. }
  16179. else
  16180. {
  16181. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SupportedFeatureProfiles].ReadOnly, "1"/*"TRUE"*/);
  16182. }
  16183. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SupportedFeatureProfiles].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemData );
  16184. isKnowKey = TRUE;
  16185. }
  16186. if(isEmpty || strcmp(keyReq, "SupportedFeatureProfilesMaxLength") == 0 )
  16187. {
  16188. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_SupportedFeatureProfilesMaxLength].Item, "SupportedFeatureProfilesMaxLength");
  16189. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SupportedFeatureProfilesMaxLength].Key, "SupportedFeatureProfilesMaxLength");
  16190. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemAccessibility == 1)
  16191. {
  16192. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SupportedFeatureProfilesMaxLength].ReadOnly, "0"/*"FALSE"*/);
  16193. }
  16194. else
  16195. {
  16196. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SupportedFeatureProfilesMaxLength].ReadOnly, "1"/*"TRUE"*/);
  16197. }
  16198. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SupportedFeatureProfilesMaxLength].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemData );
  16199. isKnowKey = TRUE;
  16200. }
  16201. if(isEmpty || strcmp(keyReq, "TransactionMessageAttempts") == 0 )
  16202. {
  16203. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_TransactionMessageAttempts].Item, "TransactionMessageAttempts");
  16204. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TransactionMessageAttempts].Key, "TransactionMessageAttempts");
  16205. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemAccessibility == 1)
  16206. {
  16207. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TransactionMessageAttempts].ReadOnly, "0"/*"FALSE"*/);
  16208. }
  16209. else
  16210. {
  16211. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TransactionMessageAttempts].ReadOnly, "1"/*"TRUE"*/);
  16212. }
  16213. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TransactionMessageAttempts].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData );
  16214. isKnowKey = TRUE;
  16215. }
  16216. if(isEmpty || strcmp(keyReq, "TransactionMessageRetryInterval") == 0 )
  16217. {
  16218. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_TransactionMessageRetryInterval].Item, "TransactionMessageRetryInterval");
  16219. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TransactionMessageRetryInterval].Key, "TransactionMessageRetryInterval");
  16220. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemAccessibility == 1)
  16221. {
  16222. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TransactionMessageRetryInterval].ReadOnly, "0"/*"FALSE"*/);
  16223. }
  16224. else
  16225. {
  16226. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TransactionMessageRetryInterval].ReadOnly, "1"/*"TRUE"*/);
  16227. }
  16228. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TransactionMessageRetryInterval].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData );
  16229. isKnowKey = TRUE;
  16230. }
  16231. if(isEmpty || strcmp(keyReq, "UnlockConnectorOnEVSideDisconnect") == 0 )
  16232. {
  16233. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_UnlockConnectorOnEVSideDisconnect].Item, "UnlockConnectorOnEVSideDisconnect");
  16234. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_UnlockConnectorOnEVSideDisconnect].Key, "UnlockConnectorOnEVSideDisconnect");
  16235. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemAccessibility == 1)
  16236. {
  16237. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_UnlockConnectorOnEVSideDisconnect].ReadOnly, "0"/*"FALSE"*/);
  16238. }
  16239. else
  16240. {
  16241. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_UnlockConnectorOnEVSideDisconnect].ReadOnly, "1"/*"TRUE"*/);
  16242. }
  16243. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_UnlockConnectorOnEVSideDisconnect].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemData );
  16244. isKnowKey = TRUE;
  16245. }
  16246. if(isEmpty || strcmp(keyReq, "WebSocketPingInterval") == 0 )
  16247. {
  16248. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_WebSocketPingInterval].Item, "WebSocketPingInterval");
  16249. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_WebSocketPingInterval].Key, "WebSocketPingInterval");
  16250. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemAccessibility == 1)
  16251. {
  16252. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_WebSocketPingInterval].ReadOnly, "0"/*"FALSE"*/);
  16253. }
  16254. else
  16255. {
  16256. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_WebSocketPingInterval].ReadOnly, "1"/*"TRUE"*/);
  16257. }
  16258. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_WebSocketPingInterval].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemData );
  16259. isKnowKey = TRUE;
  16260. }
  16261. if(isEmpty || strcmp(keyReq, "QueueOffLineMeterValues") == 0 )
  16262. {
  16263. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_QueueOffLineMeterValues].Item, "QueueOffLineMeterValues");
  16264. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_QueueOffLineMeterValues].Key, "QueueOffLineMeterValues");
  16265. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[QueueOffLineMeterValues].ItemAccessibility == 1)
  16266. {
  16267. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_QueueOffLineMeterValues].ReadOnly, "0"/*"FALSE"*/);
  16268. }
  16269. else
  16270. {
  16271. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_QueueOffLineMeterValues].ReadOnly, "1"/*"TRUE"*/);
  16272. }
  16273. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_QueueOffLineMeterValues].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[QueueOffLineMeterValues].ItemData );
  16274. isKnowKey = TRUE;
  16275. }
  16276. /*
  16277. if(isEmpty || strcmp(keyReq, "AuthorizationKey") == 0 )
  16278. {
  16279. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_AuthorizationKey].Item, "AuthorizationKey");
  16280. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizationKey].Key, "AuthorizationKey");
  16281. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationKey].ItemAccessibility == 1)
  16282. {
  16283. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizationKey].ReadOnly, "0");
  16284. }
  16285. else
  16286. {
  16287. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizationKey].ReadOnly, "1");
  16288. }
  16289. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizationKey].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationKey].ItemData );
  16290. isKnowKey = TRUE;
  16291. }*/
  16292. if(isEmpty || strcmp(keyReq, "SecurityProfile") == 0 )
  16293. {
  16294. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_SecurityProfile].Item, "SecurityProfile");
  16295. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SecurityProfile].Key, "SecurityProfile");
  16296. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[SecurityProfile].ItemAccessibility == 1)
  16297. {
  16298. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SecurityProfile].ReadOnly, "0"/*"FALSE"*/);
  16299. }
  16300. else
  16301. {
  16302. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SecurityProfile].ReadOnly, "1"/*"TRUE"*/);
  16303. }
  16304. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SecurityProfile].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SecurityProfile].ItemData );
  16305. isKnowKey = TRUE;
  16306. }
  16307. if(isEmpty || strcmp(keyReq, "DefaultPrice") == 0 )
  16308. {
  16309. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_DefaultPrice].Item, "DefaultPrice");
  16310. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_DefaultPrice].Key, "DefaultPrice");
  16311. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[DefaultPrice].ItemAccessibility == 1)
  16312. {
  16313. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_DefaultPrice].ReadOnly, "0"/*"FALSE"*/);
  16314. }
  16315. else
  16316. {
  16317. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_DefaultPrice].ReadOnly, "1"/*"TRUE"*/);
  16318. }
  16319. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_DefaultPrice].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[DefaultPrice].ItemData );
  16320. isKnowKey = TRUE;
  16321. }
  16322. if(isEmpty || strcmp(keyReq, "CustomDisplayCostAndPrice") == 0 )
  16323. {
  16324. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_CustomDisplayCostAndPrice].Item, "CustomDisplayCostAndPrice");
  16325. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_CustomDisplayCostAndPrice].Key, "CustomDisplayCostAndPrice");
  16326. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemAccessibility == 1)
  16327. {
  16328. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_CustomDisplayCostAndPrice].ReadOnly, "0"/*"FALSE"*/);
  16329. }
  16330. else
  16331. {
  16332. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_CustomDisplayCostAndPrice].ReadOnly, "1"/*"TRUE"*/);
  16333. }
  16334. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_CustomDisplayCostAndPrice].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemData );
  16335. isKnowKey = TRUE;
  16336. }
  16337. if(isEmpty || strcmp(keyReq, "CustomIdleFeeAfterStop") == 0 )
  16338. {
  16339. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_CustomIdleFeeAfterStop].Item, "CustomIdleFeeAfterStop");
  16340. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_CustomIdleFeeAfterStop].Key, "CustomIdleFeeAfterStop");
  16341. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemAccessibility == 1)
  16342. {
  16343. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_CustomIdleFeeAfterStop].ReadOnly, "0"/*"FALSE"*/);
  16344. }
  16345. else
  16346. {
  16347. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_CustomIdleFeeAfterStop].ReadOnly, "1"/*"TRUE"*/);
  16348. }
  16349. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_CustomIdleFeeAfterStop].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemData );
  16350. isKnowKey = TRUE;
  16351. }
  16352. if(isEmpty || strcmp(keyReq, "TimeOffset") == 0 )
  16353. {
  16354. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_TimeOffset].Item, "TimeOffset");
  16355. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TimeOffset].Key, "TimeOffset");
  16356. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffset].ItemAccessibility == 1)
  16357. {
  16358. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TimeOffset].ReadOnly, "0"/*"FALSE"*/);
  16359. }
  16360. else
  16361. {
  16362. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TimeOffset].ReadOnly, "1"/*"TRUE"*/);
  16363. }
  16364. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TimeOffset].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffset].ItemData );
  16365. isKnowKey = TRUE;
  16366. }
  16367. if(isEmpty || strcmp(keyReq, "NextTimeOffsetTransitionDateTime") == 0 )
  16368. {
  16369. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_NextTimeOffsetTransitionDateTime].Item, "NextTimeOffsetTransitionDateTime");
  16370. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_NextTimeOffsetTransitionDateTime].Key, "NextTimeOffsetTransitionDateTime");
  16371. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[NextTimeOffsetTransitionDateTime].ItemAccessibility == 1)
  16372. {
  16373. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_NextTimeOffsetTransitionDateTime].ReadOnly, "0"/*"FALSE"*/);
  16374. }
  16375. else
  16376. {
  16377. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_NextTimeOffsetTransitionDateTime].ReadOnly, "1"/*"TRUE"*/);
  16378. }
  16379. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_NextTimeOffsetTransitionDateTime].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NextTimeOffsetTransitionDateTime].ItemData );
  16380. isKnowKey = TRUE;
  16381. }
  16382. if(isEmpty || strcmp(keyReq, "TimeOffsetNextTransition") == 0 )
  16383. {
  16384. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_TimeOffsetNextTransition].Item, "TimeOffsetNextTransition");
  16385. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TimeOffsetNextTransition].Key, "TimeOffsetNextTransition");
  16386. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffsetNextTransition].ItemAccessibility == 1)
  16387. {
  16388. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TimeOffsetNextTransition].ReadOnly, "0"/*"FALSE"*/);
  16389. }
  16390. else
  16391. {
  16392. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TimeOffsetNextTransition].ReadOnly, "1"/*"TRUE"*/);
  16393. }
  16394. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TimeOffsetNextTransition].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffsetNextTransition].ItemData );
  16395. isKnowKey = TRUE;
  16396. }
  16397. if(isEmpty || strcmp(keyReq, "SystemUptimeSec") == 0 )
  16398. {
  16399. struct sysinfo s_info;
  16400. int error = sysinfo(&s_info);
  16401. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_SystemUptimeSec].Item, "SystemUptimeSec");
  16402. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SystemUptimeSec].Key, "SystemUptimeSec");
  16403. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[SystemUptimeSec].ItemAccessibility == 1)
  16404. {
  16405. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SystemUptimeSec].ReadOnly, "0"/*"FALSE"*/);
  16406. }
  16407. else
  16408. {
  16409. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SystemUptimeSec].ReadOnly, "1"/*"TRUE"*/);
  16410. }
  16411. if(error != 0)
  16412. {
  16413. DEBUG_WARN("System uptime get error: %d\n", error);
  16414. }
  16415. else
  16416. {
  16417. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SystemUptimeSec].ItemData, "%ld", s_info.uptime);
  16418. sprintf((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SystemUptimeSec].Value, "%ld", s_info.uptime);
  16419. }
  16420. isKnowKey = TRUE;
  16421. }
  16422. if(isEmpty || strcmp(keyReq, "FreeVend") == 0 )
  16423. {
  16424. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_FreeVend].Item, "FreeVend");
  16425. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_FreeVend].Key, "FreeVend");
  16426. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[FreeVend].ItemAccessibility == 1)
  16427. {
  16428. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_FreeVend].ReadOnly, "0"/*"FALSE"*/);
  16429. }
  16430. else
  16431. {
  16432. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_FreeVend].ReadOnly, "1"/*"TRUE"*/);
  16433. }
  16434. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_FreeVend].Value, (ShmSysConfigAndInfo->SysConfig.AuthorisationMode?"TRUE":"FALSE"));
  16435. isKnowKey = TRUE;
  16436. }
  16437. if(isEmpty || strcmp(keyReq, "FreeVendIdtag") == 0 )
  16438. {
  16439. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_FreeVendIdtag].Item, "FreeVendIdtag");
  16440. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_FreeVendIdtag].Key, "FreeVendIdtag");
  16441. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[FreeVendIdtag].ItemAccessibility == 1)
  16442. {
  16443. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_FreeVendIdtag].ReadOnly, "0"/*"FALSE"*/);
  16444. }
  16445. else
  16446. {
  16447. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_FreeVendIdtag].ReadOnly, "1"/*"TRUE"*/);
  16448. }
  16449. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_FreeVendIdtag].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[FreeVendIdtag].ItemData);
  16450. isKnowKey = TRUE;
  16451. }
  16452. if(isEmpty || strcmp(keyReq, "OcppServer") == 0 )
  16453. {
  16454. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_OcppServer].Item, "OcppServer");
  16455. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_OcppServer].Key, "OcppServer");
  16456. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[OcppServer].ItemAccessibility == 1)
  16457. {
  16458. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_OcppServer].ReadOnly, "0"/*"FALSE"*/);
  16459. }
  16460. else
  16461. {
  16462. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_OcppServer].ReadOnly, "1"/*"TRUE"*/);
  16463. }
  16464. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_OcppServer].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[OcppServer].ItemData);
  16465. isKnowKey = TRUE;
  16466. }
  16467. if(isEmpty || strcmp(keyReq, "MaintainServer") == 0 )
  16468. {
  16469. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_MaintainServer].Item, "MaintainServer");
  16470. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaintainServer].Key, "MaintainServer");
  16471. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MaintainServer].ItemAccessibility == 1)
  16472. {
  16473. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaintainServer].ReadOnly, "0"/*"FALSE"*/);
  16474. }
  16475. else
  16476. {
  16477. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaintainServer].ReadOnly, "1"/*"TRUE"*/);
  16478. }
  16479. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaintainServer].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MaintainServer].ItemData);
  16480. isKnowKey = TRUE;
  16481. }
  16482. if(isEmpty || strcmp(keyReq, "StatusNotificationPeriodically") == 0 )
  16483. {
  16484. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_StatusNotificationPeriodically].Item, "StatusNotificationPeriodically");
  16485. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StatusNotificationPeriodically].Key, "StatusNotificationPeriodically");
  16486. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StatusNotificationPeriodically].ItemAccessibility == 1)
  16487. {
  16488. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StatusNotificationPeriodically].ReadOnly, "0"/*"FALSE"*/);
  16489. }
  16490. else
  16491. {
  16492. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StatusNotificationPeriodically].ReadOnly, "1"/*"TRUE"*/);
  16493. }
  16494. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StatusNotificationPeriodically].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StatusNotificationPeriodically].ItemData );
  16495. isKnowKey = TRUE;
  16496. }
  16497. if(isEmpty || strcmp(keyReq, "StatusNotificationInterval") == 0 )
  16498. {
  16499. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_StatusNotificationInterval].Item, "StatusNotificationInterval");
  16500. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StatusNotificationInterval].Key, "StatusNotificationInterval");
  16501. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StatusNotificationInterval].ItemAccessibility == 1)
  16502. {
  16503. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StatusNotificationInterval].ReadOnly, "0"/*"FALSE"*/);
  16504. }
  16505. else
  16506. {
  16507. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StatusNotificationInterval].ReadOnly, "1"/*"TRUE"*/);
  16508. }
  16509. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StatusNotificationInterval].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StatusNotificationInterval].ItemData );
  16510. isKnowKey = TRUE;
  16511. }
  16512. if(isEmpty || strcmp(keyReq, "PreAuthAmount") == 0 )
  16513. {
  16514. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_PreAuthAmount].Item, "PreAuthAmount");
  16515. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_PreAuthAmount].Key, "PreAuthAmount");
  16516. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[PreAuthAmount].ItemAccessibility == 1)
  16517. {
  16518. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_PreAuthAmount].ReadOnly, "0"/*"FALSE"*/);
  16519. }
  16520. else
  16521. {
  16522. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_PreAuthAmount].ReadOnly, "1"/*"TRUE"*/);
  16523. }
  16524. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_PreAuthAmount].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[PreAuthAmount].ItemData );
  16525. isKnowKey = TRUE;
  16526. }
  16527. if(isEmpty || strcmp(keyReq, "isEnableLocalPowerSharing") == 0 )
  16528. {
  16529. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_isEnableLocalPowerSharing].Item, "isEnableLocalPowerSharing");
  16530. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_isEnableLocalPowerSharing].Key, "isEnableLocalPowerSharing");
  16531. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[isEnableLocalPowerSharing].ItemAccessibility == 1)
  16532. {
  16533. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_isEnableLocalPowerSharing].ReadOnly, "0"/*"FALSE"*/);
  16534. }
  16535. else
  16536. {
  16537. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_isEnableLocalPowerSharing].ReadOnly, "1"/*"TRUE"*/);
  16538. }
  16539. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_isEnableLocalPowerSharing].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[isEnableLocalPowerSharing].ItemData );
  16540. isKnowKey = TRUE;
  16541. }
  16542. if(isEmpty || strcmp(keyReq, "PowerSharingServerIP") == 0 )
  16543. {
  16544. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_PowerSharingServerIP].Item, "PowerSharingServerIP");
  16545. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_PowerSharingServerIP].Key, "PowerSharingServerIP");
  16546. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[PowerSharingServerIP].ItemAccessibility == 1)
  16547. {
  16548. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_PowerSharingServerIP].ReadOnly, "0"/*"FALSE"*/);
  16549. }
  16550. else
  16551. {
  16552. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_PowerSharingServerIP].ReadOnly, "1"/*"TRUE"*/);
  16553. }
  16554. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_PowerSharingServerIP].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[PowerSharingServerIP].ItemData );
  16555. isKnowKey = TRUE;
  16556. }
  16557. if(isEmpty || strcmp(keyReq, "EVCCID_PREFIX") == 0 )
  16558. {
  16559. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_EVCCID_PREFIX].Item, "EVCCID_PREFIX");
  16560. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_EVCCID_PREFIX].Key, "EVCCID_PREFIX");
  16561. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[EVCCID_PREFIX].ItemAccessibility == 1)
  16562. {
  16563. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_EVCCID_PREFIX].ReadOnly, "0"/*"FALSE"*/);
  16564. }
  16565. else
  16566. {
  16567. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_EVCCID_PREFIX].ReadOnly, "1"/*"TRUE"*/);
  16568. }
  16569. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_EVCCID_PREFIX].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[EVCCID_PREFIX].ItemData );
  16570. isKnowKey = TRUE;
  16571. }
  16572. if(isEmpty || strcmp(keyReq, "OffLineMaxChargingPower") == 0 )
  16573. {
  16574. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_OffLineMaxChargingPower].Item, "OffLineMaxChargingPower");
  16575. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_OffLineMaxChargingPower].Key, "OffLineMaxChargingPower");
  16576. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[OffLineMaxChargingPower].ItemAccessibility == 1)
  16577. {
  16578. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_OffLineMaxChargingPower].ReadOnly, "0"/*"FALSE"*/);
  16579. }
  16580. else
  16581. {
  16582. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_OffLineMaxChargingPower].ReadOnly, "1"/*"TRUE"*/);
  16583. }
  16584. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_OffLineMaxChargingPower].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[OffLineMaxChargingPower].ItemData );
  16585. isKnowKey = TRUE;
  16586. }
  16587. if(isEmpty || strcmp(keyReq, "ConfigurationVersion") == 0 )
  16588. {
  16589. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_ConfigurationVersion].Item, "ConfigurationVersion");
  16590. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConfigurationVersion].Key, "ConfigurationVersion");
  16591. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[ConfigurationVersion].ItemAccessibility == 1)
  16592. {
  16593. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConfigurationVersion].ReadOnly, "0"/*"FALSE"*/);
  16594. }
  16595. else
  16596. {
  16597. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConfigurationVersion].ReadOnly, "1"/*"TRUE"*/);
  16598. }
  16599. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConfigurationVersion].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConfigurationVersion].ItemData );
  16600. isKnowKey = TRUE;
  16601. }
  16602. #if 1
  16603. if(isEmpty || strcmp(keyReq, "LocalAuthListEnabled") == 0 )
  16604. {
  16605. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_LocalAuthListEnabled].Item, "LocalAuthListEnabled");
  16606. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListEnabled].Key, "LocalAuthListEnabled");
  16607. if(ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemAccessibility == 1)
  16608. {
  16609. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListEnabled].ReadOnly, "0"/*"FALSE"*/);
  16610. }
  16611. else
  16612. {
  16613. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListEnabled].ReadOnly, "1"/*"TRUE"*/);
  16614. }
  16615. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListEnabled].Value, (const char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData );
  16616. isKnowKey = TRUE;
  16617. }
  16618. #endif
  16619. if(isEmpty || strcmp(keyReq, "LocalAuthListMaxLength") == 0 )
  16620. {
  16621. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_LocalAuthListMaxLength].Item, "LocalAuthListMaxLength");
  16622. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListMaxLength].Key, "LocalAuthListMaxLength");
  16623. if(ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemAccessibility == 1)
  16624. {
  16625. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListMaxLength].ReadOnly, "0"/*"FALSE"*/);
  16626. }
  16627. else
  16628. {
  16629. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListMaxLength].ReadOnly, "1"/*"TRUE"*/);
  16630. }
  16631. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListMaxLength].Value, (const char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemData );
  16632. isKnowKey = TRUE;
  16633. }
  16634. if(isEmpty || strcmp(keyReq, "SendLocalListMaxLength") == 0 )
  16635. {
  16636. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_SendLocalListMaxLength].Item, "SendLocalListMaxLength");
  16637. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SendLocalListMaxLength].Key, "SendLocalListMaxLength");
  16638. if(ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemAccessibility == 1)
  16639. {
  16640. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SendLocalListMaxLength].ReadOnly, "0"/*"FALSE"*/);
  16641. }
  16642. else
  16643. {
  16644. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SendLocalListMaxLength].ReadOnly, "1"/*"TRUE"*/);
  16645. }
  16646. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SendLocalListMaxLength].Value, (const char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemData );
  16647. isKnowKey = TRUE;
  16648. }
  16649. if(isEmpty || strcmp(keyReq, "ReserveConnectorZeroSupported") == 0 )
  16650. {
  16651. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_ReserveConnectorZeroSupported].Item, "ReserveConnectorZeroSupported");
  16652. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ReserveConnectorZeroSupported].Key, "ReserveConnectorZeroSupported");
  16653. if(ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemAccessibility == 1)
  16654. {
  16655. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ReserveConnectorZeroSupported].ReadOnly, "0"/*"FALSE"*/);
  16656. }
  16657. else
  16658. {
  16659. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ReserveConnectorZeroSupported].ReadOnly, "1"/*"TRUE"*/);
  16660. }
  16661. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ReserveConnectorZeroSupported].Value,(const char *)ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemData);
  16662. isKnowKey = TRUE;
  16663. }
  16664. if(isEmpty || strcmp(keyReq, "ChargeProfileMaxStackLevel") == 0 )
  16665. {
  16666. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_ChargeProfileMaxStackLevel].Item, "ChargeProfileMaxStackLevel");
  16667. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargeProfileMaxStackLevel].Key, "ChargeProfileMaxStackLevel");
  16668. if(ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemAccessibility == 1)
  16669. {
  16670. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargeProfileMaxStackLevel].ReadOnly, "0"/*"FALSE"*/);
  16671. }
  16672. else
  16673. {
  16674. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargeProfileMaxStackLevel].ReadOnly, "1"/*"TRUE"*/);
  16675. }
  16676. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargeProfileMaxStackLevel].Value, (const char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemData);
  16677. isKnowKey = TRUE;
  16678. }
  16679. if(isEmpty || strcmp(keyReq, "ChargingScheduleAllowedChargingRateUnit") == 0 )
  16680. {
  16681. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_ChargingScheduleAllowedChargingRateUnit].Item, "ChargingScheduleAllowedChargingRateUnit");
  16682. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargingScheduleAllowedChargingRateUnit].Key, "ChargingScheduleAllowedChargingRateUnit");
  16683. if(ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemAccessibility == 1)
  16684. {
  16685. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargingScheduleAllowedChargingRateUnit].ReadOnly, "0"/*"FALSE"*/);
  16686. }
  16687. else
  16688. {
  16689. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargingScheduleAllowedChargingRateUnit].ReadOnly, "1"/*"TRUE"*/);
  16690. }
  16691. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargingScheduleAllowedChargingRateUnit].Value, (const char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemData);
  16692. isKnowKey = TRUE;
  16693. }
  16694. if(isEmpty || strcmp(keyReq, "ChargingScheduleMaxPeriods") == 0 )
  16695. {
  16696. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_ChargingScheduleMaxPeriods].Item, "ChargingScheduleMaxPeriods");
  16697. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargingScheduleMaxPeriods].Key, "ChargingScheduleMaxPeriods");
  16698. if(ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemAccessibility == 1)
  16699. {
  16700. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargingScheduleMaxPeriods].ReadOnly, "0"/*"FALSE"*/);
  16701. }
  16702. else
  16703. {
  16704. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargingScheduleMaxPeriods].ReadOnly, "1"/*"TRUE"*/);
  16705. }
  16706. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargingScheduleMaxPeriods].Value, (const char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemData);
  16707. isKnowKey = TRUE;
  16708. }
  16709. if(isEmpty || strcmp(keyReq, "ConnectorSwitch3to1PhaseSupported") == 0 )
  16710. {
  16711. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_ConnectorSwitch3to1PhaseSupported].Item, "ConnectorSwitch3to1PhaseSupported");
  16712. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorSwitch3to1PhaseSupported].Key, "ConnectorSwitch3to1PhaseSupported");
  16713. if(ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemAccessibility == 1)
  16714. {
  16715. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorSwitch3to1PhaseSupported].ReadOnly, "0"/*"FALSE"*/);
  16716. }
  16717. else
  16718. {
  16719. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorSwitch3to1PhaseSupported].ReadOnly, "1"/*"TRUE"*/);
  16720. }
  16721. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorSwitch3to1PhaseSupported].Value, (const char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemData);
  16722. isKnowKey = TRUE;
  16723. }
  16724. if(isEmpty || strcmp(keyReq, "MaxChargingProfilesInstalled") == 0 )
  16725. {
  16726. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_MaxChargingProfilesInstalled].Item, "MaxChargingProfilesInstalled");
  16727. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaxChargingProfilesInstalled].Key, "MaxChargingProfilesInstalled");
  16728. if(ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemAccessibility == 1)
  16729. {
  16730. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaxChargingProfilesInstalled].ReadOnly, "0"/*"FLASE"*/);
  16731. }
  16732. else
  16733. {
  16734. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaxChargingProfilesInstalled].ReadOnly, "1"/*"TRUE"*/);
  16735. }
  16736. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaxChargingProfilesInstalled].Value, (const char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemData);
  16737. isKnowKey = TRUE;
  16738. }
  16739. //=========================================================
  16740. if(!isEmpty && !isKnowKey)
  16741. {
  16742. DEBUG_INFO("unKnowIndex =%d\n", UnknownKeynum);
  16743. strcpy(unknownkey[UnknownKeynum], keyReq);
  16744. UnknownKeynum = UnknownKeynum + 1;
  16745. }
  16746. }
  16747. void processUnkownKey(void)
  16748. {
  16749. DEBUG_INFO("processUnkownKey...\n");
  16750. memset(ShmOCPP16Data->GetConfiguration.ResponseUnknownKey, 0 , sizeof(struct StructConfigurationKeyItems)* 10);
  16751. for(int index=0; index < UnknownKeynum; index++)
  16752. {
  16753. if(ShmOCPP16Data->GetConfiguration.ResponseUnknownKey[index].Item[0] == 0)
  16754. {
  16755. strcpy((char *)(ShmOCPP16Data->GetConfiguration.ResponseUnknownKey[index].Item), unknownkey[index]);
  16756. }
  16757. }
  16758. }
  16759. int setKeyValue(char *key, char *value)
  16760. {
  16761. int isSuccess = NotSupported;
  16762. int check_ascii=0;
  16763. char str[501]={0};
  16764. DEBUG_INFO(" setKeyValue %s = %s\n", key, value);
  16765. if(strcmp(key, "AllowOfflineTxForUnknownId") == 0)
  16766. {
  16767. //Charger.AllowOfflineTxForUnknownId = (value.toLowerCase().equals("true")?true:false);
  16768. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemAccessibility == 1)
  16769. {
  16770. strcpy(str, (const char*)value);
  16771. for(int i = 0; str[i]; i++){
  16772. str[i] = tolower(str[i]);
  16773. }
  16774. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  16775. isSuccess = ConfigurationStatus_Accepted;
  16776. }
  16777. else
  16778. {
  16779. isSuccess = ConfigurationStatus_Rejected;
  16780. }
  16781. }
  16782. if(strcmp(key, "AuthorizationCacheEnabled") == 0)
  16783. {
  16784. //Charger.AuthorizationCacheEnabled = (value.toLowerCase().equals("true")?true:false);
  16785. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemAccessibility == 1)
  16786. {
  16787. strcpy(str, (const char*)value);
  16788. for(int i = 0; str[i]; i++){
  16789. str[i] = tolower(str[i]);
  16790. }
  16791. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  16792. isSuccess = ConfigurationStatus_Accepted;
  16793. //updateSetting("AuthorizationCacheEnabled",(char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[1].ItemData);
  16794. }
  16795. else
  16796. {
  16797. isSuccess = ConfigurationStatus_Rejected;
  16798. }
  16799. }
  16800. if(strcmp(key, "AuthorizeRemoteTxRequests") == 0)
  16801. {
  16802. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemAccessibility == 1)
  16803. {
  16804. strcpy(str, (const char*)value);
  16805. for(int i = 0; str[i]; i++)
  16806. {
  16807. str[i] = tolower(str[i]);
  16808. }
  16809. //Charger.AuthorizeRemoteTxRequests = (value.toLowerCase().equals("true")?true:false);
  16810. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  16811. isSuccess = ConfigurationStatus_Accepted;
  16812. }
  16813. else
  16814. {
  16815. isSuccess = ConfigurationStatus_Rejected;
  16816. }
  16817. }
  16818. if(strcmp(key, "BlinkRepeat") == 0)
  16819. {
  16820. //Charger.BlinkRepeat = Integer.parseInt(value);
  16821. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemAccessibility == 1)
  16822. {
  16823. check_ascii = value[0];
  16824. if( (check_ascii < 48) || (check_ascii > 57) )
  16825. {
  16826. isSuccess = ConfigurationStatus_Rejected;
  16827. }
  16828. else
  16829. {
  16830. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemData, "%d", atoi(value) );
  16831. isSuccess = ConfigurationStatus_Accepted;
  16832. }
  16833. }
  16834. else
  16835. {
  16836. isSuccess = ConfigurationStatus_Rejected;
  16837. }
  16838. }
  16839. if(strcmp(key, "ClockAlignedDataInterval") == 0)
  16840. {
  16841. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemAccessibility == 1)
  16842. {
  16843. check_ascii = value[0];
  16844. if( (check_ascii < 48) || (check_ascii > 57) )
  16845. {
  16846. isSuccess = ConfigurationStatus_Rejected;
  16847. }
  16848. else
  16849. {
  16850. if((atoi(value) == 0) || (atoi(value) >= 5))
  16851. {
  16852. //Charger.ClockAlignedDataInterval = Integer.parseInt(value)*1000;
  16853. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemData, "%d", atoi(value) );
  16854. isSuccess = ConfigurationStatus_Accepted;
  16855. }
  16856. else
  16857. isSuccess = ConfigurationStatus_Rejected;
  16858. }
  16859. }
  16860. else
  16861. {
  16862. isSuccess = ConfigurationStatus_Rejected;
  16863. }
  16864. }
  16865. if(strcmp(key, "ConnectionTimeOut") == 0 )
  16866. {
  16867. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemAccessibility == 1)
  16868. {
  16869. check_ascii = value[0];
  16870. if( (check_ascii < 48) || (check_ascii > 57) )
  16871. {
  16872. isSuccess = ConfigurationStatus_Rejected;
  16873. }
  16874. else
  16875. {
  16876. //Charger.ConnectionTimeOut = Integer.parseInt(value)*1000;
  16877. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemData, "%d", atoi(value));
  16878. isSuccess = ConfigurationStatus_Accepted;
  16879. }
  16880. }
  16881. else
  16882. {
  16883. isSuccess = ConfigurationStatus_Rejected;
  16884. }
  16885. }
  16886. if(strcmp(key, "GetConfigurationMaxKeys") == 0)
  16887. {
  16888. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemAccessibility == 1)
  16889. {
  16890. check_ascii = value[0];
  16891. if( (check_ascii < 48) || (check_ascii > 57) )
  16892. {
  16893. isSuccess = ConfigurationStatus_Rejected;
  16894. }
  16895. else
  16896. {
  16897. //Charger.HeartbeatInterval = Integer.parseInt(value)*1000;
  16898. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemData, "%d", atoi(value) );
  16899. isSuccess = ConfigurationStatus_Accepted;
  16900. }
  16901. }
  16902. else
  16903. {
  16904. isSuccess = ConfigurationStatus_Rejected;
  16905. }
  16906. }
  16907. if(strcmp(key, "HeartbeatInterval") == 0)
  16908. {
  16909. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemAccessibility == 1)
  16910. {
  16911. check_ascii = value[0];
  16912. if( (check_ascii < 48) || (check_ascii > 57) )
  16913. {
  16914. isSuccess = ConfigurationStatus_Rejected;
  16915. }
  16916. else
  16917. {
  16918. if((atoi(value) == 0) || (atoi(value) >= 10))
  16919. {
  16920. //Charger.HeartbeatInterval = Integer.parseInt(value)*1000;
  16921. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemData, "%d", atoi(value));
  16922. HeartBeatWaitTime = atoi(value);
  16923. isSuccess = ConfigurationStatus_Accepted;
  16924. }
  16925. else
  16926. {
  16927. isSuccess = ConfigurationStatus_Rejected;
  16928. }
  16929. }
  16930. }
  16931. else
  16932. {
  16933. isSuccess = ConfigurationStatus_Rejected;
  16934. }
  16935. }
  16936. if(strcmp(key, "LightIntensity") == 0)
  16937. {
  16938. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemAccessibility == 1)
  16939. {
  16940. check_ascii = value[0];
  16941. if( (check_ascii < 48) || (check_ascii > 57) )
  16942. {
  16943. isSuccess = ConfigurationStatus_Rejected;
  16944. }
  16945. else
  16946. {
  16947. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemData, "%d", atoi(value) );
  16948. isSuccess = ConfigurationStatus_Accepted;
  16949. }
  16950. }
  16951. else
  16952. {
  16953. isSuccess = ConfigurationStatus_Rejected;
  16954. }
  16955. }
  16956. if(strcmp(key, "LocalAuthorizeOffline") == 0)
  16957. {
  16958. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemAccessibility == 1)
  16959. {
  16960. strcpy(str, (const char*)value);
  16961. for(int i = 0; str[i]; i++)
  16962. {
  16963. str[i] = tolower(str[i]);
  16964. }
  16965. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  16966. isSuccess = ConfigurationStatus_Accepted;
  16967. //updateSetting("LocalAuthorizeOffline", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemData);
  16968. }
  16969. else
  16970. {
  16971. isSuccess = ConfigurationStatus_Rejected;
  16972. }
  16973. }
  16974. if(strcmp(key, "LocalPreAuthorize") == 0)
  16975. {
  16976. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemAccessibility == 1)
  16977. {
  16978. strcpy(str, (const char*)value);
  16979. for(int i = 0; str[i]; i++)
  16980. {
  16981. str[i] = tolower(str[i]);
  16982. }
  16983. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  16984. isSuccess = ConfigurationStatus_Accepted;
  16985. }
  16986. else
  16987. {
  16988. isSuccess = ConfigurationStatus_Rejected;
  16989. }
  16990. }
  16991. if(strcmp(key, "MaxEnergyOnInvalidId") == 0)
  16992. {
  16993. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemAccessibility == 1)
  16994. {
  16995. check_ascii = value[0];
  16996. if( (check_ascii < 48) || (check_ascii > 57) )
  16997. {
  16998. isSuccess = ConfigurationStatus_Rejected;
  16999. }
  17000. else
  17001. {
  17002. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemData, "%d", atoi(value) );
  17003. isSuccess = ConfigurationStatus_Accepted;
  17004. }
  17005. }
  17006. else
  17007. {
  17008. isSuccess = ConfigurationStatus_Rejected;
  17009. }
  17010. }
  17011. if(strcmp(key, "MeterValuesAlignedData") == 0)
  17012. {
  17013. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemAccessibility == 1)
  17014. {
  17015. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, "%s", value );
  17016. isSuccess = ConfigurationStatus_Accepted;
  17017. }
  17018. else
  17019. {
  17020. isSuccess = ConfigurationStatus_Rejected;
  17021. }
  17022. }
  17023. if(strcmp(key, "MeterValuesAlignedDataMaxLength") == 0)
  17024. {
  17025. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemAccessibility == 1)
  17026. {
  17027. check_ascii = value[0];
  17028. if( (check_ascii < 48) || (check_ascii > 57) )
  17029. {
  17030. isSuccess = ConfigurationStatus_Rejected;
  17031. }
  17032. else
  17033. {
  17034. //Charger.MeterValueSampleInterval = Integer.parseInt(value)*1000;
  17035. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemData, "%d", atoi(value));
  17036. isSuccess = ConfigurationStatus_Accepted;
  17037. }
  17038. }
  17039. else
  17040. {
  17041. isSuccess = ConfigurationStatus_Rejected;
  17042. }
  17043. }
  17044. if(strcmp(key, "MeterValuesSampledData") == 0 )
  17045. {
  17046. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemAccessibility == 1)
  17047. {
  17048. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, "%s", value );
  17049. isSuccess = ConfigurationStatus_Accepted;
  17050. }
  17051. else
  17052. {
  17053. isSuccess = ConfigurationStatus_Rejected;
  17054. }
  17055. }
  17056. if(strcmp(key, "MeterValuesSampledDataMaxLength") == 0)
  17057. {
  17058. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemAccessibility == 1)
  17059. {
  17060. check_ascii = value[0];
  17061. if( (check_ascii < 48) || (check_ascii > 57) )
  17062. {
  17063. isSuccess = ConfigurationStatus_Rejected;
  17064. }
  17065. else
  17066. {
  17067. //Charger.MeterValueSampleInterval = Integer.parseInt(value)*1000;
  17068. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemData, "%d", atoi(value));
  17069. isSuccess = ConfigurationStatus_Accepted;
  17070. }
  17071. }
  17072. else
  17073. {
  17074. isSuccess = ConfigurationStatus_Rejected;
  17075. }
  17076. }
  17077. if(strcmp(key, "MeterValueSampleInterval") == 0)
  17078. {
  17079. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemAccessibility == 1)
  17080. {
  17081. check_ascii = value[0];
  17082. if( (check_ascii < 48) || (check_ascii > 57) )
  17083. {
  17084. isSuccess = ConfigurationStatus_Rejected;
  17085. }
  17086. else
  17087. {
  17088. if((atoi(value) == 0) || (atoi(value) >= 3))
  17089. {
  17090. //Charger.MeterValueSampleInterval = Integer.parseInt(value)*1000;
  17091. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemData, "%d", atoi(value));
  17092. isSuccess = ConfigurationStatus_Accepted;
  17093. }
  17094. else
  17095. {
  17096. isSuccess = ConfigurationStatus_Rejected;
  17097. }
  17098. }
  17099. }
  17100. else
  17101. {
  17102. isSuccess = ConfigurationStatus_Rejected;
  17103. }
  17104. }
  17105. if(strcmp(key, "MinimumStatusDuration") == 0)
  17106. {
  17107. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemAccessibility == 1)
  17108. {
  17109. check_ascii = value[0];
  17110. if( (check_ascii < 48) || (check_ascii > 57) )
  17111. {
  17112. isSuccess = ConfigurationStatus_Rejected;
  17113. }
  17114. else
  17115. {
  17116. if(atoi(value) == 0) // MinimumStatusDuration's value can not be 0
  17117. {
  17118. isSuccess = ConfigurationStatus_Rejected;
  17119. }
  17120. else
  17121. {
  17122. //Charger.MinimumStatusDuration = Integer.parseInt(value);
  17123. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemData, "%d", atoi(value) );
  17124. server_cycle_Status = atoi(value); //StatusNotification Cycle
  17125. isSuccess = ConfigurationStatus_Accepted;
  17126. }
  17127. }
  17128. }
  17129. else
  17130. {
  17131. isSuccess = ConfigurationStatus_Rejected;
  17132. }
  17133. }
  17134. if(strcmp(key, "NumberOfConnectors") == 0)
  17135. {
  17136. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemAccessibility == 1)
  17137. {
  17138. check_ascii = value[0];
  17139. if( (check_ascii < 48) || (check_ascii > 57) )
  17140. {
  17141. isSuccess = ConfigurationStatus_Rejected;
  17142. }
  17143. else
  17144. {
  17145. //Charger.ResetRetries = Integer.parseInt(value);
  17146. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData, "%d", atoi(value) );
  17147. isSuccess = ConfigurationStatus_Accepted;
  17148. }
  17149. }
  17150. else
  17151. {
  17152. isSuccess = ConfigurationStatus_Rejected;
  17153. }
  17154. }
  17155. if(strcmp(key, "ResetRetries") == 0)
  17156. {
  17157. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemAccessibility == 1)
  17158. {
  17159. check_ascii = value[0];
  17160. if( (check_ascii < 48) || (check_ascii > 57) )
  17161. {
  17162. isSuccess = ConfigurationStatus_Rejected;
  17163. }
  17164. else
  17165. {
  17166. //Charger.ResetRetries = Integer.parseInt(value);
  17167. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemData, "%d", atoi(value) );
  17168. isSuccess = ConfigurationStatus_Accepted;
  17169. }
  17170. }
  17171. else
  17172. {
  17173. isSuccess = ConfigurationStatus_Rejected;
  17174. }
  17175. }
  17176. if(strcmp(key, "ConnectorPhaseRotation") == 0)
  17177. {
  17178. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemAccessibility == 1)
  17179. {
  17180. strcpy(str, (const char*)value);
  17181. for(int i = 0; str[i]; i++)
  17182. {
  17183. str[i] = tolower(str[i]);
  17184. }
  17185. if(strcmp(str, "notapplicable")== 0)
  17186. {
  17187. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "%s", "NotApplicable" );
  17188. isSuccess = ConfigurationStatus_Accepted;
  17189. }
  17190. else if(strcmp(str, "unknown")== 0)
  17191. {
  17192. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "%s", "Unknown" );
  17193. isSuccess = ConfigurationStatus_Accepted;
  17194. }
  17195. else if(strcmp(str, "rst")== 0)
  17196. {
  17197. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "%s", "RST" );
  17198. isSuccess = ConfigurationStatus_Accepted;
  17199. }
  17200. else if(strcmp(str, "rts")== 0)
  17201. {
  17202. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "%s", "RTS" );
  17203. isSuccess = ConfigurationStatus_Accepted;
  17204. }
  17205. else if(strcmp(str, "srt")== 0)
  17206. {
  17207. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "%s", "SRT" );
  17208. isSuccess = ConfigurationStatus_Accepted;
  17209. }
  17210. else if(strcmp(str, "str")== 0)
  17211. {
  17212. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "%s", "STR" );
  17213. isSuccess = ConfigurationStatus_Accepted;
  17214. }
  17215. else if(strcmp(str, "trs")== 0)
  17216. {
  17217. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "%s", "TRS" );
  17218. isSuccess = ConfigurationStatus_Accepted;
  17219. }
  17220. else if(strcmp(str, "tsr")== 0)
  17221. {
  17222. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "%s", "TSR" );
  17223. isSuccess = ConfigurationStatus_Accepted;
  17224. }
  17225. else
  17226. {
  17227. isSuccess = ConfigurationStatus_Rejected;
  17228. }
  17229. }
  17230. else
  17231. {
  17232. isSuccess = ConfigurationStatus_Rejected;
  17233. }
  17234. }
  17235. if(strcmp(key, "ConnectorPhaseRotationMaxLength") == 0)
  17236. {
  17237. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemAccessibility == 1)
  17238. {
  17239. check_ascii = value[0];
  17240. if( (check_ascii < 48) || (check_ascii > 57) )
  17241. {
  17242. isSuccess = ConfigurationStatus_Rejected;
  17243. }
  17244. else
  17245. {
  17246. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemData, "%d", atoi(value) );
  17247. isSuccess = ConfigurationStatus_Accepted;
  17248. }
  17249. }
  17250. else
  17251. {
  17252. isSuccess = ConfigurationStatus_Rejected;
  17253. }
  17254. }
  17255. if(strcmp(key, "StopTransactionOnEVSideDisconnect") == 0)
  17256. {
  17257. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemAccessibility == 1)
  17258. {
  17259. strcpy(str, (const char*)value);
  17260. for(int i = 0; str[i]; i++)
  17261. {
  17262. str[i] = tolower(str[i]);
  17263. }
  17264. //Charger.StopTransactionOnEVSideDisconnect = (value.toLowerCase().equals("true")?true:false);
  17265. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  17266. isSuccess = ConfigurationStatus_Accepted;
  17267. }
  17268. else
  17269. {
  17270. isSuccess = ConfigurationStatus_Rejected;
  17271. }
  17272. }
  17273. if(strcmp(key, "StopTransactionOnInvalidId") == 0)
  17274. {
  17275. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemAccessibility == 1)
  17276. {
  17277. strcpy(str, (const char*)value);
  17278. for(int i = 0; str[i]; i++)
  17279. {
  17280. str[i] = tolower(str[i]);
  17281. }
  17282. //Charger.StopTransactionOnInvalidId = (value.toLowerCase().equals("true")?true:false);
  17283. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  17284. isSuccess = ConfigurationStatus_Accepted;
  17285. }
  17286. else
  17287. {
  17288. isSuccess = ConfigurationStatus_Rejected;
  17289. }
  17290. }
  17291. if(strcmp(key, "StopTxnAlignedData") == 0)
  17292. {
  17293. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemAccessibility == 1)
  17294. {
  17295. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemData, "%s", value );
  17296. isSuccess = ConfigurationStatus_Accepted;
  17297. }
  17298. else
  17299. {
  17300. isSuccess = ConfigurationStatus_Rejected;
  17301. }
  17302. }
  17303. if(strcmp(key, "StopTxnAlignedDataMaxLength") == 0)
  17304. {
  17305. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemAccessibility == 1)
  17306. {
  17307. check_ascii = value[0];
  17308. if( (check_ascii < 48) || (check_ascii > 57) )
  17309. {
  17310. isSuccess = ConfigurationStatus_Rejected;
  17311. }
  17312. else
  17313. {
  17314. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemData, "%d", atoi(value) );
  17315. isSuccess = ConfigurationStatus_Accepted;
  17316. }
  17317. }
  17318. else
  17319. {
  17320. isSuccess = ConfigurationStatus_Rejected;
  17321. }
  17322. }
  17323. if(strcmp(key, "StopTxnSampledData") == 0)
  17324. {
  17325. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemAccessibility == 1)
  17326. {
  17327. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "%s", value );
  17328. isSuccess = ConfigurationStatus_Accepted;
  17329. }
  17330. else
  17331. {
  17332. isSuccess = ConfigurationStatus_Rejected;
  17333. }
  17334. }
  17335. if(strcmp(key, "StopTxnSampledDataMaxLength") == 0)
  17336. {
  17337. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemAccessibility == 1)
  17338. {
  17339. check_ascii = value[0];
  17340. if( (check_ascii < 48) || (check_ascii > 57) )
  17341. {
  17342. isSuccess = ConfigurationStatus_Rejected;
  17343. }
  17344. else
  17345. {
  17346. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemData, "%d", atoi(value) );
  17347. isSuccess = ConfigurationStatus_Accepted;
  17348. }
  17349. }
  17350. else
  17351. {
  17352. isSuccess = ConfigurationStatus_Rejected;
  17353. }
  17354. }
  17355. if(strcmp(key, "SupportedFeatureProfiles") == 0)
  17356. {
  17357. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemAccessibility == 1)
  17358. {
  17359. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemData, "%s", value );
  17360. isSuccess = ConfigurationStatus_Accepted;
  17361. }
  17362. else
  17363. {
  17364. isSuccess = ConfigurationStatus_Rejected;
  17365. }
  17366. }
  17367. if(strcmp(key, "SupportedFeatureProfilesMaxLength") == 0)
  17368. {
  17369. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemAccessibility == 1)
  17370. {
  17371. check_ascii = value[0];
  17372. if( (check_ascii < 48) || (check_ascii > 57) )
  17373. {
  17374. isSuccess = ConfigurationStatus_Rejected;
  17375. }
  17376. else
  17377. {
  17378. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemData, "%d", atoi(value) );
  17379. isSuccess = ConfigurationStatus_Accepted;
  17380. }
  17381. }
  17382. else
  17383. {
  17384. isSuccess = ConfigurationStatus_Rejected;
  17385. }
  17386. }
  17387. if(strcmp(key, "TransactionMessageAttempts") == 0)
  17388. {
  17389. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemAccessibility == 1)
  17390. {
  17391. check_ascii = value[0];
  17392. if( (check_ascii < 48) || (check_ascii > 57) )
  17393. {
  17394. isSuccess = ConfigurationStatus_Rejected;
  17395. }
  17396. else
  17397. {
  17398. //Charger.TransactionMessageAttempts = Integer.parseInt(value);
  17399. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData, "%d", atoi(value) );
  17400. TransactionMessageAttemptsValue = atoi(value);
  17401. isSuccess = ConfigurationStatus_Accepted;
  17402. }
  17403. }
  17404. else
  17405. {
  17406. isSuccess = ConfigurationStatus_Rejected;
  17407. }
  17408. }
  17409. if(strcmp(key, "TransactionMessageRetryInterval") == 0)
  17410. {
  17411. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemAccessibility == 1)
  17412. {
  17413. check_ascii = value[0];
  17414. if( (check_ascii < 48) || (check_ascii > 57) )
  17415. {
  17416. isSuccess = ConfigurationStatus_Rejected;
  17417. }
  17418. else
  17419. {
  17420. //Charger.TransactionMessageRetryInterval = Integer.parseInt(value)*1000;
  17421. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData, "%d", atoi(value) );
  17422. TransactionMessageRetryIntervalValue = atoi(value);
  17423. isSuccess = ConfigurationStatus_Accepted;
  17424. }
  17425. }
  17426. else
  17427. {
  17428. isSuccess = ConfigurationStatus_Rejected;
  17429. }
  17430. }
  17431. if(strcmp(key, "UnlockConnectorOnEVSideDisconnect") == 0)
  17432. {
  17433. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemAccessibility == 1)
  17434. {
  17435. strcpy(str, (const char*)value);
  17436. for(int i = 0; str[i]; i++)
  17437. {
  17438. str[i] = tolower(str[i]);
  17439. }
  17440. //Charger.UnlockConnectorOnEVSideDisconnect = (value.toLowerCase().equals("true")?true:false);
  17441. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  17442. isSuccess = ConfigurationStatus_Accepted;
  17443. }
  17444. else
  17445. {
  17446. isSuccess = ConfigurationStatus_Rejected;
  17447. }
  17448. }
  17449. if(strcmp(key, "WebSocketPingInterval") == 0)
  17450. {
  17451. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemAccessibility == 1)
  17452. {
  17453. check_ascii = value[0];
  17454. if( (check_ascii < 48) || (check_ascii > 57) )
  17455. {
  17456. isSuccess = ConfigurationStatus_Rejected;
  17457. }
  17458. else
  17459. {
  17460. if((atoi(value) == 0) || (atoi(value) >= 10))
  17461. {
  17462. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemData, "%d", atoi(value) );
  17463. isSuccess = ConfigurationStatus_Accepted;
  17464. }
  17465. else
  17466. isSuccess = ConfigurationStatus_Rejected;
  17467. }
  17468. }
  17469. else
  17470. {
  17471. isSuccess = ConfigurationStatus_Rejected;
  17472. }
  17473. }
  17474. if(strcmp(key, "QueueOffLineMeterValues") == 0)
  17475. {
  17476. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[QueueOffLineMeterValues].ItemAccessibility == 1)
  17477. {
  17478. strcpy(str, (const char*)value);
  17479. for(int i = 0; str[i]; i++)
  17480. {
  17481. str[i] = tolower(str[i]);
  17482. }
  17483. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[QueueOffLineMeterValues].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  17484. isSuccess = ConfigurationStatus_Accepted;
  17485. }
  17486. else
  17487. {
  17488. isSuccess = ConfigurationStatus_Rejected;
  17489. }
  17490. }
  17491. if(strcmp(key, "AuthorizationKey") == 0)
  17492. {
  17493. if((ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationKey].ItemAccessibility == 1) && (strlen(value) <= 40))
  17494. {
  17495. strcpy(str, (const char*)value);
  17496. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationKey].ItemData, "%s", str);
  17497. strcpy((char*)ShmSysConfigAndInfo->SysConfig.OcppSecurityPassword, (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationKey].ItemData);
  17498. isSuccess = ConfigurationStatus_Accepted;
  17499. }
  17500. else
  17501. {
  17502. isSuccess = ConfigurationStatus_Rejected;
  17503. }
  17504. }
  17505. if(strcmp(key, "SecurityProfile") == 0)
  17506. {
  17507. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[SecurityProfile].ItemAccessibility == 1)
  17508. {
  17509. check_ascii = value[0];
  17510. if( (check_ascii < 0x30) || (check_ascii > 0x33) )
  17511. {
  17512. isSuccess = ConfigurationStatus_Rejected;
  17513. }
  17514. else if(check_ascii == 0x33)
  17515. {
  17516. isSuccess = NotSupported;
  17517. }
  17518. else
  17519. {
  17520. if(atoi((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SecurityProfile].ItemData) <= (check_ascii - 0x30))
  17521. {
  17522. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SecurityProfile].ItemData, "%d", atoi(value) );
  17523. ShmSysConfigAndInfo->SysConfig.OcppSecurityProfile = atoi(value);
  17524. isSuccess = ConfigurationStatus_Accepted;
  17525. }
  17526. else
  17527. isSuccess = ConfigurationStatus_Rejected;
  17528. }
  17529. }
  17530. else
  17531. {
  17532. isSuccess = ConfigurationStatus_Rejected;
  17533. }
  17534. }
  17535. if(strcmp(key, "DefaultPrice") == 0)
  17536. {
  17537. if((ShmOCPP16Data->ConfigurationTable.CoreProfile[DefaultPrice].ItemAccessibility == 1))
  17538. {
  17539. strcpy(str, (const char*)value);
  17540. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[DefaultPrice].ItemData, "%s", str);
  17541. isSuccess = ConfigurationStatus_Accepted;
  17542. }
  17543. else
  17544. {
  17545. isSuccess = ConfigurationStatus_Rejected;
  17546. }
  17547. }
  17548. if(strcmp(key, "CustomDisplayCostAndPrice") == 0)
  17549. {
  17550. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemAccessibility == 1)
  17551. {
  17552. strcpy(str, (const char*)value);
  17553. for(int i = 0; str[i]; i++)
  17554. {
  17555. str[i] = tolower(str[i]);
  17556. }
  17557. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  17558. isSuccess = ConfigurationStatus_Accepted;
  17559. }
  17560. else
  17561. {
  17562. isSuccess = ConfigurationStatus_Rejected;
  17563. }
  17564. }
  17565. if(strcmp(key, "CustomIdleFeeAfterStop") == 0)
  17566. {
  17567. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemAccessibility == 1)
  17568. {
  17569. strcpy(str, (const char*)value);
  17570. for(int i = 0; str[i]; i++)
  17571. {
  17572. str[i] = tolower(str[i]);
  17573. }
  17574. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  17575. isSuccess = ConfigurationStatus_Accepted;
  17576. }
  17577. else
  17578. {
  17579. isSuccess = ConfigurationStatus_Rejected;
  17580. }
  17581. }
  17582. if(strcmp(key, "TimeOffset") == 0)
  17583. {
  17584. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffset].ItemAccessibility == 1)
  17585. {
  17586. strcpy(str, (const char*)value);
  17587. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffset].ItemData, "%s", str);
  17588. isSuccess = ConfigurationStatus_Accepted;
  17589. }
  17590. else
  17591. {
  17592. isSuccess = ConfigurationStatus_Rejected;
  17593. }
  17594. }
  17595. if(strcmp(key, "NextTimeOffsetTransitionDateTime") == 0)
  17596. {
  17597. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[NextTimeOffsetTransitionDateTime].ItemAccessibility == 1)
  17598. {
  17599. strcpy(str, (const char*)value);
  17600. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NextTimeOffsetTransitionDateTime].ItemData, "%s", str);
  17601. isSuccess = ConfigurationStatus_Accepted;
  17602. }
  17603. else
  17604. {
  17605. isSuccess = ConfigurationStatus_Rejected;
  17606. }
  17607. }
  17608. if(strcmp(key, "TimeOffsetNextTransition") == 0)
  17609. {
  17610. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffsetNextTransition].ItemAccessibility == 1)
  17611. {
  17612. strcpy(str, (const char*)value);
  17613. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffsetNextTransition].ItemData, "%s", str);
  17614. isSuccess = ConfigurationStatus_Accepted;
  17615. }
  17616. else
  17617. {
  17618. isSuccess = ConfigurationStatus_Rejected;
  17619. }
  17620. }
  17621. if(strcmp(key, "SystemUptimeSec") == 0)
  17622. {
  17623. isSuccess = NotSupported;
  17624. }
  17625. if(strcmp(key, "FreeVend") == 0)
  17626. {
  17627. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[FreeVend].ItemAccessibility == 1)
  17628. {
  17629. strcpy(str, (const char*)value);
  17630. for(int i = 0; str[i]; i++)
  17631. {
  17632. str[i] = tolower(str[i]);
  17633. }
  17634. ShmSysConfigAndInfo->SysConfig.AuthorisationMode = ((strcmp(str, "true")==0) ? 1 : 0 );
  17635. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[FreeVend].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  17636. isSuccess = ConfigurationStatus_Accepted;
  17637. }
  17638. else
  17639. {
  17640. isSuccess = ConfigurationStatus_Rejected;
  17641. }
  17642. }
  17643. if(strcmp(key, "FreeVendIdtag") == 0)
  17644. {
  17645. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[FreeVendIdtag].ItemAccessibility == 1)
  17646. {
  17647. strcpy(str, (const char*)value);
  17648. if(strlen(str) <= 20)
  17649. {
  17650. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[FreeVendIdtag].ItemData, "%s", str );
  17651. isSuccess = ConfigurationStatus_Accepted;
  17652. }
  17653. else
  17654. {
  17655. DEBUG_WARN("FreeVendIdtag(%s) length over 20 bytes.\n", str);
  17656. isSuccess = ConfigurationStatus_Rejected;
  17657. }
  17658. }
  17659. else
  17660. {
  17661. isSuccess = ConfigurationStatus_Rejected;
  17662. }
  17663. }
  17664. if(strcmp(key, "OcppServer") == 0)
  17665. {
  17666. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[OcppServer].ItemAccessibility == 1)
  17667. {
  17668. strcpy(str, (const char*)value);
  17669. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[OcppServer].ItemData, "%s", str );
  17670. sprintf((char *)ShmSysConfigAndInfo->SysConfig.OcppServerURL, "%s", str );
  17671. isSuccess = ConfigurationStatus_Accepted;
  17672. }
  17673. else
  17674. {
  17675. isSuccess = ConfigurationStatus_Rejected;
  17676. }
  17677. }
  17678. if(strcmp(key, "MaintainServer") == 0)
  17679. {
  17680. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MaintainServer].ItemAccessibility == 1)
  17681. {
  17682. strcpy(str, (const char*)value);
  17683. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MaintainServer].ItemData, "%s", str );
  17684. sprintf((char *)ShmSysConfigAndInfo->SysConfig.MaintainServerURL, "%s", str );
  17685. isSuccess = ConfigurationStatus_Accepted;
  17686. }
  17687. else
  17688. {
  17689. isSuccess = ConfigurationStatus_Rejected;
  17690. }
  17691. }
  17692. if(strcmp(key, "StatusNotificationPeriodically") == 0)
  17693. {
  17694. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StatusNotificationPeriodically].ItemAccessibility == 1)
  17695. {
  17696. strcpy(str, (const char*)value);
  17697. for(int i = 0; str[i]; i++)
  17698. {
  17699. str[i] = tolower(str[i]);
  17700. }
  17701. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StatusNotificationPeriodically].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE");
  17702. isSuccess = ConfigurationStatus_Accepted;
  17703. }
  17704. else
  17705. {
  17706. isSuccess = ConfigurationStatus_Rejected;
  17707. }
  17708. }
  17709. if(strcmp(key, "StatusNotificationInterval") == 0)
  17710. {
  17711. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StatusNotificationInterval].ItemAccessibility == 1)
  17712. {
  17713. check_ascii = value[0];
  17714. if( (check_ascii < 48) || (check_ascii > 57) )
  17715. {
  17716. isSuccess = ConfigurationStatus_Rejected;
  17717. }
  17718. else
  17719. {
  17720. if((atoi(value) == 0) || (atoi(value) >= 10))
  17721. {
  17722. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StatusNotificationInterval].ItemData, "%d", atoi(value) );
  17723. isSuccess = ConfigurationStatus_Accepted;
  17724. }
  17725. else
  17726. isSuccess = ConfigurationStatus_Rejected;
  17727. }
  17728. }
  17729. else
  17730. {
  17731. isSuccess = ConfigurationStatus_Rejected;
  17732. }
  17733. }
  17734. if(strcmp(key, "PreAuthAmount") == 0)
  17735. {
  17736. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[PreAuthAmount].ItemAccessibility == 1)
  17737. {
  17738. check_ascii = value[0];
  17739. if( (check_ascii < 48) || (check_ascii > 57) )
  17740. {
  17741. isSuccess = ConfigurationStatus_Rejected;
  17742. }
  17743. else
  17744. {
  17745. if(atof(value) >= 0)
  17746. {
  17747. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[PreAuthAmount].ItemData, "%.2f", atof(value) );
  17748. isSuccess = ConfigurationStatus_Accepted;
  17749. }
  17750. else
  17751. isSuccess = ConfigurationStatus_Rejected;
  17752. }
  17753. }
  17754. else
  17755. {
  17756. isSuccess = ConfigurationStatus_Rejected;
  17757. }
  17758. }
  17759. if(strcmp(key, "isEnableLocalPowerSharing") == 0)
  17760. {
  17761. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[isEnableLocalPowerSharing].ItemAccessibility == 1)
  17762. {
  17763. check_ascii = value[0];
  17764. if( (check_ascii < 48) || (check_ascii > 57) )
  17765. {
  17766. isSuccess = ConfigurationStatus_Rejected;
  17767. }
  17768. else
  17769. {
  17770. if(atoi(value) >= 0)
  17771. {
  17772. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[isEnableLocalPowerSharing].ItemData, "%d", atoi(value));
  17773. ShmSysConfigAndInfo->SysConfig.isEnableLocalPowerSharing = (unsigned char)atoi(value);
  17774. isSuccess = ConfigurationStatus_Accepted;
  17775. }
  17776. else
  17777. isSuccess = ConfigurationStatus_Rejected;
  17778. }
  17779. }
  17780. else
  17781. {
  17782. isSuccess = ConfigurationStatus_Rejected;
  17783. }
  17784. }
  17785. if(strcmp(key, "PowerSharingServerIP") == 0)
  17786. {
  17787. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[PowerSharingServerIP].ItemAccessibility == 1)
  17788. {
  17789. strcpy(str, (const char*)value);
  17790. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[PowerSharingServerIP].ItemData, "%s", str );
  17791. sprintf((char *)ShmSysConfigAndInfo->SysConfig.PowerSharingServerIP, "%s", str );
  17792. isSuccess = ConfigurationStatus_Accepted;
  17793. }
  17794. else
  17795. {
  17796. isSuccess = ConfigurationStatus_Rejected;
  17797. }
  17798. }
  17799. if(strcmp(key, "EVCCID_PREFIX") == 0)
  17800. {
  17801. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[EVCCID_PREFIX].ItemAccessibility == 1)
  17802. {
  17803. strcpy(str, (const char*)value);
  17804. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[EVCCID_PREFIX].ItemData, "%s", str );
  17805. isSuccess = ConfigurationStatus_Accepted;
  17806. }
  17807. else
  17808. {
  17809. isSuccess = ConfigurationStatus_Rejected;
  17810. }
  17811. }
  17812. if(strcmp(key, "OffLineMaxChargingPower") == 0)
  17813. {
  17814. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[OffLineMaxChargingPower].ItemAccessibility == 1)
  17815. {
  17816. strcpy(str, (const char*)value);
  17817. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[OffLineMaxChargingPower].ItemData, "%s", str );
  17818. isSuccess = ConfigurationStatus_Accepted;
  17819. }
  17820. else
  17821. {
  17822. isSuccess = ConfigurationStatus_Rejected;
  17823. }
  17824. }
  17825. #if 0
  17826. //For OCPP Test Case
  17827. if(strcmp(key, "LocalAuthorizationListEnabled") == 0)
  17828. {
  17829. if(ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemAccessibility == 1)
  17830. {
  17831. strcpy(str, (const char*)value);
  17832. for(int i = 0; str[i]; i++)
  17833. {
  17834. str[i] = tolower(str[i]);
  17835. }
  17836. sprintf((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  17837. isSuccess = ConfigurationStatus_Accepted;
  17838. //updateSetting("LocalAuthorizationListEnabled", (char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData);
  17839. }
  17840. else
  17841. {
  17842. isSuccess = ConfigurationStatus_Rejected;
  17843. }
  17844. }
  17845. #endif
  17846. #if 1
  17847. if(strcmp(key, "LocalAuthListEnabled") == 0)
  17848. {
  17849. if(ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemAccessibility == 1)
  17850. {
  17851. strcpy(str, (const char*)value);
  17852. for(int i = 0; str[i]; i++)
  17853. {
  17854. str[i] = tolower(str[i]);
  17855. }
  17856. sprintf((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  17857. isSuccess = ConfigurationStatus_Accepted;
  17858. //updateSetting("LocalAuthListEnabled", (char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData);
  17859. }
  17860. else
  17861. {
  17862. isSuccess = ConfigurationStatus_Rejected;
  17863. }
  17864. }
  17865. #endif
  17866. if(strcmp(key, "LocalAuthListMaxLength") == 0)
  17867. {
  17868. if(ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemAccessibility == 1)
  17869. {
  17870. check_ascii = value[0];
  17871. if( (check_ascii < 48) || (check_ascii > 57) )
  17872. {
  17873. isSuccess = ConfigurationStatus_Rejected;
  17874. }
  17875. else
  17876. {
  17877. sprintf((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemData, "%d", atoi(value) );
  17878. isSuccess = ConfigurationStatus_Accepted;
  17879. }
  17880. }
  17881. else
  17882. {
  17883. isSuccess = ConfigurationStatus_Rejected;
  17884. }
  17885. }
  17886. if(strcmp(key, "SendLocalListMaxLength") == 0)
  17887. {
  17888. if(ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemAccessibility == 1)
  17889. {
  17890. check_ascii = value[0];
  17891. if( (check_ascii < 48) || (check_ascii > 57) )
  17892. {
  17893. isSuccess = ConfigurationStatus_Rejected;
  17894. }
  17895. else
  17896. {
  17897. sprintf((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemData, "%d", atoi(value) );
  17898. isSuccess = ConfigurationStatus_Accepted;
  17899. }
  17900. }
  17901. else
  17902. {
  17903. isSuccess = ConfigurationStatus_Rejected;
  17904. }
  17905. }
  17906. if(strcmp(key, "ReserveConnectorZeroSupported") == 0)
  17907. {
  17908. if(ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemAccessibility == 1)
  17909. {
  17910. strcpy(str, (const char*)value);
  17911. for(int i = 0; str[i]; i++)
  17912. {
  17913. str[i] = tolower(str[i]);
  17914. }
  17915. sprintf((char *)ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  17916. isSuccess = ConfigurationStatus_Accepted;
  17917. }
  17918. else
  17919. {
  17920. isSuccess = ConfigurationStatus_Rejected;
  17921. }
  17922. }
  17923. if(strcmp(key, "ChargeProfileMaxStackLevel") == 0)
  17924. {
  17925. if(ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemAccessibility == 1)
  17926. {
  17927. check_ascii = value[0];
  17928. if( (check_ascii < 48) || (check_ascii > 57) )
  17929. {
  17930. isSuccess = ConfigurationStatus_Rejected;
  17931. }
  17932. else
  17933. {
  17934. sprintf((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemData, "%d", atoi(value) );
  17935. isSuccess = ConfigurationStatus_Accepted;
  17936. }
  17937. }
  17938. else
  17939. {
  17940. isSuccess = ConfigurationStatus_Rejected;
  17941. }
  17942. }
  17943. if(strcmp(key, "ChargingScheduleAllowedChargingRateUnit") == 0)
  17944. {
  17945. if(ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemAccessibility == 1)
  17946. {
  17947. sprintf((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemData, "%s", value );
  17948. isSuccess = ConfigurationStatus_Accepted;
  17949. }
  17950. else
  17951. {
  17952. isSuccess = ConfigurationStatus_Rejected;
  17953. }
  17954. }
  17955. if(strcmp(key, "ChargingScheduleMaxPeriods") == 0)
  17956. {
  17957. if(ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemAccessibility == 1)
  17958. {
  17959. check_ascii = value[0];
  17960. if( (check_ascii < 48) || (check_ascii > 57) )
  17961. {
  17962. isSuccess = ConfigurationStatus_Rejected;
  17963. }
  17964. else
  17965. {
  17966. sprintf((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemData, "%d", atoi(value) );
  17967. isSuccess = ConfigurationStatus_Accepted;
  17968. }
  17969. }
  17970. else
  17971. {
  17972. isSuccess = ConfigurationStatus_Rejected;
  17973. }
  17974. }
  17975. if(strcmp(key, "ConnectorSwitch3to1PhaseSupported") == 0)
  17976. {
  17977. if(ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemAccessibility == 1)
  17978. {
  17979. strcpy(str, (const char*)value);
  17980. for(int i = 0; str[i]; i++)
  17981. {
  17982. str[i] = tolower(str[i]);
  17983. }
  17984. sprintf((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  17985. isSuccess = ConfigurationStatus_Accepted;
  17986. }
  17987. else
  17988. {
  17989. isSuccess = ConfigurationStatus_Rejected;
  17990. }
  17991. }
  17992. if(strcmp(key, "MaxChargingProfilesInstalled") == 0)
  17993. {
  17994. if(ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemAccessibility == 1)
  17995. {
  17996. check_ascii = value[0];
  17997. if( (check_ascii < 48) || (check_ascii > 57) )
  17998. {
  17999. isSuccess = ConfigurationStatus_Rejected;
  18000. }
  18001. else
  18002. {
  18003. sprintf((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemData, "%d", atoi(value) );
  18004. isSuccess = ConfigurationStatus_Accepted;
  18005. }
  18006. }
  18007. else
  18008. {
  18009. isSuccess = ConfigurationStatus_Rejected;
  18010. }
  18011. }
  18012. system("/bin/fsync -d /dev/mtdblock13;/bin/sync &");
  18013. return isSuccess;
  18014. }
  18015. int TransactionMessageAttemptsGet(void)
  18016. {
  18017. return TransactionMessageAttemptsValue;
  18018. }
  18019. int FirstHeartBeatResponse(void)
  18020. {
  18021. return FirstHeartBeat;
  18022. }
  18023. int TransactionMessageRetryIntervalGet(void)
  18024. {
  18025. return TransactionMessageRetryIntervalValue;//atoi((const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData);
  18026. }
  18027. int ReadHttpStatus(int sock)
  18028. {
  18029. //char c;
  18030. char buff[1024]="",*ptr=buff+1;
  18031. int bytes_received, status;
  18032. DEBUG_INFO("Begin Response ..\n");
  18033. while((bytes_received = recv(sock, ptr, 1, 0))){
  18034. if(bytes_received==-1){
  18035. perror("ReadHttpStatus");
  18036. exit(1);
  18037. }
  18038. if((ptr[-1]=='\r') && (*ptr=='\n' )) break;
  18039. ptr++;
  18040. }
  18041. *ptr=0;
  18042. ptr=buff+1;
  18043. sscanf(ptr,"%*s %d ", &status);
  18044. DEBUG_INFO("%s\n",ptr);
  18045. DEBUG_INFO("status=%d\n",status);
  18046. DEBUG_INFO("End Response ..\n");
  18047. return (bytes_received>0)?status:0;
  18048. }
  18049. //the only filed that it parsed is 'Content-Length'
  18050. int ParseHeader(int sock)
  18051. {
  18052. //char c;
  18053. char buff[1024]="",*ptr=buff+4;
  18054. int bytes_received;
  18055. DEBUG_INFO("Begin HEADER ..\n");
  18056. while((bytes_received = recv(sock, ptr, 1, 0))){
  18057. if(bytes_received==-1){
  18058. perror("Parse Header");
  18059. exit(1);
  18060. }
  18061. if(
  18062. (ptr[-3]=='\r') && (ptr[-2]=='\n' ) &&
  18063. (ptr[-1]=='\r') && (*ptr=='\n' )
  18064. ) break;
  18065. ptr++;
  18066. }
  18067. *ptr=0;
  18068. ptr=buff+4;
  18069. //printf("%s",ptr);
  18070. if(bytes_received){
  18071. ptr=strstr(ptr,"Content-Length:");
  18072. if(ptr){
  18073. sscanf(ptr,"%*s %d",&bytes_received);
  18074. }else
  18075. bytes_received=-1; //unknown size
  18076. DEBUG_INFO("Content-Length: %d\n",bytes_received);
  18077. }
  18078. DEBUG_INFO("End HEADER ..\n");
  18079. return bytes_received ;
  18080. }
  18081. int httpDownLoadFile(char *location, char *path, char *filename,char *url)
  18082. {
  18083. int result = TRUE;
  18084. char rmFileCmd[100]={0};
  18085. char FilePath[100]={0};
  18086. char ftpbuf[200];
  18087. int systemresult;
  18088. sprintf(FilePath,"/mnt/%s",filename);
  18089. system("ping 8.8.8.8 &");
  18090. if((access(FilePath,F_OK))!=-1)
  18091. {
  18092. DEBUG_INFO("filename=%s exist.\n",FilePath);
  18093. sprintf(rmFileCmd,"rm -f %s",FilePath);
  18094. system(rmFileCmd);
  18095. }
  18096. memset(ftpbuf, 0, ARRAY_SIZE(ftpbuf));
  18097. sprintf(ftpbuf, "wget --tries=1 -O /mnt/%s -c %s -T 120 --no-check-certificate",filename, url);
  18098. DEBUG_INFO("Download command: %s\n",ftpbuf);
  18099. systemresult = system(ftpbuf);
  18100. if(systemresult != 0)
  18101. {
  18102. DEBUG_INFO("HTTP/HTTPS downLoad fail!\n");
  18103. result = FALSE;
  18104. }
  18105. system("pkill ping");
  18106. return result;
  18107. }
  18108. int sftpDownLoadFile(char *location, char *user, int port, char *path, char *filename,char *url)
  18109. {
  18110. int result = TRUE;
  18111. char rmFileCmd[100]={0};
  18112. char FilePath[100]={0};
  18113. char ftpbuf[200];
  18114. int systemresult;
  18115. sprintf(FilePath,"/mnt/%s",filename);
  18116. system("ping 8.8.8.8 &");
  18117. if((access(FilePath,F_OK))!=-1)
  18118. {
  18119. DEBUG_INFO("filename=%s exist.\n",FilePath);
  18120. sprintf(rmFileCmd,"rm -f %s",FilePath);
  18121. system(rmFileCmd);
  18122. }
  18123. memset(ftpbuf, 0, ARRAY_SIZE(ftpbuf));
  18124. sprintf(ftpbuf,"timeout -t 360 scp -i /root/.ssh/id_rsa_bear -P %d %s@%s%s /mnt/%s", port, user, path, filename, filename);
  18125. DEBUG_INFO("Download command: %s\n",ftpbuf);
  18126. systemresult = system(ftpbuf);
  18127. if(systemresult != 0)
  18128. {
  18129. DEBUG_WARN("scp error!\n");
  18130. result = FALSE;
  18131. }
  18132. system("pkill ping");
  18133. return result;
  18134. }
  18135. int ftpDownLoadFile(char *location, char *user, char *password, int port, char *path, char *filename,char *url)
  18136. {
  18137. int result = TRUE;
  18138. char rmFileCmd[100]={0};
  18139. char FilePath[100]={0};
  18140. char ftpbuf[200];
  18141. int systemresult;
  18142. sprintf(FilePath,"/mnt/%s",filename);
  18143. system("ping 8.8.8.8 &");
  18144. if((access(FilePath,F_OK))!=-1)
  18145. {
  18146. DEBUG_INFO("filename=%s exist.\n",FilePath);
  18147. sprintf(rmFileCmd,"rm -f %s",FilePath);
  18148. system(rmFileCmd);
  18149. }
  18150. memset(ftpbuf, 0, ARRAY_SIZE(ftpbuf));
  18151. sprintf(ftpbuf, "wget --tries=1 -O /mnt/%s -c %s -T 120",filename, url);
  18152. DEBUG_INFO("Download command: %s\n",ftpbuf);
  18153. systemresult = system(ftpbuf);
  18154. if(systemresult != 0)
  18155. {
  18156. sprintf(ftpbuf, "wget --tries=1 -O /mnt/%s -c %s -T 120 --no-passive-ftp",filename, url);
  18157. DEBUG_INFO("Download command: %s\n",ftpbuf);
  18158. systemresult = system(ftpbuf);
  18159. if(systemresult != 0)
  18160. {
  18161. DEBUG_WARN("FTP download fail!\n");
  18162. result = FALSE;
  18163. }
  18164. }
  18165. system("pkill ping");
  18166. return result;
  18167. }
  18168. int httpUploadFile(char *location, char *path, char *filename,char *url)
  18169. {
  18170. char rmFileCmd[100]={0};
  18171. char FilePath[100]={0};
  18172. char buf[512];
  18173. int systemresult = 0;
  18174. //DEBUG_INFO("filename=%s\n",filename);
  18175. //DEBUG_INFO("url=%s\n",url);
  18176. sprintf(FilePath,"%s","/mnt/upload_file.txt");
  18177. if((access(FilePath,F_OK))!=-1)
  18178. {
  18179. DEBUG_INFO("filename=%s exist.\n",FilePath);
  18180. sprintf(rmFileCmd,"rm -f %s",FilePath);
  18181. system(rmFileCmd);
  18182. }
  18183. FILE *fp = fopen("/mnt/upload_file.txt", "w+");
  18184. if(fp == NULL)
  18185. {
  18186. DEBUG_INFO("log is NULL\n");
  18187. return FALSE;
  18188. }
  18189. else
  18190. {
  18191. fprintf(fp, "%s\n", url);
  18192. fprintf(fp, "%s\n", filename);
  18193. fclose(fp);
  18194. }
  18195. FILE *phpFP = popen("/bin/php-cgi /var/www/ocpp_upload.php", "r");
  18196. if(phpFP == NULL)
  18197. {
  18198. DEBUG_INFO("PHP upload fail.\n");
  18199. return FALSE;
  18200. }
  18201. else
  18202. {
  18203. while(fgets(buf, sizeof(buf), phpFP) != NULL)
  18204. {
  18205. if(strstr(buf, "result") != NULL)
  18206. {
  18207. sscanf(buf, "result: %d", &systemresult);
  18208. DEBUG_INFO("PHP HTTP upload result: %d\n", systemresult);
  18209. }
  18210. }
  18211. pclose(phpFP);
  18212. }
  18213. if(systemresult != 1)
  18214. {
  18215. DEBUG_WARN("HTTP POST upload error, change to PUT method\n");
  18216. FILE *phpFP = popen("/bin/php-cgi /var/www/ocpp_upload_put.php", "r");
  18217. if(phpFP == NULL)
  18218. {
  18219. DEBUG_WARN("PHP PUT upload fail.\n");
  18220. return FALSE;
  18221. }
  18222. else
  18223. {
  18224. while(fgets(buf, sizeof(buf), phpFP) != NULL)
  18225. {
  18226. if(strstr(buf, "result") != NULL)
  18227. {
  18228. sscanf(buf, "result: %d", &systemresult);
  18229. DEBUG_INFO("PHP HTTP PUT upload result: %d\n", systemresult);
  18230. }
  18231. }
  18232. pclose(phpFP);
  18233. }
  18234. }
  18235. if(systemresult != 1)
  18236. {
  18237. DEBUG_WARN("PHP PUT upload fail.\n");
  18238. return FALSE;
  18239. }
  18240. return TRUE;
  18241. }
  18242. int ftpUploadFile(char *location, char *user, char *password, int port, char *path, char *fnamePlusPath,char *filename)
  18243. {
  18244. int result = FALSE;
  18245. char ftpbuf[200];
  18246. int systemresult;
  18247. /*
  18248. // Domaind name transfer to IP address
  18249. struct hostent* server;
  18250. char *IPbuffer;
  18251. server = gethostbyname(location);
  18252. IPbuffer = inet_ntoa(*((struct in_addr*)server->h_addr_list[0]));*/
  18253. memset(ftpbuf, 0, ARRAY_SIZE(ftpbuf));
  18254. sprintf(ftpbuf, "ftpput -u %s -p %s %s -P %d %s%s %s", user, password, location, port/*21*/, path, filename, fnamePlusPath);
  18255. DEBUG_INFO("ftp command: %s\n",ftpbuf);
  18256. systemresult = system(ftpbuf);
  18257. if(systemresult != 0)
  18258. {
  18259. DEBUG_INFO("ftpput error!\n");
  18260. }
  18261. else
  18262. {
  18263. result = TRUE;
  18264. DEBUG_INFO("ftpput OK!\n");
  18265. }
  18266. return result;
  18267. }
  18268. int GetOcppServerURL()
  18269. {
  18270. int result = FALSE;
  18271. memset(OcppProtocol, 0, ARRAY_SIZE(OcppProtocol));
  18272. memset(OcppHost, 0, ARRAY_SIZE(OcppHost));
  18273. memset(OcppTempPath, 0, ARRAY_SIZE(OcppTempPath));
  18274. struct yuarel url;
  18275. char urlStr[512];
  18276. if((ShmSysConfigAndInfo->SysConfig.OcppServerURL != NULL) && (strcmp((const char *)ShmSysConfigAndInfo->SysConfig.OcppServerURL,"") != 0) )
  18277. {
  18278. /*sscanf((const char *)ShmSysConfigAndInfo->SysConfig.OcppServerURL,
  18279. "%[^:]:%*2[/]%[^:]:%i/%[a-zA-Z0-9._/-]",
  18280. OcppProtocol, OcppHost, &OcppPort, OcppTempPath);*/
  18281. memcpy(urlStr, ShmSysConfigAndInfo->SysConfig.OcppServerURL, ARRAY_SIZE(ShmSysConfigAndInfo->SysConfig.OcppServerURL));
  18282. if(yuarel_parse(&url, urlStr) != -1)
  18283. {
  18284. sprintf(OcppProtocol, "%s", url.scheme);
  18285. sprintf(OcppHost, "%s", url.host);
  18286. if(url.path == NULL)
  18287. OcppTempPath[0] = '\0';
  18288. else
  18289. {
  18290. if((url.path[strlen(url.path)-1] != '/') && (strlen(url.path) > 0))
  18291. {
  18292. sprintf(OcppTempPath, "%s/", url.path);
  18293. }
  18294. else
  18295. {
  18296. sprintf(OcppTempPath, "%s", url.path);
  18297. }
  18298. }
  18299. if(url.port == 0)
  18300. {
  18301. if(strcmp(OcppProtocol, "wss") == 0)
  18302. OcppPort = 443;
  18303. else
  18304. OcppPort = 80;
  18305. }
  18306. else
  18307. OcppPort = url.port;
  18308. result = TRUE;
  18309. }
  18310. }
  18311. else if((ShmOCPP16Data->OcppServerURL != NULL) && (strcmp((const char *)ShmOCPP16Data->OcppServerURL,"") != 0))
  18312. {
  18313. /*sscanf((const char *)ShmOCPP16Data->OcppServerURL,
  18314. "%[^:]:%*2[/]%[^:]:%i/%[a-zA-Z0-9._/-]",
  18315. OcppProtocol, OcppHost, &OcppPort, OcppTempPath);*/
  18316. memcpy(urlStr, ShmOCPP16Data->OcppServerURL, ARRAY_SIZE(ShmOCPP16Data->OcppServerURL));
  18317. if(yuarel_parse(&url, urlStr) != -1)
  18318. {
  18319. sprintf(OcppProtocol, "%s", url.scheme);
  18320. sprintf(OcppHost, "%s", url.host);
  18321. if(url.path == NULL)
  18322. OcppTempPath[0] = '\0';
  18323. else
  18324. sprintf(OcppTempPath, "%s", url.path);
  18325. if(url.port == 0)
  18326. {
  18327. if(strcmp(OcppProtocol, "wss") == 0)
  18328. OcppPort = 443;
  18329. else
  18330. OcppPort = 80;
  18331. }
  18332. else
  18333. OcppPort = url.port;
  18334. result = TRUE;
  18335. }
  18336. }
  18337. else
  18338. {
  18339. strcpy(OcppHost,"");
  18340. }
  18341. return result;
  18342. }
  18343. int GetOcppPath()
  18344. {
  18345. int result = FALSE;
  18346. if((ShmSysConfigAndInfo->SysConfig.ChargeBoxId != NULL) && (strcmp((const char *)ShmSysConfigAndInfo->SysConfig.ChargeBoxId,"") != 0) )
  18347. {
  18348. if(OcppTempPath == NULL)
  18349. {
  18350. sprintf(OcppPath,"/%s",ShmSysConfigAndInfo->SysConfig.ChargeBoxId);
  18351. }
  18352. else
  18353. {
  18354. sprintf(OcppPath,"/%s%s",OcppTempPath,ShmSysConfigAndInfo->SysConfig.ChargeBoxId);
  18355. }
  18356. result = TRUE;
  18357. goto End;
  18358. }
  18359. else if((ShmOCPP16Data->ChargeBoxId != NULL) && (strcmp((const char *)ShmOCPP16Data->ChargeBoxId,"") != 0))
  18360. {
  18361. if(OcppTempPath == NULL)
  18362. {
  18363. sprintf(OcppPath,"/%s",ShmOCPP16Data->ChargeBoxId);
  18364. }
  18365. else
  18366. {
  18367. sprintf(OcppPath,"/%s%s",OcppTempPath,ShmOCPP16Data->ChargeBoxId);
  18368. }
  18369. result = TRUE;
  18370. goto End;
  18371. }
  18372. else
  18373. {
  18374. strcpy(OcppPath,"");
  18375. }
  18376. End:
  18377. return result;
  18378. }
  18379. int GetOcppPort()
  18380. {
  18381. return OcppPort;
  18382. }
  18383. int GetOcppConnStatus(void)
  18384. {
  18385. return ShmOCPP16Data->OcppConnStatus;
  18386. }
  18387. void SetOcppConnStatus(uint8_t status)
  18388. {
  18389. ShmOCPP16Data->OcppConnStatus = status;
  18390. ShmSysConfigAndInfo->SysInfo.OcppConnStatus = status;
  18391. }
  18392. int GetHeartBeatWithNOResponse(void)
  18393. {
  18394. return HeartBeatWithNOResponse;
  18395. }
  18396. void SetHeartBeatWithNOResponse(void)
  18397. {
  18398. HeartBeatWithNOResponse = 0;
  18399. }
  18400. void GetStartTransactionIdTag(int gun_index)
  18401. {
  18402. memset(StartTransactionIdTagTemp, 0 ,ARRAY_SIZE(StartTransactionIdTagTemp));
  18403. strcpy((char *)StartTransactionIdTagTemp, (const char *)ShmOCPP16Data->StartTransaction[gun_index].IdTag);
  18404. }
  18405. int GetStartTransactionId(int gun_index)
  18406. {
  18407. return ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId;
  18408. }
  18409. int GetTransactionId(int gunindex, unsigned char idTag[], uint8_t isStopTransaction)
  18410. {
  18411. char ch;
  18412. FILE *fptr1;
  18413. int temptransactionId;
  18414. char str[100]={0};
  18415. temptransactionId = 0;
  18416. if(((strcmp((const char*)idTag, "")==0)||(idTag[0]=='\0')) && isStopTransaction)
  18417. {
  18418. DEBUG_INFO("IdTag is empty.\n");
  18419. return temptransactionId;
  18420. }
  18421. /*------ Read the file ----------------*/
  18422. fptr1=fopen("/Storage/OCPP/QueueTransactionId","r");
  18423. if (!fptr1)
  18424. {
  18425. DEBUG_INFO("QueueTransactionId file open error.\n");
  18426. //printf(" File not found or unable to open the input file!!\n");
  18427. return temptransactionId;
  18428. }
  18429. ch=fgetc(fptr1);
  18430. //printf(" Now the content of the file %s is : \n","/Storage/OCPP/QueueTransactionId");
  18431. rewind(fptr1);
  18432. if(ch!=EOF)
  18433. {
  18434. // printf("%c",ch);
  18435. while (fgets(str, 100, fptr1) != NULL)
  18436. {
  18437. str[strlen(str) - 1] = '\0'; // eat the newline fgets() stores
  18438. if(str[0]=='\0')
  18439. {
  18440. break;
  18441. }
  18442. char *revbuf[8] = {0}; // Variable store string split
  18443. int num = 0;// Quantity after string split
  18444. DEBUG_INFO("Transaction queue data= %s\n", str);
  18445. splitstring(str,",",revbuf,&num); // String split
  18446. DEBUG_INFO(" revbuf[0]= %s\n", revbuf[0]);
  18447. DEBUG_INFO(" revbuf[1]= %s\n", revbuf[1]);
  18448. DEBUG_INFO(" revbuf[2]= %s\n", revbuf[2]);
  18449. DEBUG_INFO("------------------------------\n");
  18450. if((revbuf[1][0] != '\0')&&(revbuf[2][0] != '\0'))
  18451. {
  18452. if(isStopTransaction)
  18453. {
  18454. if((atoi(revbuf[0])==gunindex) && (strcmp(revbuf[1],(const char *)idTag)==0))
  18455. {
  18456. temptransactionId = atoi(revbuf[2]);
  18457. //break;
  18458. }
  18459. }
  18460. else
  18461. {
  18462. if((atoi(revbuf[0])==gunindex) || (strcmp(revbuf[1],(const char *)idTag)==0))
  18463. {
  18464. temptransactionId = atoi(revbuf[2]);
  18465. //break;
  18466. }
  18467. }
  18468. }
  18469. }
  18470. }
  18471. else
  18472. DEBUG_INFO("EOF\n");
  18473. fclose(fptr1);
  18474. /*------- End of reading ---------------*/
  18475. return temptransactionId;
  18476. }
  18477. void SetTransactionIdZero(int transactionId)
  18478. {
  18479. char ch;
  18480. FILE *fptr1, *fptr2;
  18481. int temptransactionId = 0;
  18482. char str[100]={0}, strtemp[100]={0}, temp[] = "/Storage/OCPP/QueueTransactionIdtemp.json";
  18483. fptr1 = fopen("/Storage/OCPP/QueueTransactionId", "r");
  18484. if (!fptr1)
  18485. {
  18486. //printf(" File not found or unable to open the input file!!\n");
  18487. return ;
  18488. }
  18489. fptr2 = fopen(temp, "w"); // open the temporary file in write mode
  18490. if (!fptr2)
  18491. {
  18492. DEBUG_INFO("Unable to open a temporary file to write!!\n");
  18493. fclose(fptr1);
  18494. return ;
  18495. }
  18496. ch=fgetc(fptr1);
  18497. rewind(fptr1);
  18498. if(ch!=EOF)
  18499. {
  18500. // copy all contents to the temporary file except the specific line
  18501. while (fgets(str, 100, fptr1) != NULL)
  18502. {
  18503. str[strlen(str) - 1] = '\0'; // eat the newline fgets() stores
  18504. if(str[0]=='\0')
  18505. {
  18506. break;
  18507. }
  18508. char *revbuf[8] = {0};
  18509. int num = 0;
  18510. strcpy(strtemp, str);
  18511. splitstring(str,",",revbuf,&num);
  18512. if(revbuf[2][0] != '\0')
  18513. {
  18514. temptransactionId = atoi(revbuf[2]);
  18515. if(transactionId != temptransactionId)
  18516. {
  18517. fprintf(fptr2, "%s\n", strtemp);
  18518. }
  18519. }
  18520. }
  18521. }
  18522. fclose(fptr1);
  18523. fclose(fptr2);
  18524. remove("/Storage/OCPP/QueueTransactionId"); // remove the original file
  18525. rename(temp, "/Storage/OCPP/QueueTransactionId"); // rename the temporary file to original name
  18526. /*------ Read the file ----------------*/
  18527. }
  18528. int InternetDisconnect(void)
  18529. {
  18530. return (ShmStatusCodeData->InfoCode.InfoEvents.bits.InternetDisconnectVia4Gi && ShmStatusCodeData->InfoCode.InfoEvents.bits.InternetDisconnectViaEthernet && ShmStatusCodeData->InfoCode.InfoEvents.bits.InternetDisconnectViaWiFi );
  18531. }
  18532. //Note: It is not real StopTransaction. It is temporary StopTransaction.
  18533. void storeTempStopTransaction(int gun_index)
  18534. {
  18535. char guid[37]={0};
  18536. int tempIndex = 0;
  18537. char TempStopTransaction[256];
  18538. sprintf(TempStopTransaction, "/Storage/OCPP/TempStopTransaction_%d", (gun_index+1));
  18539. DEBUG_INFO("storeTempStopTransaction...\n");
  18540. memset(queuedata, 0, ARRAY_SIZE(queuedata));
  18541. memset(&ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0], 0, ARRAY_SIZE(ShmOCPP16Data->StopTransaction[gun_index].TransactionData));
  18542. //======================== ENERGY_ACTIVE_IMPORT_REGISTER =======================================
  18543. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DCcc
  18544. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  18545. {
  18546. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  18547. {
  18548. tempIndex = ((gun_index==2) ? 1: 0);
  18549. }
  18550. else
  18551. {
  18552. tempIndex = gun_index;
  18553. }
  18554. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  18555. {
  18556. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  18557. {
  18558. ShmOCPP16Data->StopTransaction[gun_index].MeterStop = (int)(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PowerConsumption*1000);
  18559. }
  18560. }// END OF CHAdeMO_QUANTITY
  18561. }
  18562. else if(gunType[gun_index] == GUN_TYPE_CCS)
  18563. {
  18564. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  18565. {
  18566. tempIndex = ((gun_index==2) ? 1: 0);
  18567. }
  18568. else
  18569. {
  18570. tempIndex = gun_index;
  18571. }
  18572. for (int index = 0; index < CCS_QUANTITY; index++)
  18573. {
  18574. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  18575. {
  18576. ShmOCPP16Data->StopTransaction[gun_index].MeterStop = (int)(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PowerConsumption*1000);
  18577. }
  18578. }// END OF CCS_QUANTITY
  18579. }
  18580. else if(gunType[gun_index] == GUN_TYPE_GBT)
  18581. {
  18582. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  18583. {
  18584. tempIndex = ((gun_index==2) ? 1: 0);
  18585. }
  18586. else
  18587. {
  18588. tempIndex = gun_index;
  18589. }
  18590. for (int index = 0; index < GB_QUANTITY; index++)
  18591. {
  18592. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  18593. {
  18594. ShmOCPP16Data->StopTransaction[gun_index].MeterStop = (int)(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PowerConsumption*1000);
  18595. }
  18596. }// END OF GB_QUANTITY
  18597. }
  18598. else if(gunType[gun_index] == GUN_TYPE_DO)
  18599. {
  18600. tempIndex = gun_index;
  18601. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  18602. {
  18603. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  18604. {
  18605. ShmOCPP16Data->StopTransaction[gun_index].MeterStop = (int)(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PowerConsumption*1000);
  18606. }
  18607. }
  18608. }
  18609. else
  18610. {
  18611. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  18612. {
  18613. tempIndex = 2;
  18614. }
  18615. else
  18616. {
  18617. tempIndex = gun_index;
  18618. }
  18619. for (int index = 0; index < AC_QUANTITY; index++)
  18620. {
  18621. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  18622. {
  18623. ShmOCPP16Data->StopTransaction[gun_index].MeterStop = (int)(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PowerConsumption*1000);
  18624. }
  18625. }// END OF AC_QUANTITY
  18626. }
  18627. //Stop Transaction Time
  18628. struct timeval tmnow;
  18629. struct tm *tm;
  18630. char buf[28];//, usec_buf[6];
  18631. gettimeofday(&tmnow, NULL);
  18632. time_t t;
  18633. t = time(NULL);
  18634. /*UTC time and date*/
  18635. tm = gmtime(&t);
  18636. strftime(buf,28,"%Y-%m-%dT%H:%M:%SZ", tm);
  18637. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].Timestamp,buf);
  18638. ShmOCPP16Data->StopTransaction[gun_index].TransactionId = ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId;
  18639. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].IdTag, (const char*)ShmOCPP16Data->StartTransaction[gun_index].IdTag);
  18640. random_uuid(guid);
  18641. /***********************************transactionData******************************************************/
  18642. memset(ShmOCPP16Data->StopTransaction[gun_index].TransactionData, 0, sizeof(struct StructMeterValue));
  18643. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].TimeStamp, buf);
  18644. //=================================
  18645. //1. Transaction_Begin
  18646. //=================================
  18647. //============================== Energy.Active.Import.Interval ===========================================
  18648. //=================================
  18649. //2. Transaction_End
  18650. //=================================
  18651. //2.1====================================== Current.Import L1 ==============================================
  18652. if(strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Current.Import") != NULL)
  18653. {
  18654. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G : GBT DC
  18655. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  18656. {
  18657. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  18658. {
  18659. tempIndex = ((gun_index==2) ? 1: 0);
  18660. }
  18661. else
  18662. {
  18663. tempIndex = gun_index;
  18664. }
  18665. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  18666. {
  18667. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  18668. {
  18669. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargingCurrent );// PresentChargingCurrent is 0~6553.5 amp
  18670. }
  18671. }// End of for CHAdeMO_QUANTITY
  18672. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase,PhaseStr[L3_N]);
  18673. }
  18674. else if(gunType[gun_index] == GUN_TYPE_CCS)
  18675. {
  18676. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  18677. {
  18678. tempIndex = ((gun_index==2) ? 1: 0);
  18679. }
  18680. else
  18681. {
  18682. tempIndex = gun_index;
  18683. }
  18684. for (int index = 0; index < CCS_QUANTITY; index++)
  18685. {
  18686. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  18687. {
  18688. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargingCurrent );// PresentChargingCurrent is 0~6553.5 amp
  18689. }
  18690. }// End of for CCS_QUANTITY
  18691. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase,PhaseStr[L3_N]);
  18692. }
  18693. else if(gunType[gun_index] == GUN_TYPE_GBT)
  18694. {
  18695. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  18696. {
  18697. tempIndex = ((gun_index==2) ? 1: 0);
  18698. }
  18699. else
  18700. {
  18701. tempIndex = gun_index;
  18702. }
  18703. for (int index = 0; index < GB_QUANTITY; index++)
  18704. {
  18705. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  18706. {
  18707. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingCurrent );// PresentChargingCurrent is 0~6553.5 amp
  18708. }
  18709. }// End of for GB_QUANTITY
  18710. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase,PhaseStr[L3_N]);
  18711. }
  18712. else if(gunType[gun_index] == GUN_TYPE_DO)
  18713. {
  18714. tempIndex = gun_index;
  18715. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  18716. {
  18717. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  18718. {
  18719. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PresentChargingCurrent );// PresentChargingCurrent is 0~6553.5 amp
  18720. }
  18721. }
  18722. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase,PhaseStr[L3_N]);
  18723. }
  18724. else
  18725. {
  18726. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  18727. {
  18728. tempIndex = 2;
  18729. }
  18730. else
  18731. {
  18732. tempIndex = gun_index;
  18733. }
  18734. for (int index = 0; index < AC_QUANTITY; index++)
  18735. {
  18736. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  18737. {
  18738. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingCurrent );// 0~6553.5 amp for EVSE
  18739. }
  18740. }// End of for AC_QUANTITY
  18741. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase,PhaseStr[L1_N]);
  18742. }
  18743. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  18744. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Format,ValueFormatStr[Raw]);
  18745. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Measurand,MeasurandStr[Current_Import]);
  18746. //strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase,PhaseStr[L1_N]);
  18747. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Location,LocationStr[Location_Outlet]);
  18748. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Unit,UnitOfMeasureStr[UnitOfMeasure_A]);
  18749. }
  18750. //2.2===================================== Energy.Active.Import.Interval ==========================================
  18751. if(strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Energy.Active.Import.Interval") != NULL)
  18752. {
  18753. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  18754. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  18755. {
  18756. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  18757. {
  18758. tempIndex = ((gun_index==2) ? 1: 0);
  18759. }
  18760. else
  18761. {
  18762. tempIndex = gun_index;
  18763. }
  18764. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  18765. {
  18766. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  18767. {
  18768. 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
  18769. }
  18770. }// END OF CHAdeMO_QUANTITY
  18771. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase,PhaseStr[L3_N]);
  18772. }
  18773. else if(gunType[gun_index] == GUN_TYPE_CCS)
  18774. {
  18775. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  18776. {
  18777. tempIndex = ((gun_index==2) ? 1: 0);
  18778. }
  18779. else
  18780. {
  18781. tempIndex = gun_index;
  18782. }
  18783. for (int index = 0; index < CCS_QUANTITY; index++)
  18784. {
  18785. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  18786. {
  18787. 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
  18788. }
  18789. }// END OF CCS_QUANTITY
  18790. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase,PhaseStr[L3_N]);
  18791. }
  18792. else if(gunType[gun_index] == GUN_TYPE_GBT)
  18793. {
  18794. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  18795. {
  18796. tempIndex = ((gun_index==2) ? 1: 0);
  18797. }
  18798. else
  18799. {
  18800. tempIndex = gun_index;
  18801. }
  18802. for (int index = 0; index < GB_QUANTITY; index++)
  18803. {
  18804. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  18805. {
  18806. 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
  18807. }
  18808. }// END OF GB_QUANTITY
  18809. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase,PhaseStr[L3_N]);
  18810. }
  18811. else if(gunType[gun_index] == GUN_TYPE_DO)
  18812. {
  18813. tempIndex = gun_index;
  18814. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  18815. {
  18816. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  18817. {
  18818. 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
  18819. }
  18820. }
  18821. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase,PhaseStr[L3_N]);
  18822. }
  18823. else
  18824. {
  18825. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  18826. {
  18827. tempIndex = 2;
  18828. }
  18829. else
  18830. {
  18831. tempIndex = gun_index;
  18832. }
  18833. for (int index = 0; index < AC_QUANTITY; index++)
  18834. {
  18835. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  18836. {
  18837. 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
  18838. }
  18839. }// END OF AC_QUANTITY
  18840. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase,PhaseStr[L1_N]);
  18841. }
  18842. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  18843. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Format,ValueFormatStr[Raw]);
  18844. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Measurand,MeasurandStr[Energy_Active_Import_Interval]);
  18845. //strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase,PhaseStr[L1_N]);
  18846. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Location,LocationStr[Location_Outlet]);
  18847. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Unit,UnitOfMeasureStr[UnitOfMeasure_kWh]);
  18848. }
  18849. //2.3====================================== Power.Active.Import =========================================
  18850. if(strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Power.Active.Import") != NULL)
  18851. {
  18852. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  18853. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  18854. {
  18855. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  18856. {
  18857. tempIndex = ((gun_index==2) ? 1: 0);
  18858. }
  18859. else
  18860. {
  18861. tempIndex = gun_index;
  18862. }
  18863. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  18864. {
  18865. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  18866. {
  18867. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargingPower );// PresentChargingPower is 0~6553.5 kW
  18868. }
  18869. } // End for CHAdeMO_QUANTITY
  18870. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase,PhaseStr[L3_N]);
  18871. }
  18872. else if(gunType[gun_index] == GUN_TYPE_CCS)
  18873. {
  18874. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  18875. {
  18876. tempIndex = ((gun_index==2) ? 1: 0);
  18877. }
  18878. else
  18879. {
  18880. tempIndex = gun_index;
  18881. }
  18882. for (int index = 0; index < CCS_QUANTITY; index++)
  18883. {
  18884. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  18885. {
  18886. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargingPower );// PresentChargingPower is 0~6553.5 kW
  18887. }
  18888. } // END for CCS_QUANTITY
  18889. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase,PhaseStr[L3_N]);
  18890. }
  18891. else if(gunType[gun_index] == GUN_TYPE_GBT)
  18892. {
  18893. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  18894. {
  18895. tempIndex = ((gun_index==2) ? 1: 0);
  18896. }
  18897. else
  18898. {
  18899. tempIndex = gun_index;
  18900. }
  18901. for (int index = 0; index < GB_QUANTITY; index++)
  18902. {
  18903. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  18904. {
  18905. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingPower );// PresentChargingPower is 0~6553.5 kW
  18906. }
  18907. }// END for GB_QUANTITY
  18908. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase,PhaseStr[L3_N]);
  18909. }
  18910. else if(gunType[gun_index] == GUN_TYPE_DO)
  18911. {
  18912. tempIndex = gun_index;
  18913. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  18914. {
  18915. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  18916. {
  18917. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PresentChargingPower );// PresentChargingPower is 0~6553.5 kW
  18918. }
  18919. }
  18920. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase,PhaseStr[L3_N]);
  18921. }
  18922. else
  18923. {
  18924. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  18925. {
  18926. tempIndex = 2;
  18927. }
  18928. else
  18929. {
  18930. tempIndex = gun_index;
  18931. }
  18932. for (int index = 0; index < AC_QUANTITY; index++)
  18933. {
  18934. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  18935. {
  18936. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingPower );// PresentChargingPower is 0~6553.5 kW
  18937. }
  18938. } // END for AC_QUANTITY
  18939. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase,PhaseStr[L1_N]);
  18940. }
  18941. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  18942. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Format,ValueFormatStr[Raw]);
  18943. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Measurand,MeasurandStr[Power_Active_Import]);
  18944. //strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase,PhaseStr[L1_N]);
  18945. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Location,LocationStr[Location_Outlet]);
  18946. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Unit,UnitOfMeasureStr[UnitOfMeasure_kW/*UnitOfMeasure_kWh*/]);
  18947. }
  18948. //2.4====================================== Voltage L1 ====================================================
  18949. if(strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Voltage") != NULL)
  18950. {
  18951. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  18952. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  18953. {
  18954. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  18955. {
  18956. tempIndex = ((gun_index==2) ? 1: 0);
  18957. }
  18958. else
  18959. {
  18960. tempIndex = gun_index;
  18961. }
  18962. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  18963. {
  18964. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  18965. {
  18966. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargingVoltage );// PresentChargingVoltage is 0~6553.5 volt
  18967. }
  18968. } // END OF FOR CHAdeMO_QUANTITY
  18969. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase,PhaseStr[L3_N]);
  18970. }
  18971. else if(gunType[gun_index] == GUN_TYPE_CCS)
  18972. {
  18973. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  18974. {
  18975. tempIndex = ((gun_index==2) ? 1: 0);
  18976. }
  18977. else
  18978. {
  18979. tempIndex = gun_index;
  18980. }
  18981. for (int index = 0; index < CCS_QUANTITY; index++)
  18982. {
  18983. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  18984. {
  18985. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargingVoltage );// PresentChargingVoltage is 0~6553.5 volt
  18986. }
  18987. } // END OF FOR CCS_QUANTITY
  18988. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase,PhaseStr[L3_N]);
  18989. }
  18990. else if(gunType[gun_index] == GUN_TYPE_GBT)
  18991. {
  18992. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  18993. {
  18994. tempIndex = ((gun_index==2) ? 1: 0);
  18995. }
  18996. else
  18997. {
  18998. tempIndex = gun_index;
  18999. }
  19000. for (int index = 0; index < GB_QUANTITY; index++)
  19001. {
  19002. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  19003. {
  19004. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingVoltage );// PresentChargingVoltage is 0~6553.5 volt
  19005. }
  19006. } // END OF FOR GB_QUANTITY
  19007. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase,PhaseStr[L3_N]);
  19008. }
  19009. else if(gunType[gun_index] == GUN_TYPE_DO)
  19010. {
  19011. tempIndex = gun_index;
  19012. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  19013. {
  19014. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  19015. {
  19016. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PresentChargingVoltage );// PresentChargingVoltage is 0~6553.5 volt
  19017. }
  19018. }
  19019. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase,PhaseStr[L3_N]);
  19020. }
  19021. else
  19022. {
  19023. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  19024. {
  19025. tempIndex = 2;
  19026. }
  19027. else
  19028. {
  19029. tempIndex = gun_index;
  19030. }
  19031. for (int index = 0; index < AC_QUANTITY; index++)
  19032. {
  19033. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  19034. {
  19035. 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
  19036. }
  19037. } // END OF FOR AC_QUANTITY
  19038. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase,PhaseStr[L1_N]);
  19039. }
  19040. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  19041. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Format,ValueFormatStr[Raw]);
  19042. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Measurand,MeasurandStr[Voltage]);
  19043. //strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase,PhaseStr[L1_N]);
  19044. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Location,LocationStr[Location_Outlet]);
  19045. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Unit,UnitOfMeasureStr[UnitOfMeasure_V]);
  19046. }
  19047. //2.5============================================== End SoC =========================================================
  19048. if(strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, MeasurandStr[SoC]) != NULL)
  19049. {
  19050. //J : CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  19051. 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))
  19052. {
  19053. if((ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0') && (gunType[gun_index] != GUN_TYPE_DO))
  19054. {
  19055. tempIndex = ((gun_index==2) ? 1: 0);
  19056. }
  19057. else
  19058. {
  19059. tempIndex = gun_index;
  19060. }
  19061. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  19062. {
  19063. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  19064. {
  19065. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  19066. {
  19067. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].EvBatterySoc );// 0~100%
  19068. }
  19069. }
  19070. }
  19071. else if(gunType[gun_index] == GUN_TYPE_CCS)
  19072. {
  19073. for (int index = 0; index < CCS_QUANTITY; index++)
  19074. {
  19075. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  19076. {
  19077. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].EvBatterySoc );// 0~100%
  19078. }
  19079. }
  19080. }
  19081. else if(gunType[gun_index] == GUN_TYPE_GBT)
  19082. {
  19083. for (int index = 0; index < GB_QUANTITY; index++)
  19084. {
  19085. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  19086. {
  19087. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].EvBatterySoc );// 0~100%
  19088. }
  19089. }
  19090. }
  19091. else if(gunType[gun_index] == GUN_TYPE_DO)
  19092. {
  19093. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  19094. {
  19095. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  19096. {
  19097. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.EvBatterySoc );// 0~100%
  19098. }
  19099. }
  19100. }
  19101. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  19102. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Format,ValueFormatStr[Raw]);
  19103. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Measurand,MeasurandStr[SoC/*Energy_Reactive_Export_Register*/]);
  19104. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Phase,PhaseStr[L3_N]);
  19105. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Location,LocationStr[Location_EV]);
  19106. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Unit,UnitOfMeasureStr[UnitOfMeasure_Percent/*UnitOfMeasure_kWh*/]);
  19107. } // END FOR DC CASE
  19108. }
  19109. //2.6====================================== Current.Import L2 ==============================================
  19110. if(strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Current.Import") != NULL)
  19111. {
  19112. // AC 3 phase L2 current
  19113. if((gunType[gun_index] == GUN_TYPE_AC) && ((ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'W') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='D')))
  19114. {
  19115. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  19116. {
  19117. tempIndex = 2;
  19118. }
  19119. else
  19120. {
  19121. tempIndex = gun_index;
  19122. }
  19123. for (int index = 0; index < AC_QUANTITY; index++)
  19124. {
  19125. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  19126. {
  19127. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingCurrentL2);// 0~6553.5 amp for EVSE
  19128. }
  19129. }// End of for AC_QUANTITY
  19130. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Phase,PhaseStr[L2_N]);
  19131. }
  19132. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  19133. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Format,ValueFormatStr[Raw]);
  19134. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Measurand,MeasurandStr[Current_Import]);
  19135. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Location,LocationStr[Location_Outlet]);
  19136. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Unit,UnitOfMeasureStr[UnitOfMeasure_A]);
  19137. }
  19138. //2.7====================================== Current.Import L3 ==============================================
  19139. if(strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Current.Import") != NULL)
  19140. {
  19141. // AC 3 phase L3 current
  19142. if((gunType[gun_index] == GUN_TYPE_AC) && ((ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'W') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='D')))
  19143. {
  19144. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  19145. {
  19146. tempIndex = 2;
  19147. }
  19148. else
  19149. {
  19150. tempIndex = gun_index;
  19151. }
  19152. for (int index = 0; index < AC_QUANTITY; index++)
  19153. {
  19154. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  19155. {
  19156. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingCurrentL3);// 0~6553.5 amp for EVSE
  19157. }
  19158. }// End of for AC_QUANTITY
  19159. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Phase,PhaseStr[L3_N]);
  19160. }
  19161. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  19162. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Format,ValueFormatStr[Raw]);
  19163. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Measurand,MeasurandStr[Current_Import]);
  19164. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Location,LocationStr[Location_Outlet]);
  19165. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Unit,UnitOfMeasureStr[UnitOfMeasure_A]);
  19166. }
  19167. //2.9====================================== Voltage L2 ====================================================
  19168. if(strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Voltage") != NULL)
  19169. {
  19170. // AC 3 phase L2 volatge
  19171. if((gunType[gun_index] == GUN_TYPE_AC) && ((ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'W') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='D')))
  19172. {
  19173. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  19174. {
  19175. tempIndex = 2;
  19176. }
  19177. else
  19178. {
  19179. tempIndex = gun_index;
  19180. }
  19181. for (int index = 0; index < AC_QUANTITY; index++)
  19182. {
  19183. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  19184. {
  19185. 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
  19186. }
  19187. } // END OF FOR AC_QUANTITY
  19188. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Phase,PhaseStr[L2_N]);
  19189. }
  19190. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  19191. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Format,ValueFormatStr[Raw]);
  19192. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Measurand,MeasurandStr[Voltage]);
  19193. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Location,LocationStr[Location_Outlet]);
  19194. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Unit,UnitOfMeasureStr[UnitOfMeasure_V]);
  19195. }
  19196. //2.10====================================== Voltage L3 ====================================================
  19197. if(strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Voltage") != NULL)
  19198. {
  19199. // AC 3 phase L3 volatge
  19200. if((gunType[gun_index] == GUN_TYPE_AC) && ((ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'W') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='D')))
  19201. {
  19202. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  19203. {
  19204. tempIndex = 2;
  19205. }
  19206. else
  19207. {
  19208. tempIndex = gun_index;
  19209. }
  19210. for (int index = 0; index < AC_QUANTITY; index++)
  19211. {
  19212. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  19213. {
  19214. 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
  19215. }
  19216. } // END OF FOR AC_QUANTITY
  19217. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Phase,PhaseStr[L3_N]);
  19218. }
  19219. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  19220. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Format,ValueFormatStr[Raw]);
  19221. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Measurand,MeasurandStr[Voltage]);
  19222. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Location,LocationStr[Location_Outlet]);
  19223. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Unit,UnitOfMeasureStr[UnitOfMeasure_V]);
  19224. }
  19225. //====================== Start SoC ================================
  19226. if(strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, MeasurandStr[SoC]) != NULL)
  19227. {
  19228. //J : CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  19229. 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))
  19230. {
  19231. if((ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0') && (gunType[gun_index] != GUN_TYPE_DO))
  19232. {
  19233. tempIndex = ((gun_index==2) ? 1: 0);
  19234. }
  19235. else
  19236. {
  19237. tempIndex = gun_index;
  19238. }
  19239. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  19240. {
  19241. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  19242. {
  19243. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  19244. {
  19245. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].EvBatteryStartSoc );// 0~100%
  19246. }
  19247. }
  19248. }
  19249. else if(gunType[gun_index] == GUN_TYPE_CCS)
  19250. {
  19251. for (int index = 0; index < CCS_QUANTITY; index++)
  19252. {
  19253. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  19254. {
  19255. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].EvBatteryStartSoc );// 0~100%
  19256. }
  19257. }
  19258. }
  19259. else if(gunType[gun_index] == GUN_TYPE_GBT)
  19260. {
  19261. for (int index = 0; index < GB_QUANTITY; index++)
  19262. {
  19263. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  19264. {
  19265. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].EvBatteryStartSoc );// 0~100%
  19266. }
  19267. }
  19268. }
  19269. else if(gunType[gun_index] == GUN_TYPE_DO)
  19270. {
  19271. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  19272. {
  19273. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  19274. {
  19275. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.EvBatteryStartSoc );// 0~100%
  19276. }
  19277. }
  19278. }
  19279. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Context,ReadingContextStr[ReadingContext_Transaction_Begin]);
  19280. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Format,ValueFormatStr[Raw]);
  19281. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Measurand,MeasurandStr[SoC/*Energy_Reactive_Export_Register*/]);
  19282. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Phase,PhaseStr[L3_N]);
  19283. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Location,LocationStr[Location_EV]);
  19284. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Unit,UnitOfMeasureStr[UnitOfMeasure_Percent/*UnitOfMeasure_kWh*/]);
  19285. } // END FOR DC CASE
  19286. }
  19287. //======================================== Message create ==============================================
  19288. json_object *StopTransaction = json_object_new_object();
  19289. json_object *transactionDatas = json_object_new_array();
  19290. json_object *sampledValues = json_object_new_array();
  19291. if(strlen((char*)ShmOCPP16Data->StopTransaction[gun_index].IdTag) > 0)
  19292. json_object_object_add(StopTransaction, "idTag", json_object_new_string((char*)ShmOCPP16Data->StopTransaction[gun_index].IdTag));
  19293. json_object_object_add(StopTransaction, "meterStop", json_object_new_int(ShmOCPP16Data->StopTransaction[gun_index].MeterStop));
  19294. json_object_object_add(StopTransaction, "transactionId", json_object_new_int(ShmOCPP16Data->StopTransaction[gun_index].TransactionId));
  19295. json_object_object_add(StopTransaction, "timestamp", json_object_new_string((char*)ShmOCPP16Data->StopTransaction[gun_index].Timestamp));
  19296. json_object_object_add(StopTransaction, "reason", json_object_new_string("PowerLoss"));
  19297. for(int idxTrans = 0;idxTrans<ARRAY_SIZE(ShmOCPP16Data->StopTransaction[gun_index].TransactionData);idxTrans++)
  19298. {
  19299. json_object *transactionData = json_object_new_object();
  19300. json_object_object_add(transactionData, "timestamp", json_object_new_string((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].TimeStamp));
  19301. for(int idx=0;idx<ARRAY_SIZE(ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue);idx++)
  19302. {
  19303. if(strlen((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Value) > 0)
  19304. {
  19305. json_object *sampledValue = json_object_new_object();
  19306. json_object_object_add(sampledValue, "value", json_object_new_string((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Value));
  19307. if(strlen((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Context) > 0)
  19308. json_object_object_add(sampledValue, "context", json_object_new_string((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Context));
  19309. if(strlen((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Format) > 0)
  19310. json_object_object_add(sampledValue, "format", json_object_new_string((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Format));
  19311. if(strlen((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Measurand) > 0)
  19312. json_object_object_add(sampledValue, "measurand", json_object_new_string((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Measurand));
  19313. if(strlen((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Phase) > 0)
  19314. json_object_object_add(sampledValue, "phase", json_object_new_string((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Phase));
  19315. if(strlen((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Location) > 0)
  19316. json_object_object_add(sampledValue, "location", json_object_new_string((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Location));
  19317. if(strlen((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Unit) > 0)
  19318. json_object_object_add(sampledValue, "unit", json_object_new_string((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Unit));
  19319. json_object_array_add(sampledValues, sampledValue);
  19320. }
  19321. }
  19322. json_object_object_add(transactionData, "sampledValue", sampledValues);
  19323. json_object_array_add(transactionDatas, transactionData);
  19324. }
  19325. json_object_object_add(StopTransaction, "transactionData", transactionDatas);
  19326. sprintf(queuedata, "%d,[%d,\"%s\",\"StopTransaction\",%s]",(gun_index+1)
  19327. ,MESSAGE_TYPE_CALL
  19328. ,guid
  19329. ,json_object_to_json_string_ext(StopTransaction, JSON_C_TO_STRING_PLAIN));
  19330. json_object_put(StopTransaction);
  19331. // Check File "TempStopTransaction" Exist
  19332. if((access(TempStopTransaction,F_OK))!=-1)
  19333. {
  19334. //DEBUG_INFO("TransactionRelatedQueue exist.\n");
  19335. fclose(fopen(TempStopTransaction, "w"));
  19336. }
  19337. else
  19338. {
  19339. //DEBUG_INFO("TransactionRelatedQueue not exist\n");
  19340. FILE *log = fopen(TempStopTransaction, "w+");
  19341. if(log == NULL)
  19342. {
  19343. //DEBUG_INFO("Can't Create File TransactionRelatedQueue \n");
  19344. return ;
  19345. }
  19346. else
  19347. {
  19348. fclose(log);
  19349. }
  19350. }
  19351. //Add TempStopTransaction | Update TempStopTransaction
  19352. // open file for writing
  19353. FILE *outfile;
  19354. outfile = fopen (TempStopTransaction, "a");
  19355. //DEBUG_INFO("data = %s\n", queuedata);
  19356. fputs(queuedata, outfile);
  19357. fputs("\n", outfile);
  19358. fclose (outfile);
  19359. system("/bin/fsync -d /dev/mtdblock13;/bin/sync &");
  19360. OCPP_updatePeriodEnergy(gun_index);
  19361. }
  19362. void checkTempStopTransaction(int gun_index)
  19363. {
  19364. FILE *fptr1;
  19365. char ch;
  19366. char str[QUEUE_MESSAGE_LENGTH]={0};
  19367. char guid[37]={0};
  19368. char tempdata[65]={0};
  19369. char connectorStr[2]={0};
  19370. char TempStopTransaction[256];
  19371. sprintf(TempStopTransaction, "/Storage/OCPP/TempStopTransaction_%d", (gun_index+1));
  19372. fptr1 = fopen(TempStopTransaction, "r");
  19373. //TempStopTransaction格式: 槍號,StopTransaction封包
  19374. if (!fptr1)
  19375. {
  19376. //printf(" File not found or unable to open the input file!!\n");
  19377. return ;
  19378. }
  19379. ch=fgetc(fptr1);
  19380. //printf(" Now the content of the file %s is : \n",fname);
  19381. rewind(fptr1);
  19382. if(ch!=EOF)
  19383. {
  19384. // copy all contents to the temporary file except the specific line
  19385. while (fgets(str, QUEUE_MESSAGE_LENGTH, fptr1) != NULL)
  19386. {
  19387. str[strlen(str) - 1] = '\0'; // eat the newline fgets() stores
  19388. if(str[0]=='\0')
  19389. {
  19390. break;
  19391. }
  19392. //TempStopTransaction格式: 槍號,StopTransaction封包
  19393. strncpy(connectorStr, str, 1);
  19394. if(atoi(connectorStr) != (gun_index+1))
  19395. {
  19396. DEBUG_INFO("atoi(connectorStr) = %d, gun_index = %d\n", atoi(connectorStr), gun_index);
  19397. fclose(fptr1);
  19398. return ;
  19399. }
  19400. //random_uuid(guid);
  19401. strncpy(guid, str+6, 36); //copy guid
  19402. sprintf(tempdata, "StopTransaction,%d", (gun_index));
  19403. if(hashmap_operation(HASH_OP_ADD, guid, tempdata) == 1)
  19404. {
  19405. //DEBUG_INFO("StopTransaction mapitem pass\n");
  19406. }
  19407. queue_operation(QUEUE_OPERATION_ADD, guid, str);//addq(guid, queuedata); ---> remove temporally
  19408. OCPP_insert_transaction_msg(NO, str);
  19409. memset(str,0,ARRAY_SIZE(str));
  19410. }
  19411. }
  19412. // fptr1=freopen(NULL,"w",fptr1); // reset the fptr1 again
  19413. fclose(fptr1);
  19414. remove(TempStopTransaction); // remove the original file
  19415. system("/bin/fsync -d /dev/mtdblock13;/bin/sync &");
  19416. }
  19417. void FillStartTransaction(int ConnectorId, unsigned char IdTag[], int MeterStart,int ReservationId,unsigned char Timestamp[])
  19418. {
  19419. ShmOCPP16Data->StartTransaction[ConnectorId-1].ConnectorId = ConnectorId;
  19420. ShmOCPP16Data->StartTransaction[ConnectorId-1].ReservationId = ReservationId;
  19421. ShmOCPP16Data->StartTransaction[ConnectorId-1].MeterStart = MeterStart;
  19422. strcpy((char *)ShmOCPP16Data->StartTransaction[ConnectorId-1].IdTag, (char *)IdTag);
  19423. strcpy((char *)ShmOCPP16Data->StartTransaction[ConnectorId-1].Timestamp,(char *) Timestamp);
  19424. }
  19425. int GetWebSocketPingInterval(void)
  19426. {
  19427. return atoi((const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemData);
  19428. }
  19429. int GetServerSign(void)
  19430. {
  19431. return server_sign;
  19432. }
  19433. uint8_t GetOcppSecurityProfile()
  19434. {
  19435. return atoi((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[SecurityProfile].ItemData);
  19436. }
  19437. void GetOcppChargerBoxId(uint8_t *data)
  19438. {
  19439. sprintf((char*)data, "%s", ShmSysConfigAndInfo->SysConfig.ChargeBoxId);
  19440. }
  19441. void GetOcppSecurityPassword(uint8_t *data)
  19442. {
  19443. sprintf((char*)data, "%s", ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationKey].ItemData);
  19444. }
  19445. void SetOcppVersion(uint8_t *version)
  19446. {
  19447. for (uint8_t idx=0; idx<strlen((char*)version); idx++) version[idx] = tolower(version[idx]);
  19448. DEBUG_INFO("ocpp version: %s\n", version);
  19449. if(strstr((char*)version, "ocpp1.6") != NULL)
  19450. {
  19451. ShmSysConfigAndInfo->SysInfo.OcppRunningVer = OCPP_RUNNING_VERSION_16;
  19452. }
  19453. else if(strstr((char*)version, "ocpp2.0") != NULL)
  19454. {
  19455. ShmSysConfigAndInfo->SysInfo.OcppRunningVer = OCPP_RUNNING_VERSION_20;
  19456. system("pkill OcppBackend");
  19457. }
  19458. }
  19459. void SetServerSign(int value)
  19460. {
  19461. server_sign = value;
  19462. }
  19463. int GetBootNotificationInterval(void)
  19464. {
  19465. return BootNotificationInterval;
  19466. }
  19467. int GetInternetConn(void)
  19468. {
  19469. return ShmSysConfigAndInfo->SysInfo.InternetConn;
  19470. }
  19471. int GetBackendConnectionTimeout(void)
  19472. {
  19473. return ShmSysConfigAndInfo->SysConfig.BackendConnTimeout>=0?ShmSysConfigAndInfo->SysConfig.BackendConnTimeout:300;
  19474. }
  19475. int isConnectorInitMode(int gun_index)
  19476. {
  19477. int tempIndex = 0;
  19478. int result = TRUE;
  19479. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DCcc
  19480. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  19481. {
  19482. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  19483. {
  19484. tempIndex = ((gun_index==2) ? 1: 0);
  19485. }
  19486. else
  19487. {
  19488. tempIndex = gun_index;
  19489. }
  19490. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  19491. {
  19492. if ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex))
  19493. {
  19494. result = (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus==SYS_MODE_BOOTING)?TRUE:FALSE;
  19495. } //end of the same index
  19496. }//end of for CHAdeMO_QUANTITY
  19497. }
  19498. else if(gunType[gun_index] == GUN_TYPE_CCS)
  19499. {
  19500. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  19501. {
  19502. tempIndex = ((gun_index==2) ? 1: 0);
  19503. }
  19504. else
  19505. {
  19506. tempIndex = gun_index;
  19507. }
  19508. for (int index = 0; index < CCS_QUANTITY; index++)
  19509. {
  19510. if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  19511. {
  19512. result = (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus==SYS_MODE_BOOTING)?TRUE:FALSE;
  19513. } //end of the same index
  19514. } // end of for CCS_QUANTITY
  19515. }
  19516. else if(gunType[gun_index] == GUN_TYPE_GBT)
  19517. {
  19518. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  19519. {
  19520. tempIndex = ((gun_index==2) ? 1: 0);
  19521. }
  19522. else
  19523. {
  19524. tempIndex = gun_index;
  19525. }
  19526. for (int index = 0; index < GB_QUANTITY; index++)
  19527. {
  19528. if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  19529. {
  19530. result = (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus==SYS_MODE_BOOTING)?TRUE:FALSE;
  19531. } //end of the same index
  19532. } // end of for GB_QUANTITY
  19533. }
  19534. else if(gunType[gun_index] == GUN_TYPE_DO)
  19535. {
  19536. tempIndex = gun_index;
  19537. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  19538. {
  19539. if(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  19540. {
  19541. result = (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus==SYS_MODE_BOOTING)?TRUE:FALSE;
  19542. } //end of the same index
  19543. }
  19544. }
  19545. else
  19546. {
  19547. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  19548. {
  19549. tempIndex = 2;
  19550. }
  19551. else
  19552. {
  19553. tempIndex = gun_index;
  19554. }
  19555. for (int index = 0; index < AC_QUANTITY; index++)
  19556. {
  19557. if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  19558. {
  19559. result = (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus==SYS_MODE_BOOTING)?TRUE:FALSE;
  19560. }//end of the same index
  19561. }//end of for AC_QUANTITY
  19562. }
  19563. return result;
  19564. }
  19565. void refreshProcDogTimer()
  19566. {
  19567. ShmOCPP16Data->procDogTime = time((time_t*)NULL);
  19568. }
  19569. void InitialSystemValue(void)
  19570. {
  19571. server_cycle_Status = atoi((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemData);
  19572. locallistVersion=0;
  19573. BootNotificationInterval = 0;
  19574. authorizeRetryTimes = 0;
  19575. GunStatusInterval = 10;
  19576. TransactionMessageAttemptsValue = atoi((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData);
  19577. TransactionMessageRetryIntervalValue = atoi((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData);
  19578. //Hear Beat
  19579. HeartBeatWithNOResponse = 0;
  19580. HeartBeatWaitTime = atoi((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemData);;
  19581. FirstHeartBeat = 0;
  19582. FirmwareStatusNotificationStatus = FIRMWARE_STATUS_IDLE; // Idle
  19583. DiagnosticsStatusNotificationStatus = DIAGNOSTIC_STATUS_IDLE; // Idle
  19584. memset(CurrentChargingProfileScheduleStr, 0, ARRAY_SIZE(CurrentChargingProfileScheduleStr));
  19585. memset(ChademoPreviousSystemStatus, 0, ARRAY_SIZE(ChademoPreviousSystemStatus));
  19586. memset(CcsPreviousSystemStatus, 0, ARRAY_SIZE(CcsPreviousSystemStatus));
  19587. memset(GbPreviousSystemStatus, 0, ARRAY_SIZE(GbPreviousSystemStatus));
  19588. memset(AcPreviousSystemStatus, 0, ARRAY_SIZE(AcPreviousSystemStatus));
  19589. memset(ChademoPreviousConnectorPlugIn, 0, ARRAY_SIZE(ChademoPreviousConnectorPlugIn));
  19590. memset(CcsPreviousConnectorPlugIn, 0, ARRAY_SIZE(CcsPreviousConnectorPlugIn));
  19591. memset(GbPreviousConnectorPlugIn, 0, ARRAY_SIZE(GbPreviousConnectorPlugIn));
  19592. memset(AcPreviousConnectorPlugIn, 0, ARRAY_SIZE(AcPreviousConnectorPlugIn));
  19593. //Status && ConnectorPlugIn Setting
  19594. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  19595. {
  19596. ChademoPreviousSystemStatus[index] = 99; //ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PreviousSystemStatus;
  19597. ChademoPreviousConnectorPlugIn[index] = ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ConnectorPlugIn;
  19598. }
  19599. for (int index = 0; index < CCS_QUANTITY; index++)
  19600. {
  19601. CcsPreviousSystemStatus[index] = 99; //ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PreviousSystemStatus;
  19602. CcsPreviousConnectorPlugIn[index] = ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ConnectorPlugIn;
  19603. }
  19604. for (int index = 0; index < GB_QUANTITY; index++)
  19605. {
  19606. GbPreviousSystemStatus[index] = 99; //ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PreviousSystemStatus;
  19607. GbPreviousConnectorPlugIn[index] = ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ConnectorPlugIn;
  19608. }
  19609. for (int index = 0; index < AC_QUANTITY; index++)
  19610. {
  19611. AcPreviousSystemStatus[index] = 99; //ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PreviousSystemStatus;
  19612. AcPreviousConnectorPlugIn[index] = ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PilotState;
  19613. }
  19614. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  19615. {
  19616. DoPreviousSystemStatus[index] = 99; //ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PreviousSystemStatus;
  19617. DoPreviousConnectorPlugIn[index] = ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PilotState;
  19618. }
  19619. for(int gun_index=0; gun_index < gunTotalNumber; gun_index++ )
  19620. {
  19621. cpinitateMsg.bits[gun_index].TriggerStatusNotificationReq = 0;
  19622. cpinitateMsg.bits[gun_index].StatusNotificationReq = 0;
  19623. cpinitateMsg.bits[gun_index].StatusNotificationConf = 0;
  19624. //clientTime.MeterValues[gun_index] = time((time_t*)NULL);
  19625. //memset(&ShmOCPP16Data->StatusNotification[gun_index], 0x00, sizeof(struct StructStatusNotification));
  19626. memset(&ShmOCPP16Data->StatusNotification[gun_index].Status, 0x00, sizeof(ShmOCPP16Data->StatusNotification[gun_index].Status));
  19627. }
  19628. memset( (void *)unknownkey, 0, sizeof(unknownkey));
  19629. refreshStartTimer(&clientTime.Heartbeat);
  19630. sleep(1);
  19631. }
  19632. void LWS_Send(char *str)
  19633. {
  19634. //=====================================================
  19635. // Check InternetConn 0: disconnected, 1: connected
  19636. //====================================================
  19637. if(GetOcppConnStatus() == 0)
  19638. {
  19639. DEBUG_INFO("offline now !!!\n");
  19640. return;
  19641. }
  19642. // Only disable isWebsocketSendable operation initiated by charger
  19643. if((strstr((char*)str, "\"Authorize\"") != NULL)
  19644. || (strstr((char*)str, "\"BootNotification\"") != NULL)
  19645. || (strstr((char*)str, "\"DataTransfer\"") != NULL)
  19646. || (strstr((char*)str, "\"DiagnosticsStatusNotification\"") != NULL)
  19647. || (strstr((char*)str, "\"FirmwareStatusNotification\"") != NULL)
  19648. || (strstr((char*)str, "\"Heartbeat\"") != NULL)
  19649. || (strstr((char*)str, "\"MeterValues\"") != NULL)
  19650. || (strstr((char*)str, "\"StartTransaction\"") != NULL)
  19651. || (strstr((char*)str, "\"StatusNotification\"") != NULL)
  19652. || (strstr((char*)str, "\"StopTransaction\"") != NULL)
  19653. || (strstr((char*)str, "\"LogStatusNotification\"") != NULL)
  19654. || (strstr((char*)str, "\"SecurityEventNotification\"") != NULL)
  19655. || (strstr((char*)str, "\"SignCertificate\"") != NULL)
  19656. || (strstr((char*)str, "\"SignedFirmwareStatusNotification\"") != NULL))
  19657. {
  19658. isWebsocketSendable = 0;
  19659. }
  19660. pthread_mutex_lock(&lock_send);
  19661. memset(SendBuffer, 0, ARRAY_SIZE(SendBuffer));
  19662. sprintf((char *)SendBuffer, "%s", str);
  19663. SendBufLen = strlen(str);
  19664. pthread_mutex_unlock(&lock_send);
  19665. lws_callback_on_writable(wsi_client);
  19666. //lws_service(context, 0);
  19667. //sleep(1);
  19668. }
  19669. void LWS_SendNow(char *str)
  19670. {
  19671. //=====================================================
  19672. // Check InternetConn 0: disconnected, 1: connected
  19673. //====================================================
  19674. if(GetOcppConnStatus() == 0)
  19675. {
  19676. DEBUG_INFO("offline now !!!\n");
  19677. return;
  19678. }
  19679. // Only disable isWebsocketSendable operation initiated by charger
  19680. if((strstr((char*)str, "\"Authorize\"") != NULL)
  19681. || (strstr((char*)str, "\"BootNotification\"") != NULL)
  19682. || (strstr((char*)str, "\"DataTransfer\"") != NULL)
  19683. || (strstr((char*)str, "\"DiagnosticsStatusNotification\"") != NULL)
  19684. || (strstr((char*)str, "\"FirmwareStatusNotification\"") != NULL)
  19685. || (strstr((char*)str, "\"Heartbeat\"") != NULL)
  19686. || (strstr((char*)str, "\"MeterValues\"") != NULL)
  19687. || (strstr((char*)str, "\"StartTransaction\"") != NULL)
  19688. || (strstr((char*)str, "\"StatusNotification\"") != NULL)
  19689. || (strstr((char*)str, "\"StopTransaction\"") != NULL)
  19690. || (strstr((char*)str, "\"LogStatusNotification\"") != NULL)
  19691. || (strstr((char*)str, "\"SecurityEventNotification\"") != NULL)
  19692. || (strstr((char*)str, "\"SignCertificate\"") != NULL)
  19693. || (strstr((char*)str, "\"SignedFirmwareStatusNotification\"") != NULL))
  19694. {
  19695. isWebsocketSendable = 0;
  19696. }
  19697. pthread_mutex_lock(&lock_send);
  19698. memset(SendBuffer, 0, ARRAY_SIZE(SendBuffer));
  19699. sprintf((char *)SendBuffer, "%s", str);
  19700. SendBufLen = strlen(str);
  19701. pthread_mutex_unlock(&lock_send);
  19702. lws_callback_on_writable(wsi_client);
  19703. lws_service(context, 0);
  19704. //sleep(1);
  19705. }