MessageHandler.c 990 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309331033113312331333143315331633173318331933203321332233233324332533263327332833293330333133323333333433353336333733383339334033413342334333443345334633473348334933503351335233533354335533563357335833593360336133623363336433653366336733683369337033713372337333743375337633773378337933803381338233833384338533863387338833893390339133923393339433953396339733983399340034013402340334043405340634073408340934103411341234133414341534163417341834193420342134223423342434253426342734283429343034313432343334343435343634373438343934403441344234433444344534463447344834493450345134523453345434553456345734583459346034613462346334643465346634673468346934703471347234733474347534763477347834793480348134823483348434853486348734883489349034913492349334943495349634973498349935003501350235033504350535063507350835093510351135123513351435153516351735183519352035213522352335243525352635273528352935303531353235333534353535363537353835393540354135423543354435453546354735483549355035513552355335543555355635573558355935603561356235633564356535663567356835693570357135723573357435753576357735783579358035813582358335843585358635873588358935903591359235933594359535963597359835993600360136023603360436053606360736083609361036113612361336143615361636173618361936203621362236233624362536263627362836293630363136323633363436353636363736383639364036413642364336443645364636473648364936503651365236533654365536563657365836593660366136623663366436653666366736683669367036713672367336743675367636773678367936803681368236833684368536863687368836893690369136923693369436953696369736983699370037013702370337043705370637073708370937103711371237133714371537163717371837193720372137223723372437253726372737283729373037313732373337343735373637373738373937403741374237433744374537463747374837493750375137523753375437553756375737583759376037613762376337643765376637673768376937703771377237733774377537763777377837793780378137823783378437853786378737883789379037913792379337943795379637973798379938003801380238033804380538063807380838093810381138123813381438153816381738183819382038213822382338243825382638273828382938303831383238333834383538363837383838393840384138423843384438453846384738483849385038513852385338543855385638573858385938603861386238633864386538663867386838693870387138723873387438753876387738783879388038813882388338843885388638873888388938903891389238933894389538963897389838993900390139023903390439053906390739083909391039113912391339143915391639173918391939203921392239233924392539263927392839293930393139323933393439353936393739383939394039413942394339443945394639473948394939503951395239533954395539563957395839593960396139623963396439653966396739683969397039713972397339743975397639773978397939803981398239833984398539863987398839893990399139923993399439953996399739983999400040014002400340044005400640074008400940104011401240134014401540164017401840194020402140224023402440254026402740284029403040314032403340344035403640374038403940404041404240434044404540464047404840494050405140524053405440554056405740584059406040614062406340644065406640674068406940704071407240734074407540764077407840794080408140824083408440854086408740884089409040914092409340944095409640974098409941004101410241034104410541064107410841094110411141124113411441154116411741184119412041214122412341244125412641274128412941304131413241334134413541364137413841394140414141424143414441454146414741484149415041514152415341544155415641574158415941604161416241634164416541664167416841694170417141724173417441754176417741784179418041814182418341844185418641874188418941904191419241934194419541964197419841994200420142024203420442054206420742084209421042114212421342144215421642174218421942204221422242234224422542264227422842294230423142324233423442354236423742384239424042414242424342444245424642474248424942504251425242534254425542564257425842594260426142624263426442654266426742684269427042714272427342744275427642774278427942804281428242834284428542864287428842894290429142924293429442954296429742984299430043014302430343044305430643074308430943104311431243134314431543164317431843194320432143224323432443254326432743284329433043314332433343344335433643374338433943404341434243434344434543464347434843494350435143524353435443554356435743584359436043614362436343644365436643674368436943704371437243734374437543764377437843794380438143824383438443854386438743884389439043914392439343944395439643974398439944004401440244034404440544064407440844094410441144124413441444154416441744184419442044214422442344244425442644274428442944304431443244334434443544364437443844394440444144424443444444454446444744484449445044514452445344544455445644574458445944604461446244634464446544664467446844694470447144724473447444754476447744784479448044814482448344844485448644874488448944904491449244934494449544964497449844994500450145024503450445054506450745084509451045114512451345144515451645174518451945204521452245234524452545264527452845294530453145324533453445354536453745384539454045414542454345444545454645474548454945504551455245534554455545564557455845594560456145624563456445654566456745684569457045714572457345744575457645774578457945804581458245834584458545864587458845894590459145924593459445954596459745984599460046014602460346044605460646074608460946104611461246134614461546164617461846194620462146224623462446254626462746284629463046314632463346344635463646374638463946404641464246434644464546464647464846494650465146524653465446554656465746584659466046614662466346644665466646674668466946704671467246734674467546764677467846794680468146824683468446854686468746884689469046914692469346944695469646974698469947004701470247034704470547064707470847094710471147124713471447154716471747184719472047214722472347244725472647274728472947304731473247334734473547364737473847394740474147424743474447454746474747484749475047514752475347544755475647574758475947604761476247634764476547664767476847694770477147724773477447754776477747784779478047814782478347844785478647874788478947904791479247934794479547964797479847994800480148024803480448054806480748084809481048114812481348144815481648174818481948204821482248234824482548264827482848294830483148324833483448354836483748384839484048414842484348444845484648474848484948504851485248534854485548564857485848594860486148624863486448654866486748684869487048714872487348744875487648774878487948804881488248834884488548864887488848894890489148924893489448954896489748984899490049014902490349044905490649074908490949104911491249134914491549164917491849194920492149224923492449254926492749284929493049314932493349344935493649374938493949404941494249434944494549464947494849494950495149524953495449554956495749584959496049614962496349644965496649674968496949704971497249734974497549764977497849794980498149824983498449854986498749884989499049914992499349944995499649974998499950005001500250035004500550065007500850095010501150125013501450155016501750185019502050215022502350245025502650275028502950305031503250335034503550365037503850395040504150425043504450455046504750485049505050515052505350545055505650575058505950605061506250635064506550665067506850695070507150725073507450755076507750785079508050815082508350845085508650875088508950905091509250935094509550965097509850995100510151025103510451055106510751085109511051115112511351145115511651175118511951205121512251235124512551265127512851295130513151325133513451355136513751385139514051415142514351445145514651475148514951505151515251535154515551565157515851595160516151625163516451655166516751685169517051715172517351745175517651775178517951805181518251835184518551865187518851895190519151925193519451955196519751985199520052015202520352045205520652075208520952105211521252135214521552165217521852195220522152225223522452255226522752285229523052315232523352345235523652375238523952405241524252435244524552465247524852495250525152525253525452555256525752585259526052615262526352645265526652675268526952705271527252735274527552765277527852795280528152825283528452855286528752885289529052915292529352945295529652975298529953005301530253035304530553065307530853095310531153125313531453155316531753185319532053215322532353245325532653275328532953305331533253335334533553365337533853395340534153425343534453455346534753485349535053515352535353545355535653575358535953605361536253635364536553665367536853695370537153725373537453755376537753785379538053815382538353845385538653875388538953905391539253935394539553965397539853995400540154025403540454055406540754085409541054115412541354145415541654175418541954205421542254235424542554265427542854295430543154325433543454355436543754385439544054415442544354445445544654475448544954505451545254535454545554565457545854595460546154625463546454655466546754685469547054715472547354745475547654775478547954805481548254835484548554865487548854895490549154925493549454955496549754985499550055015502550355045505550655075508550955105511551255135514551555165517551855195520552155225523552455255526552755285529553055315532553355345535553655375538553955405541554255435544554555465547554855495550555155525553555455555556555755585559556055615562556355645565556655675568556955705571557255735574557555765577557855795580558155825583558455855586558755885589559055915592559355945595559655975598559956005601560256035604560556065607560856095610561156125613561456155616561756185619562056215622562356245625562656275628562956305631563256335634563556365637563856395640564156425643564456455646564756485649565056515652565356545655565656575658565956605661566256635664566556665667566856695670567156725673567456755676567756785679568056815682568356845685568656875688568956905691569256935694569556965697569856995700570157025703570457055706570757085709571057115712571357145715571657175718571957205721572257235724572557265727572857295730573157325733573457355736573757385739574057415742574357445745574657475748574957505751575257535754575557565757575857595760576157625763576457655766576757685769577057715772577357745775577657775778577957805781578257835784578557865787578857895790579157925793579457955796579757985799580058015802580358045805580658075808580958105811581258135814581558165817581858195820582158225823582458255826582758285829583058315832583358345835583658375838583958405841584258435844584558465847584858495850585158525853585458555856585758585859586058615862586358645865586658675868586958705871587258735874587558765877587858795880588158825883588458855886588758885889589058915892589358945895589658975898589959005901590259035904590559065907590859095910591159125913591459155916591759185919592059215922592359245925592659275928592959305931593259335934593559365937593859395940594159425943594459455946594759485949595059515952595359545955595659575958595959605961596259635964596559665967596859695970597159725973597459755976597759785979598059815982598359845985598659875988598959905991599259935994599559965997599859996000600160026003600460056006600760086009601060116012601360146015601660176018601960206021602260236024602560266027602860296030603160326033603460356036603760386039604060416042604360446045604660476048604960506051605260536054605560566057605860596060606160626063606460656066606760686069607060716072607360746075607660776078607960806081608260836084608560866087608860896090609160926093609460956096609760986099610061016102610361046105610661076108610961106111611261136114611561166117611861196120612161226123612461256126612761286129613061316132613361346135613661376138613961406141614261436144614561466147614861496150615161526153615461556156615761586159616061616162616361646165616661676168616961706171617261736174617561766177617861796180618161826183618461856186618761886189619061916192619361946195619661976198619962006201620262036204620562066207620862096210621162126213621462156216621762186219622062216222622362246225622662276228622962306231623262336234623562366237623862396240624162426243624462456246624762486249625062516252625362546255625662576258625962606261626262636264626562666267626862696270627162726273627462756276627762786279628062816282628362846285628662876288628962906291629262936294629562966297629862996300630163026303630463056306630763086309631063116312631363146315631663176318631963206321632263236324632563266327632863296330633163326333633463356336633763386339634063416342634363446345634663476348634963506351635263536354635563566357635863596360636163626363636463656366636763686369637063716372637363746375637663776378637963806381638263836384638563866387638863896390639163926393639463956396639763986399640064016402640364046405640664076408640964106411641264136414641564166417641864196420642164226423642464256426642764286429643064316432643364346435643664376438643964406441644264436444644564466447644864496450645164526453645464556456645764586459646064616462646364646465646664676468646964706471647264736474647564766477647864796480648164826483648464856486648764886489649064916492649364946495649664976498649965006501650265036504650565066507650865096510651165126513651465156516651765186519652065216522652365246525652665276528652965306531653265336534653565366537653865396540654165426543654465456546654765486549655065516552655365546555655665576558655965606561656265636564656565666567656865696570657165726573657465756576657765786579658065816582658365846585658665876588658965906591659265936594659565966597659865996600660166026603660466056606660766086609661066116612661366146615661666176618661966206621662266236624662566266627662866296630663166326633663466356636663766386639664066416642664366446645664666476648664966506651665266536654665566566657665866596660666166626663666466656666666766686669667066716672667366746675667666776678667966806681668266836684668566866687668866896690669166926693669466956696669766986699670067016702670367046705670667076708670967106711671267136714671567166717671867196720672167226723672467256726672767286729673067316732673367346735673667376738673967406741674267436744674567466747674867496750675167526753675467556756675767586759676067616762676367646765676667676768676967706771677267736774677567766777677867796780678167826783678467856786678767886789679067916792679367946795679667976798679968006801680268036804680568066807680868096810681168126813681468156816681768186819682068216822682368246825682668276828682968306831683268336834683568366837683868396840684168426843684468456846684768486849685068516852685368546855685668576858685968606861686268636864686568666867686868696870687168726873687468756876687768786879688068816882688368846885688668876888688968906891689268936894689568966897689868996900690169026903690469056906690769086909691069116912691369146915691669176918691969206921692269236924692569266927692869296930693169326933693469356936693769386939694069416942694369446945694669476948694969506951695269536954695569566957695869596960696169626963696469656966696769686969697069716972697369746975697669776978697969806981698269836984698569866987698869896990699169926993699469956996699769986999700070017002700370047005700670077008700970107011701270137014701570167017701870197020702170227023702470257026702770287029703070317032703370347035703670377038703970407041704270437044704570467047704870497050705170527053705470557056705770587059706070617062706370647065706670677068706970707071707270737074707570767077707870797080708170827083708470857086708770887089709070917092709370947095709670977098709971007101710271037104710571067107710871097110711171127113711471157116711771187119712071217122712371247125712671277128712971307131713271337134713571367137713871397140714171427143714471457146714771487149715071517152715371547155715671577158715971607161716271637164716571667167716871697170717171727173717471757176717771787179718071817182718371847185718671877188718971907191719271937194719571967197719871997200720172027203720472057206720772087209721072117212721372147215721672177218721972207221722272237224722572267227722872297230723172327233723472357236723772387239724072417242724372447245724672477248724972507251725272537254725572567257725872597260726172627263726472657266726772687269727072717272727372747275727672777278727972807281728272837284728572867287728872897290729172927293729472957296729772987299730073017302730373047305730673077308730973107311731273137314731573167317731873197320732173227323732473257326732773287329733073317332733373347335733673377338733973407341734273437344734573467347734873497350735173527353735473557356735773587359736073617362736373647365736673677368736973707371737273737374737573767377737873797380738173827383738473857386738773887389739073917392739373947395739673977398739974007401740274037404740574067407740874097410741174127413741474157416741774187419742074217422742374247425742674277428742974307431743274337434743574367437743874397440744174427443744474457446744774487449745074517452745374547455745674577458745974607461746274637464746574667467746874697470747174727473747474757476747774787479748074817482748374847485748674877488748974907491749274937494749574967497749874997500750175027503750475057506750775087509751075117512751375147515751675177518751975207521752275237524752575267527752875297530753175327533753475357536753775387539754075417542754375447545754675477548754975507551755275537554755575567557755875597560756175627563756475657566756775687569757075717572757375747575757675777578757975807581758275837584758575867587758875897590759175927593759475957596759775987599760076017602760376047605760676077608760976107611761276137614761576167617761876197620762176227623762476257626762776287629763076317632763376347635763676377638763976407641764276437644764576467647764876497650765176527653765476557656765776587659766076617662766376647665766676677668766976707671767276737674767576767677767876797680768176827683768476857686768776887689769076917692769376947695769676977698769977007701770277037704770577067707770877097710771177127713771477157716771777187719772077217722772377247725772677277728772977307731773277337734773577367737773877397740774177427743774477457746774777487749775077517752775377547755775677577758775977607761776277637764776577667767776877697770777177727773777477757776777777787779778077817782778377847785778677877788778977907791779277937794779577967797779877997800780178027803780478057806780778087809781078117812781378147815781678177818781978207821782278237824782578267827782878297830783178327833783478357836783778387839784078417842784378447845784678477848784978507851785278537854785578567857785878597860786178627863786478657866786778687869787078717872787378747875787678777878787978807881788278837884788578867887788878897890789178927893789478957896789778987899790079017902790379047905790679077908790979107911791279137914791579167917791879197920792179227923792479257926792779287929793079317932793379347935793679377938793979407941794279437944794579467947794879497950795179527953795479557956795779587959796079617962796379647965796679677968796979707971797279737974797579767977797879797980798179827983798479857986798779887989799079917992799379947995799679977998799980008001800280038004800580068007800880098010801180128013801480158016801780188019802080218022802380248025802680278028802980308031803280338034803580368037803880398040804180428043804480458046804780488049805080518052805380548055805680578058805980608061806280638064806580668067806880698070807180728073807480758076807780788079808080818082808380848085808680878088808980908091809280938094809580968097809880998100810181028103810481058106810781088109811081118112811381148115811681178118811981208121812281238124812581268127812881298130813181328133813481358136813781388139814081418142814381448145814681478148814981508151815281538154815581568157815881598160816181628163816481658166816781688169817081718172817381748175817681778178817981808181818281838184818581868187818881898190819181928193819481958196819781988199820082018202820382048205820682078208820982108211821282138214821582168217821882198220822182228223822482258226822782288229823082318232823382348235823682378238823982408241824282438244824582468247824882498250825182528253825482558256825782588259826082618262826382648265826682678268826982708271827282738274827582768277827882798280828182828283828482858286828782888289829082918292829382948295829682978298829983008301830283038304830583068307830883098310831183128313831483158316831783188319832083218322832383248325832683278328832983308331833283338334833583368337833883398340834183428343834483458346834783488349835083518352835383548355835683578358835983608361836283638364836583668367836883698370837183728373837483758376837783788379838083818382838383848385838683878388838983908391839283938394839583968397839883998400840184028403840484058406840784088409841084118412841384148415841684178418841984208421842284238424842584268427842884298430843184328433843484358436843784388439844084418442844384448445844684478448844984508451845284538454845584568457845884598460846184628463846484658466846784688469847084718472847384748475847684778478847984808481848284838484848584868487848884898490849184928493849484958496849784988499850085018502850385048505850685078508850985108511851285138514851585168517851885198520852185228523852485258526852785288529853085318532853385348535853685378538853985408541854285438544854585468547854885498550855185528553855485558556855785588559856085618562856385648565856685678568856985708571857285738574857585768577857885798580858185828583858485858586858785888589859085918592859385948595859685978598859986008601860286038604860586068607860886098610861186128613861486158616861786188619862086218622862386248625862686278628862986308631863286338634863586368637863886398640864186428643864486458646864786488649865086518652865386548655865686578658865986608661866286638664866586668667866886698670867186728673867486758676867786788679868086818682868386848685868686878688868986908691869286938694869586968697869886998700870187028703870487058706870787088709871087118712871387148715871687178718871987208721872287238724872587268727872887298730873187328733873487358736873787388739874087418742874387448745874687478748874987508751875287538754875587568757875887598760876187628763876487658766876787688769877087718772877387748775877687778778877987808781878287838784878587868787878887898790879187928793879487958796879787988799880088018802880388048805880688078808880988108811881288138814881588168817881888198820882188228823882488258826882788288829883088318832883388348835883688378838883988408841884288438844884588468847884888498850885188528853885488558856885788588859886088618862886388648865886688678868886988708871887288738874887588768877887888798880888188828883888488858886888788888889889088918892889388948895889688978898889989008901890289038904890589068907890889098910891189128913891489158916891789188919892089218922892389248925892689278928892989308931893289338934893589368937893889398940894189428943894489458946894789488949895089518952895389548955895689578958895989608961896289638964896589668967896889698970897189728973897489758976897789788979898089818982898389848985898689878988898989908991899289938994899589968997899889999000900190029003900490059006900790089009901090119012901390149015901690179018901990209021902290239024902590269027902890299030903190329033903490359036903790389039904090419042904390449045904690479048904990509051905290539054905590569057905890599060906190629063906490659066906790689069907090719072907390749075907690779078907990809081908290839084908590869087908890899090909190929093909490959096909790989099910091019102910391049105910691079108910991109111911291139114911591169117911891199120912191229123912491259126912791289129913091319132913391349135913691379138913991409141914291439144914591469147914891499150915191529153915491559156915791589159916091619162916391649165916691679168916991709171917291739174917591769177917891799180918191829183918491859186918791889189919091919192919391949195919691979198919992009201920292039204920592069207920892099210921192129213921492159216921792189219922092219222922392249225922692279228922992309231923292339234923592369237923892399240924192429243924492459246924792489249925092519252925392549255925692579258925992609261926292639264926592669267926892699270927192729273927492759276927792789279928092819282928392849285928692879288928992909291929292939294929592969297929892999300930193029303930493059306930793089309931093119312931393149315931693179318931993209321932293239324932593269327932893299330933193329333933493359336933793389339934093419342934393449345934693479348934993509351935293539354935593569357935893599360936193629363936493659366936793689369937093719372937393749375937693779378937993809381938293839384938593869387938893899390939193929393939493959396939793989399940094019402940394049405940694079408940994109411941294139414941594169417941894199420942194229423942494259426942794289429943094319432943394349435943694379438943994409441944294439444944594469447944894499450945194529453945494559456945794589459946094619462946394649465946694679468946994709471947294739474947594769477947894799480948194829483948494859486948794889489949094919492949394949495949694979498949995009501950295039504950595069507950895099510951195129513951495159516951795189519952095219522952395249525952695279528952995309531953295339534953595369537953895399540954195429543954495459546954795489549955095519552955395549555955695579558955995609561956295639564956595669567956895699570957195729573957495759576957795789579958095819582958395849585958695879588958995909591959295939594959595969597959895999600960196029603960496059606960796089609961096119612961396149615961696179618961996209621962296239624962596269627962896299630963196329633963496359636963796389639964096419642964396449645964696479648964996509651965296539654965596569657965896599660966196629663966496659666966796689669967096719672967396749675967696779678967996809681968296839684968596869687968896899690969196929693969496959696969796989699970097019702970397049705970697079708970997109711971297139714971597169717971897199720972197229723972497259726972797289729973097319732973397349735973697379738973997409741974297439744974597469747974897499750975197529753975497559756975797589759976097619762976397649765976697679768976997709771977297739774977597769777977897799780978197829783978497859786978797889789979097919792979397949795979697979798979998009801980298039804980598069807980898099810981198129813981498159816981798189819982098219822982398249825982698279828982998309831983298339834983598369837983898399840984198429843984498459846984798489849985098519852985398549855985698579858985998609861986298639864986598669867986898699870987198729873987498759876987798789879988098819882988398849885988698879888988998909891989298939894989598969897989898999900990199029903990499059906990799089909991099119912991399149915991699179918991999209921992299239924992599269927992899299930993199329933993499359936993799389939994099419942994399449945994699479948994999509951995299539954995599569957995899599960996199629963996499659966996799689969997099719972997399749975997699779978997999809981998299839984998599869987998899899990999199929993999499959996999799989999100001000110002100031000410005100061000710008100091001010011100121001310014100151001610017100181001910020100211002210023100241002510026100271002810029100301003110032100331003410035100361003710038100391004010041100421004310044100451004610047100481004910050100511005210053100541005510056100571005810059100601006110062100631006410065100661006710068100691007010071100721007310074100751007610077100781007910080100811008210083100841008510086100871008810089100901009110092100931009410095100961009710098100991010010101101021010310104101051010610107101081010910110101111011210113101141011510116101171011810119101201012110122101231012410125101261012710128101291013010131101321013310134101351013610137101381013910140101411014210143101441014510146101471014810149101501015110152101531015410155101561015710158101591016010161101621016310164101651016610167101681016910170101711017210173101741017510176101771017810179101801018110182101831018410185101861018710188101891019010191101921019310194101951019610197101981019910200102011020210203102041020510206102071020810209102101021110212102131021410215102161021710218102191022010221102221022310224102251022610227102281022910230102311023210233102341023510236102371023810239102401024110242102431024410245102461024710248102491025010251102521025310254102551025610257102581025910260102611026210263102641026510266102671026810269102701027110272102731027410275102761027710278102791028010281102821028310284102851028610287102881028910290102911029210293102941029510296102971029810299103001030110302103031030410305103061030710308103091031010311103121031310314103151031610317103181031910320103211032210323103241032510326103271032810329103301033110332103331033410335103361033710338103391034010341103421034310344103451034610347103481034910350103511035210353103541035510356103571035810359103601036110362103631036410365103661036710368103691037010371103721037310374103751037610377103781037910380103811038210383103841038510386103871038810389103901039110392103931039410395103961039710398103991040010401104021040310404104051040610407104081040910410104111041210413104141041510416104171041810419104201042110422104231042410425104261042710428104291043010431104321043310434104351043610437104381043910440104411044210443104441044510446104471044810449104501045110452104531045410455104561045710458104591046010461104621046310464104651046610467104681046910470104711047210473104741047510476104771047810479104801048110482104831048410485104861048710488104891049010491104921049310494104951049610497104981049910500105011050210503105041050510506105071050810509105101051110512105131051410515105161051710518105191052010521105221052310524105251052610527105281052910530105311053210533105341053510536105371053810539105401054110542105431054410545105461054710548105491055010551105521055310554105551055610557105581055910560105611056210563105641056510566105671056810569105701057110572105731057410575105761057710578105791058010581105821058310584105851058610587105881058910590105911059210593105941059510596105971059810599106001060110602106031060410605106061060710608106091061010611106121061310614106151061610617106181061910620106211062210623106241062510626106271062810629106301063110632106331063410635106361063710638106391064010641106421064310644106451064610647106481064910650106511065210653106541065510656106571065810659106601066110662106631066410665106661066710668106691067010671106721067310674106751067610677106781067910680106811068210683106841068510686106871068810689106901069110692106931069410695106961069710698106991070010701107021070310704107051070610707107081070910710107111071210713107141071510716107171071810719107201072110722107231072410725107261072710728107291073010731107321073310734107351073610737107381073910740107411074210743107441074510746107471074810749107501075110752107531075410755107561075710758107591076010761107621076310764107651076610767107681076910770107711077210773107741077510776107771077810779107801078110782107831078410785107861078710788107891079010791107921079310794107951079610797107981079910800108011080210803108041080510806108071080810809108101081110812108131081410815108161081710818108191082010821108221082310824108251082610827108281082910830108311083210833108341083510836108371083810839108401084110842108431084410845108461084710848108491085010851108521085310854108551085610857108581085910860108611086210863108641086510866108671086810869108701087110872108731087410875108761087710878108791088010881108821088310884108851088610887108881088910890108911089210893108941089510896108971089810899109001090110902109031090410905109061090710908109091091010911109121091310914109151091610917109181091910920109211092210923109241092510926109271092810929109301093110932109331093410935109361093710938109391094010941109421094310944109451094610947109481094910950109511095210953109541095510956109571095810959109601096110962109631096410965109661096710968109691097010971109721097310974109751097610977109781097910980109811098210983109841098510986109871098810989109901099110992109931099410995109961099710998109991100011001110021100311004110051100611007110081100911010110111101211013110141101511016110171101811019110201102111022110231102411025110261102711028110291103011031110321103311034110351103611037110381103911040110411104211043110441104511046110471104811049110501105111052110531105411055110561105711058110591106011061110621106311064110651106611067110681106911070110711107211073110741107511076110771107811079110801108111082110831108411085110861108711088110891109011091110921109311094110951109611097110981109911100111011110211103111041110511106111071110811109111101111111112111131111411115111161111711118111191112011121111221112311124111251112611127111281112911130111311113211133111341113511136111371113811139111401114111142111431114411145111461114711148111491115011151111521115311154111551115611157111581115911160111611116211163111641116511166111671116811169111701117111172111731117411175111761117711178111791118011181111821118311184111851118611187111881118911190111911119211193111941119511196111971119811199112001120111202112031120411205112061120711208112091121011211112121121311214112151121611217112181121911220112211122211223112241122511226112271122811229112301123111232112331123411235112361123711238112391124011241112421124311244112451124611247112481124911250112511125211253112541125511256112571125811259112601126111262112631126411265112661126711268112691127011271112721127311274112751127611277112781127911280112811128211283112841128511286112871128811289112901129111292112931129411295112961129711298112991130011301113021130311304113051130611307113081130911310113111131211313113141131511316113171131811319113201132111322113231132411325113261132711328113291133011331113321133311334113351133611337113381133911340113411134211343113441134511346113471134811349113501135111352113531135411355113561135711358113591136011361113621136311364113651136611367113681136911370113711137211373113741137511376113771137811379113801138111382113831138411385113861138711388113891139011391113921139311394113951139611397113981139911400114011140211403114041140511406114071140811409114101141111412114131141411415114161141711418114191142011421114221142311424114251142611427114281142911430114311143211433114341143511436114371143811439114401144111442114431144411445114461144711448114491145011451114521145311454114551145611457114581145911460114611146211463114641146511466114671146811469114701147111472114731147411475114761147711478114791148011481114821148311484114851148611487114881148911490114911149211493114941149511496114971149811499115001150111502115031150411505115061150711508115091151011511115121151311514115151151611517115181151911520115211152211523115241152511526115271152811529115301153111532115331153411535115361153711538115391154011541115421154311544115451154611547115481154911550115511155211553115541155511556115571155811559115601156111562115631156411565115661156711568115691157011571115721157311574115751157611577115781157911580115811158211583115841158511586115871158811589115901159111592115931159411595115961159711598115991160011601116021160311604116051160611607116081160911610116111161211613116141161511616116171161811619116201162111622116231162411625116261162711628116291163011631116321163311634116351163611637116381163911640116411164211643116441164511646116471164811649116501165111652116531165411655116561165711658116591166011661116621166311664116651166611667116681166911670116711167211673116741167511676116771167811679116801168111682116831168411685116861168711688116891169011691116921169311694116951169611697116981169911700117011170211703117041170511706117071170811709117101171111712117131171411715117161171711718117191172011721117221172311724117251172611727117281172911730117311173211733117341173511736117371173811739117401174111742117431174411745117461174711748117491175011751117521175311754117551175611757117581175911760117611176211763117641176511766117671176811769117701177111772117731177411775117761177711778117791178011781117821178311784117851178611787117881178911790117911179211793117941179511796117971179811799118001180111802118031180411805118061180711808118091181011811118121181311814118151181611817118181181911820118211182211823118241182511826118271182811829118301183111832118331183411835118361183711838118391184011841118421184311844118451184611847118481184911850118511185211853118541185511856118571185811859118601186111862118631186411865118661186711868118691187011871118721187311874118751187611877118781187911880118811188211883118841188511886118871188811889118901189111892118931189411895118961189711898118991190011901119021190311904119051190611907119081190911910119111191211913119141191511916119171191811919119201192111922119231192411925119261192711928119291193011931119321193311934119351193611937119381193911940119411194211943119441194511946119471194811949119501195111952119531195411955119561195711958119591196011961119621196311964119651196611967119681196911970119711197211973119741197511976119771197811979119801198111982119831198411985119861198711988119891199011991119921199311994119951199611997119981199912000120011200212003120041200512006120071200812009120101201112012120131201412015120161201712018120191202012021120221202312024120251202612027120281202912030120311203212033120341203512036120371203812039120401204112042120431204412045120461204712048120491205012051120521205312054120551205612057120581205912060120611206212063120641206512066120671206812069120701207112072120731207412075120761207712078120791208012081120821208312084120851208612087120881208912090120911209212093120941209512096120971209812099121001210112102121031210412105121061210712108121091211012111121121211312114121151211612117121181211912120121211212212123121241212512126121271212812129121301213112132121331213412135121361213712138121391214012141121421214312144121451214612147121481214912150121511215212153121541215512156121571215812159121601216112162121631216412165121661216712168121691217012171121721217312174121751217612177121781217912180121811218212183121841218512186121871218812189121901219112192121931219412195121961219712198121991220012201122021220312204122051220612207122081220912210122111221212213122141221512216122171221812219122201222112222122231222412225122261222712228122291223012231122321223312234122351223612237122381223912240122411224212243122441224512246122471224812249122501225112252122531225412255122561225712258122591226012261122621226312264122651226612267122681226912270122711227212273122741227512276122771227812279122801228112282122831228412285122861228712288122891229012291122921229312294122951229612297122981229912300123011230212303123041230512306123071230812309123101231112312123131231412315123161231712318123191232012321123221232312324123251232612327123281232912330123311233212333123341233512336123371233812339123401234112342123431234412345123461234712348123491235012351123521235312354123551235612357123581235912360123611236212363123641236512366123671236812369123701237112372123731237412375123761237712378123791238012381123821238312384123851238612387123881238912390123911239212393123941239512396123971239812399124001240112402124031240412405124061240712408124091241012411124121241312414124151241612417124181241912420124211242212423124241242512426124271242812429124301243112432124331243412435124361243712438124391244012441124421244312444124451244612447124481244912450124511245212453124541245512456124571245812459124601246112462124631246412465124661246712468124691247012471124721247312474124751247612477124781247912480124811248212483124841248512486124871248812489124901249112492124931249412495124961249712498124991250012501125021250312504125051250612507125081250912510125111251212513125141251512516125171251812519125201252112522125231252412525125261252712528125291253012531125321253312534125351253612537125381253912540125411254212543125441254512546125471254812549125501255112552125531255412555125561255712558125591256012561125621256312564125651256612567125681256912570125711257212573125741257512576125771257812579125801258112582125831258412585125861258712588125891259012591125921259312594125951259612597125981259912600126011260212603126041260512606126071260812609126101261112612126131261412615126161261712618126191262012621126221262312624126251262612627126281262912630126311263212633126341263512636126371263812639126401264112642126431264412645126461264712648126491265012651126521265312654126551265612657126581265912660126611266212663126641266512666126671266812669126701267112672126731267412675126761267712678126791268012681126821268312684126851268612687126881268912690126911269212693126941269512696126971269812699127001270112702127031270412705127061270712708127091271012711127121271312714127151271612717127181271912720127211272212723127241272512726127271272812729127301273112732127331273412735127361273712738127391274012741127421274312744127451274612747127481274912750127511275212753127541275512756127571275812759127601276112762127631276412765127661276712768127691277012771127721277312774127751277612777127781277912780127811278212783127841278512786127871278812789127901279112792127931279412795127961279712798127991280012801128021280312804128051280612807128081280912810128111281212813128141281512816128171281812819128201282112822128231282412825128261282712828128291283012831128321283312834128351283612837128381283912840128411284212843128441284512846128471284812849128501285112852128531285412855128561285712858128591286012861128621286312864128651286612867128681286912870128711287212873128741287512876128771287812879128801288112882128831288412885128861288712888128891289012891128921289312894128951289612897128981289912900129011290212903129041290512906129071290812909129101291112912129131291412915129161291712918129191292012921129221292312924129251292612927129281292912930129311293212933129341293512936129371293812939129401294112942129431294412945129461294712948129491295012951129521295312954129551295612957129581295912960129611296212963129641296512966129671296812969129701297112972129731297412975129761297712978129791298012981129821298312984129851298612987129881298912990129911299212993129941299512996129971299812999130001300113002130031300413005130061300713008130091301013011130121301313014130151301613017130181301913020130211302213023130241302513026130271302813029130301303113032130331303413035130361303713038130391304013041130421304313044130451304613047130481304913050130511305213053130541305513056130571305813059130601306113062130631306413065130661306713068130691307013071130721307313074130751307613077130781307913080130811308213083130841308513086130871308813089130901309113092130931309413095130961309713098130991310013101131021310313104131051310613107131081310913110131111311213113131141311513116131171311813119131201312113122131231312413125131261312713128131291313013131131321313313134131351313613137131381313913140131411314213143131441314513146131471314813149131501315113152131531315413155131561315713158131591316013161131621316313164131651316613167131681316913170131711317213173131741317513176131771317813179131801318113182131831318413185131861318713188131891319013191131921319313194131951319613197131981319913200132011320213203132041320513206132071320813209132101321113212132131321413215132161321713218132191322013221132221322313224132251322613227132281322913230132311323213233132341323513236132371323813239132401324113242132431324413245132461324713248132491325013251132521325313254132551325613257132581325913260132611326213263132641326513266132671326813269132701327113272132731327413275132761327713278132791328013281132821328313284132851328613287132881328913290132911329213293132941329513296132971329813299133001330113302133031330413305133061330713308133091331013311133121331313314133151331613317133181331913320133211332213323133241332513326133271332813329133301333113332133331333413335133361333713338133391334013341133421334313344133451334613347133481334913350133511335213353133541335513356133571335813359133601336113362133631336413365133661336713368133691337013371133721337313374133751337613377133781337913380133811338213383133841338513386133871338813389133901339113392133931339413395133961339713398133991340013401134021340313404134051340613407134081340913410134111341213413134141341513416134171341813419134201342113422134231342413425134261342713428134291343013431134321343313434134351343613437134381343913440134411344213443134441344513446134471344813449134501345113452134531345413455134561345713458134591346013461134621346313464134651346613467134681346913470134711347213473134741347513476134771347813479134801348113482134831348413485134861348713488134891349013491134921349313494134951349613497134981349913500135011350213503135041350513506135071350813509135101351113512135131351413515135161351713518135191352013521135221352313524135251352613527135281352913530135311353213533135341353513536135371353813539135401354113542135431354413545135461354713548135491355013551135521355313554135551355613557135581355913560135611356213563135641356513566135671356813569135701357113572135731357413575135761357713578135791358013581135821358313584135851358613587135881358913590135911359213593135941359513596135971359813599136001360113602136031360413605136061360713608136091361013611136121361313614136151361613617136181361913620136211362213623136241362513626136271362813629136301363113632136331363413635136361363713638136391364013641136421364313644136451364613647136481364913650136511365213653136541365513656136571365813659136601366113662136631366413665136661366713668136691367013671136721367313674136751367613677136781367913680136811368213683136841368513686136871368813689136901369113692136931369413695136961369713698136991370013701137021370313704137051370613707137081370913710137111371213713137141371513716137171371813719137201372113722137231372413725137261372713728137291373013731137321373313734137351373613737137381373913740137411374213743137441374513746137471374813749137501375113752137531375413755137561375713758137591376013761137621376313764137651376613767137681376913770137711377213773137741377513776137771377813779137801378113782137831378413785137861378713788137891379013791137921379313794137951379613797137981379913800138011380213803138041380513806138071380813809138101381113812138131381413815138161381713818138191382013821138221382313824138251382613827138281382913830138311383213833138341383513836138371383813839138401384113842138431384413845138461384713848138491385013851138521385313854138551385613857138581385913860138611386213863138641386513866138671386813869138701387113872138731387413875138761387713878138791388013881138821388313884138851388613887138881388913890138911389213893138941389513896138971389813899139001390113902139031390413905139061390713908139091391013911139121391313914139151391613917139181391913920139211392213923139241392513926139271392813929139301393113932139331393413935139361393713938139391394013941139421394313944139451394613947139481394913950139511395213953139541395513956139571395813959139601396113962139631396413965139661396713968139691397013971139721397313974139751397613977139781397913980139811398213983139841398513986139871398813989139901399113992139931399413995139961399713998139991400014001140021400314004140051400614007140081400914010140111401214013140141401514016140171401814019140201402114022140231402414025140261402714028140291403014031140321403314034140351403614037140381403914040140411404214043140441404514046140471404814049140501405114052140531405414055140561405714058140591406014061140621406314064140651406614067140681406914070140711407214073140741407514076140771407814079140801408114082140831408414085140861408714088140891409014091140921409314094140951409614097140981409914100141011410214103141041410514106141071410814109141101411114112141131411414115141161411714118141191412014121141221412314124141251412614127141281412914130141311413214133141341413514136141371413814139141401414114142141431414414145141461414714148141491415014151141521415314154141551415614157141581415914160141611416214163141641416514166141671416814169141701417114172141731417414175141761417714178141791418014181141821418314184141851418614187141881418914190141911419214193141941419514196141971419814199142001420114202142031420414205142061420714208142091421014211142121421314214142151421614217142181421914220142211422214223142241422514226142271422814229142301423114232142331423414235142361423714238142391424014241142421424314244142451424614247142481424914250142511425214253142541425514256142571425814259142601426114262142631426414265142661426714268142691427014271142721427314274142751427614277142781427914280142811428214283142841428514286142871428814289142901429114292142931429414295142961429714298142991430014301143021430314304143051430614307143081430914310143111431214313143141431514316143171431814319143201432114322143231432414325143261432714328143291433014331143321433314334143351433614337143381433914340143411434214343143441434514346143471434814349143501435114352143531435414355143561435714358143591436014361143621436314364143651436614367143681436914370143711437214373143741437514376143771437814379143801438114382143831438414385143861438714388143891439014391143921439314394143951439614397143981439914400144011440214403144041440514406144071440814409144101441114412144131441414415144161441714418144191442014421144221442314424144251442614427144281442914430144311443214433144341443514436144371443814439144401444114442144431444414445144461444714448144491445014451144521445314454144551445614457144581445914460144611446214463144641446514466144671446814469144701447114472144731447414475144761447714478144791448014481144821448314484144851448614487144881448914490144911449214493144941449514496144971449814499145001450114502145031450414505145061450714508145091451014511145121451314514145151451614517145181451914520145211452214523145241452514526145271452814529145301453114532145331453414535145361453714538145391454014541145421454314544145451454614547145481454914550145511455214553145541455514556145571455814559145601456114562145631456414565145661456714568145691457014571145721457314574145751457614577145781457914580145811458214583145841458514586145871458814589145901459114592145931459414595145961459714598145991460014601146021460314604146051460614607146081460914610146111461214613146141461514616146171461814619146201462114622146231462414625146261462714628146291463014631146321463314634146351463614637146381463914640146411464214643146441464514646146471464814649146501465114652146531465414655146561465714658146591466014661146621466314664146651466614667146681466914670146711467214673146741467514676146771467814679146801468114682146831468414685146861468714688146891469014691146921469314694146951469614697146981469914700147011470214703147041470514706147071470814709147101471114712147131471414715147161471714718147191472014721147221472314724147251472614727147281472914730147311473214733147341473514736147371473814739147401474114742147431474414745147461474714748147491475014751147521475314754147551475614757147581475914760147611476214763147641476514766147671476814769147701477114772147731477414775147761477714778147791478014781147821478314784147851478614787147881478914790147911479214793147941479514796147971479814799148001480114802148031480414805148061480714808148091481014811148121481314814148151481614817148181481914820148211482214823148241482514826148271482814829148301483114832148331483414835148361483714838148391484014841148421484314844148451484614847148481484914850148511485214853148541485514856148571485814859148601486114862148631486414865148661486714868148691487014871148721487314874148751487614877148781487914880148811488214883148841488514886148871488814889148901489114892148931489414895148961489714898148991490014901149021490314904149051490614907149081490914910149111491214913149141491514916149171491814919149201492114922149231492414925149261492714928149291493014931149321493314934149351493614937149381493914940149411494214943149441494514946149471494814949149501495114952149531495414955149561495714958149591496014961149621496314964149651496614967149681496914970149711497214973149741497514976149771497814979149801498114982149831498414985149861498714988149891499014991149921499314994149951499614997149981499915000150011500215003150041500515006150071500815009150101501115012150131501415015150161501715018150191502015021150221502315024150251502615027150281502915030150311503215033150341503515036150371503815039150401504115042150431504415045150461504715048150491505015051150521505315054150551505615057150581505915060150611506215063150641506515066150671506815069150701507115072150731507415075150761507715078150791508015081150821508315084150851508615087150881508915090150911509215093150941509515096150971509815099151001510115102151031510415105151061510715108151091511015111151121511315114151151511615117151181511915120151211512215123151241512515126151271512815129151301513115132151331513415135151361513715138151391514015141151421514315144151451514615147151481514915150151511515215153151541515515156151571515815159151601516115162151631516415165151661516715168151691517015171151721517315174151751517615177151781517915180151811518215183151841518515186151871518815189151901519115192151931519415195151961519715198151991520015201152021520315204152051520615207152081520915210152111521215213152141521515216152171521815219152201522115222152231522415225152261522715228152291523015231152321523315234152351523615237152381523915240152411524215243152441524515246152471524815249152501525115252152531525415255152561525715258152591526015261152621526315264152651526615267152681526915270152711527215273152741527515276152771527815279152801528115282152831528415285152861528715288152891529015291152921529315294152951529615297152981529915300153011530215303153041530515306153071530815309153101531115312153131531415315153161531715318153191532015321153221532315324153251532615327153281532915330153311533215333153341533515336153371533815339153401534115342153431534415345153461534715348153491535015351153521535315354153551535615357153581535915360153611536215363153641536515366153671536815369153701537115372153731537415375153761537715378153791538015381153821538315384153851538615387153881538915390153911539215393153941539515396153971539815399154001540115402154031540415405154061540715408154091541015411154121541315414154151541615417154181541915420154211542215423154241542515426154271542815429154301543115432154331543415435154361543715438154391544015441154421544315444154451544615447154481544915450154511545215453154541545515456154571545815459154601546115462154631546415465154661546715468154691547015471154721547315474154751547615477154781547915480154811548215483154841548515486154871548815489154901549115492154931549415495154961549715498154991550015501155021550315504155051550615507155081550915510155111551215513155141551515516155171551815519155201552115522155231552415525155261552715528155291553015531155321553315534155351553615537155381553915540155411554215543155441554515546155471554815549155501555115552155531555415555155561555715558155591556015561155621556315564155651556615567155681556915570155711557215573155741557515576155771557815579155801558115582155831558415585155861558715588155891559015591155921559315594155951559615597155981559915600156011560215603156041560515606156071560815609156101561115612156131561415615156161561715618156191562015621156221562315624156251562615627156281562915630156311563215633156341563515636156371563815639156401564115642156431564415645156461564715648156491565015651156521565315654156551565615657156581565915660156611566215663156641566515666156671566815669156701567115672156731567415675156761567715678156791568015681156821568315684156851568615687156881568915690156911569215693156941569515696156971569815699157001570115702157031570415705157061570715708157091571015711157121571315714157151571615717157181571915720157211572215723157241572515726157271572815729157301573115732157331573415735157361573715738157391574015741157421574315744157451574615747157481574915750157511575215753157541575515756157571575815759157601576115762157631576415765157661576715768157691577015771157721577315774157751577615777157781577915780157811578215783157841578515786157871578815789157901579115792157931579415795157961579715798157991580015801158021580315804158051580615807158081580915810158111581215813158141581515816158171581815819158201582115822158231582415825158261582715828158291583015831158321583315834158351583615837158381583915840158411584215843158441584515846158471584815849158501585115852158531585415855158561585715858158591586015861158621586315864158651586615867158681586915870158711587215873158741587515876158771587815879158801588115882158831588415885158861588715888158891589015891158921589315894158951589615897158981589915900159011590215903159041590515906159071590815909159101591115912159131591415915159161591715918159191592015921159221592315924159251592615927159281592915930159311593215933159341593515936159371593815939159401594115942159431594415945159461594715948159491595015951159521595315954159551595615957159581595915960159611596215963159641596515966159671596815969159701597115972159731597415975159761597715978159791598015981159821598315984159851598615987159881598915990159911599215993159941599515996159971599815999160001600116002160031600416005160061600716008160091601016011160121601316014160151601616017160181601916020160211602216023160241602516026160271602816029160301603116032160331603416035160361603716038160391604016041160421604316044160451604616047160481604916050160511605216053160541605516056160571605816059160601606116062160631606416065160661606716068160691607016071160721607316074160751607616077160781607916080160811608216083160841608516086160871608816089160901609116092160931609416095160961609716098160991610016101161021610316104161051610616107161081610916110161111611216113161141611516116161171611816119161201612116122161231612416125161261612716128161291613016131161321613316134161351613616137161381613916140161411614216143161441614516146161471614816149161501615116152161531615416155161561615716158161591616016161161621616316164161651616616167161681616916170161711617216173161741617516176161771617816179161801618116182161831618416185161861618716188161891619016191161921619316194161951619616197161981619916200162011620216203162041620516206162071620816209162101621116212162131621416215162161621716218162191622016221162221622316224162251622616227162281622916230162311623216233162341623516236162371623816239162401624116242162431624416245162461624716248162491625016251162521625316254162551625616257162581625916260162611626216263162641626516266162671626816269162701627116272162731627416275162761627716278162791628016281162821628316284162851628616287162881628916290162911629216293162941629516296162971629816299163001630116302163031630416305163061630716308163091631016311163121631316314163151631616317163181631916320163211632216323163241632516326163271632816329163301633116332163331633416335163361633716338163391634016341163421634316344163451634616347163481634916350163511635216353163541635516356163571635816359163601636116362163631636416365163661636716368163691637016371163721637316374163751637616377163781637916380163811638216383163841638516386163871638816389163901639116392163931639416395163961639716398163991640016401164021640316404164051640616407164081640916410164111641216413164141641516416164171641816419164201642116422164231642416425164261642716428164291643016431164321643316434164351643616437164381643916440164411644216443164441644516446164471644816449164501645116452164531645416455164561645716458164591646016461164621646316464164651646616467164681646916470164711647216473164741647516476164771647816479164801648116482164831648416485164861648716488164891649016491164921649316494164951649616497164981649916500165011650216503165041650516506165071650816509165101651116512165131651416515165161651716518165191652016521165221652316524165251652616527165281652916530165311653216533165341653516536165371653816539165401654116542165431654416545165461654716548165491655016551165521655316554165551655616557165581655916560165611656216563165641656516566165671656816569165701657116572165731657416575165761657716578165791658016581165821658316584165851658616587165881658916590165911659216593165941659516596165971659816599166001660116602166031660416605166061660716608166091661016611166121661316614166151661616617166181661916620166211662216623166241662516626166271662816629166301663116632166331663416635166361663716638166391664016641166421664316644166451664616647166481664916650166511665216653166541665516656166571665816659166601666116662166631666416665166661666716668166691667016671166721667316674166751667616677166781667916680166811668216683166841668516686166871668816689166901669116692166931669416695166961669716698166991670016701167021670316704167051670616707167081670916710167111671216713167141671516716167171671816719167201672116722167231672416725167261672716728167291673016731167321673316734167351673616737167381673916740167411674216743167441674516746167471674816749167501675116752167531675416755167561675716758167591676016761167621676316764167651676616767167681676916770167711677216773167741677516776167771677816779167801678116782167831678416785167861678716788167891679016791167921679316794167951679616797167981679916800168011680216803168041680516806168071680816809168101681116812168131681416815168161681716818168191682016821168221682316824168251682616827168281682916830168311683216833168341683516836168371683816839168401684116842168431684416845168461684716848168491685016851168521685316854168551685616857168581685916860168611686216863168641686516866168671686816869168701687116872168731687416875168761687716878168791688016881168821688316884168851688616887168881688916890168911689216893168941689516896168971689816899169001690116902169031690416905169061690716908169091691016911169121691316914169151691616917169181691916920169211692216923169241692516926169271692816929169301693116932169331693416935169361693716938169391694016941169421694316944169451694616947169481694916950169511695216953169541695516956169571695816959169601696116962169631696416965169661696716968169691697016971169721697316974169751697616977169781697916980169811698216983169841698516986169871698816989169901699116992169931699416995169961699716998169991700017001170021700317004170051700617007170081700917010170111701217013170141701517016170171701817019170201702117022170231702417025170261702717028170291703017031170321703317034170351703617037170381703917040170411704217043170441704517046170471704817049170501705117052170531705417055170561705717058170591706017061170621706317064170651706617067170681706917070170711707217073170741707517076170771707817079170801708117082170831708417085170861708717088170891709017091170921709317094170951709617097170981709917100171011710217103171041710517106171071710817109171101711117112171131711417115171161711717118171191712017121171221712317124171251712617127171281712917130171311713217133171341713517136171371713817139171401714117142171431714417145171461714717148171491715017151171521715317154171551715617157171581715917160171611716217163171641716517166171671716817169171701717117172171731717417175171761717717178171791718017181171821718317184171851718617187171881718917190171911719217193171941719517196171971719817199172001720117202172031720417205172061720717208172091721017211172121721317214172151721617217172181721917220172211722217223172241722517226172271722817229172301723117232172331723417235172361723717238172391724017241172421724317244172451724617247172481724917250172511725217253172541725517256172571725817259172601726117262172631726417265172661726717268172691727017271172721727317274172751727617277172781727917280172811728217283172841728517286172871728817289172901729117292172931729417295172961729717298172991730017301173021730317304173051730617307173081730917310173111731217313173141731517316173171731817319173201732117322173231732417325173261732717328173291733017331173321733317334173351733617337173381733917340173411734217343173441734517346173471734817349173501735117352173531735417355173561735717358173591736017361173621736317364173651736617367173681736917370173711737217373173741737517376173771737817379173801738117382173831738417385173861738717388173891739017391173921739317394173951739617397173981739917400174011740217403174041740517406174071740817409174101741117412174131741417415174161741717418174191742017421174221742317424174251742617427174281742917430174311743217433174341743517436174371743817439174401744117442174431744417445174461744717448174491745017451174521745317454174551745617457174581745917460174611746217463174641746517466174671746817469174701747117472174731747417475174761747717478174791748017481174821748317484174851748617487174881748917490174911749217493174941749517496174971749817499175001750117502175031750417505175061750717508175091751017511175121751317514175151751617517175181751917520175211752217523175241752517526175271752817529175301753117532175331753417535175361753717538175391754017541175421754317544175451754617547175481754917550175511755217553175541755517556175571755817559175601756117562175631756417565175661756717568175691757017571175721757317574175751757617577175781757917580175811758217583175841758517586175871758817589175901759117592175931759417595175961759717598175991760017601176021760317604176051760617607176081760917610176111761217613176141761517616176171761817619176201762117622176231762417625176261762717628176291763017631176321763317634176351763617637176381763917640176411764217643176441764517646176471764817649176501765117652176531765417655176561765717658176591766017661176621766317664176651766617667176681766917670176711767217673176741767517676176771767817679176801768117682176831768417685176861768717688176891769017691176921769317694176951769617697176981769917700177011770217703177041770517706177071770817709177101771117712177131771417715177161771717718177191772017721177221772317724177251772617727177281772917730177311773217733177341773517736177371773817739177401774117742177431774417745177461774717748177491775017751177521775317754177551775617757177581775917760177611776217763177641776517766177671776817769177701777117772177731777417775177761777717778177791778017781177821778317784177851778617787177881778917790177911779217793177941779517796177971779817799178001780117802178031780417805178061780717808178091781017811178121781317814178151781617817178181781917820178211782217823178241782517826178271782817829178301783117832178331783417835178361783717838178391784017841178421784317844178451784617847178481784917850178511785217853178541785517856178571785817859178601786117862178631786417865178661786717868178691787017871178721787317874178751787617877178781787917880178811788217883178841788517886178871788817889178901789117892178931789417895178961789717898178991790017901179021790317904179051790617907179081790917910179111791217913179141791517916179171791817919179201792117922179231792417925179261792717928179291793017931179321793317934179351793617937179381793917940179411794217943179441794517946179471794817949179501795117952179531795417955179561795717958179591796017961179621796317964179651796617967179681796917970179711797217973179741797517976179771797817979179801798117982179831798417985179861798717988179891799017991179921799317994179951799617997179981799918000180011800218003180041800518006180071800818009180101801118012180131801418015180161801718018180191802018021180221802318024180251802618027180281802918030180311803218033180341803518036180371803818039180401804118042180431804418045180461804718048180491805018051180521805318054180551805618057180581805918060180611806218063180641806518066180671806818069180701807118072180731807418075180761807718078180791808018081180821808318084180851808618087180881808918090180911809218093180941809518096180971809818099181001810118102181031810418105181061810718108181091811018111181121811318114181151811618117181181811918120181211812218123181241812518126181271812818129181301813118132181331813418135181361813718138181391814018141181421814318144181451814618147181481814918150181511815218153181541815518156181571815818159181601816118162181631816418165181661816718168181691817018171181721817318174181751817618177181781817918180181811818218183181841818518186181871818818189181901819118192181931819418195181961819718198181991820018201182021820318204182051820618207182081820918210182111821218213182141821518216182171821818219182201822118222182231822418225182261822718228182291823018231182321823318234182351823618237182381823918240182411824218243182441824518246182471824818249182501825118252182531825418255182561825718258182591826018261182621826318264182651826618267182681826918270182711827218273182741827518276182771827818279182801828118282182831828418285182861828718288182891829018291182921829318294182951829618297182981829918300183011830218303183041830518306183071830818309183101831118312183131831418315183161831718318183191832018321183221832318324183251832618327183281832918330183311833218333183341833518336183371833818339183401834118342183431834418345183461834718348183491835018351183521835318354183551835618357183581835918360183611836218363183641836518366183671836818369183701837118372183731837418375183761837718378183791838018381183821838318384183851838618387183881838918390183911839218393183941839518396183971839818399184001840118402184031840418405184061840718408184091841018411184121841318414184151841618417184181841918420184211842218423184241842518426184271842818429184301843118432184331843418435184361843718438184391844018441184421844318444184451844618447184481844918450184511845218453184541845518456184571845818459184601846118462184631846418465184661846718468184691847018471184721847318474184751847618477184781847918480184811848218483184841848518486184871848818489184901849118492184931849418495184961849718498184991850018501185021850318504185051850618507185081850918510185111851218513185141851518516185171851818519185201852118522185231852418525185261852718528185291853018531185321853318534185351853618537185381853918540185411854218543185441854518546185471854818549185501855118552185531855418555185561855718558185591856018561185621856318564185651856618567185681856918570185711857218573185741857518576185771857818579185801858118582185831858418585185861858718588185891859018591185921859318594185951859618597185981859918600186011860218603186041860518606186071860818609186101861118612186131861418615186161861718618186191862018621186221862318624186251862618627186281862918630186311863218633186341863518636186371863818639186401864118642186431864418645186461864718648186491865018651186521865318654186551865618657186581865918660186611866218663186641866518666186671866818669186701867118672186731867418675186761867718678186791868018681186821868318684186851868618687186881868918690186911869218693186941869518696186971869818699187001870118702187031870418705187061870718708187091871018711187121871318714187151871618717187181871918720187211872218723187241872518726187271872818729187301873118732187331873418735187361873718738187391874018741187421874318744187451874618747187481874918750187511875218753187541875518756187571875818759187601876118762187631876418765187661876718768187691877018771187721877318774187751877618777187781877918780187811878218783187841878518786187871878818789187901879118792187931879418795187961879718798187991880018801188021880318804188051880618807188081880918810188111881218813188141881518816188171881818819188201882118822188231882418825188261882718828188291883018831188321883318834188351883618837188381883918840188411884218843188441884518846188471884818849188501885118852188531885418855188561885718858188591886018861188621886318864188651886618867188681886918870188711887218873188741887518876188771887818879188801888118882188831888418885188861888718888188891889018891188921889318894188951889618897188981889918900189011890218903189041890518906189071890818909189101891118912189131891418915189161891718918189191892018921189221892318924189251892618927189281892918930189311893218933189341893518936189371893818939189401894118942189431894418945189461894718948189491895018951189521895318954189551895618957189581895918960189611896218963189641896518966189671896818969189701897118972189731897418975189761897718978189791898018981189821898318984189851898618987189881898918990189911899218993189941899518996189971899818999190001900119002190031900419005190061900719008190091901019011190121901319014190151901619017190181901919020190211902219023190241902519026190271902819029190301903119032190331903419035190361903719038190391904019041190421904319044190451904619047190481904919050190511905219053190541905519056190571905819059190601906119062190631906419065190661906719068190691907019071190721907319074190751907619077190781907919080190811908219083190841908519086190871908819089190901909119092190931909419095190961909719098190991910019101191021910319104191051910619107191081910919110191111911219113191141911519116191171911819119191201912119122191231912419125191261912719128191291913019131191321913319134191351913619137191381913919140191411914219143191441914519146191471914819149191501915119152191531915419155191561915719158191591916019161191621916319164191651916619167191681916919170191711917219173191741917519176191771917819179191801918119182191831918419185191861918719188191891919019191191921919319194191951919619197191981919919200192011920219203192041920519206192071920819209192101921119212192131921419215192161921719218192191922019221192221922319224192251922619227192281922919230192311923219233192341923519236192371923819239192401924119242192431924419245192461924719248192491925019251192521925319254192551925619257192581925919260192611926219263192641926519266192671926819269192701927119272192731927419275192761927719278192791928019281192821928319284192851928619287192881928919290192911929219293192941929519296192971929819299193001930119302193031930419305193061930719308193091931019311193121931319314193151931619317193181931919320193211932219323193241932519326193271932819329193301933119332193331933419335193361933719338193391934019341193421934319344193451934619347193481934919350193511935219353193541935519356193571935819359193601936119362193631936419365193661936719368193691937019371193721937319374193751937619377193781937919380193811938219383193841938519386193871938819389193901939119392193931939419395193961939719398193991940019401194021940319404194051940619407194081940919410194111941219413194141941519416194171941819419194201942119422194231942419425194261942719428194291943019431194321943319434194351943619437194381943919440194411944219443194441944519446194471944819449194501945119452194531945419455194561945719458194591946019461194621946319464194651946619467194681946919470194711947219473194741947519476194771947819479194801948119482194831948419485194861948719488194891949019491194921949319494194951949619497194981949919500195011950219503195041950519506195071950819509195101951119512195131951419515195161951719518195191952019521195221952319524195251952619527195281952919530195311953219533195341953519536195371953819539195401954119542195431954419545195461954719548195491955019551195521955319554195551955619557195581955919560195611956219563195641956519566195671956819569195701957119572195731957419575195761957719578195791958019581195821958319584195851958619587195881958919590195911959219593195941959519596195971959819599196001960119602196031960419605196061960719608196091961019611196121961319614196151961619617196181961919620196211962219623196241962519626196271962819629196301963119632196331963419635196361963719638196391964019641196421964319644196451964619647196481964919650196511965219653196541965519656196571965819659196601966119662196631966419665196661966719668196691967019671196721967319674196751967619677196781967919680196811968219683196841968519686196871968819689196901969119692196931969419695196961969719698196991970019701197021970319704197051970619707197081970919710197111971219713197141971519716197171971819719197201972119722197231972419725197261972719728197291973019731197321973319734197351973619737197381973919740197411974219743197441974519746197471974819749197501975119752197531975419755197561975719758197591976019761197621976319764197651976619767197681976919770197711977219773197741977519776197771977819779197801978119782197831978419785197861978719788197891979019791197921979319794197951979619797197981979919800198011980219803198041980519806198071980819809198101981119812198131981419815198161981719818198191982019821198221982319824198251982619827198281982919830198311983219833198341983519836198371983819839198401984119842198431984419845198461984719848198491985019851198521985319854198551985619857198581985919860198611986219863198641986519866198671986819869198701987119872198731987419875198761987719878198791988019881198821988319884198851988619887198881988919890198911989219893198941989519896198971989819899199001990119902199031990419905199061990719908199091991019911199121991319914199151991619917199181991919920199211992219923199241992519926199271992819929199301993119932199331993419935199361993719938199391994019941199421994319944199451994619947199481994919950199511995219953199541995519956199571995819959199601996119962199631996419965199661996719968199691997019971199721997319974199751997619977199781997919980199811998219983199841998519986199871998819989199901999119992199931999419995199961999719998199992000020001200022000320004200052000620007200082000920010200112001220013200142001520016200172001820019200202002120022200232002420025200262002720028200292003020031200322003320034200352003620037200382003920040200412004220043200442004520046200472004820049200502005120052200532005420055200562005720058200592006020061200622006320064200652006620067200682006920070200712007220073200742007520076200772007820079200802008120082200832008420085200862008720088200892009020091200922009320094200952009620097200982009920100201012010220103201042010520106201072010820109201102011120112201132011420115201162011720118201192012020121201222012320124201252012620127201282012920130201312013220133201342013520136201372013820139201402014120142201432014420145201462014720148201492015020151201522015320154201552015620157201582015920160201612016220163201642016520166201672016820169201702017120172201732017420175201762017720178201792018020181201822018320184201852018620187201882018920190201912019220193201942019520196201972019820199202002020120202202032020420205202062020720208202092021020211202122021320214202152021620217202182021920220202212022220223202242022520226202272022820229202302023120232202332023420235202362023720238202392024020241202422024320244202452024620247202482024920250202512025220253202542025520256202572025820259202602026120262202632026420265202662026720268202692027020271202722027320274202752027620277202782027920280202812028220283202842028520286202872028820289202902029120292202932029420295202962029720298202992030020301203022030320304203052030620307203082030920310203112031220313203142031520316203172031820319203202032120322203232032420325203262032720328203292033020331203322033320334203352033620337203382033920340203412034220343203442034520346203472034820349203502035120352203532035420355203562035720358203592036020361203622036320364203652036620367203682036920370203712037220373203742037520376203772037820379203802038120382203832038420385203862038720388203892039020391203922039320394203952039620397203982039920400204012040220403204042040520406204072040820409204102041120412204132041420415204162041720418204192042020421204222042320424204252042620427204282042920430204312043220433204342043520436204372043820439204402044120442204432044420445204462044720448204492045020451204522045320454204552045620457204582045920460204612046220463204642046520466204672046820469204702047120472204732047420475204762047720478204792048020481204822048320484204852048620487204882048920490204912049220493204942049520496204972049820499205002050120502205032050420505205062050720508205092051020511205122051320514205152051620517205182051920520205212052220523205242052520526205272052820529205302053120532205332053420535205362053720538205392054020541205422054320544205452054620547205482054920550205512055220553205542055520556205572055820559205602056120562205632056420565205662056720568205692057020571205722057320574205752057620577205782057920580205812058220583205842058520586205872058820589205902059120592205932059420595205962059720598205992060020601206022060320604206052060620607206082060920610206112061220613206142061520616206172061820619206202062120622206232062420625206262062720628206292063020631206322063320634206352063620637206382063920640206412064220643206442064520646206472064820649206502065120652206532065420655206562065720658206592066020661206622066320664206652066620667206682066920670206712067220673206742067520676206772067820679206802068120682206832068420685206862068720688206892069020691206922069320694206952069620697206982069920700207012070220703207042070520706207072070820709207102071120712207132071420715207162071720718207192072020721207222072320724207252072620727207282072920730207312073220733207342073520736207372073820739207402074120742207432074420745207462074720748207492075020751207522075320754207552075620757207582075920760207612076220763207642076520766207672076820769207702077120772207732077420775207762077720778207792078020781207822078320784207852078620787207882078920790207912079220793207942079520796207972079820799208002080120802208032080420805208062080720808208092081020811208122081320814208152081620817208182081920820208212082220823208242082520826208272082820829208302083120832208332083420835208362083720838208392084020841208422084320844208452084620847208482084920850208512085220853208542085520856208572085820859208602086120862208632086420865208662086720868208692087020871208722087320874208752087620877208782087920880208812088220883208842088520886208872088820889208902089120892208932089420895208962089720898208992090020901209022090320904209052090620907209082090920910209112091220913209142091520916209172091820919209202092120922209232092420925209262092720928209292093020931209322093320934209352093620937209382093920940209412094220943209442094520946209472094820949209502095120952209532095420955209562095720958209592096020961209622096320964209652096620967209682096920970209712097220973209742097520976209772097820979209802098120982209832098420985209862098720988209892099020991209922099320994209952099620997209982099921000210012100221003210042100521006210072100821009210102101121012210132101421015210162101721018210192102021021210222102321024210252102621027210282102921030210312103221033210342103521036210372103821039210402104121042210432104421045210462104721048210492105021051210522105321054210552105621057210582105921060210612106221063210642106521066210672106821069210702107121072210732107421075210762107721078210792108021081210822108321084210852108621087210882108921090210912109221093210942109521096210972109821099211002110121102211032110421105211062110721108211092111021111211122111321114211152111621117211182111921120211212112221123211242112521126211272112821129211302113121132211332113421135211362113721138211392114021141211422114321144211452114621147211482114921150211512115221153211542115521156211572115821159211602116121162211632116421165211662116721168211692117021171211722117321174211752117621177211782117921180211812118221183211842118521186211872118821189211902119121192211932119421195211962119721198211992120021201212022120321204212052120621207212082120921210212112121221213212142121521216212172121821219212202122121222212232122421225212262122721228212292123021231212322123321234212352123621237212382123921240212412124221243212442124521246212472124821249212502125121252212532125421255212562125721258212592126021261212622126321264212652126621267212682126921270212712127221273212742127521276212772127821279212802128121282212832128421285212862128721288212892129021291212922129321294212952129621297212982129921300213012130221303213042130521306213072130821309213102131121312213132131421315213162131721318213192132021321213222132321324213252132621327213282132921330213312133221333213342133521336213372133821339213402134121342213432134421345213462134721348213492135021351213522135321354213552135621357213582135921360213612136221363213642136521366213672136821369213702137121372213732137421375213762137721378213792138021381213822138321384213852138621387213882138921390213912139221393213942139521396213972139821399214002140121402214032140421405214062140721408214092141021411214122141321414214152141621417214182141921420214212142221423214242142521426214272142821429214302143121432214332143421435214362143721438214392144021441214422144321444214452144621447214482144921450214512145221453214542145521456214572145821459214602146121462214632146421465214662146721468214692147021471214722147321474214752147621477214782147921480214812148221483214842148521486214872148821489214902149121492214932149421495214962149721498214992150021501215022150321504215052150621507215082150921510215112151221513215142151521516215172151821519215202152121522215232152421525215262152721528215292153021531215322153321534215352153621537215382153921540215412154221543215442154521546215472154821549215502155121552215532155421555215562155721558215592156021561215622156321564215652156621567215682156921570215712157221573215742157521576215772157821579215802158121582215832158421585215862158721588215892159021591215922159321594215952159621597215982159921600216012160221603216042160521606216072160821609216102161121612216132161421615216162161721618216192162021621216222162321624216252162621627216282162921630216312163221633216342163521636216372163821639216402164121642216432164421645216462164721648216492165021651216522165321654216552165621657216582165921660216612166221663216642166521666216672166821669216702167121672216732167421675216762167721678216792168021681216822168321684216852168621687216882168921690216912169221693216942169521696216972169821699217002170121702217032170421705217062170721708217092171021711217122171321714217152171621717217182171921720217212172221723217242172521726217272172821729217302173121732217332173421735217362173721738217392174021741217422174321744217452174621747217482174921750217512175221753217542175521756217572175821759217602176121762217632176421765217662176721768217692177021771217722177321774217752177621777217782177921780217812178221783217842178521786217872178821789217902179121792217932179421795217962179721798217992180021801218022180321804218052180621807218082180921810218112181221813218142181521816218172181821819218202182121822218232182421825218262182721828218292183021831218322183321834218352183621837218382183921840218412184221843218442184521846218472184821849218502185121852218532185421855218562185721858218592186021861218622186321864218652186621867218682186921870218712187221873218742187521876218772187821879218802188121882218832188421885218862188721888218892189021891218922189321894218952189621897218982189921900219012190221903219042190521906219072190821909219102191121912219132191421915219162191721918219192192021921219222192321924219252192621927219282192921930219312193221933219342193521936219372193821939219402194121942219432194421945219462194721948219492195021951219522195321954219552195621957219582195921960219612196221963219642196521966219672196821969219702197121972219732197421975219762197721978219792198021981219822198321984219852198621987219882198921990219912199221993219942199521996219972199821999220002200122002220032200422005220062200722008220092201022011220122201322014220152201622017220182201922020220212202222023220242202522026220272202822029220302203122032220332203422035220362203722038220392204022041220422204322044220452204622047220482204922050220512205222053220542205522056220572205822059220602206122062220632206422065220662206722068220692207022071220722207322074220752207622077220782207922080220812208222083220842208522086220872208822089220902209122092220932209422095220962209722098220992210022101221022210322104221052210622107221082210922110221112211222113221142211522116221172211822119221202212122122221232212422125221262212722128221292213022131221322213322134221352213622137221382213922140221412214222143221442214522146221472214822149221502215122152221532215422155221562215722158221592216022161221622216322164221652216622167221682216922170221712217222173221742217522176221772217822179221802218122182221832218422185221862218722188221892219022191221922219322194221952219622197221982219922200222012220222203222042220522206222072220822209222102221122212222132221422215222162221722218222192222022221222222222322224222252222622227222282222922230222312223222233222342223522236222372223822239222402224122242222432224422245222462224722248222492225022251222522225322254222552225622257222582225922260222612226222263222642226522266222672226822269222702227122272222732227422275222762227722278222792228022281222822228322284222852228622287222882228922290222912229222293222942229522296222972229822299223002230122302223032230422305223062230722308223092231022311223122231322314223152231622317223182231922320223212232222323223242232522326223272232822329223302233122332223332233422335223362233722338223392234022341223422234322344223452234622347223482234922350223512235222353223542235522356223572235822359223602236122362223632236422365223662236722368223692237022371223722237322374223752237622377223782237922380223812238222383223842238522386223872238822389223902239122392223932239422395223962239722398223992240022401224022240322404224052240622407224082240922410224112241222413224142241522416224172241822419224202242122422224232242422425224262242722428224292243022431224322243322434224352243622437224382243922440224412244222443224442244522446224472244822449224502245122452224532245422455224562245722458224592246022461224622246322464224652246622467224682246922470224712247222473224742247522476224772247822479224802248122482224832248422485224862248722488224892249022491224922249322494224952249622497224982249922500225012250222503225042250522506225072250822509225102251122512225132251422515225162251722518225192252022521225222252322524225252252622527225282252922530225312253222533225342253522536225372253822539225402254122542225432254422545225462254722548225492255022551225522255322554225552255622557225582255922560225612256222563225642256522566225672256822569225702257122572225732257422575225762257722578225792258022581225822258322584225852258622587225882258922590225912259222593225942259522596225972259822599226002260122602226032260422605226062260722608226092261022611226122261322614226152261622617226182261922620226212262222623226242262522626226272262822629226302263122632226332263422635226362263722638226392264022641226422264322644226452264622647226482264922650226512265222653226542265522656226572265822659226602266122662226632266422665
  1. #include "Module_OcppBackend.h"
  2. #include "define.h"
  3. //ChargePointMaxProfile
  4. #define ChargePointMaxProfile_JSON "/Storage/OCPP/ChargePointMaxProfile.json"
  5. //TxDefaultProfile
  6. #define TxDefaultProfile_0_JSON "/Storage/OCPP/TxDefaultProfile_0.json"
  7. struct SysConfigAndInfo *ShmSysConfigAndInfo;
  8. struct StatusCodeData *ShmStatusCodeData;
  9. struct PsuData *ShmPsuData ;
  10. struct OCPP16Data *ShmOCPP16Data;
  11. //ConfigurationMaxKeys
  12. #define GetConfigurationMaxKeysNUM _GetConfiguration_CNT
  13. pthread_mutex_t lock_send = PTHREAD_MUTEX_INITIALIZER;
  14. char queuedata[QUEUE_MESSAGE_LENGTH] = {0};
  15. //=================================
  16. // StatusNotification cycle
  17. //=================================
  18. static int server_cycle_Status = 120;
  19. //===============================
  20. // Configuration: unknown key
  21. //===============================
  22. static char unknownkey[10][36] = {0};
  23. static int UnknownKeynum = 0;
  24. //===============================
  25. // Gun Total Numbers
  26. //===============================
  27. static ParsingRatedCur modelnameInfo = {0};
  28. static int gunTotalNumber = 0;
  29. static uint8_t gunType[4] = {0};
  30. //===============================
  31. // Local List Version
  32. //===============================
  33. static int locallistVersion=0;
  34. static char idTagAuthorization[32] = {0};
  35. //===============================
  36. // OCPP sign variable
  37. //===============================
  38. static int server_sign = FALSE;
  39. int server_pending = FALSE;
  40. static int BootNotificationInterval = 0;
  41. //===============================
  42. // OCPP auth variable
  43. //===============================
  44. static int authorizeRetryTimes = 0; //number of Retry times
  45. //===============================
  46. // OCPP other variables
  47. //===============================
  48. static int HeartBeatWaitTime = 10;
  49. static int FirstHeartBeat = 0;
  50. static int FirmwareStatusNotificationStatus = FIRMWARE_STATUS_IDLE; // Idle
  51. static int DiagnosticsStatusNotificationStatus = DIAGNOSTIC_STATUS_IDLE; // Idle
  52. static char CurrentChargingProfileScheduleStr[30] = {0};
  53. static float periousPeriodicPowerConsumption[CONNECTOR_QUANTITY] = {0};
  54. static float periousClockPowerConsumption[CONNECTOR_QUANTITY] = {0};
  55. //========================================
  56. // OCPP status/previous related variables
  57. //========================================
  58. static int GunStatusInterval = 10;
  59. static uint8_t ChademoPreviousSystemStatus[(CHAdeMO_QUANTITY>0?CHAdeMO_QUANTITY:1)];
  60. static uint8_t CcsPreviousSystemStatus[(CCS_QUANTITY>0?CCS_QUANTITY:1)];
  61. static uint8_t GbPreviousSystemStatus[(GB_QUANTITY>0?GB_QUANTITY:1)];
  62. static uint8_t AcPreviousSystemStatus[(AC_QUANTITY>0?AC_QUANTITY:1)];
  63. static uint8_t DoPreviousSystemStatus[(CONNECTOR_QUANTITY>0?CONNECTOR_QUANTITY:1)];
  64. static uint8_t ChademoPreviousConnectorPlugIn[(CHAdeMO_QUANTITY>0?CHAdeMO_QUANTITY:1)];
  65. static uint8_t CcsPreviousConnectorPlugIn[(CCS_QUANTITY>0?CCS_QUANTITY:1)];
  66. static uint8_t GbPreviousConnectorPlugIn[(GB_QUANTITY>0?GB_QUANTITY:1)];
  67. static uint8_t AcPreviousConnectorPlugIn[(AC_QUANTITY>0?AC_QUANTITY:1)];
  68. static uint8_t DoPreviousConnectorPlugIn[(CONNECTOR_QUANTITY>0?CONNECTOR_QUANTITY:1)];
  69. static int TransactionMessageAttemptsValue = 0;
  70. static int TransactionMessageRetryIntervalValue = 0;
  71. static int TempMeterValueInterval = 0;
  72. static struct OCPPAuthLocalElemet
  73. {
  74. int listVersionInt;
  75. char idTagstr[21];
  76. char parentIdTag[21];
  77. char expiryDate[36];
  78. char idTagstatus[16];
  79. }idTagQuery;
  80. //============================================
  81. // OCPP MeterValue request flag
  82. //============================================
  83. uint8_t reqSampleMeter[CONNECTOR_QUANTITY]={0};
  84. uint8_t reqClockAlignMeter[CONNECTOR_QUANTITY]={0};
  85. //============================================
  86. // OCPP HeartBeat Response Not Receive Counts
  87. //============================================
  88. static int HeartBeatWithNOResponse = 0;
  89. //============================================
  90. // OCPP California Pricing Requirements
  91. //============================================
  92. static char dmsVersion[21] = {0};
  93. extern sqlite3 *db;
  94. int TransactionMessageAttemptsGet(void);
  95. int TransactionMessageRetryIntervalGet(void);
  96. int GetOcppConnStatus(void);
  97. void SetOcppConnStatus(uint8_t status);
  98. int setKeyValue(char *key, char *value);
  99. void OCPP_get_TableAuthlocalAllData(void);
  100. void processUnkownKey(void);
  101. struct InterLock
  102. {
  103. unsigned char isSentUnplug[CONNECTOR_QUANTITY];
  104. unsigned char isGetDiagnosticGoing:1;
  105. unsigned char isUpdateFirmwareGoing:1;
  106. }interLock;
  107. struct ClientTime
  108. {
  109. struct timespec Heartbeat;
  110. struct timespec StatusNotification[CONNECTOR_QUANTITY];
  111. struct timespec StartTransaction;
  112. struct timespec StopTransaction;
  113. struct timespec MeterValues[CONNECTOR_QUANTITY];
  114. struct timespec RemoteStartWait;
  115. struct timespec TcciQueryDeduct;
  116. struct timespec CharingProfileRefresh[CONNECTOR_QUANTITY];
  117. }clientTime;
  118. typedef union
  119. {
  120. //Operations Initiated by Central System
  121. unsigned char CsMsgValue[CONNECTOR_QUANTITY];
  122. struct
  123. {
  124. //CsMsgValue[0]
  125. unsigned char StatusNotificationReq:1; //bit 0,
  126. unsigned char StatusNotificationConf:1; //bit 1,
  127. unsigned char TriggerMeterValue:1; //bit 2,
  128. unsigned char TriggerStatusNotificationReq:1; //bit 3,
  129. unsigned char isOnCharging:1; //bit 4,
  130. unsigned char :3; //bit5~7
  131. }bits[CONNECTOR_QUANTITY];
  132. }CpinitiateMsg;
  133. CpinitiateMsg cpinitateMsg;
  134. //GetConfiguration Array
  135. struct StructConfigurationKeyItems staticKeyArray[GetConfigurationMaxKeysNUM]={0};
  136. struct StructConfigurationKey staticResponseConfigurationKeyArray[GetConfigurationMaxKeysNUM]={0};
  137. struct StructConfigurationKeyItems staticResponseUnknownKey[10]={0};
  138. struct StructLocalAuthorizationList staticLocalAuthorizationList[1]={0};
  139. static char *ChargePointErrorCodeStr[] = {
  140. MACROSTR(ConnectorLockFailure),
  141. MACROSTR(EVCommunicationError),
  142. MACROSTR(GroundFailure),
  143. MACROSTR(HighTemperature),
  144. MACROSTR(InternalError),
  145. MACROSTR(LocalListConflict),
  146. MACROSTR(NoError),
  147. MACROSTR(OtherError),
  148. MACROSTR(OverCurrentFailure),
  149. MACROSTR(OverVoltage),
  150. MACROSTR(PowerMeterFailure),
  151. MACROSTR(PowerSwitchFailure),
  152. MACROSTR(ReaderFailure),
  153. MACROSTR(ResetFailure),
  154. MACROSTR(UnderVoltage),
  155. MACROSTR(WeakSignal)
  156. };
  157. static char * ChargePointStatusStr[] = {
  158. MACROSTR(Available),
  159. MACROSTR(Preparing),
  160. MACROSTR(Charging),
  161. MACROSTR(SuspendedEVSE),
  162. MACROSTR(SuspendedEV),
  163. MACROSTR(Finishing),
  164. MACROSTR(Reserved),
  165. MACROSTR(Unavailable),
  166. MACROSTR(Faulted)
  167. };
  168. static char *RegistrationStatusStr[] = {
  169. MACROSTR(Accepted),
  170. MACROSTR(Pending),
  171. MACROSTR(Rejected)
  172. };
  173. static char *AvailabilityTypeStr[] = {
  174. MACROSTR(Inoperative),
  175. MACROSTR(Operative)
  176. };
  177. static char *AvailabilityStatusStr[] = {
  178. MACROSTR(Accepted),
  179. MACROSTR(Rejected),
  180. MACROSTR(Scheduled)
  181. };
  182. static char *ConfigurationStatusStr[] = {
  183. MACROSTR(Accepted),
  184. MACROSTR(Rejected),
  185. MACROSTR(RebootRequired),
  186. MACROSTR(NotSupported)
  187. };
  188. static char *ClearCacheStatusStr[] = {
  189. MACROSTR(Accepted),
  190. MACROSTR(Rejected)
  191. };
  192. static char *ChargingProfilePurposeTypeStr[] = {
  193. MACROSTR(ChargePointMaxProfile),
  194. MACROSTR(TxDefaultProfile),
  195. MACROSTR(TxProfile)
  196. };
  197. static char *ChargingProfileStatusStr[] = {
  198. MACROSTR(Accepted),
  199. MACROSTR(Rejected),
  200. MACROSTR(NotSupported)
  201. };
  202. static char *ClearChargingProfileStatusStr[] = {
  203. MACROSTR(Accepted),
  204. MACROSTR(Unknown)
  205. };
  206. static char *GetCompositeScheduleStatusStr[] = {
  207. MACROSTR(Accepted),
  208. MACROSTR(Rejected)
  209. };
  210. static char *UpdateTypeStr[] = {
  211. MACROSTR(Differential),
  212. MACROSTR(Full)
  213. };
  214. static char *UpdateStatusStr[] = {
  215. MACROSTR(Accepted),
  216. MACROSTR(Failed),
  217. MACROSTR(NotSupported),
  218. MACROSTR(VersionMismatch)
  219. };
  220. static char *RemoteStartStopStatusStr[] = {
  221. MACROSTR(Accepted),
  222. MACROSTR(Rejected)
  223. };
  224. static char *ReservationStatusStr[] = {
  225. MACROSTR(Accepted),
  226. MACROSTR(Faulted),
  227. MACROSTR(Occupied),
  228. MACROSTR(Rejected),
  229. MACROSTR(Unavailable)
  230. };
  231. static char *ResetTypeStr[] = {
  232. MACROSTR(Hard),
  233. MACROSTR(Soft)
  234. };
  235. static char *ResetStatusStr[] = {
  236. MACROSTR(Accepted),
  237. MACROSTR(Rejected)
  238. };
  239. static char * DiagnosticsStatusStr[] = {
  240. MACROSTR(Idle),
  241. MACROSTR(Uploaded),
  242. MACROSTR(UploadFailed),
  243. MACROSTR(Uploading)
  244. };
  245. static char * FirmwareStatusStr[] = {
  246. MACROSTR(Downloaded),
  247. MACROSTR(DownloadFailed),
  248. MACROSTR(Downloading),
  249. MACROSTR(Idle),
  250. MACROSTR(InstallationFailed),
  251. MACROSTR(Installing),
  252. MACROSTR(Installed)
  253. };
  254. static char * MessageTriggerStr[] = {
  255. MACROSTR(BootNotification),
  256. MACROSTR(DiagnosticsStatusNotification),
  257. MACROSTR(FirmwareStatusNotification),
  258. MACROSTR(Heartbeat),
  259. MACROSTR(MeterValues),
  260. MACROSTR(StatusNotification)
  261. };
  262. static char * TriggerMessageStatusStr[] = {
  263. MACROSTR(Accepted),
  264. MACROSTR(Rejected),
  265. MACROSTR(NotImplemented)
  266. };
  267. static char * UnlockStatusStr[] = {
  268. MACROSTR(Unlocked),
  269. MACROSTR(UnlockFailed),
  270. MACROSTR(NotSupported)
  271. };
  272. #if 0
  273. static char * StopTransactionReasonStr[] = {
  274. MACROSTR(EmergencyStop),
  275. MACROSTR(EVDisconnected),
  276. MACROSTR(HardReset),
  277. MACROSTR(Local),
  278. MACROSTR(Other),
  279. MACROSTR(PowerLoss),
  280. MACROSTR(Reboot),
  281. MACROSTR(Remote),
  282. MACROSTR(SoftReset),
  283. MACROSTR(UnlockCommand),
  284. MACROSTR(DeAuthorized)
  285. };
  286. #endif
  287. static char * CancelReservationStatusStr[] = {
  288. MACROSTR(Accepted),
  289. MACROSTR(Rejected)
  290. };
  291. static char * ReadingContextStr[] = {
  292. MACROSTR(Interruption.Begin),
  293. MACROSTR(Interruption.End),
  294. MACROSTR(Other),
  295. MACROSTR(Sample.Clock),
  296. MACROSTR(Sample.Periodic),
  297. MACROSTR(Transaction.Begin),
  298. MACROSTR(Transaction.End),
  299. MACROSTR(Trigger)
  300. };
  301. static char * ValueFormatStr[] = {
  302. MACROSTR(Raw),
  303. MACROSTR(SignedData)
  304. };
  305. static char * MeasurandStr[] = {
  306. MACROSTR(Current.Export),
  307. MACROSTR(Current.Import),
  308. MACROSTR(Current.Offered),
  309. MACROSTR(Energy.Active.Export.Register),
  310. MACROSTR(Energy.Active.Import.Register),
  311. MACROSTR(Energy.Reactive.Export.Register),
  312. MACROSTR(Energy.Reactive.Import.Register),
  313. MACROSTR(Energy.Active.Export.Interval),
  314. MACROSTR(Energy.Active.Import.Interval),
  315. MACROSTR(Energy.Reactive.Export.Interval),
  316. MACROSTR(Energy.Reactive.Import.Interval),
  317. MACROSTR(Frequency),
  318. MACROSTR(Power.Active.Export),
  319. MACROSTR(Power.Active.Import),
  320. MACROSTR(Power.Factor),
  321. MACROSTR(Power.Offered),
  322. MACROSTR(Power.Reactive.ExportMACROSTR),
  323. MACROSTR(Power.Reactive.Import),
  324. MACROSTR(RPM),
  325. MACROSTR(SoC),
  326. MACROSTR(Temperature),
  327. MACROSTR(Voltage)
  328. };
  329. static char * LocationStr[] = {
  330. MACROSTR(Body),
  331. MACROSTR(Cable),
  332. MACROSTR(EV),
  333. MACROSTR(Inlet),
  334. MACROSTR(Outlet)
  335. };
  336. static char * PhaseStr[] = {
  337. MACROSTR(L1),
  338. MACROSTR(L2),
  339. MACROSTR(L3),
  340. MACROSTR(N),
  341. MACROSTR(L1-N),
  342. MACROSTR(L2-N),
  343. MACROSTR(L3-N),
  344. MACROSTR(L1-L2),
  345. MACROSTR(L2-L3),
  346. MACROSTR(L3-L1)
  347. };
  348. static char * UnitOfMeasureStr[] = {
  349. MACROSTR(Wh),
  350. MACROSTR(kWh),
  351. MACROSTR(varh),
  352. MACROSTR(kvarh),
  353. MACROSTR(W),
  354. MACROSTR(kW),
  355. MACROSTR(VA),
  356. MACROSTR(kVA),
  357. MACROSTR(var),
  358. MACROSTR(kvar),
  359. MACROSTR(A),
  360. MACROSTR(V),
  361. MACROSTR(Celsius),
  362. MACROSTR(Fahrenheit),
  363. MACROSTR(K),
  364. MACROSTR(Percent)
  365. };
  366. //=========================================
  367. // TTIA routine
  368. //=========================================
  369. int sendTTIAInfo(uint8_t gun_index)
  370. {
  371. static int sn = 0;
  372. int result = FAIL;
  373. struct hostent *server;
  374. int udp_socket_fd;
  375. struct sockaddr_in dest_addr = {0};
  376. uint8_t tx_buf[80] = {0};
  377. uint8_t logBuf[256]= {0};
  378. uint8_t tx_len, tempIndex, socStart, socEnd;
  379. uint16_t PresentChargedEnergy;
  380. struct tm tmStart, tmEnd;
  381. DEBUG_INFO("sendTTIAInfo...\n");
  382. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  383. {
  384. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  385. {
  386. tempIndex = ((gun_index==2) ? 1: 0);
  387. }
  388. else
  389. {
  390. tempIndex = gun_index;
  391. }
  392. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  393. {
  394. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  395. {
  396. socStart = ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].EvBatteryStartSoc;
  397. socEnd = ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].EvBatterySoc;
  398. PresentChargedEnergy = (uint16_t)(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargedEnergy*10);
  399. }
  400. }
  401. }
  402. else if(gunType[gun_index] == GUN_TYPE_CCS)
  403. {
  404. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  405. {
  406. tempIndex = ((gun_index==2) ? 1: 0);
  407. }
  408. else
  409. {
  410. tempIndex = gun_index;
  411. }
  412. for (int index = 0; index < CCS_QUANTITY; index++)
  413. {
  414. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  415. {
  416. socStart = ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].EvBatteryStartSoc;
  417. socEnd = ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].EvBatterySoc;
  418. PresentChargedEnergy = (uint16_t)(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargedEnergy*10);
  419. }
  420. }
  421. }
  422. else if(gunType[gun_index] == GUN_TYPE_GBT)
  423. {
  424. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  425. {
  426. tempIndex = ((gun_index==2) ? 1: 0);
  427. }
  428. else
  429. {
  430. tempIndex = gun_index;
  431. }
  432. for (int index = 0; index < GB_QUANTITY; index++)
  433. {
  434. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  435. {
  436. socStart = ShmSysConfigAndInfo->SysInfo.GbChargingData[index].EvBatteryStartSoc;
  437. socEnd = ShmSysConfigAndInfo->SysInfo.GbChargingData[index].EvBatterySoc;
  438. PresentChargedEnergy = (uint16_t)(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargedEnergy*10);
  439. }
  440. }
  441. }
  442. else if(gunType[gun_index] == GUN_TYPE_DO)
  443. {
  444. tempIndex = gun_index;
  445. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  446. {
  447. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  448. {
  449. socStart = ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.EvBatteryStartSoc;
  450. socEnd = ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.EvBatterySoc;
  451. PresentChargedEnergy = (uint16_t)(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PresentChargedEnergy*10);
  452. }
  453. }
  454. }
  455. else
  456. {
  457. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  458. {
  459. tempIndex = 2;
  460. }
  461. else
  462. {
  463. tempIndex = gun_index;
  464. }
  465. for (int index = 0; index < AC_QUANTITY; index++)
  466. {
  467. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  468. {
  469. socStart = ShmSysConfigAndInfo->SysInfo.AcChargingData[index].EvBatteryStartSoc;
  470. socEnd = ShmSysConfigAndInfo->SysInfo.AcChargingData[index].EvBatterySoc;
  471. PresentChargedEnergy = (uint16_t)(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargedEnergy*10);
  472. }
  473. }// END
  474. }
  475. // Message assembly
  476. sprintf((char*)&tx_buf[0], "APTS"); // Protocol ID
  477. tx_buf[4] = 0x02; // Protocol Version
  478. tx_buf[5] = 0xb0; // Message ID
  479. tx_buf[6] = ShmSysConfigAndInfo->SysConfig.TTIA_Info.busVenderId & 0xff; // CustomerID low byte
  480. tx_buf[7] = (ShmSysConfigAndInfo->SysConfig.TTIA_Info.busVenderId>>8) & 0xff; // CustomerID high byte
  481. tx_buf[8] = 0x00; // CarID low byte
  482. tx_buf[9] = 0x00; // CarID high byte
  483. tx_buf[10] = 0x00; // ID Storage
  484. tx_buf[11] = 0x00; // Driver lowest byte
  485. tx_buf[12] = 0x00; // Driver 2nd byte
  486. tx_buf[13] = 0x00; // Driver 3rd byte
  487. tx_buf[14] = 0x00; // Driver highest byte
  488. tx_buf[15] = sn & 0xff; // Sequence SN low byte
  489. tx_buf[16] = (sn>>8) & 0xff; // Sequence SN high byte
  490. tx_buf[17] = 0x00; // Reserve
  491. tx_buf[18] = 60 & 0xff; // Payload length low byte
  492. tx_buf[19] = (60>>8) & 0xff; // Payload length high byte
  493. // EVSE provider
  494. memcpy((char*)&tx_buf[20], ShmSysConfigAndInfo->SysConfig.TTIA_Info.EquipmentProvider, 15);
  495. // EVSE provider
  496. tx_buf[35] = ShmSysConfigAndInfo->SysConfig.TTIA_Info.TransportationCompanyNo;
  497. // EVSE id
  498. tx_buf[36] = ShmSysConfigAndInfo->SysConfig.TTIA_Info.ChargeBoxId;
  499. // Connector id
  500. tx_buf[37] = gun_index;
  501. // EVSE station
  502. memcpy((char*)&tx_buf[38], ShmSysConfigAndInfo->SysConfig.TTIA_Info.evseStation, 15);
  503. // Vehicle SN
  504. memcpy(&tx_buf[53], &ShmOCPP16Data->StartTransaction[gun_index].IdTag, 8);
  505. // Mileage
  506. tx_buf[61] = 0x00; // lowest byte
  507. tx_buf[62] = 0x00; // 2nd byte
  508. tx_buf[63] = 0x00; // highest byte
  509. // Start date time 6 bytes
  510. if((sscanf((char*)ShmOCPP16Data->StartTransaction[gun_index].Timestamp, "%4d-%2d-%2dT%2d:%2d:%2d", &tmStart.tm_year, &tmStart.tm_mon, &tmStart.tm_mday, &tmStart.tm_hour, &tmStart.tm_min, &tmStart.tm_sec) == 6))
  511. {
  512. struct tm *tmTarget;
  513. struct timeb tbTarget;
  514. tmStart.tm_year -= 1900;
  515. tmStart.tm_mon -= 1;
  516. tmStart.tm_gmtoff = 0;
  517. tbTarget.time = mktime(&tmStart);
  518. tbTarget.timezone = 0;
  519. tbTarget.time += (8*3600);
  520. tmTarget = gmtime(&tbTarget.time);
  521. tx_buf[64] = ((tmTarget->tm_year+1900)-2000);
  522. tx_buf[65] = (tmTarget->tm_mon+1);
  523. tx_buf[66] = tmTarget->tm_mday;
  524. tx_buf[67] = tmTarget->tm_hour;
  525. tx_buf[68] = tmTarget->tm_min;
  526. tx_buf[69] = tmTarget->tm_sec;
  527. }
  528. // Stop date time 6 bytes
  529. if((sscanf((char*)ShmOCPP16Data->StopTransaction[gun_index].Timestamp, "%4d-%2d-%2dT%2d:%2d:%2d", &tmEnd.tm_year, &tmEnd.tm_mon, &tmEnd.tm_mday, &tmEnd.tm_hour, &tmEnd.tm_min, &tmEnd.tm_sec) == 6))
  530. {
  531. struct tm *tmTarget;
  532. struct timeb tbTarget;
  533. tmEnd.tm_year -= 1900;
  534. tmEnd.tm_mon -= 1;
  535. tmEnd.tm_gmtoff = 0;
  536. tbTarget.time = mktime(&tmEnd);
  537. tbTarget.timezone = 0;
  538. tbTarget.time += (8*3600);
  539. tmTarget = gmtime(&tbTarget.time);
  540. tx_buf[70] = ((tmTarget->tm_year+1900)-2000);
  541. tx_buf[71] = (tmTarget->tm_mon+1);
  542. tx_buf[72] = tmTarget->tm_mday;
  543. tx_buf[73] = tmTarget->tm_hour;
  544. tx_buf[74] = tmTarget->tm_min;
  545. tx_buf[75] = tmTarget->tm_sec;
  546. }
  547. // Session energy 2 bytes
  548. tx_buf[76] = PresentChargedEnergy & 0xff;
  549. tx_buf[77] = (PresentChargedEnergy>>8) & 0xff;
  550. // Start SOC 1 byte
  551. tx_buf[78] = socStart;
  552. // Stop SOC 1 byte
  553. tx_buf[79] = socEnd;
  554. // Open socket
  555. udp_socket_fd = socket(AF_INET, SOCK_DGRAM, 0);
  556. if(udp_socket_fd == -1)
  557. {
  558. DEBUG_ERROR("UDP socket create failed!\n");
  559. }
  560. else
  561. {
  562. // Get server DNS entry
  563. server = gethostbyname((char*)ShmSysConfigAndInfo->SysConfig.TTIA_Info.server_addr);
  564. if (server == NULL)
  565. {
  566. DEBUG_ERROR("ERROR, no such host as %s\n", ShmSysConfigAndInfo->SysConfig.TTIA_Info.server_addr);
  567. }
  568. else
  569. {
  570. // Build the server's Internet address
  571. bzero((char *) &dest_addr, sizeof(dest_addr));
  572. dest_addr.sin_family = AF_INET;
  573. bcopy((char *)server->h_addr, (char *)&dest_addr.sin_addr.s_addr, server->h_length);
  574. dest_addr.sin_port = htons(ShmSysConfigAndInfo->SysConfig.TTIA_Info.server_port);
  575. if((tx_len = sendto(udp_socket_fd, tx_buf, ARRAY_SIZE(tx_buf), 0, &dest_addr, sizeof(dest_addr))) >= 0)
  576. {
  577. for(uint8_t idx=0;idx<ARRAY_SIZE(tx_buf);idx++)
  578. {
  579. sprintf((char*)logBuf, "%s %02X", logBuf, tx_buf[idx]);
  580. }
  581. DEBUG_TTIA_INFO("TX raw data length: %d\n", tx_len);
  582. DEBUG_TTIA_INFO("Message raw: %s\n", logBuf);
  583. DEBUG_TTIA_INFO("OCPP Transaction ID: %d\n", ShmOCPP16Data->StopTransaction[gun_index].TransactionId);
  584. DEBUG_TTIA_INFO("TTIA server address: %s\n", ShmSysConfigAndInfo->SysConfig.TTIA_Info.server_addr);
  585. DEBUG_TTIA_INFO("TTIA server port: %d\n", ShmSysConfigAndInfo->SysConfig.TTIA_Info.server_port);
  586. DEBUG_TTIA_INFO("---------- Header ----------\n");
  587. DEBUG_TTIA_INFO("ProtocolID: APTS\n");
  588. DEBUG_TTIA_INFO("ProtocolVer: 0x02\n");
  589. DEBUG_TTIA_INFO("MessageID: 0xB0\n");
  590. DEBUG_TTIA_INFO("CustomerID: 0x%04X\n", ShmSysConfigAndInfo->SysConfig.TTIA_Info.busVenderId);
  591. DEBUG_TTIA_INFO("CarID: 0x0000\n");
  592. DEBUG_TTIA_INFO("IDStorage: 0x00\n");
  593. DEBUG_TTIA_INFO("DriverID: 0x00000000\n");
  594. DEBUG_TTIA_INFO("Sequence: %d\n", sn);
  595. DEBUG_TTIA_INFO("Reserved: 0x00\n");
  596. DEBUG_TTIA_INFO("Len: 0x3C\n");
  597. DEBUG_TTIA_INFO("--------- Payload ---------\n");
  598. DEBUG_TTIA_INFO("EquipmentProvider: %s\n", ShmSysConfigAndInfo->SysConfig.TTIA_Info.EquipmentProvider);
  599. DEBUG_TTIA_INFO("TransportationCompanyNo: %d\n", ShmSysConfigAndInfo->SysConfig.TTIA_Info.TransportationCompanyNo);
  600. DEBUG_TTIA_INFO("ChargeBoxId: %d\n", ShmSysConfigAndInfo->SysConfig.TTIA_Info.ChargeBoxId);
  601. DEBUG_TTIA_INFO("Gun index: %d\n", gun_index);
  602. DEBUG_TTIA_INFO("evseStation: %s\n", ShmSysConfigAndInfo->SysConfig.TTIA_Info.evseStation);
  603. DEBUG_TTIA_INFO("EV vehicle: %s\n", ShmOCPP16Data->StartTransaction[gun_index].IdTag);
  604. DEBUG_TTIA_INFO("EV mileage: 000000\n");
  605. DEBUG_TTIA_INFO("Session start data time: %s\n", ShmOCPP16Data->StartTransaction[gun_index].Timestamp);
  606. DEBUG_TTIA_INFO("Session stop data time: %s\n", ShmOCPP16Data->StopTransaction[gun_index].Timestamp);
  607. DEBUG_TTIA_INFO("Session charged energy (kwh): %f\n", (PresentChargedEnergy/10.0));
  608. DEBUG_TTIA_INFO("Session start SOC: %d\n", socStart);
  609. DEBUG_TTIA_INFO("Session end SOC: %d\n", socEnd);
  610. DEBUG_TTIA_INFO("=========================================\n");
  611. sn++;
  612. result = PASS;
  613. }
  614. else
  615. {
  616. DEBUG_ERROR("UDP sent out fail.\n");
  617. }
  618. }
  619. }
  620. return result;
  621. }
  622. //=========================================
  623. // Save configuration
  624. //=========================================
  625. int runShellCmd(const char*cmd)
  626. {
  627. int result = FAIL;
  628. char buf[256];
  629. FILE *fp;
  630. fp = popen(cmd, "r");
  631. if(fp != NULL)
  632. {
  633. while(fgets(buf, sizeof(buf), fp) != NULL)
  634. {
  635. DEBUG_INFO("%s\n", buf);
  636. }
  637. result = PASS;
  638. }
  639. pclose(fp);
  640. return result;
  641. }
  642. int StoreUsrConfigData(struct SysConfigData *UsrData)
  643. {
  644. int result = PASS;
  645. int fd,wrd;
  646. unsigned int i,Chk;
  647. unsigned char *ptr, *BufTmp;
  648. int MtdBlockSize = 0x300000;
  649. Chk=0;
  650. ptr=(unsigned char *)UsrData;
  651. if((BufTmp=malloc(MtdBlockSize))!=NULL)
  652. {
  653. memset(BufTmp,0,MtdBlockSize);
  654. memcpy(BufTmp,ptr,sizeof(struct SysConfigData));
  655. for(i=ARRAY_SIZE(UsrData->CsuBootLoadFwRev);i<MtdBlockSize-4;i++)
  656. Chk+=*(BufTmp+i);
  657. memcpy(BufTmp+MtdBlockSize-4, &Chk, 4);
  658. // Output configuration to file.
  659. fd = open("/mnt/EvseConfig.bin", O_RDWR|O_CREAT);
  660. if (fd < 0)
  661. {
  662. DEBUG_ERROR("open /mnt/EvseConfig.bin NG\n");
  663. free(BufTmp);
  664. return 0;
  665. }
  666. wrd=write(fd, BufTmp, MtdBlockSize);
  667. close(fd);
  668. if(wrd<MtdBlockSize)
  669. {
  670. DEBUG_ERROR("write /mnt/EvseConfig.bin NG\n");
  671. free(BufTmp);
  672. return 0;
  673. }
  674. DEBUG_INFO("EvseConfig write to file in /mnt OK.\n");
  675. DEBUG_INFO("Erase /dev/mtd10.\n");
  676. runShellCmd("flash_erase /dev/mtd10 0 0");
  677. DEBUG_INFO("Write /dev/mtd10.\n");
  678. runShellCmd("nandwrite -p /dev/mtd10 /mnt/EvseConfig.bin");
  679. DEBUG_INFO("Erase /dev/mtd11.\n");
  680. runShellCmd("flash_erase /dev/mtd11 0 0");
  681. DEBUG_INFO("Write /dev/mtd11.\n");
  682. runShellCmd("nandwrite -p /dev/mtd11 /mnt/EvseConfig.bin");
  683. system("rm -f /mnt/EvseConfig.bin");
  684. DEBUG_INFO("EvseConfig write to flash OK\n");
  685. }
  686. else
  687. {
  688. DEBUG_ERROR("alloc BlockSize NG\r\n");
  689. result = FAIL;
  690. }
  691. if(BufTmp!=NULL)
  692. free(BufTmp);
  693. return result;
  694. }
  695. //=========================================
  696. // Sqlite3 related function
  697. //=========================================
  698. static int selectSqlCount = 0;
  699. static int callback(void *data, int argc, char **argv, char **azColName){
  700. int i;
  701. //printf("%s: ", (const char*)data);
  702. selectSqlCount = argc;
  703. for(i = 0; i<argc; i++){
  704. // printf("%s = %s\n", azColName[i], argv[i] ? argv[i] : "NULL");
  705. }
  706. //printf("\n");
  707. return 0;
  708. }
  709. static int versioncallback(void *data, int argc, char **argv, char **azColName){
  710. //int i;
  711. //printf("%s:\n", (const char*)data);
  712. locallistVersion = (argv[5] ? atoi(argv[5]) : 0);
  713. DEBUG_INFO("Callback query locallistVersion : %d\n", locallistVersion);
  714. return 0;
  715. }
  716. static int IdTagcallback(void *data, int columenCount, char **columnValue, char **columnName){
  717. //printf("%s:\n", (const char*)data);
  718. //idTag
  719. sprintf(idTagAuthorization,"%s", columnValue[1] ? columnValue[1] : "NULL");
  720. sprintf(idTagQuery.idTagstr,"%s", columnValue[1] ? columnValue[1] : "NULL");
  721. //parentIdTag
  722. sprintf(idTagQuery.parentIdTag,"%s", columnValue[2] ? columnValue[2] : "NULL");
  723. //expir_date
  724. sprintf(idTagQuery.expiryDate,"%s", columnValue[3] ? columnValue[3] : "NULL");
  725. //status
  726. sprintf(idTagQuery.idTagstatus,"%s", columnValue[4] ? columnValue[4] : "NULL");
  727. //version
  728. if(columenCount > 5)
  729. idTagQuery.listVersionInt = atoi(columnValue[5]);
  730. //DEBUG_INFO("IdTag=%s\n", idTagAuthorization);
  731. return 0;
  732. }
  733. static int deleteIdTagcallback(void *data, int argc, char **argv, char **azColName)
  734. {
  735. // localversion = argv[5] ? atoi(argv[5]) : 0;
  736. // printf("localversion=%d\n", localversion);
  737. return 0;
  738. }
  739. int sqlite3_exec_callback(void *data, int n_columns, char **col_values, char **col_names)
  740. {
  741. for (int i = 0; i < n_columns; i++)
  742. {
  743. DEBUG_INFO("%s\t", col_values[i]);
  744. }
  745. DEBUG_INFO("\n");
  746. return 0;
  747. }
  748. int OCPP_cleanLocalCache()
  749. {
  750. char * sqlcleanLocalList = "delete from ocpp_auth_cache";
  751. char *errMsg = 0;
  752. int rc =sqlite3_exec(db, sqlcleanLocalList, 0, 0, &errMsg);
  753. if (SQLITE_OK != rc)
  754. {
  755. DEBUG_INFO("SQL error: %s\n",errMsg);
  756. return FALSE;
  757. }
  758. return TRUE;
  759. }
  760. int OCPP_addLocalCache(char *idTag, char *parentTage, char *expiryDate, char *status)
  761. {
  762. int isSuccess = TRUE;
  763. int ret = 0;
  764. //const char* data = "Callback function called";
  765. char sql[300];
  766. char zErrMsg[200];
  767. memset(sql, 0, 300);
  768. memset(zErrMsg, 0, 200);
  769. sprintf(sql, "insert or replace into ocpp_auth_cache (idtag, parent_idtag, expir_date, status) " "VALUES ('%s', '%s', '%s', '%s'); ""SELECT * from ocpp_auth_cache", idTag, parentTage, expiryDate, status);
  770. //* Execute SQL statement */
  771. ret = sqlite3_exec(db, sql, callback, 0, (char **)&zErrMsg);
  772. if( ret != SQLITE_OK )
  773. {
  774. DEBUG_INFO("SQL error: %s\n", zErrMsg);
  775. isSuccess = FALSE;
  776. }
  777. return isSuccess;
  778. }
  779. void OCPP_getIdTagFromLocalCache(char idTag[])
  780. {
  781. int rc = 0;
  782. char sql[100];
  783. char zErrMsg[100];
  784. memset(sql, 0, 100);
  785. memset(zErrMsg, 0, 100);
  786. memset(idTagAuthorization, 0, ARRAY_SIZE(idTagAuthorization));
  787. memset(&idTagQuery, 0, sizeof(idTagQuery));
  788. sprintf(sql,"select * from ocpp_auth_cache where idtag='%s'", idTag);
  789. /* Execute SQL statement */
  790. rc = sqlite3_exec(db, sql, IdTagcallback, 0, (char **)&zErrMsg);
  791. if( rc != SQLITE_OK )
  792. {
  793. DEBUG_INFO("SQL error: %s\n", zErrMsg);
  794. }
  795. }
  796. void OCPP_getListVerion()
  797. {
  798. int rc = 0;
  799. // const char* data = "Callback function called";
  800. char sql[100];
  801. char zErrMsg[100];
  802. memset(sql, 0, 100);
  803. memset(zErrMsg, 0, 100);
  804. strcpy(sql, "select * from ocpp_auth_local order by version desc, idx desc limit 1");
  805. /* Execute SQL statement */
  806. rc = sqlite3_exec(db, sql, versioncallback, 0, (char **)&zErrMsg);
  807. if( rc != SQLITE_OK )
  808. {
  809. DEBUG_INFO("SQL error: %s\n", zErrMsg);
  810. }
  811. }
  812. void OCPP_get_TableAuthlocalAllData(void)
  813. {
  814. int rc = 0;
  815. char sql[100];
  816. char zErrMsg[100];
  817. memset(sql, 0, 100);
  818. memset(zErrMsg, 0, 100);
  819. sprintf(sql,"select * from ocpp_auth_local ");
  820. /* Execute SQL statement */
  821. rc = sqlite3_exec(db, sql, &sqlite3_exec_callback, 0,(char **)&zErrMsg);
  822. if( rc != SQLITE_OK )
  823. {
  824. DEBUG_INFO("SQL error: %s\n", zErrMsg);
  825. }
  826. //return ver;
  827. }
  828. int OCPP_cleanLocalList()
  829. {
  830. char * sqlcleanLocalList = "delete from ocpp_auth_local";
  831. char *errMsg = 0;
  832. int rc =sqlite3_exec(db, sqlcleanLocalList, 0, 0, &errMsg);
  833. if (SQLITE_OK != rc)
  834. {
  835. DEBUG_INFO("%s\n",errMsg);
  836. return FALSE;
  837. }
  838. return TRUE;
  839. }
  840. int OCPP_addLocalList(int version, char *idTag, char *parentTage, char *expiryDate, char *status)
  841. {
  842. int isSuccess = FALSE;
  843. int ret = 0;
  844. //const char* data = "Callback function called";
  845. char sql[300];
  846. char zErrMsg[200];
  847. memset(sql, 0, 300);
  848. memset(zErrMsg, 0, 200);
  849. sprintf(sql,"insert or replace into ocpp_auth_local (idtag, parent_idtag, expir_date, status, version) " "VALUES ('%s', '%s', '%s', '%s', %d ); ""SELECT * from ocpp_auth_local", idTag, parentTage, expiryDate, status, version);
  850. //* Execute SQL statement */
  851. ret = sqlite3_exec(db, sql, callback, 0, (char **)&zErrMsg);
  852. if( ret != SQLITE_OK )
  853. {
  854. DEBUG_INFO("SQL error: %s\n", zErrMsg);
  855. return isSuccess;
  856. }
  857. memset(sql, 0, 300);
  858. sprintf(sql, "UPDATE ocpp_auth_local SET version=%d",version);
  859. ret = sqlite3_exec(db, sql, NULL, NULL, (char **)&zErrMsg);
  860. if( ret != SQLITE_OK )
  861. {
  862. DEBUG_INFO("SQL error: %s\n", zErrMsg);
  863. return isSuccess;
  864. }
  865. isSuccess = TRUE;
  866. return isSuccess;
  867. }
  868. void OCPP_getIdTagFromLocalList(char idTag[])
  869. {
  870. int rc = 0;
  871. // const char* data = "Callback function called";
  872. char sql[100];
  873. char zErrMsg[100];
  874. memset(sql, 0, 100);
  875. memset(zErrMsg, 0, 100);
  876. memset(idTagAuthorization, 0, ARRAY_SIZE(idTagAuthorization));
  877. memset(&idTagQuery, 0, sizeof(idTagQuery));
  878. //DEBUG_INFO("look up card: %s in ocpp_auth_local table", idTag);
  879. sprintf(sql,"select * from ocpp_auth_local where idtag='%s'", idTag);
  880. /* Execute SQL statement */
  881. rc = sqlite3_exec(db, sql, IdTagcallback, 0, (char **)&zErrMsg);
  882. if( rc != SQLITE_OK )
  883. {
  884. DEBUG_INFO("SQL error: %s\n", zErrMsg);
  885. }
  886. //return ver;
  887. }
  888. void OCPP_deleteIdTagFromLocalList(char idTag[])
  889. {
  890. //int ver = 0;
  891. //int isSuccess = FALSE;
  892. int rc = 0;
  893. char sql[100];
  894. char zErrMsg[100];
  895. memset(sql, 0, 100);
  896. memset(zErrMsg, 0, 100);
  897. sprintf(sql,"DELETE from ocpp_auth_local where idtag='%s'; SELECT * from ocpp_auth_local;", idTag);
  898. //* Execute SQL statement */
  899. rc = sqlite3_exec(db, sql, deleteIdTagcallback, 0,(char **)&zErrMsg);
  900. if( rc != SQLITE_OK )
  901. {
  902. DEBUG_INFO("SQL error: %s\n", zErrMsg);
  903. }
  904. }
  905. int getCurrentYear()
  906. {
  907. int result = 0;
  908. time_t CurrentTime;
  909. struct tm *tm;
  910. CurrentTime = time(NULL);
  911. tm=localtime(&CurrentTime);
  912. result = (tm->tm_year + 1900);
  913. return result;
  914. }
  915. int OCPP_insert_transaction_msg(uint8_t isStartTransaction, char *transactionMsg)
  916. {
  917. int result = PASS;
  918. char* errMsg = NULL;
  919. char sqlStr[8192];
  920. sprintf(sqlStr, "insert into ocpp_transaction_record(occurDatetime, message_type, message_content) values(CURRENT_TIMESTAMP, '%s', '%s');", (isStartTransaction?"startTransaction":"stopTransaction"), transactionMsg);
  921. if (sqlite3_exec(db, sqlStr, 0, 0, &errMsg) != SQLITE_OK)
  922. {
  923. result = FAIL;
  924. DEBUG_WARN( "Insert local transaction record error message: %s\n", errMsg);
  925. }
  926. sprintf(sqlStr, "delete from ocpp_transaction_record where (idx < (select idx from ocpp_transaction_record order by idx desc limit 1)-2000) and (occurDatetime < '%04d-01-01 00:00:00');", (getCurrentYear()-3));
  927. if (sqlite3_exec(db, sqlStr, 0, 0, &errMsg) != SQLITE_OK)
  928. {
  929. result = FAIL;
  930. DEBUG_WARN( "delete local transaction record error message: %s\n", errMsg);
  931. }
  932. return result;
  933. }
  934. int OCPP_updatePeriodEnergy(uint8_t gun_index)
  935. {
  936. int isSuccess = TRUE;
  937. int tempIndex;
  938. json_object *EnergyDataTransfer = json_object_new_object();
  939. json_object *periodEnergys = json_object_new_object();
  940. char sql[1024];
  941. char zErrMsg[200];
  942. memset(sql, 0, ARRAY_SIZE(sql));
  943. memset(zErrMsg, 0, ARRAY_SIZE(zErrMsg));
  944. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  945. {
  946. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  947. {
  948. tempIndex = ((gun_index==2) ? 1: 0);
  949. }
  950. else
  951. {
  952. tempIndex = gun_index;
  953. }
  954. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  955. {
  956. if ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex))
  957. {
  958. json_object_object_add(EnergyDataTransfer, "txId", json_object_new_int(ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId));
  959. for(uint8_t idxPeriod=0;idxPeriod<ARRAY_SIZE(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].presentChargedEnergyPeriod);idxPeriod++)
  960. {
  961. uint8_t period[3];
  962. sprintf((char*)period, "%d", idxPeriod);
  963. json_object_object_add(periodEnergys, (const char *)period, json_object_new_double(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].presentChargedEnergyPeriod[idxPeriod]));
  964. }
  965. json_object_object_add(EnergyDataTransfer, "periodEnergy", periodEnergys);
  966. } //end of the same index
  967. }//end of for CHAdeMO_QUANTITY
  968. }
  969. else if(gunType[gun_index] == GUN_TYPE_CCS)
  970. {
  971. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  972. {
  973. tempIndex = ((gun_index==2) ? 1: 0);
  974. }
  975. else
  976. {
  977. tempIndex = gun_index;
  978. }
  979. for (int index = 0; index < CCS_QUANTITY; index++)
  980. {
  981. if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  982. {
  983. json_object_object_add(EnergyDataTransfer, "txId", json_object_new_int(ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId));
  984. for(uint8_t idxPeriod=0;idxPeriod<ARRAY_SIZE(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].presentChargedEnergyPeriod);idxPeriod++)
  985. {
  986. uint8_t period[3];
  987. sprintf((char*)period, "%d", idxPeriod);
  988. json_object_object_add(periodEnergys, (const char *)period, json_object_new_double(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].presentChargedEnergyPeriod[idxPeriod]));
  989. }
  990. json_object_object_add(EnergyDataTransfer, "periodEnergy", periodEnergys);
  991. } //end of the same index
  992. } // end of for CCS_QUANTITY
  993. }
  994. else if(gunType[gun_index] == GUN_TYPE_GBT)
  995. {
  996. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  997. {
  998. tempIndex = ((gun_index==2) ? 1: 0);
  999. }
  1000. else
  1001. {
  1002. tempIndex = gun_index;
  1003. }
  1004. for (int index = 0; index < GB_QUANTITY; index++)
  1005. {
  1006. if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  1007. {
  1008. json_object_object_add(EnergyDataTransfer, "txId", json_object_new_int(ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId));
  1009. for(uint8_t idxPeriod=0;idxPeriod<ARRAY_SIZE(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].presentChargedEnergyPeriod);idxPeriod++)
  1010. {
  1011. uint8_t period[3];
  1012. sprintf((char*)period, "%d", idxPeriod);
  1013. json_object_object_add(periodEnergys, (const char *)period, json_object_new_double(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].presentChargedEnergyPeriod[idxPeriod]));
  1014. }
  1015. json_object_object_add(EnergyDataTransfer, "periodEnergy", periodEnergys);
  1016. } //end of the same index
  1017. } // end of for GB_QUANTITY
  1018. }
  1019. else if(gunType[gun_index] == GUN_TYPE_DO)
  1020. {
  1021. tempIndex = gun_index;
  1022. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  1023. {
  1024. if(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  1025. {
  1026. json_object_object_add(EnergyDataTransfer, "txId", json_object_new_int(ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId));
  1027. for(uint8_t idxPeriod=0;idxPeriod<ARRAY_SIZE(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.presentChargedEnergyPeriod);idxPeriod++)
  1028. {
  1029. uint8_t period[3];
  1030. sprintf((char*)period, "%d", idxPeriod);
  1031. json_object_object_add(periodEnergys, (const char *)period, json_object_new_double(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.presentChargedEnergyPeriod[idxPeriod]));
  1032. }
  1033. json_object_object_add(EnergyDataTransfer, "periodEnergy", periodEnergys);
  1034. } //end of the same index
  1035. }
  1036. }
  1037. else
  1038. {
  1039. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  1040. {
  1041. tempIndex = 2;
  1042. }
  1043. else
  1044. {
  1045. tempIndex = gun_index;
  1046. }
  1047. for (int index = 0; index < AC_QUANTITY; index++)
  1048. {
  1049. if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  1050. {
  1051. json_object_object_add(EnergyDataTransfer, "txId", json_object_new_int(ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId));
  1052. for(uint8_t idxPeriod=0;idxPeriod<ARRAY_SIZE(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].presentChargedEnergyPeriod);idxPeriod++)
  1053. {
  1054. uint8_t period[3];
  1055. sprintf((char*)period, "%d", idxPeriod);
  1056. json_object_object_add(periodEnergys, (const char *)period, json_object_new_double(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].presentChargedEnergyPeriod[idxPeriod]));
  1057. }
  1058. json_object_object_add(EnergyDataTransfer, "periodEnergy", periodEnergys);
  1059. }//end of the same index
  1060. }//end of for AC_QUANTITY
  1061. }
  1062. sprintf(sql, "insert or replace into ocpp_period_energy (transactionId, connectorId, occurDatetime, periodEnergy) VALUES ('%d', '%d', CURRENT_TIMESTAMP, '%s');", ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId, (gun_index+1), json_object_to_json_string_ext(EnergyDataTransfer, JSON_C_TO_STRING_PLAIN));
  1063. json_object_put(EnergyDataTransfer);
  1064. //* Execute SQL statement */
  1065. if( sqlite3_exec(db, sql, callback, 0, (char **)&zErrMsg) != SQLITE_OK )
  1066. {
  1067. DEBUG_WARN("SQL error: %s\n", zErrMsg);
  1068. isSuccess = FALSE;
  1069. }
  1070. sprintf(sql, "delete from ocpp_period_energy where (occurDatetime < '%04d-01-01 00:00:00');", (getCurrentYear()-3));
  1071. if (sqlite3_exec(db, sql, 0, 0, (char **)&zErrMsg) != SQLITE_OK)
  1072. {
  1073. DEBUG_WARN( "delete period energy record error message: %s\n", zErrMsg);
  1074. isSuccess = FALSE;
  1075. }
  1076. return isSuccess;
  1077. }
  1078. int OCPP_getPeriodEnergyToDataTransfer(int32_t transactionId)
  1079. {
  1080. int isSuccess = TRUE;
  1081. char sql[512];
  1082. char zErrMsg[200];
  1083. int rows, cols;
  1084. char **resultData;
  1085. sprintf(sql, "select * from ocpp_period_energy where transactionId=%d;", transactionId);
  1086. /* Execute SQL statement */
  1087. if( sqlite3_get_table(db, sql, &resultData, &rows, &cols, (char **)&zErrMsg) != SQLITE_OK)
  1088. {
  1089. DEBUG_WARN("SQL error: %s\n", zErrMsg);
  1090. isSuccess = FALSE;
  1091. }
  1092. else
  1093. {
  1094. if((rows > 0) && (atoi(resultData[4]) > 0))
  1095. {
  1096. sprintf((char*)ShmOCPP16Data->DataTransfer[0].ResponseData, "%s", resultData[7]);
  1097. }
  1098. else
  1099. {
  1100. DEBUG_WARN("There is not match transaction data.\n");
  1101. isSuccess = FALSE;
  1102. }
  1103. }
  1104. return isSuccess;
  1105. }
  1106. int OCPP_insert_deduct_info(int txId, char *creditNo, uint8_t deductResult, uint8_t isDonateInvoice, double amount, char *vemData, char *ROC, char *RRN, char *approvalNo, char *storeId)
  1107. {
  1108. int result = PASS;
  1109. char* errMsg = NULL;
  1110. char sqlStr[8192];
  1111. sprintf(sqlStr, "insert or replace into report_deduct_info(txId, creditNo, deductResult, isDonateInvoice, amount, vemData, ROC, RRN, approvalNo, storeId, isUploaded) values('%d', '%s', '%d', '%d', '%.2f', '%s', '%s', '%s', '%s', '%s', '0');",
  1112. txId, creditNo, deductResult, isDonateInvoice, amount, vemData, ROC, RRN, approvalNo, storeId);
  1113. if (sqlite3_exec(db, sqlStr, 0, 0, &errMsg) != SQLITE_OK)
  1114. {
  1115. result = FAIL;
  1116. DEBUG_WARN( "Insert local report_deduct_info error message: %s\n", errMsg);
  1117. }
  1118. sprintf(sqlStr, "delete from report_deduct_info where (idx < (select idx from report_deduct_info order by idx desc limit 1)-5000);");
  1119. if (sqlite3_exec(db, sqlStr, 0, 0, &errMsg) != SQLITE_OK)
  1120. {
  1121. result = FAIL;
  1122. DEBUG_WARN( "delete local report_deduct_info error message: %s\n", errMsg);
  1123. }
  1124. return result;
  1125. }
  1126. int OCPP_update_deduct_info(int txId, char *creditNo)
  1127. {
  1128. int result = PASS;
  1129. char* errMsg = NULL;
  1130. char sqlStr[8192];
  1131. sprintf(sqlStr, "update report_deduct_info set isUploaded='1' where txId='%d' and creditNo='%s';", txId, creditNo);
  1132. if (sqlite3_exec(db, sqlStr, 0, 0, &errMsg) != SQLITE_OK)
  1133. {
  1134. result = FAIL;
  1135. DEBUG_WARN( "Update local report_deduct_info error message: %s\n", errMsg);
  1136. }
  1137. return result;
  1138. }
  1139. int queryDeductCallBack(void *data, int columenCount, char **columnValue, char **columnName)
  1140. {
  1141. sprintf((char*)ShmOCPP16Data->DataTransfer[0].VendorId, "%s", ShmSysConfigAndInfo->SysConfig.chargePointVendor);
  1142. sprintf((char*)ShmOCPP16Data->DataTransfer[0].MessageId,"%s","ID_CreditDeductResult");
  1143. sprintf((char*)ShmOCPP16Data->DataTransfer[0].Data, "{\\\"txId\\\":%d,\\\"creditNo\\\":\\\"%s\\\",\\\"deductResult\\\":%s,\\\"isDonateInvoice\\\":%s,\\\"amount\\\":%s,\\\"approvalNo\\\":\\\"%s\\\"}",
  1144. atoi(columnValue[1]),
  1145. columnValue[2],
  1146. atoi(columnValue[3])==1?"true":"false",
  1147. atoi(columnValue[4])==1?"true":"false",
  1148. columnValue[5],
  1149. columnValue[9]);
  1150. ShmOCPP16Data->CsMsg.bits[0].DataTransferReq = 1;
  1151. return 0;
  1152. }
  1153. void OCPP_query_deduct_info()
  1154. {
  1155. int rc = 0;
  1156. char sql[100];
  1157. char zErrMsg[100];
  1158. sprintf(sql,"select * from report_deduct_info where isUploaded='0' order by idx limit 1");
  1159. /* Execute SQL statement */
  1160. rc = sqlite3_exec(db, sql, queryDeductCallBack, 0, (char **)&zErrMsg);
  1161. if( rc != SQLITE_OK )
  1162. {
  1163. DEBUG_INFO("SQL error: %s\n", zErrMsg);
  1164. }
  1165. }
  1166. void reportReaderStatus(int gun_index)
  1167. {
  1168. struct timeval tmnow;
  1169. struct tm *tm;
  1170. char buf[28];//, usec_buf[6];
  1171. gettimeofday(&tmnow, NULL);
  1172. time_t t;
  1173. t = time(NULL);
  1174. /*UTC time and date*/
  1175. tm = gmtime(&t);
  1176. strftime(buf,28,"%Y-%m-%dT%H:%M:%SZ", tm);
  1177. #if 0 // remove temporally
  1178. strftime(buf,30,"%Y-%m-%dT%H:%M:%S", tm);
  1179. strcat(buf,".");
  1180. sprintf(usec_buf,"%dZ",(int)tmnow.tv_usec);
  1181. strcat(buf,usec_buf);
  1182. #endif
  1183. sprintf((char*)ShmOCPP16Data->DataTransfer[gun_index].VendorId, "%s", ShmSysConfigAndInfo->SysConfig.chargePointVendor);
  1184. sprintf((char*)ShmOCPP16Data->DataTransfer[gun_index].MessageId,"%s","ID_ReaderStatus");
  1185. sprintf((char*)ShmOCPP16Data->DataTransfer[gun_index].Data, "{\\\"connectorId\\\":%d,\\\"readerStatus\\\":%d,\\\"timestamp\\\":\\\"%s\\\",\\\"SerialNo\\\":\\\"%s\\\",\\\"creditNo\\\":\\\"%s\\\",\\\"VEMData\\\":\\\"%s\\\"}",
  1186. (gun_index+1),
  1187. ShmOCPP16Data->TcciCustomData.ReaderStatus[gun_index].readerStatus,
  1188. buf,
  1189. ShmOCPP16Data->TcciCustomData.SerialNo[gun_index],
  1190. ShmOCPP16Data->TcciCustomData.ReaderStatus[gun_index].creditNo,
  1191. ShmOCPP16Data->TcciCustomData.VEMData[gun_index]);
  1192. ShmOCPP16Data->CsMsg.bits[gun_index].DataTransferReq = 1;
  1193. }
  1194. //==========================================
  1195. // Check time passed since today
  1196. //==========================================
  1197. long long DiffTimebWithNow(struct timeb ST)
  1198. {
  1199. //return milli-second
  1200. struct timeb ET;
  1201. long long StartTime,StopTime;
  1202. ftime(&ET);
  1203. StartTime=(long long)ST.time;
  1204. StopTime=(long long)ET.time;
  1205. return ((StopTime-StartTime)*1000) + (ET.millitm-ST.millitm);
  1206. }
  1207. int getTimePassSinceToday(uint8_t gun_index)
  1208. {
  1209. int result = -1;
  1210. static time_t lastTime[4];
  1211. time_t t;
  1212. struct tm *tmStartToday;
  1213. struct timeb tbStartToday;
  1214. t=time(NULL);
  1215. if(difftime(t, lastTime[gun_index])>0)
  1216. {
  1217. tmStartToday=localtime(&t);
  1218. tmStartToday->tm_hour = 0;
  1219. tmStartToday->tm_min = 0;
  1220. tmStartToday->tm_sec = 0;
  1221. tbStartToday.time = mktime(tmStartToday);
  1222. tbStartToday.millitm = 0;
  1223. result = DiffTimebWithNow(tbStartToday)/1000;
  1224. lastTime[gun_index] = t;
  1225. }
  1226. return result;
  1227. }
  1228. void getNowDatetime(uint8_t *data)
  1229. {
  1230. time_t t = time(NULL);
  1231. struct tm tm = *localtime(&t);
  1232. sprintf((char*)data, "%04d-%02d-%02dT%02d:%02d:%02dZ", tm.tm_year + 1900, tm.tm_mon + 1, tm.tm_mday, tm.tm_hour, tm.tm_min, tm.tm_sec);
  1233. }
  1234. int syncDateTimeRTC(uint8_t *data)
  1235. {
  1236. struct ParsingResult
  1237. {
  1238. int result;
  1239. int scanedElement;
  1240. int year;
  1241. int month;
  1242. int mday;
  1243. int hour;
  1244. int min;
  1245. int sec;
  1246. int tz_hour;
  1247. int tz_min;
  1248. float minSec;
  1249. }result;
  1250. struct tm tmOrg;
  1251. struct tm *tmTarget;
  1252. struct timeb tbTarget;
  1253. char buf[128];
  1254. memset(&result, 0x00, sizeof(struct ParsingResult));
  1255. result.result = PASS;
  1256. if(strstr((char*)data, ".") != NULL)
  1257. {
  1258. // Original data with mini second
  1259. if(strstr((char*)data, "Z") != NULL)
  1260. {
  1261. // Original data with Z
  1262. result.scanedElement = sscanf((char*)data, "%d-%d-%dT%d:%d:%d.%fZ",
  1263. &result.year,
  1264. &result.month,
  1265. &result.mday,
  1266. &result.hour,
  1267. &result.min,
  1268. &result.sec,
  1269. &result.minSec);
  1270. }
  1271. else
  1272. {
  1273. // Original data without Z
  1274. result.scanedElement = sscanf((char*)data, "%d-%d-%dT%d:%d:%d.%f%d:%d",
  1275. &result.year,
  1276. &result.month,
  1277. &result.mday,
  1278. &result.hour,
  1279. &result.min,
  1280. &result.sec,
  1281. &result.minSec,
  1282. &result.tz_hour,
  1283. &result.tz_min);
  1284. }
  1285. }
  1286. else
  1287. {
  1288. // Original data without mini second
  1289. if(strstr((char*)data, "Z") != NULL)
  1290. {
  1291. // Original data with Z
  1292. result.scanedElement = sscanf((char*)data, "%d-%d-%dT%d:%d:%dZ",
  1293. &result.year,
  1294. &result.month,
  1295. &result.mday,
  1296. &result.hour,
  1297. &result.min,
  1298. &result.sec);
  1299. }
  1300. else
  1301. {
  1302. // Original data without Z
  1303. result.scanedElement = sscanf((char*)data, "%d-%d-%dT%d:%d:%d%d:%d",
  1304. &result.year,
  1305. &result.month,
  1306. &result.mday,
  1307. &result.hour,
  1308. &result.min,
  1309. &result.sec,
  1310. &result.tz_hour,
  1311. &result.tz_min);
  1312. }
  1313. }
  1314. tmOrg.tm_year = result.year - 1900;
  1315. tmOrg.tm_mon = result.month - 1;
  1316. tmOrg.tm_mday = result.mday;
  1317. tmOrg.tm_hour = result.hour;
  1318. tmOrg.tm_min = result.min;
  1319. tmOrg.tm_sec = result.sec;
  1320. tmOrg.tm_gmtoff = 0;
  1321. tbTarget.time = mktime(&tmOrg);
  1322. tbTarget.timezone = 0;
  1323. tbTarget.time -= (result.tz_hour*3600) + (result.tz_min*60*(result.tz_hour>=0?1:-1));
  1324. tmTarget = gmtime(&tbTarget.time);
  1325. sprintf(buf, "date -s '%04d-%02d-%02d %02d:%02d:%02d'", (tmTarget->tm_year+1900), (tmTarget->tm_mon+1), tmTarget->tm_mday, tmTarget->tm_hour, tmTarget->tm_min, tmTarget->tm_sec);
  1326. //DEBUG_INFO(" org date time: %s\n", data);
  1327. //DEBUG_INFO("parse date time: %s\n", buf);
  1328. system(buf);
  1329. system("/sbin/hwclock -w --systohc");
  1330. if(result.scanedElement < 6)
  1331. result.result = FAIL;
  1332. return result.result;
  1333. }
  1334. //==========================================
  1335. // GetCompositeSchedule logic related function
  1336. //==========================================
  1337. int DiffTimebSec(struct timeb ST, struct timeb ET)
  1338. {
  1339. //return milli-second
  1340. unsigned int StartTime,StopTime;
  1341. StartTime=(unsigned int)ST.time;
  1342. StopTime=(unsigned int)ET.time;
  1343. return (StopTime-StartTime);
  1344. }
  1345. int DiffTimebWithNowSec(struct timeb ST)
  1346. {
  1347. //return milli-second
  1348. struct timeb ET;
  1349. unsigned int StartTime,StopTime;
  1350. ftime(&ET);
  1351. StartTime=(unsigned int)ST.time;
  1352. StopTime=(unsigned int)ET.time;
  1353. return (StopTime-StartTime);
  1354. }
  1355. int getStartStop(uint8_t *start, uint8_t *stop)
  1356. {
  1357. struct ParsingResult
  1358. {
  1359. int result;
  1360. int scanedElement;
  1361. int year;
  1362. int month;
  1363. int mday;
  1364. int hour;
  1365. int min;
  1366. int sec;
  1367. int tz_hour;
  1368. int tz_min;
  1369. float minSec;
  1370. };
  1371. struct ParsingResult parseStart;
  1372. struct ParsingResult parseStop;
  1373. int result = -1;
  1374. struct tm tmStart;
  1375. struct timeb tbStart;
  1376. struct tm tmStop;
  1377. struct timeb tbStop;
  1378. memset(&parseStart, 0x00, sizeof(struct ParsingResult));
  1379. memset(&parseStop, 0x00, sizeof(struct ParsingResult));
  1380. // Scan start & stop date time
  1381. if(strstr((char*)start, ".") != NULL)
  1382. {
  1383. // Original data with mini second
  1384. if(strstr((char*)start, "Z") != NULL)
  1385. {
  1386. // Original data with Z
  1387. parseStart.scanedElement = sscanf((char*)start, "%d-%d-%dT%d:%d:%d.%fZ",
  1388. &parseStart.year,
  1389. &parseStart.month,
  1390. &parseStart.mday,
  1391. &parseStart.hour,
  1392. &parseStart.min,
  1393. &parseStart.sec,
  1394. &parseStart.minSec);
  1395. }
  1396. else
  1397. {
  1398. // Original data without Z
  1399. parseStart.scanedElement = sscanf((char*)start, "%d-%d-%dT%d:%d:%d.%f%d:%d",
  1400. &parseStart.year,
  1401. &parseStart.month,
  1402. &parseStart.mday,
  1403. &parseStart.hour,
  1404. &parseStart.min,
  1405. &parseStart.sec,
  1406. &parseStart.minSec,
  1407. &parseStart.tz_hour,
  1408. &parseStart.tz_min);
  1409. }
  1410. }
  1411. else
  1412. {
  1413. // Original data without mini second
  1414. if(strstr((char*)start, "Z") != NULL)
  1415. {
  1416. // Original data with Z
  1417. parseStart.scanedElement = sscanf((char*)start, "%d-%d-%dT%d:%d:%dZ",
  1418. &parseStart.year,
  1419. &parseStart.month,
  1420. &parseStart.mday,
  1421. &parseStart.hour,
  1422. &parseStart.min,
  1423. &parseStart.sec);
  1424. }
  1425. else
  1426. {
  1427. // Original data without Z
  1428. parseStart.scanedElement = sscanf((char*)start, "%d-%d-%dT%d:%d:%d%d:%d",
  1429. &parseStart.year,
  1430. &parseStart.month,
  1431. &parseStart.mday,
  1432. &parseStart.hour,
  1433. &parseStart.min,
  1434. &parseStart.sec,
  1435. &parseStart.tz_hour,
  1436. &parseStart.tz_min);
  1437. }
  1438. }
  1439. if(strstr((char*)stop, ".") != NULL)
  1440. {
  1441. // Original data with mini second
  1442. if(strstr((char*)stop, "Z") != NULL)
  1443. {
  1444. // Original data with Z
  1445. parseStop.scanedElement = sscanf((char*)stop, "%d-%d-%dT%d:%d:%d.%fZ",
  1446. &parseStop.year,
  1447. &parseStop.month,
  1448. &parseStop.mday,
  1449. &parseStop.hour,
  1450. &parseStop.min,
  1451. &parseStop.sec,
  1452. &parseStop.minSec);
  1453. }
  1454. else
  1455. {
  1456. // Original data without Z
  1457. parseStop.scanedElement = sscanf((char*)stop, "%d-%d-%dT%d:%d:%d.%f%d:%d",
  1458. &parseStop.year,
  1459. &parseStop.month,
  1460. &parseStop.mday,
  1461. &parseStop.hour,
  1462. &parseStop.min,
  1463. &parseStop.sec,
  1464. &parseStop.minSec,
  1465. &parseStop.tz_hour,
  1466. &parseStop.tz_min);
  1467. }
  1468. }
  1469. else
  1470. {
  1471. // Original data without mini second
  1472. if(strstr((char*)stop, "Z") != NULL)
  1473. {
  1474. // Original data with Z
  1475. parseStop.scanedElement = sscanf((char*)stop, "%d-%d-%dT%d:%d:%dZ",
  1476. &parseStop.year,
  1477. &parseStop.month,
  1478. &parseStop.mday,
  1479. &parseStop.hour,
  1480. &parseStop.min,
  1481. &parseStop.sec);
  1482. }
  1483. else
  1484. {
  1485. // Original data without Z
  1486. parseStop.scanedElement = sscanf((char*)stop, "%d-%d-%dT%d:%d:%d%d:%d",
  1487. &parseStop.year,
  1488. &parseStop.month,
  1489. &parseStop.mday,
  1490. &parseStop.hour,
  1491. &parseStop.min,
  1492. &parseStop.sec,
  1493. &parseStop.tz_hour,
  1494. &parseStop.tz_min);
  1495. }
  1496. }
  1497. // Calculate date time difference
  1498. if((parseStart.scanedElement >=6) &&
  1499. (parseStop.scanedElement >=6))
  1500. {
  1501. //DEBUG_INFO("Start: %04d-%02d-%02d %02d:%02d:%02d(%02d:%02d)\n", parseStart.year, parseStart.month, parseStart.mday, parseStart.hour, parseStart.min, parseStart.sec, parseStart.tz_hour, parseStart.tz_min);
  1502. //DEBUG_INFO("Stop: %04d-%02d-%02d %02d:%02d:%02d(%02d:%02d)\n", parseStop.year, parseStop.month, parseStop.mday, parseStop.hour, parseStop.min, parseStop.sec, parseStop.tz_hour, parseStop.tz_min);
  1503. tmStart.tm_year = parseStart.year - 1900;
  1504. tmStart.tm_mon = parseStart.month - 1;
  1505. tmStart.tm_mday = parseStart.mday;
  1506. tmStart.tm_hour = parseStart.hour;
  1507. tmStart.tm_min = parseStart.min;
  1508. tmStart.tm_sec = parseStart.sec;
  1509. tmStart.tm_gmtoff = 0;
  1510. tbStart.time = mktime(&tmStart);
  1511. tbStart.timezone = 0;
  1512. tbStart.time -= (parseStart.tz_hour*3600) + (parseStart.tz_min*60*(parseStart.tz_hour>=0?1:-1));
  1513. tmStop.tm_year = parseStop.year - 1900;
  1514. tmStop.tm_mon = parseStop.month - 1;
  1515. tmStop.tm_mday = parseStop.mday;
  1516. tmStop.tm_hour = parseStop.hour;
  1517. tmStop.tm_min = parseStop.min;
  1518. tmStop.tm_sec = parseStop.sec;
  1519. tmStop.tm_gmtoff = 0;
  1520. tbStop.time = mktime(&tmStop);
  1521. tbStop.timezone = 0;
  1522. tbStop.time -= (parseStop.tz_hour*3600) + (parseStop.tz_min*60*(parseStop.tz_hour>=0?1:-1));
  1523. result = DiffTimebSec(tbStart, tbStop);
  1524. //DEBUG_INFO("getStartStop(): %d\n", result);
  1525. }
  1526. else
  1527. {
  1528. DEBUG_WARN("Start or stop date parsing error.\r\n");
  1529. }
  1530. return result;
  1531. }
  1532. int isOvertNow(uint8_t *start)
  1533. {
  1534. int result = NO;
  1535. struct ParsingResult
  1536. {
  1537. int result;
  1538. int scanedElement;
  1539. int year;
  1540. int month;
  1541. int mday;
  1542. int hour;
  1543. int min;
  1544. int sec;
  1545. int tz_hour;
  1546. int tz_min;
  1547. float minSec;
  1548. }parsingResult;
  1549. struct tm tmStart;
  1550. struct timeb tbStart;
  1551. memset(&parsingResult, 0x00, sizeof(struct ParsingResult));
  1552. if(strstr((char*)start, ".") != NULL)
  1553. {
  1554. // Original data with mini second
  1555. if(strstr((char*)start, "Z") != NULL)
  1556. {
  1557. // Original data with Z
  1558. parsingResult.scanedElement = sscanf((char*)start, "%d-%d-%dT%d:%d:%d.%fZ",
  1559. &parsingResult.year,
  1560. &parsingResult.month,
  1561. &parsingResult.mday,
  1562. &parsingResult.hour,
  1563. &parsingResult.min,
  1564. &parsingResult.sec,
  1565. &parsingResult.minSec);
  1566. }
  1567. else
  1568. {
  1569. // Original data without Z
  1570. parsingResult.scanedElement = sscanf((char*)start, "%d-%d-%dT%d:%d:%d.%f%d:%d",
  1571. &parsingResult.year,
  1572. &parsingResult.month,
  1573. &parsingResult.mday,
  1574. &parsingResult.hour,
  1575. &parsingResult.min,
  1576. &parsingResult.sec,
  1577. &parsingResult.minSec,
  1578. &parsingResult.tz_hour,
  1579. &parsingResult.tz_min);
  1580. }
  1581. }
  1582. else
  1583. {
  1584. // Original data without mini second
  1585. if(strstr((char*)start, "Z") != NULL)
  1586. {
  1587. // Original data with Z
  1588. parsingResult.scanedElement = sscanf((char*)start, "%d-%d-%dT%d:%d:%dZ",
  1589. &parsingResult.year,
  1590. &parsingResult.month,
  1591. &parsingResult.mday,
  1592. &parsingResult.hour,
  1593. &parsingResult.min,
  1594. &parsingResult.sec);
  1595. }
  1596. else
  1597. {
  1598. // Original data without Z
  1599. parsingResult.scanedElement = sscanf((char*)start, "%d-%d-%dT%d:%d:%d%d:%d",
  1600. &parsingResult.year,
  1601. &parsingResult.month,
  1602. &parsingResult.mday,
  1603. &parsingResult.hour,
  1604. &parsingResult.min,
  1605. &parsingResult.sec,
  1606. &parsingResult.tz_hour,
  1607. &parsingResult.tz_min);
  1608. }
  1609. }
  1610. if(parsingResult.scanedElement >= 6)
  1611. {
  1612. tmStart.tm_year = parsingResult.year - 1900;
  1613. tmStart.tm_mon = parsingResult.month - 1;
  1614. tmStart.tm_mday = parsingResult.mday;
  1615. tmStart.tm_hour = parsingResult.hour;
  1616. tmStart.tm_min = parsingResult.min;
  1617. tmStart.tm_sec = parsingResult.sec;
  1618. tmStart.tm_gmtoff = 0;
  1619. tbStart.time = mktime(&tmStart);
  1620. tbStart.timezone = 0;
  1621. tbStart.millitm = 0;
  1622. tbStart.time -= (parsingResult.tz_hour*3600) + (parsingResult.tz_min*60*(parsingResult.tz_hour>=0?1:-1));
  1623. if(DiffTimebWithNowSec(tbStart) <= 0)
  1624. result = NO;
  1625. else
  1626. result = YES;
  1627. }
  1628. else
  1629. {
  1630. DEBUG_WARN("Start date parsing error.\n");
  1631. }
  1632. return result;
  1633. }
  1634. int getStartSinceRecurring(uint8_t *start, uint8_t *stop, uint8_t isDaily)
  1635. {
  1636. struct ParsingResult
  1637. {
  1638. int result;
  1639. int scanedElement;
  1640. int year;
  1641. int month;
  1642. int mday;
  1643. int hour;
  1644. int min;
  1645. int sec;
  1646. int tz_hour;
  1647. int tz_min;
  1648. float minSec;
  1649. };
  1650. struct ParsingResult parseStart;
  1651. struct ParsingResult parseStop;
  1652. int result = -1;
  1653. struct tm tmStart;
  1654. struct timeb tbStart;
  1655. struct tm tmStop;
  1656. struct timeb tbStop;
  1657. memset(&parseStart, 0x00, sizeof(struct ParsingResult));
  1658. memset(&parseStop, 0x00, sizeof(struct ParsingResult));
  1659. // Scan start & stop date time
  1660. if(strstr((char*)start, ".") != NULL)
  1661. {
  1662. // Original data with mini second
  1663. if(strstr((char*)start, "Z") != NULL)
  1664. {
  1665. // Original data with Z
  1666. parseStart.scanedElement = sscanf((char*)start, "%d-%d-%dT%d:%d:%d.%fZ",
  1667. &parseStart.year,
  1668. &parseStart.month,
  1669. &parseStart.mday,
  1670. &parseStart.hour,
  1671. &parseStart.min,
  1672. &parseStart.sec,
  1673. &parseStart.minSec);
  1674. }
  1675. else
  1676. {
  1677. // Original data without Z
  1678. parseStart.scanedElement = sscanf((char*)start, "%d-%d-%dT%d:%d:%d.%f%d:%d",
  1679. &parseStart.year,
  1680. &parseStart.month,
  1681. &parseStart.mday,
  1682. &parseStart.hour,
  1683. &parseStart.min,
  1684. &parseStart.sec,
  1685. &parseStart.minSec,
  1686. &parseStart.tz_hour,
  1687. &parseStart.tz_min);
  1688. }
  1689. }
  1690. else
  1691. {
  1692. // Original data without mini second
  1693. if(strstr((char*)start, "Z") != NULL)
  1694. {
  1695. // Original data with Z
  1696. parseStart.scanedElement = sscanf((char*)start, "%d-%d-%dT%d:%d:%dZ",
  1697. &parseStart.year,
  1698. &parseStart.month,
  1699. &parseStart.mday,
  1700. &parseStart.hour,
  1701. &parseStart.min,
  1702. &parseStart.sec);
  1703. }
  1704. else
  1705. {
  1706. // Original data without Z
  1707. parseStart.scanedElement = sscanf((char*)start, "%d-%d-%dT%d:%d:%d%d:%d",
  1708. &parseStart.year,
  1709. &parseStart.month,
  1710. &parseStart.mday,
  1711. &parseStart.hour,
  1712. &parseStart.min,
  1713. &parseStart.sec,
  1714. &parseStart.tz_hour,
  1715. &parseStart.tz_min);
  1716. }
  1717. }
  1718. if(strstr((char*)stop, ".") != NULL)
  1719. {
  1720. // Original data with mini second
  1721. if(strstr((char*)stop, "Z") != NULL)
  1722. {
  1723. // Original data with Z
  1724. parseStop.scanedElement = sscanf((char*)stop, "%d-%d-%dT%d:%d:%d.%fZ",
  1725. &parseStop.year,
  1726. &parseStop.month,
  1727. &parseStop.mday,
  1728. &parseStop.hour,
  1729. &parseStop.min,
  1730. &parseStop.sec,
  1731. &parseStop.minSec);
  1732. }
  1733. else
  1734. {
  1735. // Original data without Z
  1736. parseStop.scanedElement = sscanf((char*)stop, "%d-%d-%dT%d:%d:%d.%f%d:%d",
  1737. &parseStop.year,
  1738. &parseStop.month,
  1739. &parseStop.mday,
  1740. &parseStop.hour,
  1741. &parseStop.min,
  1742. &parseStop.sec,
  1743. &parseStop.minSec,
  1744. &parseStop.tz_hour,
  1745. &parseStop.tz_min);
  1746. }
  1747. }
  1748. else
  1749. {
  1750. // Original data without mini second
  1751. if(strstr((char*)stop, "Z") != NULL)
  1752. {
  1753. // Original data with Z
  1754. parseStop.scanedElement = sscanf((char*)stop, "%d-%d-%dT%d:%d:%dZ",
  1755. &parseStop.year,
  1756. &parseStop.month,
  1757. &parseStop.mday,
  1758. &parseStop.hour,
  1759. &parseStop.min,
  1760. &parseStop.sec);
  1761. }
  1762. else
  1763. {
  1764. // Original data without Z
  1765. parseStop.scanedElement = sscanf((char*)stop, "%d-%d-%dT%d:%d:%d%d:%d",
  1766. &parseStop.year,
  1767. &parseStop.month,
  1768. &parseStop.mday,
  1769. &parseStop.hour,
  1770. &parseStop.min,
  1771. &parseStop.sec,
  1772. &parseStop.tz_hour,
  1773. &parseStop.tz_min);
  1774. }
  1775. }
  1776. // Calculate date time difference
  1777. if((parseStart.scanedElement >=6) &&
  1778. (parseStop.scanedElement >=6))
  1779. {
  1780. //DEBUG_INFO("Start: %04d-%02d-%02d %02d:%02d:%02d(%02d:%02d)\n", parseStart.year, parseStart.month, parseStart.mday, parseStart.hour, parseStart.min, parseStart.sec, parseStart.tz_hour, parseStart.tz_min);
  1781. //DEBUG_INFO("Stop: %04d-%02d-%02d %02d:%02d:%02d(%02d:%02d)\n", parseStop.year, parseStop.month, parseStop.mday, parseStop.hour, parseStop.min, parseStop.sec, parseStop.tz_hour, parseStop.tz_min);
  1782. tmStart.tm_year = parseStart.year - 1900;
  1783. tmStart.tm_mon = parseStart.month - 1;
  1784. tmStart.tm_mday = parseStart.mday;
  1785. tmStart.tm_hour = parseStart.hour;
  1786. tmStart.tm_min = parseStart.min;
  1787. tmStart.tm_sec = parseStart.sec;
  1788. tmStart.tm_gmtoff = 0;
  1789. tbStart.time = mktime(&tmStart);
  1790. tbStart.timezone = 0;
  1791. tbStart.time -= (parseStart.tz_hour*3600) + (parseStart.tz_min*60*(parseStart.tz_hour>=0?1:-1));
  1792. tmStop.tm_year = parseStop.year - 1900;
  1793. tmStop.tm_mon = parseStop.month - 1;
  1794. tmStop.tm_mday = parseStop.mday;
  1795. tmStop.tm_hour = parseStop.hour;
  1796. tmStop.tm_min = parseStop.min;
  1797. tmStop.tm_sec = parseStop.sec;
  1798. tmStop.tm_gmtoff = 0;
  1799. tbStop.time = mktime(&tmStop);
  1800. tbStop.timezone = 0;
  1801. tbStop.time -= (parseStop.tz_hour*3600) + (parseStop.tz_min*60*(parseStop.tz_hour>=0?1:-1));
  1802. result = DiffTimebSec(tbStart, tbStop)%(isDaily?86400:604800);
  1803. //DEBUG_INFO("getStartStop(): %d\n", result);
  1804. }
  1805. else
  1806. {
  1807. DEBUG_WARN("Start or stop date parsing error.\r\n");
  1808. }
  1809. return result;
  1810. }
  1811. void checkChargePointMaxProfile(uint32_t durationReq, struct StructChargingProfile *targetCompositeProfile, uint8_t isUnitA)
  1812. {
  1813. FILE *fp;
  1814. char profileFileName[128];
  1815. char *line = NULL;
  1816. size_t len = 0;
  1817. time_t CurrentTime;
  1818. struct tm *tmComposite;
  1819. struct StructChargingProfile maxProfile;
  1820. struct StructChargingProfile compositeProfile;
  1821. uint8_t limitMax=0;
  1822. int compositePeriodIdx = 0;
  1823. //uint8_t isDurationNull = FALSE;
  1824. CurrentTime = time(NULL);
  1825. tmComposite=localtime(&CurrentTime);
  1826. sprintf((char*)compositeProfile.ChargingSchedule.StartSchedule, "%04d-%02d-%02dT%02d:%02d:%02dZ", tmComposite->tm_year+1900, tmComposite->tm_mon+1, tmComposite->tm_mday, tmComposite->tm_hour, tmComposite->tm_min, tmComposite->tm_sec);
  1827. if(isUnitA)
  1828. sprintf((char*)compositeProfile.ChargingSchedule.ChargingRateUnit, "A");
  1829. else
  1830. sprintf((char*)compositeProfile.ChargingSchedule.ChargingRateUnit, "W");
  1831. compositeProfile.ChargingSchedule.Duration = durationReq;
  1832. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(compositeProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  1833. {
  1834. compositeProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = -1;
  1835. compositeProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit = -1;
  1836. compositeProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases = 3;
  1837. }
  1838. compositeProfile.ChargingProfileId = 0;
  1839. compositeProfile.StackLevel = 99 ;
  1840. sprintf((char*)compositeProfile.ChargingProfileKind ,"Absolute");
  1841. maxProfile.ChargingProfileId = -1;
  1842. maxProfile.ChargingSchedule.Duration = -1;
  1843. system("rm -f /tmp/*.json");
  1844. system("cp /Storage/OCPP/*.json /tmp 2>/dev/null");
  1845. // Search max profile
  1846. sprintf(profileFileName, "/tmp/ChargePointMaxProfile.json");
  1847. if((access(profileFileName, F_OK))!=-1)
  1848. {
  1849. fp = fopen(profileFileName, "r");
  1850. while(getline(&line, &len, fp) != -1)
  1851. {
  1852. json_object *obj = NULL;
  1853. obj = json_tokener_parse(line);
  1854. if(is_error(obj))
  1855. {
  1856. DEBUG_ERROR("Parse MaxProfile from file error.\n");
  1857. }
  1858. else
  1859. {
  1860. if((json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileId")) != maxProfile.ChargingProfileId) &&
  1861. (json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "stackLevel")) >= maxProfile.StackLevel)
  1862. )
  1863. {
  1864. if((json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom") != NULL) &&
  1865. (json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo") != NULL)
  1866. )
  1867. {
  1868. struct tm tmFrom, tmTo;
  1869. struct timeb tbFrom, tbTo;
  1870. if((sscanf((char*)json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom")), "%4d-%2d-%2dT%2d:%2d:%2d", &tmFrom.tm_year, &tmFrom.tm_mon, &tmFrom.tm_mday, &tmFrom.tm_hour, &tmFrom.tm_min, &tmFrom.tm_sec) == 6) &&
  1871. (sscanf((char*)json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo")), "%4d-%2d-%2dT%2d:%2d:%2d", &tmTo.tm_year, &tmTo.tm_mon, &tmTo.tm_mday, &tmTo.tm_hour, &tmTo.tm_min, &tmTo.tm_sec) == 6))
  1872. {
  1873. tmFrom.tm_year -= 1900;
  1874. tmFrom.tm_mon -= 1;
  1875. tbFrom.time = mktime(&tmFrom);
  1876. tmTo.tm_year -= 1900;
  1877. tmTo.tm_mon -= 1;
  1878. tbTo.time = mktime(&tmTo);
  1879. if((DiffTimebWithNowSec(tbFrom)>=0) && (DiffTimebWithNowSec(tbTo)<=0))
  1880. {
  1881. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  1882. {
  1883. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = -1;
  1884. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit = -1;
  1885. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases = 3;
  1886. }
  1887. if(maxProfile.ChargingProfileId == -1)
  1888. DEBUG_INFO("MaxProfile found.\n");
  1889. else
  1890. DEBUG_INFO("MaxProfile updated.\n");
  1891. // Required item
  1892. maxProfile.ChargingProfileId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileId"));
  1893. maxProfile.StackLevel = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "stackLevel"));
  1894. sprintf((char*)maxProfile.ChargingProfileKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileKind")));
  1895. if(isUnitA)
  1896. {
  1897. sprintf((char*)maxProfile.ChargingSchedule.ChargingRateUnit, "A");
  1898. for(int idxPeriod=0;idxPeriod<json_object_array_length(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"));idxPeriod++)
  1899. {
  1900. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = json_object_get_int(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "startPeriod"));
  1901. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases = (json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "numberPhases")==NULL?
  1902. 3:
  1903. json_object_get_int(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "numberPhases")));
  1904. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit = (strstr(json_object_get_string(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingRateUnit")),"W")!=NULL?json_object_get_double(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "limit"))/(220*maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases):json_object_get_double(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "limit")));
  1905. }
  1906. }
  1907. else
  1908. {
  1909. sprintf((char*)maxProfile.ChargingSchedule.ChargingRateUnit, "W");
  1910. for(int idxPeriod=0;idxPeriod<json_object_array_length(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"));idxPeriod++)
  1911. {
  1912. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = json_object_get_int(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "startPeriod"));
  1913. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases = (json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "numberPhases")==NULL?
  1914. 3:
  1915. json_object_get_int(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "numberPhases")));
  1916. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit = (strstr(json_object_get_string(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingRateUnit")),"W")!=NULL?json_object_get_double(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "limit")):json_object_get_double(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "limit"))*(220*maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases));
  1917. }
  1918. }
  1919. // Optional item
  1920. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom") != NULL)
  1921. {
  1922. sprintf((char*)maxProfile.ValidFrom, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom")));
  1923. }
  1924. else
  1925. {
  1926. sprintf((char*)maxProfile.ValidFrom, " ");
  1927. }
  1928. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo") != NULL)
  1929. {
  1930. sprintf((char*)maxProfile.ValidTo, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo")));
  1931. }
  1932. else
  1933. {
  1934. sprintf((char*)maxProfile.ValidTo, " ");
  1935. }
  1936. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "recurrencyKind") != NULL)
  1937. {
  1938. sprintf((char*)maxProfile.RecurrencyKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "recurrencyKind")));
  1939. }
  1940. else
  1941. {
  1942. sprintf((char*)maxProfile.RecurrencyKind, " ");
  1943. }
  1944. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId") != NULL)
  1945. {
  1946. maxProfile.TransactionId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId"));
  1947. }
  1948. else
  1949. {
  1950. maxProfile.TransactionId = -1;
  1951. }
  1952. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration") != NULL)
  1953. {
  1954. maxProfile.ChargingSchedule.Duration = json_object_get_int(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration"));
  1955. }
  1956. else
  1957. {
  1958. maxProfile.ChargingSchedule.Duration = 86400;
  1959. //isDurationNull = TRUE;
  1960. }
  1961. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "startSchedule") != NULL)
  1962. {
  1963. sprintf((char*)maxProfile.ChargingSchedule.StartSchedule, "%s", json_object_get_string(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "startSchedule")));
  1964. }
  1965. else
  1966. {
  1967. sprintf((char*)maxProfile.ChargingSchedule.StartSchedule, "%s", compositeProfile.ChargingSchedule.StartSchedule);
  1968. }
  1969. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate") != NULL)
  1970. {
  1971. maxProfile.ChargingSchedule.MinChargingRate = json_object_get_double(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate"));
  1972. }
  1973. else
  1974. {
  1975. maxProfile.ChargingSchedule.MinChargingRate = -1;
  1976. }
  1977. }
  1978. }
  1979. }
  1980. else
  1981. {
  1982. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  1983. {
  1984. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = -1;
  1985. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit = -1;
  1986. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases = 3;
  1987. }
  1988. if(maxProfile.ChargingProfileId == -1)
  1989. DEBUG_INFO("MaxProfile found.\n");
  1990. else
  1991. DEBUG_INFO("MaxProfile updated.\n");
  1992. // Required item
  1993. maxProfile.ChargingProfileId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileId"));
  1994. maxProfile.StackLevel = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "stackLevel"));
  1995. sprintf((char*)maxProfile.ChargingProfileKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileKind")));
  1996. if(isUnitA)
  1997. {
  1998. sprintf((char*)maxProfile.ChargingSchedule.ChargingRateUnit, "A");
  1999. for(int idxPeriod=0;idxPeriod<json_object_array_length(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"));idxPeriod++)
  2000. {
  2001. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = json_object_get_int(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "startPeriod"));
  2002. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases = (json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "numberPhases")==NULL?
  2003. 3:
  2004. json_object_get_int(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "numberPhases")));
  2005. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit = (strstr((char*)json_object_get_string(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingRateUnit")),"W")!=NULL?json_object_get_double(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "limit"))/(220*maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases):json_object_get_double(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "limit")));
  2006. }
  2007. }
  2008. else
  2009. {
  2010. sprintf((char*)maxProfile.ChargingSchedule.ChargingRateUnit, "W");
  2011. for(int idxPeriod=0;idxPeriod<json_object_array_length(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"));idxPeriod++)
  2012. {
  2013. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = json_object_get_int(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "startPeriod"));
  2014. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases = (json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "numberPhases")==NULL?
  2015. 3:
  2016. json_object_get_int(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "numberPhases")));
  2017. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit = (strstr((char*)json_object_get_string(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingRateUnit")),"W")!=NULL?json_object_get_double(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "limit")):json_object_get_double(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "limit"))*(220*maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases));
  2018. }
  2019. }
  2020. // Optional item
  2021. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom") != NULL)
  2022. {
  2023. sprintf((char*)maxProfile.ValidFrom, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom")));
  2024. }
  2025. else
  2026. {
  2027. sprintf((char*)maxProfile.ValidFrom, " ");
  2028. }
  2029. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo") != NULL)
  2030. {
  2031. sprintf((char*)maxProfile.ValidTo, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo")));
  2032. }
  2033. else
  2034. {
  2035. sprintf((char*)maxProfile.ValidTo, " ");
  2036. }
  2037. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "recurrencyKind") != NULL)
  2038. {
  2039. sprintf((char*)maxProfile.RecurrencyKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "recurrencyKind")));
  2040. }
  2041. else
  2042. {
  2043. sprintf((char*)maxProfile.RecurrencyKind, " ");
  2044. }
  2045. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId") != NULL)
  2046. {
  2047. maxProfile.TransactionId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId"));
  2048. }
  2049. else
  2050. {
  2051. maxProfile.TransactionId = -1;
  2052. }
  2053. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration") != NULL)
  2054. {
  2055. maxProfile.ChargingSchedule.Duration = json_object_get_int(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration"));
  2056. }
  2057. else
  2058. {
  2059. maxProfile.ChargingSchedule.Duration = 86400;
  2060. //isDurationNull = TRUE;
  2061. }
  2062. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "startSchedule") != NULL)
  2063. {
  2064. sprintf((char*)maxProfile.ChargingSchedule.StartSchedule, "%s", json_object_get_string(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "startSchedule")));
  2065. }
  2066. else
  2067. {
  2068. sprintf((char*)maxProfile.ChargingSchedule.StartSchedule, "%s", compositeProfile.ChargingSchedule.StartSchedule);
  2069. }
  2070. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate") != NULL)
  2071. {
  2072. maxProfile.ChargingSchedule.MinChargingRate = json_object_get_double(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate"));
  2073. }
  2074. else
  2075. {
  2076. maxProfile.ChargingSchedule.MinChargingRate = -1;
  2077. }
  2078. }
  2079. }
  2080. }
  2081. json_object_put(obj);
  2082. }
  2083. fclose(fp);
  2084. /*
  2085. if(maxProfile.ChargingProfileId !=-1)
  2086. {
  2087. DEBUG_INFO("Profile ID: %d\n", maxProfile.ChargingProfileId);
  2088. DEBUG_INFO("Profile stackLevel: %d\n", maxProfile.StackLevel);
  2089. DEBUG_INFO("Profile TransactionId: %d\n", maxProfile.TransactionId);
  2090. DEBUG_INFO("Profile valid from: %s\n", maxProfile.ValidFrom);
  2091. DEBUG_INFO("Profile valid to: %s\n", maxProfile.ValidTo);
  2092. DEBUG_INFO("Profile ChargingProfileKind: %s\n", maxProfile.ChargingProfileKind);
  2093. DEBUG_INFO("Profile recurrencyKind: %s\n", maxProfile.RecurrencyKind);
  2094. DEBUG_INFO("Profile start schedule: %s\n", maxProfile.ChargingSchedule.StartSchedule);
  2095. DEBUG_INFO("Profile schedule duration: %d\n", maxProfile.ChargingSchedule.Duration);
  2096. DEBUG_INFO("Profile charging rate unit: %s\n", maxProfile.ChargingSchedule.ChargingRateUnit);
  2097. DEBUG_INFO("Profile charging min rate: %f\n", maxProfile.ChargingSchedule.MinChargingRate);
  2098. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  2099. {
  2100. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod >= 0)
  2101. {
  2102. DEBUG_INFO("Period-%02d startPeriod: %d\n", idxPeriod, maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod);
  2103. DEBUG_INFO("Period-%02d limit: %f\n", idxPeriod, maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit);
  2104. DEBUG_INFO("Period-%02d NumberPhases: %d\n", idxPeriod, maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases);
  2105. }
  2106. }
  2107. }
  2108. else
  2109. DEBUG_INFO("MaxProfile not found.\n");
  2110. DEBUG_INFO("------------------------------------\n");*/
  2111. }
  2112. if(maxProfile.ChargingProfileId != -1)
  2113. {
  2114. if(strstr((char*)maxProfile.ChargingProfileKind, "Absolute") != NULL)
  2115. {
  2116. if((maxProfile.ChargingSchedule.Duration != -1)/* && (isDurationNull)*/)
  2117. {
  2118. maxProfile.ChargingSchedule.Duration = ((maxProfile.ChargingSchedule.Duration-getStartStop(maxProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule))<0?
  2119. 0:
  2120. (maxProfile.ChargingSchedule.Duration-getStartStop(maxProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule)));
  2121. }
  2122. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  2123. {
  2124. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  2125. {
  2126. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = ((maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartStop(maxProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule))<0?
  2127. 0:
  2128. (maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartStop(maxProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule)));
  2129. if(idxPeriod > 0)
  2130. {
  2131. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
  2132. {
  2133. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit = maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit;
  2134. }
  2135. }
  2136. }
  2137. }
  2138. }
  2139. else if(strstr((char*)maxProfile.ChargingProfileKind, "Relative") != NULL)
  2140. {
  2141. if(maxProfile.ChargingSchedule.Duration != -1)
  2142. {
  2143. maxProfile.ChargingSchedule.Duration = maxProfile.ChargingSchedule.Duration;
  2144. }
  2145. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  2146. {
  2147. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  2148. {
  2149. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod;
  2150. if(idxPeriod > 0)
  2151. {
  2152. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
  2153. {
  2154. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit = maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit;
  2155. }
  2156. }
  2157. }
  2158. }
  2159. }
  2160. else
  2161. {
  2162. if(strstr((char*)maxProfile.RecurrencyKind, "Weekly") != NULL)
  2163. {
  2164. if(maxProfile.ChargingSchedule.Duration != -1)
  2165. {
  2166. maxProfile.ChargingSchedule.Duration = ((maxProfile.ChargingSchedule.Duration-getStartSinceRecurring(maxProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule, FALSE))<0?
  2167. 0:
  2168. (maxProfile.ChargingSchedule.Duration-getStartSinceRecurring(maxProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule, FALSE)));
  2169. }
  2170. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  2171. {
  2172. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  2173. {
  2174. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = ((maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceRecurring(maxProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule, FALSE))<0?
  2175. 0:
  2176. (maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceRecurring(maxProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule, FALSE)));
  2177. if(idxPeriod > 0)
  2178. {
  2179. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
  2180. {
  2181. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit = maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit;
  2182. }
  2183. }
  2184. }
  2185. }
  2186. }
  2187. else
  2188. {
  2189. if(maxProfile.ChargingSchedule.Duration != -1)
  2190. {
  2191. maxProfile.ChargingSchedule.Duration = ((maxProfile.ChargingSchedule.Duration-getStartSinceRecurring(maxProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule, TRUE))<0?
  2192. 0:
  2193. (maxProfile.ChargingSchedule.Duration-getStartSinceRecurring(maxProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule, TRUE)));
  2194. }
  2195. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  2196. {
  2197. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  2198. {
  2199. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = ((maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceRecurring(maxProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule, TRUE))<0?
  2200. 0:
  2201. (maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceRecurring(maxProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule, TRUE)));
  2202. if(idxPeriod > 0)
  2203. {
  2204. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
  2205. {
  2206. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit = maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit;
  2207. }
  2208. }
  2209. }
  2210. }
  2211. }
  2212. }
  2213. /*
  2214. DEBUG_INFO("MaxProfile after align.\n");
  2215. DEBUG_INFO("Profile ID: %d\n", maxProfile.ChargingProfileId);
  2216. DEBUG_INFO("Profile stackLevel: %d\n", maxProfile.StackLevel);
  2217. DEBUG_INFO("Profile TransactionId: %d\n", maxProfile.TransactionId);
  2218. DEBUG_INFO("Profile valid from: %s\n", maxProfile.ValidFrom);
  2219. DEBUG_INFO("Profile valid to: %s\n", maxProfile.ValidTo);
  2220. DEBUG_INFO("Profile ChargingProfileKind: %s\n", maxProfile.ChargingProfileKind);
  2221. DEBUG_INFO("Profile RecurrencyKind: %s\n", maxProfile.RecurrencyKind);
  2222. DEBUG_INFO("Profile start schedule: %s\n", compositeProfile->ChargingSchedule.StartSchedule);
  2223. DEBUG_INFO("Profile schedule duration: %d\n", maxProfile.ChargingSchedule.Duration);
  2224. DEBUG_INFO("Profile charging rate unit: %s\n", maxProfile.ChargingSchedule.ChargingRateUnit);
  2225. DEBUG_INFO("Profile charging min rate: %f\n", maxProfile.ChargingSchedule.MinChargingRate);
  2226. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  2227. {
  2228. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod >= 0)
  2229. {
  2230. DEBUG_INFO("Period-%02d startPeriod: %d\n", idxPeriod, maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod);
  2231. DEBUG_INFO("Period-%02d limit: %f\n", idxPeriod, maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit);
  2232. DEBUG_INFO("Period-%02d NumberPhases: %d\n", idxPeriod, maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases);
  2233. }
  2234. }
  2235. DEBUG_INFO("------------------------------------\n");*/
  2236. }
  2237. // Find each profile period quantity
  2238. for(int idx=0;idx<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idx++)
  2239. {
  2240. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idx].Limit != -1)
  2241. limitMax = idx+1;
  2242. }
  2243. if(maxProfile.ChargingProfileId != -1)
  2244. {
  2245. for(int idxMaxPeriod=0;idxMaxPeriod<limitMax;idxMaxPeriod++)
  2246. {
  2247. if((maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].Limit != -1) &&
  2248. (maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].StartPeriod < durationReq) &&
  2249. (maxProfile.ChargingSchedule.Duration > 0))
  2250. {
  2251. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].StartPeriod != compositeProfile.ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].StartPeriod)
  2252. {
  2253. memcpy(&compositeProfile.ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx], &maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod],sizeof(struct StructChargingSchedulePeriod));
  2254. compositePeriodIdx++;
  2255. }
  2256. else
  2257. {
  2258. memcpy(&compositeProfile.ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)], &maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod],sizeof(struct StructChargingSchedulePeriod));
  2259. }
  2260. }
  2261. }
  2262. }
  2263. DEBUG_INFO("ChargePointMaxProfile ready.\n");
  2264. DEBUG_INFO("Schedule start: %s\n", compositeProfile.ChargingSchedule.StartSchedule);
  2265. DEBUG_INFO("Schedule duration: %d\n", compositeProfile.ChargingSchedule.Duration);
  2266. DEBUG_INFO("Rate unit: %s\n", compositeProfile.ChargingSchedule.ChargingRateUnit);
  2267. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(compositeProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  2268. {
  2269. if(compositeProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod >= 0)
  2270. {
  2271. compositeProfile.ChargingProfileId = 1;
  2272. DEBUG_INFO("Period-%02d startPeriod: %d\n", idxPeriod, compositeProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod);
  2273. DEBUG_INFO("Period-%02d limit: %f\n", idxPeriod, compositeProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit);
  2274. DEBUG_INFO("Period-%02d NumberPhases: %d\n", idxPeriod, compositeProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases);
  2275. }
  2276. if(compositeProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit == -1)
  2277. compositeProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit =0;
  2278. if(compositeProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod == -1)
  2279. compositeProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod =0;
  2280. }
  2281. memcpy(targetCompositeProfile, &compositeProfile, sizeof(struct StructChargingProfile));
  2282. if(line)
  2283. free(line);
  2284. }
  2285. void checkCompositeSchedule(uint8_t connectorId, uint32_t durationReq, struct StructChargingProfile *targetCompositeProfile, uint8_t isUnitA)
  2286. {
  2287. FILE *fp;
  2288. char profileFileName[128];
  2289. char *line = NULL;
  2290. size_t len = 0;
  2291. time_t CurrentTime;
  2292. struct tm *tmComposite;
  2293. struct StructChargingProfile maxProfile;
  2294. struct StructChargingProfile defaultTxProfile;
  2295. struct StructChargingProfile txProfile;
  2296. struct StructChargingProfile compositeProfile;
  2297. struct StructChargingSchedulePeriod tmpPeriod;
  2298. uint8_t limitMax=0;
  2299. uint8_t limitDef=0;
  2300. uint8_t limitTx=0;
  2301. int compositePeriodIdx = 0;
  2302. CurrentTime = time(NULL);
  2303. tmComposite=localtime(&CurrentTime);
  2304. sprintf((char*)compositeProfile.ChargingSchedule.StartSchedule, "%04d-%02d-%02dT%02d:%02d:%02dZ", tmComposite->tm_year+1900, tmComposite->tm_mon+1, tmComposite->tm_mday, tmComposite->tm_hour, tmComposite->tm_min, tmComposite->tm_sec);
  2305. if(isUnitA)
  2306. sprintf((char*)compositeProfile.ChargingSchedule.ChargingRateUnit, "A");
  2307. else
  2308. sprintf((char*)compositeProfile.ChargingSchedule.ChargingRateUnit, "W");
  2309. compositeProfile.ChargingSchedule.Duration = durationReq;
  2310. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(compositeProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  2311. {
  2312. compositeProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = -1;
  2313. compositeProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit = -1;
  2314. compositeProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases = 3;
  2315. }
  2316. compositeProfile.ChargingProfileId = 0;
  2317. compositeProfile.StackLevel = 99 ;
  2318. sprintf((char*)compositeProfile.ChargingProfileKind ,"Absolute");
  2319. maxProfile.ChargingProfileId = -1;
  2320. defaultTxProfile.ChargingProfileId = -1;
  2321. txProfile.ChargingProfileId = -1;
  2322. maxProfile.ChargingSchedule.Duration = -1;
  2323. defaultTxProfile.ChargingSchedule.Duration = -1;
  2324. txProfile.ChargingSchedule.Duration = -1;
  2325. system("rm -f /tmp/*.json");
  2326. system("cp /Storage/OCPP/*.json /tmp 2>/dev/null");
  2327. /*
  2328. * Search valid charging profile
  2329. */
  2330. //DEBUG_INFO("====================================\n");
  2331. // Search tx profile
  2332. sprintf(profileFileName, "/tmp/TxProfile_%d.json", connectorId);
  2333. if((access(profileFileName, F_OK))!=-1)
  2334. {
  2335. fp = fopen(profileFileName, "r");
  2336. while(getline(&line, &len, fp) != -1)
  2337. {
  2338. json_object *obj = NULL;
  2339. obj = json_tokener_parse(line);
  2340. if(is_error(obj))
  2341. {
  2342. DEBUG_ERROR("Parse txProfile from file error.\n");
  2343. }
  2344. else
  2345. {
  2346. if((json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileId")) != txProfile.ChargingProfileId) &&
  2347. (json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "stackLevel")) >= txProfile.StackLevel)
  2348. )
  2349. {
  2350. if((json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom") != NULL) &&
  2351. (json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo") != NULL)
  2352. )
  2353. {
  2354. struct tm tmFrom, tmTo;
  2355. struct timeb tbFrom, tbTo;
  2356. if((sscanf((char*)json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom")), "%4d-%2d-%2dT%2d:%2d:%2d", &tmFrom.tm_year, &tmFrom.tm_mon, &tmFrom.tm_mday, &tmFrom.tm_hour, &tmFrom.tm_min, &tmFrom.tm_sec) == 6) &&
  2357. (sscanf((char*)json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo")), "%4d-%2d-%2dT%2d:%2d:%2d", &tmTo.tm_year, &tmTo.tm_mon, &tmTo.tm_mday, &tmTo.tm_hour, &tmTo.tm_min, &tmTo.tm_sec) == 6))
  2358. {
  2359. tmFrom.tm_year -= 1900;
  2360. tmFrom.tm_mon -= 1;
  2361. tbFrom.time = mktime(&tmFrom);
  2362. tmTo.tm_year -= 1900;
  2363. tmTo.tm_mon -= 1;
  2364. tbTo.time = mktime(&tmTo);
  2365. if((DiffTimebWithNowSec(tbFrom)>=0) && (DiffTimebWithNowSec(tbTo)<=0))
  2366. {
  2367. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(txProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  2368. {
  2369. txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = -1;
  2370. txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit = -1;
  2371. txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases = 3;
  2372. }
  2373. if(txProfile.ChargingProfileId == -1)
  2374. DEBUG_INFO("TxProfile found.\n");
  2375. else
  2376. DEBUG_INFO("TxProfile updated.\n");
  2377. // Required item
  2378. txProfile.ChargingProfileId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileId"));
  2379. txProfile.StackLevel = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "stackLevel"));
  2380. sprintf((char*)txProfile.ChargingProfileKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileKind")));
  2381. if(isUnitA)
  2382. {
  2383. sprintf((char*)txProfile.ChargingSchedule.ChargingRateUnit, "A");
  2384. for(int idxPeriod=0;idxPeriod<json_object_array_length(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"));idxPeriod++)
  2385. {
  2386. txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = json_object_get_int(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "startPeriod"));
  2387. txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases = (json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "numberPhases")==NULL?
  2388. 3:
  2389. json_object_get_int(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "numberPhases")));
  2390. txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit = (strstr(json_object_get_string(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingRateUnit")),"W")!=NULL?json_object_get_double(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "limit"))/(220*txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases):json_object_get_double(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "limit")));
  2391. }
  2392. }
  2393. else
  2394. {
  2395. sprintf((char*)txProfile.ChargingSchedule.ChargingRateUnit, "W");
  2396. for(int idxPeriod=0;idxPeriod<json_object_array_length(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"));idxPeriod++)
  2397. {
  2398. txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = json_object_get_int(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "startPeriod"));
  2399. txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases = (json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "numberPhases")==NULL?
  2400. 3:
  2401. json_object_get_int(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "numberPhases")));
  2402. txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit = (strstr(json_object_get_string(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingRateUnit")),"W")!=NULL?json_object_get_double(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "limit")):json_object_get_double(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "limit"))*(220*txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases));
  2403. }
  2404. }
  2405. // Optional item
  2406. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom") != NULL)
  2407. {
  2408. sprintf((char*)txProfile.ValidFrom, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom")));
  2409. }
  2410. else
  2411. {
  2412. sprintf((char*)txProfile.ValidFrom, " ");
  2413. }
  2414. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo") != NULL)
  2415. {
  2416. sprintf((char*)txProfile.ValidTo, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo")));
  2417. }
  2418. else
  2419. {
  2420. sprintf((char*)txProfile.ValidTo, " ");
  2421. }
  2422. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "recurrencyKind") != NULL)
  2423. {
  2424. sprintf((char*)txProfile.RecurrencyKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "recurrencyKind")));
  2425. }
  2426. else
  2427. {
  2428. sprintf((char*)txProfile.RecurrencyKind, " ");
  2429. }
  2430. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId") != NULL)
  2431. {
  2432. txProfile.TransactionId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId"));
  2433. }
  2434. else
  2435. {
  2436. txProfile.TransactionId = -1;
  2437. }
  2438. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration") != NULL)
  2439. {
  2440. txProfile.ChargingSchedule.Duration = json_object_get_int(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration"));
  2441. }
  2442. else
  2443. {
  2444. txProfile.ChargingSchedule.Duration = 86400;
  2445. }
  2446. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "startSchedule") != NULL)
  2447. {
  2448. sprintf((char*)txProfile.ChargingSchedule.StartSchedule, "%s", json_object_get_string(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "startSchedule")));
  2449. }
  2450. else
  2451. {
  2452. sprintf((char*)txProfile.ChargingSchedule.StartSchedule, "%s", (!cpinitateMsg.bits[(connectorId==0?0:connectorId-1)].isOnCharging ? compositeProfile.ChargingSchedule.StartSchedule : ShmOCPP16Data->StartTransaction[(connectorId==0?0:connectorId-1)].Timestamp));
  2453. }
  2454. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate") != NULL)
  2455. {
  2456. txProfile.ChargingSchedule.MinChargingRate = json_object_get_double(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate"));
  2457. }
  2458. else
  2459. {
  2460. txProfile.ChargingSchedule.MinChargingRate = -1;
  2461. }
  2462. }
  2463. }
  2464. }
  2465. else
  2466. {
  2467. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(txProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  2468. {
  2469. txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = -1;
  2470. txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit = -1;
  2471. txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases = 3;
  2472. }
  2473. if(txProfile.ChargingProfileId == -1)
  2474. DEBUG_INFO("TxProfile found.\n");
  2475. else
  2476. DEBUG_INFO("TxProfile updated.\n");
  2477. // Required item
  2478. txProfile.ChargingProfileId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileId"));
  2479. txProfile.StackLevel = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "stackLevel"));
  2480. sprintf((char*)txProfile.ChargingProfileKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileKind")));
  2481. if(isUnitA)
  2482. {
  2483. sprintf((char*)txProfile.ChargingSchedule.ChargingRateUnit, "A");
  2484. for(int idxPeriod=0;idxPeriod<json_object_array_length(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"));idxPeriod++)
  2485. {
  2486. txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = json_object_get_int(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "startPeriod"));
  2487. txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases = (json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "numberPhases")==NULL?
  2488. 3:
  2489. json_object_get_int(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "numberPhases")));
  2490. txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit = (strstr(json_object_get_string(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingRateUnit")),"W")!=NULL?json_object_get_double(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "limit"))/(220*txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases):json_object_get_double(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "limit")));
  2491. }
  2492. }
  2493. else
  2494. {
  2495. sprintf((char*)txProfile.ChargingSchedule.ChargingRateUnit, "W");
  2496. for(int idxPeriod=0;idxPeriod<json_object_array_length(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"));idxPeriod++)
  2497. {
  2498. txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = json_object_get_int(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "startPeriod"));
  2499. txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases = (json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "numberPhases")==NULL?
  2500. 3:
  2501. json_object_get_int(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "numberPhases")));
  2502. txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit = (strstr(json_object_get_string(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingRateUnit")),"W")!=NULL?json_object_get_double(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "limit")):json_object_get_double(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "limit"))*(220*txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases));
  2503. }
  2504. }
  2505. // Optional item
  2506. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom") != NULL)
  2507. {
  2508. sprintf((char*)txProfile.ValidFrom, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom")));
  2509. }
  2510. else
  2511. {
  2512. sprintf((char*)txProfile.ValidFrom, " ");
  2513. }
  2514. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo") != NULL)
  2515. {
  2516. sprintf((char*)txProfile.ValidTo, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo")));
  2517. }
  2518. else
  2519. {
  2520. sprintf((char*)txProfile.ValidTo, " ");
  2521. }
  2522. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "recurrencyKind") != NULL)
  2523. {
  2524. sprintf((char*)txProfile.RecurrencyKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "recurrencyKind")));
  2525. }
  2526. else
  2527. {
  2528. sprintf((char*)txProfile.RecurrencyKind, " ");
  2529. }
  2530. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId") != NULL)
  2531. {
  2532. txProfile.TransactionId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId"));
  2533. }
  2534. else
  2535. {
  2536. txProfile.TransactionId = -1;
  2537. }
  2538. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration") != NULL)
  2539. {
  2540. txProfile.ChargingSchedule.Duration = json_object_get_int(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration"));
  2541. }
  2542. else
  2543. {
  2544. txProfile.ChargingSchedule.Duration = 86400;
  2545. }
  2546. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "startSchedule") != NULL)
  2547. {
  2548. sprintf((char*)txProfile.ChargingSchedule.StartSchedule, "%s", json_object_get_string(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "startSchedule")));
  2549. }
  2550. else
  2551. {
  2552. sprintf((char*)txProfile.ChargingSchedule.StartSchedule, "%s", (!cpinitateMsg.bits[(connectorId==0?0:connectorId-1)].isOnCharging ? compositeProfile.ChargingSchedule.StartSchedule : ShmOCPP16Data->StartTransaction[(connectorId==0?0:connectorId-1)].Timestamp));
  2553. }
  2554. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate") != NULL)
  2555. {
  2556. txProfile.ChargingSchedule.MinChargingRate = json_object_get_double(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate"));
  2557. }
  2558. else
  2559. {
  2560. txProfile.ChargingSchedule.MinChargingRate = -1;
  2561. }
  2562. }
  2563. }
  2564. }
  2565. json_object_put(obj);
  2566. }
  2567. fclose(fp);
  2568. /*
  2569. if(txProfile.ChargingProfileId != -1)
  2570. {
  2571. DEBUG_INFO("Profile ID: %d\n", txProfile.ChargingProfileId);
  2572. DEBUG_INFO("Profile stackLevel: %d\n", txProfile.StackLevel);
  2573. DEBUG_INFO("Profile TransactionId: %d\n", txProfile.TransactionId);
  2574. DEBUG_INFO("Profile valid from: %s\n", txProfile.ValidFrom);
  2575. DEBUG_INFO("Profile valid to: %s\n", txProfile.ValidTo);
  2576. DEBUG_INFO("Profile ChargingProfileKind: %s\n", txProfile.ChargingProfileKind);
  2577. DEBUG_INFO("Profile recurrencyKind: %s\n", txProfile.RecurrencyKind);
  2578. DEBUG_INFO("Profile start schedule: %s\n", txProfile.ChargingSchedule.StartSchedule);
  2579. DEBUG_INFO("Profile schedule duration: %d\n", txProfile.ChargingSchedule.Duration);
  2580. DEBUG_INFO("Profile charging rate unit: %s\n", txProfile.ChargingSchedule.ChargingRateUnit);
  2581. DEBUG_INFO("Profile charging min rate: %f\n", txProfile.ChargingSchedule.MinChargingRate);
  2582. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(txProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  2583. {
  2584. if(txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod >= 0)
  2585. {
  2586. DEBUG_INFO("Period-%02d startPeriod: %d\n", idxPeriod, txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod);
  2587. DEBUG_INFO("Period-%02d limit: %f\n", idxPeriod, txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit);
  2588. DEBUG_INFO("Period-%02d NumberPhases: %d\n", idxPeriod, txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases);
  2589. }
  2590. }
  2591. }
  2592. else
  2593. DEBUG_INFO("TxProfile not found.\n");*/
  2594. }
  2595. // Search default tx profile
  2596. sprintf(profileFileName, "/tmp/TxDefaultProfile_%d.json", connectorId);
  2597. if((access(profileFileName, F_OK))==-1)
  2598. sprintf(profileFileName, "/tmp/TxDefaultProfile_0.json");
  2599. if((access(profileFileName, F_OK))!=-1)
  2600. {
  2601. fp = fopen(profileFileName, "r");
  2602. while(getline(&line, &len, fp) != -1)
  2603. {
  2604. json_object *obj = NULL;
  2605. obj = json_tokener_parse(line);
  2606. if(is_error(obj))
  2607. {
  2608. DEBUG_ERROR("Parse TxDefaultProfile from file error.\n");
  2609. }
  2610. else
  2611. {
  2612. if((json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileId")) != defaultTxProfile.ChargingProfileId) &&
  2613. (json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "stackLevel")) >= defaultTxProfile.StackLevel)
  2614. )
  2615. {
  2616. if((json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom") != NULL) &&
  2617. (json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo") != NULL)
  2618. )
  2619. {
  2620. struct tm tmFrom, tmTo;
  2621. struct timeb tbFrom, tbTo;
  2622. if((sscanf((char*)json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom")), "%4d-%2d-%2dT%2d:%2d:%2d", &tmFrom.tm_year, &tmFrom.tm_mon, &tmFrom.tm_mday, &tmFrom.tm_hour, &tmFrom.tm_min, &tmFrom.tm_sec) == 6) &&
  2623. (sscanf((char*)json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo")), "%4d-%2d-%2dT%2d:%2d:%2d", &tmTo.tm_year, &tmTo.tm_mon, &tmTo.tm_mday, &tmTo.tm_hour, &tmTo.tm_min, &tmTo.tm_sec) == 6))
  2624. {
  2625. tmFrom.tm_year -= 1900;
  2626. tmFrom.tm_mon -= 1;
  2627. tbFrom.time = mktime(&tmFrom);
  2628. tmTo.tm_year -= 1900;
  2629. tmTo.tm_mon -= 1;
  2630. tbTo.time = mktime(&tmTo);
  2631. if((DiffTimebWithNowSec(tbFrom)>=0) && (DiffTimebWithNowSec(tbTo)<=0))
  2632. {
  2633. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  2634. {
  2635. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = -1;
  2636. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit = -1;
  2637. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases = 3;
  2638. }
  2639. if(defaultTxProfile.ChargingProfileId == -1)
  2640. DEBUG_INFO("TxDefaultProfile found.\n");
  2641. else
  2642. DEBUG_INFO("TxDefaultProfile updated.\n");
  2643. // Required item
  2644. defaultTxProfile.ChargingProfileId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileId"));
  2645. defaultTxProfile.StackLevel = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "stackLevel"));
  2646. sprintf((char*)defaultTxProfile.ChargingProfileKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileKind")));
  2647. if(isUnitA)
  2648. {
  2649. sprintf((char*)defaultTxProfile.ChargingSchedule.ChargingRateUnit, "A");
  2650. for(int idxPeriod=0;idxPeriod<json_object_array_length(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"));idxPeriod++)
  2651. {
  2652. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = json_object_get_int(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "startPeriod"));
  2653. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases = (json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "numberPhases")==NULL?
  2654. 3:
  2655. json_object_get_int(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "numberPhases")));
  2656. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit = (strstr(json_object_get_string(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingRateUnit")),"W")!=NULL?json_object_get_double(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "limit"))/(220*defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases):json_object_get_double(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "limit")));
  2657. }
  2658. }
  2659. else
  2660. {
  2661. sprintf((char*)defaultTxProfile.ChargingSchedule.ChargingRateUnit, "W");
  2662. for(int idxPeriod=0;idxPeriod<json_object_array_length(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"));idxPeriod++)
  2663. {
  2664. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = json_object_get_int(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "startPeriod"));
  2665. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases = (json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "numberPhases")==NULL?
  2666. 3:
  2667. json_object_get_int(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "numberPhases")));
  2668. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit = (strstr(json_object_get_string(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingRateUnit")),"W")!=NULL?json_object_get_double(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "limit")):json_object_get_double(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "limit"))*(220*defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases));
  2669. }
  2670. }
  2671. // Optional item
  2672. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom") != NULL)
  2673. {
  2674. sprintf((char*)defaultTxProfile.ValidFrom, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom")));
  2675. }
  2676. else
  2677. {
  2678. sprintf((char*)defaultTxProfile.ValidFrom, " ");
  2679. }
  2680. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo") != NULL)
  2681. {
  2682. sprintf((char*)defaultTxProfile.ValidTo, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo")));
  2683. }
  2684. else
  2685. {
  2686. sprintf((char*)defaultTxProfile.ValidTo, " ");
  2687. }
  2688. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "recurrencyKind") != NULL)
  2689. {
  2690. sprintf((char*)defaultTxProfile.RecurrencyKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "recurrencyKind")));
  2691. }
  2692. else
  2693. {
  2694. sprintf((char*)defaultTxProfile.RecurrencyKind, " ");
  2695. }
  2696. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId") != NULL)
  2697. {
  2698. defaultTxProfile.TransactionId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId"));
  2699. }
  2700. else
  2701. {
  2702. defaultTxProfile.TransactionId = -1;
  2703. }
  2704. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration") != NULL)
  2705. {
  2706. defaultTxProfile.ChargingSchedule.Duration = json_object_get_int(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration"));
  2707. }
  2708. else
  2709. {
  2710. defaultTxProfile.ChargingSchedule.Duration = 86400;
  2711. }
  2712. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "startSchedule") != NULL)
  2713. {
  2714. sprintf((char*)defaultTxProfile.ChargingSchedule.StartSchedule, "%s", json_object_get_string(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "startSchedule")));
  2715. }
  2716. else
  2717. {
  2718. sprintf((char*)defaultTxProfile.ChargingSchedule.StartSchedule, "%s", (!cpinitateMsg.bits[(connectorId==0?0:connectorId-1)].isOnCharging ? compositeProfile.ChargingSchedule.StartSchedule : ShmOCPP16Data->StartTransaction[(connectorId==0?0:connectorId-1)].Timestamp));
  2719. }
  2720. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate") != NULL)
  2721. {
  2722. defaultTxProfile.ChargingSchedule.MinChargingRate = json_object_get_double(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate"));
  2723. }
  2724. else
  2725. {
  2726. defaultTxProfile.ChargingSchedule.MinChargingRate = -1;
  2727. }
  2728. }
  2729. }
  2730. }
  2731. else
  2732. {
  2733. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  2734. {
  2735. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = -1;
  2736. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit = -1;
  2737. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases = 3;
  2738. }
  2739. if(defaultTxProfile.ChargingProfileId == -1)
  2740. DEBUG_INFO("TxDefaultProfile found.\n");
  2741. else
  2742. DEBUG_INFO("TxDefaultProfile updated.\n");
  2743. // Required item
  2744. defaultTxProfile.ChargingProfileId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileId"));
  2745. defaultTxProfile.StackLevel = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "stackLevel"));
  2746. sprintf((char*)defaultTxProfile.ChargingProfileKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileKind")));
  2747. if(isUnitA)
  2748. {
  2749. sprintf((char*)defaultTxProfile.ChargingSchedule.ChargingRateUnit, "A");
  2750. for(int idxPeriod=0;idxPeriod<json_object_array_length(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"));idxPeriod++)
  2751. {
  2752. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = json_object_get_int(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "startPeriod"));
  2753. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases = (json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "numberPhases")==NULL?
  2754. 3:
  2755. json_object_get_int(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "numberPhases")));
  2756. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit = (strstr(json_object_get_string(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingRateUnit")),"W")!=NULL?json_object_get_double(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "limit"))/(220*defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases):json_object_get_double(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "limit")));
  2757. }
  2758. }
  2759. else
  2760. {
  2761. sprintf((char*)defaultTxProfile.ChargingSchedule.ChargingRateUnit, "W");
  2762. for(int idxPeriod=0;idxPeriod<json_object_array_length(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"));idxPeriod++)
  2763. {
  2764. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = json_object_get_int(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "startPeriod"));
  2765. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases = (json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "numberPhases")==NULL?
  2766. 3:
  2767. json_object_get_int(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "numberPhases")));
  2768. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit = (strstr(json_object_get_string(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingRateUnit")),"W")!=NULL?json_object_get_double(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "limit")):json_object_get_double(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "limit"))*(220*defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases));
  2769. }
  2770. }
  2771. // Optional item
  2772. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom") != NULL)
  2773. {
  2774. sprintf((char*)defaultTxProfile.ValidFrom, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom")));
  2775. }
  2776. else
  2777. {
  2778. sprintf((char*)defaultTxProfile.ValidFrom, " ");
  2779. }
  2780. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo") != NULL)
  2781. {
  2782. sprintf((char*)defaultTxProfile.ValidTo, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo")));
  2783. }
  2784. else
  2785. {
  2786. sprintf((char*)defaultTxProfile.ValidTo, " ");
  2787. }
  2788. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "recurrencyKind") != NULL)
  2789. {
  2790. sprintf((char*)defaultTxProfile.RecurrencyKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "recurrencyKind")));
  2791. }
  2792. else
  2793. {
  2794. sprintf((char*)defaultTxProfile.RecurrencyKind, " ");
  2795. }
  2796. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId") != NULL)
  2797. {
  2798. defaultTxProfile.TransactionId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId"));
  2799. }
  2800. else
  2801. {
  2802. defaultTxProfile.TransactionId = -1;
  2803. }
  2804. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration") != NULL)
  2805. {
  2806. defaultTxProfile.ChargingSchedule.Duration = json_object_get_int(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration"));
  2807. }
  2808. else
  2809. {
  2810. defaultTxProfile.ChargingSchedule.Duration = 86400;
  2811. }
  2812. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "startSchedule") != NULL)
  2813. {
  2814. sprintf((char*)defaultTxProfile.ChargingSchedule.StartSchedule, "%s", json_object_get_string(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "startSchedule")));
  2815. }
  2816. else
  2817. {
  2818. sprintf((char*)defaultTxProfile.ChargingSchedule.StartSchedule, "%s", (!cpinitateMsg.bits[(connectorId==0?0:connectorId-1)].isOnCharging ? compositeProfile.ChargingSchedule.StartSchedule : ShmOCPP16Data->StartTransaction[(connectorId==0?0:connectorId-1)].Timestamp));
  2819. }
  2820. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate") != NULL)
  2821. {
  2822. defaultTxProfile.ChargingSchedule.MinChargingRate = json_object_get_double(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate"));
  2823. }
  2824. else
  2825. {
  2826. defaultTxProfile.ChargingSchedule.MinChargingRate = -1;
  2827. }
  2828. }
  2829. }
  2830. }
  2831. json_object_put(obj);
  2832. }
  2833. fclose(fp);
  2834. /*
  2835. if(defaultTxProfile.ChargingProfileId != -1)
  2836. {
  2837. DEBUG_INFO("Profile ID: %d\n", defaultTxProfile.ChargingProfileId);
  2838. DEBUG_INFO("Profile stackLevel: %d\n", defaultTxProfile.StackLevel);
  2839. DEBUG_INFO("Profile TransactionId: %d\n", defaultTxProfile.TransactionId);
  2840. DEBUG_INFO("Profile valid from: %s\n", defaultTxProfile.ValidFrom);
  2841. DEBUG_INFO("Profile valid to: %s\n", defaultTxProfile.ValidTo);
  2842. DEBUG_INFO("Profile ChargingProfileKind: %s\n", defaultTxProfile.ChargingProfileKind);
  2843. DEBUG_INFO("Profile recurrencyKind: %s\n", defaultTxProfile.RecurrencyKind);
  2844. DEBUG_INFO("Profile start schedule: %s\n", defaultTxProfile.ChargingSchedule.StartSchedule);
  2845. DEBUG_INFO("Profile schedule duration: %d\n", defaultTxProfile.ChargingSchedule.Duration);
  2846. DEBUG_INFO("Profile charging rate unit: %s\n", defaultTxProfile.ChargingSchedule.ChargingRateUnit);
  2847. DEBUG_INFO("Profile charging min rate: %f\n", defaultTxProfile.ChargingSchedule.MinChargingRate);
  2848. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  2849. {
  2850. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod >= 0)
  2851. {
  2852. DEBUG_INFO("Period-%02d startPeriod: %d\n", idxPeriod, defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod);
  2853. DEBUG_INFO("Period-%02d limit: %f\n", idxPeriod, defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit);
  2854. DEBUG_INFO("Period-%02d NumberPhases: %d\n", idxPeriod, defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases);
  2855. }
  2856. }
  2857. }
  2858. else
  2859. DEBUG_INFO("TxDefaultProfile not found.\n");
  2860. DEBUG_INFO("------------------------------------\n");*/
  2861. }
  2862. // Search max profile
  2863. sprintf(profileFileName, "/tmp/ChargePointMaxProfile.json");
  2864. if((access(profileFileName, F_OK))!=-1)
  2865. {
  2866. fp = fopen(profileFileName, "r");
  2867. while(getline(&line, &len, fp) != -1)
  2868. {
  2869. json_object *obj = NULL;
  2870. obj = json_tokener_parse(line);
  2871. if(is_error(obj))
  2872. {
  2873. DEBUG_ERROR("Parse MaxProfile from file error.\n");
  2874. }
  2875. else
  2876. {
  2877. if((json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileId")) != maxProfile.ChargingProfileId) &&
  2878. (json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "stackLevel")) >= maxProfile.StackLevel)
  2879. )
  2880. {
  2881. if((json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom") != NULL) &&
  2882. (json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo") != NULL)
  2883. )
  2884. {
  2885. struct tm tmFrom, tmTo;
  2886. struct timeb tbFrom, tbTo;
  2887. if((sscanf((char*)json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom")), "%4d-%2d-%2dT%2d:%2d:%2d", &tmFrom.tm_year, &tmFrom.tm_mon, &tmFrom.tm_mday, &tmFrom.tm_hour, &tmFrom.tm_min, &tmFrom.tm_sec) == 6) &&
  2888. (sscanf((char*)json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo")), "%4d-%2d-%2dT%2d:%2d:%2d", &tmTo.tm_year, &tmTo.tm_mon, &tmTo.tm_mday, &tmTo.tm_hour, &tmTo.tm_min, &tmTo.tm_sec) == 6))
  2889. {
  2890. tmFrom.tm_year -= 1900;
  2891. tmFrom.tm_mon -= 1;
  2892. tbFrom.time = mktime(&tmFrom);
  2893. tmTo.tm_year -= 1900;
  2894. tmTo.tm_mon -= 1;
  2895. tbTo.time = mktime(&tmTo);
  2896. if((DiffTimebWithNowSec(tbFrom)>=0) && (DiffTimebWithNowSec(tbTo)<=0))
  2897. {
  2898. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  2899. {
  2900. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = -1;
  2901. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit = -1;
  2902. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases = 3;
  2903. }
  2904. if(maxProfile.ChargingProfileId == -1)
  2905. DEBUG_INFO("MaxProfile found.\n");
  2906. else
  2907. DEBUG_INFO("MaxProfile updated.\n");
  2908. // Required item
  2909. maxProfile.ChargingProfileId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileId"));
  2910. maxProfile.StackLevel = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "stackLevel"));
  2911. sprintf((char*)maxProfile.ChargingProfileKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileKind")));
  2912. if(isUnitA)
  2913. {
  2914. sprintf((char*)maxProfile.ChargingSchedule.ChargingRateUnit, "A");
  2915. for(int idxPeriod=0;idxPeriod<json_object_array_length(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"));idxPeriod++)
  2916. {
  2917. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = json_object_get_int(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "startPeriod"));
  2918. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases = (json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "numberPhases")==NULL?
  2919. 3:
  2920. json_object_get_int(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "numberPhases")));
  2921. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit = (strstr(json_object_get_string(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingRateUnit")),"W")!=NULL?json_object_get_double(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "limit"))/(220*maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases):json_object_get_double(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "limit")));
  2922. }
  2923. }
  2924. else
  2925. {
  2926. sprintf((char*)maxProfile.ChargingSchedule.ChargingRateUnit, "W");
  2927. for(int idxPeriod=0;idxPeriod<json_object_array_length(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"));idxPeriod++)
  2928. {
  2929. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = json_object_get_int(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "startPeriod"));
  2930. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases = (json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "numberPhases")==NULL?
  2931. 3:
  2932. json_object_get_int(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "numberPhases")));
  2933. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit = (strstr(json_object_get_string(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingRateUnit")),"W")!=NULL?json_object_get_double(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "limit")):json_object_get_double(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "limit"))*(220*maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases));
  2934. }
  2935. }
  2936. // Optional item
  2937. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom") != NULL)
  2938. {
  2939. sprintf((char*)maxProfile.ValidFrom, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom")));
  2940. }
  2941. else
  2942. {
  2943. sprintf((char*)maxProfile.ValidFrom, " ");
  2944. }
  2945. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo") != NULL)
  2946. {
  2947. sprintf((char*)maxProfile.ValidTo, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo")));
  2948. }
  2949. else
  2950. {
  2951. sprintf((char*)maxProfile.ValidTo, " ");
  2952. }
  2953. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "recurrencyKind") != NULL)
  2954. {
  2955. sprintf((char*)maxProfile.RecurrencyKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "recurrencyKind")));
  2956. }
  2957. else
  2958. {
  2959. sprintf((char*)maxProfile.RecurrencyKind, " ");
  2960. }
  2961. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId") != NULL)
  2962. {
  2963. maxProfile.TransactionId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId"));
  2964. }
  2965. else
  2966. {
  2967. maxProfile.TransactionId = -1;
  2968. }
  2969. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration") != NULL)
  2970. {
  2971. maxProfile.ChargingSchedule.Duration = json_object_get_int(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration"));
  2972. }
  2973. else
  2974. {
  2975. maxProfile.ChargingSchedule.Duration = 86400;
  2976. }
  2977. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "startSchedule") != NULL)
  2978. {
  2979. sprintf((char*)maxProfile.ChargingSchedule.StartSchedule, "%s", json_object_get_string(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "startSchedule")));
  2980. }
  2981. else
  2982. {
  2983. sprintf((char*)maxProfile.ChargingSchedule.StartSchedule, "%s", (!cpinitateMsg.bits[(connectorId==0?0:connectorId-1)].isOnCharging ? compositeProfile.ChargingSchedule.StartSchedule : ShmOCPP16Data->StartTransaction[(connectorId==0?0:connectorId-1)].Timestamp));
  2984. }
  2985. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate") != NULL)
  2986. {
  2987. maxProfile.ChargingSchedule.MinChargingRate = json_object_get_double(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate"));
  2988. }
  2989. else
  2990. {
  2991. maxProfile.ChargingSchedule.MinChargingRate = -1;
  2992. }
  2993. }
  2994. }
  2995. }
  2996. else
  2997. {
  2998. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  2999. {
  3000. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = -1;
  3001. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit = -1;
  3002. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases = 3;
  3003. }
  3004. if(maxProfile.ChargingProfileId == -1)
  3005. DEBUG_INFO("MaxProfile found.\n");
  3006. else
  3007. DEBUG_INFO("MaxProfile updated.\n");
  3008. // Required item
  3009. maxProfile.ChargingProfileId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileId"));
  3010. maxProfile.StackLevel = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "stackLevel"));
  3011. sprintf((char*)maxProfile.ChargingProfileKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileKind")));
  3012. if(isUnitA)
  3013. {
  3014. sprintf((char*)maxProfile.ChargingSchedule.ChargingRateUnit, "A");
  3015. for(int idxPeriod=0;idxPeriod<json_object_array_length(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"));idxPeriod++)
  3016. {
  3017. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = json_object_get_int(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "startPeriod"));
  3018. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases = (json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "numberPhases")==NULL?
  3019. 3:
  3020. json_object_get_int(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "numberPhases")));
  3021. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit = (strstr((char*)json_object_get_string(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingRateUnit")),"W")!=NULL?json_object_get_double(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "limit"))/(220*maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases):json_object_get_double(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "limit")));
  3022. }
  3023. }
  3024. else
  3025. {
  3026. sprintf((char*)maxProfile.ChargingSchedule.ChargingRateUnit, "W");
  3027. for(int idxPeriod=0;idxPeriod<json_object_array_length(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"));idxPeriod++)
  3028. {
  3029. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = json_object_get_int(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "startPeriod"));
  3030. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases = (json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "numberPhases")==NULL?
  3031. 3:
  3032. json_object_get_int(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "numberPhases")));
  3033. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit = (strstr((char*)json_object_get_string(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingRateUnit")),"W")!=NULL?json_object_get_double(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "limit")):json_object_get_double(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "limit"))*(220*maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases));
  3034. }
  3035. }
  3036. // Optional item
  3037. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom") != NULL)
  3038. {
  3039. sprintf((char*)maxProfile.ValidFrom, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom")));
  3040. }
  3041. else
  3042. {
  3043. sprintf((char*)maxProfile.ValidFrom, " ");
  3044. }
  3045. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo") != NULL)
  3046. {
  3047. sprintf((char*)maxProfile.ValidTo, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo")));
  3048. }
  3049. else
  3050. {
  3051. sprintf((char*)maxProfile.ValidTo, " ");
  3052. }
  3053. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "recurrencyKind") != NULL)
  3054. {
  3055. sprintf((char*)maxProfile.RecurrencyKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "recurrencyKind")));
  3056. }
  3057. else
  3058. {
  3059. sprintf((char*)maxProfile.RecurrencyKind, " ");
  3060. }
  3061. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId") != NULL)
  3062. {
  3063. maxProfile.TransactionId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId"));
  3064. }
  3065. else
  3066. {
  3067. maxProfile.TransactionId = -1;
  3068. }
  3069. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration") != NULL)
  3070. {
  3071. maxProfile.ChargingSchedule.Duration = json_object_get_int(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration"));
  3072. }
  3073. else
  3074. {
  3075. maxProfile.ChargingSchedule.Duration = 86400;
  3076. }
  3077. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "startSchedule") != NULL)
  3078. {
  3079. sprintf((char*)maxProfile.ChargingSchedule.StartSchedule, "%s", json_object_get_string(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "startSchedule")));
  3080. }
  3081. else
  3082. {
  3083. sprintf((char*)maxProfile.ChargingSchedule.StartSchedule, "%s", (!cpinitateMsg.bits[(connectorId==0?0:connectorId-1)].isOnCharging ? compositeProfile.ChargingSchedule.StartSchedule : ShmOCPP16Data->StartTransaction[(connectorId==0?0:connectorId-1)].Timestamp));
  3084. }
  3085. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate") != NULL)
  3086. {
  3087. maxProfile.ChargingSchedule.MinChargingRate = json_object_get_double(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate"));
  3088. }
  3089. else
  3090. {
  3091. maxProfile.ChargingSchedule.MinChargingRate = -1;
  3092. }
  3093. }
  3094. }
  3095. }
  3096. json_object_put(obj);
  3097. }
  3098. fclose(fp);
  3099. /*
  3100. if(maxProfile.ChargingProfileId !=-1)
  3101. {
  3102. DEBUG_INFO("Profile ID: %d\n", maxProfile.ChargingProfileId);
  3103. DEBUG_INFO("Profile stackLevel: %d\n", maxProfile.StackLevel);
  3104. DEBUG_INFO("Profile TransactionId: %d\n", maxProfile.TransactionId);
  3105. DEBUG_INFO("Profile valid from: %s\n", maxProfile.ValidFrom);
  3106. DEBUG_INFO("Profile valid to: %s\n", maxProfile.ValidTo);
  3107. DEBUG_INFO("Profile ChargingProfileKind: %s\n", maxProfile.ChargingProfileKind);
  3108. DEBUG_INFO("Profile recurrencyKind: %s\n", maxProfile.RecurrencyKind);
  3109. DEBUG_INFO("Profile start schedule: %s\n", maxProfile.ChargingSchedule.StartSchedule);
  3110. DEBUG_INFO("Profile schedule duration: %d\n", maxProfile.ChargingSchedule.Duration);
  3111. DEBUG_INFO("Profile charging rate unit: %s\n", maxProfile.ChargingSchedule.ChargingRateUnit);
  3112. DEBUG_INFO("Profile charging min rate: %f\n", maxProfile.ChargingSchedule.MinChargingRate);
  3113. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  3114. {
  3115. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod >= 0)
  3116. {
  3117. DEBUG_INFO("Period-%02d startPeriod: %d\n", idxPeriod, maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod);
  3118. DEBUG_INFO("Period-%02d limit: %f\n", idxPeriod, maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit);
  3119. DEBUG_INFO("Period-%02d NumberPhases: %d\n", idxPeriod, maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases);
  3120. }
  3121. }
  3122. }
  3123. else
  3124. DEBUG_INFO("MaxProfile not found.\n");
  3125. DEBUG_INFO("------------------------------------\n");*/
  3126. }
  3127. /*
  3128. * Align found profile start schedule & periods
  3129. */
  3130. //DEBUG_INFO("====================================\n");
  3131. /*
  3132. // For local test usage, force modify found profile start schedule info
  3133. sprintf((char*)maxProfile.ChargingSchedule.StartSchedule, "%04d-%02d-%02dT%02d:%02d:%02dZ", tmComposite->tm_year+1900, tmComposite->tm_mon+1, tmComposite->tm_mday, tmComposite->tm_hour, tmComposite->tm_min, tmComposite->tm_sec-10);
  3134. sprintf((char*)defaultTxProfile.ChargingSchedule.StartSchedule, "%04d-%02d-%02dT%02d:%02d:%02dZ", tmComposite->tm_year+1900, tmComposite->tm_mon+1, tmComposite->tm_mday, tmComposite->tm_hour, tmComposite->tm_min, tmComposite->tm_sec-5);
  3135. sprintf((char*)txProfile.ChargingSchedule.StartSchedule, "%04d-%02d-%02dT%02d:%02d:%02dZ", tmComposite->tm_year+1900, tmComposite->tm_mon+1, tmComposite->tm_mday, tmComposite->tm_hour, tmComposite->tm_min, tmComposite->tm_sec-3);
  3136. */
  3137. if(txProfile.ChargingProfileId != -1)
  3138. {
  3139. if(strstr((char*)txProfile.ChargingProfileKind, "Absolute") != NULL)
  3140. {
  3141. if(txProfile.ChargingSchedule.Duration != -1)
  3142. {
  3143. txProfile.ChargingSchedule.Duration = ((txProfile.ChargingSchedule.Duration-getStartStop(txProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule))<0?
  3144. 0:
  3145. (txProfile.ChargingSchedule.Duration-getStartStop(txProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule)));
  3146. }
  3147. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(txProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  3148. {
  3149. if(txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  3150. {
  3151. txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = ((txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartStop(txProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule))<0?
  3152. 0:
  3153. (txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartStop(txProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule)));
  3154. if(idxPeriod > 0)
  3155. {
  3156. if(txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
  3157. {
  3158. txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit = txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit;
  3159. }
  3160. }
  3161. }
  3162. }
  3163. }
  3164. else if(strstr((char*)txProfile.ChargingProfileKind, "Relative") != NULL)
  3165. {
  3166. if(txProfile.ChargingSchedule.Duration != -1)
  3167. {
  3168. txProfile.ChargingSchedule.Duration = !cpinitateMsg.bits[(connectorId==0?0:connectorId-1)].isOnCharging?txProfile.ChargingSchedule.Duration:((txProfile.ChargingSchedule.Duration-getStartStop(ShmOCPP16Data->StartTransaction[(connectorId==0?0:connectorId-1)].Timestamp, compositeProfile.ChargingSchedule.StartSchedule))<0?
  3169. 0:
  3170. (txProfile.ChargingSchedule.Duration-getStartStop(ShmOCPP16Data->StartTransaction[(connectorId==0?0:connectorId-1)].Timestamp, compositeProfile.ChargingSchedule.StartSchedule)));
  3171. }
  3172. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(txProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  3173. {
  3174. if(txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  3175. {
  3176. txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = !cpinitateMsg.bits[(connectorId==0?0:connectorId-1)].isOnCharging?txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod:((txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartStop(ShmOCPP16Data->StartTransaction[(connectorId==0?0:connectorId-1)].Timestamp, compositeProfile.ChargingSchedule.StartSchedule))<0?
  3177. 0:
  3178. (txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartStop(ShmOCPP16Data->StartTransaction[(connectorId==0?0:connectorId-1)].Timestamp, compositeProfile.ChargingSchedule.StartSchedule)));
  3179. if(idxPeriod > 0)
  3180. {
  3181. if(txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
  3182. {
  3183. txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit = txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit;
  3184. }
  3185. }
  3186. }
  3187. }
  3188. }
  3189. else
  3190. {
  3191. if(strstr((char*)txProfile.RecurrencyKind, "Weekly") != NULL)
  3192. {
  3193. if(txProfile.ChargingSchedule.Duration != -1)
  3194. {
  3195. txProfile.ChargingSchedule.Duration = ((txProfile.ChargingSchedule.Duration-getStartSinceRecurring(txProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule, FALSE))<0?
  3196. 0:
  3197. (txProfile.ChargingSchedule.Duration-getStartSinceRecurring(txProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule, FALSE)));
  3198. }
  3199. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(txProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  3200. {
  3201. if(txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  3202. {
  3203. txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = ((txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceRecurring(txProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule, FALSE))<0?
  3204. 0:
  3205. (txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceRecurring(txProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule, FALSE)));
  3206. if(idxPeriod > 0)
  3207. {
  3208. if(txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
  3209. {
  3210. txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit = txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit;
  3211. }
  3212. }
  3213. }
  3214. }
  3215. }
  3216. else
  3217. {
  3218. if(txProfile.ChargingSchedule.Duration != -1)
  3219. {
  3220. txProfile.ChargingSchedule.Duration = ((txProfile.ChargingSchedule.Duration-getStartSinceRecurring(txProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule, TRUE))<0?
  3221. 0:
  3222. (txProfile.ChargingSchedule.Duration-getStartSinceRecurring(txProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule, TRUE)));
  3223. }
  3224. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(txProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  3225. {
  3226. if(txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  3227. {
  3228. txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = ((txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceRecurring(txProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule, TRUE))<0?
  3229. 0:
  3230. (txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceRecurring(txProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule, TRUE)));
  3231. if(idxPeriod > 0)
  3232. {
  3233. if(txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
  3234. {
  3235. txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit = txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit;
  3236. }
  3237. }
  3238. }
  3239. }
  3240. }
  3241. }
  3242. /*
  3243. DEBUG_INFO("txProfile after align.\n");
  3244. DEBUG_INFO("Profile ID: %d\n", txProfile.ChargingProfileId);
  3245. DEBUG_INFO("Profile stackLevel: %d\n", txProfile.StackLevel);
  3246. DEBUG_INFO("Profile TransactionId: %d\n", txProfile.TransactionId);
  3247. DEBUG_INFO("Profile valid from: %s\n", txProfile.ValidFrom);
  3248. DEBUG_INFO("Profile valid to: %s\n", txProfile.ValidTo);
  3249. DEBUG_INFO("Profile ChargingProfileKind: %s\n", txProfile.ChargingProfileKind);
  3250. DEBUG_INFO("Profile recurrencyKind: %s\n", txProfile.RecurrencyKind);
  3251. DEBUG_INFO("Profile start schedule: %s\n", compositeProfile.ChargingSchedule.StartSchedule);
  3252. DEBUG_INFO("Profile schedule duration: %d\n", txProfile.ChargingSchedule.Duration);
  3253. DEBUG_INFO("Profile charging rate unit: %s\n", txProfile.ChargingSchedule.ChargingRateUnit);
  3254. DEBUG_INFO("Profile charging min rate: %f\n", txProfile.ChargingSchedule.MinChargingRate);
  3255. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(txProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  3256. {
  3257. if(txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod >= 0)
  3258. {
  3259. DEBUG_INFO("Period-%02d startPeriod: %d\n", idxPeriod, txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod);
  3260. DEBUG_INFO("Period-%02d limit: %f\n", idxPeriod, txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit);
  3261. DEBUG_INFO("Period-%02d NumberPhases: %d\n", idxPeriod, txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases);
  3262. }
  3263. }*/
  3264. }
  3265. if(defaultTxProfile.ChargingProfileId != -1)
  3266. {
  3267. if(strstr((char*)defaultTxProfile.ChargingProfileKind, "Absolute") != NULL)
  3268. {
  3269. if(defaultTxProfile.ChargingSchedule.Duration != -1)
  3270. {
  3271. defaultTxProfile.ChargingSchedule.Duration = ((defaultTxProfile.ChargingSchedule.Duration-getStartStop(defaultTxProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule))<0?
  3272. 0:
  3273. (defaultTxProfile.ChargingSchedule.Duration-getStartStop(defaultTxProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule)));
  3274. }
  3275. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  3276. {
  3277. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  3278. {
  3279. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = ((defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartStop(defaultTxProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule))<0?
  3280. 0:
  3281. (defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartStop(defaultTxProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule)));
  3282. if(idxPeriod > 0)
  3283. {
  3284. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
  3285. {
  3286. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit = defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit;
  3287. }
  3288. }
  3289. }
  3290. }
  3291. }
  3292. else if(strstr((char*)defaultTxProfile.ChargingProfileKind, "Relative") != NULL)
  3293. {
  3294. if(defaultTxProfile.ChargingSchedule.Duration != -1)
  3295. {
  3296. defaultTxProfile.ChargingSchedule.Duration = !cpinitateMsg.bits[(connectorId==0?0:connectorId-1)].isOnCharging?defaultTxProfile.ChargingSchedule.Duration:((defaultTxProfile.ChargingSchedule.Duration-getStartStop(ShmOCPP16Data->StartTransaction[(connectorId==0?0:connectorId-1)].Timestamp, compositeProfile.ChargingSchedule.StartSchedule))<0?
  3297. 0:
  3298. (defaultTxProfile.ChargingSchedule.Duration-getStartStop(ShmOCPP16Data->StartTransaction[(connectorId==0?0:connectorId-1)].Timestamp, compositeProfile.ChargingSchedule.StartSchedule)));
  3299. }
  3300. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  3301. {
  3302. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  3303. {
  3304. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = !cpinitateMsg.bits[(connectorId==0?0:connectorId-1)].isOnCharging?defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod:((defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartStop(ShmOCPP16Data->StartTransaction[(connectorId==0?0:connectorId-1)].Timestamp, compositeProfile.ChargingSchedule.StartSchedule))<0?
  3305. 0:
  3306. (defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartStop(ShmOCPP16Data->StartTransaction[(connectorId==0?0:connectorId-1)].Timestamp, compositeProfile.ChargingSchedule.StartSchedule)));
  3307. if(idxPeriod > 0)
  3308. {
  3309. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
  3310. {
  3311. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit = defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit;
  3312. }
  3313. }
  3314. }
  3315. }
  3316. }
  3317. else
  3318. {
  3319. if(strstr((char*)defaultTxProfile.RecurrencyKind, "Weekly") != NULL)
  3320. {
  3321. if(defaultTxProfile.ChargingSchedule.Duration != -1)
  3322. {
  3323. defaultTxProfile.ChargingSchedule.Duration = ((defaultTxProfile.ChargingSchedule.Duration-getStartSinceRecurring(defaultTxProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule, FALSE))<0?
  3324. 0:
  3325. (defaultTxProfile.ChargingSchedule.Duration-getStartSinceRecurring(defaultTxProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule, FALSE)));
  3326. }
  3327. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  3328. {
  3329. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  3330. {
  3331. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = ((defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceRecurring(defaultTxProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule, FALSE))<0?
  3332. 0:
  3333. (defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceRecurring(defaultTxProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule, FALSE)));
  3334. if(idxPeriod > 0)
  3335. {
  3336. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
  3337. {
  3338. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit = defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit;
  3339. }
  3340. }
  3341. }
  3342. }
  3343. }
  3344. else
  3345. {
  3346. if(defaultTxProfile.ChargingSchedule.Duration != -1)
  3347. {
  3348. defaultTxProfile.ChargingSchedule.Duration = ((defaultTxProfile.ChargingSchedule.Duration-getStartSinceRecurring(defaultTxProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule, TRUE))<0?
  3349. 0:
  3350. (defaultTxProfile.ChargingSchedule.Duration-getStartSinceRecurring(defaultTxProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule, TRUE)));
  3351. }
  3352. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  3353. {
  3354. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  3355. {
  3356. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = ((defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceRecurring(defaultTxProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule, TRUE))<0?
  3357. 0:
  3358. (defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceRecurring(defaultTxProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule, TRUE)));
  3359. if(idxPeriod > 0)
  3360. {
  3361. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
  3362. {
  3363. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit = defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit;
  3364. }
  3365. }
  3366. }
  3367. }
  3368. }
  3369. }
  3370. /*
  3371. DEBUG_INFO("defaultTxProfile after align.\n");
  3372. DEBUG_INFO("Profile ID: %d\n", defaultTxProfile.ChargingProfileId);
  3373. DEBUG_INFO("Profile stackLevel: %d\n", defaultTxProfile.StackLevel);
  3374. DEBUG_INFO("Profile TransactionId: %d\n", defaultTxProfile.TransactionId);
  3375. DEBUG_INFO("Profile valid from: %s\n", defaultTxProfile.ValidFrom);
  3376. DEBUG_INFO("Profile valid to: %s\n", defaultTxProfile.ValidTo);
  3377. DEBUG_INFO("Profile ChargingProfileKind: %s\n", defaultTxProfile.ChargingProfileKind);
  3378. DEBUG_INFO("Profile recurrencyKind: %s\n", defaultTxProfile.RecurrencyKind);
  3379. DEBUG_INFO("Profile start schedule: %s\n", compositeProfile.ChargingSchedule.StartSchedule);
  3380. DEBUG_INFO("Profile schedule duration: %d\n", defaultTxProfile.ChargingSchedule.Duration);
  3381. DEBUG_INFO("Profile charging rate unit: %s\n", defaultTxProfile.ChargingSchedule.ChargingRateUnit);
  3382. DEBUG_INFO("Profile charging min rate: %f\n", defaultTxProfile.ChargingSchedule.MinChargingRate);
  3383. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  3384. {
  3385. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod >= 0)
  3386. {
  3387. DEBUG_INFO("Period-%02d startPeriod: %d\n", idxPeriod, defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod);
  3388. DEBUG_INFO("Period-%02d limit: %f\n", idxPeriod, defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit);
  3389. DEBUG_INFO("Period-%02d NumberPhases: %d\n", idxPeriod, defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases);
  3390. }
  3391. }
  3392. DEBUG_INFO("------------------------------------\n");*/
  3393. }
  3394. if(maxProfile.ChargingProfileId != -1)
  3395. {
  3396. if(strstr((char*)maxProfile.ChargingProfileKind, "Absolute") != NULL)
  3397. {
  3398. if(maxProfile.ChargingSchedule.Duration != -1)
  3399. {
  3400. maxProfile.ChargingSchedule.Duration = ((maxProfile.ChargingSchedule.Duration-getStartStop(maxProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule))<0?
  3401. 0:
  3402. (maxProfile.ChargingSchedule.Duration-getStartStop(maxProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule)));
  3403. }
  3404. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  3405. {
  3406. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  3407. {
  3408. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = ((maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartStop(maxProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule))<0?
  3409. 0:
  3410. (maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartStop(maxProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule)));
  3411. if(idxPeriod > 0)
  3412. {
  3413. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
  3414. {
  3415. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit = maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit;
  3416. }
  3417. }
  3418. }
  3419. }
  3420. }
  3421. else if(strstr((char*)maxProfile.ChargingProfileKind, "Relative") != NULL)
  3422. {
  3423. if(maxProfile.ChargingSchedule.Duration != -1)
  3424. {
  3425. maxProfile.ChargingSchedule.Duration = !cpinitateMsg.bits[(connectorId==0?0:connectorId-1)].isOnCharging?maxProfile.ChargingSchedule.Duration:((maxProfile.ChargingSchedule.Duration-getStartStop(ShmOCPP16Data->StartTransaction[(connectorId==0?0:connectorId-1)].Timestamp, compositeProfile.ChargingSchedule.StartSchedule))<0?
  3426. 0:
  3427. (maxProfile.ChargingSchedule.Duration-getStartStop(ShmOCPP16Data->StartTransaction[(connectorId==0?0:connectorId-1)].Timestamp, compositeProfile.ChargingSchedule.StartSchedule)));
  3428. }
  3429. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  3430. {
  3431. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  3432. {
  3433. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = !cpinitateMsg.bits[(connectorId==0?0:connectorId-1)].isOnCharging?maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod:((maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartStop(ShmOCPP16Data->StartTransaction[(connectorId==0?0:connectorId-1)].Timestamp, compositeProfile.ChargingSchedule.StartSchedule))<0?
  3434. 0:
  3435. (maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartStop(ShmOCPP16Data->StartTransaction[(connectorId==0?0:connectorId-1)].Timestamp, compositeProfile.ChargingSchedule.StartSchedule)));
  3436. if(idxPeriod > 0)
  3437. {
  3438. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
  3439. {
  3440. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit = maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit;
  3441. }
  3442. }
  3443. }
  3444. }
  3445. }
  3446. else
  3447. {
  3448. if(strstr((char*)maxProfile.RecurrencyKind, "Weekly") != NULL)
  3449. {
  3450. if(maxProfile.ChargingSchedule.Duration != -1)
  3451. {
  3452. maxProfile.ChargingSchedule.Duration = ((maxProfile.ChargingSchedule.Duration-getStartSinceRecurring(maxProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule, FALSE))<0?
  3453. 0:
  3454. (maxProfile.ChargingSchedule.Duration-getStartSinceRecurring(maxProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule, FALSE)));
  3455. }
  3456. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  3457. {
  3458. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  3459. {
  3460. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = ((maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceRecurring(maxProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule, FALSE))<0?
  3461. 0:
  3462. (maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceRecurring(maxProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule, FALSE)));
  3463. if(idxPeriod > 0)
  3464. {
  3465. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
  3466. {
  3467. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit = maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit;
  3468. }
  3469. }
  3470. }
  3471. }
  3472. }
  3473. else
  3474. {
  3475. if(maxProfile.ChargingSchedule.Duration != -1)
  3476. {
  3477. maxProfile.ChargingSchedule.Duration = ((maxProfile.ChargingSchedule.Duration-getStartSinceRecurring(maxProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule, TRUE))<0?
  3478. 0:
  3479. (maxProfile.ChargingSchedule.Duration-getStartSinceRecurring(maxProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule, TRUE)));
  3480. }
  3481. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  3482. {
  3483. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  3484. {
  3485. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = ((maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceRecurring(maxProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule, TRUE))<0?
  3486. 0:
  3487. (maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceRecurring(maxProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule, TRUE)));
  3488. if(idxPeriod > 0)
  3489. {
  3490. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
  3491. {
  3492. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit = maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit;
  3493. }
  3494. }
  3495. }
  3496. }
  3497. }
  3498. }
  3499. /*
  3500. DEBUG_INFO("MaxProfile after align.\n");
  3501. DEBUG_INFO("Profile ID: %d\n", maxProfile.ChargingProfileId);
  3502. DEBUG_INFO("Profile stackLevel: %d\n", maxProfile.StackLevel);
  3503. DEBUG_INFO("Profile TransactionId: %d\n", maxProfile.TransactionId);
  3504. DEBUG_INFO("Profile valid from: %s\n", maxProfile.ValidFrom);
  3505. DEBUG_INFO("Profile valid to: %s\n", maxProfile.ValidTo);
  3506. DEBUG_INFO("Profile ChargingProfileKind: %s\n", maxProfile.ChargingProfileKind);
  3507. DEBUG_INFO("Profile recurrencyKind: %s\n", maxProfile.RecurrencyKind);
  3508. DEBUG_INFO("Profile start schedule: %s\n", compositeProfile.ChargingSchedule.StartSchedule);
  3509. DEBUG_INFO("Profile schedule duration: %d\n", maxProfile.ChargingSchedule.Duration);
  3510. DEBUG_INFO("Profile charging rate unit: %s\n", maxProfile.ChargingSchedule.ChargingRateUnit);
  3511. DEBUG_INFO("Profile charging min rate: %f\n", maxProfile.ChargingSchedule.MinChargingRate);
  3512. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  3513. {
  3514. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod >= 0)
  3515. {
  3516. DEBUG_INFO("Period-%02d startPeriod: %d\n", idxPeriod, maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod);
  3517. DEBUG_INFO("Period-%02d limit: %f\n", idxPeriod, maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit);
  3518. DEBUG_INFO("Period-%02d NumberPhases: %d\n", idxPeriod, maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases);
  3519. }
  3520. }
  3521. DEBUG_INFO("------------------------------------\n");*/
  3522. }
  3523. /*
  3524. * Merge to conposite schedule
  3525. */
  3526. //DEBUG_INFO("====================================\n");
  3527. // Find each profile period quantity
  3528. for(int idx=0;idx<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idx++)
  3529. {
  3530. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idx].Limit != -1)
  3531. limitMax = idx+1;
  3532. }
  3533. for(int idx=0;idx<ARRAY_SIZE(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod);idx++)
  3534. {
  3535. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idx].Limit != -1)
  3536. limitDef = idx+1;
  3537. }
  3538. for(int idx=0;idx<ARRAY_SIZE(txProfile.ChargingSchedule.ChargingSchedulePeriod);idx++)
  3539. {
  3540. if(txProfile.ChargingSchedule.ChargingSchedulePeriod[idx].Limit != -1)
  3541. limitTx = idx+1;
  3542. }
  3543. // TxProfile found, composite schedule based on it
  3544. if(txProfile.ChargingProfileId != -1)
  3545. {
  3546. compositeProfile.ChargingSchedule.Duration = txProfile.ChargingSchedule.Duration;
  3547. for(int idxTxPeriod=0;idxTxPeriod<limitTx;idxTxPeriod++)
  3548. {
  3549. if((txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod].Limit != -1) &&
  3550. (txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod].StartPeriod < durationReq) &&
  3551. (txProfile.ChargingSchedule.Duration > 0))
  3552. {
  3553. if(maxProfile.ChargingProfileId != -1)
  3554. {
  3555. for(int idxMaxPeriod=0;idxMaxPeriod<limitMax;idxMaxPeriod++)
  3556. {
  3557. if((txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod].StartPeriod >= maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].StartPeriod))
  3558. {
  3559. if((maxProfile.ChargingSchedule.Duration > 0))
  3560. {
  3561. tmpPeriod.StartPeriod = txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod].StartPeriod;
  3562. tmpPeriod.NumberPhases = txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod].NumberPhases;
  3563. tmpPeriod.Limit = (txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod].Limit>maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].Limit?maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].Limit:txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod].Limit);
  3564. }
  3565. else
  3566. {
  3567. tmpPeriod.StartPeriod = txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod].StartPeriod;
  3568. tmpPeriod.NumberPhases = txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod].NumberPhases;
  3569. tmpPeriod.Limit = txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod].Limit;
  3570. }
  3571. }
  3572. if(idxMaxPeriod == (limitMax-1))
  3573. {
  3574. if(tmpPeriod.Limit != compositeProfile.ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].Limit)
  3575. {
  3576. if(tmpPeriod.StartPeriod != compositeProfile.ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].StartPeriod)
  3577. {
  3578. memcpy(&compositeProfile.ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx], &tmpPeriod , sizeof(struct StructChargingSchedulePeriod));
  3579. compositePeriodIdx++;
  3580. }
  3581. else
  3582. {
  3583. memcpy(&compositeProfile.ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)], &tmpPeriod , sizeof(struct StructChargingSchedulePeriod));
  3584. }
  3585. }
  3586. }
  3587. }
  3588. }
  3589. else
  3590. {
  3591. if(txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod].StartPeriod != compositeProfile.ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].StartPeriod)
  3592. {
  3593. memcpy(&compositeProfile.ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx], &txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod],sizeof(struct StructChargingSchedulePeriod));
  3594. compositePeriodIdx++;
  3595. }
  3596. else
  3597. {
  3598. memcpy(&compositeProfile.ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)], &txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod],sizeof(struct StructChargingSchedulePeriod));
  3599. }
  3600. }
  3601. }
  3602. if(idxTxPeriod == (limitTx-1))
  3603. {
  3604. if(defaultTxProfile.ChargingProfileId != -1)
  3605. {
  3606. compositeProfile.ChargingSchedule.Duration = (defaultTxProfile.ChargingSchedule.Duration>compositeProfile.ChargingSchedule.Duration)?defaultTxProfile.ChargingSchedule.Duration:compositeProfile.ChargingSchedule.Duration;
  3607. for(int idxDefPeriod=0;idxDefPeriod<limitDef;idxDefPeriod++)
  3608. {
  3609. if((defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].StartPeriod >= (txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod].StartPeriod + (txProfile.ChargingSchedule.Duration-defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].StartPeriod))) &&
  3610. (defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].StartPeriod < durationReq) &&
  3611. (defaultTxProfile.ChargingSchedule.Duration>0))
  3612. {
  3613. if(maxProfile.ChargingProfileId != -1)
  3614. {
  3615. for(int idxMaxPeriod=0;idxMaxPeriod<limitMax;idxMaxPeriod++)
  3616. {
  3617. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].StartPeriod >= maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].StartPeriod)
  3618. {
  3619. if((maxProfile.ChargingSchedule.Duration > 0))
  3620. {
  3621. tmpPeriod.StartPeriod = defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].StartPeriod;
  3622. tmpPeriod.NumberPhases = defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].NumberPhases;
  3623. tmpPeriod.Limit = (defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].Limit>maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].Limit?maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].Limit:defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod].Limit);
  3624. }
  3625. else
  3626. {
  3627. tmpPeriod.StartPeriod = defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].StartPeriod;
  3628. tmpPeriod.NumberPhases = defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].NumberPhases;
  3629. tmpPeriod.Limit = defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].Limit;
  3630. }
  3631. if(tmpPeriod.Limit != compositeProfile.ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].Limit)
  3632. {
  3633. if(tmpPeriod.StartPeriod != compositeProfile.ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].StartPeriod)
  3634. {
  3635. memcpy(&compositeProfile.ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx], &tmpPeriod , sizeof(struct StructChargingSchedulePeriod));
  3636. compositePeriodIdx++;
  3637. }
  3638. else
  3639. {
  3640. memcpy(&compositeProfile.ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)], &tmpPeriod , sizeof(struct StructChargingSchedulePeriod));
  3641. }
  3642. }
  3643. // Delete duplicate period
  3644. if(compositePeriodIdx > 1)
  3645. {
  3646. if(compositeProfile.ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx-1].Limit == compositeProfile.ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx-2].Limit)
  3647. {
  3648. compositeProfile.ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx-1].StartPeriod = -1;
  3649. compositeProfile.ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx-1].Limit = -1;
  3650. compositePeriodIdx -= 1;
  3651. }
  3652. }
  3653. }
  3654. else
  3655. {
  3656. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].StartPeriod != compositeProfile.ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].StartPeriod)
  3657. {
  3658. memcpy(&compositeProfile.ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx], &defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod],sizeof(struct StructChargingSchedulePeriod));
  3659. compositePeriodIdx++;
  3660. }
  3661. else
  3662. {
  3663. memcpy(&compositeProfile.ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)], &defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod],sizeof(struct StructChargingSchedulePeriod));
  3664. }
  3665. break;
  3666. }
  3667. }
  3668. }
  3669. else
  3670. {
  3671. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].StartPeriod != compositeProfile.ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].StartPeriod)
  3672. {
  3673. memcpy(&compositeProfile.ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx], &defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod],sizeof(struct StructChargingSchedulePeriod));
  3674. compositePeriodIdx++;
  3675. }
  3676. else
  3677. {
  3678. memcpy(&compositeProfile.ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)], &defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod],sizeof(struct StructChargingSchedulePeriod));
  3679. }
  3680. }
  3681. }
  3682. }
  3683. }
  3684. }
  3685. }
  3686. }
  3687. // TxProfile not found but defaultTxProfile found, composite schedule based on it
  3688. else if(defaultTxProfile.ChargingProfileId != -1)
  3689. {
  3690. compositeProfile.ChargingSchedule.Duration = defaultTxProfile.ChargingSchedule.Duration;
  3691. for(int idxDefPeriod=0;idxDefPeriod<limitDef;idxDefPeriod++)
  3692. {
  3693. if((defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].Limit != -1) &&
  3694. (defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].StartPeriod < durationReq) &&
  3695. (defaultTxProfile.ChargingSchedule.Duration > 0))
  3696. {
  3697. if(maxProfile.ChargingProfileId != -1)
  3698. {
  3699. for(int idxMaxPeriod=0;idxMaxPeriod<limitMax;idxMaxPeriod++)
  3700. {
  3701. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].StartPeriod >= maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].StartPeriod)
  3702. {
  3703. tmpPeriod.StartPeriod = defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].StartPeriod;
  3704. tmpPeriod.NumberPhases = defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].NumberPhases;
  3705. if((maxProfile.ChargingSchedule.Duration > 0))
  3706. {
  3707. tmpPeriod.Limit = (defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].Limit>maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].Limit?maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].Limit:defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].Limit);
  3708. }
  3709. else
  3710. {
  3711. tmpPeriod.Limit = defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].Limit;
  3712. }
  3713. if(tmpPeriod.Limit != compositeProfile.ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].Limit)
  3714. {
  3715. if(tmpPeriod.StartPeriod != compositeProfile.ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].StartPeriod)
  3716. {
  3717. memcpy(&compositeProfile.ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx], &tmpPeriod , sizeof(struct StructChargingSchedulePeriod));
  3718. compositePeriodIdx++;
  3719. }
  3720. else
  3721. {
  3722. memcpy(&compositeProfile.ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)], &tmpPeriod , sizeof(struct StructChargingSchedulePeriod));
  3723. }
  3724. }
  3725. // Delete duplicate period
  3726. if(compositePeriodIdx > 1)
  3727. {
  3728. if(compositeProfile.ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx-1].Limit == compositeProfile.ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx-2].Limit)
  3729. {
  3730. compositeProfile.ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx-1].StartPeriod = -1;
  3731. compositeProfile.ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx-1].Limit = -1;
  3732. compositePeriodIdx -= 1;
  3733. }
  3734. }
  3735. }
  3736. else
  3737. {
  3738. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].StartPeriod != compositeProfile.ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].StartPeriod)
  3739. {
  3740. memcpy(&compositeProfile.ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx], &defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod],sizeof(struct StructChargingSchedulePeriod));
  3741. compositePeriodIdx++;
  3742. }
  3743. else
  3744. {
  3745. memcpy(&compositeProfile.ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)], &defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod],sizeof(struct StructChargingSchedulePeriod));
  3746. }
  3747. break;
  3748. }
  3749. }
  3750. }
  3751. else
  3752. {
  3753. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].StartPeriod != compositeProfile.ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].StartPeriod)
  3754. {
  3755. memcpy(&compositeProfile.ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx], &defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod],sizeof(struct StructChargingSchedulePeriod));
  3756. compositePeriodIdx++;
  3757. }
  3758. else
  3759. {
  3760. memcpy(&compositeProfile.ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)], &defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod],sizeof(struct StructChargingSchedulePeriod));
  3761. }
  3762. }
  3763. }
  3764. }
  3765. }
  3766. // Fill other period by MaxProfile
  3767. if(maxProfile.ChargingProfileId != -1)
  3768. {
  3769. if(compositePeriodIdx==0)
  3770. {
  3771. compositeProfile.ChargingSchedule.Duration = maxProfile.ChargingSchedule.Duration;
  3772. for(int idxMaxPeriod=0;idxMaxPeriod<limitDef;idxMaxPeriod++)
  3773. {
  3774. if((maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].Limit != -1) &&
  3775. (maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].StartPeriod < durationReq) &&
  3776. (maxProfile.ChargingSchedule.Duration > 0))
  3777. {
  3778. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].StartPeriod != compositeProfile.ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].StartPeriod)
  3779. {
  3780. memcpy(&compositeProfile.ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx], &maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod],sizeof(struct StructChargingSchedulePeriod));
  3781. compositePeriodIdx++;
  3782. }
  3783. else
  3784. {
  3785. memcpy(&compositeProfile.ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)], &maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod],sizeof(struct StructChargingSchedulePeriod));
  3786. }
  3787. }
  3788. }
  3789. }
  3790. else
  3791. {
  3792. int lastCompositePeriodIdx = compositePeriodIdx;
  3793. for(int idxMaxPeriod=0;idxMaxPeriod<limitMax;idxMaxPeriod++)
  3794. {
  3795. if((maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].Limit != -1) &&
  3796. (maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].StartPeriod < durationReq) &&
  3797. (maxProfile.ChargingSchedule.Duration > 0))
  3798. {
  3799. if((maxProfile.ChargingSchedule.Duration >= compositeProfile.ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx-1].StartPeriod))
  3800. {
  3801. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].Limit > compositeProfile.ChargingSchedule.ChargingSchedulePeriod[lastCompositePeriodIdx-1].Limit)
  3802. {
  3803. tmpPeriod.StartPeriod = maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].StartPeriod;
  3804. tmpPeriod.NumberPhases = maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].NumberPhases;
  3805. tmpPeriod.Limit = compositeProfile.ChargingSchedule.ChargingSchedulePeriod[lastCompositePeriodIdx-1].Limit;
  3806. }
  3807. else
  3808. {
  3809. tmpPeriod.StartPeriod = maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].StartPeriod;
  3810. tmpPeriod.NumberPhases = maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].NumberPhases;
  3811. tmpPeriod.Limit = maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].Limit;
  3812. }
  3813. }
  3814. if(tmpPeriod.Limit != -1)
  3815. {
  3816. if(tmpPeriod.Limit != compositeProfile.ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx-1].Limit)
  3817. {
  3818. if(tmpPeriod.StartPeriod != compositeProfile.ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx-1].StartPeriod)
  3819. {
  3820. memcpy(&compositeProfile.ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx], &tmpPeriod , sizeof(struct StructChargingSchedulePeriod));
  3821. compositePeriodIdx++;
  3822. }
  3823. else
  3824. {
  3825. memcpy(&compositeProfile.ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx-1], &tmpPeriod , sizeof(struct StructChargingSchedulePeriod));
  3826. }
  3827. }
  3828. // Delete duplicate period
  3829. if(compositePeriodIdx > 1)
  3830. {
  3831. if(compositeProfile.ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx-1].Limit == compositeProfile.ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx-2].Limit)
  3832. {
  3833. compositeProfile.ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx-1].StartPeriod = -1;
  3834. compositeProfile.ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx-1].Limit = -1;
  3835. compositePeriodIdx -= 1;
  3836. }
  3837. }
  3838. }
  3839. }
  3840. }
  3841. }
  3842. }
  3843. compositeProfile.ChargingSchedule.Duration = durationReq;
  3844. DEBUG_INFO("Connector-%d composite schedule ready.\n", connectorId);
  3845. DEBUG_INFO("Schedule start: %s\n", compositeProfile.ChargingSchedule.StartSchedule);
  3846. DEBUG_INFO("Schedule duration: %d\n", compositeProfile.ChargingSchedule.Duration);
  3847. DEBUG_INFO("Rate unit: %s\n", compositeProfile.ChargingSchedule.ChargingRateUnit);
  3848. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(compositeProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  3849. {
  3850. if(compositeProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod >= 0)
  3851. {
  3852. compositeProfile.ChargingProfileId = 1;
  3853. DEBUG_INFO("Period-%02d startPeriod: %d\n", idxPeriod, compositeProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod);
  3854. DEBUG_INFO("Period-%02d limit: %f\n", idxPeriod, compositeProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit);
  3855. DEBUG_INFO("Period-%02d NumberPhases: %d\n", idxPeriod, compositeProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases);
  3856. }
  3857. if(compositeProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit == -1)
  3858. compositeProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit =0;
  3859. if(compositeProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod == -1)
  3860. compositeProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod =0;
  3861. }
  3862. memcpy(targetCompositeProfile, &compositeProfile, sizeof(struct StructChargingProfile));
  3863. if(line)
  3864. free(line);
  3865. checkChargePointMaxProfile(durationReq, &ShmOCPP16Data->MaxChargingProfile, isUnitA);
  3866. ShmOCPP16Data->CSUMsg.bits[(connectorId==0?0:connectorId-1)].ChargingProfileConf = 1;
  3867. }
  3868. //==========================================
  3869. // Init all share memory
  3870. //==========================================
  3871. int InitShareMemory()
  3872. {
  3873. int result = PASS;
  3874. int MeterSMId;
  3875. //creat ShmSysConfigAndInfo
  3876. if ((MeterSMId = shmget(ShmSysConfigAndInfoKey, sizeof(struct SysConfigAndInfo), 0777)) < 0)
  3877. {
  3878. DEBUG_ERROR("shmget ShmSysConfigAndInfo NG\n");
  3879. result = FAIL;
  3880. }
  3881. else if ((ShmSysConfigAndInfo = shmat(MeterSMId, NULL, 0)) == (void *) -1)
  3882. {
  3883. DEBUG_ERROR("shmat ShmSysConfigAndInfo NG\n");
  3884. result = FAIL;
  3885. }
  3886. else
  3887. {}
  3888. if ((MeterSMId = shmget(ShmStatusCodeKey, sizeof(struct StatusCodeData), 0777)) < 0)
  3889. {
  3890. DEBUG_ERROR("shmget ShmStatusCodeData NG\n");
  3891. result = FAIL;
  3892. }
  3893. else if ((ShmStatusCodeData = shmat(MeterSMId, NULL, 0)) == (void *) -1)
  3894. {
  3895. DEBUG_ERROR("shmat ShmStatusCodeData NG\n");
  3896. result = FAIL;
  3897. }
  3898. else
  3899. {}
  3900. //creat ShmPsuData
  3901. if ((MeterSMId = shmget(ShmPsuKey, sizeof(struct PsuData), 0777)) < 0)
  3902. {
  3903. DEBUG_ERROR("shmget ShmPsuData NG\n");
  3904. result = FAIL;
  3905. }
  3906. else if ((ShmPsuData = shmat(MeterSMId, NULL, 0)) == (void *) -1)
  3907. {
  3908. DEBUG_ERROR("shmat ShmPsuData NG\n");
  3909. result = FAIL;
  3910. }
  3911. else
  3912. {}
  3913. //creat ShmOCPP16Data
  3914. if ((MeterSMId = shmget(ShmOcppModuleKey, sizeof(struct OCPP16Data), 0777)) < 0)
  3915. {
  3916. DEBUG_ERROR("shmget ShmOCPP16Data NG\n");
  3917. result = FAIL;
  3918. }
  3919. else if ((ShmOCPP16Data = shmat(MeterSMId, NULL, 0)) == (void *) -1)
  3920. {
  3921. DEBUG_ERROR("shmat ShmOCPP16Data NG\n");
  3922. result = FAIL;
  3923. }
  3924. else
  3925. {}
  3926. /****************************** For Initial Settings************************************************/
  3927. ShmOCPP16Data->GetConfiguration.ResponseUnknownKey = NULL;
  3928. ShmOCPP16Data->SendLocalList.LocalAuthorizationList = NULL;
  3929. // allocate Configuration memory address
  3930. ShmOCPP16Data->GetConfiguration.Key = staticKeyArray;
  3931. ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey = staticResponseConfigurationKeyArray;
  3932. ShmOCPP16Data->GetConfiguration.ResponseUnknownKey = staticResponseUnknownKey;
  3933. ShmOCPP16Data->SendLocalList.LocalAuthorizationList = staticLocalAuthorizationList;
  3934. sprintf((char*)ShmOCPP16Data->FirmwareStatusNotification.Status, "%s",FirmwareStatusStr[FirmwareStatus_Idle]);
  3935. //offline MeterValue Interval
  3936. TempMeterValueInterval = 0;
  3937. return result;
  3938. }
  3939. int ProcessShareMemory()
  3940. {
  3941. int result = PASS;
  3942. if(InitShareMemory() == FAIL)
  3943. {
  3944. DEBUG_ERROR("InitShareMemory NG\n");
  3945. if(ShmStatusCodeData!=NULL)
  3946. {
  3947. ShmStatusCodeData->AlarmCode.AlarmEvents.bits.FailToCreateShareMemory=1;
  3948. }
  3949. result = FAIL;
  3950. }
  3951. // Model name parsing
  3952. if(RatedCurrentParsing((char*)ShmSysConfigAndInfo->SysConfig.ModelName, &modelnameInfo) != -1)
  3953. {
  3954. DEBUG_INFO("Model name rated power: %d\n", modelnameInfo.ratedPower);
  3955. if((ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D') &&
  3956. ((ShmSysConfigAndInfo->SysConfig.ModelName[1]=='B') ||
  3957. (ShmSysConfigAndInfo->SysConfig.ModelName[1]=='K') ||
  3958. (ShmSysConfigAndInfo->SysConfig.ModelName[1]=='O'))
  3959. ) // 'D' means DC
  3960. {
  3961. // DO series
  3962. for(int gun_index=0; gun_index<GENERAL_GUN_QUANTITY ; gun_index++)
  3963. {
  3964. gunTotalNumber += 1;
  3965. gunType[gun_index] = GUN_TYPE_DO;
  3966. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  3967. {
  3968. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == gun_index)
  3969. {
  3970. periousPeriodicPowerConsumption[gun_index] = ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PowerConsumption;
  3971. periousClockPowerConsumption[gun_index] = ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PowerConsumption;
  3972. DEBUG_INFO("Gun-%02d PowerConsumption: %.3f\n", gun_index, ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PowerConsumption);
  3973. }
  3974. }
  3975. switch(modelnameInfo.ParsingInfo[gun_index].GunType)
  3976. {
  3977. case Gun_Type_Chademo:
  3978. DEBUG_INFO("Gun-%02d type: Cabinet CHAdeMO\n", gun_index);
  3979. break;
  3980. case Gun_Type_CCS_2:
  3981. DEBUG_INFO("Gun-%02d type: Cabinet CCS\n", gun_index);
  3982. break;
  3983. case Gun_Type_GB:
  3984. DEBUG_INFO("Gun-%02d type: Cabinet GBT\n", gun_index);
  3985. break;
  3986. case Gun_Type_AC:
  3987. DEBUG_INFO("Gun-%02d type: Cabinet AC\n", gun_index);
  3988. break;
  3989. default:
  3990. DEBUG_WARN("Gun-%02d type: Cabinet unknown\n", gun_index);
  3991. break;
  3992. }
  3993. }
  3994. }
  3995. else
  3996. {
  3997. for(int gun_index=0;gun_index<modelnameInfo.GetGunCount;gun_index++)
  3998. {
  3999. gunTotalNumber += 1;
  4000. switch(modelnameInfo.ParsingInfo[gun_index].GunType)
  4001. {
  4002. case Gun_Type_Chademo:
  4003. gunType[gun_index] = GUN_TYPE_CHAdeMO;
  4004. DEBUG_INFO("Gun-%02d type: CHAdeMO\n", gun_index);
  4005. for(int index = 0; index < CHAdeMO_QUANTITY; index++)
  4006. {
  4007. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == gun_index)
  4008. {
  4009. periousPeriodicPowerConsumption[gun_index] = ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PowerConsumption;
  4010. periousClockPowerConsumption[gun_index] = ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PowerConsumption;
  4011. DEBUG_INFO("Gun-%02d PowerConsumption: %.3f\n", gun_index, ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PowerConsumption);
  4012. }
  4013. }
  4014. break;
  4015. case Gun_Type_CCS_2:
  4016. gunType[gun_index] = GUN_TYPE_CCS;
  4017. DEBUG_INFO("Gun-%02d type: CCS\n", gun_index);
  4018. for (int index = 0; index < CCS_QUANTITY; index++)
  4019. {
  4020. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == gun_index)
  4021. {
  4022. periousPeriodicPowerConsumption[gun_index] = ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PowerConsumption;
  4023. periousClockPowerConsumption[gun_index] = ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PowerConsumption;
  4024. DEBUG_INFO("Gun-%02d PowerConsumption: %.3f\n", gun_index, ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PowerConsumption);
  4025. }
  4026. }
  4027. break;
  4028. case Gun_Type_GB:
  4029. gunType[gun_index] = GUN_TYPE_GBT;
  4030. DEBUG_INFO("Gun-%02d type: GBT\n", gun_index);
  4031. for (int index = 0; index < GB_QUANTITY; index++)
  4032. {
  4033. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == gun_index)
  4034. {
  4035. periousPeriodicPowerConsumption[gun_index] = ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PowerConsumption;
  4036. periousClockPowerConsumption[gun_index] = ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PowerConsumption;
  4037. DEBUG_INFO("Gun-%02d PowerConsumption: %.3f\n", gun_index, ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PowerConsumption);
  4038. }
  4039. }
  4040. break;
  4041. case Gun_Type_AC:
  4042. gunType[gun_index] = GUN_TYPE_AC;
  4043. DEBUG_INFO("Gun-%02d type: AC\n", gun_index);
  4044. for (int index = 0; index < AC_QUANTITY; index++)
  4045. {
  4046. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == gun_index)
  4047. {
  4048. periousPeriodicPowerConsumption[gun_index] = ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PowerConsumption;
  4049. periousClockPowerConsumption[gun_index] = ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PowerConsumption;
  4050. DEBUG_INFO("Gun-%02d PowerConsumption: %.3f\n", gun_index, ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PowerConsumption);
  4051. }
  4052. }
  4053. break;
  4054. default:
  4055. DEBUG_WARN("Gun-%02d type: Unknown\n", gun_index);
  4056. break;
  4057. }
  4058. }
  4059. }
  4060. }
  4061. else
  4062. {
  4063. DEBUG_ERROR("Model name parsing fail.\n");
  4064. result = FAIL;
  4065. }
  4066. if(result != PASS)sleep(5);
  4067. return result;
  4068. }
  4069. void checkRemoteStart(uint8_t connectorIdInt)
  4070. {
  4071. uint8_t tempIndex;
  4072. int result = PASS;
  4073. char cmdBuf[512];
  4074. //check Transaction active
  4075. if(gunType[connectorIdInt -1] == GUN_TYPE_CHAdeMO)
  4076. {
  4077. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4078. {
  4079. tempIndex = ((connectorIdInt -1) == 2) ? 1: 0;
  4080. }
  4081. else
  4082. {
  4083. tempIndex = connectorIdInt -1;
  4084. }
  4085. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  4086. {
  4087. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  4088. {
  4089. if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ReservationId != -1) &&
  4090. (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ReservationId >= 0) &&
  4091. (strcmp((const char *)ShmOCPP16Data->ReserveNow[index].IdTag, (char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag) == 0))
  4092. {
  4093. //Reserved
  4094. DEBUG_INFO("CHAdeMO connector already reserved and idTag match.\n");
  4095. }
  4096. else if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ReservationId != -1) &&
  4097. (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ReservationId >= 0) &&
  4098. (strcmp((const char *)ShmOCPP16Data->ReserveNow[index].IdTag, (char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag) != 0))
  4099. {
  4100. //Reserved
  4101. DEBUG_INFO("CHAdeMO connector already reserved and idTag does not match.\n");
  4102. result = FAIL;
  4103. goto end;
  4104. }
  4105. else
  4106. {
  4107. if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  4108. && (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_PREPARING ) //S_PRECHARGE
  4109. && (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EV ) //S_PREPARING_FOR_EV
  4110. && (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EVSE )) // S_PREPARING_FOR_EVSE
  4111. {
  4112. DEBUG_WARN("CHAdeMO connector not allow start cause busy.\n");
  4113. result = FAIL;
  4114. goto end;
  4115. }
  4116. }//END FOR ELSE
  4117. }
  4118. }// END FOR CHAdeMO_QUANTITY
  4119. }
  4120. else if(gunType[connectorIdInt -1] == GUN_TYPE_CCS)
  4121. {
  4122. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4123. {
  4124. tempIndex = ((connectorIdInt -1) == 2) ? 1: 0;
  4125. }
  4126. else
  4127. {
  4128. tempIndex = connectorIdInt -1;
  4129. }
  4130. for (int index = 0; index < CCS_QUANTITY; index++)
  4131. {
  4132. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  4133. {
  4134. if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ReservationId != -1) &&
  4135. (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ReservationId >= 0) &&
  4136. (strcmp((const char *)ShmOCPP16Data->ReserveNow[index].IdTag, (char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag) == 0))
  4137. {
  4138. //Reserved
  4139. DEBUG_INFO("CCS connector already reserved and idTag match.\n");
  4140. }
  4141. else if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ReservationId != -1) &&
  4142. (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ReservationId >= 0) &&
  4143. (strcmp((const char *)ShmOCPP16Data->ReserveNow[index].IdTag, (char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag) != 0))
  4144. {
  4145. //Reserved
  4146. DEBUG_INFO("CCS connector already reserved and idTag does not match.\n");
  4147. result = FAIL;
  4148. goto end;
  4149. }
  4150. else
  4151. {
  4152. if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  4153. && (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_PREPARING) //S_PRECHARGE
  4154. && (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EV) //S_PREPARING_FOR_EV
  4155. && (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EVSE)) // S_PREPARING_FOR_EVSE
  4156. {
  4157. DEBUG_WARN("CCS connector not allow start cause busy.\n.");
  4158. result = FAIL;
  4159. goto end;
  4160. }
  4161. }// END FOR ELSE
  4162. }
  4163. }// END FOR CCS_QUANTITY
  4164. }
  4165. else if(gunType[connectorIdInt -1] == GUN_TYPE_GBT)
  4166. {
  4167. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4168. {
  4169. tempIndex = ((connectorIdInt -1) == 2) ? 1: 0;
  4170. }
  4171. else
  4172. {
  4173. tempIndex = connectorIdInt -1;
  4174. }
  4175. for (int index = 0; index < GB_QUANTITY; index++)
  4176. {
  4177. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex )
  4178. {
  4179. if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ReservationId != -1) &&
  4180. (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ReservationId >= 0) &&
  4181. (strcmp((const char *)ShmOCPP16Data->ReserveNow[index].IdTag, (char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag) == 0))
  4182. {
  4183. //Reserved
  4184. DEBUG_INFO("GBT connector already reserved and idTag match.\n");
  4185. }
  4186. else if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ReservationId != -1) &&
  4187. (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ReservationId >= 0) &&
  4188. (strcmp((const char *)ShmOCPP16Data->ReserveNow[index].IdTag, (char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag) != 0))
  4189. {
  4190. //Reserved
  4191. DEBUG_INFO("GBT connector already reserved and idTag does not match.\n");
  4192. result = FAIL;
  4193. goto end;
  4194. }
  4195. else
  4196. {
  4197. if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  4198. && (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_PREPARING) //S_PRECHARGE
  4199. && (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EV) //S_PREPARING_FOR_EV
  4200. && (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EVSE)) // S_PREPARING_FOR_EVSE
  4201. {
  4202. DEBUG_WARN("GBT connector not allow start cause busy.\n");
  4203. result = FAIL;
  4204. goto end;
  4205. }
  4206. }// END FOR ELSE
  4207. }
  4208. } // END FOR GB_QUANTITY
  4209. }
  4210. else if(gunType[connectorIdInt -1] == GUN_TYPE_DO)
  4211. {
  4212. tempIndex = connectorIdInt -1;
  4213. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  4214. {
  4215. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex )
  4216. {
  4217. if((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.ReservationId != -1) &&
  4218. (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.ReservationId >= 0) &&
  4219. (strcmp((const char *)ShmOCPP16Data->ReserveNow[index].IdTag, (char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag) == 0))
  4220. {
  4221. //Reserved
  4222. DEBUG_INFO("Dispenser connector already reserved and idTag match.\n");
  4223. }
  4224. else if((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.ReservationId != -1) &&
  4225. (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.ReservationId >= 0) &&
  4226. (strcmp((const char *)ShmOCPP16Data->ReserveNow[index].IdTag, (char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag) != 0))
  4227. {
  4228. //Reserved
  4229. DEBUG_INFO("Dispenser connector already reserved and idTag does not match.\n");
  4230. result = FAIL;
  4231. goto end;
  4232. }
  4233. else
  4234. {
  4235. if((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus != SYS_MODE_IDLE) //S_IDLE
  4236. && (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus != SYS_MODE_PREPARING) //S_PRECHARGE
  4237. && (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus != SYS_MODE_PREPARE_FOR_EV) //S_PREPARING_FOR_EV
  4238. && (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus != SYS_MODE_PREPARE_FOR_EVSE)) // S_PREPARING_FOR_EVSE
  4239. {
  4240. DEBUG_WARN("Dispenser connector not allow start cause busy.\n");
  4241. result = FAIL;
  4242. goto end;
  4243. }
  4244. }// END FOR ELSE
  4245. }
  4246. } // END FOR GB_QUANTITY
  4247. }
  4248. else
  4249. {
  4250. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D') // 'D' means DC
  4251. {
  4252. tempIndex = 2;
  4253. }
  4254. else
  4255. {
  4256. tempIndex = connectorIdInt -1;
  4257. }
  4258. for (int index = 0; index < AC_QUANTITY; index++)
  4259. {
  4260. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex )
  4261. {
  4262. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].ReservationId != -1) &&
  4263. (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].ReservationId >= 0) &&
  4264. (strcmp((const char *)ShmOCPP16Data->ReserveNow[index].IdTag, (char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag) == 0))
  4265. {
  4266. //Reserved
  4267. DEBUG_INFO("AC connector already reserved and idTag match.\n");
  4268. }
  4269. else if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].ReservationId != -1) &&
  4270. (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].ReservationId >= 0) &&
  4271. (strcmp((const char *)ShmOCPP16Data->ReserveNow[index].IdTag, (char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag) != 0))
  4272. {
  4273. //Reserved
  4274. DEBUG_INFO("AC connector already reserved and idTag does not match.\n");
  4275. result = FAIL;
  4276. goto end;
  4277. }
  4278. else
  4279. {
  4280. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  4281. && (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_PREPARING) //S_PRECHARGE
  4282. && (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EV) //S_PREPARING_FOR_EV
  4283. && (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EVSE)) // S_PREPARING_FOR_EVSE
  4284. {
  4285. DEBUG_WARN("AC connector not allow start cause busy.\n");
  4286. result = FAIL;
  4287. goto end;
  4288. }
  4289. }//END FOR ELSE
  4290. }
  4291. }// END FOR AC_QUANTITY
  4292. }
  4293. if(ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingProfileId > -1)
  4294. {
  4295. if(strcmp((char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingProfilePurpose, ChargingProfilePurposeTypeStr[TxProfile]) == 0)
  4296. {
  4297. if((access("/Storage/OCPP/TxProfile_Tmp.json", F_OK))!=-1)
  4298. {
  4299. sprintf(cmdBuf, "mv /Storage/OCPP/TxProfile_Tmp.json /Storage/OCPP/TxProfile_%d.json", connectorIdInt);
  4300. system(cmdBuf);
  4301. }
  4302. }
  4303. else
  4304. {
  4305. DEBUG_WARN("Profile purpose not TxProfile.\n.");
  4306. result = FAIL;
  4307. }
  4308. }
  4309. end:
  4310. if(result == PASS)
  4311. {
  4312. ShmOCPP16Data->CsMsg.bits[connectorIdInt -1].RemoteStartTransactionReq = 1;
  4313. memset((char *)ShmOCPP16Data->StartTransaction[connectorIdInt -1].IdTag, 0, 20);
  4314. strcpy((char *)ShmOCPP16Data->StartTransaction[connectorIdInt -1].IdTag, (char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag);
  4315. memset((char *)ShmOCPP16Data->StopTransaction[connectorIdInt -1].IdTag, 0, 20);
  4316. strcpy((char *)ShmOCPP16Data->StopTransaction[connectorIdInt -1].IdTag, (char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag);
  4317. }
  4318. }
  4319. void CheckSystemValue(void)
  4320. {
  4321. char filenmae[100]={0};
  4322. char str[100]={0};
  4323. int tempIndex = 0;
  4324. //===============================
  4325. // send Heartbeat
  4326. //===============================
  4327. if((server_sign == TRUE) && (getDiffSecNow(clientTime.Heartbeat) >= (HeartBeatWaitTime + HeartBeatWithNOResponse)))
  4328. {
  4329. //parameter for test
  4330. sendHeartbeatRequest(0);
  4331. //===========================
  4332. // Reset Waiting Time
  4333. //===========================
  4334. HeartBeatWithNOResponse += 1;
  4335. }
  4336. //===============================
  4337. // Credit deduct report
  4338. //===============================
  4339. if(ShmOCPP16Data->TcciCustomData.ReportCreditDeductReq)
  4340. {
  4341. OCPP_insert_deduct_info(ShmOCPP16Data->TcciCustomData.DeductInfo.txId, (char*)ShmOCPP16Data->TcciCustomData.DeductInfo.creditNo,
  4342. ShmOCPP16Data->TcciCustomData.DeductInfo.deductResult, ShmOCPP16Data->TcciCustomData.DeductInfo.isDonateInvoice,
  4343. ShmOCPP16Data->TcciCustomData.DeductInfo.amount, (char*)ShmOCPP16Data->TcciCustomData.DeductInfo.vemData,
  4344. (char*)ShmOCPP16Data->TcciCustomData.DeductInfo.ROC,(char*)ShmOCPP16Data->TcciCustomData.DeductInfo.RRN,
  4345. (char*)ShmOCPP16Data->TcciCustomData.DeductInfo.approvalNo,(char*)ShmOCPP16Data->TcciCustomData.DeductInfo.storeId);
  4346. ShmOCPP16Data->TcciCustomData.ReportCreditDeductReq = FALSE;
  4347. }
  4348. if(getDiffSecNow(clientTime.TcciQueryDeduct) > 5)
  4349. {
  4350. OCPP_query_deduct_info();
  4351. refreshStartTimer(&clientTime.TcciQueryDeduct);
  4352. }
  4353. for(int gun_index=0;gun_index < gunTotalNumber;gun_index++)
  4354. {
  4355. // ClockAlign MeterValue
  4356. if((server_sign == TRUE) && ((atoi((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemData) > 0)?((getTimePassSinceToday(gun_index)%(atoi((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemData)))==0):FALSE))
  4357. {
  4358. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  4359. {
  4360. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4361. {
  4362. tempIndex = ((gun_index==2) ? 1: 0);
  4363. }
  4364. else
  4365. {
  4366. tempIndex = gun_index;
  4367. }
  4368. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  4369. {
  4370. // 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault
  4371. if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  4372. {
  4373. reqClockAlignMeter[gun_index] = 1;
  4374. }
  4375. }// End for CHAdeMO
  4376. }
  4377. else if(gunType[gun_index] == GUN_TYPE_CCS)
  4378. {
  4379. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4380. {
  4381. tempIndex = ((gun_index==2) ? 1: 0);
  4382. }
  4383. else
  4384. {
  4385. tempIndex = gun_index;
  4386. }
  4387. for (int index = 0; index < CCS_QUANTITY; index++)
  4388. {
  4389. // 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault
  4390. if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  4391. {
  4392. reqClockAlignMeter[gun_index] = 1;
  4393. }
  4394. } // End for CCS
  4395. }
  4396. else if(gunType[gun_index] == GUN_TYPE_GBT)
  4397. {
  4398. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4399. {
  4400. tempIndex = ((gun_index==2) ? 1: 0);
  4401. }
  4402. else
  4403. {
  4404. tempIndex = gun_index;
  4405. }
  4406. for (int index = 0; index < GB_QUANTITY; index++)
  4407. {
  4408. // 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault
  4409. if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  4410. {
  4411. reqClockAlignMeter[gun_index] = 1;
  4412. }
  4413. }// End for GB
  4414. }
  4415. else if(gunType[gun_index] == GUN_TYPE_DO)
  4416. {
  4417. tempIndex = gun_index;
  4418. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  4419. {
  4420. // 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault
  4421. if(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  4422. {
  4423. reqClockAlignMeter[gun_index] = 1;
  4424. }
  4425. }
  4426. }
  4427. else
  4428. {
  4429. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  4430. {
  4431. tempIndex = 2;
  4432. }
  4433. else
  4434. {
  4435. tempIndex = gun_index;
  4436. }
  4437. for (int index = 0; index < AC_QUANTITY; index++)
  4438. {
  4439. // 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault
  4440. if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  4441. {
  4442. reqClockAlignMeter[gun_index] = 1;
  4443. }
  4444. }//End for AC
  4445. }
  4446. }
  4447. }
  4448. for(int gun_index=0;gun_index < gunTotalNumber ;gun_index++)
  4449. {
  4450. //==========================================
  4451. // Check remote start without connector id
  4452. //==========================================
  4453. if(ShmOCPP16Data->MsMsg.bits.isRemoteStartWaitReq)
  4454. {
  4455. int connectorIdInt = -1;
  4456. for(uint8_t gun_index=0;gun_index<gunTotalNumber;gun_index++)
  4457. {
  4458. if(!cpinitateMsg.bits[gun_index].isOnCharging && (strstr((char*)ShmOCPP16Data->StatusNotification[gun_index].Status, "Preparing") != NULL))
  4459. {
  4460. connectorIdInt = (gun_index+1);
  4461. DEBUG_INFO("Detect connector-%02d connected ready to start.\n", connectorIdInt);
  4462. checkRemoteStart(connectorIdInt);
  4463. ShmOCPP16Data->MsMsg.bits.isRemoteStartWaitReq = 0;
  4464. break;
  4465. }
  4466. }
  4467. if(getDiffSecNow(clientTime.RemoteStartWait) > atoi((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemData))
  4468. {
  4469. DEBUG_WARN("Remote start request without connector id wait link over %s seconds.\n", ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemData);
  4470. ShmOCPP16Data->MsMsg.bits.isRemoteStartWaitReq = 0;
  4471. }
  4472. }
  4473. //==========================================
  4474. // csu trigger DataTransferReq
  4475. //==========================================
  4476. if(isWebsocketSendable && (server_sign == TRUE) && (ShmOCPP16Data->CsMsg.bits[gun_index].DataTransferReq == 1))
  4477. {
  4478. sendDataTransferRequest(gun_index);
  4479. ShmOCPP16Data->CsMsg.bits[gun_index].DataTransferReq = 0;
  4480. }
  4481. //==========================================
  4482. // CSU Trigger Authorize Request
  4483. //==========================================
  4484. if(isWebsocketSendable && (server_sign == TRUE) && (ShmOCPP16Data->SpMsg.bits.AuthorizeReq == 1)&&(authorizeRetryTimes < 3))
  4485. {
  4486. sendAuthorizeRequest(0);
  4487. authorizeRetryTimes = authorizeRetryTimes + 1;
  4488. if(authorizeRetryTimes < 3)
  4489. ShmOCPP16Data->SpMsg.bits.AuthorizeReq = 0;
  4490. }
  4491. else if((server_sign == TRUE) && (ShmOCPP16Data->SpMsg.bits.AuthorizeReq == 1) && (authorizeRetryTimes >= 3))
  4492. {
  4493. authorizeRetryTimes = 0;
  4494. SetOcppConnStatus(FALSE);
  4495. server_sign = FALSE;
  4496. }
  4497. else if((server_sign == FALSE) && (strcmp((const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemData, "TRUE") == 0)&&(strcmp((const char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "TRUE") == 0)&&(ShmOCPP16Data->OcppConnStatus == 0)&& (ShmOCPP16Data->SpMsg.bits.AuthorizeReq == 1))
  4498. {
  4499. sendAuthorizeRequest(0);
  4500. }
  4501. //==========================================
  4502. // Charger start transaction
  4503. //==========================================
  4504. if(/*(server_sign == TRUE) &&*/ (ShmOCPP16Data->CpMsg.bits[gun_index].StartTransactionReq == 1))
  4505. {
  4506. ShmOCPP16Data->CpMsg.bits[gun_index].StartTransactionReq = 0;
  4507. sendStartTransactionRequest(gun_index);
  4508. refreshStartTimer(&clientTime.StartTransaction);
  4509. refreshStartTimer(&clientTime.MeterValues[gun_index]);
  4510. storeTempStopTransaction(gun_index);
  4511. }
  4512. //==========================================
  4513. // Charger stop transaction
  4514. //==========================================
  4515. if(/*(server_sign == TRUE) &&*/ ((ShmOCPP16Data->CpMsg.bits[gun_index].StopTransactionReq == 1)))
  4516. {
  4517. ShmOCPP16Data->CpMsg.bits[gun_index].StopTransactionReq = 0;
  4518. sendStopTransactionRequest(gun_index);
  4519. OCPP_updatePeriodEnergy(gun_index);
  4520. if(ShmSysConfigAndInfo->SysConfig.TTIA_Info.isEnableTTIA && (gunType[gun_index] != GUN_TYPE_AC) )sendTTIAInfo(gun_index);
  4521. refreshStartTimer(&clientTime.StopTransaction);
  4522. memset(&ShmOCPP16Data->SessionTarget[gun_index], 0x00, sizeof(struct StructSessionTarget));
  4523. }
  4524. //==========================================
  4525. // Charger OCMF message
  4526. //==========================================
  4527. if(/*(server_sign == TRUE) &&*/ ((ShmOCPP16Data->OcmfData[gun_index].SendOcmfDataReq == 1)))
  4528. {
  4529. sendOcmfByDataTransferRequest(gun_index);
  4530. ShmOCPP16Data->OcmfData[gun_index].SendOcmfDataReq = 0;
  4531. }
  4532. //==========================================
  4533. // Charger status report
  4534. //==========================================
  4535. //--- Check Mode Change ---//
  4536. // J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DCcc
  4537. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  4538. {
  4539. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4540. {
  4541. tempIndex = ((gun_index==2) ? 1: 0);
  4542. }
  4543. else
  4544. {
  4545. tempIndex = gun_index;
  4546. }
  4547. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  4548. {
  4549. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  4550. {
  4551. if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != ChademoPreviousSystemStatus[index]) || (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ConnectorPlugIn != ChademoPreviousConnectorPlugIn[index]) )
  4552. {
  4553. // Sent unplug message for California pricing logic
  4554. if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_COMPLETE) && (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ConnectorPlugIn == 0) && !interLock.isSentUnplug[gun_index])
  4555. {
  4556. uint8_t ts[36];
  4557. getNowDatetime(ts);
  4558. sprintf((char*)ShmOCPP16Data->DataTransfer[gun_index].VendorId, "org.openchargealliance.costmsg");
  4559. sprintf((char*)ShmOCPP16Data->DataTransfer[gun_index].MessageId, "ConnectorUnplugged");
  4560. if(strcmp((char*)dmsVersion, "2.0")==0)
  4561. sprintf((char*)ShmOCPP16Data->DataTransfer[gun_index].Data, "{\\\"transactionId\\\":%d,\\\"timestamp\\\":\\\"%s\\\"}", ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId, ts);
  4562. else
  4563. sprintf((char*)ShmOCPP16Data->DataTransfer[gun_index].Data, "{\\\"idTx\\\":%d,\\\"timestamp\\\":\\\"%s\\\"}", ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId, ts);
  4564. sendUnplugByDataTransferRequest(gun_index);
  4565. interLock.isSentUnplug[gun_index] = 1;
  4566. }
  4567. else if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_IDLE))
  4568. {
  4569. interLock.isSentUnplug[gun_index] = 0;
  4570. }
  4571. ChademoPreviousSystemStatus[index] = ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus;
  4572. ChademoPreviousConnectorPlugIn[index] = ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ConnectorPlugIn;
  4573. cpinitateMsg.bits[gun_index].StatusNotificationReq = 1;
  4574. if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex) && ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_COMPLETE) || (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus <= SYS_MODE_IDLE))) // complete
  4575. {
  4576. sprintf(filenmae,"/Storage/OCPP/TxProfile_%d.json",(gun_index+1));
  4577. if((access(filenmae,F_OK))!=-1)
  4578. {
  4579. DEBUG_INFO("TxProfile exist. OCPP will delete TX Charging Profile\n");
  4580. sprintf(str,"rm -f %s",filenmae);
  4581. system(str);
  4582. }
  4583. }
  4584. }
  4585. cpinitateMsg.bits[gun_index].isOnCharging = ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_TERMINATING)?1:0);
  4586. #if 1 // for TempStopTransaction
  4587. if(((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_BOOTING) || (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_IDLE)) &&
  4588. (ShmOCPP16Data->CpMsg.bits[gun_index].StopTransactionReq == 0))
  4589. {
  4590. checkTempStopTransaction(gun_index);
  4591. }
  4592. #endif
  4593. }
  4594. }
  4595. }
  4596. else if(gunType[gun_index] == GUN_TYPE_CCS)
  4597. {
  4598. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4599. {
  4600. tempIndex = ((gun_index==2) ? 1: 0);
  4601. }
  4602. else
  4603. {
  4604. tempIndex = gun_index;
  4605. }
  4606. for (int index = 0; index < CCS_QUANTITY; index++)
  4607. {
  4608. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  4609. {
  4610. if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != CcsPreviousSystemStatus[index]) || (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ConnectorPlugIn != CcsPreviousConnectorPlugIn[index]) )//if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != CcsPreviousSystemStatus[index]/*PRE_SYS_MODE[gun_index]*/ )
  4611. {
  4612. // Sent unplug message for California pricing logic
  4613. if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_COMPLETE) && (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ConnectorPlugIn == 0) && !interLock.isSentUnplug[gun_index])
  4614. {
  4615. uint8_t ts[36];
  4616. getNowDatetime(ts);
  4617. sprintf((char*)ShmOCPP16Data->DataTransfer[gun_index].VendorId, "org.openchargealliance.costmsg");
  4618. sprintf((char*)ShmOCPP16Data->DataTransfer[gun_index].MessageId, "ConnectorUnplugged");
  4619. if(strcmp((char*)dmsVersion, "2.0")==0)
  4620. sprintf((char*)ShmOCPP16Data->DataTransfer[gun_index].Data, "{\\\"transactionId\\\":%d,\\\"timestamp\\\":\\\"%s\\\"}", ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId, ts);
  4621. else
  4622. sprintf((char*)ShmOCPP16Data->DataTransfer[gun_index].Data, "{\\\"idTx\\\":%d,\\\"timestamp\\\":\\\"%s\\\"}", ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId, ts);
  4623. sendUnplugByDataTransferRequest(gun_index);
  4624. interLock.isSentUnplug[gun_index] = 1;
  4625. }
  4626. else if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_IDLE))
  4627. {
  4628. interLock.isSentUnplug[gun_index] = 0;
  4629. }
  4630. CcsPreviousSystemStatus[index] = ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus;
  4631. CcsPreviousConnectorPlugIn[index] = ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ConnectorPlugIn;
  4632. cpinitateMsg.bits[gun_index].StatusNotificationReq = 1;
  4633. if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex) && ((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_COMPLETE) || (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus <= SYS_MODE_IDLE))) // complete
  4634. {
  4635. sprintf(filenmae,"/Storage/OCPP/TxProfile_%d.json",(gun_index+1));
  4636. if((access(filenmae,F_OK))!=-1)
  4637. {
  4638. DEBUG_INFO("TxProfile exist. OCPP will delete TX Charging Profile\n");
  4639. sprintf(str,"rm -f %s",filenmae);
  4640. system(str);
  4641. }
  4642. }
  4643. }
  4644. cpinitateMsg.bits[gun_index].isOnCharging = ((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_TERMINATING)?1:0);
  4645. #if 1 // for TempStopTransaction
  4646. if(((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_BOOTING) || (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_IDLE)) &&
  4647. (ShmOCPP16Data->CpMsg.bits[gun_index].StopTransactionReq == 0))
  4648. {
  4649. checkTempStopTransaction(gun_index);
  4650. }
  4651. #endif
  4652. }
  4653. }
  4654. }
  4655. else if(gunType[gun_index] == GUN_TYPE_GBT)
  4656. {
  4657. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4658. {
  4659. tempIndex = ((gun_index==2) ? 1: 0);
  4660. }
  4661. else
  4662. {
  4663. tempIndex = gun_index;
  4664. }
  4665. for (int index = 0; index < GB_QUANTITY; index++)
  4666. {
  4667. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  4668. {
  4669. if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != GbPreviousSystemStatus[index]) || (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ConnectorPlugIn != GbPreviousConnectorPlugIn[index]) )
  4670. {
  4671. // Sent unplug message for California pricing logic
  4672. if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_COMPLETE) && (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ConnectorPlugIn == 0) && !interLock.isSentUnplug[gun_index])
  4673. {
  4674. uint8_t ts[36];
  4675. getNowDatetime(ts);
  4676. sprintf((char*)ShmOCPP16Data->DataTransfer[gun_index].VendorId, "org.openchargealliance.costmsg");
  4677. sprintf((char*)ShmOCPP16Data->DataTransfer[gun_index].MessageId, "ConnectorUnplugged");
  4678. if(strcmp((char*)dmsVersion, "2.0")==0)
  4679. sprintf((char*)ShmOCPP16Data->DataTransfer[gun_index].Data, "{\\\"transactionId\\\":%d,\\\"timestamp\\\":\\\"%s\\\"}", ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId, ts);
  4680. else
  4681. sprintf((char*)ShmOCPP16Data->DataTransfer[gun_index].Data, "{\\\"idTx\\\":%d,\\\"timestamp\\\":\\\"%s\\\"}", ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId, ts);
  4682. sendUnplugByDataTransferRequest(gun_index);
  4683. interLock.isSentUnplug[gun_index] = 1;
  4684. }
  4685. else if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_IDLE))
  4686. {
  4687. interLock.isSentUnplug[gun_index] = 0;
  4688. }
  4689. GbPreviousSystemStatus[index] = ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus;
  4690. GbPreviousConnectorPlugIn[index] = ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ConnectorPlugIn;
  4691. cpinitateMsg.bits[gun_index].StatusNotificationReq = 1;
  4692. if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex) && ((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_COMPLETE) || (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus <= SYS_MODE_IDLE))) // complete
  4693. {
  4694. sprintf(filenmae,"/Storage/OCPP/TxProfile_%d.json",(gun_index+1));
  4695. if((access(filenmae,F_OK))!=-1)
  4696. {
  4697. DEBUG_INFO("TxProfile exist. OCPP will delete TX Charging Profile\n");
  4698. sprintf(str,"rm -f %s",filenmae);
  4699. system(str);
  4700. }
  4701. }
  4702. }
  4703. cpinitateMsg.bits[gun_index].isOnCharging = ((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_TERMINATING)?1:0);
  4704. #if 1 // for TempStopTransaction
  4705. if(((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_BOOTING) || (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_IDLE)) &&
  4706. (ShmOCPP16Data->CpMsg.bits[gun_index].StopTransactionReq == 0))
  4707. {
  4708. checkTempStopTransaction(gun_index);
  4709. }
  4710. #endif
  4711. }
  4712. }
  4713. }
  4714. else if(gunType[gun_index] == GUN_TYPE_DO)
  4715. {
  4716. tempIndex = gun_index;
  4717. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  4718. {
  4719. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  4720. {
  4721. if((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus != DoPreviousSystemStatus[index]) || (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.ConnectorPlugIn != DoPreviousConnectorPlugIn[index]) )
  4722. {
  4723. // Sent unplug message for California pricing logic
  4724. if((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_COMPLETE) && (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.ConnectorPlugIn == 0) && !interLock.isSentUnplug[gun_index])
  4725. {
  4726. uint8_t ts[36];
  4727. getNowDatetime(ts);
  4728. sprintf((char*)ShmOCPP16Data->DataTransfer[gun_index].VendorId, "org.openchargealliance.costmsg");
  4729. sprintf((char*)ShmOCPP16Data->DataTransfer[gun_index].MessageId, "ConnectorUnplugged");
  4730. if(strcmp((char*)dmsVersion, "2.0")==0)
  4731. sprintf((char*)ShmOCPP16Data->DataTransfer[gun_index].Data, "{\\\"transactionId\\\":%d,\\\"timestamp\\\":\\\"%s\\\"}", ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId, ts);
  4732. else
  4733. sprintf((char*)ShmOCPP16Data->DataTransfer[gun_index].Data, "{\\\"idTx\\\":%d,\\\"timestamp\\\":\\\"%s\\\"}", ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId, ts);
  4734. sendUnplugByDataTransferRequest(gun_index);
  4735. interLock.isSentUnplug[gun_index] = 1;
  4736. }
  4737. else if((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_IDLE))
  4738. {
  4739. interLock.isSentUnplug[gun_index] = 0;
  4740. }
  4741. DoPreviousSystemStatus[index] = ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus;
  4742. DoPreviousConnectorPlugIn[index] = ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.ConnectorPlugIn;
  4743. cpinitateMsg.bits[gun_index].StatusNotificationReq = 1;
  4744. if((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex) && ((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_COMPLETE) || (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus <= SYS_MODE_IDLE))) // complete
  4745. {
  4746. sprintf(filenmae,"/Storage/OCPP/TxProfile_%d.json",(gun_index+1));
  4747. if((access(filenmae,F_OK))!=-1)
  4748. {
  4749. DEBUG_INFO("TxProfile exist. OCPP will delete TX Charging Profile\n");
  4750. sprintf(str,"rm -f %s",filenmae);
  4751. system(str);
  4752. }
  4753. }
  4754. }
  4755. cpinitateMsg.bits[gun_index].isOnCharging = ((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_TERMINATING)?1:0);
  4756. #if 1 // for TempStopTransaction
  4757. if(((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_BOOTING) || (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_IDLE)) &&
  4758. (ShmOCPP16Data->CpMsg.bits[gun_index].StopTransactionReq == 0))
  4759. {
  4760. checkTempStopTransaction(gun_index);
  4761. }
  4762. #endif
  4763. }
  4764. }
  4765. }
  4766. else
  4767. {
  4768. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  4769. {
  4770. tempIndex = 2;
  4771. }
  4772. else
  4773. {
  4774. tempIndex = gun_index;
  4775. }
  4776. for (int index = 0; index < AC_QUANTITY; index++)
  4777. {
  4778. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  4779. {
  4780. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != AcPreviousSystemStatus[index]) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PilotState != AcPreviousConnectorPlugIn[index]) )
  4781. {
  4782. // Sent unplug message for California pricing logic
  4783. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_COMPLETE) && (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PilotState == CP_STATE_A) && !interLock.isSentUnplug[gun_index])
  4784. {
  4785. uint8_t ts[36];
  4786. getNowDatetime(ts);
  4787. sprintf((char*)ShmOCPP16Data->DataTransfer[gun_index].VendorId, "org.openchargealliance.costmsg");
  4788. sprintf((char*)ShmOCPP16Data->DataTransfer[gun_index].MessageId, "ConnectorUnplugged");
  4789. if(strcmp((char*)dmsVersion, "2.0")==0)
  4790. sprintf((char*)ShmOCPP16Data->DataTransfer[gun_index].Data, "{\\\"transactionId\\\":%d,\\\"timestamp\\\":\\\"%s\\\"}", ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId, ts);
  4791. else
  4792. sprintf((char*)ShmOCPP16Data->DataTransfer[gun_index].Data, "{\\\"idTx\\\":%d,\\\"timestamp\\\":\\\"%s\\\"}", ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId, ts);
  4793. sendUnplugByDataTransferRequest(gun_index);
  4794. interLock.isSentUnplug[gun_index] = 1;
  4795. }
  4796. else if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_IDLE))
  4797. {
  4798. interLock.isSentUnplug[gun_index] = 0;
  4799. }
  4800. AcPreviousSystemStatus[index] = ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus;
  4801. AcPreviousConnectorPlugIn[index] = ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PilotState;
  4802. cpinitateMsg.bits[gun_index].StatusNotificationReq = 1;
  4803. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex) && ((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_COMPLETE) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus <= SYS_MODE_IDLE))) // complete
  4804. {
  4805. sprintf(filenmae,"/Storage/OCPP/TxProfile_%d.json",(gun_index+1));
  4806. if((access(filenmae,F_OK))!=-1)
  4807. {
  4808. DEBUG_INFO("TxProfile exist. OCPP will delete TX Charging Profile\n");
  4809. sprintf(str,"rm -f %s",filenmae);
  4810. system(str);
  4811. }
  4812. }
  4813. }
  4814. cpinitateMsg.bits[gun_index].isOnCharging = ((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_TERMINATING)?1:0);
  4815. #if 1 // for TempStopTransaction
  4816. if(((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_BOOTING) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_IDLE)) &&
  4817. (ShmOCPP16Data->CpMsg.bits[gun_index].StopTransactionReq == 0))
  4818. {
  4819. checkTempStopTransaction(gun_index);
  4820. }
  4821. #endif
  4822. }
  4823. }// END
  4824. }
  4825. if(isWebsocketSendable && (server_sign == TRUE) && (getDiffSecNow(clientTime.StatusNotification[gun_index]) >= 1) &&
  4826. (
  4827. (cpinitateMsg.bits[gun_index].StatusNotificationReq == 1) || (cpinitateMsg.bits[gun_index].TriggerStatusNotificationReq == 1) ||
  4828. ((strcmp((const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StatusNotificationPeriodically].ItemData, "TRUE") == 0) && (getDiffSecNow(clientTime.StatusNotification[gun_index]) >= atoi((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[StatusNotificationInterval].ItemData)))
  4829. )
  4830. )
  4831. {
  4832. sendStatusNotificationRequest(gun_index);
  4833. refreshStartTimer(&clientTime.StatusNotification[gun_index]);
  4834. }
  4835. //==============================================
  4836. // TCCI reader status report
  4837. //==============================================
  4838. if(isWebsocketSendable && (server_sign == TRUE) && (ShmOCPP16Data->TcciCustomData.ReaderStatus[gun_index].ReportReaderStatusReq == 1))
  4839. {
  4840. reportReaderStatus(gun_index);
  4841. //ShmOCPP16Data->TcciCustomData.ReaderStatus[gun_index].ReportReaderStatusReq = 0;
  4842. }
  4843. //==============================================
  4844. // CSU Trigger or timer timeout refresh Smart Charging Profile
  4845. //==============================================
  4846. if((ShmOCPP16Data->CSUMsg.bits[gun_index].ChargingProfileReq == 1) ||
  4847. ((cpinitateMsg.bits[gun_index].isOnCharging) && (atoi((const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CharingProfileRefreshInterval].ItemData) > 0) && (getDiffSecNow(clientTime.CharingProfileRefresh[gun_index]) > atoi((const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CharingProfileRefreshInterval].ItemData))))
  4848. {
  4849. checkCompositeSchedule(gun_index+1, 86400, &ShmOCPP16Data->SmartChargingProfile[gun_index], TRUE);
  4850. ShmOCPP16Data->CSUMsg.bits[gun_index].ChargingProfileReq = 0;
  4851. refreshStartTimer(&clientTime.CharingProfileRefresh[gun_index]);
  4852. }
  4853. //==============================================
  4854. // Meter report
  4855. //==============================================
  4856. // Trigger MeterValue
  4857. if(isWebsocketSendable && (server_sign == TRUE) && cpinitateMsg.bits[gun_index].TriggerMeterValue)
  4858. {
  4859. sendMeterValuesRequest(gun_index, ReadingContext_Trigger);
  4860. cpinitateMsg.bits[gun_index].TriggerMeterValue = 0;
  4861. }
  4862. // Clock-aligned Meter value
  4863. if(isWebsocketSendable && (reqClockAlignMeter[gun_index] == 1))
  4864. {
  4865. sendMeterValuesRequest(gun_index, ReadingContext_Sample_Clock);
  4866. reqClockAlignMeter[gun_index] = 0;
  4867. }
  4868. // Sample period MeterValue
  4869. if(((getDiffSecNow(clientTime.MeterValues[gun_index]) >= ((atoi((const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemData))>3?(atoi((const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemData)- 1):3))))
  4870. {
  4871. //check Transaction active
  4872. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  4873. {
  4874. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4875. {
  4876. tempIndex = ((gun_index==2) ? 1: 0);
  4877. }
  4878. else
  4879. {
  4880. tempIndex = gun_index;
  4881. }
  4882. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  4883. {
  4884. // 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault
  4885. if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  4886. {
  4887. if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_CHARGING)
  4888. {
  4889. reqSampleMeter[gun_index] = 1;
  4890. }
  4891. }
  4892. }// End for CHAdeMO
  4893. }
  4894. else if(gunType[gun_index] == GUN_TYPE_CCS)
  4895. {
  4896. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4897. {
  4898. tempIndex = ((gun_index==2) ? 1: 0);
  4899. }
  4900. else
  4901. {
  4902. tempIndex = gun_index;
  4903. }
  4904. for (int index = 0; index < CCS_QUANTITY; index++)
  4905. {
  4906. // 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault
  4907. if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  4908. {
  4909. if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_CHARGING)
  4910. {
  4911. reqSampleMeter[gun_index] = 1;
  4912. }
  4913. }
  4914. } // End for CCS
  4915. }
  4916. else if(gunType[gun_index] == GUN_TYPE_GBT)
  4917. {
  4918. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4919. {
  4920. tempIndex = ((gun_index==2) ? 1: 0);
  4921. }
  4922. else
  4923. {
  4924. tempIndex = gun_index;
  4925. }
  4926. for (int index = 0; index < GB_QUANTITY; index++)
  4927. {
  4928. // 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault
  4929. if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  4930. {
  4931. if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_CHARGING)
  4932. {
  4933. reqSampleMeter[gun_index] = 1;
  4934. }
  4935. }
  4936. }// End for GB
  4937. }
  4938. else if(gunType[gun_index] == GUN_TYPE_DO)
  4939. {
  4940. tempIndex = gun_index;
  4941. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  4942. {
  4943. // 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault
  4944. if(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  4945. {
  4946. if(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_CHARGING)
  4947. {
  4948. reqSampleMeter[gun_index] = 1;
  4949. }
  4950. }
  4951. }
  4952. }
  4953. else
  4954. {
  4955. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  4956. {
  4957. tempIndex = 2;
  4958. }
  4959. else
  4960. {
  4961. tempIndex = gun_index;
  4962. }
  4963. for (int index = 0; index < AC_QUANTITY; index++)
  4964. {
  4965. // 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault
  4966. if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  4967. {
  4968. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_TERMINATING))
  4969. {
  4970. reqSampleMeter[gun_index] = 1;
  4971. }
  4972. }
  4973. }//End for AC
  4974. }
  4975. if(reqSampleMeter[gun_index] == 1)
  4976. {
  4977. if(atoi((const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemData)>0)
  4978. sendMeterValuesRequest(gun_index, ReadingContext_Sample_Periodic);
  4979. storeTempStopTransaction(gun_index);
  4980. reqSampleMeter[gun_index] = 0;
  4981. }
  4982. refreshStartTimer(&clientTime.MeterValues[gun_index]);
  4983. }
  4984. //==============================================
  4985. // Check Connector reserved
  4986. //==============================================
  4987. //===============================
  4988. // Check if Reserve is expired
  4989. //===============================
  4990. if((server_sign == TRUE) && (ShmOCPP16Data->ReserveNow[gun_index].ExpiryDate[0] != 0))
  4991. {
  4992. if(isOvertNow(ShmOCPP16Data->ReserveNow[gun_index].ExpiryDate))
  4993. {
  4994. DEBUG_INFO("reserve expired.\n");
  4995. memset(ShmOCPP16Data->ReserveNow[gun_index].ExpiryDate,0,ARRAY_SIZE(ShmOCPP16Data->ReserveNow[gun_index].ExpiryDate));
  4996. }
  4997. }//END OF Check if Reserve is expired
  4998. //==========================================
  4999. // csu trigger FirmwareStatusNotificationReq
  5000. //==========================================
  5001. if(isWebsocketSendable && (server_sign == TRUE) && (ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationReq == 1))
  5002. {
  5003. sendFirmwareStatusNotificationRequest((char *)ShmOCPP16Data->FirmwareStatusNotification.Status);
  5004. }
  5005. //==========================================
  5006. // csu trigger DiagnosticsStatusNotificationReq
  5007. //==========================================
  5008. if(isWebsocketSendable && (server_sign == TRUE) && (ShmOCPP16Data->SpMsg.bits.DiagnosticsStatusNotificationReq == 1))
  5009. {
  5010. sendDiagnosticsStatusNotificationRequest((char *)ShmOCPP16Data->DiagnosticsStatusNotification.Status);
  5011. }
  5012. //==========================================
  5013. // csu trigger CancelReservationConf
  5014. //==========================================
  5015. if(isWebsocketSendable && (server_sign == TRUE) && (ShmOCPP16Data->CsMsg.bits[gun_index].CancelReservationConf == 1))
  5016. {
  5017. sendCancelReservationConfirmation((char *)ShmOCPP16Data->CancelReservation[gun_index].guid,(char *)ShmOCPP16Data->CancelReservation[gun_index].ResponseStatus);
  5018. ShmOCPP16Data->CsMsg.bits[gun_index].CancelReservationConf = 0;
  5019. }
  5020. //==========================================
  5021. // csu trigger ChangeAvailabilityConf
  5022. //==========================================
  5023. if(isWebsocketSendable && (server_sign == TRUE) && (ShmOCPP16Data->CsMsg.bits[gun_index].ChangeAvailabilityConf == 1))
  5024. {
  5025. //sendChangeAvailabilityConfirmation(,(char *)ShmOCPP16Data->ChangeAvailability[gun_index].ResponseStatus);
  5026. }
  5027. //==========================================
  5028. // csu trigger UnlockConnectorConf
  5029. //==========================================
  5030. if(isWebsocketSendable && (server_sign == TRUE) && (ShmOCPP16Data->CsMsg.bits[gun_index].UnlockConnectorConf == 1))
  5031. {
  5032. sendUnlockConnectorConfirmation((char *)ShmOCPP16Data->UnlockConnector[gun_index].guid, (char *)ShmOCPP16Data->UnlockConnector[gun_index].ResponseStatus);
  5033. ShmOCPP16Data->CsMsg.bits[gun_index].UnlockConnectorConf = 0;
  5034. }
  5035. //==========================================
  5036. // csu trigger ReserveNowConf
  5037. //==========================================
  5038. if(isWebsocketSendable && (server_sign == TRUE) && (ShmOCPP16Data->CsMsg.bits[gun_index].ReserveNowConf == 1))
  5039. {
  5040. sendReserveNowTransactionConfirmation((char *)ShmOCPP16Data->ReserveNow[gun_index].guid, (char *)ShmOCPP16Data->ReserveNow[gun_index].ResponseStatus);
  5041. ShmOCPP16Data->CsMsg.bits[gun_index].ReserveNowConf = 0;
  5042. }
  5043. if(isWebsocketSendable && (server_sign == TRUE) && (ShmOCPP16Data->SpMsg.bits.SignCertificateReq == 1) && (access("/Storage/OCPP/certCP.csr",F_OK) != -1))
  5044. {
  5045. sendSignCertificateRequest();
  5046. }
  5047. }
  5048. }
  5049. //==========================================
  5050. // send request routine
  5051. //==========================================
  5052. int sendAuthorizeRequest(int gun_index)
  5053. {
  5054. mtrace();
  5055. int result = FAIL;
  5056. char message[100]={0};
  5057. char guid[37];
  5058. char tempdata[65]={0};
  5059. DEBUG_INFO("sendAuthorizeRequest...\n");
  5060. memset(&(ShmOCPP16Data->Authorize.ResponseIdTagInfo),0,sizeof(struct StructIdTagInfo));
  5061. //Local Authorize
  5062. if((strcmp((const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemData , "TRUE")==0) &&(ShmOCPP16Data->OcppConnStatus == 0))
  5063. {
  5064. DEBUG_INFO("Allow OfflineTx UnknownId Pass.\n");
  5065. strcpy((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.ExpiryDate, "");
  5066. strcpy((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.ParentIdTag, "");
  5067. strcpy((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.Status, "Accepted");
  5068. result = PASS;
  5069. ShmOCPP16Data->SpMsg.bits.AuthorizeReq = 0;
  5070. ShmOCPP16Data->SpMsg.bits.AuthorizeConf = 1; // inform csu
  5071. authorizeRetryTimes = 0;
  5072. return result;
  5073. }
  5074. else if(((strcmp((const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemData, "TRUE") == 0)&&(strcmp((const char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "TRUE") == 0)&&(ShmOCPP16Data->OcppConnStatus == 0))||
  5075. ((strcmp((const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemData, "TRUE") == 0)&&(strcmp((const char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "TRUE") == 0)))
  5076. {
  5077. // Query from cache
  5078. DEBUG_INFO("Authorize from cache.\n");
  5079. OCPP_getIdTagFromLocalCache((char *)ShmSysConfigAndInfo->SysConfig.UserId);
  5080. // Query from list
  5081. if((strcmp(idTagQuery.idTagstr,"") == 0) || (strcmp(idTagQuery.idTagstatus,"Accepted") != 0) )
  5082. {
  5083. DEBUG_INFO("Authorize from list.\n");
  5084. OCPP_getIdTagFromLocalList((char *)ShmSysConfigAndInfo->SysConfig.UserId);
  5085. }
  5086. if((strcmp(idTagQuery.idTagstr,"") == 0) || (strcmp(idTagQuery.idTagstatus,"Accepted") != 0) )
  5087. {
  5088. if(strcmp(idTagQuery.idTagstr,"") == 0)
  5089. {
  5090. DEBUG_INFO("Local Authorization Fail, Card %s is not in local cache and list.\n", ShmSysConfigAndInfo->SysConfig.UserId);
  5091. }
  5092. else if(strcmp(idTagQuery.idTagstatus,"Accepted") != 0)
  5093. {
  5094. DEBUG_INFO("Local Authorization Fail, Card %s is not Accepted.\n", idTagQuery.idTagstr);
  5095. }
  5096. if(!GetOcppConnStatus())
  5097. {
  5098. DEBUG_INFO("off-line Local Authorization Fail.\n");
  5099. strcpy((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.ExpiryDate, idTagQuery.expiryDate);
  5100. strcpy((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.ParentIdTag, idTagQuery.parentIdTag);
  5101. strcpy((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.Status, "Invalid");
  5102. DEBUG_INFO("ShmOCPP16Data->Authorize.ResponseIdTagInfo.Status: %s \n", ShmOCPP16Data->Authorize.ResponseIdTagInfo.Status);
  5103. ShmOCPP16Data->SpMsg.bits.AuthorizeReq = 0;
  5104. ShmOCPP16Data->SpMsg.bits.AuthorizeConf = 1; // inform csu
  5105. authorizeRetryTimes = 0;
  5106. return result;
  5107. }
  5108. }
  5109. else
  5110. {
  5111. DEBUG_INFO("off-line Local Authorization get result !!!!\n");
  5112. strcpy((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.ExpiryDate, idTagQuery.expiryDate);
  5113. strcpy((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.ParentIdTag, idTagQuery.parentIdTag);
  5114. if(isOvertNow((uint8_t*)&idTagQuery.expiryDate[0]))
  5115. sprintf((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.Status, "Expired");
  5116. else
  5117. strcpy((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.Status, idTagQuery.idTagstatus);
  5118. DEBUG_INFO("ShmOCPP16Data->Authorize.ResponseIdTagInfo.Status: %s \n", ShmOCPP16Data->Authorize.ResponseIdTagInfo.Status);
  5119. result = PASS;
  5120. ShmOCPP16Data->SpMsg.bits.AuthorizeReq = 0;
  5121. ShmOCPP16Data->SpMsg.bits.AuthorizeConf = 1; // inform csu
  5122. authorizeRetryTimes = 0;
  5123. return result;
  5124. }
  5125. }
  5126. //initialize struct Authorize
  5127. memset(&(ShmOCPP16Data->Authorize), 0 , sizeof(struct StructAuthorize));
  5128. //get data from shared memory
  5129. strcpy((char *)ShmOCPP16Data->Authorize.IdTag, (const char *)ShmSysConfigAndInfo->SysConfig.UserId);
  5130. random_uuid(guid);
  5131. sprintf(message,"[%d,\"%s\",\"Authorize\",{\"idTag\":\"%s\"}]",MESSAGE_TYPE_CALL, guid, ShmOCPP16Data->Authorize.IdTag);
  5132. LWS_Send(message);
  5133. sprintf(tempdata, "Authorize,%d", gun_index);
  5134. if(hashmap_operation(HASH_OP_ADD, guid, tempdata) == 1)
  5135. {
  5136. result = PASS;
  5137. DEBUG_INFO("Authorize mapItem pass\n");
  5138. }
  5139. ShmOCPP16Data->SpMsg.bits.AuthorizeReq = 0;
  5140. return result;
  5141. }
  5142. int sendBootNotificationRequest(void)
  5143. {
  5144. mtrace();
  5145. int result = FAIL;
  5146. char message[500]={0}, payload[700]={0};
  5147. char guid[37]={0};
  5148. char tempdata[65]={0};
  5149. // Fill BootNotification fields
  5150. strcpy((char *)ShmOCPP16Data->BootNotification.CbSN,(const char *)ShmOCPP16Data->ChargeBoxId);
  5151. strcpy((char *)ShmOCPP16Data->BootNotification.CpModel,(const char *)ShmSysConfigAndInfo->SysConfig.ModelName);
  5152. strcpy((char *)ShmOCPP16Data->BootNotification.CpSN,(const char *)ShmSysConfigAndInfo->SysConfig.SerialNumber);
  5153. strcpy((char *)ShmOCPP16Data->BootNotification.CpVendor,(const char *)ShmSysConfigAndInfo->SysConfig.chargePointVendor);
  5154. strcpy((char *)ShmOCPP16Data->BootNotification.CpFwVersion,(const char *)ShmSysConfigAndInfo->SysInfo.CsuRootFsFwRev);
  5155. strcpy((char *)ShmOCPP16Data->BootNotification.CpIccid,(const char *)ShmSysConfigAndInfo->SysConfig.TelecomInterface.TelcomSimIccid);
  5156. strcpy((char *)ShmOCPP16Data->BootNotification.CpImsi,(const char *)ShmSysConfigAndInfo->SysConfig.TelecomInterface.TelcomSimImsi);
  5157. sprintf(payload, "{\"chargeBoxSerialNumber\":\"%s\",\"chargePointModel\":\"%s\",\"chargePointSerialNumber\":\"%s\",\"chargePointVendor\":\"%s\",\"firmwareVersion\":\"%s\",\"iccid\":\"%s\",\"imsi\":\"%s\"} ",
  5158. ShmOCPP16Data->ChargeBoxId
  5159. ,ShmSysConfigAndInfo->SysConfig.ModelName
  5160. ,ShmSysConfigAndInfo->SysConfig.SerialNumber
  5161. ,ShmSysConfigAndInfo->SysConfig.chargePointVendor
  5162. ,ShmOCPP16Data->BootNotification.CpFwVersion
  5163. ,ShmOCPP16Data->BootNotification.CpIccid
  5164. ,ShmOCPP16Data->BootNotification.CpImsi);
  5165. random_uuid(guid);
  5166. sprintf(message,"[%d,\"%s\",\"%s\",%s]",MESSAGE_TYPE_CALL, guid, "BootNotification", payload);
  5167. LWS_Send(message);
  5168. sprintf(tempdata, "BootNotification,0");
  5169. if(hashmap_operation(HASH_OP_ADD, guid, tempdata) == 1)//if(hashmap_operation(0,NULL/*hashMap*/, guid,mapItem, tempdata/*(void**)(&mapItem)*//*(void**)(&mapItem)*/) == MAP_OK/*hashmap_put(hashMap, mapItem->key_string, mapItem) == MAP_OK*/)
  5170. {
  5171. result = PASS;
  5172. }
  5173. memset(queuedata, 0, ARRAY_SIZE(queuedata));
  5174. strcpy(queuedata,message);
  5175. return result;
  5176. }
  5177. int sendDataTransferRequest(int gun_index)
  5178. {
  5179. mtrace();
  5180. char message[1000]={0};
  5181. char guid[37]={0};
  5182. char tempdata[65]={0};
  5183. int result = FAIL;
  5184. random_uuid(guid);
  5185. sprintf(message,"[%d,\"%s\",\"DataTransfer\",{\"vendorId\":\"%s\",\"messageId\":\"%s\",\"data\":\"%s\"}]",
  5186. MESSAGE_TYPE_CALL,
  5187. guid,
  5188. ShmOCPP16Data->DataTransfer[gun_index].VendorId,
  5189. ShmOCPP16Data->DataTransfer[gun_index].MessageId,
  5190. ShmOCPP16Data->DataTransfer[gun_index].Data);
  5191. LWS_Send(message);
  5192. sprintf(tempdata, "DataTransfer,%d", (gun_index + 1));
  5193. if(hashmap_operation(HASH_OP_ADD, guid, tempdata) == 1)
  5194. {
  5195. result = PASS;
  5196. DEBUG_INFO("DataTransfer mapItem pass\n");
  5197. }
  5198. return result;
  5199. }
  5200. int sendUnplugByDataTransferRequest(int gun_index)
  5201. {
  5202. mtrace();
  5203. char message[1000]={0};
  5204. char guid[37]={0};
  5205. char tempdata[65]={0};
  5206. int result = FAIL;
  5207. random_uuid(guid);
  5208. sprintf(message,"%d,[%d,\"%s\",\"DataTransfer\",{\"vendorId\":\"%s\",\"messageId\":\"%s\",\"data\":\"%s\"}]",
  5209. (gun_index+1),
  5210. MESSAGE_TYPE_CALL,
  5211. guid,
  5212. ShmOCPP16Data->DataTransfer[gun_index].VendorId,
  5213. ShmOCPP16Data->DataTransfer[gun_index].MessageId,
  5214. ShmOCPP16Data->DataTransfer[gun_index].Data);
  5215. sprintf(tempdata, "DataTransfer,%d", (gun_index + 1));
  5216. if(hashmap_operation(HASH_OP_ADD, guid, tempdata) == 1)
  5217. {
  5218. result = PASS;
  5219. DEBUG_INFO("DataTransfer mapItem pass\n");
  5220. }
  5221. queue_operation(QUEUE_OPERATION_ADD, guid, message);
  5222. return result;
  5223. }
  5224. int sendOcmfByDataTransferRequest(int gun_index)
  5225. {
  5226. sprintf((char*)ShmOCPP16Data->DataTransfer[gun_index].VendorId, (char*)ShmSysConfigAndInfo->SysConfig.chargePointVendor);
  5227. sprintf((char*)ShmOCPP16Data->DataTransfer[gun_index].MessageId, "ID_OCMF");
  5228. sprintf((char*)ShmOCPP16Data->DataTransfer[gun_index].Data, "{\\\"txId\\\":%d,\\\"dataString\\\":\\\"%s\\\",\\\"publicKey\\\":\\\"%s\\\"}", ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId, ShmOCPP16Data->OcmfData[gun_index].DataString, ShmOCPP16Data->OcmfData[gun_index].PublicKey);
  5229. mtrace();
  5230. char message[3000]={0};
  5231. char guid[37]={0};
  5232. char tempdata[65]={0};
  5233. int result = FAIL;
  5234. random_uuid(guid);
  5235. sprintf(message,"%d,[%d,\"%s\",\"DataTransfer\",{\"vendorId\":\"%s\",\"messageId\":\"%s\",\"data\":\"%s\"}]",
  5236. (gun_index+1),
  5237. MESSAGE_TYPE_CALL,
  5238. guid,
  5239. ShmOCPP16Data->DataTransfer[gun_index].VendorId,
  5240. ShmOCPP16Data->DataTransfer[gun_index].MessageId,
  5241. ShmOCPP16Data->DataTransfer[gun_index].Data);
  5242. sprintf(tempdata, "DataTransfer,%d", (gun_index + 1));
  5243. if(hashmap_operation(HASH_OP_ADD, guid, tempdata) == 1)
  5244. {
  5245. result = PASS;
  5246. DEBUG_INFO("DataTransfer mapItem pass\n");
  5247. }
  5248. queue_operation(QUEUE_OPERATION_ADD, guid, message);
  5249. return result;
  5250. }
  5251. int sendDiagnosticsStatusNotificationRequest(char *status)
  5252. {
  5253. mtrace();
  5254. int result = FAIL;
  5255. char message[110]={0};
  5256. char guid[37]={0};
  5257. char tempdata[65]={0};
  5258. //[ 2, "9f7bced1-b8b1-40ec-b3bb-2e15630e3cdc", "DiagnosticsStatusNotification", { "status": "Idle" } ]
  5259. DEBUG_INFO("sendDiagnosticsStatusNotificationRequest...\n");
  5260. sprintf((char *)ShmOCPP16Data->DiagnosticsStatusNotification.Status,"%s",(const char *)status);
  5261. random_uuid(guid);
  5262. sprintf(message,"[%d,\"%s\",\"DiagnosticsStatusNotification\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALL, guid,status);
  5263. LWS_SendNow(message);
  5264. sprintf(tempdata, "DiagnosticsStatusNotification,%d", 0);
  5265. if(hashmap_operation(HASH_OP_ADD, guid, tempdata) == 1)
  5266. {
  5267. result = PASS;
  5268. //DEBUG_INFO("DiagnosticsStatusNotification mapItem pass\n");
  5269. }
  5270. //#ifdef SystemLogMessage
  5271. //DEBUG_INFO(">>>>>DiagnosticsStatusNotification request\n");
  5272. //DEBUG_INFO("Message: %s\n", SendBuffer);
  5273. //DEBUG_INFO("After push hash length: %d\n", hashmapForMessageLength()/*hashmap_length(hashMap)*/);
  5274. //#endif
  5275. ShmOCPP16Data->SpMsg.bits.DiagnosticsStatusNotificationReq = 0;
  5276. ShmOCPP16Data->SpMsg.bits.DiagnosticsStatusNotificationConf = 0;
  5277. //record status
  5278. if(strcmp(status,"Idle")==0)
  5279. {
  5280. DiagnosticsStatusNotificationStatus = DIAGNOSTIC_STATUS_IDLE;
  5281. }
  5282. else if(strcmp(status,"Uploaded")==0)
  5283. {
  5284. DiagnosticsStatusNotificationStatus = DIAGNOSTIC_STATUS_UPLOADED;
  5285. }
  5286. else if(strcmp(status,"UploadFailed")==0)
  5287. {
  5288. DiagnosticsStatusNotificationStatus = DIAGNOSTIC_STATUS_UPLOAD_FAIL;
  5289. }
  5290. else if(strcmp(status,"Uploading")==0)
  5291. {
  5292. DiagnosticsStatusNotificationStatus = DIAGNOSTIC_STATUS_UPLOADING;
  5293. }
  5294. return result;
  5295. }
  5296. int sendFirmwareStatusNotificationRequest(char *status)
  5297. {
  5298. mtrace();
  5299. int result = FAIL;
  5300. char message[110]={0};
  5301. char guid[37]={0};
  5302. char tempdata[65]={0};
  5303. // [ 2, "eb841424-ae56-42b0-8c84-d5296018c33c", "FirmwareStatusNotification", { "status": "Downloaded" } ]
  5304. DEBUG_INFO("sendFirmwareStatusNotificationRequest \n");
  5305. sprintf((char *)ShmOCPP16Data->FirmwareStatusNotification.Status, "%s", (const char *)status);
  5306. random_uuid(guid);
  5307. sprintf(message,"[%d,\"%s\",\"FirmwareStatusNotification\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALL, guid, status);
  5308. LWS_SendNow(message);
  5309. sprintf(tempdata, "FirmwareStatusNotification,%d", 0);
  5310. if(hashmap_operation(HASH_OP_ADD, guid, tempdata) == 1)//if(hashmap_operation(0,NULL/*hashMap*/, mapItem[0].key_string, mapItem[0].key_value/*mapItem*/, (void**)(&mapItem)/*(void**)(&mapItem)*/) == MAP_OK/*hashmap_put(hashMap, mapItem->key_string, mapItem) == MAP_OK*/)
  5311. {
  5312. result = PASS;
  5313. DEBUG_INFO("FirmwareStatusNotification mapItem pass\n");
  5314. }
  5315. //#ifdef SystemLogMessage
  5316. //DEBUG_INFO(">>>>>FirmwareStatusNotification request\n");
  5317. //DEBUG_INFO("Message: %s\n", SendBuffer);
  5318. //#endif
  5319. ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationReq = 0;
  5320. ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationConf = 0;
  5321. //record status
  5322. if(strcmp(status,"Downloaded")==0)
  5323. {
  5324. FirmwareStatusNotificationStatus = FIRMWARE_STATUS_DOWNLOADED;
  5325. }
  5326. else if(strcmp(status,"DownloadFailed")==0)
  5327. {
  5328. FirmwareStatusNotificationStatus = FIRMWARE_STATUS_DOWNLOAD_FAILED;
  5329. }
  5330. else if(strcmp(status,"Downloading")==0)
  5331. {
  5332. FirmwareStatusNotificationStatus = FIRMWARE_STATUS_DOWNLOADING;
  5333. }
  5334. else if(strcmp(status,"Idle")==0)
  5335. {
  5336. FirmwareStatusNotificationStatus = FIRMWARE_STATUS_IDLE;
  5337. }
  5338. else if(strcmp(status,"InstallationFailed")==0)
  5339. {
  5340. FirmwareStatusNotificationStatus = FIRMWARE_STATUS_INSTALLATION_FAILED;
  5341. }
  5342. else if(strcmp(status,"Installing")==0)
  5343. {
  5344. FirmwareStatusNotificationStatus = FIRMWARE_STATUS_INSTALLING;
  5345. }
  5346. else if(strcmp(status,"Installed")==0)
  5347. {
  5348. FirmwareStatusNotificationStatus = FIRMWARE_STATUS_INSTALLED;
  5349. }
  5350. return result;
  5351. }
  5352. int sendHeartbeatRequest(int gun_index)
  5353. {
  5354. mtrace();
  5355. int result = FAIL;
  5356. char message[80]={0};
  5357. char guid[37]={0};
  5358. char tempdata[65]={0};
  5359. random_uuid(guid);
  5360. sprintf(message, "[%d,\"%s\",\"Heartbeat\",{ }]"
  5361. , MESSAGE_TYPE_CALL
  5362. , guid );
  5363. LWS_Send(message);
  5364. sprintf(tempdata, "Heartbeat,%d", 0);
  5365. if(hashmap_operation(HASH_OP_ADD, guid, tempdata) == 1)//if(hashmap_operation(0,NULL/*hashMap*/, guid, mapItem, tempdata/*(void**)(&mapItem)*/) == MAP_OK/*hashmap_put(hashMap, mapItem->key_string, mapItem) == MAP_OK*/)
  5366. {
  5367. result = PASS;
  5368. }
  5369. return result;
  5370. }
  5371. int sendStartTransactionRequest(int gun_index)
  5372. {
  5373. mtrace();
  5374. int result = FAIL;
  5375. char message[250]={0};
  5376. char guid[37]={0};
  5377. struct timeval tmnow;
  5378. struct tm *tm;
  5379. char buf[28];//, usec_buf[6];
  5380. char tempdata[65]={0};
  5381. int tempIndex = 0;
  5382. DEBUG_INFO("sendStartTransactionRequest...\n");
  5383. gettimeofday(&tmnow, NULL);
  5384. time_t t;
  5385. t = time(NULL);
  5386. /*UTC time and date*/
  5387. tm = gmtime(&t);
  5388. strftime(buf,28,"%Y-%m-%dT%H:%M:%SZ", tm);
  5389. #if 0 // remove temporally
  5390. strftime(buf,30,"%Y-%m-%dT%H:%M:%S", tm);
  5391. strcat(buf,".");
  5392. sprintf(usec_buf,"%dZ",(int)tmnow.tv_usec);
  5393. strcat(buf,usec_buf);
  5394. #endif
  5395. ShmOCPP16Data->StartTransaction[gun_index].ConnectorId = gun_index +1 ; // gun start from 1~
  5396. strcpy((char *)ShmOCPP16Data->StartTransaction[gun_index].Timestamp, buf);
  5397. //strcpy((char *)ShmOCPP16Data->StartTransaction[gun_index].IdTag, (const char *)ShmSysConfigAndInfo->SysConfig.UserId);
  5398. // clear StartTransaction Response
  5399. strcpy((char *)ShmOCPP16Data->StartTransaction[gun_index].ResponseIdTagInfo.ExpiryDate, "");
  5400. strcpy((char *)ShmOCPP16Data->StartTransaction[gun_index].ResponseIdTagInfo.ParentIdTag, "");
  5401. strcpy((char *)ShmOCPP16Data->StartTransaction[gun_index].ResponseIdTagInfo.Status, "");
  5402. ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId = 0;
  5403. refreshStartTimer(&clientTime.MeterValues[gun_index]);
  5404. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DCcc
  5405. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  5406. {
  5407. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  5408. {
  5409. tempIndex = ((gun_index==2) ? 1: 0);
  5410. }
  5411. else
  5412. {
  5413. tempIndex = gun_index;
  5414. }
  5415. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  5416. {
  5417. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  5418. {
  5419. ShmOCPP16Data->StartTransaction[gun_index].MeterStart = (int)(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PowerConsumption*1000);
  5420. ShmOCPP16Data->StartTransaction[gun_index].ReservationId = ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ReservationId;
  5421. periousPeriodicPowerConsumption[gun_index] = ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PowerConsumption;
  5422. }
  5423. }
  5424. }
  5425. else if(gunType[gun_index] == GUN_TYPE_CCS)
  5426. {
  5427. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  5428. {
  5429. tempIndex = ((gun_index==2) ? 1: 0);
  5430. }
  5431. else
  5432. {
  5433. tempIndex = gun_index;
  5434. }
  5435. for (int index = 0; index < CCS_QUANTITY; index++)
  5436. {
  5437. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  5438. {
  5439. ShmOCPP16Data->StartTransaction[gun_index].MeterStart = (int)(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PowerConsumption*1000);
  5440. ShmOCPP16Data->StartTransaction[gun_index].ReservationId = ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ReservationId;
  5441. periousPeriodicPowerConsumption[gun_index] = ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PowerConsumption;
  5442. }
  5443. }
  5444. }
  5445. else if(gunType[gun_index] == GUN_TYPE_GBT)
  5446. {
  5447. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  5448. {
  5449. tempIndex = ((gun_index==2) ? 1: 0);
  5450. }
  5451. else
  5452. {
  5453. tempIndex = gun_index;
  5454. }
  5455. for (int index = 0; index < GB_QUANTITY; index++)
  5456. {
  5457. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  5458. {
  5459. ShmOCPP16Data->StartTransaction[gun_index].MeterStart = (int)(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PowerConsumption*1000);
  5460. ShmOCPP16Data->StartTransaction[gun_index].ReservationId = ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ReservationId;
  5461. periousPeriodicPowerConsumption[gun_index] = ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PowerConsumption;
  5462. }
  5463. }
  5464. }
  5465. else if(gunType[gun_index] == GUN_TYPE_DO)
  5466. {
  5467. tempIndex = gun_index;
  5468. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  5469. {
  5470. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  5471. {
  5472. ShmOCPP16Data->StartTransaction[gun_index].MeterStart = (int)(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PowerConsumption*1000);
  5473. ShmOCPP16Data->StartTransaction[gun_index].ReservationId = ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.ReservationId;
  5474. periousPeriodicPowerConsumption[gun_index] = ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PowerConsumption;
  5475. }
  5476. }
  5477. }
  5478. else
  5479. {
  5480. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  5481. {
  5482. tempIndex = 2;
  5483. }
  5484. else
  5485. {
  5486. tempIndex = gun_index;
  5487. }
  5488. for (int index = 0; index < AC_QUANTITY; index++)
  5489. {
  5490. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  5491. {
  5492. ShmOCPP16Data->StartTransaction[gun_index].MeterStart = (int)(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PowerConsumption*1000);
  5493. ShmOCPP16Data->StartTransaction[gun_index].ReservationId = ShmSysConfigAndInfo->SysInfo.AcChargingData[index].ReservationId;
  5494. periousPeriodicPowerConsumption[gun_index] = ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PowerConsumption;
  5495. }
  5496. }
  5497. }
  5498. random_uuid(guid);
  5499. if(ShmOCPP16Data->StartTransaction[gun_index].ReservationId == -1) // No Reservation
  5500. {
  5501. sprintf(message, "%d,[%d,\"%s\",\"StartTransaction\",{\"connectorId\":%d,\"idTag\":\"%s\",\"meterStart\":%d,\"timestamp\":\"%s\"}]"
  5502. , gun_index +1
  5503. , MESSAGE_TYPE_CALL
  5504. , guid
  5505. , ShmOCPP16Data->StartTransaction[gun_index].ConnectorId
  5506. , ShmOCPP16Data->StartTransaction[gun_index].IdTag
  5507. , ShmOCPP16Data->StartTransaction[gun_index].MeterStart
  5508. , ShmOCPP16Data->StartTransaction[gun_index].Timestamp );
  5509. }
  5510. else
  5511. {
  5512. sprintf(message, "%d,[%d,\"%s\",\"StartTransaction\",{\"connectorId\":%d,\"idTag\":\"%s\",\"meterStart\":%d,\"reservationId\":%d,\"timestamp\":\"%s\"}]"
  5513. , gun_index +1
  5514. , MESSAGE_TYPE_CALL
  5515. , guid
  5516. , ShmOCPP16Data->StartTransaction[gun_index].ConnectorId
  5517. , ShmOCPP16Data->StartTransaction[gun_index].IdTag
  5518. , ShmOCPP16Data->StartTransaction[gun_index].MeterStart
  5519. , ShmOCPP16Data->StartTransaction[gun_index].ReservationId
  5520. , ShmOCPP16Data->StartTransaction[gun_index].Timestamp );
  5521. }
  5522. #if 1
  5523. sprintf(tempdata, "StartTransaction,%d", (gun_index));
  5524. if(hashmap_operation(HASH_OP_ADD, guid, tempdata) == 1)//if(hashmap_operation(0,NULL/*hashMap*/, mapItem[0].key_string, mapItem[0].key_value/*mapItem*/, (void**)(&mapItem)/*(void**)(&mapItem)*/) == MAP_OK/*hashmap_put(hashMap, mapItem->key_string, mapItem) == MAP_OK*/)
  5525. {
  5526. result = PASS;
  5527. }
  5528. #endif
  5529. strcpy(queuedata, message);
  5530. queue_operation(QUEUE_OPERATION_ADD, guid, queuedata );//addq(guid, queuedata); ---> remove temporally
  5531. OCPP_insert_transaction_msg(YES, queuedata);
  5532. return result;
  5533. }
  5534. int sendStatusNotificationRequest(int gun_index)
  5535. {
  5536. mtrace();
  5537. int result = FAIL;
  5538. char message[600]={0};
  5539. char guid[37];
  5540. int currentStatus = 0;
  5541. struct timeval tmnow;
  5542. struct tm *tm;
  5543. char buf[28];//, usec_buf[6];
  5544. char tempdata[65]={0};
  5545. int tempIndex = 0;
  5546. uint8_t isStateChanged = TRUE;
  5547. uint8_t isContentIllegal = TRUE;
  5548. DEBUG_INFO("sendStatusNotificationRequest...\n");
  5549. gettimeofday(&tmnow, NULL);
  5550. time_t t;
  5551. t = time(NULL);
  5552. /*UTC time and date*/
  5553. tm = gmtime(&t);
  5554. strftime(buf,28,"%Y-%m-%dT%H:%M:%SZ", tm);
  5555. #if 0 // remove temporally
  5556. strftime(buf,30,"%Y-%m-%dT%H:%M:%S", tm);
  5557. strcat(buf,".");
  5558. sprintf(usec_buf,"%dZ",(int)tmnow.tv_usec);
  5559. strcat(buf,usec_buf);
  5560. #endif
  5561. //printf("%s",buf);
  5562. ShmOCPP16Data->StatusNotification[gun_index].ConnectorId = (gun_index + 1);
  5563. //strcpy(ShmOCPP16Data->StatusNotification[gun_index].ErrorCode, "NoError"); --- CSU Setting
  5564. // it's option
  5565. //strcpy((char *)ShmOCPP16Data->StatusNotification[gun_index].Info, "");
  5566. /*
  5567. enum _SYSTEM_STATUS
  5568. {
  5569. S_BOOTING = 0,
  5570. S_IDLE, = 1
  5571. S_AUTHORIZING, =2
  5572. S_REASSIGN_CHECK, =3
  5573. S_REASSIGN, =4
  5574. S_PRECHARGE, =5
  5575. S_PREPARING_FOR_EV, =6
  5576. S_PREPARING_FOR_EVSE, =7
  5577. S_CHARGING, =8
  5578. S_TERMINATING, =9
  5579. S_COMPLETE, =10
  5580. S_ALARM, =11
  5581. S_FAULT =12
  5582. }
  5583. */
  5584. //check Transaction active
  5585. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DCcc
  5586. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  5587. {
  5588. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  5589. {
  5590. tempIndex = ((gun_index==2) ? 1: 0);
  5591. }
  5592. else
  5593. {
  5594. tempIndex = gun_index;
  5595. }
  5596. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  5597. {
  5598. if ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex))
  5599. {
  5600. if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_IDLE)//S_IDLE
  5601. {
  5602. if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ConnectorPlugIn == 1) // //0: unplug, 1: Plug-in
  5603. {
  5604. currentStatus = Preparing; //OCPP Status: Preparing
  5605. }
  5606. else
  5607. {
  5608. currentStatus = Available; //OCPP Status: Available
  5609. }
  5610. }
  5611. else if ( ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus >= SYS_MODE_AUTHORIZING)&&( ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus <= SYS_MODE_PREPARE_FOR_EVSE)) ||
  5612. ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus >= SYS_MODE_CCS_PRECHARGE_STEP0) && ( ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus <= SYS_MODE_CCS_PRECHARGE_STEP1) )
  5613. ) //S_PRECHARGE
  5614. {
  5615. currentStatus = Preparing; //OCPP Status: Preparing
  5616. }
  5617. else if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_CHARGING) //S_CHARGING
  5618. {
  5619. currentStatus = Charging; //OCPP Status: Charging
  5620. }
  5621. else if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_COMPLETE) //S_COMPLETE
  5622. {
  5623. currentStatus = Finishing; //OCPP Status: Finishing
  5624. }
  5625. else if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_TERMINATING) // S_TERMINATING ---> SuspendedEV
  5626. {
  5627. currentStatus = SuspendedEV; //OCPP Status: SuspendedEV
  5628. }
  5629. else if ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_BOOTING) || (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_MAINTAIN) || (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_DEBUG) || (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_UPDATE)) // ---> Unavailable
  5630. {
  5631. currentStatus = Unavailable; //OCPP Status: Unavailable
  5632. }
  5633. else if ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_FAULT) || (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_ALARM)) //S_ALARM,S_FAULT ---> Faulted
  5634. {
  5635. currentStatus = Faulted; //OCPP Status: Faulted
  5636. }
  5637. else if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_RESERVATION) // ---> Reserved
  5638. {
  5639. currentStatus = Reserved; //OCPP Status: Reserved
  5640. }
  5641. } //end of the same index
  5642. }//end of for CHAdeMO_QUANTITY
  5643. }
  5644. else if(gunType[gun_index] == GUN_TYPE_CCS)
  5645. {
  5646. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  5647. {
  5648. tempIndex = ((gun_index==2) ? 1: 0);
  5649. }
  5650. else
  5651. {
  5652. tempIndex = gun_index;
  5653. }
  5654. for (int index = 0; index < CCS_QUANTITY; index++)
  5655. {
  5656. if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  5657. {
  5658. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_IDLE) //S_IDLE
  5659. {
  5660. if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ConnectorPlugIn == 1) //0: unplug, 1: Plug-in
  5661. {
  5662. currentStatus = Preparing; //OCPP Status: Preparing
  5663. }
  5664. else
  5665. {
  5666. currentStatus = Available; //OCPP Status: Available
  5667. }
  5668. }
  5669. else if ( ((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus >= SYS_MODE_AUTHORIZING)&&( ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus <= SYS_MODE_PREPARE_FOR_EVSE)) ||
  5670. ((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus >= SYS_MODE_CCS_PRECHARGE_STEP0) && ( ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus <= SYS_MODE_CCS_PRECHARGE_STEP1) )
  5671. ) //S_PRECHARGE
  5672. {
  5673. currentStatus = Preparing; //OCPP Status: Preparing
  5674. }
  5675. else if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_CHARGING) //S_CHARGING
  5676. {
  5677. currentStatus = Charging; //OCPP Status: Charging
  5678. }
  5679. else if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_COMPLETE) //S_COMPLETE
  5680. {
  5681. currentStatus = Finishing; //OCPP Status: Finishing
  5682. }
  5683. else if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_TERMINATING) //S_TERMINATING ---> SuspendedEV
  5684. {
  5685. currentStatus = SuspendedEV; //OCPP Status: SuspendedEV
  5686. }
  5687. else if ((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_BOOTING) || (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_MAINTAIN) || (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_DEBUG) || (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_UPDATE)) // ---> Unavailable
  5688. {
  5689. currentStatus = Unavailable; //OCPP Status : Unavailable
  5690. }
  5691. else if ((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_FAULT) || (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_ALARM)) //S_ALARM ,S_FAULT ---> Faulted
  5692. {
  5693. currentStatus = Faulted; //OCPP Status: Faulted
  5694. }
  5695. else if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_RESERVATION) // ---> Reserved
  5696. {
  5697. currentStatus = Reserved; //OCPP Status: Reserved
  5698. }
  5699. } //end of the same index
  5700. } // end of for CCS_QUANTITY
  5701. }
  5702. else if(gunType[gun_index] == GUN_TYPE_GBT)
  5703. {
  5704. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  5705. {
  5706. tempIndex = ((gun_index==2) ? 1: 0);
  5707. }
  5708. else
  5709. {
  5710. tempIndex = gun_index;
  5711. }
  5712. for (int index = 0; index < GB_QUANTITY; index++)
  5713. {
  5714. if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  5715. {
  5716. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_IDLE) //S_IDLE
  5717. {
  5718. if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ConnectorPlugIn == 1) // //0: unplug, 1: Plug-in
  5719. {
  5720. currentStatus = Preparing; //OCPP Status: Preparing
  5721. }
  5722. else
  5723. {
  5724. currentStatus = Available; //OCPP Status: Available
  5725. }
  5726. }
  5727. else if ( ((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus >= SYS_MODE_AUTHORIZING)&&( ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus <= SYS_MODE_PREPARE_FOR_EVSE)) ||
  5728. ((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus >= SYS_MODE_CCS_PRECHARGE_STEP0) && ( ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus <= SYS_MODE_CCS_PRECHARGE_STEP1) )
  5729. ) //S_PRECHARGE
  5730. {
  5731. currentStatus = Preparing; //OCPP Status: Preparing
  5732. }
  5733. else if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_CHARGING) //S_CHARGING
  5734. {
  5735. currentStatus = Charging; //OCPP Status: Charging
  5736. }
  5737. else if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_COMPLETE) //S_COMPLETE
  5738. {
  5739. currentStatus = Finishing; //OCPP Status: Finishing
  5740. }
  5741. else if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_TERMINATING) // S_TERMINATING ---> SuspendedEV
  5742. {
  5743. currentStatus = SuspendedEV; //OCPP Status: SuspendedEV
  5744. }
  5745. else if ((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_BOOTING) || (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_MAINTAIN) || (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_DEBUG) || (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_UPDATE)) // ---> Unavailable
  5746. {
  5747. currentStatus = Unavailable; //OCPP Status: Unavailable
  5748. }
  5749. else if ((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_FAULT) || (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_ALARM)) //S_ALARM ,S_FAULT ---> Faulted
  5750. {
  5751. currentStatus = Faulted; //OCPP Status: Faulted
  5752. }
  5753. else if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_RESERVATION) // ---> Reserved
  5754. {
  5755. currentStatus = Reserved; //OCPP Status: Reserved
  5756. }
  5757. } //end of the same index
  5758. } // end of for GB_QUANTITY
  5759. }
  5760. else if(gunType[gun_index] == GUN_TYPE_DO)
  5761. {
  5762. tempIndex = gun_index;
  5763. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  5764. {
  5765. if(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  5766. {
  5767. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_IDLE) //S_IDLE
  5768. {
  5769. if(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.ConnectorPlugIn == 1) // //0: unplug, 1: Plug-in
  5770. {
  5771. currentStatus = Preparing; //OCPP Status: Preparing
  5772. }
  5773. else
  5774. {
  5775. currentStatus = Available; //OCPP Status: Available
  5776. }
  5777. }
  5778. else if ( ((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus >= SYS_MODE_AUTHORIZING) && (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus <= SYS_MODE_PREPARE_FOR_EVSE)) ||
  5779. ((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus >= SYS_MODE_CCS_PRECHARGE_STEP0) && (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus <= SYS_MODE_CCS_PRECHARGE_STEP1) )
  5780. ) //S_PRECHARGE
  5781. {
  5782. currentStatus = Preparing; //OCPP Status: Preparing
  5783. }
  5784. else if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_CHARGING) //S_CHARGING
  5785. {
  5786. currentStatus = Charging; //OCPP Status: Charging
  5787. }
  5788. else if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_COMPLETE) //S_COMPLETE
  5789. {
  5790. currentStatus = Finishing; //OCPP Status: Finishing
  5791. }
  5792. else if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_TERMINATING) // S_TERMINATING ---> SuspendedEV
  5793. {
  5794. currentStatus = SuspendedEV; //OCPP Status: SuspendedEV
  5795. }
  5796. else if ((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_BOOTING) || (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_MAINTAIN) || (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_DEBUG) || (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_UPDATE)) // ---> Unavailable
  5797. {
  5798. currentStatus = Unavailable; //OCPP Status: Unavailable
  5799. }
  5800. else if ((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_FAULT) || (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_ALARM)) //S_ALARM ,S_FAULT ---> Faulted
  5801. {
  5802. currentStatus = Faulted; //OCPP Status: Faulted
  5803. }
  5804. else if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_RESERVATION) // ---> Reserved
  5805. {
  5806. currentStatus = Reserved; //OCPP Status: Reserved
  5807. }
  5808. } //end of the same index
  5809. }
  5810. }
  5811. else
  5812. {
  5813. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  5814. {
  5815. tempIndex = 2;
  5816. }
  5817. else
  5818. {
  5819. tempIndex = gun_index;
  5820. }
  5821. for (int index = 0; index < AC_QUANTITY; index++)
  5822. {
  5823. if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  5824. {
  5825. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_IDLE) //SYS_MODE_IDLE
  5826. {
  5827. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PilotState == CP_STATE_B) ||(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PilotState == CP_STATE_C) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PilotState == CP_STATE_D))
  5828. {
  5829. currentStatus = Preparing; //OCPP Status: Preparing
  5830. }
  5831. else
  5832. {
  5833. currentStatus = Available; //OCPP Status: Available
  5834. }
  5835. }
  5836. else if ((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_AUTHORIZING) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_PREPARING)) //SYS_MODE_PREPARING
  5837. {
  5838. currentStatus = Preparing; //OCPP Status: Preparing
  5839. }
  5840. else if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_CHARGING) //SYS_MODE_CHARGING
  5841. {
  5842. currentStatus = Charging; //OCPP Status: Charging
  5843. }
  5844. else if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_COMPLETE) //SYS_MODE_COMPLETE
  5845. {
  5846. currentStatus = Finishing; //OCPP Status: Finishing
  5847. }
  5848. else if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_TERMINATING) // S_TERMINATING ---> SuspendedEV
  5849. {
  5850. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PilotState == CP_STATE_B))
  5851. currentStatus = SuspendedEV; //OCPP Status: SuspendedEV
  5852. else
  5853. currentStatus = SuspendedEVSE; //OCPP Status: SuspendedEVSE
  5854. }
  5855. else if ((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_BOOTING) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_MAINTAIN) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_DEBUG) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_UPDATE)) // ---> Unavailable
  5856. {
  5857. currentStatus = Unavailable; //OCPP Status: Unavailable
  5858. }
  5859. else if ((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_FAULT) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_ALARM)) //S_ALARM,S_FAULT ---> Faulted
  5860. {
  5861. currentStatus = Faulted; //OCPP Status: Faulted
  5862. }
  5863. else if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_RESERVATION) // ---> Reserved
  5864. {
  5865. currentStatus = Reserved; //OCPP Status: Reserved
  5866. }
  5867. }//end of the same index
  5868. }//end of for AC_QUANTITY
  5869. }
  5870. //it's option
  5871. if(((strstr((char *)ShmOCPP16Data->StatusNotification[gun_index].Status, ChargePointStatusStr[currentStatus]) != NULL) || (((currentStatus == SuspendedEV) || (currentStatus == SuspendedEVSE)) && ShmOCPP16Data->CsMsg.bits[gun_index].RemoteStopTransactionReq)) &&
  5872. !cpinitateMsg.bits[gun_index].TriggerStatusNotificationReq &&
  5873. (strcmp((const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StatusNotificationPeriodically].ItemData, "TRUE") != 0))
  5874. {
  5875. isStateChanged = FALSE;
  5876. }
  5877. cpinitateMsg.bits[gun_index].TriggerStatusNotificationReq = 0;
  5878. strcpy((char *)ShmOCPP16Data->StatusNotification[gun_index].Timestamp, buf);
  5879. strcpy((char *)ShmOCPP16Data->StatusNotification[gun_index].VendorId, (char*)ShmSysConfigAndInfo->SysConfig.chargePointVendor);
  5880. strcpy((char *)ShmOCPP16Data->StatusNotification[gun_index].Status, ChargePointStatusStr[currentStatus]);
  5881. isContentIllegal = TRUE;
  5882. for(int index = 0; index < ARRAY_SIZE(ChargePointErrorCodeStr); index++)
  5883. {
  5884. if(strcmp((char *)ShmOCPP16Data->StatusNotification[gun_index].ErrorCode, ChargePointErrorCodeStr[index])==0)
  5885. {
  5886. isContentIllegal = FALSE;
  5887. break;
  5888. }
  5889. }
  5890. if(isContentIllegal)
  5891. {
  5892. //DEBUG_WARN("Detect illegal ErrorCode: %s \n",(char *)ShmOCPP16Data->StatusNotification[gun_index].ErrorCode);
  5893. strcpy((char *)ShmOCPP16Data->StatusNotification[gun_index].ErrorCode, ChargePointErrorCodeStr[6]);
  5894. }
  5895. random_uuid(guid);
  5896. sprintf(message, "[%d,\"%s\",\"StatusNotification\",{\"connectorId\":%d,\"errorCode\":\"%s\",\"info\":\"%s\",\"status\":\"%s\",\"timestamp\":\"%s\",\"vendorId\":\"%s\",\"vendorErrorCode\":\"%s\"}]"
  5897. , MESSAGE_TYPE_CALL
  5898. , guid
  5899. , ShmOCPP16Data->StatusNotification[gun_index].ConnectorId
  5900. , ShmOCPP16Data->StatusNotification[gun_index].ErrorCode
  5901. , ShmOCPP16Data->StatusNotification[gun_index].Info
  5902. , ShmOCPP16Data->StatusNotification[gun_index].Status
  5903. , ShmOCPP16Data->StatusNotification[gun_index].Timestamp
  5904. , ShmOCPP16Data->StatusNotification[gun_index].VendorId
  5905. , ShmOCPP16Data->StatusNotification[gun_index].VendorErrorCode);
  5906. if((server_sign == TRUE) && isStateChanged)
  5907. {
  5908. cpinitateMsg.bits[gun_index].StatusNotificationReq = 0;
  5909. cpinitateMsg.bits[gun_index].TriggerStatusNotificationReq = 0;
  5910. LWS_Send(message);
  5911. sprintf(tempdata, "StatusNotification,%d", (gun_index));
  5912. if(hashmap_operation(HASH_OP_ADD, guid, tempdata) == 1)//if(hashmap_operation(0,NULL/*hashMap*/, guid, mapItem, tempdata/*(void**)(&mapItem)*//*(void**)(&mapItem)*/) == MAP_OK/*hashmap_put(hashMap, mapItem->key_string, mapItem) == MAP_OK*/)
  5913. {
  5914. //DEBUG_ERROR("statusNotification mapitem pass");
  5915. result = PASS;
  5916. }
  5917. }
  5918. else
  5919. {
  5920. cpinitateMsg.bits[gun_index].StatusNotificationReq = 0;
  5921. cpinitateMsg.bits[gun_index].TriggerStatusNotificationReq = 0;
  5922. result = PASS;
  5923. }
  5924. return result;
  5925. }
  5926. int sendStopTransactionRequest(int gun_index)
  5927. {
  5928. mtrace();
  5929. int result = FAIL;
  5930. //char message[1500]={0};
  5931. char guid[37]={0};
  5932. char tempdata[65]={0};
  5933. int tempIndex = 0;
  5934. char TempStopTransaction[256];
  5935. sprintf(TempStopTransaction, "/Storage/OCPP/TempStopTransaction_%d", (gun_index+1));
  5936. //int idx_sample=0;
  5937. DEBUG_INFO("sendStopTransactionRequest \n");
  5938. memset(queuedata, 0, ARRAY_SIZE(queuedata));
  5939. memset(&ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0], 0, ARRAY_SIZE(ShmOCPP16Data->StopTransaction[gun_index].TransactionData));
  5940. //=========================== ENERGY_ACTIVE_IMPORT_REGISTER =======================================
  5941. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DCcc
  5942. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  5943. {
  5944. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  5945. {
  5946. tempIndex = ((gun_index==2) ? 1: 0);
  5947. }
  5948. else
  5949. {
  5950. tempIndex = gun_index;
  5951. }
  5952. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  5953. {
  5954. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  5955. {
  5956. ShmOCPP16Data->StopTransaction[gun_index].MeterStop = (int)(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PowerConsumption*1000);
  5957. }
  5958. }// END OF CHAdeMO_QUANTITY
  5959. }
  5960. else if(gunType[gun_index] == GUN_TYPE_CCS)
  5961. {
  5962. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  5963. {
  5964. tempIndex = ((gun_index==2) ? 1: 0);
  5965. }
  5966. else
  5967. {
  5968. tempIndex = gun_index;
  5969. }
  5970. for (int index = 0; index < CCS_QUANTITY; index++)
  5971. {
  5972. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  5973. {
  5974. ShmOCPP16Data->StopTransaction[gun_index].MeterStop = (int)(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PowerConsumption*1000);
  5975. }
  5976. }// END OF CCS_QUANTITY
  5977. }
  5978. else if(gunType[gun_index] == GUN_TYPE_GBT)
  5979. {
  5980. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  5981. {
  5982. tempIndex = ((gun_index==2) ? 1: 0);
  5983. }
  5984. else
  5985. {
  5986. tempIndex = gun_index;
  5987. }
  5988. for (int index = 0; index < GB_QUANTITY; index++)
  5989. {
  5990. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  5991. {
  5992. ShmOCPP16Data->StopTransaction[gun_index].MeterStop = (int)(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PowerConsumption*1000);
  5993. }
  5994. }// END OF GB_QUANTITY
  5995. }
  5996. else if(gunType[gun_index] == GUN_TYPE_DO)
  5997. {
  5998. tempIndex = gun_index;
  5999. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  6000. {
  6001. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  6002. {
  6003. ShmOCPP16Data->StopTransaction[gun_index].MeterStop = (int)(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PowerConsumption*1000);
  6004. }
  6005. }// END OF GB_QUANTITY
  6006. }
  6007. else
  6008. {
  6009. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  6010. {
  6011. tempIndex = 2;
  6012. }
  6013. else
  6014. {
  6015. tempIndex = gun_index;
  6016. }
  6017. for (int index = 0; index < AC_QUANTITY; index++)
  6018. {
  6019. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  6020. {
  6021. ShmOCPP16Data->StopTransaction[gun_index].MeterStop = (int)(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PowerConsumption*1000);
  6022. }
  6023. }// END OF AC_QUANTITY
  6024. }
  6025. //====================================== Stop Transaction Time =====================================================
  6026. struct timeval tmnow;
  6027. struct tm *tm;
  6028. char buf[28];//, usec_buf[6];
  6029. gettimeofday(&tmnow, NULL);
  6030. time_t t;
  6031. t = time(NULL);
  6032. /*UTC time and date*/
  6033. tm = gmtime(&t);
  6034. strftime(buf,28,"%Y-%m-%dT%H:%M:%SZ", tm);
  6035. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].Timestamp,buf);
  6036. ShmOCPP16Data->StopTransaction[gun_index].TransactionId = ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId;
  6037. random_uuid(guid);
  6038. /***********************************transactionData******************************************************/
  6039. memset(ShmOCPP16Data->StopTransaction[gun_index].TransactionData, 0, sizeof(struct StructMeterValue));
  6040. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].TimeStamp, buf);
  6041. //=================================
  6042. // Transaction_Begin
  6043. //=================================
  6044. //=================================
  6045. // Transaction_End
  6046. //=================================
  6047. // ================================= Current.Import L1 ===============================================
  6048. if(strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Current.Import") != NULL)
  6049. {
  6050. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G : GBT DC
  6051. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  6052. {
  6053. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  6054. {
  6055. tempIndex = ((gun_index==2) ? 1: 0);
  6056. }
  6057. else
  6058. {
  6059. tempIndex = gun_index;
  6060. }
  6061. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  6062. {
  6063. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  6064. {
  6065. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargingCurrent );// PresentChargingCurrent is 0~6553.5 amp
  6066. }
  6067. }// End of for CHAdeMO_QUANTITY
  6068. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase,PhaseStr[L3_N]);
  6069. }
  6070. else if(gunType[gun_index] == GUN_TYPE_CCS)
  6071. {
  6072. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  6073. {
  6074. tempIndex = ((gun_index==2) ? 1: 0);
  6075. }
  6076. else
  6077. {
  6078. tempIndex = gun_index;
  6079. }
  6080. for (int index = 0; index < CCS_QUANTITY; index++)
  6081. {
  6082. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  6083. {
  6084. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargingCurrent );// PresentChargingCurrent is 0~6553.5 amp
  6085. }
  6086. }// End of for CCS_QUANTITY
  6087. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase,PhaseStr[L3_N]);
  6088. }
  6089. else if(gunType[gun_index] == GUN_TYPE_GBT)
  6090. {
  6091. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  6092. {
  6093. tempIndex = ((gun_index==2) ? 1: 0);
  6094. }
  6095. else
  6096. {
  6097. tempIndex = gun_index;
  6098. }
  6099. for (int index = 0; index < GB_QUANTITY; index++)
  6100. {
  6101. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  6102. {
  6103. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingCurrent );// PresentChargingCurrent is 0~6553.5 amp
  6104. }
  6105. }// End of for GB_QUANTITY
  6106. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase,PhaseStr[L3_N]);
  6107. }
  6108. else if(gunType[gun_index] == GUN_TYPE_DO)
  6109. {
  6110. tempIndex = gun_index;
  6111. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  6112. {
  6113. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  6114. {
  6115. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PresentChargingCurrent );// PresentChargingCurrent is 0~6553.5 amp
  6116. }
  6117. }
  6118. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase,PhaseStr[L3_N]);
  6119. }
  6120. else
  6121. {
  6122. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  6123. {
  6124. tempIndex = 2;
  6125. }
  6126. else
  6127. {
  6128. tempIndex = gun_index;
  6129. }
  6130. for (int index = 0; index < AC_QUANTITY; index++)
  6131. {
  6132. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  6133. {
  6134. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingCurrent );// 0~6553.5 amp for EVSE
  6135. }
  6136. }// End of for AC_QUANTITY
  6137. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase,PhaseStr[L1_N]);
  6138. }
  6139. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  6140. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Format,ValueFormatStr[Raw]);
  6141. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Measurand,MeasurandStr[Current_Import]);
  6142. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Location,LocationStr[Location_Outlet]);
  6143. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Unit,UnitOfMeasureStr[UnitOfMeasure_A]);
  6144. }
  6145. // ================================= Energy.Active.Import.Interval ==============================================
  6146. if(strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Energy.Active.Import.Interval") != NULL)
  6147. {
  6148. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  6149. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  6150. {
  6151. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  6152. {
  6153. tempIndex = ((gun_index==2) ? 1: 0);
  6154. }
  6155. else
  6156. {
  6157. tempIndex = gun_index;
  6158. }
  6159. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  6160. {
  6161. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  6162. {
  6163. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Value, "%.3f" ,(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PowerConsumption - periousPeriodicPowerConsumption[gun_index]));// PresentChargedEnergy is 0~6553.5 kWh
  6164. periousPeriodicPowerConsumption[gun_index] = ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PowerConsumption;
  6165. }
  6166. }// END OF CHAdeMO_QUANTITY
  6167. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase,PhaseStr[L3_N]);
  6168. }
  6169. else if(gunType[gun_index] == GUN_TYPE_CCS)
  6170. {
  6171. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  6172. {
  6173. tempIndex = ((gun_index==2) ? 1: 0);
  6174. }
  6175. else
  6176. {
  6177. tempIndex = gun_index;
  6178. }
  6179. for (int index = 0; index < CCS_QUANTITY; index++)
  6180. {
  6181. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  6182. {
  6183. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Value, "%.3f" ,(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PowerConsumption - periousPeriodicPowerConsumption[gun_index]));// PresentChargedEnergy is 0~6553.5 kWh
  6184. periousPeriodicPowerConsumption[gun_index] = ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PowerConsumption;
  6185. }
  6186. }// END OF CCS_QUANTITY
  6187. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase,PhaseStr[L3_N]);
  6188. }
  6189. else if(gunType[gun_index] == GUN_TYPE_GBT)
  6190. {
  6191. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  6192. {
  6193. tempIndex = ((gun_index==2) ? 1: 0);
  6194. }
  6195. else
  6196. {
  6197. tempIndex = gun_index;
  6198. }
  6199. for (int index = 0; index < GB_QUANTITY; index++)
  6200. {
  6201. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  6202. {
  6203. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Value, "%.3f" ,(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PowerConsumption - periousPeriodicPowerConsumption[gun_index]));// PresentChargedEnergy is 0~6553.5 kWh
  6204. periousPeriodicPowerConsumption[gun_index] = ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PowerConsumption;
  6205. }
  6206. }// END OF GB_QUANTITY
  6207. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase,PhaseStr[L3_N]);
  6208. }
  6209. else if(gunType[gun_index] == GUN_TYPE_DO)
  6210. {
  6211. tempIndex = gun_index;
  6212. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  6213. {
  6214. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  6215. {
  6216. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Value, "%.3f" ,(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PowerConsumption - periousPeriodicPowerConsumption[gun_index]));// PresentChargedEnergy is 0~6553.5 kWh
  6217. periousPeriodicPowerConsumption[gun_index] = ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PowerConsumption;
  6218. }
  6219. }
  6220. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase,PhaseStr[L3_N]);
  6221. }
  6222. else
  6223. {
  6224. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  6225. {
  6226. tempIndex = 2;
  6227. }
  6228. else
  6229. {
  6230. tempIndex = gun_index;
  6231. }
  6232. for (int index = 0; index < AC_QUANTITY; index++)
  6233. {
  6234. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  6235. {
  6236. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Value, "%.3f" ,(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PowerConsumption - periousPeriodicPowerConsumption[gun_index]));// PresentChargedEnergy is 0~6553.5 kWh
  6237. periousPeriodicPowerConsumption[gun_index] = ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PowerConsumption;
  6238. }
  6239. }// END OF AC_QUANTITY
  6240. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase,PhaseStr[L1_N]);
  6241. }
  6242. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  6243. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Format,ValueFormatStr[Raw]);
  6244. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Measurand,MeasurandStr[Energy_Active_Import_Interval]);
  6245. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Location,LocationStr[Location_Outlet]);
  6246. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Unit,UnitOfMeasureStr[UnitOfMeasure_kWh]);
  6247. }
  6248. //=================================== Power.Active.Import ==================================================
  6249. if(strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Power.Active.Import") != NULL)
  6250. {
  6251. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  6252. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  6253. {
  6254. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  6255. {
  6256. tempIndex = ((gun_index==2) ? 1: 0);
  6257. }
  6258. else
  6259. {
  6260. tempIndex = gun_index;
  6261. }
  6262. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  6263. {
  6264. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  6265. {
  6266. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargingPower );// PresentChargingPower is 0~6553.5 kW
  6267. }
  6268. } // End for CHAdeMO_QUANTITY
  6269. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase,PhaseStr[L3_N]);
  6270. }
  6271. else if(gunType[gun_index] == GUN_TYPE_CCS)
  6272. {
  6273. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  6274. {
  6275. tempIndex = ((gun_index==2) ? 1: 0);
  6276. }
  6277. else
  6278. {
  6279. tempIndex = gun_index;
  6280. }
  6281. for (int index = 0; index < CCS_QUANTITY; index++)
  6282. {
  6283. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  6284. {
  6285. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargingPower );// PresentChargingPower is 0~6553.5 kW
  6286. }
  6287. } // END for CCS_QUANTITY
  6288. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase,PhaseStr[L3_N]);
  6289. }
  6290. else if(gunType[gun_index] == GUN_TYPE_GBT)
  6291. {
  6292. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  6293. {
  6294. tempIndex = ((gun_index==2) ? 1: 0);
  6295. }
  6296. else
  6297. {
  6298. tempIndex = gun_index;
  6299. }
  6300. for (int index = 0; index < GB_QUANTITY; index++)
  6301. {
  6302. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  6303. {
  6304. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingPower );// PresentChargingPower is 0~6553.5 kW
  6305. }
  6306. }// END for GB_QUANTITY
  6307. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase,PhaseStr[L3_N]);
  6308. }
  6309. else if(gunType[gun_index] == GUN_TYPE_DO)
  6310. {
  6311. tempIndex = gun_index;
  6312. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  6313. {
  6314. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  6315. {
  6316. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PresentChargingPower );// PresentChargingPower is 0~6553.5 kW
  6317. }
  6318. }
  6319. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase,PhaseStr[L3_N]);
  6320. }
  6321. else
  6322. {
  6323. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  6324. {
  6325. tempIndex = 2;
  6326. }
  6327. else
  6328. {
  6329. tempIndex = gun_index;
  6330. }
  6331. for (int index = 0; index < AC_QUANTITY; index++)
  6332. {
  6333. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  6334. {
  6335. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingPower );// PresentChargingPower is 0~6553.5 kW
  6336. }
  6337. } // END for AC_QUANTITY
  6338. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase,PhaseStr[L1_N]);
  6339. }
  6340. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  6341. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Format,ValueFormatStr[Raw]);
  6342. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Measurand,MeasurandStr[Power_Active_Import]);
  6343. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Location,LocationStr[Location_Outlet]);
  6344. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Unit,UnitOfMeasureStr[UnitOfMeasure_kW/*UnitOfMeasure_kWh*/]);
  6345. }
  6346. //============================ Voltage L1 ====================================
  6347. if(strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Voltage") != NULL)
  6348. {
  6349. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  6350. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  6351. {
  6352. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  6353. {
  6354. tempIndex = ((gun_index==2) ? 1: 0);
  6355. }
  6356. else
  6357. {
  6358. tempIndex = gun_index;
  6359. }
  6360. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  6361. {
  6362. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  6363. {
  6364. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargingVoltage );// PresentChargingVoltage is 0~6553.5 volt
  6365. }
  6366. } // END OF FOR CHAdeMO_QUANTITY
  6367. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase,PhaseStr[L3_N]);
  6368. }
  6369. else if(gunType[gun_index] == GUN_TYPE_CCS)
  6370. {
  6371. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  6372. {
  6373. tempIndex = ((gun_index==2) ? 1: 0);
  6374. }
  6375. else
  6376. {
  6377. tempIndex = gun_index;
  6378. }
  6379. for (int index = 0; index < CCS_QUANTITY; index++)
  6380. {
  6381. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  6382. {
  6383. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargingVoltage );// PresentChargingVoltage is 0~6553.5 volt
  6384. }
  6385. } // END OF FOR CCS_QUANTITY
  6386. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase,PhaseStr[L3_N]);
  6387. }
  6388. else if(gunType[gun_index] == GUN_TYPE_GBT)
  6389. {
  6390. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  6391. {
  6392. tempIndex = ((gun_index==2) ? 1: 0);
  6393. }
  6394. else
  6395. {
  6396. tempIndex = gun_index;
  6397. }
  6398. for (int index = 0; index < GB_QUANTITY; index++)
  6399. {
  6400. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  6401. {
  6402. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingVoltage );// PresentChargingVoltage is 0~6553.5 volt
  6403. }
  6404. } // END OF FOR GB_QUANTITY
  6405. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase,PhaseStr[L3_N]);
  6406. }
  6407. else if(gunType[gun_index] == GUN_TYPE_DO)
  6408. {
  6409. tempIndex = gun_index;
  6410. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  6411. {
  6412. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  6413. {
  6414. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PresentChargingVoltage );// PresentChargingVoltage is 0~6553.5 volt
  6415. }
  6416. }
  6417. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase,PhaseStr[L3_N]);
  6418. }
  6419. else
  6420. {
  6421. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  6422. {
  6423. tempIndex = 2;
  6424. }
  6425. else
  6426. {
  6427. tempIndex = gun_index;
  6428. }
  6429. for (int index = 0; index < AC_QUANTITY; index++)
  6430. {
  6431. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  6432. {
  6433. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingVoltage );//AcChargingVoltage is 0~6553.5 volt for AC EVSE
  6434. }
  6435. } // END OF FOR AC_QUANTITY
  6436. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase,PhaseStr[L1_N]);
  6437. }
  6438. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  6439. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Format,ValueFormatStr[Raw]);
  6440. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Measurand,MeasurandStr[Voltage]);
  6441. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Location,LocationStr[Location_Outlet]);
  6442. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Unit,UnitOfMeasureStr[UnitOfMeasure_V]);
  6443. }
  6444. //====================== End SoC ================================
  6445. if(strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, MeasurandStr[SoC]) != NULL)
  6446. {
  6447. //J : CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  6448. if((gunType[gun_index] == GUN_TYPE_CHAdeMO)||(gunType[gun_index] == GUN_TYPE_CCS)||(gunType[gun_index] == GUN_TYPE_GBT)||(gunType[gun_index] == GUN_TYPE_DO))
  6449. {
  6450. if((ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0') && (gunType[gun_index] != GUN_TYPE_DO))
  6451. {
  6452. tempIndex = ((gun_index==2) ? 1: 0);
  6453. }
  6454. else
  6455. {
  6456. tempIndex = gun_index;
  6457. }
  6458. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  6459. {
  6460. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  6461. {
  6462. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  6463. {
  6464. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].EvBatterySoc );// 0~100%
  6465. }
  6466. }
  6467. }
  6468. else if(gunType[gun_index] == GUN_TYPE_CCS)
  6469. {
  6470. for (int index = 0; index < CCS_QUANTITY; index++)
  6471. {
  6472. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  6473. {
  6474. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].EvBatterySoc );// 0~100%
  6475. }
  6476. }
  6477. }
  6478. else if(gunType[gun_index] == GUN_TYPE_GBT)
  6479. {
  6480. for (int index = 0; index < GB_QUANTITY; index++)
  6481. {
  6482. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  6483. {
  6484. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].EvBatterySoc );// 0~100%
  6485. }
  6486. }
  6487. }
  6488. else if(gunType[gun_index] == GUN_TYPE_DO)
  6489. {
  6490. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  6491. {
  6492. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  6493. {
  6494. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.EvBatterySoc );// 0~100%
  6495. }
  6496. }
  6497. }
  6498. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  6499. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Format,ValueFormatStr[Raw]);
  6500. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Measurand,MeasurandStr[SoC/*Energy_Reactive_Export_Register*/]);
  6501. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Phase,PhaseStr[L3_N]);
  6502. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Location,LocationStr[Location_EV]);
  6503. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Unit,UnitOfMeasureStr[UnitOfMeasure_Percent/*UnitOfMeasure_kWh*/]);
  6504. } // END FOR DC CASE
  6505. }
  6506. // ================================= Current.Import L2 ===============================================
  6507. if(strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Current.Import") != NULL)
  6508. {
  6509. // AC 3 phse L2 current
  6510. if((gunType[gun_index] == GUN_TYPE_AC) && ((ShmSysConfigAndInfo->SysConfig.ModelName[2]=='Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='W') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='D')))
  6511. {
  6512. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  6513. {
  6514. tempIndex = 2;
  6515. }
  6516. else
  6517. {
  6518. tempIndex = gun_index;
  6519. }
  6520. for (int index = 0; index < AC_QUANTITY; index++)
  6521. {
  6522. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  6523. {
  6524. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingCurrentL2 );// 0~6553.5 amp for EVSE
  6525. }
  6526. }// End of for AC_QUANTITY
  6527. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Phase,PhaseStr[L2_N]);
  6528. }
  6529. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  6530. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Format,ValueFormatStr[Raw]);
  6531. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Measurand,MeasurandStr[Current_Import]);
  6532. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Location,LocationStr[Location_Outlet]);
  6533. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Unit,UnitOfMeasureStr[UnitOfMeasure_A]);
  6534. }
  6535. // ================================= Current.Import L3 ===============================================
  6536. if(strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Current.Import") != NULL)
  6537. {
  6538. // AC 3 phse L3 current
  6539. if((gunType[gun_index] == GUN_TYPE_AC) && ((ShmSysConfigAndInfo->SysConfig.ModelName[2]=='Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='W') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='D')))
  6540. {
  6541. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  6542. {
  6543. tempIndex = 2;
  6544. }
  6545. else
  6546. {
  6547. tempIndex = gun_index;
  6548. }
  6549. for (int index = 0; index < AC_QUANTITY; index++)
  6550. {
  6551. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  6552. {
  6553. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingCurrentL3 );// 0~6553.5 amp for EVSE
  6554. }
  6555. }// End of for AC_QUANTITY
  6556. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Phase,PhaseStr[L3_N]);
  6557. }
  6558. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  6559. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Format,ValueFormatStr[Raw]);
  6560. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Measurand,MeasurandStr[Current_Import]);
  6561. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Location,LocationStr[Location_Outlet]);
  6562. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Unit,UnitOfMeasureStr[UnitOfMeasure_A]);
  6563. }
  6564. //============================ Voltage L2 ====================================
  6565. if(strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Voltage") != NULL)
  6566. {
  6567. // AC 3 phse L2 voltage
  6568. if((gunType[gun_index] == GUN_TYPE_AC) && ((ShmSysConfigAndInfo->SysConfig.ModelName[2]=='Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='W') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='D')))
  6569. {
  6570. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  6571. {
  6572. tempIndex = 2;
  6573. }
  6574. else
  6575. {
  6576. tempIndex = gun_index;
  6577. }
  6578. for (int index = 0; index < AC_QUANTITY; index++)
  6579. {
  6580. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  6581. {
  6582. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingVoltageL2 );//AcChargingVoltage is 0~6553.5 volt for AC EVSE
  6583. }
  6584. } // END OF FOR AC_QUANTITY
  6585. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Phase,PhaseStr[L2_N]);
  6586. }
  6587. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  6588. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Format,ValueFormatStr[Raw]);
  6589. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Measurand,MeasurandStr[Voltage]);
  6590. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Location,LocationStr[Location_Outlet]);
  6591. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Unit,UnitOfMeasureStr[UnitOfMeasure_V]);
  6592. }
  6593. //============================ Voltage L3 ====================================
  6594. if(strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Voltage") != NULL)
  6595. {
  6596. // AC 3 phse L3 voltage
  6597. if((gunType[gun_index] == GUN_TYPE_AC) && ((ShmSysConfigAndInfo->SysConfig.ModelName[2]=='Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='W') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='D')))
  6598. {
  6599. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  6600. {
  6601. tempIndex = 2;
  6602. }
  6603. else
  6604. {
  6605. tempIndex = gun_index;
  6606. }
  6607. for (int index = 0; index < AC_QUANTITY; index++)
  6608. {
  6609. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  6610. {
  6611. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingVoltageL3 );//AcChargingVoltage is 0~6553.5 volt for AC EVSE
  6612. }
  6613. } // END OF FOR AC_QUANTITY
  6614. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Phase,PhaseStr[L3_N]);
  6615. }
  6616. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  6617. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Format,ValueFormatStr[Raw]);
  6618. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Measurand,MeasurandStr[Voltage]);
  6619. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Location,LocationStr[Location_Outlet]);
  6620. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Unit,UnitOfMeasureStr[UnitOfMeasure_V]);
  6621. }
  6622. //====================== Start SoC ================================
  6623. if(strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, MeasurandStr[SoC]) != NULL)
  6624. {
  6625. //J : CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  6626. if((gunType[gun_index] == GUN_TYPE_CHAdeMO)||(gunType[gun_index] == GUN_TYPE_CCS)||(gunType[gun_index] == GUN_TYPE_GBT)||(gunType[gun_index] == GUN_TYPE_DO))
  6627. {
  6628. if((ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0') && (gunType[gun_index] != GUN_TYPE_DO))
  6629. {
  6630. tempIndex = ((gun_index==2) ? 1: 0);
  6631. }
  6632. else
  6633. {
  6634. tempIndex = gun_index;
  6635. }
  6636. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  6637. {
  6638. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  6639. {
  6640. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  6641. {
  6642. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].EvBatteryStartSoc );// 0~100%
  6643. }
  6644. }
  6645. }
  6646. else if(gunType[gun_index] == GUN_TYPE_CCS)
  6647. {
  6648. for (int index = 0; index < CCS_QUANTITY; index++)
  6649. {
  6650. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  6651. {
  6652. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].EvBatteryStartSoc );// 0~100%
  6653. }
  6654. }
  6655. }
  6656. else if(gunType[gun_index] == GUN_TYPE_GBT)
  6657. {
  6658. for (int index = 0; index < GB_QUANTITY; index++)
  6659. {
  6660. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  6661. {
  6662. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].EvBatteryStartSoc );// 0~100%
  6663. }
  6664. }
  6665. }
  6666. else if(gunType[gun_index] == GUN_TYPE_DO)
  6667. {
  6668. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  6669. {
  6670. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  6671. {
  6672. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.EvBatteryStartSoc );// 0~100%
  6673. }
  6674. }
  6675. }
  6676. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Context,ReadingContextStr[ReadingContext_Transaction_Begin]);
  6677. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Format,ValueFormatStr[Raw]);
  6678. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Measurand,MeasurandStr[SoC/*Energy_Reactive_Export_Register*/]);
  6679. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Phase,PhaseStr[L3_N]);
  6680. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Location,LocationStr[Location_EV]);
  6681. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Unit,UnitOfMeasureStr[UnitOfMeasure_Percent/*UnitOfMeasure_kWh*/]);
  6682. } // END FOR DC CASE
  6683. }
  6684. //================================================ Message create ====================================================
  6685. json_object *StopTransaction = json_object_new_object();
  6686. json_object *transactionDatas = json_object_new_array();
  6687. json_object *sampledValues = json_object_new_array();
  6688. if(strlen((char*)ShmOCPP16Data->StopTransaction[gun_index].IdTag) > 0)
  6689. json_object_object_add(StopTransaction, "idTag", json_object_new_string((char*)ShmOCPP16Data->StopTransaction[gun_index].IdTag));
  6690. json_object_object_add(StopTransaction, "meterStop", json_object_new_int(ShmOCPP16Data->StopTransaction[gun_index].MeterStop));
  6691. json_object_object_add(StopTransaction, "transactionId", json_object_new_int(ShmOCPP16Data->StopTransaction[gun_index].TransactionId));
  6692. json_object_object_add(StopTransaction, "timestamp", json_object_new_string((char*)ShmOCPP16Data->StopTransaction[gun_index].Timestamp));
  6693. if(strlen((char*)ShmOCPP16Data->StopTransaction[gun_index].StopReason) > 0)
  6694. json_object_object_add(StopTransaction, "reason", json_object_new_string((char*)ShmOCPP16Data->StopTransaction[gun_index].StopReason));
  6695. for(int idxTrans = 0;idxTrans<ARRAY_SIZE(ShmOCPP16Data->StopTransaction[gun_index].TransactionData);idxTrans++)
  6696. {
  6697. json_object *transactionData = json_object_new_object();
  6698. json_object_object_add(transactionData, "timestamp", json_object_new_string((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].TimeStamp));
  6699. for(int idx=0;idx<ARRAY_SIZE(ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue);idx++)
  6700. {
  6701. if(strlen((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Value) > 0)
  6702. {
  6703. json_object *sampledValue = json_object_new_object();
  6704. json_object_object_add(sampledValue, "value", json_object_new_string((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Value));
  6705. if(strlen((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Context) > 0)
  6706. json_object_object_add(sampledValue, "context", json_object_new_string((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Context));
  6707. if(strlen((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Format) > 0)
  6708. json_object_object_add(sampledValue, "format", json_object_new_string((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Format));
  6709. if(strlen((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Measurand) > 0)
  6710. json_object_object_add(sampledValue, "measurand", json_object_new_string((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Measurand));
  6711. if(strlen((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Phase) > 0)
  6712. json_object_object_add(sampledValue, "phase", json_object_new_string((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Phase));
  6713. if(strlen((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Location) > 0)
  6714. json_object_object_add(sampledValue, "location", json_object_new_string((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Location));
  6715. if(strlen((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Unit) > 0)
  6716. json_object_object_add(sampledValue, "unit", json_object_new_string((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Unit));
  6717. json_object_array_add(sampledValues, sampledValue);
  6718. }
  6719. }
  6720. json_object_object_add(transactionData, "sampledValue", sampledValues);
  6721. json_object_array_add(transactionDatas, transactionData);
  6722. }
  6723. json_object_object_add(StopTransaction, "transactionData", transactionDatas);
  6724. sprintf(queuedata, "%d,[%d,\"%s\",\"StopTransaction\",%s]",(gun_index+1)
  6725. ,MESSAGE_TYPE_CALL
  6726. ,guid
  6727. ,json_object_to_json_string_ext(StopTransaction, JSON_C_TO_STRING_PLAIN));
  6728. json_object_put(StopTransaction);
  6729. #if 1 // for TempStopTransaction
  6730. //Delete TempStopTransaction
  6731. if((access(TempStopTransaction,F_OK))!=-1)
  6732. {
  6733. remove(TempStopTransaction); // remove file "TempStopTransaction"
  6734. }
  6735. #endif
  6736. #if 1
  6737. sprintf(tempdata, "StopTransaction,%d", (gun_index));
  6738. if(hashmap_operation(HASH_OP_ADD, guid, tempdata) == 1)
  6739. {
  6740. result = PASS;
  6741. //DEBUG_INFO("StopTransaction mapitem pass\n");
  6742. }
  6743. #endif
  6744. queue_operation(QUEUE_OPERATION_ADD, guid, queuedata );//addq(guid, queuedata); ---> remove temporally
  6745. OCPP_insert_transaction_msg(NO, queuedata);
  6746. //----------------------------replace queue StopTransaction TransactionId ---------------------------//
  6747. //int gettransactionId = GetTransactionId(gun_index+1, ShmOCPP16Data->StopTransaction[gun_index].IdTag);
  6748. int gettransactionId = GetTransactionId(gun_index+1, ShmOCPP16Data->StartTransaction[gun_index].IdTag, TRUE);
  6749. if((ShmOCPP16Data->StopTransaction[gun_index].TransactionId != 0) && (gettransactionId != 0))
  6750. {
  6751. //SetTransactionIdZero(ShmOCPP16Data->StopTransaction[gun_index].TransactionId);
  6752. }
  6753. //for test
  6754. //ShmOCPP16Data->CpMsg.bits[gun_index].StopTransactionReq = 0;
  6755. return result;
  6756. }
  6757. int sendMeterValuesRequest(int gun_index, ReadingContext dataType)
  6758. {
  6759. mtrace();
  6760. int result = FAIL;
  6761. char guid[37]={0};
  6762. char tempdata[65]={0};
  6763. int tempIndex = 0;
  6764. DEBUG_INFO("sendMeterValuesRequest ...\n");
  6765. memset(queuedata, 0, ARRAY_SIZE(queuedata));
  6766. memset(&ShmOCPP16Data->MeterValues[gun_index], 0, sizeof(struct StructMeterValues));
  6767. //set value
  6768. ShmOCPP16Data->MeterValues[gun_index].ConnectorId = gun_index + 1; // gun start from 1~
  6769. ShmOCPP16Data->MeterValues[gun_index].TransactionId = (cpinitateMsg.bits[gun_index].isOnCharging?
  6770. ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId :
  6771. -1);
  6772. random_uuid(guid);
  6773. //UTC Date time
  6774. struct timeval tmnow;
  6775. struct tm *tm;
  6776. char buf[28];//, usec_buf[6];
  6777. gettimeofday(&tmnow, NULL);
  6778. time_t t;
  6779. t = time(NULL);
  6780. /*UTC time and date*/
  6781. tm = gmtime(&t);
  6782. if(dataType == ReadingContext_Sample_Clock)
  6783. {
  6784. struct tm *tmTarget;
  6785. struct timeb tbTarget;
  6786. tbTarget.time = mktime(tm);
  6787. tbTarget.time -= (atoi((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemData));
  6788. tmTarget = gmtime(&tbTarget.time);
  6789. strftime(buf,28,"%Y-%m-%dT%H:%M:%SZ", tmTarget);
  6790. }
  6791. else
  6792. {
  6793. strftime(buf,28,"%Y-%m-%dT%H:%M:%SZ", tm);
  6794. }
  6795. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].TimeStamp, buf);
  6796. //DEBUG_INFO("ShmSysConfigAndInfo->SysConfig.ModelName[0]=%c\n", ShmSysConfigAndInfo->SysConfig.ModelName[0]);
  6797. //********************************(1)Current.Import L1************************************************/
  6798. if(((dataType == ReadingContext_Sample_Clock) && (strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, MeasurandStr[Current_Import]) != NULL)) ||
  6799. ((dataType == ReadingContext_Sample_Periodic) && (strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, MeasurandStr[Current_Import]) != NULL)) ||
  6800. (dataType == ReadingContext_Trigger))
  6801. {
  6802. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  6803. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  6804. {
  6805. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  6806. {
  6807. tempIndex = ((gun_index==2) ? 1: 0);
  6808. }
  6809. else
  6810. {
  6811. tempIndex = gun_index;
  6812. }
  6813. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  6814. {
  6815. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  6816. {
  6817. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargingCurrent );
  6818. }
  6819. }
  6820. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Phase, PhaseStr[L3_N]);
  6821. }
  6822. else if(gunType[gun_index] == GUN_TYPE_CCS)
  6823. {
  6824. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  6825. {
  6826. tempIndex = ((gun_index==2) ? 1: 0);
  6827. }
  6828. else
  6829. {
  6830. tempIndex = gun_index;
  6831. }
  6832. for (int index = 0; index < CCS_QUANTITY; index++)
  6833. {
  6834. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  6835. {
  6836. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargingCurrent );
  6837. }
  6838. }
  6839. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Phase, PhaseStr[L3_N]);
  6840. }
  6841. else if(gunType[gun_index] == GUN_TYPE_GBT)
  6842. {
  6843. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  6844. {
  6845. tempIndex = ((gun_index==2) ? 1: 0);
  6846. }
  6847. else
  6848. {
  6849. tempIndex = gun_index;
  6850. }
  6851. for (int index = 0; index < GB_QUANTITY; index++)
  6852. {
  6853. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  6854. {
  6855. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingCurrent );
  6856. }
  6857. }
  6858. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Phase, PhaseStr[L3_N]);
  6859. }
  6860. else if(gunType[gun_index] == GUN_TYPE_DO)
  6861. {
  6862. tempIndex = gun_index;
  6863. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  6864. {
  6865. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  6866. {
  6867. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PresentChargingCurrent );
  6868. }
  6869. }
  6870. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Phase, PhaseStr[L3_N]);
  6871. }
  6872. else
  6873. {
  6874. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  6875. {
  6876. tempIndex = 2;
  6877. }
  6878. else
  6879. {
  6880. tempIndex = gun_index;
  6881. }
  6882. for (int index = 0; index < AC_QUANTITY; index++)
  6883. {
  6884. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  6885. {
  6886. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingCurrent );
  6887. }
  6888. }
  6889. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Phase, PhaseStr[L1_N]);
  6890. }
  6891. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Context, ReadingContextStr[dataType]);
  6892. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Format, ValueFormatStr[Raw]);
  6893. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Measurand, MeasurandStr[Current_Import]);
  6894. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Location, LocationStr[Location_Outlet]);
  6895. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Unit,UnitOfMeasureStr[UnitOfMeasure_A]);
  6896. }
  6897. //********************************(2)Energy.Active.Import.Register ************************************************/
  6898. if(((dataType == ReadingContext_Sample_Clock) && (strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, MeasurandStr[Energy_Active_Import_Register]) != NULL)) ||
  6899. ((dataType == ReadingContext_Sample_Periodic) && (strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, MeasurandStr[Energy_Active_Import_Register]) != NULL)) ||
  6900. (dataType == ReadingContext_Trigger))
  6901. {
  6902. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  6903. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  6904. {
  6905. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  6906. {
  6907. tempIndex = ((gun_index==2) ? 1: 0);
  6908. }
  6909. else
  6910. {
  6911. tempIndex = gun_index;
  6912. }
  6913. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  6914. {
  6915. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  6916. {
  6917. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PowerConsumption );
  6918. }
  6919. }
  6920. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Phase, PhaseStr[L3_N]);
  6921. }
  6922. else if(gunType[gun_index] == GUN_TYPE_CCS)
  6923. {
  6924. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  6925. {
  6926. tempIndex = ((gun_index==2) ? 1: 0);
  6927. }
  6928. else
  6929. {
  6930. tempIndex = gun_index;
  6931. }
  6932. for (int index = 0; index < CCS_QUANTITY; index++)
  6933. {
  6934. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  6935. {
  6936. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PowerConsumption );
  6937. }
  6938. }
  6939. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Phase, PhaseStr[L3_N]);
  6940. }
  6941. else if(gunType[gun_index] == GUN_TYPE_GBT)
  6942. {
  6943. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  6944. {
  6945. tempIndex = ((gun_index==2) ? 1: 0);
  6946. }
  6947. else
  6948. {
  6949. tempIndex = gun_index;
  6950. }
  6951. for (int index = 0; index < GB_QUANTITY; index++)
  6952. {
  6953. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  6954. {
  6955. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PowerConsumption );
  6956. }
  6957. }
  6958. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Phase, PhaseStr[L3_N]);
  6959. }
  6960. else if(gunType[gun_index] == GUN_TYPE_DO)
  6961. {
  6962. tempIndex = gun_index;
  6963. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  6964. {
  6965. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  6966. {
  6967. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PowerConsumption );
  6968. }
  6969. }
  6970. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Phase, PhaseStr[L3_N]);
  6971. }
  6972. else
  6973. {
  6974. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  6975. {
  6976. tempIndex = 2;
  6977. }
  6978. else
  6979. {
  6980. tempIndex = gun_index;
  6981. }
  6982. for (int index = 0; index < AC_QUANTITY; index++)
  6983. {
  6984. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  6985. {
  6986. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PowerConsumption );
  6987. }
  6988. }
  6989. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Phase, PhaseStr[L1_N]);
  6990. }
  6991. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Context, ReadingContextStr[dataType]);
  6992. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Format, ValueFormatStr[Raw]);
  6993. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Measurand, MeasurandStr[Energy_Active_Import_Register]);
  6994. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Location, LocationStr[Location_Outlet]);
  6995. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Unit,UnitOfMeasureStr[UnitOfMeasure_kWh]);
  6996. }
  6997. //****************************************************(3)Energy.Active.Import.Interval*********************************************/
  6998. if(((dataType == ReadingContext_Sample_Clock) && (strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, MeasurandStr[Energy_Active_Import_Interval]) != NULL)) ||
  6999. ((dataType == ReadingContext_Sample_Periodic) && (strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, MeasurandStr[Energy_Active_Import_Interval]) != NULL)) ||
  7000. (dataType == ReadingContext_Trigger))
  7001. {
  7002. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  7003. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  7004. {
  7005. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  7006. {
  7007. tempIndex = ((gun_index==2) ? 1: 0);
  7008. }
  7009. else
  7010. {
  7011. tempIndex = gun_index;
  7012. }
  7013. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  7014. {
  7015. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  7016. {
  7017. if(dataType == ReadingContext_Sample_Clock)
  7018. {
  7019. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Value, "%.3f" ,(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PowerConsumption - periousClockPowerConsumption[gun_index]));
  7020. periousClockPowerConsumption[gun_index] = ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PowerConsumption;
  7021. }
  7022. else if(dataType == ReadingContext_Sample_Periodic)
  7023. {
  7024. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Value, "%.3f" ,(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PowerConsumption - periousPeriodicPowerConsumption[gun_index]));
  7025. periousPeriodicPowerConsumption[gun_index] = ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PowerConsumption;
  7026. }
  7027. else
  7028. {
  7029. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Value, "0.000");
  7030. }
  7031. }
  7032. } // END OF FOR CHAdeMO_QUANTITY
  7033. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Phase, PhaseStr[L3_N]);
  7034. }
  7035. else if(gunType[gun_index] == GUN_TYPE_CCS)
  7036. {
  7037. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  7038. {
  7039. tempIndex = ((gun_index==2) ? 1: 0);
  7040. }
  7041. else
  7042. {
  7043. tempIndex = gun_index;
  7044. }
  7045. for (int index = 0; index < CCS_QUANTITY; index++)
  7046. {
  7047. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  7048. {
  7049. if(dataType == ReadingContext_Sample_Clock)
  7050. {
  7051. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Value, "%.3f" ,(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PowerConsumption - periousClockPowerConsumption[gun_index]));
  7052. periousClockPowerConsumption[gun_index] = ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PowerConsumption;
  7053. }
  7054. else if(dataType == ReadingContext_Sample_Periodic)
  7055. {
  7056. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Value, "%.3f" ,(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PowerConsumption - periousPeriodicPowerConsumption[gun_index]));
  7057. periousPeriodicPowerConsumption[gun_index] = ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PowerConsumption;
  7058. }
  7059. else
  7060. {
  7061. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Value, "0.000");
  7062. }
  7063. }
  7064. } // END OF CCS_QUANTITY
  7065. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Phase, PhaseStr[L3_N]);
  7066. }
  7067. else if(gunType[gun_index] == GUN_TYPE_GBT)
  7068. {
  7069. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  7070. {
  7071. tempIndex = ((gun_index==2) ? 1: 0);
  7072. }
  7073. else
  7074. {
  7075. tempIndex = gun_index;
  7076. }
  7077. for (int index = 0; index < GB_QUANTITY; index++)
  7078. {
  7079. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  7080. {
  7081. if(dataType == ReadingContext_Sample_Clock)
  7082. {
  7083. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Value, "%.3f" ,(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PowerConsumption - periousClockPowerConsumption[gun_index]));
  7084. periousClockPowerConsumption[gun_index] = ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PowerConsumption;
  7085. }
  7086. else if(dataType == ReadingContext_Sample_Periodic)
  7087. {
  7088. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Value, "%.3f" ,(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PowerConsumption - periousPeriodicPowerConsumption[gun_index]));
  7089. periousPeriodicPowerConsumption[gun_index] = ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PowerConsumption;
  7090. }
  7091. else
  7092. {
  7093. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Value, "0.000");
  7094. }
  7095. }
  7096. } // END OF GB_QUANTITY
  7097. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Phase, PhaseStr[L3_N]);
  7098. }
  7099. else if(gunType[gun_index] == GUN_TYPE_DO)
  7100. {
  7101. tempIndex = gun_index;
  7102. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  7103. {
  7104. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  7105. {
  7106. if(dataType == ReadingContext_Sample_Clock)
  7107. {
  7108. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Value, "%.3f" ,(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PowerConsumption - periousClockPowerConsumption[gun_index]));
  7109. periousClockPowerConsumption[gun_index] = ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PowerConsumption;
  7110. }
  7111. else if(dataType == ReadingContext_Sample_Periodic)
  7112. {
  7113. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Value, "%.3f" ,(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PowerConsumption - periousPeriodicPowerConsumption[gun_index]));
  7114. periousPeriodicPowerConsumption[gun_index] = ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PowerConsumption;
  7115. }
  7116. else
  7117. {
  7118. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Value, "0.000");
  7119. }
  7120. }
  7121. }
  7122. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Phase, PhaseStr[L3_N]);
  7123. }
  7124. else
  7125. {
  7126. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  7127. {
  7128. tempIndex = 2;
  7129. }
  7130. else
  7131. {
  7132. tempIndex = gun_index;
  7133. }
  7134. for (int index = 0; index < AC_QUANTITY; index++)
  7135. {
  7136. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  7137. {
  7138. if(dataType == ReadingContext_Sample_Clock)
  7139. {
  7140. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Value, "%.3f" ,(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PowerConsumption - periousClockPowerConsumption[gun_index]));
  7141. periousClockPowerConsumption[gun_index] = ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PowerConsumption;
  7142. }
  7143. else if(dataType == ReadingContext_Sample_Periodic)
  7144. {
  7145. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Value, "%.3f" ,(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PowerConsumption - periousPeriodicPowerConsumption[gun_index]));
  7146. periousPeriodicPowerConsumption[gun_index] = ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PowerConsumption;
  7147. }
  7148. else
  7149. {
  7150. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Value, "0.000");
  7151. }
  7152. }
  7153. }
  7154. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Phase, PhaseStr[L1_N]);
  7155. }
  7156. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Context, ReadingContextStr[dataType]);
  7157. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Format, ValueFormatStr[Raw]);
  7158. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Measurand, MeasurandStr[Energy_Active_Import_Interval]);
  7159. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Location, LocationStr[Location_Outlet]);
  7160. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Unit,UnitOfMeasureStr[UnitOfMeasure_kWh]);
  7161. }
  7162. //********************************(4)Power.Active.Import************************************************/
  7163. if(((dataType == ReadingContext_Sample_Clock) && (strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, MeasurandStr[Power_Active_Import]) != NULL)) ||
  7164. ((dataType == ReadingContext_Sample_Periodic) && (strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, MeasurandStr[Power_Active_Import]) != NULL)) ||
  7165. (dataType == ReadingContext_Trigger))
  7166. {
  7167. //J : CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  7168. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  7169. {
  7170. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  7171. {
  7172. tempIndex = ((gun_index==2) ? 1: 0);
  7173. }
  7174. else
  7175. {
  7176. tempIndex = gun_index;
  7177. }
  7178. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  7179. {
  7180. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  7181. {
  7182. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Value, "%.1f" , ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargingPower);
  7183. }
  7184. } // END OF FOR
  7185. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Phase, PhaseStr[L3_N]);
  7186. }
  7187. else if(gunType[gun_index] == GUN_TYPE_CCS)
  7188. {
  7189. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  7190. {
  7191. tempIndex = ((gun_index==2) ? 1: 0);
  7192. }
  7193. else
  7194. {
  7195. tempIndex = gun_index;
  7196. }
  7197. for (int index = 0; index < CCS_QUANTITY; index++)
  7198. {
  7199. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  7200. {
  7201. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Value, "%.1f" , ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargingPower);
  7202. }
  7203. }
  7204. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Phase, PhaseStr[L3_N]);
  7205. }
  7206. else if(gunType[gun_index] == GUN_TYPE_GBT)
  7207. {
  7208. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  7209. {
  7210. tempIndex = ((gun_index==2) ? 1: 0);
  7211. }
  7212. else
  7213. {
  7214. tempIndex = gun_index;
  7215. }
  7216. for (int index = 0; index < GB_QUANTITY; index++)
  7217. {
  7218. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  7219. {
  7220. //ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingPower = 100.0;
  7221. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Value, "%.1f" , ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingPower);
  7222. }
  7223. }
  7224. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Phase, PhaseStr[L3_N]);
  7225. }
  7226. else if(gunType[gun_index] == GUN_TYPE_DO)
  7227. {
  7228. tempIndex = gun_index;
  7229. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  7230. {
  7231. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  7232. {
  7233. //ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingPower = 100.0;
  7234. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Value, "%.1f" , ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PresentChargingPower);
  7235. }
  7236. }
  7237. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Phase, PhaseStr[L3_N]);
  7238. }
  7239. else
  7240. {
  7241. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  7242. {
  7243. tempIndex = 2;
  7244. }
  7245. else
  7246. {
  7247. tempIndex = gun_index;
  7248. }
  7249. for (int index = 0; index < AC_QUANTITY; index++)
  7250. {
  7251. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  7252. {
  7253. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Value, "%.1f" , ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingPower);
  7254. }
  7255. }
  7256. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Phase, PhaseStr[L1_N]);
  7257. }
  7258. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Context, ReadingContextStr[dataType]);
  7259. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Format, ValueFormatStr[Raw]);
  7260. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Measurand, MeasurandStr[Power_Active_Import]);
  7261. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Location, LocationStr[Location_Outlet]);
  7262. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Unit,UnitOfMeasureStr[UnitOfMeasure_kW]);
  7263. }
  7264. //***********************************************(5)VOLTAGE L1******************************************************/
  7265. if(((dataType == ReadingContext_Sample_Clock) && (strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, MeasurandStr[Voltage]) != NULL)) ||
  7266. ((dataType == ReadingContext_Sample_Periodic) && (strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, MeasurandStr[Voltage]) != NULL)) ||
  7267. (dataType == ReadingContext_Trigger))
  7268. {
  7269. //J : CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  7270. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  7271. {
  7272. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  7273. {
  7274. tempIndex = ((gun_index==2) ? 1: 0);
  7275. }
  7276. else
  7277. {
  7278. tempIndex = gun_index;
  7279. }
  7280. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  7281. {
  7282. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  7283. {
  7284. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargingVoltage );
  7285. }
  7286. }
  7287. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Phase, PhaseStr[L3_N]);
  7288. }
  7289. else if(gunType[gun_index] == GUN_TYPE_CCS)
  7290. {
  7291. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  7292. {
  7293. tempIndex = ((gun_index==2) ? 1: 0);
  7294. }
  7295. else
  7296. {
  7297. tempIndex = gun_index;
  7298. }
  7299. for (int index = 0; index < CCS_QUANTITY; index++)
  7300. {
  7301. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  7302. {
  7303. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargingVoltage );
  7304. }
  7305. }
  7306. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Phase, PhaseStr[L3_N]);
  7307. }
  7308. else if(gunType[gun_index] == GUN_TYPE_GBT)
  7309. {
  7310. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  7311. {
  7312. tempIndex = ((gun_index==2) ? 1: 0);
  7313. }
  7314. else
  7315. {
  7316. tempIndex = gun_index;
  7317. }
  7318. for (int index = 0; index < GB_QUANTITY; index++)
  7319. {
  7320. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  7321. {
  7322. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingVoltage );
  7323. }
  7324. }
  7325. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Phase, PhaseStr[L3_N]);
  7326. }
  7327. else if(gunType[gun_index] == GUN_TYPE_DO)
  7328. {
  7329. tempIndex = gun_index;
  7330. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  7331. {
  7332. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  7333. {
  7334. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PresentChargingVoltage );
  7335. }
  7336. }
  7337. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Phase, PhaseStr[L3_N]);
  7338. }
  7339. else
  7340. {
  7341. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  7342. {
  7343. tempIndex = 2;
  7344. }
  7345. else
  7346. {
  7347. tempIndex = gun_index;
  7348. }
  7349. for (int index = 0; index < AC_QUANTITY; index++)
  7350. {
  7351. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  7352. {
  7353. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingVoltage );
  7354. }
  7355. }
  7356. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Phase, PhaseStr[L1_N]);
  7357. }
  7358. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Context, ReadingContextStr[dataType]);
  7359. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Format, ValueFormatStr[Raw]);
  7360. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Measurand, MeasurandStr[Voltage]);
  7361. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Location, LocationStr[Location_Outlet]);
  7362. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Unit,UnitOfMeasureStr[UnitOfMeasure_V]);
  7363. }
  7364. //***********************************************(6)SOC******************************************************/
  7365. if(((dataType == ReadingContext_Sample_Clock) && (strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, MeasurandStr[SoC]) != NULL)) ||
  7366. ((dataType == ReadingContext_Sample_Periodic) && (strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, MeasurandStr[SoC]) != NULL)) ||
  7367. (dataType == ReadingContext_Trigger))
  7368. {
  7369. if((gunType[gun_index] == GUN_TYPE_CHAdeMO)||(gunType[gun_index] == GUN_TYPE_CCS)||(gunType[gun_index] == GUN_TYPE_GBT)||(gunType[gun_index] == GUN_TYPE_DO))
  7370. {
  7371. //idx_sample=5;
  7372. //sampledValue = NULL;
  7373. if((ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0') && (gunType[gun_index] != GUN_TYPE_DO))
  7374. {
  7375. tempIndex = ((gun_index==2) ? 1: 0);
  7376. }
  7377. else
  7378. {
  7379. tempIndex = gun_index;
  7380. }
  7381. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  7382. {
  7383. //tempIndex = ((gun_index==2) ? 1: 0);
  7384. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  7385. {
  7386. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  7387. {
  7388. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].EvBatterySoc );
  7389. }
  7390. }
  7391. }
  7392. else if(gunType[gun_index] == GUN_TYPE_CCS)
  7393. {
  7394. //tempIndex = ((gun_index==2) ? 1: 0);
  7395. for (int index = 0; index < CCS_QUANTITY; index++)
  7396. {
  7397. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  7398. {
  7399. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].EvBatterySoc );
  7400. }
  7401. }
  7402. }
  7403. else if(gunType[gun_index] == GUN_TYPE_GBT)
  7404. {
  7405. //tempIndex = ((gun_index==2) ? 1: 0);
  7406. for (int index = 0; index < GB_QUANTITY; index++)
  7407. {
  7408. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  7409. {
  7410. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].EvBatterySoc );
  7411. }
  7412. }
  7413. }
  7414. else if(gunType[gun_index] == GUN_TYPE_DO)
  7415. {
  7416. //tempIndex = ((gun_index==2) ? 1: 0);
  7417. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  7418. {
  7419. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  7420. {
  7421. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.EvBatterySoc );
  7422. }
  7423. }
  7424. }
  7425. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[5].Context, ReadingContextStr[dataType]);
  7426. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[5].Format, ValueFormatStr[Raw]);
  7427. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[5].Measurand, MeasurandStr[SoC]);
  7428. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[5].Phase, PhaseStr[L3_N]);
  7429. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[5].Location, LocationStr[Location_EV]);
  7430. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[5].Unit,UnitOfMeasureStr[UnitOfMeasure_Percent]);
  7431. }
  7432. }
  7433. //********************************(7)Current.Import L2************************************************/
  7434. if(((dataType == ReadingContext_Sample_Clock) && (strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, MeasurandStr[Current_Import]) != NULL)) ||
  7435. ((dataType == ReadingContext_Sample_Periodic) && (strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, MeasurandStr[Current_Import]) != NULL)) ||
  7436. (dataType == ReadingContext_Trigger))
  7437. {
  7438. // Only for AC 3 phase
  7439. if((gunType[gun_index] == GUN_TYPE_AC) && ((ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'W') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='D')))
  7440. {
  7441. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  7442. {
  7443. tempIndex = 2;
  7444. }
  7445. else
  7446. {
  7447. tempIndex = gun_index;
  7448. }
  7449. for (int index = 0; index < AC_QUANTITY; index++)
  7450. {
  7451. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  7452. {
  7453. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[6].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingCurrentL2);
  7454. }
  7455. }
  7456. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[6].Phase, PhaseStr[L2_N]);
  7457. }
  7458. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[6].Context, ReadingContextStr[dataType]);
  7459. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[6].Format, ValueFormatStr[Raw]);
  7460. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[6].Measurand, MeasurandStr[Current_Import]);
  7461. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[6].Location, LocationStr[Location_Outlet]);
  7462. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[6].Unit,UnitOfMeasureStr[UnitOfMeasure_A]);
  7463. }
  7464. //********************************(8)Current.Import L3************************************************/
  7465. if(((dataType == ReadingContext_Sample_Clock) && (strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, MeasurandStr[Current_Import]) != NULL)) ||
  7466. ((dataType == ReadingContext_Sample_Periodic) && (strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, MeasurandStr[Current_Import]) != NULL)) ||
  7467. (dataType == ReadingContext_Trigger))
  7468. {
  7469. // Only for AC 3 phase
  7470. if((gunType[gun_index] == GUN_TYPE_AC) && ((ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'W') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='D')))
  7471. {
  7472. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  7473. {
  7474. tempIndex = 2;
  7475. }
  7476. else
  7477. {
  7478. tempIndex = gun_index;
  7479. }
  7480. for (int index = 0; index < AC_QUANTITY; index++)
  7481. {
  7482. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  7483. {
  7484. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[7].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingCurrentL3);
  7485. }
  7486. }
  7487. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[7].Phase, PhaseStr[L3_N]);
  7488. }
  7489. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[7].Context, ReadingContextStr[dataType]);
  7490. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[7].Format, ValueFormatStr[Raw]);
  7491. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[7].Measurand, MeasurandStr[Current_Import]);
  7492. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[7].Location, LocationStr[Location_Outlet]);
  7493. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[7].Unit,UnitOfMeasureStr[UnitOfMeasure_A]);
  7494. }
  7495. //***********************************************(9)VOLTAGE L2******************************************************/
  7496. if(((dataType == ReadingContext_Sample_Clock) && (strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, MeasurandStr[Voltage]) != NULL)) ||
  7497. ((dataType == ReadingContext_Sample_Periodic) && (strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, MeasurandStr[Voltage]) != NULL)) ||
  7498. (dataType == ReadingContext_Trigger))
  7499. {
  7500. if((gunType[gun_index] == GUN_TYPE_AC) && ((ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'W') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='D')))
  7501. {
  7502. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  7503. {
  7504. tempIndex = 2;
  7505. }
  7506. else
  7507. {
  7508. tempIndex = gun_index;
  7509. }
  7510. for (int index = 0; index < AC_QUANTITY; index++)
  7511. {
  7512. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  7513. {
  7514. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[8].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingVoltageL2);
  7515. }
  7516. }
  7517. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[8].Phase, PhaseStr[L2_N]);
  7518. }
  7519. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[8].Context, ReadingContextStr[dataType]);
  7520. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[8].Format, ValueFormatStr[Raw]);
  7521. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[8].Measurand, MeasurandStr[Voltage]);
  7522. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[8].Location, LocationStr[Location_Outlet]);
  7523. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[8].Unit,UnitOfMeasureStr[UnitOfMeasure_V]);
  7524. }
  7525. //***********************************************(10)VOLTAGE L3******************************************************/
  7526. if(((dataType == ReadingContext_Sample_Clock) && (strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, MeasurandStr[Voltage]) != NULL)) ||
  7527. ((dataType == ReadingContext_Sample_Periodic) && (strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, MeasurandStr[Voltage]) != NULL)) ||
  7528. (dataType == ReadingContext_Trigger))
  7529. {
  7530. if((gunType[gun_index] == GUN_TYPE_AC) && ((ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'W') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='D')))
  7531. {
  7532. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  7533. {
  7534. tempIndex = 2;
  7535. }
  7536. else
  7537. {
  7538. tempIndex = gun_index;
  7539. }
  7540. for (int index = 0; index < AC_QUANTITY; index++)
  7541. {
  7542. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  7543. {
  7544. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[9].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingVoltageL3);
  7545. }
  7546. }
  7547. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[9].Phase, PhaseStr[L3_N]);
  7548. }
  7549. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[9].Context, ReadingContextStr[dataType]);
  7550. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[9].Format, ValueFormatStr[Raw]);
  7551. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[9].Measurand, MeasurandStr[Voltage]);
  7552. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[9].Location, LocationStr[Location_Outlet]);
  7553. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[9].Unit,UnitOfMeasureStr[UnitOfMeasure_V]);
  7554. }
  7555. //***********************************************(11)Current.Offered******************************************************/
  7556. if(((dataType == ReadingContext_Sample_Clock) && (strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, MeasurandStr[Current_Offered]) != NULL)) ||
  7557. ((dataType == ReadingContext_Sample_Periodic) && (strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, MeasurandStr[Current_Offered]) != NULL)) ||
  7558. (dataType == ReadingContext_Trigger))
  7559. {
  7560. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  7561. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  7562. {
  7563. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  7564. {
  7565. tempIndex = ((gun_index==2) ? 1: 0);
  7566. }
  7567. else
  7568. {
  7569. tempIndex = gun_index;
  7570. }
  7571. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  7572. {
  7573. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  7574. {
  7575. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[10].Value, "%d", (uint16_t) (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].CurrentOffered/10));
  7576. }
  7577. } // END OF FOR CHAdeMO_QUANTITY
  7578. }
  7579. else if(gunType[gun_index] == GUN_TYPE_CCS)
  7580. {
  7581. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  7582. {
  7583. tempIndex = ((gun_index==2) ? 1: 0);
  7584. }
  7585. else
  7586. {
  7587. tempIndex = gun_index;
  7588. }
  7589. for (int index = 0; index < CCS_QUANTITY; index++)
  7590. {
  7591. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  7592. {
  7593. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[10].Value, "%d", (uint16_t) (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].CurrentOffered/10));
  7594. }
  7595. } // END OF CCS_QUANTITY
  7596. }
  7597. else if(gunType[gun_index] == GUN_TYPE_GBT)
  7598. {
  7599. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  7600. {
  7601. tempIndex = ((gun_index==2) ? 1: 0);
  7602. }
  7603. else
  7604. {
  7605. tempIndex = gun_index;
  7606. }
  7607. for (int index = 0; index < GB_QUANTITY; index++)
  7608. {
  7609. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  7610. {
  7611. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[10].Value, "%d", (uint16_t) (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].CurrentOffered/10));
  7612. }
  7613. } // END OF GB_QUANTITY
  7614. }
  7615. else if(gunType[gun_index] == GUN_TYPE_DO)
  7616. {
  7617. tempIndex = gun_index;
  7618. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  7619. {
  7620. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  7621. {
  7622. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[10].Value, "%d", (uint16_t) (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.CurrentOffered/10));
  7623. }
  7624. }
  7625. }
  7626. else
  7627. {
  7628. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  7629. {
  7630. tempIndex = 2;
  7631. }
  7632. else
  7633. {
  7634. tempIndex = gun_index;
  7635. }
  7636. for (int index = 0; index < AC_QUANTITY; index++)
  7637. {
  7638. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  7639. {
  7640. uint16_t currentOffer;
  7641. if(ShmSysConfigAndInfo->SysConfig.MaxChargingCurrent == 0)
  7642. {
  7643. currentOffer = ShmSysConfigAndInfo->SysConfig.RatingCurrent;
  7644. }
  7645. else
  7646. {
  7647. currentOffer = ((ShmSysConfigAndInfo->SysConfig.MaxChargingCurrent>ShmSysConfigAndInfo->SysConfig.RatingCurrent)?ShmSysConfigAndInfo->SysConfig.RatingCurrent:ShmSysConfigAndInfo->SysConfig.MaxChargingCurrent);
  7648. }
  7649. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[10].Value, "%d", currentOffer);
  7650. }
  7651. }
  7652. }
  7653. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[10].Context, ReadingContextStr[dataType]);
  7654. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[10].Format, ValueFormatStr[Raw]);
  7655. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[10].Measurand, MeasurandStr[Current_Offered]);
  7656. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[10].Location, LocationStr[Location_Outlet]);
  7657. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[10].Unit,UnitOfMeasureStr[UnitOfMeasure_A]);
  7658. }
  7659. //***********************************************(12)Power.Offered******************************************************/
  7660. if(((dataType == ReadingContext_Sample_Clock) && (strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, MeasurandStr[Power_Offered]) != NULL) && (gunType[gun_index] != GUN_TYPE_AC)) ||
  7661. ((dataType == ReadingContext_Sample_Periodic) && (strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, MeasurandStr[Power_Offered]) != NULL) && (gunType[gun_index] != GUN_TYPE_AC)) ||
  7662. ((dataType == ReadingContext_Trigger) && (gunType[gun_index] != GUN_TYPE_AC)))
  7663. {
  7664. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  7665. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  7666. {
  7667. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  7668. {
  7669. tempIndex = ((gun_index==2) ? 1: 0);
  7670. }
  7671. else
  7672. {
  7673. tempIndex = gun_index;
  7674. }
  7675. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  7676. {
  7677. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  7678. {
  7679. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[11].Value, "%d", (uint32_t) (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PowerOffered*100));
  7680. }
  7681. } // END OF FOR CHAdeMO_QUANTITY
  7682. }
  7683. else if(gunType[gun_index] == GUN_TYPE_CCS)
  7684. {
  7685. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  7686. {
  7687. tempIndex = ((gun_index==2) ? 1: 0);
  7688. }
  7689. else
  7690. {
  7691. tempIndex = gun_index;
  7692. }
  7693. for (int index = 0; index < CCS_QUANTITY; index++)
  7694. {
  7695. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  7696. {
  7697. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[11].Value, "%d", (uint32_t) (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PowerOffered*100));
  7698. }
  7699. } // END OF CCS_QUANTITY
  7700. }
  7701. else if(gunType[gun_index] == GUN_TYPE_GBT)
  7702. {
  7703. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  7704. {
  7705. tempIndex = ((gun_index==2) ? 1: 0);
  7706. }
  7707. else
  7708. {
  7709. tempIndex = gun_index;
  7710. }
  7711. for (int index = 0; index < GB_QUANTITY; index++)
  7712. {
  7713. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  7714. {
  7715. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[11].Value, "%d", (uint32_t) (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PowerOffered*100));
  7716. }
  7717. } // END OF GB_QUANTITY
  7718. }
  7719. else if(gunType[gun_index] == GUN_TYPE_DO)
  7720. {
  7721. tempIndex = gun_index;
  7722. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  7723. {
  7724. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  7725. {
  7726. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[11].Value, "%d", (uint32_t) (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PowerOffered*100));
  7727. }
  7728. }
  7729. }
  7730. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[11].Context, ReadingContextStr[dataType]);
  7731. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[11].Format, ValueFormatStr[Raw]);
  7732. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[11].Measurand, MeasurandStr[Power_Offered]);
  7733. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[11].Location, LocationStr[Location_Outlet]);
  7734. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[11].Unit,UnitOfMeasureStr[UnitOfMeasure_W]);
  7735. }
  7736. // Message create ====================================================================================================
  7737. if(TRUE)
  7738. {
  7739. json_object *MeterValueReq = json_object_new_object();
  7740. json_object *MeterValues = json_object_new_array();
  7741. json_object *sampledValues = json_object_new_array();
  7742. json_object_object_add(MeterValueReq, "connectorId", json_object_new_int(ShmOCPP16Data->MeterValues[gun_index].ConnectorId));
  7743. if(ShmOCPP16Data->MeterValues[gun_index].TransactionId != -1)
  7744. json_object_object_add(MeterValueReq, "transactionId", json_object_new_int(ShmOCPP16Data->MeterValues[gun_index].TransactionId));
  7745. for(uint8_t idxMeter=0;idxMeter<ARRAY_SIZE(ShmOCPP16Data->MeterValues[gun_index].MeterValue);idxMeter++)
  7746. {
  7747. json_object *MeterValue = json_object_new_object();
  7748. for(int idxSample=0;idxSample<ARRAY_SIZE(ShmOCPP16Data->MeterValues[gun_index].MeterValue[idxMeter].SampledValue);idxSample++)
  7749. {
  7750. if(strlen((char*)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Value) > 0)
  7751. {
  7752. json_object *sampledValue = json_object_new_object();
  7753. json_object_object_add(sampledValue, "value", json_object_new_string((char*)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Value));
  7754. if(strlen((char*)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Context) > 0)
  7755. json_object_object_add(sampledValue, "context", json_object_new_string((char*)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Context));
  7756. if(strlen((char*)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Format) > 0)
  7757. json_object_object_add(sampledValue, "format", json_object_new_string((char*)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Format));
  7758. if(strlen((char*)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Measurand) > 0)
  7759. json_object_object_add(sampledValue, "measurand", json_object_new_string((char*)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Measurand));
  7760. if(strlen((char*)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Phase) > 0)
  7761. json_object_object_add(sampledValue, "phase", json_object_new_string((char*)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Phase));
  7762. if(strlen((char*)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Location) > 0)
  7763. json_object_object_add(sampledValue, "location", json_object_new_string((char*)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Location));
  7764. if(strlen((char*)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Unit) > 0)
  7765. json_object_object_add(sampledValue, "unit", json_object_new_string((char*)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Unit));
  7766. json_object_array_add(sampledValues, sampledValue);
  7767. }
  7768. }
  7769. json_object_object_add(MeterValue, "timestamp", json_object_new_string((char*)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idxMeter].TimeStamp));
  7770. json_object_object_add(MeterValue, "sampledValue", sampledValues);
  7771. json_object_array_add(MeterValues, MeterValue);
  7772. }
  7773. json_object_object_add(MeterValueReq, "meterValue", MeterValues);
  7774. sprintf(queuedata,"%d,[%d,\"%s\",\"MeterValues\",%s]"
  7775. ,gun_index + 1
  7776. ,MESSAGE_TYPE_CALL
  7777. ,guid
  7778. ,json_object_to_json_string_ext(MeterValueReq, JSON_C_TO_STRING_PLAIN));
  7779. json_object_put(MeterValueReq);
  7780. }
  7781. // Put request guid to hash map
  7782. sprintf(tempdata, "MeterValues,%d", (gun_index));
  7783. if(hashmap_operation(HASH_OP_ADD, guid, tempdata) == 1)//if(hashmap_operation(0,NULL/*hashMap*/, mapItem[0].key_string, mapItem[0].key_value/*mapItem*/, (void**)(&mapItem)/*(void**)(&mapItem)*/) == MAP_OK/*hashmap_put(hashMap, mapItem->key_string, mapItem) == MAP_OK*/)
  7784. {
  7785. result = PASS;
  7786. //DEBUG_INFO("MeterValues mapitem pass\n");
  7787. }
  7788. if((dataType != ReadingContext_Trigger) &&
  7789. (dataType != ReadingContext_Sample_Clock) &&
  7790. ((ShmOCPP16Data->MeterValues[gun_index].TransactionId > 0) || (strstr((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[QueueOffLineMeterValues].ItemData, "TRUE"))))
  7791. queue_operation(QUEUE_OPERATION_ADD, guid, queuedata );
  7792. else
  7793. {
  7794. if(FirstHeartBeat)
  7795. LWS_Send(queuedata +2);
  7796. }
  7797. return result;
  7798. }
  7799. int sendLogStatusNotificationRequest(char *status)
  7800. {
  7801. mtrace();
  7802. int result = PASS;
  7803. char message[4096]={0};
  7804. char guid[37]={0};
  7805. char tempdata[128]={0};
  7806. json_object *LogStatusNotification = json_object_new_object();
  7807. DEBUG_INFO("sendLogStatusNotificationRequest...\n");
  7808. ShmOCPP16Data->LogStatusNotification.requestId = ShmOCPP16Data->GetLog.requestId;
  7809. sprintf((char *)ShmOCPP16Data->LogStatusNotification.status,"%s",(const char *)status);
  7810. json_object_object_add(LogStatusNotification, "status", json_object_new_string((char*)ShmOCPP16Data->LogStatusNotification.status));
  7811. json_object_object_add(LogStatusNotification, "requestId", json_object_new_int(ShmOCPP16Data->LogStatusNotification.requestId));
  7812. random_uuid(guid);
  7813. sprintf(message,"[%d,\"%s\",\"LogStatusNotification\",%s]",MESSAGE_TYPE_CALL, guid, json_object_to_json_string_ext(LogStatusNotification, JSON_C_TO_STRING_PLAIN));
  7814. json_object_put(LogStatusNotification);
  7815. LWS_Send(message);
  7816. sprintf(tempdata, "LogStatusNotification,%d", 0);
  7817. if(hashmap_operation(HASH_OP_ADD, guid, tempdata) == PASS)
  7818. {
  7819. result = PASS;
  7820. }
  7821. ShmOCPP16Data->SpMsg.bits.LogStatusNotificationReq = 0;
  7822. ShmOCPP16Data->SpMsg.bits.LogStatusNotificationConf = 0;
  7823. return result;
  7824. }
  7825. int sendSecurityEventNotificationRequest()
  7826. {
  7827. mtrace();
  7828. int result = PASS;
  7829. char message[4096]={0};
  7830. char guid[37]={0};
  7831. char tempdata[128]={0};
  7832. json_object *SecurityEventNotification = json_object_new_object();
  7833. DEBUG_INFO("sendSecurityEventNotificationRequest...\n");
  7834. json_object_object_add(SecurityEventNotification, "type", json_object_new_string((char*)ShmOCPP16Data->SecurityEventNotification.type));
  7835. json_object_object_add(SecurityEventNotification, "timestamp", json_object_new_string((char*)ShmOCPP16Data->SecurityEventNotification.timestamp));
  7836. json_object_object_add(SecurityEventNotification, "techInfo", json_object_new_string((char*)ShmOCPP16Data->SecurityEventNotification.techInfo));
  7837. random_uuid(guid);
  7838. sprintf(message,"[%d,\"%s\",\"%s\",%s]",MESSAGE_TYPE_CALL, guid, "SecurityEventNotification", json_object_to_json_string_ext(SecurityEventNotification, JSON_C_TO_STRING_PLAIN));
  7839. json_object_put(SecurityEventNotification);
  7840. LWS_Send(message);
  7841. sprintf(tempdata, "SecurityEventNotification,0");
  7842. if(hashmap_operation(HASH_OP_ADD, guid, tempdata) == PASS)
  7843. {
  7844. result = PASS;
  7845. }
  7846. ShmOCPP16Data->SpMsg.bits.SecurityEventNotificationReq = 0;
  7847. ShmOCPP16Data->SpMsg.bits.SecurityEventNotificationConf = 0;
  7848. return result;
  7849. }
  7850. int sendSignCertificateRequest()
  7851. {
  7852. mtrace();
  7853. int result = PASS;
  7854. char message[4096]={0};
  7855. char guid[37]={0};
  7856. char tempdata[128]={0};
  7857. json_object *SignCertificate = json_object_new_object();
  7858. DEBUG_INFO("sendSignCertificateRequest...\n");
  7859. // Read csr file content
  7860. memset(ShmOCPP16Data->SignCertificate.csr, 0x00, ARRAY_SIZE(ShmOCPP16Data->SignCertificate.csr));
  7861. FILE *fp=fopen("/Storage/OCPP/certCP.csr","r");
  7862. char *line = NULL;
  7863. size_t len = 0;
  7864. while(getline(&line, &len, fp) != -1)
  7865. {
  7866. if((strstr(line, "BEGIN CERTIFICATE REQUEST") == NULL) && (strstr(line, "END CERTIFICATE REQUEST") == NULL))
  7867. {
  7868. memcpy(&ShmOCPP16Data->SignCertificate.csr[strlen((char*)ShmOCPP16Data->SignCertificate.csr)], line, (strlen(line)-1));
  7869. }
  7870. }
  7871. fclose(fp);
  7872. json_object_object_add(SignCertificate, "csr", json_object_new_string((char*)ShmOCPP16Data->SignCertificate.csr));
  7873. random_uuid(guid);
  7874. sprintf(message,"[%d,\"%s\",\"%s\",%s]",MESSAGE_TYPE_CALL, guid, "SignCertificate", json_object_to_json_string_ext(SignCertificate, JSON_C_TO_STRING_PLAIN));
  7875. json_object_put(SignCertificate);
  7876. LWS_Send(message);
  7877. sprintf(tempdata, "SignCertificate,0");
  7878. if(hashmap_operation(HASH_OP_ADD, guid, tempdata) == PASS)
  7879. {
  7880. result = PASS;
  7881. }
  7882. ShmOCPP16Data->SpMsg.bits.SignCertificateReq = 0;
  7883. ShmOCPP16Data->SpMsg.bits.SignCertificateConf = 0;
  7884. return result;
  7885. }
  7886. int sendSignedFirmwareStatusNotificationRequest(char *status)
  7887. {
  7888. mtrace();
  7889. int result = PASS;
  7890. char message[110]={0};
  7891. char guid[37]={0};
  7892. char tempdata[65]={0};
  7893. json_object *FirmwareStatusNotification = json_object_new_object();
  7894. DEBUG_INFO("sendSignedFirmwareStatusNotificationRequest...\n");
  7895. sprintf((char *)ShmOCPP16Data->SignedFirmwareStatusNotification.status , "%s", (const char *)status);
  7896. ShmOCPP16Data->SignedFirmwareStatusNotification.requestId = ShmOCPP16Data->SignedUpdateFirmware.requestId;
  7897. json_object_object_add(FirmwareStatusNotification, "status", json_object_new_string((char*)ShmOCPP16Data->SignedFirmwareStatusNotification.status));
  7898. json_object_object_add(FirmwareStatusNotification, "requestId", json_object_new_int(ShmOCPP16Data->SignedFirmwareStatusNotification.requestId));
  7899. random_uuid(guid);
  7900. sprintf(message,"[%d,\"%s\",\"FirmwareStatusNotification\",%s]",MESSAGE_TYPE_CALL, guid, json_object_to_json_string_ext(FirmwareStatusNotification, JSON_C_TO_STRING_PLAIN));
  7901. json_object_put(FirmwareStatusNotification);
  7902. LWS_Send(message);
  7903. sprintf(tempdata, "FirmwareStatusNotification,%d", 0);
  7904. if(hashmap_operation(HASH_OP_ADD, guid, tempdata) == PASS)
  7905. {
  7906. result = PASS;
  7907. }
  7908. ShmOCPP16Data->SpMsg.bits.SignedFirmwareStatusNotificationReq = 0;
  7909. ShmOCPP16Data->SpMsg.bits.SignedFirmwareStatusNotificationConf = 0;
  7910. return result;
  7911. }
  7912. //==========================================
  7913. // send confirm routine
  7914. //==========================================
  7915. int sendCancelReservationConfirmation(char *uuid,char *payload)
  7916. {
  7917. mtrace();
  7918. int result = FAIL;
  7919. char message[100]={0};
  7920. DEBUG_INFO("sendCancelReservationConfirmation...\n");
  7921. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT,uuid, payload);
  7922. LWS_Send(message);
  7923. result = TRUE;
  7924. return result;
  7925. }
  7926. int sendChangeAvailabilityConfirmation(char *uuid,char *payload)
  7927. {
  7928. mtrace();
  7929. int result = FAIL;
  7930. char message[100]={0};
  7931. DEBUG_INFO("sendChangeAvailabilityConfirmation...\n");
  7932. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT,uuid, payload);
  7933. LWS_Send(message);
  7934. result = TRUE;
  7935. return result;
  7936. }
  7937. int sendChangeConfigurationConfirmation(char *uuid,char *payload)
  7938. {
  7939. mtrace();
  7940. int result = FAIL;
  7941. char message[100]={0};
  7942. DEBUG_INFO("sendChangeConfigurationConfirmation...\n");
  7943. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT,uuid, payload);
  7944. LWS_Send(message);
  7945. result = TRUE;
  7946. return result;
  7947. }
  7948. int sendClearCacheConfirmation(char *uuid,char *payload)
  7949. {
  7950. mtrace();
  7951. int result = FAIL;
  7952. char message[500]={0};
  7953. DEBUG_INFO("sendClearCacheConfirmation...\n");
  7954. sprintf(message,"[%d,\"%s\",{\"%s\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, "status", payload);
  7955. LWS_Send(message);
  7956. return result;
  7957. }
  7958. int sendClearChargingProfileConfirmation(char *uuid,char *payload)
  7959. {
  7960. mtrace();
  7961. int result = FAIL;
  7962. char message[500]={0};
  7963. DEBUG_INFO("sendClearChargingProfileConfirmation...\n");
  7964. sprintf(message,"[%d,\"%s\",{\"%s\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, "status", payload);
  7965. LWS_Send(message);
  7966. return result;
  7967. }
  7968. int sendDataTransferConfirmation(char *uuid,char *payload)
  7969. {
  7970. mtrace();
  7971. char statusStr[20]={0};
  7972. char dataStr[10]={0};
  7973. char sstr[20]={0};
  7974. int c = 0;
  7975. char *loc;
  7976. int result = FAIL;
  7977. DEBUG_INFO("sendDataTransferConfirmation...\n");
  7978. /**********************status**************************/
  7979. loc = strstr(payload, "status");
  7980. memset(sstr ,0, ARRAY_SIZE(sstr) );
  7981. c = 0;
  7982. while (loc[3+strlen("status")+c] != '\"')
  7983. {
  7984. sstr[c] = loc[3+strlen("status")+c];
  7985. c++;
  7986. }
  7987. sstr[c] = '\0';
  7988. strcpy(statusStr, sstr);
  7989. /**********************data**************************/
  7990. loc = strstr(payload, "data");
  7991. memset(sstr ,0, ARRAY_SIZE(sstr) );
  7992. c = 0;
  7993. while (loc[3+strlen("data")+c] != '\"')
  7994. {
  7995. sstr[c] = loc[3+strlen("data")+c];
  7996. c++;
  7997. }
  7998. sstr[c] = '\0';
  7999. strcpy(dataStr, sstr);
  8000. return result;
  8001. }
  8002. int sendGetCompositeScheduleConfirmation(char *uuid, char *payload, int connectorIdInt, int nPeriod)
  8003. {
  8004. mtrace();
  8005. int result = FAIL;
  8006. char message[1000]={0};
  8007. int CompositeScheduleIndex = 0;
  8008. DEBUG_INFO("sendGetCompositeScheduleConfirmation...\n");
  8009. CompositeScheduleIndex = (connectorIdInt > 0) ?(connectorIdInt -1) : 0;
  8010. if(nPeriod == 0)
  8011. {
  8012. if(strcmp((const char *)ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.StartSchedule,"")==0)
  8013. {
  8014. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\",\"connectorId\":%d}]"
  8015. ,MESSAGE_TYPE_CALLRESULT
  8016. ,uuid
  8017. ,payload
  8018. ,connectorIdInt);
  8019. }
  8020. else
  8021. {
  8022. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\",\"connectorId\":%d,\"scheduleStart\":\"%s\",\"chargingSchedule\":{\"duration\":%d,\"startSchedule\":\"%s\",\"chargingRateUnit\":\"%s\",\"chargingSchedulePeriod\":[{\"startPeriod\":0,\"limit\":%d}]}}]"
  8023. ,MESSAGE_TYPE_CALLRESULT
  8024. ,uuid
  8025. ,payload
  8026. ,connectorIdInt
  8027. ,ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.StartSchedule
  8028. ,ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.Duration
  8029. ,ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.StartSchedule
  8030. ,ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.ChargingRateUnit
  8031. ,ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.ChargingRateUnit[0]=='W'?modelnameInfo.ratedPower:(ShmSysConfigAndInfo->SysConfig.MaxChargingCurrent==0?ShmSysConfigAndInfo->SysConfig.RatingCurrent:ShmSysConfigAndInfo->SysConfig.MaxChargingCurrent));
  8032. }
  8033. }
  8034. else
  8035. {
  8036. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\",\"connectorId\":%d,\"scheduleStart\":\"%s\",\"chargingSchedule\":{\"duration\":%d,\"startSchedule\":\"%s\",\"chargingRateUnit\":\"%s\",\"chargingSchedulePeriod\":["
  8037. ,MESSAGE_TYPE_CALLRESULT
  8038. ,uuid
  8039. ,payload
  8040. ,connectorIdInt
  8041. ,ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.StartSchedule
  8042. ,ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.Duration
  8043. ,ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.StartSchedule
  8044. ,ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.ChargingRateUnit);
  8045. for(int idx_sample=0;idx_sample< nPeriod;idx_sample++)
  8046. {
  8047. if (idx_sample == 0)
  8048. {
  8049. sprintf(message + strlen(message), "{\"startPeriod\":%d,\"limit\":%.1f,\"numberPhases\":%d}"
  8050. , ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[idx_sample].StartPeriod
  8051. , ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[idx_sample].Limit
  8052. , ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[idx_sample].NumberPhases );
  8053. }
  8054. else
  8055. {
  8056. sprintf(message + strlen(message), ",{\"startPeriod\":%d,\"limit\":%.1f,\"numberPhases\":%d}"
  8057. , ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[idx_sample].StartPeriod
  8058. , ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[idx_sample].Limit
  8059. , ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[idx_sample].NumberPhases );
  8060. }
  8061. }
  8062. sprintf(message + strlen(message), "]}}]");
  8063. }
  8064. LWS_Send(message);
  8065. result = TRUE;
  8066. return result;
  8067. }
  8068. int sendGetConfigurationConfirmation(char *uuid)
  8069. {
  8070. mtrace();
  8071. int result = FAIL;
  8072. int MaxKeySupported = 0;
  8073. int sentConfigurationNumber= 0;
  8074. int sentunConfigurationNumber= 0;
  8075. char message[1024*10]={0};
  8076. DEBUG_INFO("sendGetConfigurationConfirmation...\n");
  8077. MaxKeySupported = atoi((const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemData);
  8078. sprintf(message,"[%d,\"%s\",{\"configurationKey\":["
  8079. ,MESSAGE_TYPE_CALLRESULT
  8080. ,uuid );
  8081. //configuration key
  8082. for(int idx_sample=0;idx_sample< MaxKeySupported/*43*/;idx_sample++)
  8083. {
  8084. if(strcmp((const char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[idx_sample].Key, "")!= 0)
  8085. {
  8086. if (sentConfigurationNumber == 0)
  8087. {
  8088. sprintf(message + strlen(message), "{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}"
  8089. , ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[idx_sample].Key
  8090. , atoi((const char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[idx_sample].ReadOnly) == 1 ? "true":"false"
  8091. , ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[idx_sample].Value );
  8092. }
  8093. else
  8094. {
  8095. sprintf(message + strlen(message), ", {\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}"
  8096. , ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[idx_sample].Key
  8097. , atoi((const char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[idx_sample].ReadOnly) == 1 ? "true":"false"
  8098. , ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[idx_sample].Value );
  8099. }
  8100. sentConfigurationNumber = sentConfigurationNumber + 1;
  8101. }
  8102. }
  8103. sprintf(message + strlen(message), "]");
  8104. if(UnknownKeynum != 0)
  8105. {
  8106. sprintf(message + strlen(message), ",\"unknownKey\":[");
  8107. //unkown key
  8108. for(int idx_sample=0;idx_sample< UnknownKeynum ;idx_sample++)
  8109. {
  8110. // json_object *jstring1 = json_object_new_string((const char *)((ShmOCPP16Data->GetConfiguration.ResponseUnknownKey + idx_sample)->Item));
  8111. DEBUG_INFO("unkown key:%s\n", ShmOCPP16Data->GetConfiguration.ResponseUnknownKey[idx_sample].Item);
  8112. if(sentunConfigurationNumber == 0)
  8113. {
  8114. sprintf(message + strlen(message), "\"%s\""
  8115. , ShmOCPP16Data->GetConfiguration.ResponseUnknownKey[idx_sample].Item );
  8116. }
  8117. else
  8118. {
  8119. sprintf(message + strlen(message), ",\"%s\""
  8120. , ShmOCPP16Data->GetConfiguration.ResponseUnknownKey[idx_sample].Item );
  8121. }
  8122. sentunConfigurationNumber = sentunConfigurationNumber + 1;
  8123. }
  8124. sprintf(message + strlen(message), "]");
  8125. }
  8126. sprintf(message + strlen(message), "}]");
  8127. LWS_Send(message);
  8128. return result;
  8129. }
  8130. int sendGetDiagnosticsConfirmation(char *uuid,char *payload)
  8131. {
  8132. mtrace();
  8133. int result = FAIL;
  8134. char message[400]={0};
  8135. DEBUG_INFO("sendGetDiagnosticsConfirmation...\n");
  8136. if(strcmp(payload,"")==0)
  8137. {
  8138. sprintf(message,"[%d,\"%s\",{}]",MESSAGE_TYPE_CALLRESULT, uuid);
  8139. }
  8140. else
  8141. {
  8142. sprintf(message,"[%d,\"%s\",{\"fileName\":\"%s\"}]", MESSAGE_TYPE_CALLRESULT, uuid, payload);
  8143. }
  8144. LWS_Send(message);
  8145. result = TRUE;
  8146. return result;
  8147. }
  8148. int sendGetLocalListVersionConfirmation(char *uuid,char *payload)
  8149. {
  8150. mtrace();
  8151. int result = FAIL;
  8152. char message[80]={0};
  8153. DEBUG_INFO("sendGetLocalListVersionConfirmation...\n");
  8154. sprintf(message,"[%d,\"%s\",{\"listVersion\":%d}]",MESSAGE_TYPE_CALLRESULT, uuid, ShmOCPP16Data->GetLocalListVersion.ResponseListVersion);
  8155. LWS_Send(message);
  8156. result = TRUE;
  8157. return result;
  8158. }
  8159. int sendRemoteStartConfirmation(char *uuid,char *payload)
  8160. {
  8161. mtrace();
  8162. int result = FAIL;
  8163. char message[80]={0};
  8164. DEBUG_INFO("sendRemoteStartConfirmation...\n");
  8165. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, payload);
  8166. LWS_Send(message);
  8167. result = TRUE;
  8168. return result;
  8169. }
  8170. int sendRemoteStopTransactionConfirmation(char *uuid,char *payload)
  8171. {
  8172. mtrace();
  8173. int result = FAIL;
  8174. char message[80]={0};
  8175. DEBUG_INFO("sendRemoteStopTransactionConfirmation...\n");
  8176. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, payload);
  8177. LWS_Send(message);
  8178. result = TRUE;
  8179. return result;
  8180. }
  8181. int sendReserveNowTransactionConfirmation(char *uuid,char *payload)
  8182. {
  8183. mtrace();
  8184. int result = FAIL;
  8185. char message[80]={0};
  8186. // [3,"287d837d-809e-41ea-8385-fdab7f72a01c",{"status":"Accepted"}]
  8187. DEBUG_INFO("sendReserveNowTransactionConfirmation...\n");
  8188. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, payload);
  8189. LWS_Send(message);
  8190. result = TRUE;
  8191. return result;
  8192. }
  8193. int sendResetConfirmation(char *uuid,char *payload)
  8194. {
  8195. mtrace();
  8196. int result = FAIL;
  8197. //[ 3, "6f88d461-4d17-462c-a69b-1f7a8c5b12df", { "status": 0 } ]
  8198. char message[80]={0};
  8199. ShmOCPP16Data->MsMsg.bits.ResetConf = 0;
  8200. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, payload);
  8201. LWS_Send(message);
  8202. result = TRUE;
  8203. return result;
  8204. }
  8205. int sendSendLocalListConfirmation(char *uuid,char *payload)
  8206. {
  8207. mtrace();
  8208. int result = FAIL;
  8209. char message[500]={0};
  8210. // [ 3, "1571284266109", { "status": "Accepted" } ]
  8211. sprintf(message,"[%d,\"%s\",{\"%s\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, "status", payload);
  8212. LWS_Send(message);
  8213. result = TRUE;
  8214. return result;
  8215. }
  8216. int sendSetChargingProfileConfirmation(char *uuid,char *payload)
  8217. {
  8218. mtrace();
  8219. int result = FAIL;
  8220. //[3,"5748585f-8524-4fa6-9b4f-4a7eca750b90",{"status":"NotSupported"}]
  8221. char message[80]={0};
  8222. DEBUG_INFO("sendSetChargingProfileConfirmation...\n");
  8223. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, payload);
  8224. LWS_Send(message);
  8225. result = TRUE;
  8226. return result;
  8227. }
  8228. int sendTriggerMessageConfirmation(char *uuid,char *payload)
  8229. {
  8230. mtrace();
  8231. int result = FAIL;
  8232. char message[80]={0};
  8233. DEBUG_INFO("sendTriggerMessageConfirmation...\n");
  8234. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, payload);
  8235. LWS_Send(message);
  8236. result = TRUE;
  8237. return result;
  8238. }
  8239. int sendUnlockConnectorConfirmation(char *uuid,char *payload)
  8240. {
  8241. mtrace();
  8242. int result = FAIL;
  8243. char message[80]={0};
  8244. //[ 3, "ba1cbd49-2a76-493a-8f76-fa23e7606532", { "status": "Unlocked" } ]
  8245. DEBUG_INFO("sendUnlockConnectorConfirmation...\n");
  8246. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, payload);
  8247. LWS_Send(message);
  8248. result = TRUE;
  8249. return result;
  8250. }
  8251. int sendUpdateFirmwareConfirmation(char *uuid)
  8252. {
  8253. mtrace();
  8254. int result = FAIL;
  8255. char message[60]={0};
  8256. //[ 3, "ba1cbd49-2a76-493a-8f76-fa23e7606532", { "status": "Unlocked" } ]
  8257. DEBUG_INFO("sendUpdateFirmwareConfirmation...\n");
  8258. sprintf(message,"[%d,\"%s\",{}]",MESSAGE_TYPE_CALLRESULT, uuid);
  8259. LWS_Send(message);
  8260. result = TRUE;
  8261. return result;
  8262. }
  8263. int sendCertificateSignedConfirmation(char *uuid)
  8264. {
  8265. mtrace();
  8266. int result = PASS;
  8267. char message[4096]={0};
  8268. json_object *CertificateSigned = json_object_new_object();
  8269. DEBUG_INFO("sendCertificateSignedConfirmation...\n");
  8270. json_object_object_add(CertificateSigned, "status", json_object_new_string((char*)ShmOCPP16Data->CertificateSigned.Response_status));
  8271. sprintf(message,"[%d,\"%s\",%s]"
  8272. ,MESSAGE_TYPE_CALLRESULT
  8273. ,uuid
  8274. ,json_object_to_json_string_ext(CertificateSigned, JSON_C_TO_STRING_PLAIN));
  8275. json_object_put(CertificateSigned);
  8276. LWS_Send(message);
  8277. return result;
  8278. }
  8279. int sendDeleteCertificateConfirmation(char *uuid)
  8280. {
  8281. mtrace();
  8282. int result = PASS;
  8283. char message[4096]={0};
  8284. json_object *DeleteCertificate = json_object_new_object();
  8285. DEBUG_INFO("sendDeleteCertificateConfirmation...\n");
  8286. json_object_object_add(DeleteCertificate, "status", json_object_new_string((char*)ShmOCPP16Data->DeleteCertificate.Response_status));
  8287. sprintf(message,"[%d,\"%s\",%s]"
  8288. ,MESSAGE_TYPE_CALLRESULT
  8289. ,uuid
  8290. ,json_object_to_json_string_ext(DeleteCertificate, JSON_C_TO_STRING_PLAIN));
  8291. json_object_put(DeleteCertificate);
  8292. LWS_Send(message);
  8293. return result;
  8294. }
  8295. int sendExtendedTriggerMessageConfirmation(char *uuid)
  8296. {
  8297. mtrace();
  8298. int result = PASS;
  8299. char message[4096]={0};
  8300. json_object *ExtendedTriggerMessage = json_object_new_object();
  8301. DEBUG_INFO("sendExtendedTriggerMessageConfirmation...\n");
  8302. json_object_object_add(ExtendedTriggerMessage, "status", json_object_new_string((char*)ShmOCPP16Data->ExtendedTriggerMessage.Response_status));
  8303. sprintf(message,"[%d,\"%s\",%s]"
  8304. ,MESSAGE_TYPE_CALLRESULT
  8305. ,uuid
  8306. ,json_object_to_json_string_ext(ExtendedTriggerMessage, JSON_C_TO_STRING_PLAIN));
  8307. json_object_put(ExtendedTriggerMessage);
  8308. LWS_Send(message);
  8309. return result;
  8310. }
  8311. int sendGetInstalledCertificateIdsConfirmation(char *uuid)
  8312. {
  8313. mtrace();
  8314. int result = PASS;
  8315. char message[4096]={0};
  8316. json_object *GetInstalledCertificateIds = json_object_new_object();
  8317. json_object *certificateHashDataDatas = json_object_new_array();
  8318. DEBUG_INFO("sendGetInstalledCertificateIdsConfirmation...\n");
  8319. json_object_object_add(GetInstalledCertificateIds, "status", json_object_new_string((char*)ShmOCPP16Data->GetInstalledCertificateIds.Response_status));
  8320. if(strlen((char*)ShmOCPP16Data->GetInstalledCertificateIds.Response_certificateHashData[0].hashAlgorithm) > 0)
  8321. {
  8322. for(int idx=0;idx<ARRAY_SIZE(ShmOCPP16Data->GetInstalledCertificateIds.Response_certificateHashData);idx++)
  8323. {
  8324. json_object *certificateHashData = json_object_new_object();
  8325. json_object_object_add(certificateHashData, "hashAlgorithm", json_object_new_string((char*)ShmOCPP16Data->GetInstalledCertificateIds.Response_certificateHashData[idx].hashAlgorithm));
  8326. json_object_object_add(certificateHashData, "issuerNameHash", json_object_new_string((char*)ShmOCPP16Data->GetInstalledCertificateIds.Response_certificateHashData[idx].issuerNameHash));
  8327. json_object_object_add(certificateHashData, "issuerKeyHash", json_object_new_string((char*)ShmOCPP16Data->GetInstalledCertificateIds.Response_certificateHashData[idx].issuerKeyHash));
  8328. json_object_object_add(certificateHashData, "serialNumber", json_object_new_string((char*)ShmOCPP16Data->GetInstalledCertificateIds.Response_certificateHashData[idx].serialNumber));
  8329. json_object_array_add(certificateHashDataDatas, certificateHashData);
  8330. }
  8331. json_object_object_add(GetInstalledCertificateIds , "certificateHashData", certificateHashDataDatas);
  8332. }
  8333. else
  8334. {
  8335. json_object_put(certificateHashDataDatas);
  8336. }
  8337. sprintf(message,"[%d,\"%s\",%s]"
  8338. ,MESSAGE_TYPE_CALLRESULT
  8339. ,uuid
  8340. ,json_object_to_json_string_ext(GetInstalledCertificateIds, JSON_C_TO_STRING_PLAIN));
  8341. json_object_put(GetInstalledCertificateIds);
  8342. LWS_Send(message);
  8343. return result;
  8344. }
  8345. int sendGetLogConfirmation(char *uuid)
  8346. {
  8347. mtrace();
  8348. int result = PASS;
  8349. char message[4096]={0};
  8350. json_object *GetLog = json_object_new_object();
  8351. DEBUG_INFO("sendGetLogConfirmation...\n");
  8352. json_object_object_add(GetLog, "status", json_object_new_string((char*)ShmOCPP16Data->GetLog.Response_status));
  8353. if(strlen((char*)ShmOCPP16Data->GetLog.Response_filename) > 0)
  8354. json_object_object_add(GetLog, "filename", json_object_new_string((char*)ShmOCPP16Data->GetLog.Response_filename));
  8355. sprintf(message,"[%d,\"%s\",%s]"
  8356. ,MESSAGE_TYPE_CALLRESULT
  8357. ,uuid
  8358. ,json_object_to_json_string_ext(GetLog, JSON_C_TO_STRING_PLAIN));
  8359. json_object_put(GetLog);
  8360. LWS_Send(message);
  8361. return result;
  8362. }
  8363. int sendInstallCertificateConfirmation(char *uuid)
  8364. {
  8365. mtrace();
  8366. int result = PASS;
  8367. char message[4096]={0};
  8368. json_object *InstallCertificate = json_object_new_object();
  8369. DEBUG_INFO("sendInstallCertificateConfirmation...\n");
  8370. json_object_object_add(InstallCertificate, "status", json_object_new_string((char*)ShmOCPP16Data->InstallCertificate.Response_status));
  8371. sprintf(message,"[%d,\"%s\",%s]"
  8372. ,MESSAGE_TYPE_CALLRESULT
  8373. ,uuid
  8374. ,json_object_to_json_string_ext(InstallCertificate, JSON_C_TO_STRING_PLAIN));
  8375. json_object_put(InstallCertificate);
  8376. LWS_Send(message);
  8377. return result;
  8378. }
  8379. int sendSignedUpdateFirmwareConfirmation(char *uuid)
  8380. {
  8381. mtrace();
  8382. int result = PASS;
  8383. char message[4096]={0};
  8384. json_object *SignedUpdateFirmware = json_object_new_object();
  8385. DEBUG_INFO("sendSignedUpdateFirmwareConfirmation...\n");
  8386. json_object_object_add(SignedUpdateFirmware, "status", json_object_new_string((char*)ShmOCPP16Data->SignedUpdateFirmware.Response_status));
  8387. sprintf(message,"[%d,\"%s\",%s]"
  8388. ,MESSAGE_TYPE_CALLRESULT
  8389. ,uuid
  8390. ,json_object_to_json_string_ext(SignedUpdateFirmware, JSON_C_TO_STRING_PLAIN));
  8391. json_object_put(SignedUpdateFirmware);
  8392. LWS_Send(message);
  8393. return result;
  8394. }
  8395. int sendUnknownConfirmation(char *uuid)
  8396. {
  8397. mtrace();
  8398. int result = PASS;
  8399. char message[256]={0};
  8400. DEBUG_INFO("sendUnknownConfirmation...\n");
  8401. sprintf(message,"[%d,\"%s\",\"NotImplemented\",\"Requested Action is not known by receiver\",{}]", MESSAGE_TYPE_CALLERROR, uuid);
  8402. LWS_Send(message);
  8403. return result;
  8404. }
  8405. //==========================================
  8406. // Handle server request routine Start
  8407. //==========================================
  8408. int handleCancelReservationRequest(char *uuid, char *payload)
  8409. {
  8410. mtrace();
  8411. int result = FAIL;
  8412. int gunNO = 0;
  8413. int reservationIdInt = -1;
  8414. char comfirmstr[20];
  8415. DEBUG_INFO("handleCancelReservationRequest...\n");
  8416. json_object *CancelReservation;
  8417. CancelReservation = json_tokener_parse(payload);
  8418. if(!is_error(CancelReservation))
  8419. {
  8420. // Required data
  8421. if(json_object_object_get(CancelReservation, "reservationId") != NULL)
  8422. reservationIdInt = json_object_get_int(json_object_object_get(CancelReservation, "reservationId"));
  8423. }
  8424. json_object_put(CancelReservation);
  8425. DEBUG_INFO("reservationIdInt = %d\n", reservationIdInt);
  8426. memset(comfirmstr, 0, ARRAY_SIZE(comfirmstr));
  8427. sprintf(comfirmstr, "%s", CancelReservationStatusStr[CancelReservationStatus_Rejected]);
  8428. if(reservationIdInt != -1)
  8429. {
  8430. //0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault, 8: Reserved, 9: maintain
  8431. //check Transaction active
  8432. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  8433. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  8434. {
  8435. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ReservationId == reservationIdInt)
  8436. {
  8437. sprintf(comfirmstr, "%s", CancelReservationStatusStr[CancelReservationStatus_Accepted] );
  8438. sprintf((char *)ShmOCPP16Data->CancelReservation[ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index].ResponseStatus, "%s", comfirmstr );
  8439. if(gunType[2] == GUN_TYPE_CHAdeMO)
  8440. {
  8441. gunNO = ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index + 1;
  8442. }
  8443. else
  8444. {
  8445. gunNO = ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index;
  8446. }
  8447. ShmOCPP16Data->CsMsg.bits[gunNO].CancelReservationReq = 1;
  8448. goto end;
  8449. }
  8450. }
  8451. for (int index = 0; index < CCS_QUANTITY; index++)
  8452. {
  8453. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ReservationId == reservationIdInt)
  8454. {
  8455. sprintf(comfirmstr, "%s", CancelReservationStatusStr[CancelReservationStatus_Accepted] );
  8456. sprintf((char *)ShmOCPP16Data->CancelReservation[ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index].ResponseStatus, "%s", comfirmstr );
  8457. if(gunType[2] == GUN_TYPE_CCS)
  8458. {
  8459. gunNO = ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index + 1;
  8460. }
  8461. else
  8462. {
  8463. gunNO = ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index;
  8464. }
  8465. ShmOCPP16Data->CsMsg.bits[gunNO].CancelReservationReq = 1;
  8466. goto end;
  8467. }
  8468. }
  8469. for (int index = 0; index < GB_QUANTITY; index++)
  8470. {
  8471. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ReservationId == reservationIdInt)
  8472. {
  8473. sprintf(comfirmstr, "%s", CancelReservationStatusStr[CancelReservationStatus_Accepted] );
  8474. sprintf((char *)ShmOCPP16Data->CancelReservation[ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index].ResponseStatus, "%s", comfirmstr );
  8475. if(gunType[2] == GUN_TYPE_GBT)
  8476. {
  8477. gunNO = ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index + 1;
  8478. }
  8479. else
  8480. {
  8481. gunNO = ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index;
  8482. }
  8483. ShmOCPP16Data->CsMsg.bits[gunNO].CancelReservationReq = 1;
  8484. goto end;
  8485. }
  8486. }
  8487. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  8488. {
  8489. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.ReservationId == reservationIdInt)
  8490. {
  8491. sprintf(comfirmstr, "%s", CancelReservationStatusStr[CancelReservationStatus_Accepted] );
  8492. sprintf((char *)ShmOCPP16Data->CancelReservation[ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index].ResponseStatus, "%s", comfirmstr );
  8493. gunNO = ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index;
  8494. ShmOCPP16Data->CsMsg.bits[gunNO].CancelReservationReq = 1;
  8495. goto end;
  8496. }
  8497. }
  8498. for (int index = 0; index < AC_QUANTITY; index++)
  8499. {
  8500. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].ReservationId == reservationIdInt)
  8501. {
  8502. sprintf(comfirmstr, "%s", CancelReservationStatusStr[CancelReservationStatus_Accepted] );
  8503. sprintf((char *)ShmOCPP16Data->CancelReservation[ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index].ResponseStatus, "%s", comfirmstr );
  8504. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  8505. {
  8506. gunNO = 1; //ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index ;
  8507. }
  8508. else
  8509. {
  8510. gunNO = ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index;
  8511. }
  8512. ShmOCPP16Data->CsMsg.bits[gunNO].CancelReservationReq = 1;
  8513. goto end;
  8514. }
  8515. }
  8516. }
  8517. //The reservationId does NOT match the reservationId
  8518. sendCancelReservationConfirmation(uuid, comfirmstr);
  8519. end:
  8520. // Fill in ocpp packet uuid
  8521. strcpy((char *)ShmOCPP16Data->CancelReservation[gunNO].guid, uuid);
  8522. return result;
  8523. }
  8524. int handleChangeAvailabilityRequest(char *uuid, char *payload)
  8525. {
  8526. mtrace();
  8527. int result = FAIL;
  8528. int gunIndex = -1;
  8529. char typeStr[16]={0};
  8530. char comfirmstr[20];
  8531. int specificId = FALSE;
  8532. DEBUG_INFO("handleChangeAvailabilityRequest...\n");
  8533. json_object *ChangeAvailability;
  8534. ChangeAvailability = json_tokener_parse(payload);
  8535. if(!is_error(ChangeAvailability))
  8536. {
  8537. // Required data
  8538. if((json_object_object_get(ChangeAvailability, "connectorId") != NULL) && (json_object_get_type(json_object_object_get(ChangeAvailability, "connectorId")) == json_type_int))
  8539. gunIndex = json_object_get_int(json_object_object_get(ChangeAvailability, "connectorId"));
  8540. if(json_object_object_get(ChangeAvailability, "type") != NULL)
  8541. sprintf((char*)typeStr, "%s", json_object_get_string(json_object_object_get(ChangeAvailability, "type")));
  8542. }
  8543. json_object_put(ChangeAvailability);
  8544. if((gunIndex > 0) && (gunIndex <= gunTotalNumber))
  8545. {
  8546. ShmOCPP16Data->ChangeAvailability[gunIndex - 1].ConnectorId= gunIndex;
  8547. sprintf((char *)ShmOCPP16Data->ChangeAvailability[gunIndex - 1].Type, "%s", typeStr);
  8548. }
  8549. else if(gunIndex == 0)
  8550. {
  8551. for(int i=0; i < gunTotalNumber; i++)
  8552. {
  8553. ShmOCPP16Data->ChangeAvailability[i].ConnectorId= gunIndex;
  8554. sprintf((char *)ShmOCPP16Data->ChangeAvailability[i].Type, "%s", typeStr);
  8555. }
  8556. }
  8557. memset(comfirmstr, 0, ARRAY_SIZE(comfirmstr));
  8558. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  8559. if((gunIndex == 0) || ((gunIndex > 0) && (gunIndex <= gunTotalNumber)))
  8560. {
  8561. specificId = TRUE;
  8562. }
  8563. if(specificId == FALSE)
  8564. goto end;
  8565. if(strcmp((const char *)typeStr, AvailabilityTypeStr[Inoperative]) == 0)
  8566. {
  8567. //----------------------gunIndex is 0 ------------------------------------------------//
  8568. if(gunIndex == 0)
  8569. {
  8570. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D') // 'D' means DC
  8571. {
  8572. for(int i=0; i < gunTotalNumber; i++)
  8573. {
  8574. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  8575. {
  8576. if ((gunType[i] == GUN_TYPE_CHAdeMO)&&(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == i))
  8577. {
  8578. if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_RESERVATION) // S_PRECHARGE
  8579. {
  8580. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  8581. goto end;
  8582. }
  8583. else if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_AUTHORIZING) ||
  8584. (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_PREPARING) ||
  8585. (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_CHARGING) ||
  8586. (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_TERMINATING) ||
  8587. (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_COMPLETE)) // S_CHARGING
  8588. {
  8589. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  8590. goto end;
  8591. }
  8592. }
  8593. }//END FOR CHAdeMO_QUANTITY
  8594. for (int index = 0; index < CCS_QUANTITY; index++)
  8595. {
  8596. if ((gunType[i] == GUN_TYPE_CCS)&&(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == i))
  8597. {
  8598. if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_RESERVATION)// S_PRECHARGE
  8599. {
  8600. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  8601. goto end;
  8602. }
  8603. else if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_AUTHORIZING) ||
  8604. (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_PREPARING) ||
  8605. (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_CHARGING) ||
  8606. (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_TERMINATING) ||
  8607. (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_COMPLETE)) // S_CHARGING
  8608. {
  8609. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  8610. goto end;
  8611. }
  8612. }
  8613. }//END FOR CCS_QUANTITY
  8614. for (int index = 0; index < GB_QUANTITY; index++)
  8615. {
  8616. if ((gunType[i] == GUN_TYPE_GBT)&&(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == i))
  8617. {
  8618. if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_RESERVATION) // S_PRECHARGE
  8619. {
  8620. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  8621. goto end;
  8622. }
  8623. else if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_AUTHORIZING) ||
  8624. (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_PREPARING) ||
  8625. (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_CHARGING) ||
  8626. (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_TERMINATING) ||
  8627. (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_COMPLETE)) // S_CHARGING
  8628. {
  8629. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  8630. goto end;
  8631. }
  8632. }
  8633. }// END FOR GB_QUANTITY
  8634. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  8635. {
  8636. if ((gunType[i] == GUN_TYPE_DO)&&(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == i))
  8637. {
  8638. if(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_RESERVATION) // S_PRECHARGE
  8639. {
  8640. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  8641. goto end;
  8642. }
  8643. else if((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_AUTHORIZING) ||
  8644. (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_PREPARING) ||
  8645. (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_CHARGING) ||
  8646. (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_TERMINATING) ||
  8647. (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_COMPLETE)) // S_CHARGING
  8648. {
  8649. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  8650. goto end;
  8651. }
  8652. }
  8653. }// END FOR GENERAL_GUN_QUANTITY
  8654. for (int index = 0; index < AC_QUANTITY; index++)
  8655. {
  8656. if ((gunType[i] == GUN_TYPE_AC)&&(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == i))
  8657. {
  8658. if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_RESERVATION) // S_PRECHARGE
  8659. {
  8660. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  8661. goto end;
  8662. }
  8663. else if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_AUTHORIZING) ||
  8664. (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_PREPARING) ||
  8665. (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_CHARGING) ||
  8666. (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_TERMINATING) ||
  8667. (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_COMPLETE)) // S_CHARGING
  8668. {
  8669. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  8670. goto end;
  8671. }
  8672. }
  8673. }//END FOR AC_QUANTITY
  8674. }// END FOR gunTotalNumber
  8675. }
  8676. else if (ShmSysConfigAndInfo->SysConfig.ModelName[0]=='A') //'A' means AC
  8677. {
  8678. for(int i=0; i < gunTotalNumber; i++)
  8679. {
  8680. if(ShmSysConfigAndInfo->SysInfo.AcChargingData[i].SystemStatus == SYS_MODE_RESERVATION) // S_PRECHARGE
  8681. {
  8682. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  8683. goto end;
  8684. }
  8685. else if((ShmSysConfigAndInfo->SysInfo.AcChargingData[i].SystemStatus == SYS_MODE_AUTHORIZING) ||
  8686. (ShmSysConfigAndInfo->SysInfo.AcChargingData[i].SystemStatus == SYS_MODE_PREPARING) ||
  8687. (ShmSysConfigAndInfo->SysInfo.AcChargingData[i].SystemStatus == SYS_MODE_CHARGING) ||
  8688. (ShmSysConfigAndInfo->SysInfo.AcChargingData[i].SystemStatus == SYS_MODE_TERMINATING) ||
  8689. (ShmSysConfigAndInfo->SysInfo.AcChargingData[i].SystemStatus == SYS_MODE_COMPLETE)) // S_CHARGING
  8690. {
  8691. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  8692. goto end;
  8693. }
  8694. }
  8695. }
  8696. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  8697. goto end;
  8698. }
  8699. //----------------------gunIndex is not 0 ------------------------------------------------//
  8700. //check Transaction active
  8701. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  8702. {
  8703. if ((gunIndex > 0)&&(gunType[gunIndex-1] == GUN_TYPE_CHAdeMO))
  8704. {
  8705. if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_RESERVATION) ) // S_PRECHARGE
  8706. {
  8707. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  8708. goto end;
  8709. }
  8710. else if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_AUTHORIZING) ||
  8711. (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_PREPARING) ||
  8712. (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_CHARGING) ||
  8713. (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_TERMINATING) ||
  8714. (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_COMPLETE)) // S_CHARGING
  8715. {
  8716. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  8717. goto end;
  8718. }
  8719. else
  8720. {
  8721. DEBUG_INFO("ShmSysConfigAndInfo->SysInfo.ChademoChargingData[%d].SystemStatus = %d\n",index, ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus);
  8722. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  8723. goto end;
  8724. }
  8725. }
  8726. }//END FOR CHAdeMO_QUANTITY
  8727. for (int index = 0; index < CCS_QUANTITY; index++)
  8728. {
  8729. if ((gunIndex > 0)&&(gunType[gunIndex - 1] == GUN_TYPE_CCS))
  8730. {
  8731. if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_RESERVATION) )// S_PRECHARGE
  8732. {
  8733. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  8734. goto end;
  8735. }
  8736. else if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_AUTHORIZING) ||
  8737. (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_PREPARING) ||
  8738. (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_CHARGING) ||
  8739. (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_TERMINATING) ||
  8740. (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_COMPLETE)) // S_CHARGING
  8741. {
  8742. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  8743. goto end;
  8744. }
  8745. else
  8746. {
  8747. DEBUG_INFO("ShmSysConfigAndInfo->SysInfo.CcsChargingData[%d].SystemStatus=%d\n",index, ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus);
  8748. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  8749. goto end;
  8750. }
  8751. }
  8752. }//END FOR CCS_QUANTITY
  8753. for (int index = 0; index < GB_QUANTITY; index++)
  8754. {
  8755. if ((gunIndex > 0)&&(gunType[gunIndex-1] == GUN_TYPE_GBT))
  8756. {
  8757. if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_RESERVATION)) // S_PRECHARGE
  8758. {
  8759. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  8760. goto end;
  8761. }
  8762. else if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_AUTHORIZING) ||
  8763. (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_PREPARING) ||
  8764. (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_CHARGING) ||
  8765. (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_TERMINATING) ||
  8766. (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_COMPLETE)) // S_CHARGING
  8767. {
  8768. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  8769. goto end;
  8770. }
  8771. else
  8772. {
  8773. DEBUG_INFO("ShmSysConfigAndInfo->SysInfo.GbChargingData[%d].SystemStatus=%d\n",index,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus);
  8774. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  8775. goto end;
  8776. }
  8777. }
  8778. }// END FOR GB_QUANTITY
  8779. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  8780. {
  8781. if ((gunIndex > 0)&&(gunType[gunIndex-1] == GUN_TYPE_DO))
  8782. {
  8783. if((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_RESERVATION)) // S_PRECHARGE
  8784. {
  8785. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  8786. goto end;
  8787. }
  8788. else if((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_AUTHORIZING) ||
  8789. (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_PREPARING) ||
  8790. (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_CHARGING) ||
  8791. (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_TERMINATING) ||
  8792. (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_COMPLETE)) // S_CHARGING
  8793. {
  8794. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  8795. goto end;
  8796. }
  8797. else
  8798. {
  8799. DEBUG_INFO("ShmSysConfigAndInfo->SysInfo.GbChargingData[%d].SystemStatus=%d\n",index,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus);
  8800. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  8801. goto end;
  8802. }
  8803. }
  8804. }// END FOR GENERAL_GUN_QUANTITY
  8805. for (int index = 0; index < AC_QUANTITY; index++)
  8806. {
  8807. if ((gunIndex > 0)&&(gunType[gunIndex-1] ==GUN_TYPE_AC))
  8808. {
  8809. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_RESERVATION)) // S_PRECHARGE
  8810. {
  8811. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  8812. goto end;
  8813. }
  8814. else if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_AUTHORIZING) ||
  8815. (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_PREPARING) ||
  8816. (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_CHARGING) ||
  8817. (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_TERMINATING) ||
  8818. (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_COMPLETE)) // S_CHARGING
  8819. {
  8820. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  8821. goto end;
  8822. }
  8823. else
  8824. {
  8825. DEBUG_INFO("ShmSysConfigAndInfo->SysInfo.AcChargingData[%d].SystemStatus=%d\n",index, ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus);
  8826. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  8827. goto end;
  8828. }
  8829. }
  8830. }//END FOR AC_QUANTITY
  8831. }//END FOR AvailabilityTypeStr[Inoperative]
  8832. if(strcmp((const char *)typeStr, AvailabilityTypeStr[Operative]) == 0)
  8833. {
  8834. //----------------------gunIndex is 0 ------------------------------------------------//
  8835. if(gunIndex == 0)
  8836. {
  8837. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D') // 'D' means DC
  8838. {
  8839. for(int i=0; i < gunTotalNumber; i++)
  8840. {
  8841. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  8842. {
  8843. if ((gunType[i] == GUN_TYPE_CHAdeMO )&&(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == i)&&(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_FAULT)) //S_FAULT //(((gunIndex == 0)|| ((gunIndex > 0)&&(gunType[gunIndex-1] == GUN_TYPE_CHAdeMO)) ) &&(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_FAULT)) //S_FAULT
  8844. {
  8845. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  8846. goto end;
  8847. }
  8848. }//END FOR CHAdeMO_QUANTITY
  8849. for (int index = 0; index < CCS_QUANTITY; index++)
  8850. {
  8851. if ((gunType[i] == GUN_TYPE_CCS)&&(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == i)&&(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_FAULT)) //S_FAULT//(((gunIndex == 0)|| ((gunIndex > 0)&&((gunType[gunIndex - 1] == 'U')||(gunType[gunIndex - 1] == 'E'))) )&&(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_FAULT)) //S_FAULT
  8852. {
  8853. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  8854. goto end;
  8855. }
  8856. }//END FOR CCS_QUANTITY
  8857. for (int index = 0; index < GB_QUANTITY; index++)
  8858. {
  8859. if ((gunType[i] == GUN_TYPE_GBT)&&(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == i)&&(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_FAULT)) //S_FAULT //(((gunIndex == 0)|| ((gunIndex > 0)&&(gunType[gunIndex-1] == 'G')))&&(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_FAULT)) //S_FAULT
  8860. {
  8861. //ShmOCPP16Data->CsMsg.bits[gunIndex - 1].ChangeAvailabilityReq = 1;
  8862. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  8863. goto end;
  8864. }
  8865. }// END FOR GB_QUANTITY
  8866. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  8867. {
  8868. if ((gunType[i] == GUN_TYPE_DO)&&(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == i)&&(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_FAULT)) //S_FAULT //(((gunIndex == 0)|| ((gunIndex > 0)&&(gunType[gunIndex-1] == 'O')))&&(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_FAULT)) //S_FAULT
  8869. {
  8870. //ShmOCPP16Data->CsMsg.bits[gunIndex - 1].ChangeAvailabilityReq = 1;
  8871. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  8872. goto end;
  8873. }
  8874. }// END FOR GENERAL_GUN_QUANTITY
  8875. for (int index = 0; index < AC_QUANTITY; index++)
  8876. {
  8877. if ((gunType[i] == GUN_TYPE_AC) &&(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_FAULT)) //S_FAULT // (((gunIndex == 0)|| ((gunIndex > 0)&&((gunType[gunIndex-1] > '0')&&(gunType[gunIndex-1] <= '9')))) &&(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_FAULT)) //S_FAULT
  8878. {
  8879. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  8880. goto end;
  8881. }
  8882. }//END FOR CHAdeMO_QUANTITY
  8883. }// END FOR gunTotalNumber
  8884. }
  8885. else if (ShmSysConfigAndInfo->SysConfig.ModelName[0]=='A') //'A' means AC
  8886. {
  8887. for(int i=0; i < gunTotalNumber; i++)
  8888. {
  8889. for (int index = 0; index < AC_QUANTITY; index++)
  8890. {
  8891. if ((gunType[i] == GUN_TYPE_AC) &&(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_FAULT)) //S_FAULT // (((gunIndex == 0)|| ((gunIndex > 0)&&((gunType[gunIndex-1] > '0')&&(gunType[gunIndex-1] <= '9')))) &&(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_FAULT)) //S_FAULT
  8892. {
  8893. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  8894. goto end;
  8895. }
  8896. }//END FOR CHAdeMO_QUANTITY
  8897. } // END FOR gunTotalNumber
  8898. }
  8899. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  8900. goto end;
  8901. }
  8902. //----------------------gunIndex is not 0 ------------------------------------------------//
  8903. //check Transaction active
  8904. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  8905. {
  8906. if (((gunIndex > 0)&&(gunType[gunIndex-1] == GUN_TYPE_CHAdeMO) ) &&(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_FAULT)) //S_FAULT
  8907. {
  8908. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  8909. goto end;
  8910. }
  8911. }//END FOR CHAdeMO_QUANTITY
  8912. for (int index = 0; index < CCS_QUANTITY; index++)
  8913. {
  8914. if ((((gunIndex > 0)&&(gunType[gunIndex - 1] == GUN_TYPE_CCS)) )&&(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_FAULT)) //S_FAULT
  8915. {
  8916. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  8917. goto end;
  8918. }
  8919. }//END FOR CCS_QUANTITY
  8920. for (int index = 0; index < GB_QUANTITY; index++)
  8921. {
  8922. if (((gunIndex > 0)&&(gunType[gunIndex-1] == GUN_TYPE_GBT))&&(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_FAULT)) //S_FAULT
  8923. {
  8924. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  8925. goto end;
  8926. }
  8927. }// END FOR GB_QUANTITY
  8928. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  8929. {
  8930. if (((gunIndex > 0)&&(gunType[gunIndex-1] == GUN_TYPE_DO))&&(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus != SYS_MODE_FAULT)) //S_FAULT
  8931. {
  8932. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  8933. goto end;
  8934. }
  8935. }// END FOR GENERAL_GUN_QUANTITY
  8936. for (int index = 0; index < AC_QUANTITY; index++)
  8937. {
  8938. if (((gunIndex > 0)&&(gunType[gunIndex-1] == GUN_TYPE_AC)) &&(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_FAULT)) //S_FAULT
  8939. {
  8940. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  8941. goto end;
  8942. }
  8943. }//END FOR AC_QUANTITY
  8944. }//END FOR AvailabilityTypeStr[Operative]
  8945. end:
  8946. if((gunIndex != 0) && (gunIndex <= gunTotalNumber))
  8947. {
  8948. sprintf((char *)ShmOCPP16Data->ChangeAvailability[gunIndex - 1].ResponseStatus, "%s", comfirmstr );
  8949. }
  8950. else
  8951. {
  8952. sprintf((char *)ShmOCPP16Data->ChangeAvailability[0].ResponseStatus, "%s", comfirmstr );
  8953. }
  8954. if((gunIndex != 0) && (gunIndex <= gunTotalNumber))
  8955. {
  8956. if(strstr(comfirmstr, AvailabilityStatusStr[Rejected]) == NULL)
  8957. ShmOCPP16Data->CsMsg.bits[gunIndex - 1].ChangeAvailabilityReq = 1;
  8958. }
  8959. else if(gunIndex == 0)
  8960. {
  8961. if(strstr(comfirmstr, AvailabilityStatusStr[Rejected]) == NULL)
  8962. {
  8963. for(int i=0; i < gunTotalNumber/*(CHAdeMO_QUANTITY+ CCS_QUANTITY + GB_QUANTITY)*/; i++)
  8964. ShmOCPP16Data->CsMsg.bits[i].ChangeAvailabilityReq = 1;
  8965. }
  8966. }
  8967. sendChangeAvailabilityConfirmation(uuid, comfirmstr);
  8968. system("/bin/fsync -d /dev/mtdblock13;/bin/sync &");
  8969. return result;
  8970. }
  8971. int handleChangeConfigurationRequest(char *uuid, char *payload)
  8972. {
  8973. mtrace();
  8974. int valueInvalid = NO;
  8975. int result = FAIL;
  8976. char keystr[40]={0};
  8977. char valuestr[501]={0}; //value should be limited in 500 bytes
  8978. char comfirmstr[20]={0};
  8979. DEBUG_INFO("handleChangeConfigurationRequest...\n");
  8980. json_object *ChangeConfiguration;
  8981. ChangeConfiguration = json_tokener_parse(payload);
  8982. if(!is_error(ChangeConfiguration))
  8983. {
  8984. // Required data
  8985. if(json_object_object_get(ChangeConfiguration, "key") != NULL)
  8986. sprintf((char*)keystr, "%s", json_object_get_string(json_object_object_get(ChangeConfiguration, "key")));
  8987. if((json_object_object_get(ChangeConfiguration, "value") != NULL) && (strlen(json_object_get_string(json_object_object_get(ChangeConfiguration, "value"))) < ARRAY_SIZE(valuestr)))
  8988. {
  8989. sprintf((char*)valuestr, "%s", json_object_get_string(json_object_object_get(ChangeConfiguration, "value")));
  8990. }
  8991. else
  8992. {
  8993. valueInvalid = YES;
  8994. DEBUG_ERROR("The ChangeConfiguration value is NULL or OVER SIZE.\n");
  8995. }
  8996. }
  8997. json_object_put(ChangeConfiguration);
  8998. if((uuid==NULL) || (payload ==NULL) || (valueInvalid==YES))
  8999. {
  9000. DEBUG_ERROR("Payload is null or value is invalid.\n");
  9001. sprintf(comfirmstr, "%s", ConfigurationStatusStr[ConfigurationStatus_Rejected] );
  9002. }
  9003. else
  9004. {
  9005. int status = setKeyValue(keystr, valuestr);
  9006. switch(status)
  9007. {
  9008. case ConfigurationStatus_Accepted:
  9009. sprintf(comfirmstr, "%s", ConfigurationStatusStr[ConfigurationStatus_Accepted]);
  9010. ShmOCPP16Data->MsMsg.bits.ChangeConfigurationReq = 1;
  9011. StoreConfigurationTable();
  9012. break;
  9013. case RebootRequired:
  9014. sprintf(comfirmstr, "%s", ConfigurationStatusStr[RebootRequired]);
  9015. StoreConfigurationTable();
  9016. break;
  9017. case NotSupported:
  9018. sprintf(comfirmstr, "%s", ConfigurationStatusStr[NotSupported] );
  9019. break;
  9020. case ConfigurationStatus_Rejected:
  9021. default:
  9022. sprintf(comfirmstr, "%s", ConfigurationStatusStr[ConfigurationStatus_Rejected] );
  9023. break;
  9024. }
  9025. }
  9026. sendChangeConfigurationConfirmation(uuid, comfirmstr);
  9027. ShmOCPP16Data->MsMsg.bits.ChangeConfigurationConf = 1;
  9028. if(((strcmp(keystr,"AuthorizationKey")==0) || (strcmp(keystr,"SecurityProfile")==0) || (strcmp(keystr,"OcppServer")==0) || (strcmp(keystr,"MaintainServer")==0)) && (strcmp(comfirmstr,"Accepted")==0))
  9029. {
  9030. StoreUsrConfigData(&ShmSysConfigAndInfo->SysConfig);
  9031. SetOcppConnStatus(FALSE);
  9032. }
  9033. if(((strcmp(keystr,"FreeVend")==0) || (strcmp(keystr,"isEnableLocalPowerSharing")==0) || (strcmp(keystr,"PowerSharingServerIP")==0)) && (strcmp(comfirmstr,"Accepted")==0))
  9034. {
  9035. StoreUsrConfigData(&ShmSysConfigAndInfo->SysConfig);
  9036. }
  9037. return result;
  9038. }
  9039. int handleClearCacheRequest(char *uuid, char *payload)
  9040. {
  9041. mtrace();
  9042. int result = FAIL;
  9043. char comfirmstr[20];
  9044. char rmFileCmd[100]={0};
  9045. struct stat stats;
  9046. DEBUG_INFO("handleClearCacheRequest...\n");
  9047. stat("/Storage/OCPP", &stats);
  9048. // Check for directory existence
  9049. if (S_ISDIR(stats.st_mode) == 1)
  9050. {}
  9051. else
  9052. {
  9053. DEBUG_INFO("\n OCPP directory not exist, create dir \n");
  9054. sprintf(rmFileCmd,"mkdir -p %s","/Storage/OCPP");
  9055. system(rmFileCmd);
  9056. }
  9057. if(OCPP_cleanLocalCache())
  9058. {
  9059. sprintf(comfirmstr, "%s", ClearCacheStatusStr[ClearCacheStatus_Accepted] );
  9060. }
  9061. else
  9062. {
  9063. sprintf(comfirmstr, "%s", ClearCacheStatusStr[ClearCacheStatus_Rejected] );
  9064. }
  9065. sendClearCacheConfirmation(uuid, comfirmstr);
  9066. system("/bin/fsync -d /dev/mtdblock13;/bin/sync &");
  9067. return result;
  9068. }
  9069. int handleClearChargingProfileRequest(char *uuid, char *payload)
  9070. {
  9071. mtrace();
  9072. int result = FAIL;
  9073. int resultRename;
  9074. int connectorIdInt, chargingProfileIdInt, stackLevelInt;
  9075. char chargingProfilePurposeStr[26]={0};
  9076. int tempconnectorIdInt, tempchargingProfileIdInt, tempstackLevelInt;
  9077. char tempchargingProfilePurposeStr[26]={0};
  9078. char str[100]={0};
  9079. char fname[200]={0};
  9080. char comfirmstr[20]={0};
  9081. char word[1600]={0};
  9082. int clearflag = FALSE;
  9083. int chargingProfileIdIsNULL = FALSE;
  9084. int connectorIsNULL = FALSE;
  9085. int chargingProfilePurposeIsNULL = FALSE;
  9086. int stackLevelIsNULL = FALSE;
  9087. //int GotoEnd = FALSE;
  9088. FILE *fptr1, *fptr2;
  9089. char temp[] = "/Storage/OCPP/ClearChargingProfiletemp.json"; // Create temp file
  9090. int n_chargingProfile=0;
  9091. int isEmptyFile = FALSE;
  9092. char sLineWord[1600]={0};
  9093. char chargingProfiles[10][100]={0};
  9094. int ChargeProfileCount = 0;
  9095. int ch;
  9096. connectorIdInt = chargingProfileIdInt = stackLevelInt = 0;
  9097. DEBUG_INFO("handleClearChargingProfileRequest...\n");
  9098. json_object *ClearChargingProfile;
  9099. ClearChargingProfile = json_tokener_parse(payload);
  9100. if(!is_error(ClearChargingProfile))
  9101. {
  9102. // Optional data
  9103. if(json_object_object_get(ClearChargingProfile, "id") != NULL)
  9104. chargingProfileIdInt = json_object_get_int(json_object_object_get(ClearChargingProfile, "id"));
  9105. else
  9106. chargingProfileIdIsNULL = TRUE;
  9107. if(json_object_object_get(ClearChargingProfile, "connectorId") != NULL)
  9108. connectorIdInt = json_object_get_int(json_object_object_get(ClearChargingProfile, "connectorId"));
  9109. else
  9110. connectorIsNULL = TRUE;
  9111. if(json_object_object_get(ClearChargingProfile, "chargingProfilePurpose") != NULL)
  9112. sprintf((char*)chargingProfilePurposeStr, "%s", json_object_get_string(json_object_object_get(ClearChargingProfile, "chargingProfilePurpose")));
  9113. else
  9114. chargingProfilePurposeIsNULL = TRUE;
  9115. if(json_object_object_get(ClearChargingProfile, "stackLevel") != NULL)
  9116. stackLevelInt = json_object_get_int(json_object_object_get(ClearChargingProfile, "stackLevel"));
  9117. else
  9118. stackLevelIsNULL = TRUE;
  9119. }
  9120. json_object_put(ClearChargingProfile);
  9121. if(connectorIsNULL == FALSE)
  9122. {
  9123. switch(connectorIdInt)
  9124. {
  9125. case 0:
  9126. if(chargingProfilePurposeIsNULL == TRUE)
  9127. {
  9128. int l = 0;
  9129. strcpy(fname, ChargePointMaxProfile_JSON);
  9130. if((access(fname,F_OK))!=-1)
  9131. {
  9132. strcpy(chargingProfiles[l], fname);
  9133. l = l + 1;
  9134. }
  9135. strcpy(fname, TxDefaultProfile_0_JSON);
  9136. if((access(fname,F_OK))!=-1)
  9137. {
  9138. strcpy(chargingProfiles[l], fname);
  9139. l = l + 1;
  9140. }
  9141. ChargeProfileCount = l;
  9142. }
  9143. else if((chargingProfilePurposeIsNULL == FALSE)&&(strcmp(chargingProfilePurposeStr,"ChargePointMaxProfile")==0))
  9144. {
  9145. strcpy(fname, ChargePointMaxProfile_JSON);
  9146. if((access(fname,F_OK))!=-1)
  9147. {
  9148. strcpy(chargingProfiles[0], fname);
  9149. ChargeProfileCount = 1;
  9150. }
  9151. }
  9152. else if((chargingProfilePurposeIsNULL == FALSE)&&(strcmp(chargingProfilePurposeStr,"TxDefaultProfile")==0))
  9153. {
  9154. strcpy(fname, TxDefaultProfile_0_JSON);
  9155. if((access(fname,F_OK))!=-1)
  9156. {
  9157. strcpy(chargingProfiles[0], fname);
  9158. ChargeProfileCount = 1;
  9159. }
  9160. }
  9161. break;
  9162. default:
  9163. if(chargingProfilePurposeIsNULL == TRUE)
  9164. {
  9165. int m = 0;
  9166. memset(fname, 0, ARRAY_SIZE(fname));
  9167. sprintf(fname, "/Storage/OCPP/TxDefaultProfile_%d.json", connectorIdInt);
  9168. if((access(fname,F_OK))!=-1)
  9169. {
  9170. strcpy(chargingProfiles[m], fname);
  9171. m = m + 1;
  9172. }
  9173. memset(fname, 0, ARRAY_SIZE(fname));
  9174. sprintf(fname, "/Storage/OCPP/TxProfile_%d.json", connectorIdInt);
  9175. if((access(fname,F_OK))!=-1)
  9176. {
  9177. strcpy(chargingProfiles[m], fname);
  9178. m = m + 1;
  9179. }
  9180. ChargeProfileCount = m;
  9181. }
  9182. else if((chargingProfilePurposeIsNULL == FALSE)&&(strcmp(chargingProfilePurposeStr,"TxDefaultProfile")==0))
  9183. {
  9184. //strcpy(fname, TxDefaultProfile_1_JSON);
  9185. sprintf(fname, "/Storage/OCPP/TxDefaultProfile_%d.json", connectorIdInt);
  9186. if((access(fname,F_OK))!=-1)
  9187. {
  9188. strcpy(chargingProfiles[0], fname);
  9189. ChargeProfileCount = 1;
  9190. }
  9191. }
  9192. else if((chargingProfilePurposeIsNULL == FALSE)&&(strcmp(chargingProfilePurposeStr,"TxProfile")==0))
  9193. {
  9194. sprintf(fname, "/Storage/OCPP/TxProfile_%d.json", connectorIdInt);
  9195. if((access(fname,F_OK))!=-1)
  9196. {
  9197. strcpy(chargingProfiles[0], fname);
  9198. ChargeProfileCount = 1;
  9199. }
  9200. //strcpy(fname, TxProfile_1_JSON);
  9201. }
  9202. //strcpy(fname, ChargePointMaxProfile_JSON );
  9203. break;
  9204. }
  9205. }
  9206. else // Check all Charging Profiles
  9207. {
  9208. int i = 0;
  9209. char fnametemp[200]={0};
  9210. ChargeProfileCount = 0;
  9211. //Check ChargePointMaxProfile.json exit
  9212. if((access("/Storage/OCPP/ChargePointMaxProfile.json",F_OK))!=-1)
  9213. {
  9214. strcpy(chargingProfiles[i], "/Storage/OCPP/ChargePointMaxProfile.json");
  9215. i = i + 1;
  9216. }
  9217. //Check TxDefaultProfile_0.json exit
  9218. if((access("/Storage/OCPP/TxDefaultProfile_0.json",F_OK))!=-1)
  9219. {
  9220. strcpy(chargingProfiles[i], "/Storage/OCPP/TxDefaultProfile_0.json");
  9221. i = i + 1;
  9222. }
  9223. //Check TxDefaultProfile_%d.json
  9224. for(int j=1; j <= gunTotalNumber; j++)
  9225. {
  9226. memset(fnametemp, 0, ARRAY_SIZE(fnametemp));
  9227. sprintf(fnametemp, "/Storage/OCPP/TxDefaultProfile_%d.json", j);
  9228. if((access(fnametemp,F_OK))!=-1)
  9229. {
  9230. strcpy(chargingProfiles[i], fnametemp);
  9231. i = i + 1;
  9232. }
  9233. }
  9234. //Check TxProfile_%d.json
  9235. for(int j=1; j <= gunTotalNumber; j++)
  9236. {
  9237. memset(fnametemp, 0, ARRAY_SIZE(fnametemp));
  9238. sprintf(fnametemp, "/Storage/OCPP/TxProfile_%d.json", j);
  9239. if((access(fnametemp,F_OK))!=-1)
  9240. {
  9241. strcpy(chargingProfiles[i], fnametemp);
  9242. i = i + 1;
  9243. }
  9244. }
  9245. ChargeProfileCount = i;
  9246. }// End connectorIsNULL is TRUE
  9247. if(ChargeProfileCount == 0)
  9248. {
  9249. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Unknown] );
  9250. goto end;
  9251. }
  9252. if(connectorIsNULL == FALSE && (connectorIdInt != 0) && ( (connectorIdInt-1) > gunTotalNumber) )
  9253. {
  9254. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Unknown] );
  9255. goto end;
  9256. }
  9257. if((connectorIsNULL == FALSE) && (connectorIdInt == 0) )
  9258. {
  9259. memset(str, 0, ARRAY_SIZE(str));
  9260. // clear temp file
  9261. sprintf(str,"rm -f %s",temp);
  9262. system(str);
  9263. for(int k=0; k < ChargeProfileCount; k++)
  9264. {
  9265. memset(str, 0, ARRAY_SIZE(str));
  9266. //clear file in C
  9267. sprintf(str,"rm -f %s",chargingProfiles[k]);
  9268. system(str);
  9269. }
  9270. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Accepted] );
  9271. goto end;
  9272. }
  9273. else if(connectorIsNULL == TRUE)
  9274. {
  9275. for(int k=0; k < ChargeProfileCount; k++)
  9276. {
  9277. fptr1 = fopen(chargingProfiles[k], "r");
  9278. fptr2 = fopen("/Storage/OCPP/ClearChargingProfiletemp.json", "w+");
  9279. //Check Charging Profile Count
  9280. while(fscanf(fptr1, "%s", word) != EOF)
  9281. {
  9282. //DEBUG_INFO("word=%s\n",word);
  9283. if(strstr(word, "chargingProfileId")!= NULL)
  9284. {
  9285. //DEBUG_INFO("test chargingProfileId \n");
  9286. n_chargingProfile = n_chargingProfile + 1;
  9287. //DEBUG_INFO("chargingProfileId Found\n");
  9288. }
  9289. }
  9290. rewind(fptr1);
  9291. //search Charging Profile Element
  9292. //int i= 0;
  9293. while ( fgets( sLineWord, sizeof sLineWord, fptr1 ) != NULL )
  9294. {
  9295. json_object *tmpProfilee;
  9296. tmpProfilee = json_tokener_parse(sLineWord);
  9297. if(!is_error(tmpProfilee))
  9298. {
  9299. if(json_object_object_get(tmpProfilee, "connectorId") != NULL)
  9300. {
  9301. tempconnectorIdInt = json_object_get_int(json_object_object_get(tmpProfilee, "connectorId"));
  9302. DEBUG_INFO("file's gun number: %d\n", tempconnectorIdInt);
  9303. }
  9304. if(json_object_object_get(json_object_object_get(tmpProfilee, "csChargingProfiles"), "chargingProfileId") != NULL)
  9305. {
  9306. tempchargingProfileIdInt = json_object_get_int(json_object_object_get(json_object_object_get(tmpProfilee, "csChargingProfiles"), "chargingProfileId"));
  9307. DEBUG_INFO("file's chargingProfileId: %d\n", tempchargingProfileIdInt);
  9308. }
  9309. if(json_object_object_get(json_object_object_get(tmpProfilee, "csChargingProfiles"), "stackLevel") != NULL)
  9310. {
  9311. tempstackLevelInt = json_object_get_int(json_object_object_get(json_object_object_get(tmpProfilee, "csChargingProfiles"), "stackLevel"));
  9312. DEBUG_INFO("file's stackLevel: %d\n", tempstackLevelInt);
  9313. }
  9314. if(json_object_object_get(json_object_object_get(tmpProfilee, "csChargingProfiles"), "chargingProfilePurpose") != NULL)
  9315. {
  9316. sprintf((char*)tempchargingProfilePurposeStr, "%s", json_object_get_string(json_object_object_get(json_object_object_get(tmpProfilee, "csChargingProfiles"), "chargingProfilePurpose")));
  9317. DEBUG_INFO("file's chargingProfilePurpose: %s\n", tempchargingProfilePurposeStr);
  9318. }
  9319. }
  9320. json_object_put(tmpProfilee);
  9321. if((chargingProfileIdIsNULL == FALSE)&&(tempchargingProfileIdInt == chargingProfileIdInt))
  9322. {
  9323. //------- not write to fptr2-------//
  9324. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Accepted] );
  9325. //clearflag = TRUE;
  9326. }
  9327. else if((chargingProfilePurposeIsNULL == FALSE)&&(strcmp(tempchargingProfilePurposeStr, chargingProfilePurposeStr) == 0))
  9328. {
  9329. //------- not write to fptr2-------//
  9330. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Accepted] );
  9331. }
  9332. else if((stackLevelIsNULL == FALSE) &&(tempstackLevelInt == stackLevelInt))
  9333. {
  9334. //------- not write to fptr2-------//
  9335. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Accepted] );
  9336. }
  9337. else if(chargingProfileIdIsNULL && chargingProfilePurposeIsNULL && stackLevelIsNULL)
  9338. {
  9339. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Accepted] );
  9340. }
  9341. else
  9342. {
  9343. fprintf(fptr2, sLineWord);//writing data into file
  9344. }
  9345. memset(sLineWord, 0, ARRAY_SIZE(sLineWord));
  9346. } //End of while ( fgets( sLineWord, sizeof sLineWord, fptr1 ) != NULL )
  9347. if(clearflag == TRUE)
  9348. {
  9349. fclose(fptr1);
  9350. fclose(fptr2);
  9351. sprintf(str,"rm -f %s",chargingProfiles[k]);
  9352. system(str);
  9353. // clear temp file
  9354. sprintf(str,"rm -f %s",temp);
  9355. system(str);
  9356. }
  9357. else
  9358. {
  9359. fclose(fptr1);
  9360. fclose(fptr2);
  9361. memset(str, 0, ARRAY_SIZE(str));
  9362. sprintf(str,"rm -f %s",chargingProfiles[k]);
  9363. system(str);
  9364. resultRename = rename(temp, chargingProfiles[k]);
  9365. if(resultRename == 0)
  9366. {
  9367. DEBUG_INFO("File ChargingProfile renamed successfully\n");
  9368. }
  9369. else
  9370. {
  9371. DEBUG_INFO("Error: unable to rename the ChargingProfile file\n");
  9372. }
  9373. if(comfirmstr[0]== 0)
  9374. {
  9375. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Unknown] );
  9376. }
  9377. //Check chargingProfile is empty file
  9378. /*------ Read the file ----------------*/
  9379. fptr1=fopen(chargingProfiles[k],"r");
  9380. ch=fgetc(fptr1);
  9381. rewind(fptr1);
  9382. memset(sLineWord, 0, ARRAY_SIZE(sLineWord));
  9383. if(ch!=EOF)
  9384. {
  9385. while (fgets( sLineWord, sizeof sLineWord, fptr1) != NULL)
  9386. {
  9387. str[strlen(sLineWord) - 1] = '\0'; // eat the newline fgets() stores
  9388. if(sLineWord[0]=='\0')
  9389. {
  9390. isEmptyFile = TRUE;
  9391. break;
  9392. }
  9393. else
  9394. {
  9395. isEmptyFile = FALSE;
  9396. break;
  9397. }
  9398. }
  9399. }
  9400. else
  9401. isEmptyFile = TRUE;
  9402. fclose(fptr1);
  9403. if(isEmptyFile == TRUE)
  9404. {
  9405. memset(str, 0, ARRAY_SIZE(str));
  9406. sprintf(str,"rm -f %s",chargingProfiles[k]);
  9407. system(str);
  9408. }
  9409. }
  9410. }// End of while(int k=0; k < ChargePointCount; k++)
  9411. }
  9412. else if((connectorIsNULL == FALSE) && (connectorIdInt != 0) )
  9413. {
  9414. DEBUG_INFO("ChargeProfileCount = %d\n", ChargeProfileCount);
  9415. for(int k=0; k < ChargeProfileCount; k++)
  9416. {
  9417. fptr1 = fopen(chargingProfiles[k], "r");
  9418. fptr2 = fopen(temp, "w+");
  9419. //Check Charging Profile Count
  9420. while(fscanf(fptr1, "%s", word) != EOF)
  9421. {
  9422. //DEBUG_INFO("word=%s\n",word);
  9423. if(strstr(word, "chargingProfileId")!= NULL)
  9424. {
  9425. n_chargingProfile = n_chargingProfile + 1;
  9426. }
  9427. }
  9428. rewind(fptr1);
  9429. //search Charging Profile Element
  9430. //int i= 0;
  9431. while ( fgets( sLineWord, sizeof sLineWord, fptr1 ) != NULL )
  9432. {
  9433. json_object *tmpProfilee;
  9434. tmpProfilee = json_tokener_parse(sLineWord);
  9435. if(!is_error(tmpProfilee))
  9436. {
  9437. if(json_object_object_get(tmpProfilee, "connectorId") != NULL)
  9438. {
  9439. tempconnectorIdInt = json_object_get_int(json_object_object_get(tmpProfilee, "connectorId"));
  9440. DEBUG_INFO("file's gun number: %d\n", tempconnectorIdInt);
  9441. }
  9442. if(json_object_object_get(json_object_object_get(tmpProfilee, "csChargingProfiles"), "chargingProfileId") != NULL)
  9443. {
  9444. tempchargingProfileIdInt = json_object_get_int(json_object_object_get(json_object_object_get(tmpProfilee, "csChargingProfiles"), "chargingProfileId"));
  9445. DEBUG_INFO("file's chargingProfileId: %d\n", tempchargingProfileIdInt);
  9446. }
  9447. if(json_object_object_get(json_object_object_get(tmpProfilee, "csChargingProfiles"), "stackLevel") != NULL)
  9448. {
  9449. tempstackLevelInt = json_object_get_int(json_object_object_get(json_object_object_get(tmpProfilee, "csChargingProfiles"), "stackLevel"));
  9450. DEBUG_INFO("file's stackLevel: %d\n", tempstackLevelInt);
  9451. }
  9452. if(json_object_object_get(json_object_object_get(tmpProfilee, "csChargingProfiles"), "chargingProfilePurpose") != NULL)
  9453. {
  9454. sprintf((char*)tempchargingProfilePurposeStr, "%s", json_object_get_string(json_object_object_get(json_object_object_get(tmpProfilee, "csChargingProfiles"), "chargingProfilePurpose")));
  9455. DEBUG_INFO("file's chargingProfilePurpose: %s\n", tempchargingProfilePurposeStr);
  9456. }
  9457. }
  9458. json_object_put(tmpProfilee);
  9459. if((chargingProfileIdIsNULL == FALSE)&&(tempchargingProfileIdInt == chargingProfileIdInt))
  9460. {
  9461. //------- not write to fptr2-------//
  9462. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Accepted] );
  9463. //clearflag = TRUE;
  9464. }
  9465. else if((stackLevelIsNULL == FALSE) &&(tempstackLevelInt == stackLevelInt))
  9466. {
  9467. //------- not write to fptr2-------//
  9468. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Accepted] );
  9469. }
  9470. else if(stackLevelIsNULL == TRUE)
  9471. {
  9472. //Clear Whole File
  9473. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Accepted] );
  9474. clearflag = TRUE;
  9475. break;
  9476. }
  9477. else
  9478. {
  9479. fprintf(fptr2, sLineWord);//writing data into file
  9480. }
  9481. memset(sLineWord, 0, ARRAY_SIZE(sLineWord));
  9482. }
  9483. if(clearflag == TRUE)
  9484. {
  9485. fclose(fptr1);
  9486. fclose(fptr2);
  9487. sprintf(str,"rm -f %s",chargingProfiles[k]);
  9488. system(str);
  9489. // clear temp file
  9490. sprintf(str,"rm -f %s",temp);
  9491. system(str);
  9492. }
  9493. else
  9494. {
  9495. fclose(fptr1);
  9496. fclose(fptr2);
  9497. sprintf(str,"rm -f %s",chargingProfiles[k]);
  9498. system(str);
  9499. resultRename = rename(temp, chargingProfiles[k]);
  9500. if(resultRename == 0)
  9501. {
  9502. DEBUG_INFO("File ChargingProfile renamed successfully");
  9503. }
  9504. else
  9505. {
  9506. DEBUG_INFO("Error: unable to rename the ChargingProfile file");
  9507. }
  9508. if(comfirmstr[0]== 0)
  9509. {
  9510. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Unknown] );
  9511. }
  9512. //Check chargingProfile is empty file
  9513. /*------ Read the file ----------------*/
  9514. fptr1=fopen(chargingProfiles[k],"r");
  9515. ch=fgetc(fptr1);
  9516. rewind(fptr1);
  9517. memset(sLineWord, 0, ARRAY_SIZE(sLineWord));
  9518. if(ch!=EOF)
  9519. {
  9520. while (fgets( sLineWord, sizeof sLineWord, fptr1) != NULL)
  9521. {
  9522. str[strlen(sLineWord) - 1] = '\0'; // eat the newline fgets() stores
  9523. if(sLineWord[0]=='\0')
  9524. {
  9525. isEmptyFile = TRUE;
  9526. break;
  9527. }
  9528. else
  9529. {
  9530. isEmptyFile = FALSE;
  9531. break;
  9532. }
  9533. }
  9534. }
  9535. else
  9536. isEmptyFile = TRUE;
  9537. fclose(fptr1);
  9538. if(isEmptyFile == TRUE)
  9539. {
  9540. memset(str, 0, ARRAY_SIZE(str));
  9541. sprintf(str,"rm -f %s",chargingProfiles[k]);
  9542. system(str);
  9543. }
  9544. /*------- End of reading ---------------*/
  9545. }
  9546. } // while(int k=0; k < ChargeProfileCount; k++)
  9547. }// (connectorIsNULL == FALSE) && (connectorIdInt != 0)
  9548. end:
  9549. if(strcmp(comfirmstr, ClearChargingProfileStatusStr[ClearChargingProfileStatus_Accepted]) == 0)
  9550. {
  9551. if(connectorIdInt == 0)
  9552. {
  9553. for(uint8_t idx=0;idx<gunTotalNumber;idx++)
  9554. {
  9555. checkCompositeSchedule((idx+1), 86400, &ShmOCPP16Data->SmartChargingProfile[idx], TRUE);
  9556. }
  9557. }
  9558. else
  9559. checkCompositeSchedule(connectorIdInt, 86400, &ShmOCPP16Data->SmartChargingProfile[connectorIdInt-1], TRUE);
  9560. }
  9561. sendClearChargingProfileConfirmation(uuid, comfirmstr);
  9562. system("/bin/fsync -d /dev/mtdblock13;/bin/sync &");
  9563. return result;
  9564. }
  9565. void createFirmwareVersionByDataTransfer(void)
  9566. {
  9567. json_object *FirmwareDataTransfer = json_object_new_object();
  9568. // AC & DC model
  9569. json_object_object_add(FirmwareDataTransfer, "CsuBootLoadFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.CsuBootLoadFwRev));
  9570. json_object_object_add(FirmwareDataTransfer, "CsuKernelFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.CsuKernelFwRev));
  9571. json_object_object_add(FirmwareDataTransfer, "CsuRootFsFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.CsuRootFsFwRev));
  9572. json_object_object_add(FirmwareDataTransfer, "CsuPrimFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.CsuPrimFwRev));
  9573. // DC model
  9574. if((ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D'))
  9575. {
  9576. if((gunType[1] != GUN_TYPE_UNKNOWN) ||
  9577. (gunType[2] != GUN_TYPE_UNKNOWN) ||
  9578. (gunType[3] != GUN_TYPE_UNKNOWN))
  9579. {
  9580. json_object_object_add(FirmwareDataTransfer, "Connector2FwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.Connector2FwRev));
  9581. }
  9582. if((ShmSysConfigAndInfo->SysConfig.ModelName[1]!='B') && (ShmSysConfigAndInfo->SysConfig.ModelName[1]!='K') && (ShmSysConfigAndInfo->SysConfig.ModelName[1]!='O'))
  9583. {
  9584. // DS DM DW
  9585. json_object_object_add(FirmwareDataTransfer, "FanModuleFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.FanModuleFwRev));
  9586. json_object_object_add(FirmwareDataTransfer, "RelayModuleFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.RelayModuleFwRev));
  9587. json_object_object_add(FirmwareDataTransfer, "LedModuleFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.LedModuleFwRev));
  9588. json_object_object_add(FirmwareDataTransfer, "Connector1FwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.Connector1FwRev));
  9589. json_object_object_add(FirmwareDataTransfer, "PsuPrimFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.PsuPrimFwRev));
  9590. json_object_object_add(FirmwareDataTransfer, "PsuSecFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.PsuSecFwRev));
  9591. }
  9592. else
  9593. {
  9594. json_object_object_add(FirmwareDataTransfer, "FanModuleFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.FanModuleFwRev));
  9595. json_object_object_add(FirmwareDataTransfer, "RelayModuleFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.RelayModuleFwRev));
  9596. json_object_object_add(FirmwareDataTransfer, "PsuPrimFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.PsuPrimFwRev));
  9597. json_object_object_add(FirmwareDataTransfer, "PsuSecFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.PsuSecFwRev));
  9598. json_object_object_add(FirmwareDataTransfer, "DD0_CsuBootLoadFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[0].CsuBootLoadFwRev));
  9599. json_object_object_add(FirmwareDataTransfer, "DD0_CsuKernelFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[0].CsuKernelFwRev));
  9600. json_object_object_add(FirmwareDataTransfer, "DD0_CsuRootFsFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[0].CsuRootFsFwRev));
  9601. json_object_object_add(FirmwareDataTransfer, "DD0_CsuPrimFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[0].CsuPrimFwRev));
  9602. json_object_object_add(FirmwareDataTransfer, "DD0_FanModuleFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[0].FanModuleFwRev));
  9603. json_object_object_add(FirmwareDataTransfer, "DD0_RelayModuleFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[0].RelayModuleFwRev));
  9604. json_object_object_add(FirmwareDataTransfer, "DD0_LedModuleFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[0].LedModuleFwRev));
  9605. json_object_object_add(FirmwareDataTransfer, "DD0_Connector1FwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[0].Connector1FwRev));
  9606. json_object_object_add(FirmwareDataTransfer, "DD0_Connector2FwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[0].Connector2FwRev));
  9607. if(strlen((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].CsuBootLoadFwRev) > 0)
  9608. json_object_object_add(FirmwareDataTransfer, "DD1_CsuBootLoadFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].CsuBootLoadFwRev));
  9609. if(strlen((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].CsuKernelFwRev) > 0)
  9610. json_object_object_add(FirmwareDataTransfer, "DD1_CsuKernelFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].CsuKernelFwRev));
  9611. if(strlen((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].CsuRootFsFwRev) > 0)
  9612. json_object_object_add(FirmwareDataTransfer, "DD1_CsuRootFsFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].CsuRootFsFwRev));
  9613. if(strlen((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].CsuPrimFwRev) > 0)
  9614. json_object_object_add(FirmwareDataTransfer, "DD1_CsuPrimFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].CsuPrimFwRev));
  9615. if(strlen((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].FanModuleFwRev) > 0)
  9616. json_object_object_add(FirmwareDataTransfer, "DD1_FanModuleFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].FanModuleFwRev));
  9617. if(strlen((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].RelayModuleFwRev) > 0)
  9618. json_object_object_add(FirmwareDataTransfer, "DD1_RelayModuleFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].RelayModuleFwRev));
  9619. if(strlen((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].LedModuleFwRev) > 0)
  9620. json_object_object_add(FirmwareDataTransfer, "DD1_LedModuleFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].LedModuleFwRev));
  9621. if(strlen((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].Connector1FwRev) > 0)
  9622. json_object_object_add(FirmwareDataTransfer, "DD1_Connector1FwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].Connector1FwRev));
  9623. if(strlen((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].Connector2FwRev) > 0)
  9624. json_object_object_add(FirmwareDataTransfer, "D11_Connector2FwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].Connector2FwRev));
  9625. }
  9626. }
  9627. // 4G model
  9628. if((ShmSysConfigAndInfo->SysConfig.ModelName[10]=='T')||(ShmSysConfigAndInfo->SysConfig.ModelName[10]=='D'))
  9629. {
  9630. json_object_object_add(FirmwareDataTransfer, "TelcomModemFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysConfig.TelecomInterface.TelcomSoftwareVer));
  9631. }
  9632. sprintf((char*)ShmOCPP16Data->DataTransfer[0].ResponseData, json_object_to_json_string_ext(FirmwareDataTransfer, JSON_C_TO_STRING_PLAIN));
  9633. json_object_put(FirmwareDataTransfer);
  9634. }
  9635. int handleDataTransferRequest(char *uuid, char *payload)
  9636. {
  9637. mtrace();
  9638. json_object *response = json_object_new_object();
  9639. int result = FAIL;
  9640. char tempvendorId[255]={0};
  9641. char tempmessageId[50]={0};
  9642. char tempdata[1024]={0};
  9643. char message[2048]={0};
  9644. DEBUG_INFO("handleDataTransferRequest...\n");
  9645. if((uuid != NULL) && (payload != NULL))
  9646. {
  9647. json_object *DataTransfer;
  9648. DataTransfer = json_tokener_parse(payload);
  9649. if(!is_error(DataTransfer))
  9650. {
  9651. // Required data
  9652. if(json_object_object_get(DataTransfer, "vendorId") != NULL)
  9653. sprintf((char*)tempvendorId, "%s", json_object_get_string(json_object_object_get(DataTransfer, "vendorId")));
  9654. // Optional data
  9655. if(json_object_object_get(DataTransfer, "messageId") != NULL)
  9656. sprintf((char*)tempmessageId, "%s", json_object_get_string(json_object_object_get(DataTransfer, "messageId")));
  9657. if(json_object_object_get(DataTransfer, "data") != NULL)
  9658. sprintf((char*)tempdata, "%s", json_object_get_string(json_object_object_get(DataTransfer, "data")));
  9659. result = PASS;
  9660. }
  9661. json_object_put(DataTransfer);
  9662. if(strstr(tempmessageId, "ID_FirmwareVersion") != NULL)
  9663. {
  9664. // Send all moudle firmware version on EVSE
  9665. createFirmwareVersionByDataTransfer();
  9666. json_object_object_add(response, "status", json_object_new_string("Accepted"));
  9667. json_object_object_add(response, "data", json_object_new_string((char*)ShmOCPP16Data->DataTransfer[0].ResponseData));
  9668. sprintf(message,"[%d,\"%s\",%s]",MESSAGE_TYPE_CALLRESULT, uuid, json_object_to_json_string_ext(response, JSON_C_TO_STRING_PLAIN));
  9669. json_object_put(response);
  9670. }
  9671. else if(strstr(tempmessageId, "ID_Tmate") != NULL)
  9672. {
  9673. system("/usr/bin/run_tmate_restart.sh &");
  9674. json_object_object_add(response, "status", json_object_new_string("Accepted"));
  9675. sprintf(message,"[%d,\"%s\",%s]",MESSAGE_TYPE_CALLRESULT, uuid, json_object_to_json_string_ext(response, JSON_C_TO_STRING_PLAIN));
  9676. json_object_put(response);
  9677. }
  9678. else if(strstr(tempmessageId, "ID_ChargingPreference") != NULL)
  9679. {
  9680. json_object *data;
  9681. data = json_tokener_parse(tempdata);
  9682. if(!is_error(data))
  9683. {
  9684. if((json_object_object_get(data, "ConnectorId") != NULL) && (json_object_get_int(json_object_object_get(data, "ConnectorId")) > 0) && (json_object_get_int(json_object_object_get(data, "ConnectorId")) <= gunTotalNumber))
  9685. {
  9686. DEBUG_INFO("ChargeingPreference connector id: %d\n", json_object_get_int(json_object_object_get(data, "ConnectorId")));
  9687. memset(&ShmOCPP16Data->SessionTarget[json_object_get_int(json_object_object_get(data, "ConnectorId"))], 0x00, sizeof(struct StructSessionTarget));
  9688. if(json_object_object_get(data, "SOC") != NULL)
  9689. {
  9690. ShmOCPP16Data->SessionTarget[json_object_get_int(json_object_object_get(data, "ConnectorId"))-1].targetSoc = json_object_get_int(json_object_object_get(data, "SOC"));
  9691. DEBUG_INFO("ChargeingPreference target soc: %d\n", json_object_get_int(json_object_object_get(data, "SOC")));
  9692. }
  9693. if(json_object_object_get(data, "Energy") != NULL)
  9694. {
  9695. ShmOCPP16Data->SessionTarget[json_object_get_int(json_object_object_get(data, "ConnectorId"))-1].targetEnergy = json_object_get_int(json_object_object_get(data, "Energy"));
  9696. DEBUG_INFO("ChargeingPreference target energy: %d KWH\n", json_object_get_int(json_object_object_get(data, "Energy")));
  9697. }
  9698. if(json_object_object_get(data, "Duration") != NULL)
  9699. {
  9700. ShmOCPP16Data->SessionTarget[json_object_get_int(json_object_object_get(data, "ConnectorId"))-1].targetDuration = json_object_get_int(json_object_object_get(data, "Duration"));
  9701. DEBUG_INFO("ChargeingPreference target duration: %d minutes\n", json_object_get_int(json_object_object_get(data, "Duration")));
  9702. }
  9703. json_object_object_add(response, "status", json_object_new_string("Accepted"));
  9704. }
  9705. else
  9706. {
  9707. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  9708. json_object_object_add(response, "data", json_object_new_string("Connector id must > 0."));
  9709. }
  9710. }
  9711. else
  9712. {
  9713. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  9714. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  9715. }
  9716. json_object_put(data);
  9717. sprintf(message,"[%d,\"%s\",%s]",MESSAGE_TYPE_CALLRESULT, uuid, json_object_to_json_string_ext(response, JSON_C_TO_STRING_PLAIN));
  9718. json_object_put(response);
  9719. }
  9720. else if(strstr(tempmessageId, "SetLEDBar") != NULL)
  9721. {
  9722. json_object *data;
  9723. data = json_tokener_parse(tempdata);
  9724. if(!is_error(data))
  9725. {
  9726. ShmSysConfigAndInfo->SysConfig.LedInfo.Intensity = json_object_get_int(json_object_object_get(data, "Intensity"));
  9727. ShmSysConfigAndInfo->SysConfig.LedInfo.Red[0] = json_object_get_int(json_object_object_get(json_object_object_get(data, "Idle"), "R"));
  9728. ShmSysConfigAndInfo->SysConfig.LedInfo.Green[0]= json_object_get_int(json_object_object_get(json_object_object_get(data, "Idle"), "G"));
  9729. ShmSysConfigAndInfo->SysConfig.LedInfo.Blue[0] = json_object_get_int(json_object_object_get(json_object_object_get(data, "Idle"), "B"));
  9730. ShmSysConfigAndInfo->SysConfig.LedInfo.Red[1] = json_object_get_int(json_object_object_get(json_object_object_get(data, "Charging"), "R"));
  9731. ShmSysConfigAndInfo->SysConfig.LedInfo.Green[1]= json_object_get_int(json_object_object_get(json_object_object_get(data, "Charging"), "G"));
  9732. ShmSysConfigAndInfo->SysConfig.LedInfo.Blue[1] = json_object_get_int(json_object_object_get(json_object_object_get(data, "Charging"), "B"));
  9733. ShmSysConfigAndInfo->SysConfig.LedInfo.Red[2] = json_object_get_int(json_object_object_get(json_object_object_get(data, "Fault"), "R"));
  9734. ShmSysConfigAndInfo->SysConfig.LedInfo.Green[2]= json_object_get_int(json_object_object_get(json_object_object_get(data, "Fault"), "G"));
  9735. ShmSysConfigAndInfo->SysConfig.LedInfo.Blue[2] = json_object_get_int(json_object_object_get(json_object_object_get(data, "Fault"), "B"));
  9736. json_object_object_add(response, "status", json_object_new_string("Accepted"));
  9737. }
  9738. else
  9739. {
  9740. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  9741. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  9742. }
  9743. json_object_put(data);
  9744. sprintf(message,"[%d,\"%s\",%s]",MESSAGE_TYPE_CALLRESULT, uuid, json_object_to_json_string_ext(response, JSON_C_TO_STRING_PLAIN));
  9745. json_object_put(response);
  9746. }
  9747. else if(strstr(tempmessageId, "SetUserPrice") != NULL)
  9748. {
  9749. json_object *data;
  9750. data = json_tokener_parse(tempdata);
  9751. if(!is_error(data))
  9752. {
  9753. memset(&ShmOCPP16Data->Cost.SetUserPrice, 0x00, sizeof(struct StrcutSetUserPrice));
  9754. json_object_object_add(response, "status", json_object_new_string("Accepted"));
  9755. if(json_object_object_get(data, "idToken") != NULL)
  9756. {
  9757. sprintf((char*)ShmOCPP16Data->Cost.SetUserPrice.idToken, "%s", json_object_get_string(json_object_object_get(data, "idToken")));
  9758. DEBUG_INFO("idToken: %s\n", json_object_get_string(json_object_object_get(data, "idToken")));
  9759. }
  9760. else
  9761. {
  9762. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  9763. json_object_object_add(response, "data", json_object_new_string("idToken not found."));
  9764. }
  9765. if(json_object_object_get(data, "price") != NULL) //v1.0
  9766. {
  9767. sprintf((char*)ShmOCPP16Data->Cost.SetUserPrice.price, "%s", json_object_get_string(json_object_object_get(data, "price")));
  9768. DEBUG_INFO("price: %s\n", json_object_get_string(json_object_object_get(data, "price")));
  9769. }
  9770. else if(json_object_object_get(data, "priceText") != NULL) //v2.0
  9771. {
  9772. sprintf((char*)ShmOCPP16Data->Cost.SetUserPrice.price, "%s", json_object_get_string(json_object_object_get(data, "priceText")));
  9773. DEBUG_INFO("priceText: %s\n", json_object_get_string(json_object_object_get(data, "priceText")));
  9774. }
  9775. else
  9776. {
  9777. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  9778. json_object_object_add(response, "data", json_object_new_string("price or priceText not found."));
  9779. }
  9780. }
  9781. else
  9782. {
  9783. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  9784. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  9785. }
  9786. json_object_put(data);
  9787. sprintf(message,"[%d,\"%s\",%s]",MESSAGE_TYPE_CALLRESULT, uuid, json_object_to_json_string_ext(response, JSON_C_TO_STRING_PLAIN));
  9788. json_object_put(response);
  9789. }
  9790. else if(strstr(tempmessageId, "RunningCost") != NULL)
  9791. {
  9792. json_object *data;
  9793. data = json_tokener_parse(tempdata);
  9794. if(!is_error(data))
  9795. {
  9796. json_object_object_add(response, "status", json_object_new_string("Accepted"));
  9797. if(json_object_object_get(data, "txId") != NULL)
  9798. {
  9799. // California pricing V1.0
  9800. DEBUG_INFO("California pricing V1.0\n");
  9801. DEBUG_INFO("txId: %d\n", json_object_get_int(json_object_object_get(data, "txId")));
  9802. sprintf((char*)dmsVersion, "1.0");
  9803. for(int idx = 0;idx<gunTotalNumber;idx++)
  9804. {
  9805. if(ShmOCPP16Data->StartTransaction[idx].ResponseTransactionId == json_object_get_int(json_object_object_get(data, "txId")))
  9806. {
  9807. memset(&ShmOCPP16Data->Cost.RunningCost[idx], 0x00, sizeof(struct StrcutRunningCost));
  9808. ShmOCPP16Data->Cost.RunningCost[idx].txId = json_object_get_int(json_object_object_get(data, "txId"));
  9809. if(json_object_object_get(data, "description") != NULL)
  9810. {
  9811. DEBUG_INFO("description: %s\n", json_object_get_string(json_object_object_get(data, "description")));
  9812. sprintf((char*)ShmOCPP16Data->Cost.RunningCost[idx].description, "%s", json_object_get_string(json_object_object_get(data, "description")));
  9813. }
  9814. else
  9815. {
  9816. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  9817. json_object_object_add(response, "data", json_object_new_string("description not found."));
  9818. }
  9819. }
  9820. }
  9821. }
  9822. else if(json_object_object_get(data, "transactionId") != NULL)
  9823. {
  9824. // California pricing V2.0
  9825. DEBUG_INFO("California pricing V2.0\n");
  9826. DEBUG_INFO("transactionId: %d\n", json_object_get_int(json_object_object_get(data, "transactionId")));
  9827. sprintf((char*)dmsVersion, "2.0");
  9828. for(int idx=0;idx<gunTotalNumber;idx++)
  9829. {
  9830. if(ShmOCPP16Data->StartTransaction[idx].ResponseTransactionId == json_object_get_int(json_object_object_get(data, "transactionId")))
  9831. {
  9832. ShmOCPP16Data->Cost.RunningCost[idx].txId = json_object_get_int(json_object_object_get(data, "transactionId"));
  9833. if(json_object_object_get(data, "timestamp") != NULL)
  9834. {
  9835. DEBUG_INFO("timestamp: %s\n", json_object_get_string(json_object_object_get(data, "timestamp")));
  9836. sprintf((char*)ShmOCPP16Data->Cost.RunningCost[idx].timestamp, "%s", json_object_get_string(json_object_object_get(data, "timestamp")));
  9837. }
  9838. else
  9839. {
  9840. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  9841. json_object_object_add(response, "data", json_object_new_string("timestamp not found."));
  9842. }
  9843. if(json_object_object_get(data, "meterValue") != NULL)
  9844. {
  9845. DEBUG_INFO("meterValue: %d\n", json_object_get_int(json_object_object_get(data, "meterValue")));
  9846. ShmOCPP16Data->Cost.RunningCost[idx].meterValue = json_object_get_int(json_object_object_get(data, "meterValue"));
  9847. }
  9848. else
  9849. {
  9850. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  9851. json_object_object_add(response, "data", json_object_new_string("meterValue not found."));
  9852. }
  9853. if(json_object_object_get(data, "cost") != NULL)
  9854. {
  9855. DEBUG_INFO("cost: %f\n", json_object_get_double(json_object_object_get(data, "cost")));
  9856. ShmOCPP16Data->Cost.RunningCost[idx].cost = json_object_get_double(json_object_object_get(data, "cost"));
  9857. }
  9858. else
  9859. {
  9860. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  9861. json_object_object_add(response, "data", json_object_new_string("cost not found."));
  9862. }
  9863. if(json_object_object_get(data, "state") != NULL)
  9864. {
  9865. DEBUG_INFO("state: %s\n", json_object_get_string(json_object_object_get(data, "state")));
  9866. sprintf((char*)ShmOCPP16Data->Cost.RunningCost[idx].state, "%s", json_object_get_string(json_object_object_get(data, "state")));
  9867. }
  9868. else
  9869. {
  9870. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  9871. json_object_object_add(response, "data", json_object_new_string("state not found."));
  9872. }
  9873. if(json_object_object_get(data, "chargingPrice") != NULL)
  9874. {
  9875. if(json_object_object_get(json_object_object_get(data, "chargingPrice"), "kWhPrice") != NULL)
  9876. {
  9877. DEBUG_INFO("chargingPrice-kWhPrice: %f\n", json_object_get_double(json_object_object_get(json_object_object_get(data, "chargingPrice"), "kWhPrice")));
  9878. ShmOCPP16Data->Cost.RunningCost[idx].chargingPrice.kWhPrice = json_object_get_double(json_object_object_get(json_object_object_get(data, "chargingPrice"), "kWhPrice"));
  9879. }
  9880. if(json_object_object_get(json_object_object_get(data, "chargingPrice"), "hourPrice") != NULL)
  9881. {
  9882. DEBUG_INFO("chargingPrice-hourPrice: %f\n", json_object_get_double(json_object_object_get(json_object_object_get(data, "chargingPrice"), "hourPrice")));
  9883. ShmOCPP16Data->Cost.RunningCost[idx].chargingPrice.hourPrice = json_object_get_double(json_object_object_get(json_object_object_get(data, "chargingPrice"), "hourPrice"));
  9884. }
  9885. if(json_object_object_get(json_object_object_get(data, "chargingPrice"), "flatFee") != NULL)
  9886. {
  9887. DEBUG_INFO("chargingPrice-flatFee: %f\n", json_object_get_double(json_object_object_get(json_object_object_get(data, "chargingPrice"), "flatFee")));
  9888. ShmOCPP16Data->Cost.RunningCost[idx].chargingPrice.flatFee = json_object_get_double(json_object_object_get(json_object_object_get(data, "chargingPrice"), "flatFee"));
  9889. }
  9890. }
  9891. else
  9892. {
  9893. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  9894. json_object_object_add(response, "data", json_object_new_string("chargingPrice not found."));
  9895. }
  9896. if(json_object_object_get(data, "idlePrice") != NULL)
  9897. {
  9898. if(json_object_object_get(json_object_object_get(data, "idlePrice"), "graceMinutes") != NULL)
  9899. {
  9900. DEBUG_INFO("idlePrice-graceMinutes: %d\n", json_object_get_int(json_object_object_get(json_object_object_get(data, "idlePrice"), "graceMinutes")));
  9901. ShmOCPP16Data->Cost.RunningCost[idx].idlePrice.graceMinutes = json_object_get_int(json_object_object_get(json_object_object_get(data, "idlePrice"), "graceMinutes"));
  9902. }
  9903. if(json_object_object_get(json_object_object_get(data, "idlePrice"), "hourPrice") != NULL)
  9904. {
  9905. DEBUG_INFO("idlePrice-hourPrice: %f\n", json_object_get_double(json_object_object_get(json_object_object_get(data, "idlePrice"), "hourPrice")));
  9906. ShmOCPP16Data->Cost.RunningCost[idx].idlePrice.hourPrice = json_object_get_double(json_object_object_get(json_object_object_get(data, "idlePrice"), "hourPrice"));
  9907. }
  9908. }
  9909. if(json_object_object_get(data, "nextPeriod") != NULL)
  9910. {
  9911. if(json_object_object_get(json_object_object_get(data, "nextPeriod"), "atTime") != NULL)
  9912. {
  9913. DEBUG_INFO("nextPeriod-atTime: %s\n", json_object_get_string(json_object_object_get(json_object_object_get(data, "nextPeriod"), "atTime")));
  9914. sprintf((char*)ShmOCPP16Data->Cost.RunningCost[idx].nextPeriod.atTime, "%s", json_object_get_string(json_object_object_get(json_object_object_get(data, "nextPeriod"), "atTime")));
  9915. }
  9916. else
  9917. {
  9918. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  9919. json_object_object_add(response, "data", json_object_new_string("atTime not found."));
  9920. }
  9921. if(json_object_object_get(json_object_object_get(data, "nextPeriod"), "chargingPrice") != NULL)
  9922. {
  9923. if(json_object_object_get(json_object_object_get(json_object_object_get(data, "nextPeriod"), "chargingPrice"), "kWhPrice") != NULL)
  9924. {
  9925. DEBUG_INFO("nextPeriod-chargingPrice-kWhPrice: %f\n", json_object_get_double(json_object_object_get(json_object_object_get(json_object_object_get(data, "nextPeriod"), "chargingPrice"), "kWhPrice")));
  9926. ShmOCPP16Data->Cost.RunningCost[idx].nextPeriod.chargingPrice.kWhPrice = json_object_get_double(json_object_object_get(json_object_object_get(json_object_object_get(data, "nextPeriod"), "chargingPrice"), "kWhPrice"));
  9927. }
  9928. if(json_object_object_get(json_object_object_get(json_object_object_get(data, "nextPeriod"), "chargingPrice"), "hourPrice") != NULL)
  9929. {
  9930. DEBUG_INFO("nextPeriod-chargingPrice-hourPrice: %f\n", json_object_get_double(json_object_object_get(json_object_object_get(json_object_object_get(data, "nextPeriod"), "chargingPrice"), "hourPrice")));
  9931. ShmOCPP16Data->Cost.RunningCost[idx].nextPeriod.chargingPrice.hourPrice = json_object_get_double(json_object_object_get(json_object_object_get(json_object_object_get(data, "nextPeriod"), "chargingPrice"), "hourPrice"));
  9932. }
  9933. if(json_object_object_get(json_object_object_get(json_object_object_get(data, "nextPeriod"), "chargingPrice"), "flatFee") != NULL)
  9934. {
  9935. DEBUG_INFO("nextPeriod-chargingPrice-flatFee: %f\n", json_object_get_double(json_object_object_get(json_object_object_get(json_object_object_get(data, "nextPeriod"), "chargingPrice"), "flatFee")));
  9936. ShmOCPP16Data->Cost.RunningCost[idx].nextPeriod.chargingPrice.flatFee = json_object_get_double(json_object_object_get(json_object_object_get(json_object_object_get(data, "nextPeriod"), "chargingPrice"), "flatFee"));
  9937. }
  9938. }
  9939. else
  9940. {
  9941. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  9942. json_object_object_add(response, "data", json_object_new_string("chargingPrice not found."));
  9943. }
  9944. if(json_object_object_get(json_object_object_get(data, "nextPeriod"), "idlePrice") != NULL)
  9945. {
  9946. if(json_object_object_get(json_object_object_get(json_object_object_get(data, "nextPeriod"), "idlePrice"), "graceMinutes") != NULL)
  9947. {
  9948. DEBUG_INFO("nextPeriod-idlePrice-graceMinutes: %d\n", json_object_get_int(json_object_object_get(json_object_object_get(json_object_object_get(data, "nextPeriod"), "idlePrice"), "graceMinutes")));
  9949. ShmOCPP16Data->Cost.RunningCost[idx].nextPeriod.idlePrice.graceMinutes = json_object_get_int(json_object_object_get(json_object_object_get(json_object_object_get(data, "nextPeriod"), "idlePrice"), "graceMinutes"));
  9950. }
  9951. if(json_object_object_get(json_object_object_get(json_object_object_get(data, "nextPeriod"), "idlePrice"), "hourPrice") != NULL)
  9952. {
  9953. DEBUG_INFO("nextPeriod-idlePrice-hourPrice: %f\n", json_object_get_double(json_object_object_get(json_object_object_get(json_object_object_get(data, "nextPeriod"), "idlePrice"), "hourPrice")));
  9954. ShmOCPP16Data->Cost.RunningCost[idx].nextPeriod.idlePrice.hourPrice = json_object_get_double(json_object_object_get(json_object_object_get(json_object_object_get(data, "nextPeriod"), "idlePrice"), "hourPrice"));
  9955. }
  9956. }
  9957. }
  9958. if(json_object_object_get(data, "triggerMeterValue") != NULL)
  9959. {
  9960. if(json_object_object_get(json_object_object_get(data, "triggerMeterValue"), "atTime") != NULL)
  9961. {
  9962. DEBUG_INFO("triggerMeterValue-atTime: %s\n", json_object_get_string(json_object_object_get(json_object_object_get(data, "triggerMeterValue"), "atTime")));
  9963. sprintf((char*)ShmOCPP16Data->Cost.RunningCost[idx].triggerMeterValue.atTime, "%s", json_object_get_string(json_object_object_get(json_object_object_get(data, "triggerMeterValue"), "atTime")));
  9964. }
  9965. if(json_object_object_get(json_object_object_get(data, "triggerMeterValue"), "atEnergykWh") != NULL)
  9966. {
  9967. DEBUG_INFO("triggerMeterValue-atEnergykWh: %f\n", json_object_get_double(json_object_object_get(json_object_object_get(data, "triggerMeterValue"), "atEnergykWh")));
  9968. ShmOCPP16Data->Cost.RunningCost[idx].triggerMeterValue.atEnergykWh = json_object_get_double(json_object_object_get(json_object_object_get(data, "triggerMeterValue"), "atEnergykWh"));
  9969. }
  9970. if(json_object_object_get(json_object_object_get(data, "triggerMeterValue"), "atPowerkW") != NULL)
  9971. {
  9972. DEBUG_INFO("triggerMeterValue-atPowerkW: %f\n", json_object_get_double(json_object_object_get(json_object_object_get(data, "triggerMeterValue"), "atPowerkW")));
  9973. ShmOCPP16Data->Cost.RunningCost[idx].triggerMeterValue.atPowerkW = json_object_get_double(json_object_object_get(json_object_object_get(data, "triggerMeterValue"), "atPowerkW"));
  9974. }
  9975. if(json_object_object_get(json_object_object_get(data, "triggerMeterValue"), "atCPStatus") != NULL)
  9976. {
  9977. DEBUG_INFO("triggerMeterValue-atCPStatus: %s\n", json_object_get_string(json_object_object_get(json_object_object_get(data, "triggerMeterValue"), "atCPStatus")));
  9978. sprintf((char*)ShmOCPP16Data->Cost.RunningCost[idx].triggerMeterValue.atCPStatus, "%s", json_object_get_string(json_object_object_get(json_object_object_get(data, "triggerMeterValue"), "atCPStatus")));
  9979. }
  9980. }
  9981. }
  9982. }
  9983. }
  9984. else
  9985. {
  9986. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  9987. json_object_object_add(response, "data", json_object_new_string("txId or transactionId not found."));
  9988. }
  9989. }
  9990. else
  9991. {
  9992. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  9993. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  9994. }
  9995. json_object_put(data);
  9996. sprintf(message,"[%d,\"%s\",%s]",MESSAGE_TYPE_CALLRESULT, uuid, json_object_to_json_string_ext(response, JSON_C_TO_STRING_PLAIN));
  9997. json_object_put(response);
  9998. }
  9999. else if(strstr(tempmessageId, "FinalCost") != NULL)
  10000. {
  10001. json_object *data;
  10002. data = json_tokener_parse(tempdata);
  10003. if(!is_error(data))
  10004. {
  10005. json_object_object_add(response, "status", json_object_new_string("Accepted"));
  10006. if(json_object_object_get(data, "txId") != NULL)
  10007. {
  10008. DEBUG_INFO("v1.0 txId: %d\n", json_object_get_int(json_object_object_get(data, "txId")));
  10009. for(int idx = 0;idx<gunTotalNumber;idx++)
  10010. {
  10011. if(ShmOCPP16Data->StartTransaction[idx].ResponseTransactionId == json_object_get_int(json_object_object_get(data, "txId")))
  10012. {
  10013. memset(&ShmOCPP16Data->Cost.FinalCost[idx], 0x00, sizeof(struct StrcutFinalCost));
  10014. ShmOCPP16Data->Cost.FinalCost[idx].txId = json_object_get_int(json_object_object_get(data, "txId"));
  10015. if(json_object_object_get(data, "description") != NULL)
  10016. {
  10017. DEBUG_INFO("description: %s\n", json_object_get_string(json_object_object_get(data, "description")));
  10018. sprintf((char*)ShmOCPP16Data->Cost.FinalCost[idx].description, "%s", json_object_get_string(json_object_object_get(data, "description")));
  10019. }
  10020. else
  10021. {
  10022. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  10023. json_object_object_add(response, "data", json_object_new_string("description not found."));
  10024. }
  10025. }
  10026. }
  10027. }
  10028. else if(json_object_object_get(data, "transactionId") != NULL)
  10029. {
  10030. DEBUG_INFO("v2.0 transactionId: %d\n", json_object_get_int(json_object_object_get(data, "transactionId")));
  10031. for(int idx = 0;idx<gunTotalNumber;idx++)
  10032. {
  10033. if(ShmOCPP16Data->StartTransaction[idx].ResponseTransactionId == json_object_get_int(json_object_object_get(data, "transactionId")))
  10034. {
  10035. memset(&ShmOCPP16Data->Cost.FinalCost[idx], 0x00, sizeof(struct StrcutFinalCost));
  10036. ShmOCPP16Data->Cost.FinalCost[idx].txId = json_object_get_int(json_object_object_get(data, "transactionId"));
  10037. if(json_object_object_get(data, "cost") != NULL)
  10038. {
  10039. DEBUG_INFO("cost: %s\n", json_object_get_string(json_object_object_get(data, "cost")));
  10040. ShmOCPP16Data->Cost.FinalCost[idx].cost = json_object_get_double(json_object_object_get(data, "cost"));
  10041. }
  10042. else
  10043. {
  10044. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  10045. json_object_object_add(response, "data", json_object_new_string("cost not found."));
  10046. }
  10047. if(json_object_object_get(data, "priceText") != NULL)
  10048. {
  10049. DEBUG_INFO("priceText: %s\n", json_object_get_string(json_object_object_get(data, "priceText")));
  10050. sprintf((char*)ShmOCPP16Data->Cost.FinalCost[idx].priceText, "%s", json_object_get_string(json_object_object_get(data, "priceText")));
  10051. }
  10052. else
  10053. {
  10054. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  10055. json_object_object_add(response, "data", json_object_new_string("priceText not found."));
  10056. }
  10057. if(json_object_object_get(data, "qrCodeText") != NULL)
  10058. {
  10059. DEBUG_INFO(": %s\n", json_object_get_string(json_object_object_get(data, "qrCodeText")));
  10060. sprintf((char*)ShmOCPP16Data->Cost.FinalCost[idx].qrCodeText, "%s", json_object_get_string(json_object_object_get(data, "qrCodeText")));
  10061. }
  10062. }
  10063. }
  10064. }
  10065. else
  10066. {
  10067. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  10068. json_object_object_add(response, "data", json_object_new_string("txId or transactionId not found."));
  10069. }
  10070. }
  10071. else
  10072. {
  10073. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  10074. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  10075. }
  10076. json_object_put(data);
  10077. sprintf(message,"[%d,\"%s\",%s]",MESSAGE_TYPE_CALLRESULT, uuid, json_object_to_json_string_ext(response, JSON_C_TO_STRING_PLAIN));
  10078. json_object_put(response);
  10079. }
  10080. else if(strstr(tempmessageId, "ID_ConfigQR") != NULL)
  10081. {
  10082. json_object *data;
  10083. data = json_tokener_parse(tempdata);
  10084. if(!is_error(data))
  10085. {
  10086. json_object_object_add(response, "status", json_object_new_string("Accepted"));
  10087. if(json_object_object_get(data, "Content_Type") != NULL)
  10088. {
  10089. if((0 <= json_object_get_int(json_object_object_get(data, "Content_Type"))) && (json_object_get_int(json_object_object_get(data, "Content_Type")) <= 1))
  10090. {
  10091. ShmSysConfigAndInfo->SysConfig.QRCodeMadeMode = json_object_get_int(json_object_object_get(data, "Content_Type"));
  10092. if(json_object_object_get(data, "Customization_Conent") != NULL)
  10093. {
  10094. sprintf((char*)ShmSysConfigAndInfo->SysConfig.QRCodeContent, "%s", json_object_get_string(json_object_object_get(data, "Customization_Conent")));
  10095. }
  10096. }
  10097. else
  10098. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  10099. }
  10100. StoreUsrConfigData(&ShmSysConfigAndInfo->SysConfig);
  10101. }
  10102. else
  10103. {
  10104. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  10105. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  10106. }
  10107. json_object_put(data);
  10108. sprintf(message,"[%d,\"%s\",%s]",MESSAGE_TYPE_CALLRESULT, uuid, json_object_to_json_string_ext(response, JSON_C_TO_STRING_PLAIN));
  10109. json_object_put(response);
  10110. }
  10111. else if(strstr(tempmessageId, "ID_LineStatusPage") != NULL)
  10112. {
  10113. json_object *data;
  10114. data = json_tokener_parse(tempdata);
  10115. if(!is_error(data))
  10116. {
  10117. json_object_object_add(response, "status", json_object_new_string("Accepted"));
  10118. if(json_object_object_get(data, "ConnectorId") != NULL)
  10119. {
  10120. ShmSysConfigAndInfo->SysInfo.LcdOveride.connectorId = json_object_get_int(json_object_object_get(data, "ConnectorId"));
  10121. }
  10122. if(json_object_object_get(data, "SerialNo") != NULL)
  10123. {
  10124. sprintf((char *)ShmOCPP16Data->TcciCustomData.SerialNo[(ShmSysConfigAndInfo->SysInfo.LcdOveride.connectorId-1)], "%s", json_object_get_string(json_object_object_get(data,"SerialNo")));
  10125. }
  10126. if(json_object_object_get(data, "Page_Index") != NULL)
  10127. {
  10128. ShmSysConfigAndInfo->SysInfo.LcdOveride.page_index = json_object_get_int(json_object_object_get(data, "Page_Index"));
  10129. }
  10130. if(json_object_object_get(data, "Duration") != NULL)
  10131. {
  10132. ShmSysConfigAndInfo->SysInfo.LcdOveride.duration = json_object_get_int(json_object_object_get(data, "Duration"));
  10133. }
  10134. ShmSysConfigAndInfo->SysInfo.LcdOveride.isOverideReq = 1;
  10135. }
  10136. else
  10137. {
  10138. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  10139. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  10140. }
  10141. json_object_put(data);
  10142. sprintf(message,"[%d,\"%s\",%s]",MESSAGE_TYPE_CALLRESULT, uuid, json_object_to_json_string_ext(response, JSON_C_TO_STRING_PLAIN));
  10143. json_object_put(response);
  10144. }
  10145. else if(strstr(tempmessageId, "ID_CpConfiguration") != NULL)
  10146. {
  10147. json_object *data;
  10148. data = json_tokener_parse(tempdata);
  10149. if(!is_error(data))
  10150. {
  10151. json_object_object_add(response, "status", json_object_new_string("Accepted"));
  10152. if(json_object_object_get(data, "MaxChargingCurrent") != NULL)
  10153. {
  10154. if(json_object_get_int(json_object_object_get(data, "MaxChargingCurrent")) >= 0)
  10155. ShmSysConfigAndInfo->SysConfig.MaxChargingCurrent = json_object_get_int(json_object_object_get(data, "MaxChargingCurrent"));
  10156. else
  10157. {
  10158. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  10159. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  10160. }
  10161. }
  10162. if(json_object_object_get(data, "MaxChargingDuration") != NULL)
  10163. {
  10164. if(json_object_get_int(json_object_object_get(data, "MaxChargingDuration")) >= 0)
  10165. ShmSysConfigAndInfo->SysConfig.MaxChargingDuration = json_object_get_int(json_object_object_get(data, "MaxChargingDuration"));
  10166. else
  10167. {
  10168. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  10169. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  10170. }
  10171. }
  10172. if(json_object_object_get(data, "MaxChargingEnergy") != NULL)
  10173. {
  10174. if(json_object_get_int(json_object_object_get(data, "MaxChargingEnergy")) >= 0)
  10175. ShmSysConfigAndInfo->SysConfig.MaxChargingEnergy = json_object_get_int(json_object_object_get(data, "MaxChargingEnergy"));
  10176. else
  10177. {
  10178. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  10179. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  10180. }
  10181. }
  10182. if(json_object_object_get(data, "MaxChargingPower") != NULL)
  10183. {
  10184. if(json_object_get_int(json_object_object_get(data, "MaxChargingPower")) >= 0)
  10185. ShmSysConfigAndInfo->SysConfig.MaxChargingPower = json_object_get_int(json_object_object_get(data, "MaxChargingPower"));
  10186. else
  10187. {
  10188. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  10189. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  10190. }
  10191. }
  10192. if(json_object_object_get(data, "OfflineMaxChargeEnergy") != NULL)
  10193. {
  10194. if(json_object_get_int(json_object_object_get(data, "OfflineMaxChargeEnergy")) >= 0)
  10195. ShmSysConfigAndInfo->SysConfig.OfflineMaxChargeEnergy = json_object_get_int(json_object_object_get(data, "OfflineMaxChargeEnergy"));
  10196. else
  10197. {
  10198. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  10199. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  10200. }
  10201. }
  10202. if(json_object_object_get(data, "OfflinePolicy") != NULL)
  10203. {
  10204. if((json_object_get_int(json_object_object_get(data, "OfflinePolicy")) == 0) ||
  10205. (json_object_get_int(json_object_object_get(data, "OfflinePolicy")) == 2) ||
  10206. (json_object_get_int(json_object_object_get(data, "OfflinePolicy")) == 3))
  10207. ShmSysConfigAndInfo->SysConfig.OfflinePolicy = json_object_get_int(json_object_object_get(data, "OfflinePolicy"));
  10208. else
  10209. {
  10210. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  10211. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  10212. }
  10213. }
  10214. if(json_object_object_get(data, "isAuthentication") != NULL)
  10215. {
  10216. switch(json_object_get_int(json_object_object_get(data, "isAuthentication")))
  10217. {
  10218. case 0:
  10219. case 1:
  10220. ShmSysConfigAndInfo->SysConfig.AuthorisationMode = json_object_get_int(json_object_object_get(data, "isAuthentication"))^1;
  10221. break;
  10222. default:
  10223. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  10224. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  10225. break;
  10226. }
  10227. }
  10228. if(strstr(json_object_get_string(json_object_object_get(response, "status")), "Accepted") != NULL)
  10229. StoreUsrConfigData(&ShmSysConfigAndInfo->SysConfig);
  10230. }
  10231. else
  10232. {
  10233. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  10234. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  10235. }
  10236. json_object_put(data);
  10237. sprintf(message,"[%d,\"%s\",%s]",MESSAGE_TYPE_CALLRESULT, uuid, json_object_to_json_string_ext(response, JSON_C_TO_STRING_PLAIN));
  10238. json_object_put(response);
  10239. }
  10240. else if(strstr(tempmessageId, "ID_TxEnergy") != NULL)
  10241. {
  10242. json_object *data;
  10243. data = json_tokener_parse(tempdata);
  10244. if(!is_error(data))
  10245. {
  10246. if((json_object_object_get(data, "ConnectorId") != NULL) && (json_object_object_get(data, "txId") != NULL))
  10247. {
  10248. if(OCPP_getPeriodEnergyToDataTransfer(json_object_get_int(json_object_object_get(data, "txId"))) == PASS)
  10249. {
  10250. json_object_object_add(response, "status", json_object_new_string("Accepted"));
  10251. json_object_object_add(response, "data", json_object_new_string((char*)ShmOCPP16Data->DataTransfer[0].ResponseData));
  10252. }
  10253. else
  10254. {
  10255. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  10256. json_object_object_add(response, "data", json_object_new_string("Present charged energy data can not get."));
  10257. }
  10258. }
  10259. else
  10260. {
  10261. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  10262. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  10263. }
  10264. }
  10265. else
  10266. {
  10267. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  10268. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  10269. }
  10270. sprintf(message,"[%d,\"%s\",%s]",MESSAGE_TYPE_CALLRESULT, uuid, json_object_to_json_string_ext(response, JSON_C_TO_STRING_PLAIN));
  10271. json_object_put(response);
  10272. }
  10273. else if(strstr(tempmessageId, "ID_Station_Location") != NULL)
  10274. {
  10275. json_object *data;
  10276. data = json_tokener_parse(tempdata);
  10277. if(!is_error(data))
  10278. {
  10279. json_object_object_add(response, "status", json_object_new_string("Accepted"));
  10280. if(json_object_object_get(data, "stationName") != NULL)
  10281. {
  10282. sprintf((char *)ShmOCPP16Data->TcciCustomData.ChargerInfo.station_name, "%s", json_object_get_string(json_object_object_get(data,"stationName")));
  10283. }
  10284. else
  10285. {
  10286. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  10287. json_object_object_add(response, "data", json_object_new_string("station_name data can not get."));
  10288. }
  10289. if(strcmp(json_object_get_string(json_object_object_get(response,"status")),"Accepted")==0)
  10290. {
  10291. ShmOCPP16Data->TcciCustomData.ChargerInfoReq = 1;
  10292. DEBUG_INFO("<<< ID_Station_Location:{station_name:%s}\n",
  10293. ShmOCPP16Data->TcciCustomData.ChargerInfo.station_name);
  10294. }
  10295. }
  10296. else
  10297. {
  10298. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  10299. json_object_object_add(response, "data", json_object_new_string("charger_info content got something wrong."));
  10300. }
  10301. sprintf(message,"[%d,\"%s\",%s]",MESSAGE_TYPE_CALLRESULT, uuid, json_object_to_json_string_ext(response, JSON_C_TO_STRING_PLAIN));
  10302. json_object_put(response);
  10303. }
  10304. else if(strstr(tempmessageId, "ID_Weather_Info") != NULL)
  10305. {
  10306. json_object *data;
  10307. data = json_tokener_parse(tempdata);
  10308. if(!is_error(data))
  10309. {
  10310. json_object_object_add(response, "status", json_object_new_string("Accepted"));
  10311. if(json_object_object_get(data, "weatherId") != NULL)
  10312. {
  10313. ShmOCPP16Data->TcciCustomData.WeatherInfo.weatherId = json_object_get_int(json_object_object_get(data, "weatherId"));
  10314. }
  10315. else
  10316. {
  10317. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  10318. json_object_object_add(response, "data", json_object_new_string("weather data can not get."));
  10319. }
  10320. if(json_object_object_get(data, "Temperature") != NULL)
  10321. {
  10322. ShmOCPP16Data->TcciCustomData.WeatherInfo.temperature = json_object_get_double(json_object_object_get(data,"Temperature"));
  10323. }
  10324. else
  10325. {
  10326. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  10327. json_object_object_add(response, "data", json_object_new_string("temperature data can not get."));
  10328. }
  10329. if(strcmp(json_object_get_string(json_object_object_get(response,"status")),"Accepted")==0)
  10330. {
  10331. ShmOCPP16Data->TcciCustomData.WeatherInfoReq = 1;
  10332. DEBUG_INFO("<<< ID_Weather_Info:{weather:%d, temperature:%.1f}\n",
  10333. ShmOCPP16Data->TcciCustomData.WeatherInfo.weatherId,
  10334. ShmOCPP16Data->TcciCustomData.WeatherInfo.temperature
  10335. );
  10336. }
  10337. }
  10338. else
  10339. {
  10340. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  10341. json_object_object_add(response, "data", json_object_new_string("weather_info content got something wrong."));
  10342. }
  10343. sprintf(message,"[%d,\"%s\",%s]",MESSAGE_TYPE_CALLRESULT, uuid, json_object_to_json_string_ext(response, JSON_C_TO_STRING_PLAIN));
  10344. json_object_put(response);
  10345. }
  10346. else if(strstr(tempmessageId, "ID_TriggerCreditReader") != NULL)
  10347. {
  10348. json_object *data;
  10349. data = json_tokener_parse(tempdata);
  10350. if(!is_error(data))
  10351. {
  10352. json_object_object_add(response, "status", json_object_new_string("Accepted"));
  10353. if(json_object_get_int(json_object_object_get(data, "ConnectorId")) > 0)
  10354. {
  10355. ShmOCPP16Data->TcciCustomData.TriggerReaderReq[json_object_get_int(json_object_object_get(data, "ConnectorId")) -1] = TRUE;
  10356. DEBUG_INFO("<<< ID_TriggerCreditReader:{ConnectorId: %d}\n", json_object_get_int(json_object_object_get(data, "ConnectorId")));
  10357. }
  10358. else
  10359. {
  10360. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  10361. json_object_object_add(response, "data", json_object_new_string("ConnectorId does not valid."));
  10362. }
  10363. }
  10364. else
  10365. {
  10366. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  10367. json_object_object_add(response, "data", json_object_new_string("charger_info content got something wrong."));
  10368. }
  10369. sprintf(message,"[%d,\"%s\",%s]",MESSAGE_TYPE_CALLRESULT, uuid, json_object_to_json_string_ext(response, JSON_C_TO_STRING_PLAIN));
  10370. json_object_put(response);
  10371. }
  10372. else if(strstr(tempmessageId, "ID_GetTxUserInfo") != NULL)
  10373. {
  10374. json_object *data;
  10375. data = json_tokener_parse(tempdata);
  10376. if(!is_error(data))
  10377. {
  10378. if((json_object_object_get(data, "ConnectorId") != NULL) && (json_object_object_get(data, "txId") != NULL))
  10379. {
  10380. int gun_index = json_object_get_int(json_object_object_get(data, "ConnectorId"))-1;
  10381. json_object_object_add(response, "status", json_object_new_string("Accepted"));
  10382. if(gun_index < gunTotalNumber)
  10383. {
  10384. if(ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId == json_object_get_int(json_object_object_get(data, "txId")))
  10385. {
  10386. json_object *responsedata = json_object_new_object();
  10387. json_object_object_add(responsedata, "txId", json_object_new_int(ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId));
  10388. json_object_object_add(responsedata, "ConnectorId", json_object_new_int(gun_index+1));
  10389. json_object_object_add(responsedata, "SerialNo", json_object_new_string((char*)ShmOCPP16Data->TcciCustomData.SerialNo[gun_index]));
  10390. json_object_object_add(responsedata, "StartTime", json_object_new_string((char*)ShmOCPP16Data->StartTransaction[gun_index].Timestamp));
  10391. json_object_object_add(responsedata, "VEMData", json_object_new_string((char*)ShmOCPP16Data->TcciCustomData.VEMData[gun_index]));
  10392. json_object_object_add(response, "data", json_object_new_string(json_object_to_json_string_ext(responsedata, JSON_C_TO_STRING_PLAIN)));
  10393. }
  10394. else
  10395. {
  10396. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  10397. json_object_object_add(response, "data", json_object_new_string("txId doesn't match the current transactionId."));
  10398. }
  10399. }
  10400. else
  10401. {
  10402. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  10403. json_object_object_add(response, "data", json_object_new_string("ConnectorId is invalid."));
  10404. }
  10405. }
  10406. else
  10407. {
  10408. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  10409. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  10410. }
  10411. }
  10412. else
  10413. {
  10414. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  10415. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  10416. }
  10417. sprintf(message,"[%d,\"%s\",%s]",MESSAGE_TYPE_CALLRESULT, uuid, json_object_to_json_string_ext(response, JSON_C_TO_STRING_PLAIN));
  10418. json_object_put(response);
  10419. }
  10420. else
  10421. {
  10422. // Can not find valid message id
  10423. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\",\"data\":\"vendorId-%s messageId-%s data-%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, "UnknownMessageId", tempvendorId, tempmessageId, tempdata);
  10424. }
  10425. }
  10426. else
  10427. {
  10428. // Payload is null
  10429. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\",\"data\":\"{}\"}]",MESSAGE_TYPE_CALLRESULT, uuid, "UnknownMessageId");
  10430. }
  10431. LWS_Send(message);
  10432. return result;
  10433. }
  10434. int handleGetCompositeScheduleRequest(char *uuid, char *payload)
  10435. {
  10436. mtrace();
  10437. int result = FAIL;
  10438. int connectorIdInt, durationInt;
  10439. char chargingRateUnitStr[4]={0};
  10440. char comfirmstr[20];
  10441. int confirmPeriods = 0;
  10442. DEBUG_INFO("handleGetCompositeScheduleRequest...\n");
  10443. json_object *GetCompositeSchedule;
  10444. GetCompositeSchedule = json_tokener_parse(payload);
  10445. if(!is_error(GetCompositeSchedule))
  10446. {
  10447. // Required data
  10448. if(json_object_object_get(GetCompositeSchedule, "connectorId") != NULL)
  10449. connectorIdInt = json_object_get_int(json_object_object_get(GetCompositeSchedule, "connectorId"));
  10450. else
  10451. connectorIdInt = -1;
  10452. if(json_object_object_get(GetCompositeSchedule, "duration"))
  10453. durationInt = json_object_get_int(json_object_object_get(GetCompositeSchedule, "duration"));
  10454. else
  10455. durationInt = 86400;
  10456. // Optional data
  10457. if(json_object_object_get(GetCompositeSchedule, "chargingRateUnit") != NULL)
  10458. sprintf((char*)chargingRateUnitStr, "%s", json_object_get_string(json_object_object_get(GetCompositeSchedule, "chargingRateUnit")));
  10459. }
  10460. json_object_put(GetCompositeSchedule);
  10461. memset(ShmOCPP16Data->GetCompositeSchedule, 0, sizeof(struct StructChargingSchedulePeriod)*gunTotalNumber);
  10462. if((connectorIdInt == 0) ||
  10463. ((connectorIdInt > 0) && ((connectorIdInt -1) < gunTotalNumber)))
  10464. {
  10465. int gun_index = (connectorIdInt==0?0:connectorIdInt-1);
  10466. struct StructChargingProfile tmpProfile[1];
  10467. if(strstr(chargingRateUnitStr, "W") != NULL)
  10468. checkCompositeSchedule(connectorIdInt, durationInt, &tmpProfile[0], FALSE);
  10469. else
  10470. checkCompositeSchedule(connectorIdInt, durationInt, &tmpProfile[0], TRUE);
  10471. for(int idx=0;idx<ARRAY_SIZE(ShmOCPP16Data->GetCompositeSchedule[gun_index].ResponseChargingSchedule.ChargingSchedulePeriod);idx++)
  10472. {
  10473. DEBUG_INFO("Smart Period-%02d start: %d\n", idx, tmpProfile[0].ChargingSchedule.ChargingSchedulePeriod[idx].StartPeriod);
  10474. DEBUG_INFO("Smart Period-%02d limit: %f\n", idx, tmpProfile[0].ChargingSchedule.ChargingSchedulePeriod[idx].Limit);
  10475. }
  10476. ShmOCPP16Data->GetCompositeSchedule[gun_index].ResponseConnectorId = connectorIdInt;
  10477. memcpy(&ShmOCPP16Data->GetCompositeSchedule[gun_index].ResponseChargingSchedule, &tmpProfile[0].ChargingSchedule, sizeof(struct StructChargingSchedule));
  10478. memcpy(&ShmOCPP16Data->GetCompositeSchedule[gun_index].ResponseScheduleStart ,&tmpProfile[0].ChargingSchedule.StartSchedule, ARRAY_SIZE(tmpProfile[0].ChargingSchedule.StartSchedule));
  10479. for(int idx=0;idx<ARRAY_SIZE(ShmOCPP16Data->GetCompositeSchedule[gun_index].ResponseChargingSchedule.ChargingSchedulePeriod);idx++)
  10480. {
  10481. DEBUG_INFO("Composite Period-%02d start: %d\n", idx, ShmOCPP16Data->GetCompositeSchedule[gun_index].ResponseChargingSchedule.ChargingSchedulePeriod[idx].StartPeriod);
  10482. DEBUG_INFO("Composite Period-%02d limit: %f\n", idx, ShmOCPP16Data->GetCompositeSchedule[gun_index].ResponseChargingSchedule.ChargingSchedulePeriod[idx].Limit);
  10483. if((ShmOCPP16Data->GetCompositeSchedule[gun_index].ResponseChargingSchedule.ChargingSchedulePeriod[idx].StartPeriod==0) &&
  10484. (ShmOCPP16Data->GetCompositeSchedule[gun_index].ResponseChargingSchedule.ChargingSchedulePeriod[idx].Limit==0) &&
  10485. (idx<(ARRAY_SIZE(ShmOCPP16Data->GetCompositeSchedule[gun_index].ResponseChargingSchedule.ChargingSchedulePeriod)-1)?(ShmOCPP16Data->GetCompositeSchedule[gun_index].ResponseChargingSchedule.ChargingSchedulePeriod[idx+1].StartPeriod==0):TRUE))
  10486. {
  10487. confirmPeriods = idx;
  10488. break;
  10489. }
  10490. }
  10491. if((confirmPeriods == 0) && (tmpProfile[0].ChargingProfileId > 0))
  10492. {
  10493. confirmPeriods += 1;
  10494. }
  10495. sprintf(comfirmstr, "%s", GetCompositeScheduleStatusStr[GetCompositeScheduleStatus_Accepted] );
  10496. }
  10497. else
  10498. {
  10499. sprintf(comfirmstr, "%s", GetCompositeScheduleStatusStr[GetCompositeScheduleStatus_Rejected] );
  10500. }
  10501. sendGetCompositeScheduleConfirmation(uuid, comfirmstr, connectorIdInt, confirmPeriods);
  10502. return result;
  10503. }
  10504. int handleGetConfigurationRequest(char *uuid, char *payload)
  10505. {
  10506. mtrace();
  10507. int result = FAIL;
  10508. int MaxKeySupported = 0;
  10509. int n_keys = 0;
  10510. char requestKey[GetConfigurationMaxKeysNUM][50]={0};
  10511. DEBUG_INFO("handleGetConfigurationRequest...\n");
  10512. json_object *GetConfiguration;
  10513. GetConfiguration = json_tokener_parse(payload);
  10514. if(!is_error(GetConfiguration))
  10515. {
  10516. // Optional data
  10517. if(json_object_object_get(GetConfiguration, "key") != NULL)
  10518. {
  10519. for(int idx=0;idx<json_object_array_length(json_object_object_get(GetConfiguration, "key"));idx++)
  10520. {
  10521. sprintf((char*)requestKey[idx], "%s", json_object_get_string(json_object_array_get_idx(json_object_object_get(GetConfiguration, "key"), idx)));
  10522. n_keys = idx + 1;
  10523. }
  10524. }
  10525. }
  10526. json_object_put(GetConfiguration);
  10527. UnknownKeynum = 0;
  10528. memset( (void *)unknownkey, 0, sizeof(unknownkey));
  10529. MaxKeySupported = GetConfigurationMaxKeysNUM;
  10530. memset(ShmOCPP16Data->GetConfiguration.Key, 0 ,sizeof(struct StructConfigurationKeyItems)*MaxKeySupported);
  10531. memset(ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey, 0, sizeof(struct StructConfigurationKey)*MaxKeySupported);
  10532. if(n_keys != 0)
  10533. {
  10534. for(int i=0;i<n_keys;i++)
  10535. {
  10536. getKeyValue(requestKey[i]);
  10537. }
  10538. }
  10539. else
  10540. {
  10541. DEBUG_INFO("There is no key in Message, get all configuration\n");
  10542. getKeyValue("");
  10543. }
  10544. processUnkownKey();
  10545. sendGetConfigurationConfirmation(uuid);
  10546. return result;
  10547. }
  10548. static char fnamePlusPath[100]={0};
  10549. static char fnamePWithNoPath[60]={0};
  10550. void checkUploadLog(void)
  10551. {
  10552. FILE *fp;
  10553. /* Open the command for reading. */
  10554. fp = popen("find /mnt/ -type f -name \"*.zip\" |xargs ls -t", "r");
  10555. if (fp == NULL) {
  10556. DEBUG_WARN("Failed to run command\n" );
  10557. exit(1);
  10558. }
  10559. int ftppathlen = 0;
  10560. memset(fnamePlusPath, 0, ARRAY_SIZE(fnamePlusPath));
  10561. int i = 0;
  10562. /* Read the output a line at a time - output it. */
  10563. while (fgets(fnamePlusPath, sizeof(fnamePlusPath), fp) != NULL) {
  10564. if(i==0)
  10565. {
  10566. ftppathlen = strlen(fnamePlusPath);
  10567. DEBUG_INFO("%s\n", fnamePlusPath);
  10568. fnamePlusPath[ftppathlen]='\0';
  10569. break;
  10570. }
  10571. i= i+1;
  10572. }
  10573. /* close */
  10574. pclose(fp);
  10575. for(int k=0; k< ARRAY_SIZE(fnamePlusPath); k++)
  10576. {
  10577. if((fnamePlusPath[k]=='\n') || (fnamePlusPath[k]=='\r'))
  10578. {
  10579. fnamePlusPath[k]='\0';
  10580. }
  10581. }
  10582. i=1;
  10583. //char fname[60]={0};
  10584. while(i < ftppathlen)
  10585. {
  10586. int len=ftppathlen-i;
  10587. if(fnamePlusPath[len]== 47) // '/' ascll code: 47
  10588. {
  10589. DEBUG_INFO("compare '/' all right\n");
  10590. break;
  10591. }
  10592. i=i+1;
  10593. }
  10594. memset(fnamePWithNoPath, 0, ARRAY_SIZE(fnamePWithNoPath));
  10595. strncpy(fnamePWithNoPath, fnamePlusPath+(ftppathlen-i+1), i+1);
  10596. fnamePWithNoPath[i+1] = '\0';
  10597. for(int j=0; j< ARRAY_SIZE(fnamePWithNoPath); j++)
  10598. {
  10599. if((fnamePWithNoPath[j]=='\n') || (fnamePWithNoPath[j]=='r'))
  10600. {
  10601. fnamePWithNoPath[j]='\0';
  10602. }
  10603. }
  10604. FILE* fp1 = fopen(fnamePlusPath, "r");
  10605. if (fp1)
  10606. {
  10607. DEBUG_INFO("testfuc : fnamePlusPath=%s exist.\n", fnamePlusPath);
  10608. // file exists
  10609. fclose(fp1);
  10610. }
  10611. else
  10612. {
  10613. // file doesn't exist
  10614. DEBUG_WARN("testfuc : fnamePlusPath=%s not exist!\n", fnamePlusPath);
  10615. }
  10616. }
  10617. int handleGetDiagnosticsRequest(char *uuid, char *payload)
  10618. {
  10619. mtrace();
  10620. int result = FAIL;
  10621. time_t CurrentTime;
  10622. struct tm *tm;
  10623. pthread_t th_Status;
  10624. CurrentTime = time(NULL);
  10625. tm = localtime(&CurrentTime);
  10626. memset(ShmOCPP16Data->GetDiagnostics.ResponseFileName, 0x00, ARRAY_SIZE(ShmOCPP16Data->GetDiagnostics.ResponseFileName));
  10627. sprintf((char*)ShmOCPP16Data->GetDiagnostics.ResponseFileName, "%s-%s-%04d%02d%02d%02d%02d%02d.zip", ShmSysConfigAndInfo->SysConfig.ModelName, ShmSysConfigAndInfo->SysConfig.SerialNumber, (tm->tm_year+1900), (tm->tm_mon+1),tm->tm_mday,tm->tm_hour,tm->tm_min,tm->tm_sec);
  10628. sendGetDiagnosticsConfirmation(uuid, (char*)ShmOCPP16Data->GetDiagnostics.ResponseFileName);
  10629. if(!interLock.isGetDiagnosticGoing)
  10630. {
  10631. interLock.isGetDiagnosticGoing = 1;
  10632. pthread_create(&th_Status, NULL, GetDiagnosticsProcess, stringtrimspace(payload));
  10633. sleep(1);
  10634. }
  10635. else
  10636. DEBUG_WARN("Other GetDiagnostic request on going.\n");
  10637. return result;
  10638. }
  10639. void* GetDiagnosticsProcess(void* data)
  10640. {
  10641. pthread_detach(pthread_self());
  10642. mtrace();
  10643. int retriesInt=0, retryIntervalInt=0;
  10644. char locationstr[1024]={0}, startTimestr[30]={0}, stopTimestr[30]={0} ;
  10645. char protocol[10]={0}, user[64]={0},password[64]={0},host[128]={0}, path[512]={0}, ftppath[512]={0},host1[128]={0},path1[512]={0};
  10646. int port=0;
  10647. int isSuccess = FALSE;
  10648. char cmdBuf[2048];
  10649. struct tm *tmNow;
  10650. time_t CurrentTime;
  10651. struct tm tmStart;
  10652. struct tm tmStop;
  10653. CurrentTime = time(NULL);
  10654. tmNow=localtime(&CurrentTime);
  10655. uint16_t targetYear, targetMonth;
  10656. json_object *GetDiagnostics;
  10657. DEBUG_INFO("GetDiagnosticsProcess...\n");
  10658. GetDiagnostics = json_tokener_parse(data);
  10659. if(!is_error(GetDiagnostics))
  10660. {
  10661. // Required data
  10662. if(json_object_object_get(GetDiagnostics, "location") != NULL)
  10663. sprintf(locationstr, "%s", json_object_get_string(json_object_object_get(GetDiagnostics, "location")));
  10664. // Optional data
  10665. if(json_object_object_get(GetDiagnostics, "retries") != NULL)
  10666. retriesInt = json_object_get_int(json_object_object_get(GetDiagnostics, "retries"));
  10667. else
  10668. retriesInt = 3; // If this field is not present, it is left to Charge Point to decide how many times it wants to retry.
  10669. if(json_object_object_get(GetDiagnostics, "retryInterval") != NULL)
  10670. retryIntervalInt = json_object_get_int(json_object_object_get(GetDiagnostics, "retryInterval"));
  10671. else
  10672. retryIntervalInt = 30;
  10673. if(json_object_object_get(GetDiagnostics, "startTime") != NULL)
  10674. sprintf(startTimestr, "%s", json_object_get_string(json_object_object_get(GetDiagnostics, "startTime")));
  10675. if(json_object_object_get(GetDiagnostics, "stopTime") != NULL)
  10676. sprintf(stopTimestr, "%s", json_object_get_string(json_object_object_get(GetDiagnostics, "stopTime")));
  10677. }
  10678. json_object_put(GetDiagnostics);
  10679. // Pack log to compress file
  10680. if((sscanf((char*)startTimestr, "%4d-%2d-%2dT%2d:%2d:%2d", &tmStart.tm_year, &tmStart.tm_mon, &tmStart.tm_mday, &tmStart.tm_hour, &tmStart.tm_min, &tmStart.tm_sec) == 6) &&
  10681. (sscanf((char*)stopTimestr, "%4d-%2d-%2dT%2d:%2d:%2d", &tmStop.tm_year, &tmStop.tm_mon, &tmStop.tm_mday, &tmStop.tm_hour, &tmStop.tm_min, &tmStop.tm_sec) == 6))
  10682. {
  10683. // Pack system log
  10684. memset(cmdBuf, 0x00, ARRAY_SIZE(cmdBuf));
  10685. sprintf(cmdBuf, "exec zip -9 --password %04d%02d%s /mnt/system.zip", tmNow->tm_year+1900, tmNow->tm_mon+1, ShmSysConfigAndInfo->SysConfig.SerialNumber);
  10686. targetYear = tmStart.tm_year;
  10687. targetMonth = tmStart.tm_mon;
  10688. do
  10689. {
  10690. sprintf(cmdBuf, "%s /Storage/SystemLog/*%04d*%02d*", cmdBuf, targetYear, targetMonth);
  10691. sprintf(cmdBuf, "%s /Storage/OCPP/*%04d*%02d*SystemLog*", cmdBuf, targetYear, targetMonth);
  10692. if(targetMonth+1>=13)
  10693. {
  10694. targetYear += 1;
  10695. targetMonth = 1;
  10696. }
  10697. else
  10698. {
  10699. targetMonth += 1;
  10700. }
  10701. }while((targetYear < (tmNow->tm_year+1900)) ||
  10702. ((targetYear <= (tmNow->tm_year+1900)) && (targetMonth <= (tmNow->tm_mon+1))));
  10703. sprintf(cmdBuf, "%s /Storage/CCS*.zip", cmdBuf);
  10704. sprintf(cmdBuf, "%s /Storage/OCPP/*.db", cmdBuf);
  10705. system(cmdBuf);
  10706. // Pack charging & event log
  10707. memset(cmdBuf, 0x00, ARRAY_SIZE(cmdBuf));
  10708. sprintf(cmdBuf, "exec zip -9 /mnt/charging_event.zip");
  10709. targetYear = tmStart.tm_year;
  10710. targetMonth = tmStart.tm_mon;
  10711. do
  10712. {
  10713. sprintf(cmdBuf, "%s /Storage/EventLog/*%04d*%02d*", cmdBuf, targetYear, targetMonth);
  10714. sprintf(cmdBuf, "%s /Storage/OCPP/*%04d*%02d*OcppMessageLog*", cmdBuf, targetYear, targetMonth);
  10715. if(targetMonth+1>=13)
  10716. {
  10717. targetYear += 1;
  10718. targetMonth = 1;
  10719. }
  10720. else
  10721. {
  10722. targetMonth += 1;
  10723. }
  10724. }while((targetYear < (tmNow->tm_year+1900)) ||
  10725. ((targetYear <= (tmNow->tm_year+1900)) && (targetMonth <= (tmNow->tm_mon+1))));
  10726. sprintf(cmdBuf, "%s /Storage/ChargeLog/*.db", cmdBuf);
  10727. sprintf(cmdBuf, "%s /Storage/EventLog/*.db", cmdBuf);
  10728. system(cmdBuf);
  10729. // Combine log file
  10730. system("exec zip -9 /mnt/log.zip /mnt/system.zip /mnt/charging_event.zip");
  10731. system("exec rm -f /mnt/system.zip /mnt/charging_event.zip");
  10732. }
  10733. else
  10734. {
  10735. system("exec /root/logPackTools 'log' 6");
  10736. }
  10737. sprintf(cmdBuf, "mv /mnt/log.zip /mnt/%s", ShmOCPP16Data->GetDiagnostics.ResponseFileName);
  10738. system(cmdBuf);
  10739. checkUploadLog();
  10740. //****************location*******************/
  10741. if(strcmp(locationstr,"")==0)
  10742. {
  10743. DEBUG_INFO("location is <Empty>!\n");
  10744. sprintf((char*)ShmOCPP16Data->DiagnosticsStatusNotification.Status, "%s", DiagnosticsStatusStr[DiagnosticsStatus_UploadFailed]);
  10745. ShmOCPP16Data->SpMsg.bits.DiagnosticsStatusNotificationReq = 1;
  10746. goto end;
  10747. }
  10748. memset(protocol, 0, ARRAY_SIZE(protocol));
  10749. memset(user, 0, ARRAY_SIZE(user) );
  10750. memset(password, 0, ARRAY_SIZE(password));
  10751. memset(host, 0, ARRAY_SIZE(host));
  10752. memset(path, 0, ARRAY_SIZE(path));
  10753. memset(ftppath, 0, ARRAY_SIZE(ftppath));
  10754. memset(host1, 0, ARRAY_SIZE(host1));
  10755. memset(path1, 0, ARRAY_SIZE(path1));
  10756. /*location: ftp://user:password@host:port/path*/
  10757. //DEBUG_INFO("fnamePlusPath =%s\n",fnamePlusPath);
  10758. if((access(fnamePlusPath,F_OK))!=-1)
  10759. {
  10760. DEBUG_INFO("fnamePlusPath exist.\n");
  10761. }
  10762. else
  10763. {
  10764. DEBUG_INFO("fnamePlusPath not exist!\n");
  10765. sprintf((char*)ShmOCPP16Data->DiagnosticsStatusNotification.Status, "%s", DiagnosticsStatusStr[DiagnosticsStatus_UploadFailed]);
  10766. ShmOCPP16Data->SpMsg.bits.DiagnosticsStatusNotificationReq = 1;
  10767. goto end;
  10768. }
  10769. if(strchr(locationstr,'@')==NULL)
  10770. {
  10771. sscanf(locationstr,
  10772. "%[^:]:%*2[/]%[^:]:%i/%[a-zA-Z0-9._/-]",
  10773. protocol, host, &port, path);
  10774. strcpy(user,"anonymous");
  10775. strcpy(password,"");
  10776. }
  10777. else
  10778. {
  10779. //DEBUG_INFO("pch=%s\n", pch);
  10780. sscanf(locationstr,"%[^:]:%*2[/]%[^:]:%[^@]@%[^:]:%i/%199[^\n]",
  10781. protocol, user, password, host, &port, path);
  10782. }
  10783. if((strcmp(protocol,"ftp")!=0)&&(strcmp(protocol,"http")!=0)&&(strcmp(protocol,"https")!=0))
  10784. {
  10785. DEBUG_INFO("protocol is not ftp/http ! \n");
  10786. sprintf((char*)ShmOCPP16Data->DiagnosticsStatusNotification.Status, "%s", DiagnosticsStatusStr[DiagnosticsStatus_UploadFailed]);
  10787. ShmOCPP16Data->SpMsg.bits.DiagnosticsStatusNotificationReq = 1;
  10788. goto end;
  10789. }
  10790. if(strncmp(locationstr,"http", 4) == 0)
  10791. {
  10792. sscanf(locationstr,"%[^:]:%*2[/]%[^/]/%199[^\n]", protocol, host, path);
  10793. sprintf(ftppath,"/%s", path);
  10794. do
  10795. {
  10796. sprintf((char*)ShmOCPP16Data->DiagnosticsStatusNotification.Status, "%s", DiagnosticsStatusStr[DiagnosticsStatus_Uploading]);
  10797. ShmOCPP16Data->SpMsg.bits.DiagnosticsStatusNotificationReq = 1;
  10798. sleep(3);
  10799. isSuccess = httpUploadFile(host, ftppath, fnamePlusPath, locationstr);
  10800. if(!isSuccess)
  10801. {
  10802. DEBUG_INFO("Diagnostics fail.\n");
  10803. sprintf((char*)ShmOCPP16Data->DiagnosticsStatusNotification.Status, "%s", DiagnosticsStatusStr[DiagnosticsStatus_UploadFailed]);
  10804. ShmOCPP16Data->SpMsg.bits.DiagnosticsStatusNotificationReq = 1;
  10805. sleep(retryIntervalInt);
  10806. }
  10807. else
  10808. {
  10809. DEBUG_INFO("sendDiagnosticsStatusNotificationRequest Uploaded\n");
  10810. sprintf((char*)ShmOCPP16Data->DiagnosticsStatusNotification.Status, "%s", DiagnosticsStatusStr[DiagnosticsStatus_Uploaded]);
  10811. ShmOCPP16Data->SpMsg.bits.DiagnosticsStatusNotificationReq = 1;
  10812. }
  10813. retriesInt--;
  10814. }while((isSuccess == 0)&&(retriesInt >= 0));
  10815. }
  10816. else
  10817. {
  10818. sscanf(host,"%[^/]%s",host1, path1);
  10819. if(strlen(path) > 0)
  10820. sprintf(ftppath,"/%s", path);
  10821. else
  10822. sprintf(ftppath,"/%s", path1);
  10823. int ftppathlen=strlen(ftppath);
  10824. int i=1;
  10825. char filenametemp[50];
  10826. while(i < ftppathlen)
  10827. {
  10828. int len=ftppathlen-i;
  10829. if(ftppath[len]== 47) // '/' ascll code: 47
  10830. {
  10831. DEBUG_INFO("find '/' all right\n");
  10832. break;
  10833. }
  10834. i=i+1;
  10835. }
  10836. memset(filenametemp, 0, ARRAY_SIZE(filenametemp));
  10837. strncpy(filenametemp, ftppath+(ftppathlen-i+1), i+1);
  10838. filenametemp[i+1] = 0;
  10839. if(port == 0)
  10840. port = 21;
  10841. do
  10842. {
  10843. sprintf((char*)ShmOCPP16Data->DiagnosticsStatusNotification.Status, "%s", DiagnosticsStatusStr[DiagnosticsStatus_Uploading]);
  10844. ShmOCPP16Data->SpMsg.bits.DiagnosticsStatusNotificationReq = 1;
  10845. sleep(3);
  10846. isSuccess = ftpUploadFile(host1, user, password, port, ftppath, fnamePlusPath, fnamePWithNoPath);
  10847. if(!isSuccess)
  10848. {
  10849. DEBUG_INFO("Diagnostics fail.\n");
  10850. sprintf((char*)ShmOCPP16Data->DiagnosticsStatusNotification.Status, "%s", DiagnosticsStatusStr[DiagnosticsStatus_UploadFailed]);
  10851. ShmOCPP16Data->SpMsg.bits.DiagnosticsStatusNotificationReq = 1;
  10852. sleep(retryIntervalInt);
  10853. }
  10854. else
  10855. {
  10856. DEBUG_INFO("sendDiagnosticsStatusNotificationRequest Uploaded\n");
  10857. sprintf((char*)ShmOCPP16Data->DiagnosticsStatusNotification.Status, "%s", DiagnosticsStatusStr[DiagnosticsStatus_Uploaded]);
  10858. ShmOCPP16Data->SpMsg.bits.DiagnosticsStatusNotificationReq = 1;
  10859. }
  10860. retriesInt--;
  10861. }while((!isSuccess)&&(retriesInt >= 0));
  10862. }
  10863. end:
  10864. system("rm -f /mnt/*");
  10865. sleep(5);
  10866. sprintf((char*)ShmOCPP16Data->DiagnosticsStatusNotification.Status, "%s", DiagnosticsStatusStr[DiagnosticsStatus_Idle]);
  10867. ShmOCPP16Data->SpMsg.bits.DiagnosticsStatusNotificationReq = 1;
  10868. interLock.isGetDiagnosticGoing = 0;
  10869. pthread_exit(NULL);
  10870. }
  10871. int handleGetLocalListVersionRequest(char *uuid, char *payload)
  10872. {
  10873. mtrace();
  10874. int result = FAIL;
  10875. DEBUG_INFO("handle GetLocalListVersionRequest\n");
  10876. if(strcmp((const char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "FALSE") == 0)
  10877. {
  10878. DEBUG_INFO("LocalAuthListEnabled is FALSE \n");
  10879. locallistVersion = -1;
  10880. }
  10881. else
  10882. {
  10883. DEBUG_INFO("handle GetLocalListVersionRequest OCPP_getListVerion \n");
  10884. locallistVersion = 0;
  10885. OCPP_getListVerion();
  10886. }
  10887. //from db.OCPP_getListVerion
  10888. ShmOCPP16Data->GetLocalListVersion.ResponseListVersion = locallistVersion;
  10889. //ShmOCPP16Data->MsMsg.bits.GetLocalListVersionReq = 1;
  10890. sendGetLocalListVersionConfirmation(uuid,"");
  10891. //ShmOCPP16Data->MsMsg.bits.GetLocalListVersionConf = 1;
  10892. return result;
  10893. }
  10894. int handleRemoteStartRequestOrg(char *uuid, char *payload)
  10895. {
  10896. mtrace();
  10897. int result = FAIL;
  10898. int connectorIdInt=-1;
  10899. int tempIndex = 0;
  10900. int connectorIdIsNULL, chargingProfileIsNULL;
  10901. char comfirmstr[20]={0};
  10902. char cmdBuf[512];
  10903. json_object *RemoteStartTransaction;
  10904. FILE *fp;
  10905. DEBUG_INFO("handleRemoteStartRequest ...\n");
  10906. if(server_pending == TRUE)
  10907. {
  10908. return 0;
  10909. }
  10910. connectorIdIsNULL = chargingProfileIsNULL= FALSE;
  10911. RemoteStartTransaction = json_tokener_parse(payload);
  10912. if(!is_error(RemoteStartTransaction))
  10913. {
  10914. if(json_object_object_get(RemoteStartTransaction, "connectorId") != NULL)
  10915. {
  10916. connectorIdInt = json_object_get_int(json_object_object_get(RemoteStartTransaction, "connectorId"));
  10917. }
  10918. else
  10919. {
  10920. connectorIdIsNULL = TRUE;
  10921. for(uint8_t gun_index=0;gun_index<gunTotalNumber;gun_index++)
  10922. {
  10923. if(!cpinitateMsg.bits[gun_index].isOnCharging && (strstr((char*)ShmOCPP16Data->StatusNotification[gun_index].Status, "Preparing") != NULL))
  10924. {
  10925. connectorIdIsNULL = FALSE;
  10926. connectorIdInt = (gun_index+1);
  10927. DEBUG_INFO("Remote start without connectorId but detect connector-%02d connected ready to start.\n", connectorIdInt);
  10928. break;
  10929. }
  10930. }
  10931. }
  10932. if((connectorIdInt <= gunTotalNumber) && (connectorIdInt > 0))
  10933. {
  10934. memset(&ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1], 0x00, sizeof(struct StructRemoteStartTransaction));
  10935. // Required data
  10936. sprintf((char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag, "%s", json_object_get_string(json_object_object_get(RemoteStartTransaction, "idTag")));
  10937. // Optional data
  10938. if(json_object_object_get(RemoteStartTransaction, "chargingProfile") != NULL)
  10939. {
  10940. ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingProfileId = json_object_get_int(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingProfileId"));
  10941. ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.StackLevel = json_object_get_int(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "stackLevel"));
  10942. sprintf((char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingProfilePurpose, "%s", json_object_get_string(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingProfilePurpose")));
  10943. sprintf((char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingProfileKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingProfileKind")));
  10944. if(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "transactionId") != NULL)
  10945. ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.TransactionId = json_object_get_int(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "transactionId"));
  10946. if(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "recurrencyKind") != NULL)
  10947. sprintf((char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.RecurrencyKind , "%s", json_object_get_string(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "recurrencyKind")));
  10948. if(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "validFrom") != NULL)
  10949. sprintf((char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ValidFrom , "%s", json_object_get_string(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "validFrom")));
  10950. if(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "validTo") != NULL)
  10951. sprintf((char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ValidTo , "%s", json_object_get_string(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "validTo")));
  10952. if(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingSchedule") != NULL)
  10953. {
  10954. 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")));
  10955. if(json_object_object_get(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingSchedule"), "duration") != NULL)
  10956. 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"));
  10957. if(json_object_object_get(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingSchedule"), "minChargingRate") != NULL)
  10958. 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"));
  10959. if(json_object_object_get(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingSchedule"), "startSchedule") != NULL)
  10960. 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")));
  10961. if(json_object_object_get(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingSchedule"), "chargingSchedulePeriod") != NULL)
  10962. {
  10963. 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++)
  10964. {
  10965. 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"));
  10966. 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"));
  10967. 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)
  10968. 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"));
  10969. }
  10970. }
  10971. }
  10972. }
  10973. else
  10974. {
  10975. chargingProfileIsNULL = TRUE;
  10976. }
  10977. }
  10978. }
  10979. else
  10980. {
  10981. connectorIdIsNULL = TRUE;
  10982. }
  10983. if(connectorIdIsNULL == TRUE) // Number of the connector on which to start the transaction. connectorId SHALL be > 0
  10984. {
  10985. DEBUG_WARN("Connector id is NULL\n.");
  10986. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  10987. goto end;
  10988. }
  10989. /*
  10990. enum _SYSTEM_STATUS
  10991. {
  10992. S_BOOTING = 0,
  10993. S_IDLE, = 1
  10994. S_AUTHORIZING, = 2
  10995. S_REASSIGN_CHECK, = 3
  10996. S_REASSIGN, = 4
  10997. S_PRECHARGE, = 5
  10998. S_PREPARING_FOR_EV, = 6
  10999. S_PREPARING_FOR_EVSE, = 7
  11000. S_CHARGING, = 8
  11001. S_TERMINATING, = 9
  11002. S_COMPLETE, = 10
  11003. S_ALARM, = 11
  11004. S_FAULT = 12
  11005. }
  11006. */
  11007. if((connectorIdIsNULL == FALSE)&&(connectorIdInt > 0) && (connectorIdInt <= gunTotalNumber))
  11008. {
  11009. //check Transaction active
  11010. if(gunType[connectorIdInt -1] == GUN_TYPE_CHAdeMO)
  11011. {
  11012. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  11013. {
  11014. tempIndex = ((connectorIdInt -1) == 2) ? 1: 0;
  11015. }
  11016. else
  11017. {
  11018. tempIndex = connectorIdInt -1;
  11019. }
  11020. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  11021. {
  11022. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex )
  11023. {
  11024. 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))
  11025. {
  11026. //Reserved
  11027. DEBUG_INFO("Reserved now !!!The idTag matches the idTag of Reservation!!!\n");
  11028. }
  11029. 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))
  11030. {
  11031. //Reserved
  11032. DEBUG_INFO("Reserved now !!! The idTag does NOT match the idTag of Reservation!!! Reject it!!!\n");
  11033. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  11034. goto end;
  11035. }
  11036. else
  11037. {
  11038. if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  11039. && (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_PREPARING ) //S_PRECHARGE
  11040. && (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EV ) //S_PREPARING_FOR_EV
  11041. && (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EVSE )) // S_PREPARING_FOR_EVSE
  11042. {
  11043. DEBUG_WARN("CHAdeMO connector not allow start\n.");
  11044. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  11045. goto end;
  11046. }
  11047. }//END FOR ELSE
  11048. }
  11049. }// END FOR CHAdeMO_QUANTITY
  11050. }
  11051. else if(gunType[connectorIdInt -1] == GUN_TYPE_CCS)
  11052. {
  11053. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  11054. {
  11055. tempIndex = ((connectorIdInt -1) == 2) ? 1: 0;
  11056. }
  11057. else
  11058. {
  11059. tempIndex = connectorIdInt -1;
  11060. }
  11061. for (int index = 0; index < CCS_QUANTITY; index++)
  11062. {
  11063. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  11064. {
  11065. 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))
  11066. {
  11067. //Reserved
  11068. DEBUG_INFO("Reserved now !!!The idTag matches the idTag of Reservation!!!\n");
  11069. }
  11070. 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))
  11071. {
  11072. //Reserved
  11073. DEBUG_INFO("Reserved now !!! The idTag does NOT match the idTag of Reservation!!! Reject it!!!\n");
  11074. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  11075. goto end;
  11076. }
  11077. else
  11078. {
  11079. if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  11080. && (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_PREPARING) //S_PRECHARGE
  11081. && (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EV) //S_PREPARING_FOR_EV
  11082. && (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EVSE)) // S_PREPARING_FOR_EVSE
  11083. {
  11084. DEBUG_WARN("CCS connector not allow start\n.");
  11085. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  11086. goto end;
  11087. }
  11088. }// END FOR ELSE
  11089. }
  11090. }// END FOR CCS_QUANTITY
  11091. }
  11092. else if(gunType[connectorIdInt -1] == GUN_TYPE_GBT)
  11093. {
  11094. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  11095. {
  11096. tempIndex = ((connectorIdInt -1) == 2) ? 1: 0;
  11097. }
  11098. else
  11099. {
  11100. tempIndex = connectorIdInt -1;
  11101. }
  11102. for (int index = 0; index < GB_QUANTITY; index++)
  11103. {
  11104. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex )
  11105. {
  11106. 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))
  11107. {
  11108. //Reserved
  11109. DEBUG_INFO("Reserved now !!!The idTag matches the idTag of Reservation!!!\n");
  11110. }
  11111. 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))
  11112. {
  11113. //Reserved
  11114. DEBUG_INFO("Reserved now !!! The idTag does NOT match the idTag of Reservation!!! Reject it!!!\n");
  11115. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  11116. goto end;
  11117. }
  11118. else
  11119. {
  11120. if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  11121. && (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_PREPARING) //S_PRECHARGE
  11122. && (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EV) //S_PREPARING_FOR_EV
  11123. && (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EVSE)) // S_PREPARING_FOR_EVSE
  11124. {
  11125. DEBUG_WARN("GB connector not allow start\n.");
  11126. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  11127. goto end;
  11128. }
  11129. }// END FOR ELSE
  11130. }
  11131. } // END FOR GB_QUANTITY
  11132. }
  11133. else if(gunType[connectorIdInt -1] == GUN_TYPE_DO)
  11134. {
  11135. tempIndex = connectorIdInt -1;
  11136. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  11137. {
  11138. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex )
  11139. {
  11140. 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))
  11141. {
  11142. //Reserved
  11143. DEBUG_INFO("Reserved now !!!The idTag matches the idTag of Reservation!!!\n");
  11144. }
  11145. 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))
  11146. {
  11147. //Reserved
  11148. DEBUG_INFO("Reserved now !!! The idTag does NOT match the idTag of Reservation!!! Reject it!!!\n");
  11149. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  11150. goto end;
  11151. }
  11152. else
  11153. {
  11154. if((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus != SYS_MODE_IDLE) //S_IDLE
  11155. && (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus != SYS_MODE_PREPARING) //S_PRECHARGE
  11156. && (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus != SYS_MODE_PREPARE_FOR_EV) //S_PREPARING_FOR_EV
  11157. && (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus != SYS_MODE_PREPARE_FOR_EVSE)) // S_PREPARING_FOR_EVSE
  11158. {
  11159. DEBUG_WARN("GB connector not allow start\n.");
  11160. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  11161. goto end;
  11162. }
  11163. }// END FOR ELSE
  11164. }
  11165. } // END FOR GB_QUANTITY
  11166. }
  11167. else
  11168. {
  11169. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D') // 'D' means DC
  11170. {
  11171. tempIndex = 2;
  11172. }
  11173. else
  11174. {
  11175. tempIndex = connectorIdInt -1;
  11176. }
  11177. for (int index = 0; index < AC_QUANTITY; index++)
  11178. {
  11179. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex )
  11180. {
  11181. 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))
  11182. {
  11183. //Reserved
  11184. DEBUG_INFO("Reserved now !!!The idTag matches the idTag of Reservation!!!\n");
  11185. }
  11186. 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))
  11187. {
  11188. //Reserved
  11189. DEBUG_INFO("Reserved now !!! The idTag does NOT match the idTag of Reservation!!! Reject it!!!\n");
  11190. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  11191. goto end;
  11192. }
  11193. else
  11194. {
  11195. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  11196. && (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_PREPARING) //S_PRECHARGE
  11197. && (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EV) //S_PREPARING_FOR_EV
  11198. && (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EVSE)) // S_PREPARING_FOR_EVSE
  11199. {
  11200. DEBUG_WARN("AC connector not allow start\n.");
  11201. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  11202. goto end;
  11203. }
  11204. }//END FOR ELSE
  11205. }
  11206. }// END FOR AC_QUANTITY
  11207. }
  11208. if(chargingProfileIsNULL == FALSE)
  11209. {
  11210. if(strcmp((char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingProfilePurpose, ChargingProfilePurposeTypeStr[TxProfile]) == 0)
  11211. {
  11212. ShmOCPP16Data->CsMsg.bits[connectorIdInt -1].RemoteStartTransactionReq = 1;
  11213. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Accepted]);
  11214. //memset idTag
  11215. memset((char *)ShmOCPP16Data->StartTransaction[connectorIdInt -1].IdTag,0, 20);
  11216. strcpy((char *)ShmOCPP16Data->StartTransaction[connectorIdInt -1].IdTag, (char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag);
  11217. memset((char *)ShmOCPP16Data->StopTransaction[connectorIdInt -1].IdTag,0, 20);
  11218. strcpy((char *)ShmOCPP16Data->StopTransaction[connectorIdInt -1].IdTag, (char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag);
  11219. // Save profile to file
  11220. sprintf(cmdBuf, "rm -f /Storage/OCPP/TxProfile_%d.json", connectorIdInt);
  11221. system(cmdBuf);
  11222. sprintf(cmdBuf, "/Storage/OCPP/TxProfile_%d.json", connectorIdInt);
  11223. fp = fopen(cmdBuf, "w");
  11224. 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));
  11225. fclose(fp);
  11226. }
  11227. else
  11228. {
  11229. DEBUG_WARN("Carging profile purpose not TxProfile.\n.");
  11230. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  11231. }
  11232. }
  11233. else
  11234. {
  11235. ShmOCPP16Data->CsMsg.bits[connectorIdInt -1].RemoteStartTransactionReq = 1;
  11236. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Accepted]);
  11237. //memset idTag
  11238. memset((char *)ShmOCPP16Data->StartTransaction[connectorIdInt -1].IdTag,0, 20);
  11239. strcpy((char *)ShmOCPP16Data->StartTransaction[connectorIdInt -1].IdTag, (char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag);
  11240. memset((char *)ShmOCPP16Data->StopTransaction[connectorIdInt -1].IdTag,0, 20);
  11241. strcpy((char *)ShmOCPP16Data->StopTransaction[connectorIdInt -1].IdTag, (char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag);
  11242. }
  11243. }
  11244. else
  11245. {
  11246. DEBUG_WARN("Connector id over\n.");
  11247. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  11248. //sprintf((char *)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ResponseStatus, "%s" ,comfirmstr);
  11249. }
  11250. end:
  11251. json_object_put(RemoteStartTransaction);
  11252. if((connectorIdIsNULL == FALSE) && (connectorIdInt <= gunTotalNumber))
  11253. {
  11254. ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ConnectorId = connectorIdInt;
  11255. sprintf((char *)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ResponseStatus, "%s" ,comfirmstr);
  11256. }
  11257. //OCPP send RemoteStartConfirmation by first.
  11258. sendRemoteStartConfirmation(uuid, comfirmstr);
  11259. return result;
  11260. }
  11261. int handleRemoteStartRequest(char *uuid, char *payload)
  11262. {
  11263. mtrace();
  11264. int result = PASS;
  11265. int connectorIdInt=-1;
  11266. int tempIndex = 0;
  11267. char comfirmstr[20]={0};
  11268. char cmdBuf[512];
  11269. json_object *RemoteStartTransaction;
  11270. FILE *fp;
  11271. DEBUG_INFO("handleRemoteStartRequest ...\n");
  11272. if(server_pending == TRUE)
  11273. {
  11274. result = FAIL;
  11275. }
  11276. RemoteStartTransaction = json_tokener_parse(payload);
  11277. if(!is_error(RemoteStartTransaction))
  11278. {
  11279. if(json_object_object_get(RemoteStartTransaction, "connectorId") != NULL)
  11280. {
  11281. connectorIdInt = json_object_get_int(json_object_object_get(RemoteStartTransaction, "connectorId"));
  11282. }
  11283. else
  11284. {
  11285. for(uint8_t gun_index=0;gun_index<gunTotalNumber;gun_index++)
  11286. {
  11287. if(!cpinitateMsg.bits[gun_index].isOnCharging && (strstr((char*)ShmOCPP16Data->StatusNotification[gun_index].Status, "Preparing") != NULL))
  11288. {
  11289. connectorIdInt = (gun_index+1);
  11290. DEBUG_INFO("Remote start without connectorId but detect connector-%02d connected ready to start.\n", connectorIdInt);
  11291. break;
  11292. }
  11293. }
  11294. }
  11295. if(connectorIdInt == 0)
  11296. {
  11297. DEBUG_WARN("Connector id shall not equal 0.\n");
  11298. result = FAIL;
  11299. }
  11300. else if(connectorIdInt == -1)
  11301. {
  11302. DEBUG_INFO("Connector id does not specific.\n");
  11303. for(uint8_t gun_index=0;gun_index<gunTotalNumber;gun_index++)
  11304. {
  11305. memset(&ShmOCPP16Data->RemoteStartTransaction[gun_index], 0x00, sizeof(struct StructRemoteStartTransaction));
  11306. // Required data
  11307. sprintf((char*)ShmOCPP16Data->RemoteStartTransaction[gun_index].IdTag, "%s", json_object_get_string(json_object_object_get(RemoteStartTransaction, "idTag")));
  11308. // Optional data
  11309. if(json_object_object_get(RemoteStartTransaction, "chargingProfile") != NULL)
  11310. {
  11311. ShmOCPP16Data->RemoteStartTransaction[gun_index].ChargingProfile.ChargingProfileId = json_object_get_int(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingProfileId"));
  11312. ShmOCPP16Data->RemoteStartTransaction[gun_index].ChargingProfile.StackLevel = json_object_get_int(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "stackLevel"));
  11313. sprintf((char*)ShmOCPP16Data->RemoteStartTransaction[gun_index].ChargingProfile.ChargingProfilePurpose, "%s", json_object_get_string(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingProfilePurpose")));
  11314. sprintf((char*)ShmOCPP16Data->RemoteStartTransaction[gun_index].ChargingProfile.ChargingProfileKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingProfileKind")));
  11315. if(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "transactionId") != NULL)
  11316. ShmOCPP16Data->RemoteStartTransaction[gun_index].ChargingProfile.TransactionId = json_object_get_int(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "transactionId"));
  11317. if(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "recurrencyKind") != NULL)
  11318. sprintf((char*)ShmOCPP16Data->RemoteStartTransaction[gun_index].ChargingProfile.RecurrencyKind , "%s", json_object_get_string(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "recurrencyKind")));
  11319. if(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "validFrom") != NULL)
  11320. sprintf((char*)ShmOCPP16Data->RemoteStartTransaction[gun_index].ChargingProfile.ValidFrom , "%s", json_object_get_string(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "validFrom")));
  11321. if(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "validTo") != NULL)
  11322. sprintf((char*)ShmOCPP16Data->RemoteStartTransaction[gun_index].ChargingProfile.ValidTo , "%s", json_object_get_string(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "validTo")));
  11323. if(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingSchedule") != NULL)
  11324. {
  11325. 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")));
  11326. if(json_object_object_get(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingSchedule"), "duration") != NULL)
  11327. 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"));
  11328. if(json_object_object_get(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingSchedule"), "minChargingRate") != NULL)
  11329. 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"));
  11330. if(json_object_object_get(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingSchedule"), "startSchedule") != NULL)
  11331. 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")));
  11332. if(json_object_object_get(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingSchedule"), "chargingSchedulePeriod") != NULL)
  11333. {
  11334. 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++)
  11335. {
  11336. 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"));
  11337. 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"));
  11338. 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)
  11339. 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"));
  11340. }
  11341. }
  11342. }
  11343. }
  11344. else
  11345. {
  11346. ShmOCPP16Data->RemoteStartTransaction[gun_index].ChargingProfile.ChargingProfileId = -1;
  11347. }
  11348. }
  11349. }
  11350. else if(((0 < connectorIdInt) && (connectorIdInt <= gunTotalNumber)))
  11351. {
  11352. DEBUG_INFO("Connector id: %d\n", connectorIdInt);
  11353. memset(&ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1], 0x00, sizeof(struct StructRemoteStartTransaction));
  11354. // Required data
  11355. sprintf((char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag, "%s", json_object_get_string(json_object_object_get(RemoteStartTransaction, "idTag")));
  11356. // Optional data
  11357. if(json_object_object_get(RemoteStartTransaction, "chargingProfile") != NULL)
  11358. {
  11359. ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingProfileId = json_object_get_int(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingProfileId"));
  11360. ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.StackLevel = json_object_get_int(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "stackLevel"));
  11361. sprintf((char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingProfilePurpose, "%s", json_object_get_string(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingProfilePurpose")));
  11362. sprintf((char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingProfileKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingProfileKind")));
  11363. if(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "transactionId") != NULL)
  11364. ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.TransactionId = json_object_get_int(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "transactionId"));
  11365. if(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "recurrencyKind") != NULL)
  11366. sprintf((char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.RecurrencyKind , "%s", json_object_get_string(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "recurrencyKind")));
  11367. if(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "validFrom") != NULL)
  11368. sprintf((char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ValidFrom , "%s", json_object_get_string(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "validFrom")));
  11369. if(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "validTo") != NULL)
  11370. sprintf((char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ValidTo , "%s", json_object_get_string(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "validTo")));
  11371. if(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingSchedule") != NULL)
  11372. {
  11373. 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")));
  11374. if(json_object_object_get(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingSchedule"), "duration") != NULL)
  11375. 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"));
  11376. if(json_object_object_get(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingSchedule"), "minChargingRate") != NULL)
  11377. 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"));
  11378. if(json_object_object_get(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingSchedule"), "startSchedule") != NULL)
  11379. 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")));
  11380. if(json_object_object_get(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingSchedule"), "chargingSchedulePeriod") != NULL)
  11381. {
  11382. 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++)
  11383. {
  11384. 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"));
  11385. 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"));
  11386. 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)
  11387. 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"));
  11388. }
  11389. }
  11390. }
  11391. }
  11392. else
  11393. {
  11394. ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingProfileId = -1;
  11395. }
  11396. }
  11397. else
  11398. {
  11399. DEBUG_WARN("Connector id is over maximun value.\n");
  11400. result = FAIL;
  11401. }
  11402. }
  11403. if(result == PASS)
  11404. {
  11405. if(connectorIdInt > 0)
  11406. {
  11407. //check Transaction active
  11408. if(gunType[connectorIdInt -1] == GUN_TYPE_CHAdeMO)
  11409. {
  11410. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  11411. {
  11412. tempIndex = ((connectorIdInt -1) == 2) ? 1: 0;
  11413. }
  11414. else
  11415. {
  11416. tempIndex = connectorIdInt -1;
  11417. }
  11418. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  11419. {
  11420. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  11421. {
  11422. if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ReservationId != -1) &&
  11423. (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ReservationId >= 0) &&
  11424. (strcmp((const char *)ShmOCPP16Data->ReserveNow[index].IdTag, (char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag) == 0))
  11425. {
  11426. //Reserved
  11427. DEBUG_INFO("CHAdeMO connector already reserved and idTag match.\n");
  11428. }
  11429. else if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ReservationId != -1) &&
  11430. (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ReservationId >= 0) &&
  11431. (strcmp((const char *)ShmOCPP16Data->ReserveNow[index].IdTag, (char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag) != 0))
  11432. {
  11433. //Reserved
  11434. DEBUG_INFO("CHAdeMO connector already reserved and idTag does not match.\n");
  11435. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  11436. goto end;
  11437. }
  11438. else
  11439. {
  11440. if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  11441. && (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_PREPARING ) //S_PRECHARGE
  11442. && (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EV ) //S_PREPARING_FOR_EV
  11443. && (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EVSE )) // S_PREPARING_FOR_EVSE
  11444. {
  11445. DEBUG_WARN("CHAdeMO connector not allow start cause busy.\n");
  11446. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  11447. goto end;
  11448. }
  11449. }//END FOR ELSE
  11450. }
  11451. }// END FOR CHAdeMO_QUANTITY
  11452. }
  11453. else if(gunType[connectorIdInt -1] == GUN_TYPE_CCS)
  11454. {
  11455. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  11456. {
  11457. tempIndex = ((connectorIdInt -1) == 2) ? 1: 0;
  11458. }
  11459. else
  11460. {
  11461. tempIndex = connectorIdInt -1;
  11462. }
  11463. for (int index = 0; index < CCS_QUANTITY; index++)
  11464. {
  11465. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  11466. {
  11467. if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ReservationId != -1) &&
  11468. (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ReservationId >= 0) &&
  11469. (strcmp((const char *)ShmOCPP16Data->ReserveNow[index].IdTag, (char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag) == 0))
  11470. {
  11471. //Reserved
  11472. DEBUG_INFO("CCS connector already reserved and idTag match.\n");
  11473. }
  11474. else if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ReservationId != -1) &&
  11475. (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ReservationId >= 0) &&
  11476. (strcmp((const char *)ShmOCPP16Data->ReserveNow[index].IdTag, (char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag) != 0))
  11477. {
  11478. //Reserved
  11479. DEBUG_INFO("CCS connector already reserved and idTag does not match.\n");
  11480. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  11481. goto end;
  11482. }
  11483. else
  11484. {
  11485. if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  11486. && (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_PREPARING) //S_PRECHARGE
  11487. && (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EV) //S_PREPARING_FOR_EV
  11488. && (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EVSE)) // S_PREPARING_FOR_EVSE
  11489. {
  11490. DEBUG_WARN("CCS connector not allow start cause busy.\n");
  11491. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  11492. goto end;
  11493. }
  11494. }// END FOR ELSE
  11495. }
  11496. }// END FOR CCS_QUANTITY
  11497. }
  11498. else if(gunType[connectorIdInt -1] == GUN_TYPE_GBT)
  11499. {
  11500. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  11501. {
  11502. tempIndex = ((connectorIdInt -1) == 2) ? 1: 0;
  11503. }
  11504. else
  11505. {
  11506. tempIndex = connectorIdInt -1;
  11507. }
  11508. for (int index = 0; index < GB_QUANTITY; index++)
  11509. {
  11510. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex )
  11511. {
  11512. if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ReservationId != -1) &&
  11513. (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ReservationId >= 0) &&
  11514. (strcmp((const char *)ShmOCPP16Data->ReserveNow[index].IdTag, (char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag) == 0))
  11515. {
  11516. //Reserved
  11517. DEBUG_INFO("GBT connector already reserved and idTag match.\n");
  11518. }
  11519. else if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ReservationId != -1) &&
  11520. (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ReservationId >= 0) &&
  11521. (strcmp((const char *)ShmOCPP16Data->ReserveNow[index].IdTag, (char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag) != 0))
  11522. {
  11523. //Reserved
  11524. DEBUG_INFO("GBT connector already reserved and idTag does not match.\n");
  11525. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  11526. goto end;
  11527. }
  11528. else
  11529. {
  11530. if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  11531. && (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_PREPARING) //S_PRECHARGE
  11532. && (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EV) //S_PREPARING_FOR_EV
  11533. && (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EVSE)) // S_PREPARING_FOR_EVSE
  11534. {
  11535. DEBUG_WARN("GBT connector not allow start cause busy.\n");
  11536. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  11537. goto end;
  11538. }
  11539. }// END FOR ELSE
  11540. }
  11541. } // END FOR GB_QUANTITY
  11542. }
  11543. else if(gunType[connectorIdInt -1] == GUN_TYPE_DO)
  11544. {
  11545. tempIndex = connectorIdInt -1;
  11546. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  11547. {
  11548. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex )
  11549. {
  11550. if((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.ReservationId != -1) &&
  11551. (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.ReservationId >= 0) &&
  11552. (strcmp((const char *)ShmOCPP16Data->ReserveNow[index].IdTag, (char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag) == 0))
  11553. {
  11554. //Reserved
  11555. DEBUG_INFO("Dispenser connector already reserved and idTag match.\n");
  11556. }
  11557. else if((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.ReservationId != -1) &&
  11558. (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.ReservationId >= 0) &&
  11559. (strcmp((const char *)ShmOCPP16Data->ReserveNow[index].IdTag, (char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag) != 0))
  11560. {
  11561. //Reserved
  11562. DEBUG_INFO("Dispenser connector already reserved and idTag does not match.\n");
  11563. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  11564. goto end;
  11565. }
  11566. else
  11567. {
  11568. if((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus != SYS_MODE_IDLE) //S_IDLE
  11569. && (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus != SYS_MODE_PREPARING) //S_PRECHARGE
  11570. && (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus != SYS_MODE_PREPARE_FOR_EV) //S_PREPARING_FOR_EV
  11571. && (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus != SYS_MODE_PREPARE_FOR_EVSE)) // S_PREPARING_FOR_EVSE
  11572. {
  11573. DEBUG_WARN("Dispenser connector not allow start cause busy.\n");
  11574. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  11575. goto end;
  11576. }
  11577. }// END FOR ELSE
  11578. }
  11579. } // END FOR GB_QUANTITY
  11580. }
  11581. else
  11582. {
  11583. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D') // 'D' means DC
  11584. {
  11585. tempIndex = 2;
  11586. }
  11587. else
  11588. {
  11589. tempIndex = connectorIdInt -1;
  11590. }
  11591. for (int index = 0; index < AC_QUANTITY; index++)
  11592. {
  11593. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex )
  11594. {
  11595. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].ReservationId != -1) &&
  11596. (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].ReservationId >= 0) &&
  11597. (strcmp((const char *)ShmOCPP16Data->ReserveNow[index].IdTag, (char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag) == 0))
  11598. {
  11599. //Reserved
  11600. DEBUG_INFO("AC connector already reserved and idTag match.\n");
  11601. }
  11602. else if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].ReservationId != -1) &&
  11603. (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].ReservationId >= 0) &&
  11604. (strcmp((const char *)ShmOCPP16Data->ReserveNow[index].IdTag, (char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag) != 0))
  11605. {
  11606. //Reserved
  11607. DEBUG_INFO("AC connector already reserved and idTag does not match.\n");
  11608. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  11609. goto end;
  11610. }
  11611. else
  11612. {
  11613. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  11614. && (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_PREPARING) //S_PRECHARGE
  11615. && (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EV) //S_PREPARING_FOR_EV
  11616. && (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EVSE)) // S_PREPARING_FOR_EVSE
  11617. {
  11618. DEBUG_WARN("AC connector not allow start cause busy.\n");
  11619. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  11620. goto end;
  11621. }
  11622. }//END FOR ELSE
  11623. }
  11624. }// END FOR AC_QUANTITY
  11625. }
  11626. if(ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingProfileId > -1)
  11627. {
  11628. if(strcmp((char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingProfilePurpose, ChargingProfilePurposeTypeStr[TxProfile]) == 0)
  11629. {
  11630. // Save profile to file
  11631. sprintf(cmdBuf, "rm -f /Storage/OCPP/TxProfile_%d.json", connectorIdInt);
  11632. system(cmdBuf);
  11633. sprintf(cmdBuf, "/Storage/OCPP/TxProfile_%d.json", connectorIdInt);
  11634. fp = fopen(cmdBuf, "w");
  11635. 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));
  11636. fclose(fp);
  11637. }
  11638. else
  11639. {
  11640. DEBUG_WARN("Profile purpose not TxProfile.\n");
  11641. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  11642. goto end;
  11643. }
  11644. }
  11645. ShmOCPP16Data->CsMsg.bits[connectorIdInt -1].RemoteStartTransactionReq = 1;
  11646. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Accepted]);
  11647. memset((char *)ShmOCPP16Data->StartTransaction[connectorIdInt -1].IdTag,0, 20);
  11648. strcpy((char *)ShmOCPP16Data->StartTransaction[connectorIdInt -1].IdTag, (char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag);
  11649. memset((char *)ShmOCPP16Data->StopTransaction[connectorIdInt -1].IdTag,0, 20);
  11650. strcpy((char *)ShmOCPP16Data->StopTransaction[connectorIdInt -1].IdTag, (char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag);
  11651. }
  11652. else
  11653. {
  11654. uint8_t isHasIdleConnector = FALSE;
  11655. for(uint8_t gun_index=0;gun_index<gunTotalNumber;gun_index++)
  11656. {
  11657. if(!cpinitateMsg.bits[gun_index].isOnCharging)
  11658. {
  11659. isHasIdleConnector = TRUE;
  11660. break;
  11661. }
  11662. }
  11663. if(isHasIdleConnector == TRUE)
  11664. {
  11665. DEBUG_INFO("Start wait connector link to EV in %s seconds.\n", ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemData);
  11666. if(ShmOCPP16Data->RemoteStartTransaction[0].ChargingProfile.ChargingProfileId > -1)
  11667. {
  11668. if(strcmp((char*)ShmOCPP16Data->RemoteStartTransaction[0].ChargingProfile.ChargingProfilePurpose, ChargingProfilePurposeTypeStr[TxProfile]) == 0)
  11669. {
  11670. // Save profile to file
  11671. sprintf(cmdBuf, "rm -f /Storage/OCPP/TxProfile_Tmp.json");
  11672. system(cmdBuf);
  11673. sprintf(cmdBuf, "/Storage/OCPP/TxProfile_Tmp.json");
  11674. fp = fopen(cmdBuf, "w");
  11675. fprintf(fp, "{\"connectorId\":0,\"csChargingProfiles\":%s}\n", json_object_to_json_string_ext(json_object_object_get(RemoteStartTransaction, "chargingProfile"), JSON_C_TO_STRING_PLAIN));
  11676. fclose(fp);
  11677. refreshStartTimer(&clientTime.RemoteStartWait);
  11678. ShmOCPP16Data->MsMsg.bits.isRemoteStartWaitReq = 1;
  11679. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Accepted]);
  11680. }
  11681. else
  11682. {
  11683. DEBUG_WARN("Profile purpose not TxProfile.\n");
  11684. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  11685. }
  11686. }
  11687. else
  11688. {
  11689. refreshStartTimer(&clientTime.RemoteStartWait);
  11690. ShmOCPP16Data->MsMsg.bits.isRemoteStartWaitReq = 1;
  11691. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Accepted]);
  11692. }
  11693. }
  11694. else
  11695. {
  11696. DEBUG_INFO("There is not any connector is idle.\n");
  11697. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  11698. }
  11699. }
  11700. }
  11701. else
  11702. {
  11703. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  11704. }
  11705. end:
  11706. json_object_put(RemoteStartTransaction);
  11707. sendRemoteStartConfirmation(uuid, comfirmstr);
  11708. return result;
  11709. }
  11710. int handleRemoteStopTransactionRequest(char *uuid, char *payload)
  11711. {
  11712. mtrace();
  11713. int result = FAIL;
  11714. int match = FALSE;
  11715. int GunNO = 0;
  11716. int tempIndex = 0;
  11717. int transactionIdInt=0;
  11718. int transactionIdIsNULL= TRUE;
  11719. char comfirmstr[20];
  11720. json_object *RemoteStopTransaction;
  11721. //[2,"ff522854-0dea-436e-87ba-23a229269994","RemoteStopTransaction",{"transactionId":1373618380}]
  11722. DEBUG_INFO("handleRemoteStopTransactionRequest...\n");
  11723. if(server_pending == TRUE)
  11724. {
  11725. return 0;
  11726. }
  11727. RemoteStopTransaction = json_tokener_parse(payload);
  11728. if(!is_error(RemoteStopTransaction))
  11729. {
  11730. if(json_object_object_get(RemoteStopTransaction, "transactionId") != NULL)
  11731. {
  11732. transactionIdInt = json_object_get_int(json_object_object_get(RemoteStopTransaction, "transactionId"));
  11733. transactionIdIsNULL = FALSE;
  11734. }
  11735. }
  11736. json_object_put(RemoteStopTransaction);
  11737. if(transactionIdIsNULL == FALSE)
  11738. {
  11739. for(int gun_index=0;gun_index < gunTotalNumber;gun_index++)
  11740. {
  11741. if(ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId == transactionIdInt)
  11742. {
  11743. //check Transaction active
  11744. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  11745. {
  11746. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  11747. {
  11748. tempIndex = ((gun_index==2) ? 1: 0);
  11749. }
  11750. else
  11751. {
  11752. tempIndex = gun_index;
  11753. }
  11754. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  11755. {
  11756. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  11757. {
  11758. if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_TERMINATING)) // SYS_MODE_CHARGING, SYS_MODE_TERMINATING
  11759. {
  11760. match = TRUE;
  11761. GunNO = gun_index;
  11762. }
  11763. }
  11764. }// END FOR CHAdeMO_QUANTITY
  11765. }
  11766. else if(gunType[gun_index] == GUN_TYPE_CCS)
  11767. {
  11768. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  11769. {
  11770. tempIndex = ((gun_index==2) ? 1: 0);
  11771. }
  11772. else
  11773. {
  11774. tempIndex = gun_index;
  11775. }
  11776. for (int index = 0; index < CCS_QUANTITY; index++)
  11777. {
  11778. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  11779. {
  11780. if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_TERMINATING) ) // SYS_MODE_CHARGING, SYS_MODE_TERMINATING
  11781. {
  11782. match = TRUE;
  11783. GunNO = gun_index;
  11784. }
  11785. }
  11786. }// END FOR CCS_QUANTITY
  11787. }
  11788. else if(gunType[gun_index] == GUN_TYPE_GBT)
  11789. {
  11790. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  11791. {
  11792. tempIndex = ((gun_index==2) ? 1: 0);
  11793. }
  11794. else
  11795. {
  11796. tempIndex = gun_index;
  11797. }
  11798. for (int index = 0; index < GB_QUANTITY; index++)
  11799. {
  11800. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  11801. {
  11802. if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_TERMINATING)) // SYS_MODE_CHARGING, SYS_MODE_TERMINATING
  11803. {
  11804. match = TRUE;
  11805. GunNO = gun_index;
  11806. }
  11807. }
  11808. }// END FOR GB_QUANTITY
  11809. }
  11810. else if(gunType[gun_index] == GUN_TYPE_DO)
  11811. {
  11812. tempIndex = gun_index;
  11813. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  11814. {
  11815. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  11816. {
  11817. 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
  11818. {
  11819. match = TRUE;
  11820. GunNO = gun_index;
  11821. }
  11822. }
  11823. }// END FOR GB_QUANTITY
  11824. }
  11825. else
  11826. {
  11827. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D') // 'D' means DC
  11828. {
  11829. tempIndex = 2;
  11830. }
  11831. else
  11832. {
  11833. tempIndex = gun_index;
  11834. }
  11835. for (int index = 0; index < AC_QUANTITY; index++)
  11836. {
  11837. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  11838. {
  11839. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_TERMINATING)) // SYS_MODE_CHARGING, SYS_MODE_TERMINATING
  11840. {
  11841. match = TRUE;
  11842. GunNO = gun_index;
  11843. }
  11844. }
  11845. }// END FOR CHAdeMO_QUANTITY
  11846. } // END FOR AC ELSE
  11847. }// CHECK IF ResponseTransactionId == transactionIdInt
  11848. }//END FOR
  11849. if( match == TRUE)
  11850. {
  11851. ShmOCPP16Data->CsMsg.bits[GunNO].RemoteStopTransactionReq = 1; // inform csu of StopTransaction
  11852. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Accepted]);
  11853. sprintf((char *)ShmOCPP16Data->RemoteStopTransaction[GunNO].ResponseStatus, "%s" ,comfirmstr);
  11854. }
  11855. else
  11856. {
  11857. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  11858. }
  11859. }
  11860. else
  11861. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  11862. sendRemoteStopTransactionConfirmation(uuid, comfirmstr);
  11863. return result;
  11864. }
  11865. int handleReserveNowTransactionRequest(char *uuid, char *payload)
  11866. {
  11867. mtrace();
  11868. int result = FAIL;
  11869. int connectorIdInt=0, reservationIdInt=0;
  11870. int tempIndex = 0;
  11871. char expiryDatestr[30]={0}, idTagstr[21]={0},parentIdTagstr[21]={0};
  11872. char comfirmstr[20]={0};
  11873. char sstr[180]={ 0 },sstrtemp[200]={ 0 };
  11874. int c = 0;
  11875. char *loc;
  11876. //char *ptr;
  11877. DEBUG_INFO("handleReserveNowTransactionRequest ...\n");
  11878. strcpy(sstrtemp, stringtrimspace(payload));
  11879. //***(1)connectorId ****/
  11880. c=0;
  11881. loc = strstr(sstrtemp, "connectorId");
  11882. memset(sstr ,0, ARRAY_SIZE(sstr) );
  11883. while ((loc != NULL) &&(loc[strlen("connectorId")+2+c] != ',') && (loc[strlen("connectorId")+2+c] != '}'))
  11884. {
  11885. sstr[c] = loc[strlen("connectorId")+2+c];
  11886. //printf("i=%d sstr=%c\n",c, sstr[c]);
  11887. c++;
  11888. }
  11889. sstr[c] = '\0';
  11890. connectorIdInt = atoi(sstr);
  11891. //***(2)expiryDate ****/
  11892. loc = strstr(sstrtemp, "expiryDate");
  11893. memset(sstr ,0, ARRAY_SIZE(sstr) );
  11894. c = 0;
  11895. while ((loc != NULL) &&(loc[3+strlen("expiryDate")+c] != '\"'))
  11896. {
  11897. sstr[c] = loc[3+strlen("expiryDate")+c];
  11898. c++;
  11899. }
  11900. sstr[c] = '\0';
  11901. strcpy(expiryDatestr, sstr);
  11902. //***(3)idTag ****/
  11903. loc = strstr(sstrtemp, "idTag");
  11904. memset(sstr ,0, ARRAY_SIZE(sstr) );
  11905. c = 0;
  11906. while ((loc != NULL) &&(loc[3+strlen("idTag")+c] != '\"'))
  11907. {
  11908. sstr[c] = loc[3+strlen("idTag")+c];
  11909. c++;
  11910. }
  11911. sstr[c] = '\0';
  11912. strcpy(idTagstr, sstr);
  11913. //***(4)parentIdTag ****/
  11914. loc = strstr(sstrtemp, "parentIdTag");
  11915. memset(sstr ,0, ARRAY_SIZE(sstr) );
  11916. c = 0;
  11917. if(loc == NULL)
  11918. {
  11919. strcpy(parentIdTagstr, "");
  11920. }
  11921. else
  11922. {
  11923. while ((loc != NULL) &&(loc[3+strlen("parentIdTag")+c] != '\"'))
  11924. {
  11925. sstr[c] = loc[3+strlen("parentIdTag")+c];
  11926. c++;
  11927. }
  11928. sstr[c] = '\0';
  11929. strcpy(parentIdTagstr, sstr);
  11930. }
  11931. //***(5)reservationId ****/
  11932. c=0;
  11933. loc = strstr(sstrtemp, "reservationId");
  11934. memset(sstr ,0, ARRAY_SIZE(sstr) );
  11935. while ((loc != NULL) &&((loc[strlen("reservationId")+2+c] != '}') && (loc[strlen("reservationId")+2+c] != ',')))
  11936. {
  11937. sstr[c] = loc[strlen("reservationId")+2+c];
  11938. //printf("i=%d sstr=%c\n",c, sstr[c]);
  11939. c++;
  11940. }
  11941. sstr[c] = '\0';
  11942. reservationIdInt = atoi(sstr);
  11943. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  11944. /*
  11945. enum SYSTEM_STATUS
  11946. {
  11947. SYS_MODE_BOOTING = 0,
  11948. SYS_MODE_IDLE = 1,
  11949. SYS_MODE_AUTHORIZING = 2,
  11950. SYS_MODE_MODE_REASSIGN_CHECK = 3,
  11951. SYS_MODE_REASSIGN = 4,
  11952. SYS_MODE_PREPARING = 5,
  11953. SYS_MODE_PREPARE_FOR_EV = 6,
  11954. SYS_MODE_PREPARE_FOR_EVSE = 7,
  11955. SYS_MODE_CHARGING = 8,
  11956. SYS_MODE_TERMINATING = 9,
  11957. SYS_MODE_COMPLETE = 10,
  11958. SYS_MODE_ALARM = 11,
  11959. SYS_MODE_FAULT = 12,
  11960. SYS_MODE_RESERVATION = 13,
  11961. SYS_MODE_BOOKING = 14,
  11962. SYS_MODE_MAINTAIN = 15,
  11963. SYS_MODE_DEBUG = 16,
  11964. SYS_MODE_CCS_PRECHARGE_STEP0 = 17,
  11965. SYS_MODE_CCS_PRECHARGE_STEP1 = 18,
  11966. SYS_MODE_UPDATE = 19
  11967. };
  11968. */
  11969. if((connectorIdInt == 0) &&(strcmp((const char *)ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemData, "FALSE") == 0)) //For OCTT Test case
  11970. {
  11971. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  11972. goto end;
  11973. }
  11974. if((connectorIdInt > 0) && ((connectorIdInt -1) <= gunTotalNumber))
  11975. {
  11976. //check Transaction active
  11977. if(gunType[connectorIdInt -1] == GUN_TYPE_CHAdeMO)
  11978. {
  11979. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  11980. {
  11981. tempIndex = (((connectorIdInt -1)==2) ? 1: 0);
  11982. }
  11983. else
  11984. {
  11985. tempIndex = connectorIdInt -1;
  11986. }
  11987. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  11988. {
  11989. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  11990. {
  11991. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ReservationId)
  11992. {
  11993. if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_FAULT)&&(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_ALARM)) //S_FAULT
  11994. {
  11995. if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_IDLE) //S_IDLE
  11996. {
  11997. if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ConnectorPlugIn == 1) || (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].InProgress == 1))
  11998. {
  11999. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  12000. }
  12001. else
  12002. {
  12003. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  12004. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  12005. }
  12006. }
  12007. 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'))
  12008. {
  12009. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  12010. }
  12011. else if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_PREPARING) || (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_RESERVATION) ) //S_PRECHARGE
  12012. {
  12013. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  12014. }
  12015. else
  12016. {
  12017. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  12018. }
  12019. }
  12020. 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
  12021. {
  12022. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  12023. }
  12024. }
  12025. else
  12026. {
  12027. //replace reservation
  12028. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  12029. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  12030. }
  12031. }
  12032. } // END FOR CHAdeMO_QUANTITY
  12033. }
  12034. else if(gunType[connectorIdInt -1] == GUN_TYPE_CCS)
  12035. {
  12036. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  12037. {
  12038. tempIndex = (((connectorIdInt -1)==2) ? 1: 0);
  12039. }
  12040. else
  12041. {
  12042. tempIndex = connectorIdInt -1;
  12043. }
  12044. for (int index = 0; index < CCS_QUANTITY; index++)
  12045. {
  12046. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  12047. {
  12048. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ReservationId)
  12049. {
  12050. //SystemStatus: 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault, 8: Reserved, 9: maintain
  12051. if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_FAULT)&&(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_ALARM)) //S_FAULT
  12052. {
  12053. if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_IDLE) //S_IDLE
  12054. {
  12055. if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ConnectorPlugIn == 1) || (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].InProgress == 1))
  12056. {
  12057. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  12058. }
  12059. else
  12060. {
  12061. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  12062. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  12063. }
  12064. }
  12065. 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'))
  12066. {
  12067. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  12068. }
  12069. else if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_PREPARING) || (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_RESERVATION)) //S_PRECHARGE
  12070. {
  12071. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  12072. }
  12073. else
  12074. {
  12075. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  12076. }
  12077. }
  12078. 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
  12079. {
  12080. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  12081. }
  12082. }
  12083. else
  12084. {
  12085. //replace reservation
  12086. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  12087. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  12088. }
  12089. }
  12090. } // END FOR CCS_QUANTITY
  12091. }
  12092. else if(gunType[connectorIdInt -1] == GUN_TYPE_GBT)
  12093. {
  12094. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  12095. {
  12096. tempIndex = (((connectorIdInt -1)==2) ? 1: 0);
  12097. }
  12098. else
  12099. {
  12100. tempIndex = connectorIdInt -1;
  12101. }
  12102. for (int index = 0; index < GB_QUANTITY; index++)
  12103. {
  12104. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  12105. {
  12106. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ReservationId)
  12107. {
  12108. //SystemStatus: 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault, 8: Reserved, 9: maintain
  12109. if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_FAULT)&&(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_ALARM)) //SYS_MODE_FAULT, SYS_MODE_ALARM
  12110. {
  12111. if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_IDLE) //S_IDLE
  12112. {
  12113. if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ConnectorPlugIn == 1) || (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].InProgress == 1))
  12114. {
  12115. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  12116. }
  12117. else
  12118. {
  12119. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  12120. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  12121. }
  12122. }
  12123. 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'))
  12124. {
  12125. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  12126. }
  12127. else if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_PREPARING) || (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_RESERVATION) ) //S_PRECHARGE
  12128. {
  12129. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  12130. }
  12131. else
  12132. {
  12133. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  12134. }
  12135. }
  12136. 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
  12137. {
  12138. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  12139. }
  12140. }
  12141. else
  12142. {
  12143. //replace reservation
  12144. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  12145. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  12146. }
  12147. }
  12148. }// END FOR GB_QUANTITY
  12149. }
  12150. else if(gunType[connectorIdInt -1] == GUN_TYPE_DO)
  12151. {
  12152. tempIndex = connectorIdInt -1;
  12153. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  12154. {
  12155. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  12156. {
  12157. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.ReservationId)
  12158. {
  12159. //SystemStatus: 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault, 8: Reserved, 9: maintain
  12160. 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
  12161. {
  12162. if(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_IDLE) //S_IDLE
  12163. {
  12164. if((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.ConnectorPlugIn == 1) || (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.InProgress == 1))
  12165. {
  12166. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  12167. }
  12168. else
  12169. {
  12170. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  12171. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  12172. }
  12173. }
  12174. 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'))
  12175. {
  12176. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  12177. }
  12178. else if((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_PREPARING) || (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_RESERVATION) ) //S_PRECHARGE
  12179. {
  12180. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  12181. }
  12182. else
  12183. {
  12184. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  12185. }
  12186. }
  12187. 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
  12188. {
  12189. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  12190. }
  12191. }
  12192. else
  12193. {
  12194. //replace reservation
  12195. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  12196. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  12197. }
  12198. }
  12199. }// END FOR GB_QUANTITY
  12200. }
  12201. else
  12202. {
  12203. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D') // 'D' means DC
  12204. {
  12205. tempIndex = 2;
  12206. }
  12207. else
  12208. {
  12209. tempIndex = (connectorIdInt -1);
  12210. }
  12211. for (int index = 0; index < AC_QUANTITY; index++)
  12212. {
  12213. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  12214. {
  12215. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.AcChargingData[index].ReservationId)
  12216. {
  12217. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_FAULT)&&(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_ALARM)) //SYS_MODE_FAULT, SYS_MODE_ALARM
  12218. {
  12219. if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_IDLE) //S_IDLE
  12220. {
  12221. 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))
  12222. {
  12223. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  12224. }
  12225. else
  12226. {
  12227. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  12228. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  12229. }
  12230. }
  12231. 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'))
  12232. {
  12233. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  12234. }
  12235. else if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_PREPARING) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_RESERVATION) ) //S_PRECHARGE
  12236. {
  12237. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  12238. }
  12239. else
  12240. {
  12241. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  12242. }
  12243. }
  12244. 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
  12245. {
  12246. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  12247. }
  12248. }
  12249. else
  12250. {
  12251. //replace reservation
  12252. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  12253. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  12254. }
  12255. }
  12256. } // END FOR AC_QUANTITY
  12257. }
  12258. sprintf((char *)ShmOCPP16Data->ReserveNow[connectorIdInt-1].ResponseStatus, "%s" ,comfirmstr);
  12259. }
  12260. else if(connectorIdInt == 0)
  12261. {
  12262. //check Transaction active
  12263. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  12264. {
  12265. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ReservationId)
  12266. {
  12267. 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'))
  12268. {
  12269. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  12270. goto end;
  12271. }
  12272. else if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_PREPARING) //S_PRECHARGE
  12273. {
  12274. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  12275. goto end;
  12276. }
  12277. 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
  12278. {
  12279. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  12280. goto end;
  12281. }
  12282. else if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  12283. {
  12284. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  12285. goto end;
  12286. }
  12287. }
  12288. }// END FOR CHAdeMO_QUANTITY
  12289. for (int index = 0; index < CCS_QUANTITY; index++)
  12290. {
  12291. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ReservationId)
  12292. {
  12293. 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'))
  12294. {
  12295. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  12296. goto end;
  12297. }
  12298. else if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_PREPARING) //SYS_MODE_PREPARING
  12299. {
  12300. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  12301. goto end;
  12302. }
  12303. 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
  12304. {
  12305. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  12306. goto end;
  12307. }
  12308. else if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  12309. {
  12310. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  12311. goto end;
  12312. }
  12313. }
  12314. } // END FOR CCS_QUANTITY
  12315. for (int index = 0; index < GB_QUANTITY; index++)
  12316. {
  12317. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ReservationId)
  12318. {
  12319. 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'))
  12320. {
  12321. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  12322. goto end;
  12323. }
  12324. else if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_PREPARING) //S_PRECHARGE
  12325. {
  12326. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  12327. goto end;
  12328. }
  12329. 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
  12330. {
  12331. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  12332. goto end;
  12333. }
  12334. else if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  12335. {
  12336. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  12337. goto end;
  12338. }
  12339. }
  12340. } // END FOR GB_QUANTITY
  12341. for (int index = 0; index < AC_QUANTITY; index++)
  12342. {
  12343. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.AcChargingData[index].ReservationId)
  12344. {
  12345. 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'))
  12346. {
  12347. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  12348. goto end;
  12349. }
  12350. else if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_PREPARING) //S_PRECHARGE
  12351. {
  12352. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  12353. goto end;
  12354. }
  12355. 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
  12356. {
  12357. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  12358. goto end;
  12359. }
  12360. if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_IDLE) //S_IDLE
  12361. {
  12362. 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))
  12363. {
  12364. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  12365. goto end;
  12366. }
  12367. }
  12368. else if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  12369. {
  12370. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  12371. goto end;
  12372. }
  12373. }
  12374. }// END FOR AC_QUANTITY
  12375. //The connectorId is 0
  12376. ShmOCPP16Data->CsMsg.bits[0].ReserveNowReq = 1;
  12377. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  12378. sprintf((char *)ShmOCPP16Data->ReserveNow[0].ResponseStatus, "%s" ,comfirmstr);
  12379. ShmOCPP16Data->ReserveNow[0].ConnectorId = connectorIdInt;
  12380. sprintf((char *)ShmOCPP16Data->ReserveNow[0].ExpiryDate, "%s" , expiryDatestr);
  12381. sprintf((char *)ShmOCPP16Data->ReserveNow[0].IdTag, "%s" , idTagstr);
  12382. sprintf((char *)ShmOCPP16Data->ReserveNow[0].ParentIdTag, "%s" , parentIdTagstr);
  12383. ShmOCPP16Data->ReserveNow[0].ReservationId = reservationIdInt;
  12384. strcpy((char *)ShmOCPP16Data->ReserveNow[0].guid, uuid);
  12385. result = TRUE;
  12386. return result;
  12387. }
  12388. else
  12389. {
  12390. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  12391. sprintf((char *)ShmOCPP16Data->ReserveNow[connectorIdInt-1].ResponseStatus, "%s" ,comfirmstr);
  12392. }
  12393. if(strcmp(comfirmstr,"Accepted") == 0)
  12394. {
  12395. ShmOCPP16Data->ReserveNow[connectorIdInt-1].ConnectorId = connectorIdInt;
  12396. sprintf((char *)ShmOCPP16Data->ReserveNow[connectorIdInt-1].ExpiryDate, "%s" , expiryDatestr);
  12397. sprintf((char *)ShmOCPP16Data->ReserveNow[connectorIdInt-1].IdTag, "%s" , idTagstr);
  12398. sprintf((char *)ShmOCPP16Data->ReserveNow[connectorIdInt-1].ParentIdTag, "%s" , parentIdTagstr);
  12399. ShmOCPP16Data->ReserveNow[connectorIdInt-1].ReservationId = reservationIdInt;
  12400. strcpy((char *)ShmOCPP16Data->ReserveNow[connectorIdInt-1].guid, uuid);
  12401. result = TRUE;
  12402. return result;
  12403. }
  12404. end:
  12405. sendReserveNowTransactionConfirmation(uuid,comfirmstr);
  12406. //ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].ReserveNowConf = 1;
  12407. return result;
  12408. }
  12409. int handleResetRequest(char *uuid, char *payload)
  12410. {
  12411. mtrace();
  12412. int result = FAIL;
  12413. char sstr[10]={0},sstrtemp[30]={ 0 };
  12414. char typestr[10]={0};
  12415. char comfirmstr[20]={0};
  12416. int c = 0;
  12417. char *loc;
  12418. DEBUG_INFO("handleResetRequest...\n");
  12419. strcpy(sstrtemp, stringtrimspace(payload));
  12420. loc = strstr(sstrtemp, "type");
  12421. memset(sstr ,0, ARRAY_SIZE(sstr) );
  12422. c = 0;
  12423. while (loc[3+strlen("type")+c] != '\"')
  12424. {
  12425. sstr[c] = loc[3+strlen("type")+c];
  12426. c++;
  12427. }
  12428. sstr[c] = '\0';
  12429. strcpy(typestr,sstr);
  12430. sprintf((char *)ShmOCPP16Data->Reset.Type, "%s" ,typestr);
  12431. if((strcmp(typestr, ResetTypeStr[Hard])==0) || (strcmp(typestr, ResetTypeStr[Soft])==0))
  12432. {
  12433. ShmOCPP16Data->MsMsg.bits.ResetReq = 1;
  12434. strcpy((char *)ShmOCPP16Data->Reset.guid, uuid);
  12435. strcpy(comfirmstr, ResetStatusStr[ResetStatus_Accepted]);
  12436. sprintf((char *)ShmOCPP16Data->Reset.ResponseStatus, "%s" ,comfirmstr);
  12437. }
  12438. else
  12439. {
  12440. strcpy(comfirmstr, ResetStatusStr[ResetStatus_Rejected]);
  12441. sprintf((char *)ShmOCPP16Data->Reset.ResponseStatus, "%s" ,comfirmstr);
  12442. result = PASS;
  12443. }
  12444. sendResetConfirmation(uuid, comfirmstr);
  12445. return result;
  12446. }
  12447. int handleSendLocalListRequest(char *uuid, char *payload)
  12448. {
  12449. mtrace();
  12450. int result = FAIL;
  12451. char comfirmstr[20];
  12452. int checkState_Faulted = FALSE;
  12453. json_object *SendLocalList;
  12454. DEBUG_INFO("handleSendLocalListRequest...\n");
  12455. if(strcmp((const char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "FALSE") == 0) //For OCTT Test case
  12456. {
  12457. strcpy(comfirmstr, UpdateStatusStr[UpdateStatus_NotSupported]);
  12458. goto end;
  12459. }
  12460. //check Charge Point state
  12461. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  12462. {
  12463. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_FAULT) //S_FAULT ---> Faulted
  12464. {
  12465. checkState_Faulted = TRUE; //OCPP Status: Faulted
  12466. }
  12467. }
  12468. for (int index = 0; index < CCS_QUANTITY; index++)
  12469. {
  12470. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_FAULT) //S_FAULT ---> Faulted
  12471. {
  12472. checkState_Faulted = TRUE; //OCPP Status
  12473. }
  12474. }
  12475. for (int index = 0; index < GB_QUANTITY; index++)
  12476. {
  12477. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_FAULT) //S_FAULT ---> Faulted
  12478. {
  12479. checkState_Faulted = TRUE; //OCPP Status: Faulted
  12480. }
  12481. }
  12482. //check Charge Point state
  12483. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  12484. {
  12485. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_FAULT) //S_FAULT ---> Faulted
  12486. {
  12487. checkState_Faulted = TRUE; //OCPP Status: Faulted
  12488. }
  12489. }
  12490. //check Charge Point state
  12491. for (int index = 0; index < AC_QUANTITY; index++)
  12492. {
  12493. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_FAULT) //S_FAULT ---> Faulted
  12494. {
  12495. checkState_Faulted = TRUE; //OCPP Status: Faulted
  12496. }
  12497. }
  12498. if(checkState_Faulted == TRUE)
  12499. {
  12500. strcpy(comfirmstr, UpdateStatusStr[UpdateStatus_Failed]);
  12501. goto end;
  12502. }
  12503. // Parsing payload
  12504. SendLocalList = json_tokener_parse(payload);
  12505. if(!is_error(SendLocalList))
  12506. {
  12507. // Required data
  12508. ShmOCPP16Data->SendLocalList.ListVersion = json_object_get_int(json_object_object_get(SendLocalList, "listVersion"));
  12509. sprintf((char*)ShmOCPP16Data->SendLocalList.UpdateType, "%s", json_object_get_string(json_object_object_get(SendLocalList, "updateType")));
  12510. // Optional data
  12511. if(json_object_object_get(SendLocalList, "localAuthorizationList") != NULL)
  12512. {
  12513. //Check UpdateType
  12514. if(strcmp((char*)ShmOCPP16Data->SendLocalList.UpdateType, UpdateTypeStr[Full]) == 0)
  12515. {
  12516. //Local list full update
  12517. DEBUG_INFO("Local list full update.\n");
  12518. locallistVersion = 0;
  12519. OCPP_getListVerion();
  12520. /*if(ShmOCPP16Data->SendLocalList.ListVersion < locallistVersion)
  12521. {
  12522. strcpy(comfirmstr, UpdateStatusStr[UpdateStatus_Failed]);
  12523. goto end;
  12524. }*/
  12525. OCPP_cleanLocalList();
  12526. }
  12527. else if(strcmp((char*)ShmOCPP16Data->SendLocalList.UpdateType, UpdateTypeStr[Differential]) == 0)
  12528. {
  12529. //Local list different update
  12530. DEBUG_INFO("Local list different update.\n");
  12531. locallistVersion = 0;
  12532. OCPP_getListVerion();
  12533. if(ShmOCPP16Data->SendLocalList.ListVersion < locallistVersion)
  12534. {
  12535. strcpy(comfirmstr, UpdateStatusStr[UpdateStatus_VersionMismatch]);
  12536. goto end;
  12537. }
  12538. }
  12539. else
  12540. {
  12541. strcpy(comfirmstr, UpdateStatusStr[UpdateStatus_NotSupported]);
  12542. goto end;
  12543. }
  12544. if(json_object_array_length(json_object_object_get(SendLocalList, "localAuthorizationList")) > atoi((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemData))
  12545. {
  12546. DEBUG_WARN("Local list length is over SendLocalListMaxLength.\n");
  12547. strcpy(comfirmstr, UpdateStatusStr[UpdateStatus_Failed]);
  12548. goto end;
  12549. }
  12550. memset(ShmOCPP16Data->SendLocalList.LocalAuthorizationList, 0 , sizeof(struct StructLocalAuthorizationList)*1);
  12551. for(int idx=0;idx<json_object_array_length(json_object_object_get(SendLocalList, "localAuthorizationList"));idx++)
  12552. {
  12553. 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")));
  12554. if(json_object_object_get(json_object_array_get_idx(json_object_object_get(SendLocalList, "localAuthorizationList"), idx), "idTagInfo") != NULL)
  12555. {
  12556. 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")));
  12557. if(json_object_object_get(json_object_object_get(json_object_array_get_idx(json_object_object_get(SendLocalList, "localAuthorizationList"), idx), "idTagInfo"), "expiryDate") != NULL)
  12558. 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")));
  12559. if(json_object_object_get(json_object_object_get(json_object_array_get_idx(json_object_object_get(SendLocalList, "localAuthorizationList"), idx), "idTagInfo"), "parentIdTag") != NULL)
  12560. 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")));
  12561. }
  12562. // Add to db
  12563. if(strcmp((char*)ShmOCPP16Data->SendLocalList.UpdateType, UpdateTypeStr[Full]) == 0)
  12564. {
  12565. //Local list full update
  12566. DEBUG_INFO("Local list full update item: %d, listVer: %d, %s, %s, %s, %s.\n",
  12567. idx,
  12568. ShmOCPP16Data->SendLocalList.ListVersion,
  12569. ShmOCPP16Data->SendLocalList.LocalAuthorizationList[0].IdTag,
  12570. ShmOCPP16Data->SendLocalList.LocalAuthorizationList[0].IdTagInfo.ParentIdTag,
  12571. ShmOCPP16Data->SendLocalList.LocalAuthorizationList[0].IdTagInfo.ExpiryDate,
  12572. ShmOCPP16Data->SendLocalList.LocalAuthorizationList[0].IdTagInfo.Status);
  12573. // update list
  12574. OCPP_addLocalList(ShmOCPP16Data->SendLocalList.ListVersion,
  12575. (char*)ShmOCPP16Data->SendLocalList.LocalAuthorizationList[0].IdTag,
  12576. (char*)ShmOCPP16Data->SendLocalList.LocalAuthorizationList[0].IdTagInfo.ParentIdTag,
  12577. (char*)ShmOCPP16Data->SendLocalList.LocalAuthorizationList[0].IdTagInfo.ExpiryDate,
  12578. (char*)ShmOCPP16Data->SendLocalList.LocalAuthorizationList[0].IdTagInfo.Status);
  12579. }
  12580. else if(strcmp((char*)ShmOCPP16Data->SendLocalList.UpdateType, UpdateTypeStr[Differential]) == 0)
  12581. {
  12582. DEBUG_INFO("Local list diff update item: %d,listVer: %d, %s, %s, %s, %s.\n",
  12583. idx,
  12584. ShmOCPP16Data->SendLocalList.ListVersion,
  12585. ShmOCPP16Data->SendLocalList.LocalAuthorizationList[0].IdTag,
  12586. ShmOCPP16Data->SendLocalList.LocalAuthorizationList[0].IdTagInfo.ParentIdTag,
  12587. ShmOCPP16Data->SendLocalList.LocalAuthorizationList[0].IdTagInfo.ExpiryDate,
  12588. ShmOCPP16Data->SendLocalList.LocalAuthorizationList[0].IdTagInfo.Status);
  12589. OCPP_addLocalList(ShmOCPP16Data->SendLocalList.ListVersion,
  12590. (char*)ShmOCPP16Data->SendLocalList.LocalAuthorizationList[0].IdTag,
  12591. (char*)ShmOCPP16Data->SendLocalList.LocalAuthorizationList[0].IdTagInfo.ParentIdTag,
  12592. (char*)ShmOCPP16Data->SendLocalList.LocalAuthorizationList[0].IdTagInfo.ExpiryDate,
  12593. (char*)ShmOCPP16Data->SendLocalList.LocalAuthorizationList[0].IdTagInfo.Status);
  12594. }
  12595. }
  12596. }
  12597. else
  12598. {
  12599. //Check UpdateType
  12600. if(strcmp((char*)ShmOCPP16Data->SendLocalList.UpdateType, UpdateTypeStr[Full]) == 0)
  12601. {
  12602. //Local list full update
  12603. DEBUG_INFO("If no (empty) localAuthorizationList is given and the updateType is Full, all identifications are removed from the list. \n");
  12604. OCPP_cleanLocalList();
  12605. strcpy(comfirmstr, UpdateStatusStr[UpdateStatus_Accepted]);
  12606. goto end;
  12607. }
  12608. if(strcmp((char*)ShmOCPP16Data->SendLocalList.UpdateType, UpdateTypeStr[Differential]) == 0)
  12609. {
  12610. //Local list different update
  12611. DEBUG_INFO("Requesting a Differential update without (empty) localAuthorizationList will have no effect on the list\n");
  12612. strcpy(comfirmstr, UpdateStatusStr[UpdateStatus_Accepted]);
  12613. goto end;
  12614. }
  12615. }
  12616. result = PASS;
  12617. }
  12618. strcpy(comfirmstr, UpdateStatusStr[UpdateStatus_Accepted]);
  12619. end:
  12620. json_object_put(SendLocalList);
  12621. sendSendLocalListConfirmation(uuid, comfirmstr);
  12622. return result;
  12623. }
  12624. int handleSetChargingProfileRequest(char *uuid, char *payload)
  12625. {
  12626. mtrace();
  12627. int result = FAIL;
  12628. struct StructSetChargingProfile SetProfileReq = {0};
  12629. int tempchargingProfileIdInt;
  12630. int tempstackLevelInt;
  12631. int chargingSchedulePeriodCount = 0;
  12632. char comfirmstr[20]={0};
  12633. char tempfile[] = "/Storage/OCPP/SetChargingProfiletemp.json";
  12634. char rmFileCmd[128]={0};
  12635. int profileQuantity = 0;
  12636. int replaceableProfileCnt = 0;
  12637. json_object *SetChargingProfile;
  12638. DEBUG_INFO("handleSetChargingProfileRequest\n");
  12639. SetChargingProfile = json_tokener_parse(payload);
  12640. if(!is_error(SetChargingProfile))
  12641. {
  12642. if(json_object_object_get(SetChargingProfile, "connectorId") != NULL)
  12643. {
  12644. SetProfileReq.ConnectorId = json_object_get_int(json_object_object_get(SetChargingProfile, "connectorId"));
  12645. }
  12646. if(json_object_object_get(SetChargingProfile, "csChargingProfiles") != NULL)
  12647. {
  12648. if(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingProfileId") != NULL)
  12649. {
  12650. SetProfileReq.ChargingProfile.ChargingProfileId = json_object_get_int(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingProfileId"));
  12651. }
  12652. else
  12653. {
  12654. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  12655. DEBUG_WARN("Cannot find chargingProfileId field.");
  12656. goto end;
  12657. }
  12658. if(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "stackLevel") != NULL)
  12659. {
  12660. SetProfileReq.ChargingProfile.StackLevel = json_object_get_int(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "stackLevel"));
  12661. }
  12662. else
  12663. {
  12664. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  12665. DEBUG_WARN("Cannot find stackLevel field.");
  12666. goto end;
  12667. }
  12668. if(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingProfilePurpose") != NULL)
  12669. {
  12670. strcpy((char*)SetProfileReq.ChargingProfile.ChargingProfilePurpose, json_object_get_string(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingProfilePurpose")));
  12671. }
  12672. else
  12673. {
  12674. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  12675. DEBUG_WARN("Cannot find chargingProfilePurpose field.");
  12676. goto end;
  12677. }
  12678. if(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingProfileKind") != NULL)
  12679. {
  12680. strcpy((char*)SetProfileReq.ChargingProfile.ChargingProfileKind, json_object_get_string(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingProfileKind")));
  12681. }
  12682. else
  12683. {
  12684. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  12685. DEBUG_WARN("Cannot find chargingProfileKind field.");
  12686. goto end;
  12687. }
  12688. if(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "transactionId") != NULL)
  12689. {
  12690. SetProfileReq.ChargingProfile.TransactionId = json_object_get_int(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "transactionId"));
  12691. }
  12692. if(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "recurrencyKind") != NULL)
  12693. {
  12694. strcpy((char*)SetProfileReq.ChargingProfile.RecurrencyKind, json_object_get_string(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "recurrencyKind")));
  12695. }
  12696. if(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "validFrom") != NULL)
  12697. {
  12698. strcpy((char*)SetProfileReq.ChargingProfile.ValidFrom, json_object_get_string(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "validFrom")));
  12699. }
  12700. if(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "validTo") != NULL)
  12701. {
  12702. strcpy((char*)SetProfileReq.ChargingProfile.ValidTo, json_object_get_string(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "validTo")));
  12703. }
  12704. if(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingSchedule") != NULL)
  12705. {
  12706. if(json_object_object_get(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingSchedule"), "chargingRateUnit") != NULL)
  12707. {
  12708. 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")));
  12709. }
  12710. else
  12711. {
  12712. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  12713. DEBUG_WARN("Cannot find chargingRateUnit field.");
  12714. goto end;
  12715. }
  12716. if(json_object_object_get(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingSchedule"), "duration") != NULL)
  12717. {
  12718. SetProfileReq.ChargingProfile.ChargingSchedule.Duration = json_object_get_int(json_object_object_get(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingSchedule"), "duration"));
  12719. }
  12720. if(json_object_object_get(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingSchedule"), "minChargingRate") != NULL)
  12721. {
  12722. SetProfileReq.ChargingProfile.ChargingSchedule.MinChargingRate = json_object_get_double(json_object_object_get(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingSchedule"), "minChargingRate"));
  12723. }
  12724. if(json_object_object_get(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingSchedule"), "startSchedule") != NULL)
  12725. {
  12726. 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")));
  12727. }
  12728. if(json_object_object_get(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod") != NULL)
  12729. {
  12730. chargingSchedulePeriodCount = json_object_array_length(json_object_object_get(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"));
  12731. if(chargingSchedulePeriodCount <= 10)
  12732. {
  12733. 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++)
  12734. {
  12735. 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)
  12736. {
  12737. 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"));
  12738. }
  12739. else
  12740. {
  12741. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  12742. DEBUG_WARN("Cannot find startPeriod field.");
  12743. goto end;
  12744. }
  12745. 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)
  12746. {
  12747. 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"));
  12748. }
  12749. else
  12750. {
  12751. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  12752. DEBUG_WARN("Cannot find limit field.");
  12753. goto end;
  12754. }
  12755. 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)
  12756. {
  12757. 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"));
  12758. }
  12759. }
  12760. }
  12761. }
  12762. else
  12763. {
  12764. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  12765. DEBUG_WARN("Cannot find chargingSchedulePeriod field.");
  12766. goto end;
  12767. }
  12768. }
  12769. else
  12770. {
  12771. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  12772. DEBUG_WARN("Cannot find chargingSchedule field.");
  12773. goto end;
  12774. }
  12775. }
  12776. }
  12777. // Profile periods quantity check
  12778. if( chargingSchedulePeriodCount > atoi((const char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemData))
  12779. {
  12780. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  12781. DEBUG_WARN("Profile period is over limit %s. \n", ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemData);
  12782. goto end;
  12783. }
  12784. // Check invalid limit
  12785. if((strcmp((char*)SetProfileReq.ChargingProfile.ChargingProfilePurpose, ChargingProfilePurposeTypeStr[ChargePointMaxProfile]) != 0) ||
  12786. ((strcmp((char*)SetProfileReq.ChargingProfile.ChargingProfilePurpose, ChargingProfilePurposeTypeStr[ChargePointMaxProfile]) == 0) && (ShmSysConfigAndInfo->SysConfig.isEnableLocalPowerSharing != 1)))
  12787. {
  12788. if(ShmSysConfigAndInfo->SysConfig.ModelName[0] == 'A')
  12789. {
  12790. for(uint8_t idxPeriod=0;idxPeriod<chargingSchedulePeriodCount;idxPeriod++)
  12791. {
  12792. 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)))) ||
  12793. (SetProfileReq.ChargingProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit > (SetProfileReq.ChargingProfile.ChargingSchedule.ChargingRateUnit[0]=='W'?modelnameInfo.ratedPower:ShmSysConfigAndInfo->SysConfig.RatingCurrent)))
  12794. {
  12795. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  12796. DEBUG_WARN("Profile period-%02d is invalid limit: %.2f %s with phase %d.\n", idxPeriod,
  12797. SetProfileReq.ChargingProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit,
  12798. SetProfileReq.ChargingProfile.ChargingSchedule.ChargingRateUnit,
  12799. (SetProfileReq.ChargingProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases==0?3:SetProfileReq.ChargingProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases));
  12800. goto end;
  12801. }
  12802. }
  12803. }
  12804. else
  12805. {
  12806. for(uint8_t idxPeriod=0;idxPeriod<chargingSchedulePeriodCount;idxPeriod++)
  12807. {
  12808. 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) ||
  12809. (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)))
  12810. {
  12811. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  12812. DEBUG_WARN("Profile period-%02d is invalid limit: %.2f %s with phase %d.\n", idxPeriod,
  12813. SetProfileReq.ChargingProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit,
  12814. SetProfileReq.ChargingProfile.ChargingSchedule.ChargingRateUnit,
  12815. (SetProfileReq.ChargingProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases==0?3:SetProfileReq.ChargingProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases));
  12816. goto end;
  12817. }
  12818. }
  12819. }
  12820. }
  12821. // Profile purpose info check
  12822. if(strcmp((char*)SetProfileReq.ChargingProfile.ChargingProfilePurpose, ChargingProfilePurposeTypeStr[ChargePointMaxProfile]) == 0)
  12823. {
  12824. FILE *fp;
  12825. DEBUG_INFO("Profile purpose is ChargePointMaxProfile.\n");
  12826. if(SetProfileReq.ConnectorId != 0)
  12827. {
  12828. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  12829. DEBUG_WARN("Profile connector id is not 0.\n");
  12830. goto end;
  12831. }
  12832. fp = fopen(ChargePointMaxProfile_JSON, "r");
  12833. if (!fp)
  12834. {
  12835. DEBUG_INFO("%s does not create.\n", ChargePointMaxProfile_JSON);
  12836. fp = fopen(ChargePointMaxProfile_JSON, "w+");
  12837. }
  12838. else
  12839. {
  12840. char *line = NULL;
  12841. size_t len = 0;
  12842. while(getline(&line, &len, fp) != -1)
  12843. {
  12844. json_object *obj = NULL;
  12845. obj = json_tokener_parse(line);
  12846. if(is_error(obj))
  12847. {
  12848. DEBUG_ERROR("Parse txProfile from file error.\n");
  12849. }
  12850. else
  12851. {
  12852. if((json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileId")) != SetProfileReq.ChargingProfile.ChargingProfileId) &&
  12853. (json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "stackLevel")) != SetProfileReq.ChargingProfile.StackLevel))
  12854. {
  12855. profileQuantity += 1;
  12856. }
  12857. else
  12858. replaceableProfileCnt += 1;
  12859. }
  12860. }
  12861. }
  12862. fclose(fp);
  12863. }
  12864. else if(strcmp((char*)SetProfileReq.ChargingProfile.ChargingProfilePurpose, ChargingProfilePurposeTypeStr[TxDefaultProfile]) == 0)
  12865. {
  12866. FILE *fp;
  12867. char filename[128]={0};
  12868. int tmpProfileQuantity;
  12869. DEBUG_INFO("Profile purpose is TxDefaultProfile.\n");
  12870. if((SetProfileReq.ConnectorId != 0) && (SetProfileReq.ConnectorId > gunTotalNumber))
  12871. {
  12872. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  12873. DEBUG_WARN("Profile connector id is over max gun number.\n");
  12874. goto end;
  12875. }
  12876. if(SetProfileReq.ConnectorId == 0)
  12877. {
  12878. for(int idxCon=1;idxCon<=gunTotalNumber;idxCon++)
  12879. {
  12880. tmpProfileQuantity = 0;
  12881. memset(filename, 0, ARRAY_SIZE(filename));
  12882. sprintf(filename, "/Storage/OCPP/TxDefaultProfile_%d.json", idxCon);
  12883. fp = fopen(filename, "r");
  12884. if (!fp)
  12885. {
  12886. DEBUG_INFO("%s does not create.\n", filename);
  12887. fp = fopen(filename, "w+");
  12888. }
  12889. else
  12890. {
  12891. char *line = NULL;
  12892. size_t len = 0;
  12893. while(getline(&line, &len, fp) != -1)
  12894. {
  12895. json_object *obj = NULL;
  12896. obj = json_tokener_parse(line);
  12897. if(is_error(obj))
  12898. {
  12899. DEBUG_ERROR("Parse txProfile from file error.\n");
  12900. }
  12901. else
  12902. {
  12903. if((json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileId")) != SetProfileReq.ChargingProfile.ChargingProfileId) &&
  12904. (json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "stackLevel")) != SetProfileReq.ChargingProfile.StackLevel))
  12905. {
  12906. tmpProfileQuantity += 1;
  12907. }
  12908. else
  12909. replaceableProfileCnt += 1;
  12910. }
  12911. }
  12912. }
  12913. fclose(fp);
  12914. profileQuantity = (profileQuantity < tmpProfileQuantity) ? tmpProfileQuantity : profileQuantity;
  12915. }
  12916. }
  12917. else
  12918. {
  12919. memset(filename, 0, ARRAY_SIZE(filename));
  12920. sprintf(filename, "/Storage/OCPP/TxDefaultProfile_%d.json", SetProfileReq.ConnectorId);
  12921. fp = fopen(filename, "r");
  12922. if (!fp)
  12923. {
  12924. DEBUG_INFO("%s does not create.\n", filename);
  12925. fp = fopen(filename, "w+");
  12926. }
  12927. else
  12928. {
  12929. char *line = NULL;
  12930. size_t len = 0;
  12931. while(getline(&line, &len, fp) != -1)
  12932. {
  12933. json_object *obj = NULL;
  12934. obj = json_tokener_parse(line);
  12935. if(is_error(obj))
  12936. {
  12937. DEBUG_ERROR("Parse txProfile from file error.\n");
  12938. }
  12939. else
  12940. {
  12941. if((json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileId")) != SetProfileReq.ChargingProfile.ChargingProfileId) &&
  12942. (json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "stackLevel")) != SetProfileReq.ChargingProfile.StackLevel))
  12943. {
  12944. profileQuantity += 1;
  12945. }
  12946. else
  12947. replaceableProfileCnt += 1;
  12948. }
  12949. }
  12950. }
  12951. fclose(fp);
  12952. }
  12953. }
  12954. else if(strcmp((char*)SetProfileReq.ChargingProfile.ChargingProfilePurpose, ChargingProfilePurposeTypeStr[TxProfile]) == 0)
  12955. {
  12956. int isMatchTransactiodId= FALSE;
  12957. FILE *fp;
  12958. char filename[128]={0};
  12959. DEBUG_INFO("Profile purposeStr is TxProfile.\n");
  12960. //---TxProfile SHALL only be set at Charge Point ConnectorId > 0. ---//
  12961. if(SetProfileReq.ConnectorId == 0)
  12962. {
  12963. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  12964. DEBUG_WARN("Profile connector id is 0.\n");
  12965. goto end;
  12966. }
  12967. int tempIndex = 0;
  12968. //check Transaction active
  12969. if(gunType[SetProfileReq.ConnectorId -1] == GUN_TYPE_CHAdeMO)
  12970. {
  12971. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  12972. {
  12973. tempIndex = (((SetProfileReq.ConnectorId -1)==2) ? 1: 0);
  12974. }
  12975. else
  12976. {
  12977. tempIndex = SetProfileReq.ConnectorId -1;
  12978. }
  12979. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  12980. {
  12981. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  12982. {
  12983. if((SYS_MODE_PREPARING <= ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus) && (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus <= SYS_MODE_TERMINATING)) // S_CHARGING
  12984. {
  12985. if(SetProfileReq.ChargingProfile.TransactionId == ShmOCPP16Data->StartTransaction[SetProfileReq.ConnectorId -1].ResponseTransactionId)
  12986. {
  12987. isMatchTransactiodId = TRUE;
  12988. break;
  12989. }
  12990. }
  12991. }
  12992. }
  12993. }
  12994. else if(gunType[SetProfileReq.ConnectorId -1] == GUN_TYPE_CCS)
  12995. {
  12996. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  12997. {
  12998. tempIndex = (((SetProfileReq.ConnectorId -1)==2) ? 1: 0);
  12999. }
  13000. else
  13001. {
  13002. tempIndex = SetProfileReq.ConnectorId -1;
  13003. }
  13004. for (int index = 0; index < CCS_QUANTITY; index++)
  13005. {
  13006. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  13007. {
  13008. if(((SYS_MODE_PREPARING <= ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus) && (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus <= SYS_MODE_TERMINATING)) ||
  13009. ((SYS_MODE_CCS_PRECHARGE_STEP0 <= ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus) && (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus <= SYS_MODE_CCS_PRECHARGE_STEP1))) // S_CHARGING
  13010. {
  13011. if(SetProfileReq.ChargingProfile.TransactionId == ShmOCPP16Data->StartTransaction[SetProfileReq.ConnectorId -1].ResponseTransactionId)
  13012. {
  13013. isMatchTransactiodId = TRUE;
  13014. break;
  13015. }
  13016. }
  13017. }
  13018. }
  13019. }
  13020. else if(gunType[SetProfileReq.ConnectorId -1] == GUN_TYPE_GBT)
  13021. {
  13022. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  13023. {
  13024. tempIndex = (((SetProfileReq.ConnectorId -1)==2) ? 1: 0);
  13025. }
  13026. else
  13027. {
  13028. tempIndex = SetProfileReq.ConnectorId -1;
  13029. }
  13030. for (int index = 0; index < GB_QUANTITY; index++)
  13031. {
  13032. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  13033. {
  13034. if((SYS_MODE_PREPARING <= ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus) && (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus <= SYS_MODE_TERMINATING)) // S_CHARGING
  13035. {
  13036. if(SetProfileReq.ChargingProfile.TransactionId == ShmOCPP16Data->StartTransaction[SetProfileReq.ConnectorId -1].ResponseTransactionId)
  13037. {
  13038. isMatchTransactiodId = TRUE;
  13039. break;
  13040. }
  13041. }
  13042. }
  13043. }
  13044. }
  13045. else if(gunType[SetProfileReq.ConnectorId -1] == GUN_TYPE_DO)
  13046. {
  13047. tempIndex = SetProfileReq.ConnectorId -1;
  13048. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  13049. {
  13050. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  13051. {
  13052. if(((SYS_MODE_PREPARING <= ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus) && (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus <= SYS_MODE_TERMINATING)) ||
  13053. ((SYS_MODE_CCS_PRECHARGE_STEP0 <= ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus) && (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus <= SYS_MODE_CCS_PRECHARGE_STEP1))) // S_CHARGING
  13054. {
  13055. if(SetProfileReq.ChargingProfile.TransactionId == ShmOCPP16Data->StartTransaction[SetProfileReq.ConnectorId -1].ResponseTransactionId)
  13056. {
  13057. isMatchTransactiodId = TRUE;
  13058. break;
  13059. }
  13060. }
  13061. }
  13062. }
  13063. }
  13064. else
  13065. {
  13066. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D') // 'D' means DC
  13067. {
  13068. tempIndex = 2;
  13069. }
  13070. else
  13071. {
  13072. tempIndex = (SetProfileReq.ConnectorId -1);
  13073. }
  13074. for (int index = 0; index < AC_QUANTITY; index++)
  13075. {
  13076. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  13077. {
  13078. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_TERMINATING)) // S_CHARGING
  13079. {
  13080. if(SetProfileReq.ChargingProfile.TransactionId == ShmOCPP16Data->StartTransaction[SetProfileReq.ConnectorId -1].ResponseTransactionId)
  13081. {
  13082. isMatchTransactiodId = TRUE;
  13083. break;
  13084. }
  13085. }
  13086. }
  13087. }
  13088. }
  13089. //check Transaction active
  13090. if(isMatchTransactiodId == FALSE)
  13091. {
  13092. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  13093. DEBUG_WARN("Tx profile transaction id is not match.\n");
  13094. goto end;
  13095. }
  13096. if((SetProfileReq.ConnectorId != 0) && (SetProfileReq.ConnectorId > gunTotalNumber))
  13097. {
  13098. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  13099. DEBUG_WARN("Connector id is over max gun number.\n");
  13100. goto end;
  13101. }
  13102. sprintf(filename, "/Storage/OCPP/TxProfile_%d.json", SetProfileReq.ConnectorId);
  13103. fp = fopen(filename, "r");
  13104. if (!fp)
  13105. {
  13106. DEBUG_INFO("%s does not create.\n", filename);
  13107. fp = fopen(filename, "w+");
  13108. }
  13109. else
  13110. {
  13111. char *line = NULL;
  13112. size_t len = 0;
  13113. while(getline(&line, &len, fp) != -1)
  13114. {
  13115. json_object *obj = NULL;
  13116. obj = json_tokener_parse(line);
  13117. if(is_error(obj))
  13118. {
  13119. DEBUG_ERROR("Parse txProfile from file error.\n");
  13120. }
  13121. else
  13122. {
  13123. if((json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileId")) != SetProfileReq.ChargingProfile.ChargingProfileId) &&
  13124. (json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "stackLevel")) != SetProfileReq.ChargingProfile.StackLevel))
  13125. {
  13126. profileQuantity += 1;
  13127. }
  13128. else
  13129. replaceableProfileCnt += 1;
  13130. }
  13131. }
  13132. }
  13133. fclose(fp);
  13134. }
  13135. // Check ChargeProfileMaxStackLevel
  13136. DEBUG_INFO("%s profile quantity: %d\n", SetProfileReq.ChargingProfile.ChargingProfilePurpose, profileQuantity);
  13137. if(profileQuantity >= atoi((const char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemData))
  13138. {
  13139. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  13140. DEBUG_WARN("Purpose profile quantify is over stack limit %s.\n", ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemData);
  13141. goto end;
  13142. }
  13143. //------------------------------Start: Check Configuration Key "MaxChargingProfilesInstalled" Logic---------------------------------------//
  13144. {
  13145. FILE *fp;
  13146. char dataLine[4096]={0};
  13147. char fnametemp[128]={0};
  13148. int tmpProfileQuantity;
  13149. //Check ChargePointMaxProfile.json exit
  13150. profileQuantity = 0;
  13151. if((access("/Storage/OCPP/ChargePointMaxProfile.json",F_OK))!=-1)
  13152. {
  13153. fp = fopen("/Storage/OCPP/ChargePointMaxProfile.json", "r");
  13154. //Check Charging Profile Count
  13155. tmpProfileQuantity = 0;
  13156. while(fscanf(fp, "%s", dataLine) != EOF)
  13157. {
  13158. if(strstr(dataLine, "chargingProfileId")!= NULL)
  13159. {
  13160. profileQuantity += 1;
  13161. tmpProfileQuantity += 1;
  13162. }
  13163. memset(dataLine, 0, ARRAY_SIZE(dataLine));
  13164. }
  13165. fclose(fp);
  13166. DEBUG_INFO("ChargePointMaxProfile.json has %d charging Profile\n", tmpProfileQuantity);
  13167. }
  13168. //Check TxDefaultProfile_%d.json
  13169. for(int idxCon=1; idxCon <= gunTotalNumber; idxCon++)
  13170. {
  13171. memset(fnametemp, 0, ARRAY_SIZE(fnametemp));
  13172. sprintf(fnametemp, "/Storage/OCPP/TxDefaultProfile_%d.json", idxCon);
  13173. if((access(fnametemp,F_OK))!=-1)
  13174. {
  13175. fp = fopen(fnametemp, "r");
  13176. //Check Charging Profile Count
  13177. tmpProfileQuantity = 0;
  13178. while(fscanf(fp, "%s", dataLine) != EOF)
  13179. {
  13180. //DEBUG_INFO("word=%s\n",word);
  13181. if(strstr(dataLine, "chargingProfileId")!= NULL)
  13182. {
  13183. profileQuantity += 1;
  13184. tmpProfileQuantity += 1;
  13185. }
  13186. memset(dataLine, 0, ARRAY_SIZE(dataLine));
  13187. }
  13188. fclose(fp);
  13189. DEBUG_INFO("%s has %d charging Profile\n",fnametemp, tmpProfileQuantity);
  13190. }
  13191. }
  13192. //Check TxProfile_%d.json
  13193. for(int idxCon=1; idxCon <= gunTotalNumber; idxCon++)
  13194. {
  13195. memset(fnametemp, 0, ARRAY_SIZE(fnametemp));
  13196. sprintf(fnametemp, "/Storage/OCPP/TxProfile_%d.json", idxCon);
  13197. if((access(fnametemp,F_OK))!=-1)
  13198. {
  13199. fp = fopen(fnametemp, "r");
  13200. //Check Charging Profile Count
  13201. tmpProfileQuantity = 0;
  13202. while(fscanf(fp, "%s", dataLine) != EOF)
  13203. {
  13204. if(strstr(dataLine, "chargingProfileId")!= NULL)
  13205. {
  13206. profileQuantity += 1;
  13207. tmpProfileQuantity += 1;
  13208. }
  13209. memset(dataLine, 0, ARRAY_SIZE(dataLine));
  13210. }
  13211. fclose(fp);
  13212. DEBUG_INFO("%s has %d charging Profile\n",fnametemp, tmpProfileQuantity);
  13213. }
  13214. }
  13215. DEBUG_INFO("All purpose profile quantity: %d\n", profileQuantity);
  13216. DEBUG_INFO("Replaceable profile quantity: %d\n", replaceableProfileCnt);
  13217. // To check total Profile quantity
  13218. if((SetProfileReq.ConnectorId > 0) || (strcmp((char*)SetProfileReq.ChargingProfile.ChargingProfilePurpose, ChargingProfilePurposeTypeStr[ChargePointMaxProfile]) == 0))
  13219. {
  13220. if((profileQuantity-replaceableProfileCnt) >= atoi((const char*)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemData))
  13221. {
  13222. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected]);
  13223. DEBUG_WARN("Total profile quantify is over installed limit %s.\n", ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemData);
  13224. goto end;
  13225. }
  13226. }
  13227. else
  13228. {
  13229. if((profileQuantity+gunTotalNumber-replaceableProfileCnt) > atoi((const char*)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemData))
  13230. {
  13231. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected]);
  13232. DEBUG_WARN("Total profile quantify is over installed limit %s.\n", ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemData);
  13233. goto end;
  13234. }
  13235. }
  13236. }
  13237. //------------------------------End: Check Configuration Key "MaxChargingProfilesInstalled" Logic---------------------------------------//
  13238. //**********************************Write to File********************************************************/
  13239. {
  13240. FILE *infile;
  13241. FILE *outfile;
  13242. char dataLine[4096]={0};
  13243. char filename[128]={0};
  13244. int chkChar=0;
  13245. for(int idxCon=1; idxCon <= (SetProfileReq.ConnectorId==0?gunTotalNumber:1); idxCon++)
  13246. {
  13247. if(strcmp((char*)SetProfileReq.ChargingProfile.ChargingProfilePurpose, ChargingProfilePurposeTypeStr[ChargePointMaxProfile]) == 0)
  13248. {
  13249. sprintf(filename, "%s", ChargePointMaxProfile_JSON);
  13250. }
  13251. else if(strcmp((char*)SetProfileReq.ChargingProfile.ChargingProfilePurpose, ChargingProfilePurposeTypeStr[TxDefaultProfile]) == 0)
  13252. {
  13253. if(SetProfileReq.ConnectorId==0)
  13254. sprintf(filename, "/Storage/OCPP/TxDefaultProfile_%d.json", idxCon);
  13255. else
  13256. sprintf(filename, "/Storage/OCPP/TxDefaultProfile_%d.json", SetProfileReq.ConnectorId);
  13257. }
  13258. else
  13259. {
  13260. sprintf(filename, "/Storage/OCPP/TxProfile_%d.json", SetProfileReq.ConnectorId);
  13261. }
  13262. infile = fopen (filename, "r");
  13263. outfile = fopen (tempfile, "w");
  13264. chkChar = fgetc(infile);
  13265. rewind(infile);
  13266. if(chkChar == EOF)
  13267. {
  13268. // Profile is empty
  13269. if((strcmp((char*)SetProfileReq.ChargingProfile.ChargingProfilePurpose, ChargingProfilePurposeTypeStr[TxDefaultProfile]) == 0) && (SetProfileReq.ConnectorId==0))
  13270. json_object_object_add(SetChargingProfile, "connectorId", json_object_new_int(idxCon));
  13271. fprintf(outfile,"%s\n",json_object_to_json_string_ext(SetChargingProfile, JSON_C_TO_STRING_PLAIN));
  13272. fclose(infile);
  13273. fclose(outfile);
  13274. sprintf(rmFileCmd,"rm -f %s",filename);
  13275. system(rmFileCmd);
  13276. rename(tempfile, filename);
  13277. }
  13278. else
  13279. {
  13280. // Profile is not empty
  13281. int ChargingProfileAdded = FALSE;
  13282. while (fgets(dataLine, ARRAY_SIZE(dataLine), infile) != NULL)
  13283. {
  13284. dataLine[strlen(dataLine) - 1] = '\0'; // eat the newline fgets() stores
  13285. json_object *tmpChargingProfile;
  13286. tmpChargingProfile = json_tokener_parse(dataLine);
  13287. if(!is_error(SetChargingProfile))
  13288. {
  13289. if(json_object_object_get(tmpChargingProfile, "csChargingProfiles") != NULL)
  13290. {
  13291. if(json_object_object_get(json_object_object_get(tmpChargingProfile, "csChargingProfiles"), "chargingProfileId") != NULL)
  13292. {
  13293. tempchargingProfileIdInt = json_object_get_int(json_object_object_get(json_object_object_get(tmpChargingProfile, "csChargingProfiles"), "chargingProfileId"));
  13294. }
  13295. if(json_object_object_get(json_object_object_get(tmpChargingProfile, "csChargingProfiles"), "stackLevel") != NULL)
  13296. {
  13297. tempstackLevelInt = json_object_get_int(json_object_object_get(json_object_object_get(tmpChargingProfile, "csChargingProfiles"), "stackLevel"));
  13298. }
  13299. }
  13300. }
  13301. json_object_put(tmpChargingProfile);
  13302. if((tempchargingProfileIdInt == SetProfileReq.ChargingProfile.ChargingProfileId))
  13303. {
  13304. if(ChargingProfileAdded == FALSE)
  13305. {
  13306. if((strcmp((char*)SetProfileReq.ChargingProfile.ChargingProfilePurpose, ChargingProfilePurposeTypeStr[TxDefaultProfile]) == 0) && (SetProfileReq.ConnectorId==0))
  13307. json_object_object_add(SetChargingProfile, "connectorId", json_object_new_int(idxCon));
  13308. fprintf(outfile,"%s\n",json_object_to_json_string_ext(SetChargingProfile, JSON_C_TO_STRING_PLAIN));
  13309. ChargingProfileAdded = TRUE;
  13310. }
  13311. }
  13312. else if(tempstackLevelInt == SetProfileReq.ChargingProfile.StackLevel)
  13313. {
  13314. if(ChargingProfileAdded == FALSE)
  13315. {
  13316. if((strcmp((char*)SetProfileReq.ChargingProfile.ChargingProfilePurpose, ChargingProfilePurposeTypeStr[TxDefaultProfile]) == 0) && (SetProfileReq.ConnectorId==0))
  13317. json_object_object_add(SetChargingProfile, "connectorId", json_object_new_int(idxCon));
  13318. fprintf(outfile,"%s\n",json_object_to_json_string_ext(SetChargingProfile, JSON_C_TO_STRING_PLAIN));
  13319. ChargingProfileAdded = TRUE;
  13320. }
  13321. }
  13322. else
  13323. {
  13324. fprintf(outfile,"%s\n",dataLine);
  13325. if(ChargingProfileAdded == FALSE)
  13326. {
  13327. if((strcmp((char*)SetProfileReq.ChargingProfile.ChargingProfilePurpose, ChargingProfilePurposeTypeStr[TxDefaultProfile]) == 0) && (SetProfileReq.ConnectorId==0))
  13328. json_object_object_add(SetChargingProfile, "connectorId", json_object_new_int(idxCon));
  13329. fprintf(outfile,"%s\n",json_object_to_json_string_ext(SetChargingProfile, JSON_C_TO_STRING_PLAIN));
  13330. ChargingProfileAdded = TRUE;
  13331. }
  13332. }
  13333. } // end of while loop
  13334. fclose(infile);
  13335. fclose(outfile);
  13336. sprintf(rmFileCmd,"rm -f %s",filename);
  13337. system(rmFileCmd);
  13338. rename(tempfile, filename);
  13339. }
  13340. }
  13341. sleep(1);
  13342. result = TRUE;
  13343. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Accepted] );
  13344. }
  13345. end:
  13346. json_object_put(SetChargingProfile);
  13347. if(strcmp(comfirmstr, ChargingProfileStatusStr[ChargingProfileStatus_Accepted]) == 0)
  13348. {
  13349. if(SetProfileReq.ConnectorId == 0)
  13350. {
  13351. for(uint8_t idx=0;idx<gunTotalNumber;idx++)
  13352. {
  13353. checkCompositeSchedule((idx+1), 86400, &ShmOCPP16Data->SmartChargingProfile[idx], TRUE);
  13354. }
  13355. }
  13356. else
  13357. checkCompositeSchedule(SetProfileReq.ConnectorId, 86400, &ShmOCPP16Data->SmartChargingProfile[SetProfileReq.ConnectorId-1], TRUE);
  13358. }
  13359. sendSetChargingProfileConfirmation(uuid, comfirmstr);
  13360. system("/bin/fsync -d /dev/mtdblock13;/bin/sync &");
  13361. return result;
  13362. }
  13363. int handleTriggerMessageRequest(char *uuid, char *payload)
  13364. {
  13365. mtrace();
  13366. int result = FAIL;
  13367. int connectorIdIsNULL = FALSE;
  13368. int connectorIdInt =0;
  13369. char sstr[40]={0},sstrtemp[100]={ 0 };
  13370. char requestedMessagestr[40]={0};
  13371. char comfirmstr[20]={0};
  13372. int c = 0;
  13373. char *loc;
  13374. DEBUG_INFO("handleTriggerMessageRequest\n");
  13375. //[2,"266e23f4-27a4-41cf-84cb-aadf56b9523f","TriggerMessage",{"requestedMessage":"DiagnosticsStatusNotification","connectorId":1}]
  13376. strcpy(sstrtemp, stringtrimspace(payload));
  13377. c = 0;
  13378. loc = strstr(sstrtemp, "requestedMessage");
  13379. while (loc[3+strlen("requestedMessage")+c] != '\"')
  13380. {
  13381. sstr[c] = loc[3+strlen("requestedMessage")+c];
  13382. c++;
  13383. }
  13384. sstr[c] = '\0';
  13385. strcpy(requestedMessagestr, sstr);
  13386. c = 0;
  13387. loc = strstr(sstrtemp, "connectorId");
  13388. if(loc == NULL)
  13389. {
  13390. connectorIdIsNULL = TRUE;
  13391. }
  13392. else
  13393. {
  13394. memset(sstr ,0, ARRAY_SIZE(sstr) );
  13395. while ((loc[strlen("connectorId")+2+c] != ',')&&(loc[strlen("connectorId")+2+c] != '}'))
  13396. {
  13397. sstr[c] = loc[strlen("connectorId")+2+c];
  13398. //printf("i=%d sstr=%c\n",c, sstr[c]);
  13399. c++;
  13400. }
  13401. sstr[c] = '\0';
  13402. connectorIdInt = atoi(sstr);
  13403. }
  13404. if((connectorIdIsNULL == TRUE) || ((connectorIdIsNULL == FALSE) && ((connectorIdInt > 0) && (connectorIdInt <= gunTotalNumber /*(CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY)*/ ))) )
  13405. {
  13406. sprintf((char *)ShmOCPP16Data->TriggerMessage[connectorIdInt -1].RequestedMessage, "%s" ,requestedMessagestr);
  13407. ShmOCPP16Data->TriggerMessage[connectorIdInt -1].ConnectorId = connectorIdInt;
  13408. if((strcmp(requestedMessagestr, MessageTriggerStr[FirmwareStatusNotification]) != 0) &&
  13409. (strcmp(requestedMessagestr, MessageTriggerStr[DiagnosticsStatusNotification]) != 0) &&
  13410. (strcmp(requestedMessagestr, MessageTriggerStr[BootNotification]) != 0 ) &&
  13411. (strcmp(requestedMessagestr, MessageTriggerStr[Heartbeat]) != 0) &&
  13412. (strcmp(requestedMessagestr, MessageTriggerStr[MeterValues]) != 0) &&
  13413. (strcmp(requestedMessagestr, MessageTriggerStr[StatusNotification]) != 0 ))
  13414. {
  13415. sprintf(comfirmstr, "%s",TriggerMessageStatusStr[TriggerMessageStatus_NotImplemented] );
  13416. sendTriggerMessageConfirmation(uuid,comfirmstr);
  13417. return TRUE;
  13418. }
  13419. else
  13420. {
  13421. sprintf(comfirmstr, "%s",TriggerMessageStatusStr[TriggerMessageStatus_Accepted] );
  13422. sendTriggerMessageConfirmation(uuid,comfirmstr);
  13423. }
  13424. }
  13425. else if(connectorIdIsNULL == FALSE && ((connectorIdInt <= 0) || (connectorIdInt > gunTotalNumber /*(CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY)*/) ))
  13426. {
  13427. sprintf(comfirmstr, "%s",TriggerMessageStatusStr[TriggerMessageStatus_Rejected] );
  13428. sendTriggerMessageConfirmation(uuid,comfirmstr);
  13429. return TRUE;
  13430. }
  13431. //==========================
  13432. // Trigger message
  13433. //==========================
  13434. if( strcmp(requestedMessagestr, MessageTriggerStr[FirmwareStatusNotification]) == 0)
  13435. {
  13436. if((strlen((char*)ShmOCPP16Data->FirmwareStatusNotification.Status) == 0) ||
  13437. ((FirmwareStatusNotificationStatus != FIRMWARE_STATUS_DOWNLOADING) && (FirmwareStatusNotificationStatus != FIRMWARE_STATUS_DOWNLOADED) && (FirmwareStatusNotificationStatus != FIRMWARE_STATUS_IDLE) && (FirmwareStatusNotificationStatus != FIRMWARE_STATUS_INSTALLING)))
  13438. {
  13439. FirmwareStatusNotificationStatus = FIRMWARE_STATUS_IDLE;
  13440. sprintf((char*)ShmOCPP16Data->FirmwareStatusNotification.Status, "%s", FirmwareStatusStr[FirmwareStatus_Idle]);
  13441. }
  13442. ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationReq = 1;
  13443. }
  13444. else if(strcmp(requestedMessagestr, MessageTriggerStr[DiagnosticsStatusNotification]) == 0 )
  13445. {
  13446. if(strlen((char*)ShmOCPP16Data->DiagnosticsStatusNotification.Status) == 0)
  13447. sprintf((char*)ShmOCPP16Data->DiagnosticsStatusNotification.Status, "%s", DiagnosticsStatusStr[DiagnosticsStatus_Idle]);
  13448. ShmOCPP16Data->SpMsg.bits.DiagnosticsStatusNotificationReq = 1;
  13449. }
  13450. else if(strcmp(requestedMessagestr, MessageTriggerStr[BootNotification]) == 0 )
  13451. {
  13452. //sendBootNotificationRequest();
  13453. server_sign = FALSE;
  13454. }
  13455. else if(strcmp(requestedMessagestr, MessageTriggerStr[Heartbeat]) == 0 )
  13456. {
  13457. refreshStartTimer(&clientTime.Heartbeat);
  13458. clientTime.Heartbeat.tv_sec -= ShmOCPP16Data->BootNotification.ResponseHeartbeatInterval;
  13459. }
  13460. else if (strcmp(requestedMessagestr, MessageTriggerStr[MeterValues]) == 0 )
  13461. {
  13462. if(connectorIdIsNULL == FALSE)
  13463. {
  13464. if((connectorIdInt > 0) && ((connectorIdInt -1) < gunTotalNumber))
  13465. {
  13466. //sendMeterValuesRequest((connectorIdInt -1), ReadingContext_Trigger);
  13467. cpinitateMsg.bits[connectorIdInt -1].TriggerMeterValue = 1;
  13468. }
  13469. }
  13470. else
  13471. {
  13472. for(int idx=0;idx< gunTotalNumber;idx++)
  13473. {
  13474. //sendMeterValuesRequest(idx, ReadingContext_Trigger);
  13475. cpinitateMsg.bits[idx].TriggerMeterValue = 1;
  13476. }
  13477. }
  13478. }
  13479. else if(strcmp(requestedMessagestr, MessageTriggerStr[StatusNotification]) == 0 )
  13480. {
  13481. if(connectorIdIsNULL == FALSE)
  13482. {
  13483. if((connectorIdInt > 0) && ((connectorIdInt-1) < gunTotalNumber))
  13484. {
  13485. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].TriggerMessageReq = 1;
  13486. cpinitateMsg.bits[connectorIdInt-1].TriggerStatusNotificationReq = 1;
  13487. //clientTime.StatusNotification[connectorIdInt-1] = time((time_t*)NULL);
  13488. }
  13489. }
  13490. else
  13491. {
  13492. for(int idx=0;idx< gunTotalNumber;idx++)
  13493. {
  13494. ShmOCPP16Data->CsMsg.bits[idx].TriggerMessageReq = 1;
  13495. cpinitateMsg.bits[idx].TriggerStatusNotificationReq = 1;
  13496. //clientTime.StatusNotification[idx] = time((time_t*)NULL);
  13497. }
  13498. }
  13499. }
  13500. return result;
  13501. }
  13502. int handleUnlockConnectorRequest(char *uuid, char *payload)
  13503. {
  13504. mtrace();
  13505. int result = FAIL;
  13506. int connectorIdInt =0;
  13507. char comfirmstr[20]={0};
  13508. int tempIndex = 0;
  13509. json_object *UnlockConnector;
  13510. //[2,"ba1cbd49-2a76-493a-8f76-fa23e7606532","UnlockConnector",{"connectorId":1}]
  13511. DEBUG_INFO("handleUnlockConnectorRequest ...\n");
  13512. UnlockConnector = json_tokener_parse(payload);
  13513. if(!is_error(UnlockConnector))
  13514. {
  13515. if(json_object_object_get(UnlockConnector, "connectorId") != NULL)
  13516. {
  13517. connectorIdInt = json_object_get_int(json_object_object_get(UnlockConnector, "connectorId"));
  13518. }
  13519. }
  13520. json_object_put(UnlockConnector);
  13521. DEBUG_INFO("Unlock connectorIdInt = %d\n",connectorIdInt);
  13522. if(gunTotalNumber == 0)
  13523. {
  13524. sprintf(comfirmstr, "%s", UnlockStatusStr[UnlockStatus_NotSupported] );
  13525. goto end;
  13526. }
  13527. else if((connectorIdInt > gunTotalNumber/*CHAdeMO_QUANTITY+ CCS_QUANTITY + GB_QUANTITY*/) || (connectorIdInt <= 0))
  13528. {
  13529. //sprintf(comfirmstr, "%s", UnlockStatusStr[UnlockStatus_NotSupported] );
  13530. sprintf(comfirmstr, "%s", UnlockStatusStr[UnlockStatus_NotSupported] );
  13531. goto end;
  13532. }
  13533. else
  13534. {
  13535. //check Transaction active
  13536. if(gunType[connectorIdInt-1] == GUN_TYPE_CHAdeMO)
  13537. {
  13538. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  13539. {
  13540. tempIndex = (((connectorIdInt -1)==2) ? 1: 0);
  13541. }
  13542. else
  13543. {
  13544. tempIndex = connectorIdInt -1;
  13545. }
  13546. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  13547. {
  13548. if ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex ))
  13549. {
  13550. //stop Transaction
  13551. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].UnlockConnectorReq = 1;
  13552. }
  13553. }
  13554. }
  13555. else if(gunType[connectorIdInt-1] == GUN_TYPE_CCS)
  13556. {
  13557. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  13558. {
  13559. tempIndex = (((connectorIdInt -1)==2) ? 1: 0);
  13560. }
  13561. else
  13562. {
  13563. tempIndex = connectorIdInt -1;
  13564. }
  13565. for (int index = 0; index < CCS_QUANTITY; index++)
  13566. {
  13567. if ((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex ))
  13568. {
  13569. //stop Transaction
  13570. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].UnlockConnectorReq = 1;
  13571. }
  13572. }
  13573. }
  13574. else if(gunType[connectorIdInt-1] == GUN_TYPE_GBT)
  13575. {
  13576. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  13577. {
  13578. tempIndex = (((connectorIdInt -1)==2) ? 1: 0);
  13579. }
  13580. else
  13581. {
  13582. tempIndex = connectorIdInt -1;
  13583. }
  13584. for (int index = 0; index < GB_QUANTITY; index++)
  13585. {
  13586. if ((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex ))
  13587. {
  13588. //stop Transaction
  13589. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].UnlockConnectorReq = 1;
  13590. }
  13591. }
  13592. }
  13593. else if(gunType[connectorIdInt-1] == GUN_TYPE_DO)
  13594. {
  13595. tempIndex = connectorIdInt -1;
  13596. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  13597. {
  13598. if ((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex ))
  13599. {
  13600. //stop Transaction
  13601. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].UnlockConnectorReq = 1;
  13602. }
  13603. }
  13604. }
  13605. else
  13606. {
  13607. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  13608. {
  13609. tempIndex = 2;
  13610. }
  13611. else
  13612. {
  13613. tempIndex = connectorIdInt-1;
  13614. }
  13615. for (int index = 0; index < AC_QUANTITY; index++)
  13616. {
  13617. if ((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex ))
  13618. {
  13619. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].UnlockConnectorReq = 1;
  13620. }
  13621. }
  13622. }
  13623. ShmOCPP16Data->UnlockConnector[connectorIdInt-1].ConnectorId = connectorIdInt;
  13624. strcpy((char *)ShmOCPP16Data->UnlockConnector[connectorIdInt-1].guid, uuid);
  13625. result = TRUE;
  13626. return result;
  13627. }
  13628. end:
  13629. //json_object_put(obj); --- remove temporally
  13630. sendUnlockConnectorConfirmation(uuid, comfirmstr);
  13631. return result;
  13632. }
  13633. static char UpdateFirmwarepayloadData[300]={0};
  13634. int handleUpdateFirmwareRequest(char *uuid, char *payload)
  13635. {
  13636. mtrace();
  13637. int result = FAIL;
  13638. pthread_t t;
  13639. sendUpdateFirmwareConfirmation(uuid);
  13640. memset(UpdateFirmwarepayloadData, 0, 300);
  13641. strcpy(UpdateFirmwarepayloadData, stringtrimspace(payload));
  13642. if(!interLock.isUpdateFirmwareGoing)
  13643. {
  13644. interLock.isUpdateFirmwareGoing = 1;
  13645. pthread_create(&t, NULL, UpdateFirmwareProcess, stringtrimspace(payload));
  13646. sleep(1);
  13647. }
  13648. else
  13649. DEBUG_WARN("Other UpdateFirmware request on going.\n");
  13650. ShmOCPP16Data->MsMsg.bits.UpdateFirmwareConf =1;
  13651. return result;
  13652. }
  13653. void *UpdateFirmwareProcess(void *data)
  13654. {
  13655. pthread_detach(pthread_self());
  13656. mtrace();
  13657. int retriesInt =0, retryIntervalInt=0;
  13658. char protocol[10], user[64],password[64],host[128], path[512], ftppath[512],host1[128],path1[512];
  13659. int port=0;
  13660. char locationstr[1024]={0}, retrieveDatestr[36]={0};
  13661. int isSuccess = 0;
  13662. char ftpbuf[1024];
  13663. char temp[1024];
  13664. char * pch;
  13665. DEBUG_INFO("handleUpdateFirmwareRequest ...\n");
  13666. json_object *UpdateFirmware;
  13667. UpdateFirmware = json_tokener_parse(UpdateFirmwarepayloadData);
  13668. if(!is_error(UpdateFirmware))
  13669. {
  13670. // Required data
  13671. if(json_object_object_get(UpdateFirmware, "location") != NULL)
  13672. sprintf((char*)locationstr, "%s", json_object_get_string(json_object_object_get(UpdateFirmware, "location")));
  13673. if(json_object_object_get(UpdateFirmware, "retrieveDate") != NULL)
  13674. sprintf((char*)retrieveDatestr, "%s", json_object_get_string(json_object_object_get(UpdateFirmware, "retrieveDate")));
  13675. // Optional data
  13676. if(json_object_object_get(UpdateFirmware, "retries"))
  13677. {
  13678. retriesInt = json_object_get_int(json_object_object_get(UpdateFirmware, "retries"));
  13679. }
  13680. if(json_object_object_get(UpdateFirmware, "retryInterval"))
  13681. {
  13682. retryIntervalInt = json_object_get_int(json_object_object_get(UpdateFirmware, "retryInterval"));
  13683. }
  13684. }
  13685. json_object_put(UpdateFirmware);
  13686. memset(ftppath, 0, ARRAY_SIZE(ftppath));
  13687. memset(path, 0, ARRAY_SIZE(path));
  13688. // Wait retrieveData
  13689. if(strlen(retrieveDatestr) > 10)
  13690. {
  13691. do
  13692. {
  13693. sleep(1);
  13694. }while(!isOvertNow((uint8_t*)retrieveDatestr));
  13695. }
  13696. // Ready to download
  13697. system("rm -f /mnt/*");
  13698. if(strncmp(locationstr,"http", 4) == 0)
  13699. {
  13700. sscanf(locationstr,"%[^:]:%*2[/]%[^/]/%199[^\n]", protocol, host, path);
  13701. sprintf(ftppath,"/%s", path);
  13702. DEBUG_INFO("locationstr: %s\n", locationstr);
  13703. DEBUG_INFO("protocol: %s\n",protocol);
  13704. DEBUG_INFO("host: %s\n",host);
  13705. DEBUG_INFO("path: %s\n",path);
  13706. DEBUG_INFO("ftppath: %s\n",ftppath);
  13707. int ftppathlen=strlen(ftppath);
  13708. int i=1;
  13709. char filenametemp[50];
  13710. while(i < ftppathlen)
  13711. {
  13712. int len=ftppathlen-i;
  13713. if(ftppath[len]== 47) // '/' ascll code: 47
  13714. {
  13715. DEBUG_INFO("compare '/' all right\n");
  13716. break;
  13717. }
  13718. i=i+1;
  13719. }
  13720. memset(filenametemp, 0, ARRAY_SIZE(filenametemp));
  13721. strncpy(filenametemp, ftppath+(ftppathlen-i+1), i+1);
  13722. filenametemp[i+1] = 0;
  13723. do
  13724. {
  13725. sprintf((char*)ShmOCPP16Data->FirmwareStatusNotification.Status, "%s",FirmwareStatusStr[FirmwareStatus_Downloading]);
  13726. ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationReq = 1;
  13727. sleep(1);
  13728. isSuccess = httpDownLoadFile(host, ftppath, filenametemp, locationstr);
  13729. if(!isSuccess)
  13730. {
  13731. sprintf((char*)ShmOCPP16Data->FirmwareStatusNotification.Status, "%s",FirmwareStatusStr[FirmwareStatus_DownloadFailed]);
  13732. ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationReq = 1;
  13733. if(retriesInt>0)sleep(retryIntervalInt);else sleep(1);
  13734. sprintf((char*)ShmOCPP16Data->FirmwareStatusNotification.Status, "%s",FirmwareStatusStr[FirmwareStatus_Idle]);
  13735. ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationReq = 1;
  13736. }
  13737. else
  13738. {
  13739. sprintf((char*)ShmOCPP16Data->FirmwareStatusNotification.Status, "%s",FirmwareStatusStr[FirmwareStatus_Downloaded]);
  13740. ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationReq = 1;
  13741. }
  13742. retriesInt--;
  13743. }while((isSuccess == 0)&&(retriesInt >= 0));
  13744. }
  13745. else if(strncmp(locationstr,"sftp", 4) == 0) // sftp
  13746. {
  13747. memset(ftpbuf, 0, ARRAY_SIZE(ftpbuf));
  13748. memset(temp, 0, ARRAY_SIZE(temp));
  13749. //DEBUG_INFO("locationstr=%s\n",locationstr);
  13750. strcpy(ftpbuf, locationstr);
  13751. int ftppathlen=strlen(ftpbuf);
  13752. int i=1;
  13753. char filenametemp[50];
  13754. while(i < ftppathlen)
  13755. {
  13756. int len=ftppathlen-i;
  13757. if(ftpbuf[len]== 47) // '/' ascii code: 47
  13758. {
  13759. DEBUG_INFO(" compare '/' all right\n");
  13760. break;
  13761. }
  13762. i=i+1;
  13763. }
  13764. memset(filenametemp, 0, ARRAY_SIZE(filenametemp));
  13765. strncpy(filenametemp, ftpbuf+(ftppathlen-i+1), i+1);
  13766. filenametemp[i+1] = 0;
  13767. strncpy(temp, ftpbuf, ftppathlen-i+1);
  13768. pch=strchr(temp,'@');
  13769. if(pch==NULL)
  13770. {
  13771. sscanf(temp,"%[^:]:%*2[/]%[^:]:%i/%[a-zA-Z0-9._/-]",
  13772. protocol, host, &port, path);
  13773. strcpy(user,"anonymous");
  13774. strcpy(password,"");
  13775. }
  13776. else
  13777. {
  13778. sscanf(temp,"%[^:]:%*2[/]%[^@]@%[^:]:%i/%199[^\n]",
  13779. protocol, user, host, &port, path);
  13780. }
  13781. sscanf(host,"%[^/]%s",host1, path1);
  13782. sprintf(ftppath,"%s:/%s", host,path);
  13783. if(port == 0)
  13784. {
  13785. port = 21;
  13786. }
  13787. do
  13788. {
  13789. sprintf((char*)ShmOCPP16Data->FirmwareStatusNotification.Status, "%s",FirmwareStatusStr[FirmwareStatus_Downloading]);
  13790. ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationReq = 1;
  13791. sleep(1);
  13792. isSuccess = sftpDownLoadFile(host1, user, port, ftppath, filenametemp, locationstr);
  13793. if(!isSuccess)
  13794. {
  13795. //BulldogUtil.sleepMs(interval*1000);
  13796. DEBUG_INFO("Update firmware request and download file fail.\n");
  13797. sprintf((char*)ShmOCPP16Data->FirmwareStatusNotification.Status, "%s",FirmwareStatusStr[FirmwareStatus_DownloadFailed]);
  13798. ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationReq = 1;
  13799. if(retriesInt>0)sleep(retryIntervalInt);else sleep(1);
  13800. sprintf((char*)ShmOCPP16Data->FirmwareStatusNotification.Status, "%s",FirmwareStatusStr[FirmwareStatus_Idle]);
  13801. ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationReq = 1;
  13802. }
  13803. else
  13804. {
  13805. sprintf((char*)ShmOCPP16Data->FirmwareStatusNotification.Status, "%s",FirmwareStatusStr[FirmwareStatus_Downloaded]);
  13806. ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationReq = 1;
  13807. }
  13808. retriesInt--;
  13809. }while((!isSuccess)&&(retriesInt >= 0));
  13810. }
  13811. else if(strncmp(locationstr,"ftp", 3) == 0) // ftp
  13812. {
  13813. memset(ftpbuf, 0, ARRAY_SIZE(ftpbuf));
  13814. memset(temp, 0, ARRAY_SIZE(temp));
  13815. //DEBUG_INFO("locationstr=%s\n",locationstr);
  13816. strcpy(ftpbuf, locationstr/*"ftp://ipc_ui:pht2016@ftp.phihong.com.tw/DC/log/DemoDC1_2018-07-13_185011_PSULog.zip"*/ );
  13817. int ftppathlen=strlen(ftpbuf);
  13818. int i=1;
  13819. char filenametemp[50];
  13820. while(i < ftppathlen)
  13821. {
  13822. int len=ftppathlen-i;
  13823. if(ftpbuf[len]== 47) // '/' ascll code: 47
  13824. {
  13825. DEBUG_INFO(" compare '/' all right\n");
  13826. break;
  13827. }
  13828. i=i+1;
  13829. }
  13830. memset(filenametemp, 0, ARRAY_SIZE(filenametemp));
  13831. strncpy(filenametemp, ftpbuf+(ftppathlen-i+1), i+1);
  13832. filenametemp[i+1] = 0;
  13833. strncpy(temp, ftpbuf, ftppathlen-i+1);
  13834. pch=strchr(temp,'@');
  13835. if(pch==NULL)
  13836. {
  13837. sscanf(temp,"%[^:]:%*2[/]%[^:]:%i/%[a-zA-Z0-9._/-]",
  13838. protocol, host, &port, path);
  13839. strcpy(user,"anonymous");
  13840. strcpy(password,"");
  13841. }
  13842. else
  13843. {
  13844. sscanf(temp,"%[^:]:%*2[/]%[^:]:%[^@]@%[^:]:%i/%199[^\n]",
  13845. protocol, user, password, host, &port, path);
  13846. }
  13847. sscanf(host,"%[^/]%s",host1, path1);
  13848. sprintf(ftppath,"%s", path1);
  13849. //DEBUG_INFO("protocol =%s\n",protocol);
  13850. //DEBUG_INFO("user =%s\n",user);
  13851. //DEBUG_INFO("password =%s\n",password);
  13852. //DEBUG_INFO("host1 =%s\n",host1);
  13853. //DEBUG_INFO("port =%d\n",port);
  13854. //DEBUG_INFO("path1 =%s\n",path1);
  13855. //DEBUG_INFO("ftppath=%s\n",ftppath);
  13856. //ftpFile(host, user, password, port, ftppath, fname);
  13857. //download firmware pthred
  13858. if(port == 0)
  13859. {
  13860. port = 21;
  13861. }
  13862. do
  13863. {
  13864. sprintf((char*)ShmOCPP16Data->FirmwareStatusNotification.Status, "%s",FirmwareStatusStr[FirmwareStatus_Downloading]);
  13865. ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationReq = 1;
  13866. sleep(1);
  13867. isSuccess = ftpDownLoadFile(host1, user, password, port, ftppath, filenametemp, locationstr);
  13868. if(!isSuccess)
  13869. {
  13870. //BulldogUtil.sleepMs(interval*1000);
  13871. DEBUG_INFO("Update firmware request and download file fail.\n");
  13872. sprintf((char*)ShmOCPP16Data->FirmwareStatusNotification.Status, "%s",FirmwareStatusStr[FirmwareStatus_DownloadFailed]);
  13873. ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationReq = 1;
  13874. if(retriesInt>0)sleep(retryIntervalInt);else sleep(1);
  13875. sprintf((char*)ShmOCPP16Data->FirmwareStatusNotification.Status, "%s",FirmwareStatusStr[FirmwareStatus_Idle]);
  13876. ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationReq = 1;
  13877. }
  13878. else
  13879. {
  13880. sprintf((char*)ShmOCPP16Data->FirmwareStatusNotification.Status, "%s",FirmwareStatusStr[FirmwareStatus_Downloaded]);
  13881. ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationReq = 1;
  13882. }
  13883. retriesInt--;
  13884. }while((!isSuccess)&&(retriesInt >= 0));
  13885. }
  13886. else
  13887. {
  13888. sprintf((char*)ShmOCPP16Data->FirmwareStatusNotification.Status, "%s",FirmwareStatusStr[FirmwareStatus_DownloadFailed]);
  13889. ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationReq = 1;
  13890. sleep(1);
  13891. sprintf((char*)ShmOCPP16Data->FirmwareStatusNotification.Status, "%s",FirmwareStatusStr[FirmwareStatus_Idle]);
  13892. ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationReq = 1;
  13893. }
  13894. if(strstr((char*)ShmOCPP16Data->FirmwareStatusNotification.Status, FirmwareStatusStr[FirmwareStatus_Downloaded]) != NULL)ShmOCPP16Data->MsMsg.bits.UpdateFirmwareReq = 1;
  13895. interLock.isUpdateFirmwareGoing = 0;
  13896. pthread_exit(NULL);
  13897. }
  13898. int handleCertificateSignedRequest(char *uuid, char *payload)
  13899. {
  13900. mtrace();
  13901. int result = PASS;
  13902. json_object *CertificateSigned;
  13903. DEBUG_INFO("handleCertificateSignedRequest...\n");
  13904. CertificateSigned = json_tokener_parse(payload);
  13905. if(!is_error(CertificateSigned))
  13906. {
  13907. sprintf((char*)ShmOCPP16Data->CertificateSigned.certificateChain, "%s", json_object_get_string(json_object_object_get(CertificateSigned, "certificateChain")));
  13908. }
  13909. json_object_put(CertificateSigned);
  13910. FILE *fp = fopen("/Storage/OCPP/certCP.crt", "w");
  13911. fprintf(fp, "%s", ShmOCPP16Data->CertificateSigned.certificateChain);
  13912. fclose(fp);
  13913. system("/bin/fsync -d /dev/mtdblock13;/bin/sync &");
  13914. ShmOCPP16Data->MsMsg.bits.CertificateSignedReq = 1;
  13915. sprintf((char*)ShmOCPP16Data->CertificateSigned.Response_status, "Accepted");
  13916. sendCertificateSignedConfirmation(uuid);
  13917. return result;
  13918. }
  13919. int handleDeleteCertificateRequest(char *uuid, char *payload)
  13920. {
  13921. mtrace();
  13922. int result = PASS;
  13923. json_object *DeleteCertificate;
  13924. DEBUG_INFO("handleDeleteCertificateRequest...\n");
  13925. DeleteCertificate = json_tokener_parse(payload);
  13926. if(!is_error(DeleteCertificate))
  13927. {
  13928. sprintf((char*)ShmOCPP16Data->DeleteCertificate.certificateHashData.hashAlgorithm, "%s", json_object_get_string(json_object_object_get(json_object_object_get(DeleteCertificate, "certificateHashData"), "hashAlgorithm")));
  13929. sprintf((char*)ShmOCPP16Data->DeleteCertificate.certificateHashData.issuerNameHash, "%s", json_object_get_string(json_object_object_get(json_object_object_get(DeleteCertificate, "certificateHashData"), "issuerNameHash")));
  13930. sprintf((char*)ShmOCPP16Data->DeleteCertificate.certificateHashData.issuerKeyHash, "%s", json_object_get_string(json_object_object_get(json_object_object_get(DeleteCertificate, "certificateHashData"), "issuerKeyHash")));
  13931. sprintf((char*)ShmOCPP16Data->DeleteCertificate.certificateHashData.serialNumber, "%s", json_object_get_string(json_object_object_get(json_object_object_get(DeleteCertificate, "certificateHashData"), "serialNumber")));
  13932. }
  13933. json_object_put(DeleteCertificate);
  13934. /*
  13935. * TODO: Delete certificateSigned process
  13936. */
  13937. ShmOCPP16Data->MsMsg.bits.DeleteCertificateReq = 1;
  13938. DEBUG_INFO("hashAlgorithm: %s\n", ShmOCPP16Data->DeleteCertificate.certificateHashData.hashAlgorithm);
  13939. DEBUG_INFO("issuerNameHash: %s\n", ShmOCPP16Data->DeleteCertificate.certificateHashData.issuerNameHash);
  13940. DEBUG_INFO("issuerKeyHash: %s\n", ShmOCPP16Data->DeleteCertificate.certificateHashData.issuerKeyHash);
  13941. DEBUG_INFO("serialNumber: %s\n", ShmOCPP16Data->DeleteCertificate.certificateHashData.serialNumber);
  13942. sprintf((char*)ShmOCPP16Data->DeleteCertificate.Response_status, "NotFound");
  13943. sendDeleteCertificateConfirmation(uuid);
  13944. return result;
  13945. }
  13946. int handleExtendedTriggerMessageRequest(char *uuid, char *payload)
  13947. {
  13948. mtrace();
  13949. int result = PASS;
  13950. json_object *ExtendedTriggerMessage;
  13951. DEBUG_INFO("handleExtendedTriggerMessageRequest...\n");
  13952. ExtendedTriggerMessage = json_tokener_parse(payload);
  13953. if(!is_error(ExtendedTriggerMessage))
  13954. {
  13955. sprintf((char*)ShmOCPP16Data->ExtendedTriggerMessage.requestedMessage, "%s", json_object_get_string(json_object_object_get(ExtendedTriggerMessage, "requestedMessage")));
  13956. if(json_object_object_get(ExtendedTriggerMessage, "connectorId") != NULL)
  13957. {
  13958. ShmOCPP16Data->ExtendedTriggerMessage.connectorId = json_object_get_int(json_object_object_get(ExtendedTriggerMessage, "connectorId"));
  13959. }
  13960. else
  13961. {
  13962. ShmOCPP16Data->ExtendedTriggerMessage.connectorId = -1;
  13963. }
  13964. }
  13965. json_object_put(ExtendedTriggerMessage);
  13966. DEBUG_INFO("requestedMessage: %s\n", ShmOCPP16Data->ExtendedTriggerMessage.requestedMessage);
  13967. DEBUG_INFO("connectorIdInt: %d\n", ShmOCPP16Data->ExtendedTriggerMessage.connectorId);
  13968. if((ShmOCPP16Data->ExtendedTriggerMessage.connectorId == 0) || (ShmOCPP16Data->ExtendedTriggerMessage.connectorId > gunTotalNumber))
  13969. {
  13970. sprintf((char*)ShmOCPP16Data->ExtendedTriggerMessage.Response_status, TriggerMessageStatusStr[TriggerMessageStatus_Rejected]);
  13971. }
  13972. else
  13973. {
  13974. if((strcmp((char*)ShmOCPP16Data->ExtendedTriggerMessage.requestedMessage, MessageTriggerStr[BootNotification]) != 0 ) &&
  13975. (strcmp((char*)ShmOCPP16Data->ExtendedTriggerMessage.requestedMessage, "LogStatusNotification") != 0) &&
  13976. (strcmp((char*)ShmOCPP16Data->ExtendedTriggerMessage.requestedMessage, MessageTriggerStr[FirmwareStatusNotification]) != 0) &&
  13977. (strcmp((char*)ShmOCPP16Data->ExtendedTriggerMessage.requestedMessage, MessageTriggerStr[Heartbeat]) != 0) &&
  13978. (strcmp((char*)ShmOCPP16Data->ExtendedTriggerMessage.requestedMessage, MessageTriggerStr[MeterValues]) != 0) &&
  13979. (strcmp((char*)ShmOCPP16Data->ExtendedTriggerMessage.requestedMessage, "SignChargePointCertificate") != 0 ) &&
  13980. (strcmp((char*)ShmOCPP16Data->ExtendedTriggerMessage.requestedMessage, MessageTriggerStr[StatusNotification]) != 0 ))
  13981. {
  13982. sprintf((char*)ShmOCPP16Data->ExtendedTriggerMessage.Response_status, "%s",TriggerMessageStatusStr[TriggerMessageStatus_NotImplemented] );
  13983. }
  13984. else
  13985. {
  13986. sprintf((char*)ShmOCPP16Data->ExtendedTriggerMessage.Response_status, "%s",TriggerMessageStatusStr[TriggerMessageStatus_Accepted] );
  13987. }
  13988. }
  13989. sendExtendedTriggerMessageConfirmation(uuid);
  13990. //==========================
  13991. // Trigger message
  13992. //==========================
  13993. if(strcmp((char*)ShmOCPP16Data->ExtendedTriggerMessage.requestedMessage, MessageTriggerStr[BootNotification]) == 0 )
  13994. {
  13995. //sendBootNotificationRequest();
  13996. server_sign = FALSE;
  13997. }
  13998. else if( strcmp((char*)ShmOCPP16Data->ExtendedTriggerMessage.requestedMessage, "LogStatusNotification") == 0)
  13999. {
  14000. ShmOCPP16Data->SpMsg.bits.LogStatusNotificationReq = 1;
  14001. }
  14002. else if( strcmp((char*)ShmOCPP16Data->ExtendedTriggerMessage.requestedMessage, MessageTriggerStr[FirmwareStatusNotification]) == 0)
  14003. {
  14004. if((strlen((char*)ShmOCPP16Data->FirmwareStatusNotification.Status) == 0) ||
  14005. ((FirmwareStatusNotificationStatus != FIRMWARE_STATUS_DOWNLOADING) && (FirmwareStatusNotificationStatus != FIRMWARE_STATUS_DOWNLOADED) && (FirmwareStatusNotificationStatus != FIRMWARE_STATUS_IDLE) && (FirmwareStatusNotificationStatus != FIRMWARE_STATUS_INSTALLING)))
  14006. {
  14007. FirmwareStatusNotificationStatus = FIRMWARE_STATUS_IDLE;
  14008. sprintf((char*)ShmOCPP16Data->FirmwareStatusNotification.Status, "%s", FirmwareStatusStr[FirmwareStatus_Idle]);
  14009. }
  14010. ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationReq = 1;
  14011. }
  14012. else if(strcmp((char*)ShmOCPP16Data->ExtendedTriggerMessage.requestedMessage, MessageTriggerStr[Heartbeat]) == 0 )
  14013. {
  14014. refreshStartTimer(&clientTime.Heartbeat);
  14015. clientTime.Heartbeat.tv_sec -= ShmOCPP16Data->BootNotification.ResponseHeartbeatInterval;
  14016. }
  14017. else if (strcmp((char*)ShmOCPP16Data->ExtendedTriggerMessage.requestedMessage, MessageTriggerStr[MeterValues]) == 0 )
  14018. {
  14019. if((ShmOCPP16Data->ExtendedTriggerMessage.connectorId > 0) && (ShmOCPP16Data->ExtendedTriggerMessage.connectorId <= gunTotalNumber))
  14020. {
  14021. cpinitateMsg.bits[ShmOCPP16Data->ExtendedTriggerMessage.connectorId-1].TriggerMeterValue = 1;
  14022. }
  14023. else
  14024. {
  14025. for(int idx=0;idx< gunTotalNumber;idx++)
  14026. {
  14027. //sendMeterValuesRequest(idx, ReadingContext_Trigger);
  14028. cpinitateMsg.bits[idx].TriggerMeterValue = 1;
  14029. }
  14030. }
  14031. }
  14032. else if(strcmp((char*)ShmOCPP16Data->ExtendedTriggerMessage.requestedMessage, "SignChargePointCertificate") == 0 )
  14033. {
  14034. ShmOCPP16Data->SpMsg.bits.SignCertificateReq = 1;
  14035. if(access("/Storage/OCPP/certCP.csr",F_OK) == -1)
  14036. {
  14037. 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\" &");
  14038. }
  14039. }
  14040. else if(strcmp((char*)ShmOCPP16Data->ExtendedTriggerMessage.requestedMessage, MessageTriggerStr[StatusNotification]) == 0 )
  14041. {
  14042. if((ShmOCPP16Data->ExtendedTriggerMessage.connectorId > 0) && (ShmOCPP16Data->ExtendedTriggerMessage.connectorId <= gunTotalNumber))
  14043. {
  14044. cpinitateMsg.bits[ShmOCPP16Data->ExtendedTriggerMessage.connectorId -1].StatusNotificationReq = 1;
  14045. }
  14046. else
  14047. {
  14048. for(int idx=0;idx< gunTotalNumber;idx++)
  14049. cpinitateMsg.bits[idx].StatusNotificationReq = 1;
  14050. }
  14051. }
  14052. return result;
  14053. }
  14054. int handleGetInstalledCertificateIdsRequest(char *uuid, char *payload)
  14055. {
  14056. mtrace();
  14057. int result = PASS;
  14058. json_object *GetInstalledCertificateIds;
  14059. DEBUG_INFO("handleGetInstalledCertificateIdsRequest...\n");
  14060. GetInstalledCertificateIds = json_tokener_parse(payload);
  14061. if(!is_error(GetInstalledCertificateIds))
  14062. {
  14063. sprintf((char*)ShmOCPP16Data->GetInstalledCertificateIds.certificateType, "%s", json_object_get_string(json_object_object_get(GetInstalledCertificateIds, "certificateType")));
  14064. }
  14065. json_object_put(GetInstalledCertificateIds);
  14066. /*
  14067. * TODO: Return installed certificate process
  14068. */
  14069. ShmOCPP16Data->MsMsg.bits.GetInstalledCertificateIdsReq = 1;
  14070. DEBUG_INFO("requestedMessage: %s\n", (char*)ShmOCPP16Data->GetInstalledCertificateIds.certificateType);
  14071. memset(ShmOCPP16Data->GetInstalledCertificateIds.Response_certificateHashData, 0x00, ARRAY_SIZE(ShmOCPP16Data->GetInstalledCertificateIds.Response_certificateHashData)*sizeof(struct CertificateHashDataType));
  14072. sprintf((char*)ShmOCPP16Data->GetInstalledCertificateIds.Response_status, "NotFound");
  14073. sendGetInstalledCertificateIdsConfirmation(uuid);
  14074. return result;
  14075. }
  14076. int handleGetLogRequest(char *uuid, char *payload)
  14077. {
  14078. mtrace();
  14079. int result = PASS;
  14080. json_object *GetLog;
  14081. DEBUG_INFO("handleGetLogRequest...\n");
  14082. GetLog = json_tokener_parse(payload);
  14083. if(!is_error(GetLog))
  14084. {
  14085. sprintf((char*)ShmOCPP16Data->GetLog.logType, "%s", json_object_get_string(json_object_object_get(GetLog, "logType")));
  14086. ShmOCPP16Data->GetLog.requestId = json_object_get_int(json_object_object_get(GetLog, "requestId"));
  14087. if(json_object_object_get(GetLog, "retries") != NULL)
  14088. {
  14089. ShmOCPP16Data->GetLog.retries = json_object_get_int(json_object_object_get(GetLog, "retries"));
  14090. }
  14091. if(json_object_object_get(GetLog, "retryInterval") != NULL)
  14092. {
  14093. ShmOCPP16Data->GetLog.retryInterval = json_object_get_int(json_object_object_get(GetLog, "retryInterval"));
  14094. }
  14095. sprintf((char*)ShmOCPP16Data->GetLog.log.remoteLocation, "%s", json_object_get_string(json_object_object_get(json_object_object_get(GetLog, "log"), "remoteLocation")));
  14096. if(json_object_object_get(json_object_object_get(GetLog, "log"), "oldestTimestamp") != NULL)
  14097. {
  14098. sprintf((char*)ShmOCPP16Data->GetLog.log.oldestTimestamp, "%s", json_object_get_string(json_object_object_get(json_object_object_get(GetLog, "log"), "oldestTimestamp")));
  14099. }
  14100. if(json_object_object_get(json_object_object_get(GetLog, "log"), "latestTimestamp") != NULL)
  14101. {
  14102. sprintf((char*)ShmOCPP16Data->GetLog.log.latestTimestamp, "%s", json_object_get_string(json_object_object_get(json_object_object_get(GetLog, "log"), "latestTimestamp")));
  14103. }
  14104. }
  14105. json_object_put(GetLog);
  14106. /*
  14107. * TODO: Upload log process
  14108. */
  14109. ShmOCPP16Data->MsMsg.bits.GetLogReq = 1;
  14110. DEBUG_INFO("logType: %s\n", ShmOCPP16Data->GetLog.logType);
  14111. DEBUG_INFO("requestId: %d\n", ShmOCPP16Data->GetLog.requestId);
  14112. DEBUG_INFO("retries: %d\n", ShmOCPP16Data->GetLog.retries);
  14113. DEBUG_INFO("retryInterval: %d\n", ShmOCPP16Data->GetLog.retryInterval);
  14114. DEBUG_INFO("remoteLocation: %s\n", ShmOCPP16Data->GetLog.log.remoteLocation);
  14115. DEBUG_INFO("oldestTimestamp: %s\n", ShmOCPP16Data->GetLog.log.oldestTimestamp);
  14116. DEBUG_INFO("latestTimestamp: %s\n", ShmOCPP16Data->GetLog.log.latestTimestamp);
  14117. sprintf((char*)ShmOCPP16Data->GetLog.Response_status, "Rejected");
  14118. sendGetLogConfirmation(uuid);
  14119. return result;
  14120. }
  14121. int handleInstallCertificateRequest(char *uuid, char *payload)
  14122. {
  14123. mtrace();
  14124. int result = PASS;
  14125. json_object *InstallCertificate;
  14126. DEBUG_INFO("handleInstallCertificateRequest...\n");
  14127. InstallCertificate = json_tokener_parse(payload);
  14128. if(!is_error(InstallCertificate))
  14129. {
  14130. sprintf((char*)ShmOCPP16Data->InstallCertificate.certificateType, "%s", json_object_get_string(json_object_object_get(InstallCertificate, "certificateType")));
  14131. sprintf((char*)ShmOCPP16Data->InstallCertificate.certificate, "%s", json_object_get_string(json_object_object_get(InstallCertificate, "certificate")));
  14132. /*
  14133. * TODO: Install certificate process
  14134. */
  14135. ShmOCPP16Data->MsMsg.bits.InstallCertificateReq = 1;
  14136. DEBUG_INFO("certificateType: %s\n", (char*)ShmOCPP16Data->InstallCertificate.certificateType);
  14137. DEBUG_INFO("certificate: %s\n", (char*)ShmOCPP16Data->InstallCertificate.certificate);
  14138. sprintf((char*)ShmOCPP16Data->InstallCertificate.Response_status, "Rejected");
  14139. sendInstallCertificateConfirmation(uuid);
  14140. }
  14141. json_object_put(InstallCertificate);
  14142. return result;
  14143. }
  14144. int handleSignedUpdateFirmwareRequest(char *uuid, char *payload)
  14145. {
  14146. mtrace();
  14147. int result = PASS;
  14148. json_object *SignedUpdateFirmware;
  14149. DEBUG_INFO("handleSignedUpdateFirmwareRequest...\n");
  14150. SignedUpdateFirmware = json_tokener_parse(payload);
  14151. if(!is_error(SignedUpdateFirmware))
  14152. {
  14153. if(json_object_object_get(SignedUpdateFirmware, "retries") != NULL)
  14154. {
  14155. ShmOCPP16Data->SignedUpdateFirmware.retries = json_object_get_int(json_object_object_get(SignedUpdateFirmware, "retries"));
  14156. }
  14157. if(json_object_object_get(SignedUpdateFirmware, "retryInterval") != NULL)
  14158. {
  14159. ShmOCPP16Data->SignedUpdateFirmware.retryInterval = json_object_get_int(json_object_object_get(SignedUpdateFirmware, "retryInterval"));
  14160. }
  14161. ShmOCPP16Data->SignedUpdateFirmware.requestId = json_object_get_int(json_object_object_get(SignedUpdateFirmware, "requestId"));
  14162. sprintf((char*)ShmOCPP16Data->SignedUpdateFirmware.firmware.location, "%s", json_object_get_string(json_object_object_get(json_object_object_get(SignedUpdateFirmware, "firmware"), "location")));
  14163. sprintf((char*)ShmOCPP16Data->SignedUpdateFirmware.firmware.retrieveDateTime, "%s", json_object_get_string(json_object_object_get(json_object_object_get(SignedUpdateFirmware, "firmware"), "retrieveDateTime")));
  14164. if(json_object_object_get(json_object_object_get(SignedUpdateFirmware, "firmware"), "installDateTime") != NULL)
  14165. {
  14166. sprintf((char*)ShmOCPP16Data->SignedUpdateFirmware.firmware.installDateTime, "%s", json_object_get_string(json_object_object_get(json_object_object_get(SignedUpdateFirmware, "firmware"), "installDateTime")));
  14167. }
  14168. sprintf((char*)ShmOCPP16Data->SignedUpdateFirmware.firmware.signingCertificate, "%s", json_object_get_string(json_object_object_get(json_object_object_get(SignedUpdateFirmware, "firmware"), "signingCertificate")));
  14169. sprintf((char*)ShmOCPP16Data->SignedUpdateFirmware.firmware.signature, "%s", json_object_get_string(json_object_object_get(json_object_object_get(SignedUpdateFirmware, "firmware"), "signature")));
  14170. }
  14171. json_object_put(SignedUpdateFirmware);
  14172. /*
  14173. * TODO: Upgrade firmware process
  14174. */
  14175. ShmOCPP16Data->MsMsg.bits.SignedUpdateFirmwareReq = 1;
  14176. DEBUG_INFO("retries: %d\n", ShmOCPP16Data->SignedUpdateFirmware.retries);
  14177. DEBUG_INFO("retryInterval: %d\n", ShmOCPP16Data->SignedUpdateFirmware.retryInterval);
  14178. DEBUG_INFO("requestId: %d\n", ShmOCPP16Data->SignedUpdateFirmware.requestId);
  14179. DEBUG_INFO("location: %s\n", ShmOCPP16Data->SignedUpdateFirmware.firmware.location);
  14180. DEBUG_INFO("retrieveDateTime: %s\n", ShmOCPP16Data->SignedUpdateFirmware.firmware.retrieveDateTime);
  14181. DEBUG_INFO("installDateTime: %s\n", ShmOCPP16Data->SignedUpdateFirmware.firmware.installDateTime);
  14182. DEBUG_INFO("signingCertificate: %s\n", ShmOCPP16Data->SignedUpdateFirmware.firmware.signingCertificate);
  14183. DEBUG_INFO("signature: %s\n", ShmOCPP16Data->SignedUpdateFirmware.firmware.signature);
  14184. sprintf((char*)ShmOCPP16Data->SignedUpdateFirmware.Response_status, "Rejected");
  14185. sendInstallCertificateConfirmation(uuid);
  14186. return result;
  14187. }
  14188. int handleUnknownRequest(char *uuid, char *payload)
  14189. {
  14190. mtrace();
  14191. int result = PASS;
  14192. DEBUG_INFO("handleUnknownRequest...\n");
  14193. sendUnknownConfirmation(uuid);
  14194. result = PASS;
  14195. return result;
  14196. }
  14197. //==========================================
  14198. // Handle server response routine
  14199. //==========================================
  14200. void handleAuthorizeResponse(char *payload, int gun_index)
  14201. {
  14202. mtrace();
  14203. char expiryDatestr[36]={0};
  14204. char parentIdTagstr[21]={0};
  14205. char statusstr[20]={0};
  14206. int expiryDateISNULL=FALSE;
  14207. int parentIdTagISNULL=FALSE;
  14208. DEBUG_INFO("handleAuthorizeResponse...\n");
  14209. json_object *Authorize;
  14210. Authorize = json_tokener_parse(payload);
  14211. if(!is_error(Authorize))
  14212. {
  14213. if(json_object_object_get(Authorize, "idTagInfo") != NULL)
  14214. {
  14215. // Required data
  14216. sprintf((char *)statusstr, "%s", json_object_get_string(json_object_object_get(json_object_object_get(Authorize,"idTagInfo"), "status")));
  14217. // Optional data
  14218. if(json_object_object_get(json_object_object_get(Authorize,"idTagInfo"), "expiryDate") != NULL)
  14219. sprintf((char *)expiryDatestr, "%s", json_object_get_string(json_object_object_get(json_object_object_get(Authorize,"idTagInfo"), "expiryDate")));
  14220. if(json_object_object_get(json_object_object_get(Authorize,"idTagInfo"), "parentIdTag") != NULL)
  14221. sprintf((char *)parentIdTagstr, "%s", json_object_get_string(json_object_object_get(json_object_object_get(Authorize,"idTagInfo"), "parentIdTag")));
  14222. }
  14223. }
  14224. json_object_put(Authorize);
  14225. if(expiryDateISNULL == FALSE)
  14226. strcpy((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.ExpiryDate, expiryDatestr);
  14227. if(parentIdTagISNULL == FALSE)
  14228. strcpy((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.ParentIdTag, parentIdTagstr);
  14229. strcpy((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.Status, statusstr);
  14230. //Update idTag information to authorization cache if supproted
  14231. if((strcmp((const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemData, "TRUE") == 0) && (ShmOCPP16Data->Authorize.ResponseIdTagInfo.ParentIdTag != NULL) && (ShmOCPP16Data->Authorize.ResponseIdTagInfo.ExpiryDate != NULL) )
  14232. {
  14233. OCPP_addLocalCache((char*)ShmOCPP16Data->Authorize.IdTag, parentIdTagstr, expiryDatestr, statusstr);
  14234. }
  14235. ShmOCPP16Data->SpMsg.bits.AuthorizeReq = 0;
  14236. ShmOCPP16Data->SpMsg.bits.AuthorizeConf = 1; // inform csu
  14237. authorizeRetryTimes = 0;
  14238. }
  14239. void handleBootNotificationResponse(char *payload, int gun_index)
  14240. {
  14241. mtrace();
  14242. char statusStr[12]={0};
  14243. char currentTimeStr[30]={0};
  14244. int intervalInt = 0;
  14245. DEBUG_INFO("handleBootNotificationResponse...\n");
  14246. json_object *BootNotification;
  14247. BootNotification = json_tokener_parse(payload);
  14248. if(!is_error(BootNotification))
  14249. {
  14250. // Required data
  14251. sprintf((char *)currentTimeStr, "%s", json_object_get_string(json_object_object_get(BootNotification,"currentTime")));
  14252. intervalInt = json_object_get_int(json_object_object_get(BootNotification,"interval"));
  14253. sprintf((char *)statusStr, "%s", json_object_get_string(json_object_object_get(BootNotification,"status")));
  14254. }
  14255. json_object_put(BootNotification);
  14256. ShmOCPP16Data->BootNotification.ResponseHeartbeatInterval = intervalInt;
  14257. BootNotificationInterval = intervalInt;
  14258. //write back to ShmOCPP16Data->BootNotification
  14259. strcpy((char *)ShmOCPP16Data->BootNotification.ResponseCurrentTime, currentTimeStr);
  14260. ShmOCPP16Data->BootNotification.ResponseHeartbeatInterval = intervalInt;
  14261. strcpy((char *)ShmOCPP16Data->BootNotification.ResponseStatus, statusStr);
  14262. if((strcmp(statusStr, RegistrationStatusStr[RegistrationStatus_Accepted]) == 0 ))
  14263. {
  14264. BootNotificationInterval = 0;
  14265. if((intervalInt == 0) || (intervalInt >= 10))
  14266. {
  14267. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemData, "%d", intervalInt);
  14268. HeartBeatWaitTime = intervalInt;
  14269. DEBUG_INFO("BootNotificationResponse setting interval to %d...\n",intervalInt);
  14270. }
  14271. server_sign = TRUE;
  14272. server_pending =FALSE;
  14273. }
  14274. else if(strcmp(statusStr, RegistrationStatusStr[RegistrationStatus_Pending]) == 0)
  14275. {
  14276. server_pending = TRUE;
  14277. }
  14278. syncDateTimeRTC(ShmOCPP16Data->BootNotification.ResponseCurrentTime);
  14279. srand(time(NULL));
  14280. refreshStartTimer(&clientTime.Heartbeat);
  14281. clientTime.Heartbeat.tv_sec -= (ShmOCPP16Data->BootNotification.ResponseHeartbeatInterval-((rand()%8)+3));
  14282. SetOcppConnStatus(TRUE);
  14283. ShmOCPP16Data->SpMsg.bits.BootNotificationConf = 1;
  14284. }
  14285. void handleDataTransferResponse(char *payload, int gun_index)
  14286. {
  14287. json_object *DataTransfer = json_tokener_parse(payload);
  14288. if(!is_error(DataTransfer))
  14289. {
  14290. // Required data
  14291. DEBUG_INFO("Status: %s.\n", json_object_get_string(json_object_object_get(DataTransfer, "status")));
  14292. // Optional data
  14293. if(json_object_object_get(DataTransfer, "data") != NULL)
  14294. {
  14295. DEBUG_INFO("Data: %s\n", json_object_get_string(json_object_object_get(DataTransfer, "data")));
  14296. json_object *Data = json_tokener_parse(json_object_get_string(json_object_object_get(DataTransfer, "data")));
  14297. if(!is_error(Data))
  14298. {
  14299. if(json_object_object_get(Data, "msgId") != NULL)
  14300. {
  14301. if(strstr(json_object_get_string(json_object_object_get(Data, "msgId")), "ID_CreditDeductResult") != NULL)
  14302. {
  14303. 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")));
  14304. }
  14305. if(strstr(json_object_get_string(json_object_object_get(Data, "msgId")), "ID_ReaderStatus") != NULL)
  14306. {
  14307. if(json_object_object_get(Data, "ConnectorId") != NULL)
  14308. ShmOCPP16Data->TcciCustomData.ReaderStatus[json_object_get_int(json_object_object_get(Data, "ConnectorId"))-1].ReportReaderStatusReq = 0;
  14309. }
  14310. }
  14311. }
  14312. json_object_put(Data);
  14313. }
  14314. }
  14315. json_object_put(DataTransfer);
  14316. }
  14317. void handleDiagnosticsStatusNotificationResponse(char *payload, int gun_index)
  14318. {
  14319. DEBUG_INFO("handleDiagnosticsStatusNotificationResponse ...\n");
  14320. //struct json_object *obj;
  14321. // obj = json_tokener_parse(payload);
  14322. ShmOCPP16Data->SpMsg.bits.DiagnosticsStatusNotificationReq = 0;
  14323. ShmOCPP16Data->SpMsg.bits.DiagnosticsStatusNotificationConf = 1;
  14324. //No fields are defined.
  14325. }
  14326. void handleFirmwareStatusNotificationResponse(char *payload, int gun_index)
  14327. {
  14328. DEBUG_INFO("handleFirmwareStatusNotificationResponse ...\n");
  14329. //struct json_object *obj;
  14330. // obj = json_tokener_parse(payload);
  14331. ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationReq = 0;
  14332. ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationConf = 1;
  14333. //No fields are defined.
  14334. }
  14335. void handleHeartbeatResponse(char *payload, int gun_index)
  14336. {
  14337. mtrace();
  14338. DEBUG_INFO("handleHeartbeatResponse...\n");
  14339. json_object *Heartbeat;
  14340. Heartbeat = json_tokener_parse(payload);
  14341. if(!is_error(Heartbeat))
  14342. {
  14343. // Required data
  14344. sprintf((char *)ShmOCPP16Data->Heartbeat.ResponseCurrentTime, "%s", json_object_get_string(json_object_object_get(Heartbeat,"currentTime")));
  14345. }
  14346. json_object_put(Heartbeat);
  14347. if(FirstHeartBeat == 0)
  14348. {
  14349. FirstHeartBeat = 1;
  14350. DEBUG_INFO("FirstHeartBeat \n");
  14351. }
  14352. HeartBeatWithNOResponse = 0;
  14353. refreshStartTimer(&clientTime.Heartbeat);
  14354. syncDateTimeRTC(ShmOCPP16Data->Heartbeat.ResponseCurrentTime);
  14355. }
  14356. void handleMeterValuesResponse(char *payload, int gun_index)
  14357. {
  14358. mtrace();
  14359. DEBUG_INFO("handleMeterValuesResponse...\n");
  14360. isQueueSendable = 1;
  14361. }
  14362. void handleStartTransactionResponse(char *payload, int gun_index)
  14363. {
  14364. mtrace();
  14365. //int transactionIdInt = 0;
  14366. FILE *outfile;
  14367. char data[100]={0};
  14368. DEBUG_INFO("handleStartTransactionResponse...\n");
  14369. json_object *StartTransaction;
  14370. StartTransaction = json_tokener_parse(payload);
  14371. if(!is_error(StartTransaction))
  14372. {
  14373. // Required data
  14374. sprintf((char *)ShmOCPP16Data->StartTransaction[gun_index].ResponseIdTagInfo.Status, "%s", json_object_get_string(json_object_object_get(json_object_object_get(StartTransaction,"idTagInfo"), "status")));
  14375. ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId = json_object_get_int(json_object_object_get(StartTransaction,"transactionId"));
  14376. // Optional data
  14377. if(json_object_object_get(json_object_object_get(StartTransaction,"idTagInfo"), "expiryDate") != NULL)
  14378. sprintf((char *)ShmOCPP16Data->StartTransaction[gun_index].ResponseIdTagInfo.ExpiryDate, "%s", json_object_get_string(json_object_object_get(json_object_object_get(StartTransaction,"idTagInfo"), "expiryDate")));
  14379. if(json_object_object_get(json_object_object_get(StartTransaction,"idTagInfo"), "parentIdTag") != NULL)
  14380. sprintf((char *)ShmOCPP16Data->StartTransaction[gun_index].ResponseIdTagInfo.ParentIdTag, "%s", json_object_get_string(json_object_object_get(json_object_object_get(StartTransaction,"idTagInfo"), "parentIdTag")));
  14381. }
  14382. json_object_put(StartTransaction);
  14383. OCPP_updatePeriodEnergy(gun_index);
  14384. //-----------Start : write to the Queue TransactionId file -----------------//
  14385. if((access("/Storage/OCPP/QueueTransactionId",F_OK))!=-1)
  14386. {}
  14387. else
  14388. {
  14389. FILE *log = fopen("/Storage/OCPP/QueueTransactionId", "w+");
  14390. if(log == NULL)
  14391. {
  14392. DEBUG_INFO("Can't Create File QueueTransactionId \n");
  14393. return ;
  14394. }
  14395. else
  14396. {
  14397. fclose(log);
  14398. }
  14399. }
  14400. // open file for writing
  14401. //-------------Start: write to the Queue TransactionId file------------------------------------------//
  14402. if((ShmOCPP16Data->StartTransaction[gun_index].ConnectorId !=0)&&(strcmp((const char *)ShmOCPP16Data->StartTransaction[gun_index].IdTag,"")!=0)&&(ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId !=0))
  14403. {
  14404. outfile = fopen ("/Storage/OCPP/QueueTransactionId", "a");
  14405. sprintf(data,"%d,%s,%d\n", ShmOCPP16Data->StartTransaction[gun_index].ConnectorId , ShmOCPP16Data->StartTransaction[gun_index].IdTag, ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId); // GunIndex, idtag, TransactionId
  14406. fputs(data, outfile);
  14407. fclose (outfile);
  14408. }
  14409. DEBUG_INFO("idTagInfo-expiryDate: %s\n", ShmOCPP16Data->StartTransaction[gun_index].ResponseIdTagInfo.ExpiryDate);
  14410. DEBUG_INFO("idTagInfo-parentIdTag: %s\n", ShmOCPP16Data->StartTransaction[gun_index].ResponseIdTagInfo.ParentIdTag);
  14411. DEBUG_INFO("idTagInfo-status: %s\n", ShmOCPP16Data->StartTransaction[gun_index].ResponseIdTagInfo.Status);
  14412. DEBUG_INFO("transactionId: %d\n", ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId);
  14413. system("/bin/fsync -d /dev/mtdblock13;/bin/sync &");
  14414. isQueueSendable = 1;
  14415. ShmOCPP16Data->CpMsg.bits[gun_index].StartTransactionConf = 1;
  14416. ShmOCPP16Data->CpMsg.bits[gun_index].StartTransactionReq = 0;
  14417. }
  14418. void handleStatusNotificationResponse(char *payload, int gun_index)
  14419. {
  14420. mtrace();
  14421. DEBUG_INFO("handleStatusNotificationResponse...\n");
  14422. //cpinitateMsg.bits[gun_index].TriggerStatusNotificationReq = 0;
  14423. //cpinitateMsg.bits[gun_index].StatusNotificationReq = 0;
  14424. cpinitateMsg.bits[gun_index].StatusNotificationConf = 1;
  14425. }
  14426. void handleStopTransactionnResponse(char *payload, int gun_index)
  14427. {
  14428. mtrace();
  14429. DEBUG_INFO("handleStopTransactionnResponse...\n");
  14430. json_object *StopTransaction;
  14431. StopTransaction = json_tokener_parse(payload);
  14432. if(!is_error(StopTransaction))
  14433. {
  14434. // Optional data
  14435. if(json_object_object_get(StopTransaction, "idTagInfo") != NULL)
  14436. {
  14437. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].ResponseIdTagInfo.Status, "%s", json_object_get_string(json_object_object_get(json_object_object_get(StopTransaction,"idTagInfo"), "status")));
  14438. if(json_object_object_get(json_object_object_get(StopTransaction,"idTagInfo"), "expiryDate") != NULL)
  14439. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].ResponseIdTagInfo.ExpiryDate, "%s", json_object_get_string(json_object_object_get(json_object_object_get(StopTransaction,"idTagInfo"), "expiryDate")));
  14440. if(json_object_object_get(json_object_object_get(StopTransaction,"idTagInfo"), "parentIdTag") != NULL)
  14441. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].ResponseIdTagInfo.ParentIdTag, "%s", json_object_get_string(json_object_object_get(json_object_object_get(StopTransaction,"idTagInfo"), "parentIdTag")));
  14442. }
  14443. }
  14444. json_object_put(StopTransaction);
  14445. isQueueSendable = 1;
  14446. ShmOCPP16Data->CpMsg.bits[gun_index].StopTransactionConf = 1;
  14447. ShmOCPP16Data->CpMsg.bits[gun_index].StopTransactionReq = 0;
  14448. DEBUG_INFO("idTagInfo-expiryDate: %s\n", ShmOCPP16Data->StopTransaction[gun_index].ResponseIdTagInfo.ExpiryDate);
  14449. DEBUG_INFO("idTagInfo-parentIdTag: %s\n", ShmOCPP16Data->StopTransaction[gun_index].ResponseIdTagInfo.ParentIdTag);
  14450. DEBUG_INFO("idTagInfo-status: %s\n", ShmOCPP16Data->StopTransaction[gun_index].ResponseIdTagInfo.Status);
  14451. SetTransactionIdZero(queueOpInfo.stopTransactionId);
  14452. }
  14453. void handleLogStatusNotificationResponse(char *payload, int gun_index)
  14454. {
  14455. mtrace();
  14456. DEBUG_INFO("handleLogStatusNotificationResponse...\n");
  14457. ShmOCPP16Data->SpMsg.bits.LogStatusNotificationConf = 1;
  14458. }
  14459. void handleSecurityEventNotificationResponse(char *payload, int gun_index)
  14460. {
  14461. mtrace();
  14462. DEBUG_INFO("handleSecurityEventNotificationResponse...\n");
  14463. ShmOCPP16Data->SpMsg.bits.SecurityEventNotificationConf = 1;
  14464. }
  14465. void handleSignCertificateResponse(char *payload, int gun_index)
  14466. {
  14467. mtrace();
  14468. DEBUG_INFO("handleSignCertificateResponse...\n");
  14469. json_object *SignCertificate;
  14470. SignCertificate = json_tokener_parse(payload);
  14471. if(!is_error(SignCertificate))
  14472. {
  14473. sprintf((char*)ShmOCPP16Data->SignCertificate.Response_status, "%s", json_object_get_string(json_object_object_get(SignCertificate, "status")));
  14474. DEBUG_INFO("status: %s\n", ShmOCPP16Data->SignCertificate.Response_status);
  14475. }
  14476. json_object_put(SignCertificate);
  14477. ShmOCPP16Data->SpMsg.bits.SignCertificateConf = 1;
  14478. }
  14479. void handleSignedFirmwareStatusNotificationResponse(char *payload, int gun_index)
  14480. {
  14481. mtrace();
  14482. DEBUG_INFO("handleSignedFirmwareStatusNotificationResponse...\n");
  14483. ShmOCPP16Data->SpMsg.bits.SignedFirmwareStatusNotificationConf = 1;
  14484. }
  14485. //==========================================
  14486. // Handle Error routine
  14487. //==========================================
  14488. void handleError(char *id, char *errorCode, char *errorDescription,char *payload)
  14489. {
  14490. mtrace();
  14491. #ifdef SystemLogMessage
  14492. DEBUG_INFO("errorCode: %s\n", errorCode);
  14493. DEBUG_INFO("errorDescription: %s\n", errorDescription);
  14494. DEBUG_INFO("errorDetails: %s\n", payload);
  14495. #endif
  14496. }
  14497. //===============================================
  14498. // Common routine
  14499. //===============================================
  14500. int initialConfigurationTable(void)
  14501. {
  14502. //clock_t start_t, end_t, total_t;
  14503. FILE *fp;
  14504. FILE *outfile;
  14505. char str[512]={0};
  14506. char sstr[256]={0};
  14507. int c = 0;
  14508. char *loc;
  14509. int confVersion = 19;
  14510. DEBUG_INFO("initialConfigurationTable...version: %d\n", confVersion);
  14511. //start_t = clock();
  14512. //printf("Starting of the program, start_t = %ld\n", start_t);
  14513. memset(&(ShmOCPP16Data->ConfigurationTable), 0, sizeof(struct OCPP16ConfigurationTable) );
  14514. // Check configuration file size is correct
  14515. if((access("/Storage/OCPP/OCPPConfiguration",F_OK))!=-1)
  14516. {
  14517. struct stat st;
  14518. stat("/Storage/OCPP/OCPPConfiguration", &st);
  14519. if(st.st_size < 3100)
  14520. {
  14521. system("rm -f /Storage/OCPP/OCPPConfiguration");
  14522. DEBUG_INFO("OCPPConfiguration file size: %d is smaller than 3100 bytes, restore to default value.\n", st.st_size);
  14523. }
  14524. }
  14525. if((access("/Storage/OCPP/OCPPConfiguration",F_OK))==-1)
  14526. {
  14527. outfile = fopen("/Storage/OCPP/OCPPConfiguration" , "w+");
  14528. if(outfile == NULL)
  14529. {
  14530. DEBUG_INFO("Error opening file\n");
  14531. return FALSE;
  14532. }
  14533. /*Core Profile*/
  14534. //AllowOfflineTxForUnknownId
  14535. ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemAccessibility = 1;
  14536. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemName, "AllowOfflineTxForUnknownId");
  14537. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemData, "FALSE" );
  14538. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","AllowOfflineTxForUnknownId", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemData);
  14539. //AuthorizationCacheEnabled
  14540. ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemAccessibility = 1;
  14541. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemName, "AuthorizationCacheEnabled");
  14542. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemData, "FALSE" );
  14543. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","AuthorizationCacheEnabled", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemData);
  14544. //AuthorizeRemoteTxRequests
  14545. ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemAccessibility = 0;
  14546. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemName, "AuthorizeRemoteTxRequests");
  14547. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemData, "FALSE" );
  14548. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","AuthorizeRemoteTxRequests", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemData);
  14549. //BlinkRepeat
  14550. ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemAccessibility = 1;
  14551. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemName, "BlinkRepeat");
  14552. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemData, "0" );
  14553. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","BlinkRepeat", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemData);
  14554. //ClockAlignedDataInterval
  14555. ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemAccessibility = 1;
  14556. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemName, "ClockAlignedDataInterval");
  14557. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemData, "0" );
  14558. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ClockAlignedDataInterval", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemData);
  14559. //ConnectionTimeOut
  14560. ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemAccessibility = 1;
  14561. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemName, "ConnectionTimeOut");
  14562. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemData, "180" );
  14563. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ConnectionTimeOut", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemData);
  14564. //GetConfigurationMaxKeys
  14565. ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemAccessibility =0;
  14566. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemName, "GetConfigurationMaxKeys");
  14567. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemData, "%d", _GetConfiguration_CNT);
  14568. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","GetConfigurationMaxKeys", "true", ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemData);
  14569. // HeartbeatInterval
  14570. ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemAccessibility = 1;
  14571. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemName, "HeartbeatInterval");
  14572. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemData, "20" );
  14573. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","HeartbeatInterval", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemData);
  14574. // LightIntensity
  14575. ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemAccessibility = 1;
  14576. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemName, "LightIntensity");
  14577. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemData, "0" );
  14578. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LightIntensity", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemData);
  14579. // LocalAuthorizeOffline
  14580. ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemAccessibility = 1;
  14581. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemName, "LocalAuthorizeOffline");
  14582. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemData, "TRUE" );
  14583. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LocalAuthorizeOffline", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemData);
  14584. // LocalPreAuthorize
  14585. ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemAccessibility = 1;
  14586. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemName, "LocalPreAuthorize");
  14587. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemData, "FALSE" );
  14588. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LocalPreAuthorize", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemData);
  14589. // MaxEnergyOnInvalidId
  14590. ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemAccessibility = 1;
  14591. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemName, "MaxEnergyOnInvalidId");
  14592. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemData, "0" );
  14593. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MaxEnergyOnInvalidId", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemData);
  14594. // MeterValuesAlignedData
  14595. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemAccessibility = 1;
  14596. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemName, "MeterValuesAlignedData");
  14597. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  14598. 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" );
  14599. else
  14600. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, "Current.Import,Energy.Active.Import.Register,Energy.Active.Import.Interval,Power.Active.Import,Voltage,Current.Offered" );
  14601. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValuesAlignedData", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData);
  14602. // MeterValuesAlignedDataMaxLength
  14603. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemAccessibility = 0;
  14604. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemName, "MeterValuesAlignedDataMaxLength");
  14605. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  14606. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemData, "8" );
  14607. else
  14608. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemData, "10" );
  14609. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValuesAlignedDataMaxLength", "true", ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemData);
  14610. // MeterValuesSampledData
  14611. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemAccessibility = 1;
  14612. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemName, "MeterValuesSampledData");
  14613. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  14614. 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" );
  14615. else
  14616. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, "Current.Import,Energy.Active.Import.Register,Energy.Active.Import.Interval,Power.Active.Import,Voltage,Current.Offered" );
  14617. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValuesSampledData", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData);
  14618. // MeterValuesSampledDataMaxLength
  14619. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemAccessibility = 0;
  14620. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemName, "MeterValuesSampledDataMaxLength");
  14621. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  14622. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemData, "8" );
  14623. else
  14624. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemData, "10" );
  14625. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValuesSampledDataMaxLength", "true", ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemData);
  14626. // MeterValueSampleInterval
  14627. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemAccessibility = 1;
  14628. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemName, "MeterValueSampleInterval");
  14629. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemData, "30" );
  14630. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValueSampleInterval", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemData);
  14631. // MinimumStatusDuration
  14632. ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemAccessibility = 1;
  14633. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemName, "MinimumStatusDuration");
  14634. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemData, "120" );
  14635. server_cycle_Status = atoi((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemData); //StatusNotification cycle
  14636. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MinimumStatusDuration", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemData);
  14637. // NumberOfConnectors
  14638. ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemAccessibility = 0;
  14639. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemName, "NumberOfConnectors");
  14640. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  14641. {
  14642. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData, "%d", (CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY));
  14643. }
  14644. else
  14645. {
  14646. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData, "%d", AC_QUANTITY);
  14647. }
  14648. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","NumberOfConnectors", "true", ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData);
  14649. // ResetRetries
  14650. ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemAccessibility = 1;
  14651. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemName, "ResetRetries");
  14652. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemData, "3" );
  14653. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ResetRetries", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemData);
  14654. // ConnectorPhaseRotation
  14655. ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemAccessibility = 1;
  14656. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemName, "ConnectorPhaseRotation");
  14657. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "NotApplicable" );
  14658. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ConnectorPhaseRotation", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData);
  14659. // ConnectorPhaseRotationMaxLength
  14660. ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemAccessibility = 0;
  14661. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemName, "ConnectorPhaseRotationMaxLength");
  14662. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemData, "1" );
  14663. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ConnectorPhaseRotationMaxLength", "true", ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemData);
  14664. // StopTransactionOnEVSideDisconnect
  14665. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemAccessibility = 0;
  14666. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemName, "StopTransactionOnEVSideDisconnect");
  14667. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemData, "TRUE" );
  14668. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTransactionOnEVSideDisconnect", "true", ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemData);
  14669. // StopTransactionOnInvalidId
  14670. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemAccessibility = 1; //1;
  14671. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemName, "StopTransactionOnInvalidId");
  14672. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemData, "FALSE" );
  14673. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTransactionOnInvalidId", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemData);
  14674. // StopTxnAlignedData
  14675. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemAccessibility = 0;
  14676. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemName, "StopTxnAlignedData");
  14677. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemData, "" );
  14678. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTxnAlignedData", "true", ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemData);
  14679. // StopTxnAlignedDataMaxLength
  14680. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemAccessibility = 0;
  14681. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemName, "StopTxnAlignedDataMaxLength");
  14682. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemData, "0" );
  14683. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTxnAlignedDataMaxLength", "true", ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemData);
  14684. // StopTxnSampledData
  14685. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemAccessibility = 1;
  14686. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemName, "StopTxnSampledData");
  14687. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  14688. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Current.Import,Energy.Active.Import.Interval,Power.Active.Import,Voltage,SoC" );
  14689. else
  14690. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Current.Import,Energy.Active.Import.Interval,Power.Active.Import,Voltage" );
  14691. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTxnSampledData", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData);
  14692. // StopTxnSampledDataMaxLength
  14693. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemAccessibility = 0;
  14694. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemName, "StopTxnSampledDataMaxLength");
  14695. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  14696. {
  14697. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemData, "%d", 7);
  14698. }
  14699. else
  14700. {
  14701. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemData, "%d", 9);
  14702. }
  14703. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTxnSampledDataMaxLength", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemData);
  14704. // SupportedFeatureProfiles
  14705. ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemAccessibility = 0;
  14706. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemName, "SupportedFeatureProfiles");
  14707. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemData, "Core,FirmwareManagement,LocalAuthListManagement,Reservation,SmartCharging,RemoteTrigger" );
  14708. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","SupportedFeatureProfiles", "true", ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemData);
  14709. // SupportedFeatureProfilesMaxLength
  14710. ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemAccessibility = 0;
  14711. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemName, "SupportedFeatureProfilesMaxLength");
  14712. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemData, "6" );
  14713. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","SupportedFeatureProfilesMaxLength", "true", ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemData);
  14714. // TransactionMessageAttempts
  14715. ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemAccessibility = 1;
  14716. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemName, "TransactionMessageAttempts");
  14717. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData, "3" );
  14718. TransactionMessageAttemptsValue = atoi((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData);
  14719. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","TransactionMessageAttempts", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData);
  14720. // TransactionMessageRetryInterval
  14721. ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemAccessibility = 1;
  14722. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemName, "TransactionMessageRetryInterval");
  14723. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData, "60" );
  14724. TransactionMessageRetryIntervalValue = atoi((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData);
  14725. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","TransactionMessageRetryInterval", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData);
  14726. // UnlockConnectorOnEVSideDisconnect
  14727. ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemAccessibility = 0;
  14728. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemName, "UnlockConnectorOnEVSideDisconnect");
  14729. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemData, "TRUE" );
  14730. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","UnlockConnectorOnEVSideDisconnect", "true", ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemData);
  14731. // WebSocketPingInterval
  14732. ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemAccessibility = 1;
  14733. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemName, "WebSocketPingInterval");
  14734. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemData, "30" );
  14735. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","WebSocketPingInterval", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemData);
  14736. // QueueOffLineMeterValues
  14737. ShmOCPP16Data->ConfigurationTable.CoreProfile[QueueOffLineMeterValues].ItemAccessibility = 1;
  14738. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[QueueOffLineMeterValues].ItemName, "QueueOffLineMeterValues");
  14739. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[QueueOffLineMeterValues].ItemData, "FALSE" );
  14740. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","QueueOffLineMeterValues", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[QueueOffLineMeterValues].ItemData);
  14741. // AuthorizationKey
  14742. ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationKey].ItemAccessibility = 1;
  14743. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationKey].ItemName, "AuthorizationKey");
  14744. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationKey].ItemData, (char*)ShmSysConfigAndInfo->SysConfig.OcppSecurityPassword);
  14745. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","AuthorizationKey", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationKey].ItemData);
  14746. // SecurityProfile
  14747. ShmOCPP16Data->ConfigurationTable.CoreProfile[SecurityProfile].ItemAccessibility = 1;
  14748. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SecurityProfile].ItemName, "SecurityProfile");
  14749. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SecurityProfile].ItemData, "%d", ShmSysConfigAndInfo->SysConfig.OcppSecurityProfile);
  14750. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","SecurityProfile", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[SecurityProfile].ItemData);
  14751. // DefaultPrice
  14752. ShmOCPP16Data->ConfigurationTable.CoreProfile[DefaultPrice].ItemAccessibility = 1;
  14753. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[DefaultPrice].ItemName, "DefaultPrice");
  14754. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[DefaultPrice].ItemData, "" );
  14755. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","DefaultPrice", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[DefaultPrice].ItemData);
  14756. // CustomDisplayCostAndPrice
  14757. ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemAccessibility = 1;
  14758. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemName, "CustomDisplayCostAndPrice");
  14759. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemData, "FALSE" );
  14760. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","CustomDisplayCostAndPrice", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemData);
  14761. // CustomIdleFeeAfterStop
  14762. ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemAccessibility = 1;
  14763. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemName, "CustomIdleFeeAfterStop");
  14764. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemData, "FALSE" );
  14765. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","CustomIdleFeeAfterStop", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemData);
  14766. // TimeOffset
  14767. ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffset].ItemAccessibility = 1;
  14768. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffset].ItemName, "TimeOffset");
  14769. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffset].ItemData, "+00:00" );
  14770. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","TimeOffset", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffset].ItemData);
  14771. // NextTimeOffsetTransitionDateTime
  14772. ShmOCPP16Data->ConfigurationTable.CoreProfile[NextTimeOffsetTransitionDateTime].ItemAccessibility = 1;
  14773. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NextTimeOffsetTransitionDateTime].ItemName, "NextTimeOffsetTransitionDateTime");
  14774. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NextTimeOffsetTransitionDateTime].ItemData, " " );
  14775. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","NextTimeOffsetTransitionDateTime", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[NextTimeOffsetTransitionDateTime].ItemData);
  14776. // TimeOffsetNextTransition
  14777. ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffsetNextTransition].ItemAccessibility = 1;
  14778. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffsetNextTransition].ItemName, "TimeOffsetNextTransition");
  14779. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffsetNextTransition].ItemData, "+00:00" );
  14780. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","TimeOffsetNextTransition", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffsetNextTransition].ItemData);
  14781. // SystemUptimeSec
  14782. ShmOCPP16Data->ConfigurationTable.CoreProfile[SystemUptimeSec].ItemAccessibility = 1;
  14783. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SystemUptimeSec].ItemName, "SystemUptimeSec");
  14784. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SystemUptimeSec].ItemData, "0" );
  14785. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","SystemUptimeSec", "true", ShmOCPP16Data->ConfigurationTable.CoreProfile[SystemUptimeSec].ItemData);
  14786. // FreeVend
  14787. ShmOCPP16Data->ConfigurationTable.CoreProfile[FreeVend].ItemAccessibility = 1;
  14788. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[FreeVend].ItemName, "FreeVend");
  14789. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[FreeVend].ItemData, (ShmSysConfigAndInfo->SysConfig.AuthorisationMode?"TRUE":"FALSE") );
  14790. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","FreeVend", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[FreeVend].ItemData);
  14791. // FreeVendIdtag
  14792. ShmOCPP16Data->ConfigurationTable.CoreProfile[FreeVendIdtag].ItemAccessibility = 1;
  14793. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[FreeVendIdtag].ItemName, "FreeVendIdtag");
  14794. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[FreeVendIdtag].ItemData, "FreeVendIdtag" );
  14795. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","FreeVendIdtag", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[FreeVendIdtag].ItemData);
  14796. // OcppServer
  14797. ShmOCPP16Data->ConfigurationTable.CoreProfile[OcppServer].ItemAccessibility = 1;
  14798. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[OcppServer].ItemName, "OcppServer");
  14799. memcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[OcppServer].ItemData, (char*)ShmSysConfigAndInfo->SysConfig.OcppServerURL, 500);
  14800. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","OcppServer", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[OcppServer].ItemData);
  14801. // MaintainServer
  14802. ShmOCPP16Data->ConfigurationTable.CoreProfile[MaintainServer].ItemAccessibility = 1;
  14803. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MaintainServer].ItemName, "MaintainServer");
  14804. memcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MaintainServer].ItemData, (char*)ShmSysConfigAndInfo->SysConfig.MaintainServerURL, 500);
  14805. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MaintainServer", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[MaintainServer].ItemData);
  14806. // StatusNotificationPeriodically
  14807. ShmOCPP16Data->ConfigurationTable.CoreProfile[StatusNotificationPeriodically].ItemAccessibility = 1;
  14808. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StatusNotificationPeriodically].ItemName, "StatusNotificationPeriodically");
  14809. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StatusNotificationPeriodically].ItemData, "FALSE" );
  14810. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StatusNotificationPeriodically", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[StatusNotificationPeriodically].ItemData);
  14811. // StatusNotificationInterval
  14812. ShmOCPP16Data->ConfigurationTable.CoreProfile[StatusNotificationInterval].ItemAccessibility = 1;
  14813. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StatusNotificationInterval].ItemName, "StatusNotificationInterval");
  14814. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StatusNotificationInterval].ItemData, "120" );
  14815. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StatusNotificationInterval", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[StatusNotificationInterval].ItemData);
  14816. // PreAuthAmount
  14817. ShmOCPP16Data->ConfigurationTable.CoreProfile[PreAuthAmount].ItemAccessibility = 1;
  14818. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[PreAuthAmount].ItemName, "PreAuthAmount");
  14819. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[PreAuthAmount].ItemData, "888" );
  14820. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","PreAuthAmount", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[PreAuthAmount].ItemData);
  14821. // isEnableLocalPowerSharing
  14822. ShmOCPP16Data->ConfigurationTable.CoreProfile[isEnableLocalPowerSharing].ItemAccessibility = 1;
  14823. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[isEnableLocalPowerSharing].ItemName, "isEnableLocalPowerSharing");
  14824. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[isEnableLocalPowerSharing].ItemData, "%d", ShmSysConfigAndInfo->SysConfig.isEnableLocalPowerSharing);
  14825. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","isEnableLocalPowerSharing", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[isEnableLocalPowerSharing].ItemData);
  14826. // PowerSharingServerIP
  14827. ShmOCPP16Data->ConfigurationTable.CoreProfile[PowerSharingServerIP].ItemAccessibility = 1;
  14828. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[PowerSharingServerIP].ItemName, "PowerSharingServerIP");
  14829. memcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[PowerSharingServerIP].ItemData, (char*)ShmSysConfigAndInfo->SysConfig.PowerSharingServerIP, 500);
  14830. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","PowerSharingServerIP", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[PowerSharingServerIP].ItemData);
  14831. // EVCCID_PREFIX
  14832. ShmOCPP16Data->ConfigurationTable.CoreProfile[EVCCID_PREFIX].ItemAccessibility = 1;
  14833. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[EVCCID_PREFIX].ItemName, "EVCCID_PREFIX");
  14834. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[EVCCID_PREFIX].ItemData, "" );
  14835. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","EVCCID_PREFIX", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[EVCCID_PREFIX].ItemData);
  14836. // OffLineMaxChargingPower
  14837. ShmOCPP16Data->ConfigurationTable.CoreProfile[OffLineMaxChargingPower].ItemAccessibility = 1;
  14838. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[OffLineMaxChargingPower].ItemName, "OffLineMaxChargingPower");
  14839. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[OffLineMaxChargingPower].ItemData, "0" );
  14840. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","OffLineMaxChargingPower", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[OffLineMaxChargingPower].ItemData);
  14841. // Configuration Version
  14842. ShmOCPP16Data->ConfigurationTable.CoreProfile[ConfigurationVersion].ItemAccessibility = 0;
  14843. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConfigurationVersion].ItemName, "ConfigurationVersion");
  14844. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConfigurationVersion].ItemData, "%d", confVersion);
  14845. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ConfigurationVersion", "true", ShmOCPP16Data->ConfigurationTable.CoreProfile[ConfigurationVersion].ItemData);
  14846. // Charging profile refresh interval
  14847. ShmOCPP16Data->ConfigurationTable.CoreProfile[CharingProfileRefreshInterval].ItemAccessibility = 1;
  14848. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CharingProfileRefreshInterval].ItemName, "CharingProfileRefreshInterval");
  14849. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CharingProfileRefreshInterval].ItemData, "30");
  14850. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","CharingProfileRefreshInterval", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[CharingProfileRefreshInterval].ItemData);
  14851. // Ocpp Software certificated version
  14852. ShmOCPP16Data->ConfigurationTable.CoreProfile[OcppSoftwareVersion].ItemAccessibility = 0;
  14853. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[OcppSoftwareVersion].ItemName, "OcppSoftwareVersion");
  14854. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[OcppSoftwareVersion].ItemData, "%s", "V1.00");
  14855. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","OcppSoftwareVersion", "true", ShmOCPP16Data->ConfigurationTable.CoreProfile[OcppSoftwareVersion].ItemData);
  14856. //* Local Auth List Management Profile*/
  14857. #if 0
  14858. //For OCTT Test Case
  14859. ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemAccessibility = 1;
  14860. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemName, "LocalAuthorizationListEnabled");
  14861. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "TRUE" );
  14862. #endif
  14863. #if 1
  14864. //LocalAuthListEnabled
  14865. ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemAccessibility = 1;
  14866. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemName, "LocalAuthListEnabled");
  14867. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "TRUE" );
  14868. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LocalAuthListEnabled", "false", ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData);
  14869. #endif
  14870. //LocalAuthListMaxLength
  14871. ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemAccessibility = 0;
  14872. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemName, "LocalAuthListMaxLength");
  14873. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemData, "100000" );
  14874. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LocalAuthListMaxLength", "true", ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemData);
  14875. //SendLocalListMaxLength
  14876. ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemAccessibility = 0;
  14877. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemName, "SendLocalListMaxLength");
  14878. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemData, "1000" );
  14879. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","SendLocalListMaxLength", "true", ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemData);
  14880. //ReserveConnectorZeroSupported
  14881. ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemAccessibility = 0;
  14882. strcpy((char *)ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemName, "ReserveConnectorZeroSupported");
  14883. strcpy((char *)ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemData, "FALSE" );
  14884. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ReserveConnectorZeroSupported", "true", ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemData);
  14885. //* Smart Charging Profile */
  14886. //ChargeProfileMaxStackLevel
  14887. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemAccessibility = 0;
  14888. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemName, "ChargeProfileMaxStackLevel");
  14889. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemData, "8" );
  14890. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ChargeProfileMaxStackLevel", "true", ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemData);
  14891. // ChargingScheduleAllowedChargingRateUnit
  14892. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemAccessibility = 0;
  14893. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemName, "ChargingScheduleAllowedChargingRateUnit");
  14894. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemData, "Current,Power" );
  14895. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ChargingScheduleAllowedChargingRateUnit", "true", ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemData);
  14896. // ChargingScheduleMaxPeriods
  14897. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemAccessibility = 0;
  14898. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemName, "ChargingScheduleMaxPeriods");
  14899. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemData, "10" );
  14900. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ChargingScheduleMaxPeriods", "true", ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemData);
  14901. // ConnectorSwitch3to1PhaseSupported
  14902. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemAccessibility = 0;
  14903. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemName, "ConnectorSwitch3to1PhaseSupported");
  14904. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemData, "FALSE" );
  14905. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ConnectorSwitch3to1PhaseSupported", "true", ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemData);
  14906. // MaxChargingProfilesInstalled
  14907. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemAccessibility = 0;
  14908. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemName, "MaxChargingProfilesInstalled");
  14909. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemData, "50" );
  14910. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MaxChargingProfilesInstalled", "true", ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemData);
  14911. fclose(outfile);
  14912. }
  14913. else
  14914. {
  14915. //DEBUG_INFO("../Storage/OCPP/OCPPConfiguration EXit\n");
  14916. char keystr[60]={0};
  14917. char readonlystr[10]={0};
  14918. char valuestr[256]={0};
  14919. fp = fopen("/Storage/OCPP/OCPPConfiguration" , "r");
  14920. if(fp == NULL) {
  14921. DEBUG_INFO("Error opening file");
  14922. return FALSE;
  14923. }
  14924. while( fgets (str, ARRAY_SIZE(str), fp)!=NULL )
  14925. {
  14926. //DEBUG_INFO("Get Configuration \n");
  14927. if(strlen(str) > 0)
  14928. {
  14929. str[strlen(str) - 1] = '\0'; // eat the newline fgets() stores
  14930. //*************************key*********************************/
  14931. if(strstr(str, "key") != NULL)
  14932. {
  14933. loc = strstr(str, "key");
  14934. c = 0;
  14935. memset(sstr ,0, ARRAY_SIZE(sstr) );
  14936. while ((loc[strlen("key")+3+c] != '\"') && (c < (ARRAY_SIZE(sstr)-1)))
  14937. {
  14938. sstr[c] = loc[strlen("key")+3+c];
  14939. c++;
  14940. }
  14941. sstr[c] = '\0';
  14942. strcpy(keystr,sstr);
  14943. }
  14944. //*************************readonly*********************************/
  14945. if(strstr(str, "readonly") != NULL)
  14946. {
  14947. loc = strstr(str, "readonly");
  14948. c = 0;
  14949. memset(sstr ,0, ARRAY_SIZE(sstr) );
  14950. while ((loc[strlen("readonly")+2+c] != ',') && (c < (ARRAY_SIZE(sstr)-1)))
  14951. {
  14952. sstr[c] = loc[strlen("readonly")+2+c];
  14953. c++;
  14954. }
  14955. sstr[c] = '\0';
  14956. strcpy(readonlystr,sstr);
  14957. }
  14958. //*************************value*********************************/
  14959. if(strstr(str, "value") != NULL)
  14960. {
  14961. loc = strstr(str, "value");
  14962. c = 0;
  14963. memset(sstr ,0, ARRAY_SIZE(sstr) );
  14964. while ((loc[strlen("value")+3+c] != '\"') && (c < (ARRAY_SIZE(sstr)-1)))
  14965. {
  14966. sstr[c] = loc[strlen("value")+3+c];
  14967. c++;
  14968. }
  14969. sstr[c] = '\0';
  14970. strcpy(valuestr,sstr);
  14971. }
  14972. // DEBUG_INFO("keystr=%s\n",keystr);
  14973. // DEBUG_INFO("readonlystr=%s\n",readonlystr);
  14974. // DEBUG_INFO("valuestr=%s\n",valuestr);
  14975. if(strcmp(keystr, "AllowOfflineTxForUnknownId") == 0)
  14976. {
  14977. //Charger.AllowOfflineTxForUnknownId = (value.toLowerCase().equals("true")?true:false);
  14978. ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14979. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemData, "%s", valuestr );
  14980. // DEBUG_INFO("AllowOfflineTxForUnknownId setting\n");
  14981. // DEBUG_INFO("AllowOfflineTxForUnknownId setting\n");
  14982. }
  14983. if(strcmp(keystr, "AuthorizationCacheEnabled") == 0)
  14984. {
  14985. //Charger.AuthorizationCacheEnabled = (value.toLowerCase().equals("true")?true:false);
  14986. ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14987. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemData, "%s", valuestr );
  14988. }
  14989. if(strcmp(keystr, "AuthorizeRemoteTxRequests") == 0)
  14990. {
  14991. ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14992. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemData, "%s", valuestr );
  14993. }
  14994. if(strcmp(keystr, "BlinkRepeat") == 0)
  14995. {
  14996. //Charger.BlinkRepeat = Integer.parseInt(value);
  14997. ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14998. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemData, "%d", atoi(valuestr) );
  14999. }
  15000. if(strcmp(keystr, "ClockAlignedDataInterval") == 0)
  15001. {
  15002. ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  15003. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemData, "%d", atoi(valuestr) );
  15004. }
  15005. if(strcmp(keystr, "ConnectionTimeOut") == 0 )
  15006. {
  15007. ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  15008. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemData, "%d", atoi(valuestr));
  15009. }
  15010. if(strcmp(keystr, "GetConfigurationMaxKeys") == 0)
  15011. {
  15012. ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  15013. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemData, "%d", (atoi(valuestr)!=GetConfigurationMaxKeysNUM?GetConfigurationMaxKeysNUM:atoi(valuestr)));
  15014. }
  15015. if(strcmp(keystr, "HeartbeatInterval") == 0)
  15016. {
  15017. ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  15018. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemData, "%d", atoi(valuestr));
  15019. HeartBeatWaitTime = atoi(valuestr);
  15020. }
  15021. if(strcmp(keystr, "LightIntensity") == 0)
  15022. {
  15023. ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  15024. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemData, "%d", atoi(valuestr));
  15025. }
  15026. if(strcmp(keystr, "LocalAuthorizeOffline") == 0)
  15027. {
  15028. ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  15029. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemData, "%s", valuestr );
  15030. }
  15031. if(strcmp(keystr, "LocalPreAuthorize") == 0)
  15032. {
  15033. ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  15034. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemData, "%s", valuestr );
  15035. }
  15036. if(strcmp(keystr, "MaxEnergyOnInvalidId") == 0)
  15037. {
  15038. ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  15039. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemData, "%d", atoi(valuestr) );
  15040. }
  15041. if(strcmp(keystr, "MeterValuesAlignedData") == 0)
  15042. {
  15043. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  15044. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, "%s", valuestr );
  15045. }
  15046. if(strcmp(keystr, "MeterValuesAlignedDataMaxLength") == 0)
  15047. {
  15048. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  15049. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemData, "%d", atoi(valuestr));
  15050. }
  15051. if(strcmp(keystr, "MeterValuesSampledData") == 0 )
  15052. {
  15053. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  15054. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, "%s", valuestr );
  15055. }
  15056. if(strcmp(keystr, "MeterValuesSampledDataMaxLength") == 0)
  15057. {
  15058. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  15059. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemData, "%d", atoi(valuestr));
  15060. }
  15061. if(strcmp(keystr, "MeterValueSampleInterval") == 0)
  15062. {
  15063. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  15064. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemData, "%d", atoi(valuestr));
  15065. }
  15066. if(strcmp(keystr, "MinimumStatusDuration") == 0)
  15067. {
  15068. ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  15069. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemData, "%d", atoi(valuestr) );
  15070. server_cycle_Status = atoi(valuestr); //StatusNotification cycle
  15071. }
  15072. if(strcmp(keystr, "NumberOfConnectors") == 0)
  15073. {
  15074. ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  15075. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData, "%d", atoi(valuestr) );
  15076. }
  15077. if(strcmp(keystr, "ResetRetries") == 0)
  15078. {
  15079. ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  15080. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemData, "%d", atoi(valuestr) );
  15081. }
  15082. if(strcmp(keystr, "ConnectorPhaseRotation") == 0)
  15083. {
  15084. ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  15085. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "%s", valuestr );
  15086. }
  15087. if(strcmp(keystr, "ConnectorPhaseRotationMaxLength") == 0)
  15088. {
  15089. ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  15090. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemData, "%d", atoi(valuestr) );
  15091. }
  15092. if(strcmp(keystr, "StopTransactionOnEVSideDisconnect") == 0)
  15093. {
  15094. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  15095. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemData, "%s", valuestr );
  15096. }
  15097. if(strcmp(keystr, "StopTransactionOnInvalidId") == 0)
  15098. {
  15099. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  15100. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemData, "%s", valuestr );
  15101. }
  15102. if(strcmp(keystr, "StopTxnAlignedData") == 0)
  15103. {
  15104. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  15105. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemData, "%s", valuestr );
  15106. }
  15107. if(strcmp(keystr, "StopTxnAlignedDataMaxLength") == 0)
  15108. {
  15109. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  15110. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemData, "%d", atoi(valuestr) );
  15111. }
  15112. if(strcmp(keystr, "StopTxnSampledData") == 0)
  15113. {
  15114. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  15115. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "%s", valuestr );
  15116. }
  15117. if(strcmp(keystr, "StopTxnSampledDataMaxLength") == 0)
  15118. {
  15119. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  15120. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemData, "%d", atoi(valuestr) );
  15121. }
  15122. if(strcmp(keystr, "SupportedFeatureProfiles") == 0)
  15123. {
  15124. ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  15125. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemData, "%s", valuestr );
  15126. }
  15127. if(strcmp(keystr, "SupportedFeatureProfilesMaxLength") == 0)
  15128. {
  15129. ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  15130. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemData, "%d", atoi(valuestr) );
  15131. }
  15132. if(strcmp(keystr, "TransactionMessageAttempts") == 0)
  15133. {
  15134. ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  15135. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData, "%d", atoi(valuestr) );
  15136. TransactionMessageAttemptsValue = atoi(valuestr);
  15137. }
  15138. if(strcmp(keystr, "TransactionMessageRetryInterval") == 0)
  15139. {
  15140. ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemAccessibility= (strcmp(readonlystr, "true")==0) ? 0 : 1;
  15141. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData, "%d", atoi(valuestr) );
  15142. TransactionMessageRetryIntervalValue = atoi(valuestr);
  15143. }
  15144. if(strcmp(keystr, "UnlockConnectorOnEVSideDisconnect") == 0)
  15145. {
  15146. ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  15147. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemData, "%s", valuestr );
  15148. }
  15149. if(strcmp(keystr, "WebSocketPingInterval") == 0)
  15150. {
  15151. ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  15152. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemData, "%d", atoi(valuestr) );
  15153. }
  15154. if(strcmp(keystr, "QueueOffLineMeterValues") == 0)
  15155. {
  15156. ShmOCPP16Data->ConfigurationTable.CoreProfile[QueueOffLineMeterValues].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  15157. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[QueueOffLineMeterValues].ItemData, "%s", valuestr);
  15158. }
  15159. if(strcmp(keystr, "AuthorizationKey") == 0)
  15160. {
  15161. ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationKey].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  15162. //sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationKey].ItemData, "%s", valuestr);
  15163. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationKey].ItemData, "%s", ShmSysConfigAndInfo->SysConfig.OcppSecurityPassword);
  15164. }
  15165. if(strcmp(keystr, "SecurityProfile") == 0)
  15166. {
  15167. ShmOCPP16Data->ConfigurationTable.CoreProfile[SecurityProfile].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  15168. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SecurityProfile].ItemData, "%d", ShmSysConfigAndInfo->SysConfig.OcppSecurityProfile);
  15169. }
  15170. if(strcmp(keystr, "DefaultPrice") == 0)
  15171. {
  15172. ShmOCPP16Data->ConfigurationTable.CoreProfile[DefaultPrice].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  15173. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[DefaultPrice].ItemData, "%s", valuestr);
  15174. }
  15175. if(strcmp(keystr, "CustomDisplayCostAndPrice") == 0)
  15176. {
  15177. ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  15178. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemData, "%s", valuestr);
  15179. }
  15180. if(strcmp(keystr, "CustomIdleFeeAfterStop") == 0)
  15181. {
  15182. ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  15183. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemData, "%s", valuestr);
  15184. }
  15185. if(strcmp(keystr, "TimeOffset") == 0)
  15186. {
  15187. ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffset].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  15188. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffset].ItemData, "%s", valuestr);
  15189. }
  15190. if(strcmp(keystr, "NextTimeOffsetTransitionDateTime") == 0)
  15191. {
  15192. ShmOCPP16Data->ConfigurationTable.CoreProfile[NextTimeOffsetTransitionDateTime].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  15193. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NextTimeOffsetTransitionDateTime].ItemData, "%s", valuestr);
  15194. }
  15195. if(strcmp(keystr, "TimeOffsetNextTransition") == 0)
  15196. {
  15197. ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffsetNextTransition].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  15198. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffsetNextTransition].ItemData, "%s", valuestr);
  15199. }
  15200. if(strcmp(keystr, "SystemUptimeSec") == 0)
  15201. {
  15202. ShmOCPP16Data->ConfigurationTable.CoreProfile[SystemUptimeSec].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  15203. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SystemUptimeSec].ItemData, "%s", valuestr);
  15204. }
  15205. if(strcmp(keystr, "FreeVend") == 0)
  15206. {
  15207. ShmOCPP16Data->ConfigurationTable.CoreProfile[FreeVend].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  15208. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[FreeVend].ItemData, "%s", (ShmSysConfigAndInfo->SysConfig.AuthorisationMode ? "TRUE" : "FALSE"));
  15209. }
  15210. if(strcmp(keystr, "FreeVendIdtag") == 0)
  15211. {
  15212. ShmOCPP16Data->ConfigurationTable.CoreProfile[FreeVendIdtag].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  15213. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[FreeVendIdtag].ItemData, "%s", valuestr);
  15214. }
  15215. if(strcmp(keystr, "OcppServer") == 0)
  15216. {
  15217. ShmOCPP16Data->ConfigurationTable.CoreProfile[OcppServer].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  15218. memcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[OcppServer].ItemData, (char *)ShmSysConfigAndInfo->SysConfig.OcppServerURL, 500);
  15219. }
  15220. if(strcmp(keystr, "MaintainServer") == 0)
  15221. {
  15222. ShmOCPP16Data->ConfigurationTable.CoreProfile[MaintainServer].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  15223. memcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MaintainServer].ItemData, (char *)ShmSysConfigAndInfo->SysConfig.MaintainServerURL,500);
  15224. }
  15225. if(strcmp(keystr, "StatusNotificationPeriodically") == 0)
  15226. {
  15227. ShmOCPP16Data->ConfigurationTable.CoreProfile[StatusNotificationPeriodically].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  15228. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StatusNotificationPeriodically].ItemData, "%s", valuestr);
  15229. }
  15230. if(strcmp(keystr, "StatusNotificationInterval") == 0)
  15231. {
  15232. ShmOCPP16Data->ConfigurationTable.CoreProfile[StatusNotificationInterval].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  15233. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StatusNotificationInterval].ItemData, "%d", atoi(valuestr));
  15234. }
  15235. if(strcmp(keystr, "PreAuthAmount") == 0)
  15236. {
  15237. ShmOCPP16Data->ConfigurationTable.CoreProfile[PreAuthAmount].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  15238. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[PreAuthAmount].ItemData, "%.2f", atof(valuestr));
  15239. }
  15240. if(strcmp(keystr, "isEnableLocalPowerSharing") == 0)
  15241. {
  15242. ShmOCPP16Data->ConfigurationTable.CoreProfile[isEnableLocalPowerSharing].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  15243. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[isEnableLocalPowerSharing].ItemData, "%d", ShmSysConfigAndInfo->SysConfig.isEnableLocalPowerSharing);
  15244. }
  15245. if(strcmp(keystr, "PowerSharingServerIP") == 0)
  15246. {
  15247. ShmOCPP16Data->ConfigurationTable.CoreProfile[PowerSharingServerIP].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  15248. memcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[PowerSharingServerIP].ItemData, (char *)ShmSysConfigAndInfo->SysConfig.PowerSharingServerIP,500);
  15249. }
  15250. if(strcmp(keystr, "EVCCID_PREFIX") == 0)
  15251. {
  15252. ShmOCPP16Data->ConfigurationTable.CoreProfile[EVCCID_PREFIX].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  15253. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[EVCCID_PREFIX].ItemData, "%s", valuestr);
  15254. }
  15255. if(strcmp(keystr, "OffLineMaxChargingPower") == 0)
  15256. {
  15257. ShmOCPP16Data->ConfigurationTable.CoreProfile[OffLineMaxChargingPower].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  15258. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[OffLineMaxChargingPower].ItemData, "%s", valuestr);
  15259. }
  15260. if(strcmp(keystr, "ConfigurationVersion") == 0)
  15261. {
  15262. ShmOCPP16Data->ConfigurationTable.CoreProfile[ConfigurationVersion].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  15263. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConfigurationVersion].ItemData, "%d", atoi(valuestr));
  15264. }
  15265. if(strcmp(keystr, "CharingProfileRefreshInterval") == 0)
  15266. {
  15267. ShmOCPP16Data->ConfigurationTable.CoreProfile[CharingProfileRefreshInterval].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  15268. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CharingProfileRefreshInterval].ItemData, "%s", valuestr);
  15269. }
  15270. if(strcmp(keystr, "OcppSoftwareVersion") == 0)
  15271. {
  15272. ShmOCPP16Data->ConfigurationTable.CoreProfile[OcppSoftwareVersion].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  15273. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[OcppSoftwareVersion].ItemData, "%s", valuestr);
  15274. }
  15275. if(strcmp(keystr, "LocalAuthListEnabled") == 0)
  15276. {
  15277. ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  15278. sprintf((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "%s", valuestr );
  15279. }
  15280. if(strcmp(keystr, "LocalAuthListMaxLength") == 0)
  15281. {
  15282. ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  15283. sprintf((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemData, "%d", atoi(valuestr) );
  15284. }
  15285. if(strcmp(keystr, "SendLocalListMaxLength") == 0)
  15286. {
  15287. ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  15288. sprintf((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemData, "%d", atoi(valuestr) );
  15289. }
  15290. if(strcmp(keystr, "ReserveConnectorZeroSupported") == 0)
  15291. {
  15292. ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  15293. sprintf((char *)ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemData, "%s", valuestr );
  15294. }
  15295. if(strcmp(keystr, "ChargeProfileMaxStackLevel") == 0)
  15296. {
  15297. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  15298. sprintf((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemData, "%d", atoi(valuestr) );
  15299. }
  15300. if(strcmp(keystr, "ChargingScheduleAllowedChargingRateUnit") == 0)
  15301. {
  15302. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  15303. sprintf((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemData, "%s", valuestr );
  15304. }
  15305. if(strcmp(keystr, "ChargingScheduleMaxPeriods") == 0)
  15306. {
  15307. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  15308. sprintf((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemData, "%d", atoi(valuestr) );
  15309. }
  15310. if(strcmp(keystr, "ConnectorSwitch3to1PhaseSupported") == 0)
  15311. {
  15312. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  15313. sprintf((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemData, "%s", valuestr);
  15314. }
  15315. if(strcmp(keystr, "MaxChargingProfilesInstalled") == 0)
  15316. {
  15317. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  15318. sprintf((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemData, "%d", atoi(valuestr) );
  15319. }
  15320. }
  15321. }
  15322. fclose(fp);
  15323. }
  15324. if(atoi((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConfigurationVersion].ItemData) == confVersion)
  15325. {
  15326. return PASS;
  15327. }
  15328. else
  15329. {
  15330. return FAIL;
  15331. }
  15332. }
  15333. void StoreConfigurationTable(void)
  15334. {
  15335. FILE *outfile;
  15336. outfile = fopen("/Storage/OCPP/OCPPConfiguration" , "w+");
  15337. if(outfile == NULL)
  15338. {
  15339. DEBUG_INFO("Error opening file");
  15340. return ;
  15341. }
  15342. /*Core Profile*/
  15343. //AllowOfflineTxForUnknownId
  15344. /*
  15345. ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemAccessibility = 1;
  15346. printf("AllowoddlineTXForUnknownId type: %d \n", ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemAccessibility);
  15347. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemName, "AllowOfflineTxForUnknownId");
  15348. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemData, "TRUE" );
  15349. */
  15350. //DEBUG_INFO("data=%s\n",data);
  15351. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","AllowOfflineTxForUnknownId", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemData);
  15352. //AuthorizationCacheEnabled
  15353. /*
  15354. ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemAccessibility = 1;
  15355. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemName, "AuthorizationCacheEnabled");
  15356. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemData, "FALSE" );
  15357. */
  15358. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","AuthorizationCacheEnabled", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemData);
  15359. //AuthorizeRemoteTxRequests
  15360. /*
  15361. ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemAccessibility = 0;
  15362. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemName, "AuthorizeRemoteTxRequests");
  15363. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemData, "TRUE" );
  15364. */
  15365. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","AuthorizeRemoteTxRequests", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemData);
  15366. //BlinkRepeat
  15367. /*
  15368. ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemAccessibility = 1;
  15369. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemName, "BlinkRepeat");
  15370. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemData, "0" );
  15371. */
  15372. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","BlinkRepeat", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemData);
  15373. //ClockAlignedDataInterval
  15374. /*
  15375. ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemAccessibility = 1;
  15376. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemName, "ClockAlignedDataInterval");
  15377. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemData, "0" );
  15378. */
  15379. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ClockAlignedDataInterval", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemData);
  15380. //ConnectionTimeOut
  15381. /*
  15382. ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemAccessibility = 1;
  15383. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemName, "ConnectionTimeOut");
  15384. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemData, "180" );
  15385. */
  15386. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ConnectionTimeOut", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemData);
  15387. //GetConfigurationMaxKeys
  15388. /*
  15389. ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemAccessibility =0;
  15390. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemName, "GetConfigurationMaxKeys");
  15391. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemData, "43" );
  15392. */
  15393. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","GetConfigurationMaxKeys", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemData);
  15394. // HeartbeatInterval
  15395. /*
  15396. ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemAccessibility = 1;
  15397. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemName, "HeartbeatInterval");
  15398. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemData, "10" );
  15399. */
  15400. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","HeartbeatInterval", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemData);
  15401. // LightIntensity
  15402. /*
  15403. ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemAccessibility = 1;
  15404. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemName, "LightIntensity");
  15405. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemData, "0" );
  15406. */
  15407. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LightIntensity", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemData);
  15408. // LocalAuthorizeOffline
  15409. /*
  15410. ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemAccessibility = 0;
  15411. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemName, "LocalAuthorizeOffline");
  15412. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemData, "TRUE" );
  15413. */
  15414. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LocalAuthorizeOffline", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemData);
  15415. // LocalPreAuthorize
  15416. /*
  15417. ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemAccessibility = 0;
  15418. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemName, "LocalPreAuthorize");
  15419. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemData, "FALSE" );
  15420. */
  15421. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LocalPreAuthorize", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemData);
  15422. // MaxEnergyOnInvalidId
  15423. /*
  15424. ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemAccessibility = 1;
  15425. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemName, "MaxEnergyOnInvalidId");
  15426. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemData, "0" );
  15427. */
  15428. //ShmSysConfigAndInfo->SysConfig.OfflineMaxChargeEnergy = 0;
  15429. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MaxEnergyOnInvalidId", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemData);
  15430. // MeterValuesAlignedData
  15431. /*
  15432. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemAccessibility = 1;
  15433. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemName, "MeterValuesAlignedData");
  15434. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, "Current.Export,Energy.Active.Export.Interval,Power.Active.Export,Voltage,SOC" );
  15435. */
  15436. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValuesAlignedData", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData);
  15437. // MeterValuesAlignedDataMaxLength
  15438. /*
  15439. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemAccessibility = 0;
  15440. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemName, "MeterValuesAlignedDataMaxLength");
  15441. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemData, "5" );
  15442. */
  15443. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValuesAlignedDataMaxLength", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemData);
  15444. // MeterValuesSampledData
  15445. /*
  15446. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemAccessibility = 1;
  15447. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemName, "MeterValuesSampledData");
  15448. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, "Current.Export,Energy.Active.Export.Interval,Power.Active.Export,Voltage,SOC" );
  15449. */
  15450. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValuesSampledData", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData);
  15451. // MeterValuesSampledDataMaxLength
  15452. /*
  15453. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemAccessibility = 0;
  15454. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemName, "MeterValuesSampledDataMaxLength");
  15455. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemData, "5" );
  15456. */
  15457. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValuesSampledDataMaxLength", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemData);
  15458. // MeterValueSampleInterval
  15459. /*
  15460. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemAccessibility = 1;
  15461. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemName, "MeterValueSampleInterval");
  15462. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemData, "10" );
  15463. */
  15464. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValueSampleInterval", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemData);
  15465. // MinimumStatusDuration
  15466. /*
  15467. ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemAccessibility = 1;
  15468. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemName, "MinimumStatusDuration");
  15469. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemData, "0" );
  15470. */
  15471. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MinimumStatusDuration", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemData);
  15472. // NumberOfConnectors
  15473. /*
  15474. ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemAccessibility = 0;
  15475. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemName, "NumberOfConnectors");
  15476. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  15477. {
  15478. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData, "%d", (CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY));
  15479. }
  15480. else
  15481. {
  15482. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData, "%d", AC_QUANTITY);
  15483. }
  15484. */
  15485. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","NumberOfConnectors", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData);
  15486. // ResetRetries
  15487. /*
  15488. ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemAccessibility = 1;
  15489. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemName, "ResetRetries");
  15490. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemData, "3" );
  15491. */
  15492. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ResetRetries", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemData);
  15493. // ConnectorPhaseRotation
  15494. /*
  15495. ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemAccessibility = 1;
  15496. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemName, "ConnectorPhaseRotation");
  15497. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "NotApplicable" );
  15498. */
  15499. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ConnectorPhaseRotation", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData);
  15500. // ConnectorPhaseRotationMaxLength
  15501. /*
  15502. ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemAccessibility = 0;
  15503. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemName, "ConnectorPhaseRotationMaxLength");
  15504. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemData, "1" );
  15505. */
  15506. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ConnectorPhaseRotationMaxLength", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemData);
  15507. // StopTransactionOnEVSideDisconnect
  15508. /*
  15509. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemAccessibility = 0;
  15510. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemName, "StopTransactionOnEVSideDisconnect");
  15511. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemData, "TRUE" );
  15512. */
  15513. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTransactionOnEVSideDisconnect", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemData);
  15514. // StopTransactionOnInvalidId
  15515. /*
  15516. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemAccessibility = 0;
  15517. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemName, "StopTransactionOnInvalidId");
  15518. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemData, "FALSE" );
  15519. */
  15520. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTransactionOnInvalidId", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemData);
  15521. // StopTxnAlignedData
  15522. /*
  15523. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemAccessibility = 1;
  15524. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemName, "StopTxnAlignedData");
  15525. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemData, "Energy.Active.Import.Register" );
  15526. */
  15527. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTxnAlignedData", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemData);
  15528. // StopTxnAlignedDataMaxLength
  15529. /*
  15530. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemAccessibility = 0;
  15531. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemName, "StopTxnAlignedDataMaxLength");
  15532. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemData, "0" );
  15533. */
  15534. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTxnAlignedDataMaxLength", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemData);
  15535. // StopTxnSampledData
  15536. /*
  15537. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemAccessibility = 1;
  15538. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemName, "StopTxnSampledData");
  15539. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Energy.Active.Import.Register" );
  15540. */
  15541. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTxnSampledData", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData);
  15542. // StopTxnSampledDataMaxLength
  15543. /*
  15544. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemAccessibility = 0;
  15545. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemName, "StopTxnSampledDataMaxLength");
  15546. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemData, "0" );
  15547. */
  15548. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTxnSampledDataMaxLength", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemData);
  15549. // SupportedFeatureProfiles
  15550. /*
  15551. ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemAccessibility = 0;
  15552. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemName, "SupportedFeatureProfiles");
  15553. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemData, "Core,FirmwareManagement,LocalAuthListManagement,Reservation,SmartCharging,RemoteTrigger" );
  15554. */
  15555. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","SupportedFeatureProfiles", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemData);
  15556. // SupportedFeatureProfilesMaxLength
  15557. /*
  15558. ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemAccessibility = 0;
  15559. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemName, "SupportedFeatureProfilesMaxLength");
  15560. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemData, "6" );
  15561. */
  15562. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","SupportedFeatureProfilesMaxLength", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemData);
  15563. // TransactionMessageAttempts
  15564. /*
  15565. ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemAccessibility = 1;
  15566. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemName, "TransactionMessageAttempts");
  15567. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData, "3" );
  15568. */
  15569. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","TransactionMessageAttempts", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData);
  15570. // TransactionMessageRetryInterval
  15571. /*
  15572. ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemAccessibility = 1;
  15573. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemName, "TransactionMessageRetryInterval");
  15574. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData, "60" );
  15575. */
  15576. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","TransactionMessageRetryInterval", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData);
  15577. // UnlockConnectorOnEVSideDisconnect
  15578. /*
  15579. ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemAccessibility = 0;
  15580. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemName, "UnlockConnectorOnEVSideDisconnect");
  15581. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemData, "TRUE" );
  15582. */
  15583. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","UnlockConnectorOnEVSideDisconnect", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemData);
  15584. // WebSocketPingInterval
  15585. /*
  15586. ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemAccessibility = 1;
  15587. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemName, "WebSocketPingInterval");
  15588. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemData, "30" );
  15589. */
  15590. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","WebSocketPingInterval", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemData);
  15591. // QueueOffLineMeterValues
  15592. /*
  15593. ShmOCPP16Data->ConfigurationTable.CoreProfile[QueueOffLineMeterValues].ItemAccessibility = 0;
  15594. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[QueueOffLineMeterValues].ItemName, "QueueOffLineMeterValues");
  15595. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[QueueOffLineMeterValues].ItemData, "TRUE" );
  15596. */
  15597. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","QueueOffLineMeterValues", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[QueueOffLineMeterValues].ItemData);
  15598. // AuthorizationKey
  15599. /*
  15600. ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationKey].ItemAccessibility = 1;
  15601. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationKey].ItemName, "AuthorizationKey");
  15602. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationKey].ItemData, "0" );
  15603. */
  15604. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","AuthorizationKey", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationKey].ItemData);
  15605. // SecurityProfile
  15606. /*
  15607. ShmOCPP16Data->ConfigurationTable.CoreProfile[SecurityProfile].ItemAccessibility = 1;
  15608. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SecurityProfile].ItemName, "SecurityProfile");
  15609. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SecurityProfile].ItemData, "30" );
  15610. */
  15611. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","SecurityProfile", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SecurityProfile].ItemData);
  15612. // DefaultPrice
  15613. /*
  15614. ShmOCPP16Data->ConfigurationTable.CoreProfile[DefaultPrice].ItemAccessibility = 1;
  15615. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[DefaultPrice].ItemName, "DefaultPrice");
  15616. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[DefaultPrice].ItemData, "" );
  15617. */
  15618. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","DefaultPrice", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[DefaultPrice].ItemData);
  15619. // CustomDisplayCostAndPrice
  15620. /*
  15621. ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemAccessibility = 1;
  15622. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemName, "CustomDisplayCostAndPrice");
  15623. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemData, "FALSE" );
  15624. */
  15625. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","CustomDisplayCostAndPrice", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemData);
  15626. // CustomIdleFeeAfterStop
  15627. /*
  15628. ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemAccessibility = 1;
  15629. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemName, "CustomIdleFeeAfterStop");
  15630. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemData, "FALSE" );
  15631. */
  15632. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","CustomIdleFeeAfterStop", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemData);
  15633. // TimeOffset
  15634. /*
  15635. ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffset].ItemAccessibility = 1;
  15636. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffset].ItemName, "TimeOffset");
  15637. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffset].ItemData, "FALSE" );
  15638. */
  15639. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","TimeOffset", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffset].ItemData);
  15640. // NextTimeOffsetTransitionDateTime
  15641. /*
  15642. ShmOCPP16Data->ConfigurationTable.CoreProfile[NextTimeOffsetTransitionDateTime].ItemAccessibility = 1;
  15643. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NextTimeOffsetTransitionDateTime].ItemName, "NextTimeOffsetTransitionDateTime");
  15644. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NextTimeOffsetTransitionDateTime].ItemData, "FALSE" );
  15645. */
  15646. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","NextTimeOffsetTransitionDateTime", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NextTimeOffsetTransitionDateTime].ItemData);
  15647. // TimeOffsetNextTransition
  15648. /*
  15649. ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffsetNextTransition].ItemAccessibility = 1;
  15650. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffsetNextTransition].ItemName, "TimeOffsetNextTransition");
  15651. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffsetNextTransition].ItemData, "FALSE" );
  15652. */
  15653. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","TimeOffsetNextTransition", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffsetNextTransition].ItemData);
  15654. // SystemUptimeSec
  15655. /*
  15656. ShmOCPP16Data->ConfigurationTable.CoreProfile[SystemUptimeSec].ItemAccessibility = 1;
  15657. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SystemUptimeSec].ItemName, "SystemUptimeSec");
  15658. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SystemUptimeSec].ItemData, "0" );
  15659. */
  15660. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","SystemUptimeSec", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SystemUptimeSec].ItemData);
  15661. // FreeVend
  15662. /*
  15663. ShmOCPP16Data->ConfigurationTable.CoreProfile[FreeVend].ItemAccessibility = 1;
  15664. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[FreeVend].ItemName, "FreeVend");
  15665. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[FreeVend].ItemData, "FALSE" );
  15666. */
  15667. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","FreeVend", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[FreeVend].ItemData);
  15668. // FreeVendIdtag
  15669. /*
  15670. ShmOCPP16Data->ConfigurationTable.CoreProfile[FreeVendIdtag].ItemAccessibility = 1;
  15671. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[FreeVendIdtag].ItemName, "FreeVendIdtag");
  15672. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[FreeVendIdtag].ItemData, "FreeVendIdtag" );
  15673. */
  15674. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","FreeVendIdtag", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[FreeVendIdtag].ItemData);
  15675. // OcppServer
  15676. /*
  15677. ShmOCPP16Data->ConfigurationTable.CoreProfile[OcppServer].ItemAccessibility = 1;
  15678. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[OcppServer].ItemName, "OcppServer");
  15679. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[OcppServer].ItemData, "FALSE" );
  15680. */
  15681. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","OcppServer", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[OcppServer].ItemData);
  15682. // MaintainServer
  15683. /*
  15684. ShmOCPP16Data->ConfigurationTable.CoreProfile[MaintainServer].ItemAccessibility = 1;
  15685. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MaintainServer].ItemName, "MaintainServer");
  15686. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MaintainServer].ItemData, "FALSE" );
  15687. */
  15688. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MaintainServer", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MaintainServer].ItemData);
  15689. // StatusNotificationPeriodically
  15690. /*
  15691. ShmOCPP16Data->ConfigurationTable.CoreProfile[StatusNotificationPeriodically].ItemAccessibility =0;
  15692. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StatusNotificationPeriodically].ItemName, "StatusNotificationPeriodically");
  15693. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StatusNotificationPeriodically].ItemData, "FALSE" );
  15694. */
  15695. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StatusNotificationPeriodically", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StatusNotificationPeriodically].ItemData);
  15696. // StatusNotificationInterval
  15697. /*
  15698. ShmOCPP16Data->ConfigurationTable.CoreProfile[StatusNotificationInterval].ItemAccessibility = 1;
  15699. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StatusNotificationInterval].ItemName, "StatusNotificationInterval");
  15700. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StatusNotificationInterval].ItemData, "120" );
  15701. */
  15702. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StatusNotificationInterval", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StatusNotificationInterval].ItemData);
  15703. // PreAuthAmount
  15704. /*
  15705. ShmOCPP16Data->ConfigurationTable.CoreProfile[PreAuthAmount].ItemAccessibility = 1;
  15706. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[PreAuthAmount].ItemName, "PreAuthAmount");
  15707. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[PreAuthAmount].ItemData, "120" );
  15708. */
  15709. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","PreAuthAmount", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[PreAuthAmount].ItemData);
  15710. // isEnableLocalPowerSharing
  15711. /*
  15712. ShmOCPP16Data->ConfigurationTable.CoreProfile[isEnableLocalPowerSharing].ItemAccessibility = 1;
  15713. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[isEnableLocalPowerSharing].ItemName, "isEnableLocalPowerSharing");
  15714. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[isEnableLocalPowerSharing].ItemData, "0" );
  15715. */
  15716. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","isEnableLocalPowerSharing", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[isEnableLocalPowerSharing].ItemData);
  15717. // PowerSharingServerIP
  15718. /*
  15719. ShmOCPP16Data->ConfigurationTable.CoreProfile[PowerSharingServerIP].ItemAccessibility = 1;
  15720. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[PowerSharingServerIP].ItemName, "PowerSharingServerIP");
  15721. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[PowerSharingServerIP].ItemData, "" );
  15722. */
  15723. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","PowerSharingServerIP", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[PowerSharingServerIP].ItemData);
  15724. // EVCCID_PREFIX
  15725. /*
  15726. ShmOCPP16Data->ConfigurationTable.CoreProfile[EVCCID_PREFIX].ItemAccessibility = 1;
  15727. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[EVCCID_PREFIX].ItemName, "EVCCID_PREFIX");
  15728. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[EVCCID_PREFIX].ItemData, "" );
  15729. */
  15730. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","EVCCID_PREFIX", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[EVCCID_PREFIX].ItemData);
  15731. // OffLineMaxChargingPower
  15732. /*
  15733. ShmOCPP16Data->ConfigurationTable.CoreProfile[OffLineMaxChargingPower].ItemAccessibility = 1;
  15734. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[OffLineMaxChargingPower].ItemName, "OffLineMaxChargingPower");
  15735. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[OffLineMaxChargingPower].ItemData, "" );
  15736. */
  15737. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","OffLineMaxChargingPower", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[OffLineMaxChargingPower].ItemData);
  15738. // ConfigurationVersion
  15739. /*
  15740. ShmOCPP16Data->ConfigurationTable.CoreProfile[ConfigurationVersion].ItemAccessibility = 1;
  15741. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConfigurationVersion].ItemName, "ConfigurationVersion");
  15742. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConfigurationVersion].ItemData, "1" );
  15743. */
  15744. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ConfigurationVersion", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConfigurationVersion].ItemData);
  15745. // CharingProfileRefreshInterval
  15746. /*
  15747. ShmOCPP16Data->ConfigurationTable.CoreProfile[CharingProfileRefreshInterval].ItemAccessibility = 1;
  15748. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CharingProfileRefreshInterval].ItemName, "CharingProfileRefreshInterval");
  15749. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CharingProfileRefreshInterval].ItemData, "" );
  15750. */
  15751. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","CharingProfileRefreshInterval", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CharingProfileRefreshInterval].ItemData);
  15752. // OcppSoftwareVersion
  15753. /*
  15754. ShmOCPP16Data->ConfigurationTable.CoreProfile[OcppSoftwareVersion].ItemAccessibility = 1;
  15755. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[OcppSoftwareVersion].ItemName, "OcppSoftwareVersion");
  15756. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[OcppSoftwareVersion].ItemData, "" );
  15757. */
  15758. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","OcppSoftwareVersion", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[OcppSoftwareVersion].ItemData);
  15759. //* Local Auth List Management Profile*/
  15760. //LocalAuthListEnabled
  15761. /*
  15762. ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemAccessibility = 1;
  15763. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemName, "LocalAuthListEnabled");
  15764. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "TRUE" );
  15765. */
  15766. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LocalAuthListEnabled", "false", (char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData);
  15767. //LocalAuthListMaxLength
  15768. /*
  15769. ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemAccessibility = 0;
  15770. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemName, "LocalAuthListMaxLength");
  15771. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemData, "500" );
  15772. */
  15773. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LocalAuthListMaxLength", "true", (char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemData);
  15774. //SendLocalListMaxLength
  15775. /*
  15776. ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemAccessibility = 0;
  15777. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemName, "SendLocalListMaxLength");
  15778. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemData, "500" );
  15779. */
  15780. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","SendLocalListMaxLength", "true", (char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemData);
  15781. //ReserveConnectorZeroSupported
  15782. /*
  15783. ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemAccessibility = 0;
  15784. strcpy((char *)ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemName, "ReserveConnectorZeroSupported");
  15785. strcpy((char *)ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemData, "FALSE" );
  15786. */
  15787. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ReserveConnectorZeroSupported", "true", (char *)ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemData);
  15788. //* Smart Charging Profile */
  15789. //ChargeProfileMaxStackLevel
  15790. /*
  15791. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemAccessibility = 0;
  15792. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemName, "ChargeProfileMaxStackLevel");
  15793. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemData, "3" );
  15794. */
  15795. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ChargeProfileMaxStackLevel", "true", (char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemData);
  15796. // ChargingScheduleAllowedChargingRateUnit
  15797. /*
  15798. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemAccessibility = 0;
  15799. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemName, "ChargingScheduleAllowedChargingRateUnit");
  15800. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemData, "Current" );
  15801. */
  15802. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ChargingScheduleAllowedChargingRateUnit", "true", (char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemData);
  15803. // ChargingScheduleMaxPeriods
  15804. /*
  15805. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemAccessibility = 0;
  15806. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemName, "ChargingScheduleMaxPeriods");
  15807. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemData, "10" );
  15808. */
  15809. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ChargingScheduleMaxPeriods", "true", (char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemData);
  15810. // ConnectorSwitch3to1PhaseSupported
  15811. /*
  15812. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemAccessibility = 0;
  15813. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemName, "ConnectorSwitch3to1PhaseSupported");
  15814. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemData, "TRUE" );
  15815. */
  15816. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ConnectorSwitch3to1PhaseSupported", "true", (char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemData);
  15817. // MaxChargingProfilesInstalled
  15818. /*
  15819. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemAccessibility = 0;
  15820. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemName, "MaxChargingProfilesInstalled");
  15821. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemData, "10" );
  15822. */
  15823. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MaxChargingProfilesInstalled", "true", (char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemData);
  15824. fclose(outfile);
  15825. system("/bin/fsync -d /dev/mtdblock13;/bin/sync &");
  15826. }
  15827. void getKeyValue(char *keyReq)
  15828. {
  15829. int isEmpty = FALSE;
  15830. int isKnowKey = FALSE;
  15831. DEBUG_INFO("keyReq = %s\n", keyReq);
  15832. if((keyReq == NULL) || (strlen(keyReq) == 0))
  15833. isEmpty = TRUE;
  15834. if(isEmpty || strcmp(keyReq, "AllowOfflineTxForUnknownId") == 0)
  15835. {
  15836. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_AllowOfflineTxForUnknownId].Item, "AllowOfflineTxForUnknownId");
  15837. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AllowOfflineTxForUnknownId].Key, "AllowOfflineTxForUnknownId");
  15838. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemAccessibility == 1)
  15839. {
  15840. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AllowOfflineTxForUnknownId].ReadOnly, "0"/*"FALSE"*/);
  15841. }
  15842. else
  15843. {
  15844. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AllowOfflineTxForUnknownId].ReadOnly, "1"/*"TRUE"*/);
  15845. }
  15846. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AllowOfflineTxForUnknownId].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemData );
  15847. isKnowKey = TRUE;
  15848. }
  15849. if(isEmpty || strcmp(keyReq, "AuthorizationCacheEnabled") == 0 )
  15850. {
  15851. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_AuthorizationCacheEnabled].Item, "AuthorizationCacheEnabled");
  15852. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizationCacheEnabled].Key, "AuthorizationCacheEnabled");
  15853. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemAccessibility == 1)
  15854. {
  15855. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizationCacheEnabled].ReadOnly, "0"/*"FALSE"*/);
  15856. }
  15857. else
  15858. {
  15859. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizationCacheEnabled].ReadOnly, "1"/*"TRUE"*/);
  15860. }
  15861. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizationCacheEnabled].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemData );
  15862. isKnowKey = TRUE;
  15863. }
  15864. if(isEmpty || strcmp(keyReq, "AuthorizeRemoteTxRequests") == 0 )
  15865. {
  15866. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_AuthorizeRemoteTxRequests].Item, "AuthorizeRemoteTxRequests");
  15867. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizeRemoteTxRequests].Key, "AuthorizeRemoteTxRequests");
  15868. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemAccessibility == 1)
  15869. {
  15870. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizeRemoteTxRequests].ReadOnly, "0"/*"FALSE"*/);
  15871. }
  15872. else
  15873. {
  15874. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizeRemoteTxRequests].ReadOnly, "1"/*"TRUE"*/);
  15875. }
  15876. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizeRemoteTxRequests].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemData );
  15877. isKnowKey = TRUE;
  15878. }
  15879. if(isEmpty || strcmp(keyReq, "BlinkRepeat") == 0 )
  15880. {
  15881. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_BlinkRepeat].Item, "BlinkRepeat");
  15882. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_BlinkRepeat].Key, "BlinkRepeat");
  15883. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemAccessibility == 1)
  15884. {
  15885. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_BlinkRepeat].ReadOnly, "0"/*"FALSE"*/);
  15886. }
  15887. else
  15888. {
  15889. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_BlinkRepeat].ReadOnly, "1"/*"TRUE"*/);
  15890. }
  15891. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_BlinkRepeat].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemData );
  15892. isKnowKey = TRUE;
  15893. }
  15894. if(isEmpty || strcmp(keyReq, "ClockAlignedDataInterval") == 0 )
  15895. {
  15896. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_ClockAlignedDataInterval].Item, "ClockAlignedDataInterval");
  15897. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ClockAlignedDataInterval].Key, "ClockAlignedDataInterval");
  15898. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemAccessibility == 1)
  15899. {
  15900. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ClockAlignedDataInterval].ReadOnly, "0"/*"FALSE"*/);
  15901. }
  15902. else
  15903. {
  15904. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ClockAlignedDataInterval].ReadOnly, "1"/*"TRUE"*/);
  15905. }
  15906. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ClockAlignedDataInterval].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemData );
  15907. isKnowKey = TRUE;
  15908. }
  15909. if(isEmpty || strcmp(keyReq, "ConnectionTimeOut") == 0 )
  15910. {
  15911. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_ConnectionTimeOut].Item, "ConnectionTimeOut");
  15912. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectionTimeOut].Key, "ConnectionTimeOut");
  15913. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemAccessibility == 1)
  15914. {
  15915. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectionTimeOut].ReadOnly, "0"/*"FALSE"*/);
  15916. }
  15917. else
  15918. {
  15919. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectionTimeOut].ReadOnly, "1"/*"TRUE"*/);
  15920. }
  15921. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectionTimeOut].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemData );
  15922. isKnowKey = TRUE;
  15923. }
  15924. if(isEmpty || strcmp(keyReq, "GetConfigurationMaxKeys") == 0 )
  15925. {
  15926. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_GetConfigurationMaxKeys].Item, "GetConfigurationMaxKeys");
  15927. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_GetConfigurationMaxKeys].Key, "GetConfigurationMaxKeys");
  15928. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemAccessibility == 1)
  15929. {
  15930. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_GetConfigurationMaxKeys].ReadOnly, "0"/*"FALSE"*/);
  15931. }
  15932. else
  15933. {
  15934. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_GetConfigurationMaxKeys].ReadOnly, "1"/*"TRUE"*/);
  15935. }
  15936. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_GetConfigurationMaxKeys].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemData );
  15937. isKnowKey = TRUE;
  15938. }
  15939. if(isEmpty || strcmp(keyReq, "HeartbeatInterval") == 0 )
  15940. {
  15941. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_HeartbeatInterval].Item, "HeartbeatInterval");
  15942. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_HeartbeatInterval].Key, "HeartbeatInterval");
  15943. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemAccessibility == 1)
  15944. {
  15945. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_HeartbeatInterval].ReadOnly, "0"/*"FALSE"*/);
  15946. }
  15947. else
  15948. {
  15949. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_HeartbeatInterval].ReadOnly, "1"/*"TRUE"*/);
  15950. }
  15951. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_HeartbeatInterval].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemData );
  15952. isKnowKey = TRUE;
  15953. }
  15954. if(isEmpty || strcmp(keyReq, "LightIntensity") == 0 )
  15955. {
  15956. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_LightIntensity].Item, "LightIntensity");
  15957. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LightIntensity].Key, "LightIntensity");
  15958. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemAccessibility == 1)
  15959. {
  15960. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LightIntensity].ReadOnly, "0"/*"FALSE"*/);
  15961. }
  15962. else
  15963. {
  15964. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LightIntensity].ReadOnly, "1"/*"TRUE"*/);
  15965. }
  15966. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LightIntensity].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemData );
  15967. isKnowKey = TRUE;
  15968. }
  15969. if(isEmpty || strcmp(keyReq, "LocalAuthorizeOffline") == 0 )
  15970. {
  15971. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_LocalAuthorizeOffline].Item, "LocalAuthorizeOffline");
  15972. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthorizeOffline].Key, "LocalAuthorizeOffline");
  15973. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemAccessibility == 1)
  15974. {
  15975. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthorizeOffline].ReadOnly, "0"/*"FALSE"*/);
  15976. }
  15977. else
  15978. {
  15979. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthorizeOffline].ReadOnly, "1"/*"TRUE"*/);
  15980. }
  15981. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthorizeOffline].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemData );
  15982. isKnowKey = TRUE;
  15983. }
  15984. if(isEmpty || strcmp(keyReq, "LocalPreAuthorize") == 0 )
  15985. {
  15986. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_LocalPreAuthorize].Item, "LocalPreAuthorize");
  15987. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalPreAuthorize].Key, "LocalPreAuthorize");
  15988. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemAccessibility == 1)
  15989. {
  15990. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalPreAuthorize].ReadOnly, "0"/*"FALSE"*/);
  15991. }
  15992. else
  15993. {
  15994. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalPreAuthorize].ReadOnly, "1"/*"TRUE"*/);
  15995. }
  15996. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalPreAuthorize].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemData );
  15997. isKnowKey = TRUE;
  15998. }
  15999. if(isEmpty || strcmp(keyReq, "MaxEnergyOnInvalidId") == 0 )
  16000. {
  16001. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_MaxEnergyOnInvalidId].Item, "MaxEnergyOnInvalidId");
  16002. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaxEnergyOnInvalidId].Key, "MaxEnergyOnInvalidId");
  16003. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemAccessibility == 1)
  16004. {
  16005. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaxEnergyOnInvalidId].ReadOnly, "0"/*"FALSE"*/);
  16006. }
  16007. else
  16008. {
  16009. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaxEnergyOnInvalidId].ReadOnly, "1"/*"TRUE"*/);
  16010. }
  16011. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaxEnergyOnInvalidId].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemData );
  16012. isKnowKey = TRUE;
  16013. }
  16014. if(isEmpty || strcmp(keyReq, "MeterValuesAlignedData") == 0 )
  16015. {
  16016. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_MeterValuesAlignedData].Item, "MeterValuesAlignedData");
  16017. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesAlignedData].Key, "MeterValuesAlignedData");
  16018. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemAccessibility == 1)
  16019. {
  16020. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesAlignedData].ReadOnly, "0"/*"FALSE"*/);
  16021. }
  16022. else
  16023. {
  16024. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesAlignedData].ReadOnly, "1"/*"TRUE"*/);
  16025. }
  16026. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesAlignedData].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData );
  16027. isKnowKey = TRUE;
  16028. }
  16029. if(isEmpty || strcmp(keyReq, "MeterValuesAlignedDataMaxLength") == 0 )
  16030. {
  16031. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_MeterValuesAlignedDataMaxLength].Item, "MeterValuesAlignedDataMaxLength");
  16032. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesAlignedDataMaxLength].Key, "MeterValuesAlignedDataMaxLength");
  16033. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemAccessibility == 1)
  16034. {
  16035. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesAlignedDataMaxLength].ReadOnly, "0"/*"FALSE"*/);
  16036. }
  16037. else
  16038. {
  16039. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesAlignedDataMaxLength].ReadOnly, "1"/*"TRUE"*/);
  16040. }
  16041. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesAlignedDataMaxLength].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemData );
  16042. isKnowKey = TRUE;
  16043. }
  16044. if(isEmpty || strcmp(keyReq, "MeterValuesSampledData") == 0 )
  16045. {
  16046. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_MeterValuesSampledData].Item, "MeterValuesSampledData");
  16047. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesSampledData].Key, "MeterValuesSampledData");
  16048. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemAccessibility == 1)
  16049. {
  16050. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesSampledData].ReadOnly, "0"/*"FALSE"*/);
  16051. }
  16052. else
  16053. {
  16054. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesSampledData].ReadOnly, "1"/*"TRUE"*/);
  16055. }
  16056. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesSampledData].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData );
  16057. isKnowKey = TRUE;
  16058. }
  16059. if(isEmpty || strcmp(keyReq, "MeterValuesSampledDataMaxLength") == 0 )
  16060. {
  16061. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_MeterValuesSampledDataMaxLength].Item, "MeterValuesSampledDataMaxLength");
  16062. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesSampledDataMaxLength].Key, "MeterValuesSampledDataMaxLength");
  16063. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemAccessibility == 1)
  16064. {
  16065. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesSampledDataMaxLength].ReadOnly, "0"/*"FALSE"*/);
  16066. }
  16067. else
  16068. {
  16069. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesSampledDataMaxLength].ReadOnly, "1"/*"TRUE"*/);
  16070. }
  16071. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesSampledDataMaxLength].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemData );
  16072. isKnowKey = TRUE;
  16073. }
  16074. if(isEmpty || strcmp(keyReq, "MeterValueSampleInterval") == 0 )
  16075. {
  16076. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_MeterValueSampleInterval].Item, "MeterValueSampleInterval");
  16077. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValueSampleInterval].Key, "MeterValueSampleInterval");
  16078. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemAccessibility == 1)
  16079. {
  16080. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValueSampleInterval].ReadOnly, "0"/*"FALSE"*/);
  16081. }
  16082. else
  16083. {
  16084. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValueSampleInterval].ReadOnly, "1"/*"TRUE"*/);
  16085. }
  16086. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValueSampleInterval].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemData );
  16087. isKnowKey = TRUE;
  16088. }
  16089. if(isEmpty || strcmp(keyReq, "MinimumStatusDuration") == 0 )
  16090. {
  16091. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_MinimumStatusDuration].Item, "MinimumStatusDuration");
  16092. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MinimumStatusDuration].Key, "MinimumStatusDuration");
  16093. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemAccessibility == 1)
  16094. {
  16095. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MinimumStatusDuration].ReadOnly, "0"/*"FALSE"*/);
  16096. }
  16097. else
  16098. {
  16099. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MinimumStatusDuration].ReadOnly, "1"/*"TRUE"*/);
  16100. }
  16101. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MinimumStatusDuration].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[17].ItemData );
  16102. isKnowKey = TRUE;
  16103. }
  16104. if(isEmpty || strcmp(keyReq, "NumberOfConnectors") == 0 )
  16105. {
  16106. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_NumberOfConnectors].Item, "NumberOfConnectors");
  16107. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_NumberOfConnectors].Key, "NumberOfConnectors");
  16108. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemAccessibility == 1)
  16109. {
  16110. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_NumberOfConnectors].ReadOnly, "0"/*"FALSE"*/);
  16111. }
  16112. else
  16113. {
  16114. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_NumberOfConnectors].ReadOnly, "1"/*"TRUE"*/);
  16115. }
  16116. sprintf((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData, "%d", gunTotalNumber);
  16117. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_NumberOfConnectors].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData );
  16118. isKnowKey = TRUE;
  16119. }
  16120. if(isEmpty || strcmp(keyReq, "ResetRetries") == 0 )
  16121. {
  16122. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_ResetRetries].Item, "ResetRetries");
  16123. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ResetRetries].Key, "ResetRetries");
  16124. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemAccessibility == 1)
  16125. {
  16126. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ResetRetries].ReadOnly, "0"/*"FALSE"*/);
  16127. }
  16128. else
  16129. {
  16130. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ResetRetries].ReadOnly, "1"/*"TRUE"*/);
  16131. }
  16132. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ResetRetries].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemData );
  16133. isKnowKey = TRUE;
  16134. }
  16135. if(isEmpty || strcmp(keyReq, "ConnectorPhaseRotation") == 0 )
  16136. {
  16137. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_ConnectorPhaseRotation].Item, "ConnectorPhaseRotation");
  16138. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorPhaseRotation].Key, "ConnectorPhaseRotation");
  16139. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemAccessibility == 1)
  16140. {
  16141. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorPhaseRotation].ReadOnly, "0"/*"FALSE"*/);
  16142. }
  16143. else
  16144. {
  16145. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorPhaseRotation].ReadOnly, "1"/*"TRUE"*/);
  16146. }
  16147. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorPhaseRotation].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData );
  16148. isKnowKey = TRUE;
  16149. }
  16150. if(isEmpty || strcmp(keyReq, "ConnectorPhaseRotationMaxLength") == 0 )
  16151. {
  16152. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_ConnectorPhaseRotationMaxLength].Item, "ConnectorPhaseRotationMaxLength");
  16153. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorPhaseRotationMaxLength].Key, "ConnectorPhaseRotationMaxLength");
  16154. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemAccessibility == 1)
  16155. {
  16156. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorPhaseRotationMaxLength].ReadOnly, "0"/*"FALSE"*/);
  16157. }
  16158. else
  16159. {
  16160. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorPhaseRotationMaxLength].ReadOnly, "1"/*"TRUE"*/);
  16161. }
  16162. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorPhaseRotationMaxLength].Value,(const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemData );
  16163. isKnowKey = TRUE;
  16164. }
  16165. if(isEmpty || strcmp(keyReq, "StopTransactionOnEVSideDisconnect") == 0 )
  16166. {
  16167. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_StopTransactionOnEVSideDisconnect].Item, "StopTransactionOnEVSideDisconnect");
  16168. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTransactionOnEVSideDisconnect].Key, "StopTransactionOnEVSideDisconnect");
  16169. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemAccessibility == 1)
  16170. {
  16171. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTransactionOnEVSideDisconnect].ReadOnly, "0"/*"FALSE"*/);
  16172. }
  16173. else
  16174. {
  16175. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTransactionOnEVSideDisconnect].ReadOnly, "1"/*"TRUE"*/);
  16176. }
  16177. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTransactionOnEVSideDisconnect].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemData );
  16178. isKnowKey = TRUE;
  16179. }
  16180. if(isEmpty || strcmp(keyReq, "StopTransactionOnInvalidId") == 0 )
  16181. {
  16182. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_StopTransactionOnInvalidId].Item, "StopTransactionOnInvalidId");
  16183. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTransactionOnInvalidId].Key, "StopTransactionOnInvalidId");
  16184. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemAccessibility == 1)
  16185. {
  16186. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTransactionOnInvalidId].ReadOnly, "0"/*"FALSE"*/);
  16187. }
  16188. else
  16189. {
  16190. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTransactionOnInvalidId].ReadOnly, "1"/*"TRUE"*/);
  16191. }
  16192. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTransactionOnInvalidId].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemData );
  16193. isKnowKey = TRUE;
  16194. }
  16195. if(isEmpty || strcmp(keyReq, "StopTxnAlignedData") == 0 )
  16196. {
  16197. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_StopTxnAlignedData].Item, "StopTxnAlignedData");
  16198. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnAlignedData].Key, "StopTxnAlignedData");
  16199. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemAccessibility == 1)
  16200. {
  16201. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnAlignedData].ReadOnly, "0"/*"FALSE"*/);
  16202. }
  16203. else
  16204. {
  16205. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnAlignedData].ReadOnly, "1"/*"TRUE"*/);
  16206. }
  16207. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnAlignedData].Value,(const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemData );
  16208. isKnowKey = TRUE;
  16209. }
  16210. if(isEmpty || strcmp(keyReq, "StopTxnAlignedDataMaxLength") == 0 )
  16211. {
  16212. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_StopTxnAlignedDataMaxLength].Item, "StopTxnAlignedDataMaxLength");
  16213. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnAlignedDataMaxLength].Key, "StopTxnAlignedDataMaxLength");
  16214. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemAccessibility == 1)
  16215. {
  16216. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnAlignedDataMaxLength].ReadOnly, "0"/*"FALSE"*/);
  16217. }
  16218. else
  16219. {
  16220. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnAlignedDataMaxLength].ReadOnly, "1"/*"TRUE"*/);
  16221. }
  16222. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnAlignedDataMaxLength].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemData );
  16223. isKnowKey = TRUE;
  16224. }
  16225. if(isEmpty || strcmp(keyReq, "StopTxnSampledData") == 0 )
  16226. {
  16227. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_StopTxnSampledData].Item, "StopTxnSampledData");
  16228. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnSampledData].Key, "StopTxnSampledData");
  16229. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemAccessibility == 1)
  16230. {
  16231. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnSampledData].ReadOnly, "0"/*"FALSE"*/);
  16232. }
  16233. else
  16234. {
  16235. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnSampledData].ReadOnly, "1"/*"TRUE"*/);
  16236. }
  16237. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnSampledData].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData );
  16238. isKnowKey = TRUE;
  16239. }
  16240. if(isEmpty || strcmp(keyReq, "StopTxnSampledDataMaxLength") == 0 )
  16241. {
  16242. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_StopTxnSampledDataMaxLength].Item, "StopTxnSampledDataMaxLength");
  16243. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnSampledDataMaxLength].Key, "StopTxnSampledDataMaxLength");
  16244. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemAccessibility == 1)
  16245. {
  16246. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnSampledDataMaxLength].ReadOnly, "0"/*"FALSE"*/);
  16247. }
  16248. else
  16249. {
  16250. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnSampledDataMaxLength].ReadOnly, "1"/*"TRUE"*/);
  16251. }
  16252. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnSampledDataMaxLength].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemData );
  16253. isKnowKey = TRUE;
  16254. }
  16255. if(isEmpty || strcmp(keyReq, "SupportedFeatureProfiles") == 0 )
  16256. {
  16257. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_SupportedFeatureProfiles].Item, "SupportedFeatureProfiles");
  16258. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SupportedFeatureProfiles].Key, "SupportedFeatureProfiles");
  16259. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemAccessibility == 1)
  16260. {
  16261. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SupportedFeatureProfiles].ReadOnly, "0"/*"FALSE"*/);
  16262. }
  16263. else
  16264. {
  16265. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SupportedFeatureProfiles].ReadOnly, "1"/*"TRUE"*/);
  16266. }
  16267. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SupportedFeatureProfiles].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemData );
  16268. isKnowKey = TRUE;
  16269. }
  16270. if(isEmpty || strcmp(keyReq, "SupportedFeatureProfilesMaxLength") == 0 )
  16271. {
  16272. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_SupportedFeatureProfilesMaxLength].Item, "SupportedFeatureProfilesMaxLength");
  16273. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SupportedFeatureProfilesMaxLength].Key, "SupportedFeatureProfilesMaxLength");
  16274. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemAccessibility == 1)
  16275. {
  16276. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SupportedFeatureProfilesMaxLength].ReadOnly, "0"/*"FALSE"*/);
  16277. }
  16278. else
  16279. {
  16280. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SupportedFeatureProfilesMaxLength].ReadOnly, "1"/*"TRUE"*/);
  16281. }
  16282. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SupportedFeatureProfilesMaxLength].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemData );
  16283. isKnowKey = TRUE;
  16284. }
  16285. if(isEmpty || strcmp(keyReq, "TransactionMessageAttempts") == 0 )
  16286. {
  16287. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_TransactionMessageAttempts].Item, "TransactionMessageAttempts");
  16288. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TransactionMessageAttempts].Key, "TransactionMessageAttempts");
  16289. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemAccessibility == 1)
  16290. {
  16291. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TransactionMessageAttempts].ReadOnly, "0"/*"FALSE"*/);
  16292. }
  16293. else
  16294. {
  16295. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TransactionMessageAttempts].ReadOnly, "1"/*"TRUE"*/);
  16296. }
  16297. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TransactionMessageAttempts].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData );
  16298. isKnowKey = TRUE;
  16299. }
  16300. if(isEmpty || strcmp(keyReq, "TransactionMessageRetryInterval") == 0 )
  16301. {
  16302. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_TransactionMessageRetryInterval].Item, "TransactionMessageRetryInterval");
  16303. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TransactionMessageRetryInterval].Key, "TransactionMessageRetryInterval");
  16304. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemAccessibility == 1)
  16305. {
  16306. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TransactionMessageRetryInterval].ReadOnly, "0"/*"FALSE"*/);
  16307. }
  16308. else
  16309. {
  16310. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TransactionMessageRetryInterval].ReadOnly, "1"/*"TRUE"*/);
  16311. }
  16312. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TransactionMessageRetryInterval].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData );
  16313. isKnowKey = TRUE;
  16314. }
  16315. if(isEmpty || strcmp(keyReq, "UnlockConnectorOnEVSideDisconnect") == 0 )
  16316. {
  16317. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_UnlockConnectorOnEVSideDisconnect].Item, "UnlockConnectorOnEVSideDisconnect");
  16318. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_UnlockConnectorOnEVSideDisconnect].Key, "UnlockConnectorOnEVSideDisconnect");
  16319. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemAccessibility == 1)
  16320. {
  16321. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_UnlockConnectorOnEVSideDisconnect].ReadOnly, "0"/*"FALSE"*/);
  16322. }
  16323. else
  16324. {
  16325. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_UnlockConnectorOnEVSideDisconnect].ReadOnly, "1"/*"TRUE"*/);
  16326. }
  16327. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_UnlockConnectorOnEVSideDisconnect].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemData );
  16328. isKnowKey = TRUE;
  16329. }
  16330. if(isEmpty || strcmp(keyReq, "WebSocketPingInterval") == 0 )
  16331. {
  16332. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_WebSocketPingInterval].Item, "WebSocketPingInterval");
  16333. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_WebSocketPingInterval].Key, "WebSocketPingInterval");
  16334. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemAccessibility == 1)
  16335. {
  16336. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_WebSocketPingInterval].ReadOnly, "0"/*"FALSE"*/);
  16337. }
  16338. else
  16339. {
  16340. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_WebSocketPingInterval].ReadOnly, "1"/*"TRUE"*/);
  16341. }
  16342. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_WebSocketPingInterval].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemData );
  16343. isKnowKey = TRUE;
  16344. }
  16345. if(isEmpty || strcmp(keyReq, "QueueOffLineMeterValues") == 0 )
  16346. {
  16347. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_QueueOffLineMeterValues].Item, "QueueOffLineMeterValues");
  16348. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_QueueOffLineMeterValues].Key, "QueueOffLineMeterValues");
  16349. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[QueueOffLineMeterValues].ItemAccessibility == 1)
  16350. {
  16351. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_QueueOffLineMeterValues].ReadOnly, "0"/*"FALSE"*/);
  16352. }
  16353. else
  16354. {
  16355. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_QueueOffLineMeterValues].ReadOnly, "1"/*"TRUE"*/);
  16356. }
  16357. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_QueueOffLineMeterValues].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[QueueOffLineMeterValues].ItemData );
  16358. isKnowKey = TRUE;
  16359. }
  16360. /*
  16361. if(isEmpty || strcmp(keyReq, "AuthorizationKey") == 0 )
  16362. {
  16363. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_AuthorizationKey].Item, "AuthorizationKey");
  16364. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizationKey].Key, "AuthorizationKey");
  16365. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationKey].ItemAccessibility == 1)
  16366. {
  16367. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizationKey].ReadOnly, "0");
  16368. }
  16369. else
  16370. {
  16371. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizationKey].ReadOnly, "1");
  16372. }
  16373. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizationKey].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationKey].ItemData );
  16374. isKnowKey = TRUE;
  16375. }*/
  16376. if(isEmpty || strcmp(keyReq, "SecurityProfile") == 0 )
  16377. {
  16378. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_SecurityProfile].Item, "SecurityProfile");
  16379. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SecurityProfile].Key, "SecurityProfile");
  16380. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[SecurityProfile].ItemAccessibility == 1)
  16381. {
  16382. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SecurityProfile].ReadOnly, "0"/*"FALSE"*/);
  16383. }
  16384. else
  16385. {
  16386. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SecurityProfile].ReadOnly, "1"/*"TRUE"*/);
  16387. }
  16388. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SecurityProfile].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SecurityProfile].ItemData );
  16389. isKnowKey = TRUE;
  16390. }
  16391. if(isEmpty || strcmp(keyReq, "DefaultPrice") == 0 )
  16392. {
  16393. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_DefaultPrice].Item, "DefaultPrice");
  16394. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_DefaultPrice].Key, "DefaultPrice");
  16395. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[DefaultPrice].ItemAccessibility == 1)
  16396. {
  16397. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_DefaultPrice].ReadOnly, "0"/*"FALSE"*/);
  16398. }
  16399. else
  16400. {
  16401. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_DefaultPrice].ReadOnly, "1"/*"TRUE"*/);
  16402. }
  16403. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_DefaultPrice].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[DefaultPrice].ItemData );
  16404. isKnowKey = TRUE;
  16405. }
  16406. if(isEmpty || strcmp(keyReq, "CustomDisplayCostAndPrice") == 0 )
  16407. {
  16408. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_CustomDisplayCostAndPrice].Item, "CustomDisplayCostAndPrice");
  16409. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_CustomDisplayCostAndPrice].Key, "CustomDisplayCostAndPrice");
  16410. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemAccessibility == 1)
  16411. {
  16412. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_CustomDisplayCostAndPrice].ReadOnly, "0"/*"FALSE"*/);
  16413. }
  16414. else
  16415. {
  16416. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_CustomDisplayCostAndPrice].ReadOnly, "1"/*"TRUE"*/);
  16417. }
  16418. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_CustomDisplayCostAndPrice].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemData );
  16419. isKnowKey = TRUE;
  16420. }
  16421. if(isEmpty || strcmp(keyReq, "CustomIdleFeeAfterStop") == 0 )
  16422. {
  16423. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_CustomIdleFeeAfterStop].Item, "CustomIdleFeeAfterStop");
  16424. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_CustomIdleFeeAfterStop].Key, "CustomIdleFeeAfterStop");
  16425. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemAccessibility == 1)
  16426. {
  16427. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_CustomIdleFeeAfterStop].ReadOnly, "0"/*"FALSE"*/);
  16428. }
  16429. else
  16430. {
  16431. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_CustomIdleFeeAfterStop].ReadOnly, "1"/*"TRUE"*/);
  16432. }
  16433. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_CustomIdleFeeAfterStop].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemData );
  16434. isKnowKey = TRUE;
  16435. }
  16436. if(isEmpty || strcmp(keyReq, "TimeOffset") == 0 )
  16437. {
  16438. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_TimeOffset].Item, "TimeOffset");
  16439. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TimeOffset].Key, "TimeOffset");
  16440. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffset].ItemAccessibility == 1)
  16441. {
  16442. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TimeOffset].ReadOnly, "0"/*"FALSE"*/);
  16443. }
  16444. else
  16445. {
  16446. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TimeOffset].ReadOnly, "1"/*"TRUE"*/);
  16447. }
  16448. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TimeOffset].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffset].ItemData );
  16449. isKnowKey = TRUE;
  16450. }
  16451. if(isEmpty || strcmp(keyReq, "NextTimeOffsetTransitionDateTime") == 0 )
  16452. {
  16453. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_NextTimeOffsetTransitionDateTime].Item, "NextTimeOffsetTransitionDateTime");
  16454. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_NextTimeOffsetTransitionDateTime].Key, "NextTimeOffsetTransitionDateTime");
  16455. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[NextTimeOffsetTransitionDateTime].ItemAccessibility == 1)
  16456. {
  16457. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_NextTimeOffsetTransitionDateTime].ReadOnly, "0"/*"FALSE"*/);
  16458. }
  16459. else
  16460. {
  16461. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_NextTimeOffsetTransitionDateTime].ReadOnly, "1"/*"TRUE"*/);
  16462. }
  16463. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_NextTimeOffsetTransitionDateTime].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NextTimeOffsetTransitionDateTime].ItemData );
  16464. isKnowKey = TRUE;
  16465. }
  16466. if(isEmpty || strcmp(keyReq, "TimeOffsetNextTransition") == 0 )
  16467. {
  16468. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_TimeOffsetNextTransition].Item, "TimeOffsetNextTransition");
  16469. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TimeOffsetNextTransition].Key, "TimeOffsetNextTransition");
  16470. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffsetNextTransition].ItemAccessibility == 1)
  16471. {
  16472. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TimeOffsetNextTransition].ReadOnly, "0"/*"FALSE"*/);
  16473. }
  16474. else
  16475. {
  16476. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TimeOffsetNextTransition].ReadOnly, "1"/*"TRUE"*/);
  16477. }
  16478. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TimeOffsetNextTransition].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffsetNextTransition].ItemData );
  16479. isKnowKey = TRUE;
  16480. }
  16481. if(isEmpty || strcmp(keyReq, "SystemUptimeSec") == 0 )
  16482. {
  16483. struct sysinfo s_info;
  16484. int error = sysinfo(&s_info);
  16485. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_SystemUptimeSec].Item, "SystemUptimeSec");
  16486. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SystemUptimeSec].Key, "SystemUptimeSec");
  16487. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[SystemUptimeSec].ItemAccessibility == 1)
  16488. {
  16489. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SystemUptimeSec].ReadOnly, "0"/*"FALSE"*/);
  16490. }
  16491. else
  16492. {
  16493. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SystemUptimeSec].ReadOnly, "1"/*"TRUE"*/);
  16494. }
  16495. if(error != 0)
  16496. {
  16497. DEBUG_WARN("System uptime get error: %d\n", error);
  16498. }
  16499. else
  16500. {
  16501. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SystemUptimeSec].ItemData, "%ld", s_info.uptime);
  16502. sprintf((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SystemUptimeSec].Value, "%ld", s_info.uptime);
  16503. }
  16504. isKnowKey = TRUE;
  16505. }
  16506. if(isEmpty || strcmp(keyReq, "FreeVend") == 0 )
  16507. {
  16508. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_FreeVend].Item, "FreeVend");
  16509. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_FreeVend].Key, "FreeVend");
  16510. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[FreeVend].ItemAccessibility == 1)
  16511. {
  16512. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_FreeVend].ReadOnly, "0"/*"FALSE"*/);
  16513. }
  16514. else
  16515. {
  16516. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_FreeVend].ReadOnly, "1"/*"TRUE"*/);
  16517. }
  16518. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_FreeVend].Value, (ShmSysConfigAndInfo->SysConfig.AuthorisationMode?"TRUE":"FALSE"));
  16519. isKnowKey = TRUE;
  16520. }
  16521. if(isEmpty || strcmp(keyReq, "FreeVendIdtag") == 0 )
  16522. {
  16523. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_FreeVendIdtag].Item, "FreeVendIdtag");
  16524. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_FreeVendIdtag].Key, "FreeVendIdtag");
  16525. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[FreeVendIdtag].ItemAccessibility == 1)
  16526. {
  16527. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_FreeVendIdtag].ReadOnly, "0"/*"FALSE"*/);
  16528. }
  16529. else
  16530. {
  16531. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_FreeVendIdtag].ReadOnly, "1"/*"TRUE"*/);
  16532. }
  16533. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_FreeVendIdtag].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[FreeVendIdtag].ItemData);
  16534. isKnowKey = TRUE;
  16535. }
  16536. if(isEmpty || strcmp(keyReq, "OcppServer") == 0 )
  16537. {
  16538. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_OcppServer].Item, "OcppServer");
  16539. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_OcppServer].Key, "OcppServer");
  16540. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[OcppServer].ItemAccessibility == 1)
  16541. {
  16542. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_OcppServer].ReadOnly, "0"/*"FALSE"*/);
  16543. }
  16544. else
  16545. {
  16546. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_OcppServer].ReadOnly, "1"/*"TRUE"*/);
  16547. }
  16548. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_OcppServer].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[OcppServer].ItemData);
  16549. isKnowKey = TRUE;
  16550. }
  16551. if(isEmpty || strcmp(keyReq, "MaintainServer") == 0 )
  16552. {
  16553. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_MaintainServer].Item, "MaintainServer");
  16554. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaintainServer].Key, "MaintainServer");
  16555. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MaintainServer].ItemAccessibility == 1)
  16556. {
  16557. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaintainServer].ReadOnly, "0"/*"FALSE"*/);
  16558. }
  16559. else
  16560. {
  16561. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaintainServer].ReadOnly, "1"/*"TRUE"*/);
  16562. }
  16563. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaintainServer].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MaintainServer].ItemData);
  16564. isKnowKey = TRUE;
  16565. }
  16566. if(isEmpty || strcmp(keyReq, "StatusNotificationPeriodically") == 0 )
  16567. {
  16568. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_StatusNotificationPeriodically].Item, "StatusNotificationPeriodically");
  16569. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StatusNotificationPeriodically].Key, "StatusNotificationPeriodically");
  16570. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StatusNotificationPeriodically].ItemAccessibility == 1)
  16571. {
  16572. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StatusNotificationPeriodically].ReadOnly, "0"/*"FALSE"*/);
  16573. }
  16574. else
  16575. {
  16576. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StatusNotificationPeriodically].ReadOnly, "1"/*"TRUE"*/);
  16577. }
  16578. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StatusNotificationPeriodically].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StatusNotificationPeriodically].ItemData );
  16579. isKnowKey = TRUE;
  16580. }
  16581. if(isEmpty || strcmp(keyReq, "StatusNotificationInterval") == 0 )
  16582. {
  16583. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_StatusNotificationInterval].Item, "StatusNotificationInterval");
  16584. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StatusNotificationInterval].Key, "StatusNotificationInterval");
  16585. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StatusNotificationInterval].ItemAccessibility == 1)
  16586. {
  16587. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StatusNotificationInterval].ReadOnly, "0"/*"FALSE"*/);
  16588. }
  16589. else
  16590. {
  16591. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StatusNotificationInterval].ReadOnly, "1"/*"TRUE"*/);
  16592. }
  16593. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StatusNotificationInterval].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StatusNotificationInterval].ItemData );
  16594. isKnowKey = TRUE;
  16595. }
  16596. if(isEmpty || strcmp(keyReq, "PreAuthAmount") == 0 )
  16597. {
  16598. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_PreAuthAmount].Item, "PreAuthAmount");
  16599. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_PreAuthAmount].Key, "PreAuthAmount");
  16600. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[PreAuthAmount].ItemAccessibility == 1)
  16601. {
  16602. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_PreAuthAmount].ReadOnly, "0"/*"FALSE"*/);
  16603. }
  16604. else
  16605. {
  16606. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_PreAuthAmount].ReadOnly, "1"/*"TRUE"*/);
  16607. }
  16608. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_PreAuthAmount].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[PreAuthAmount].ItemData );
  16609. isKnowKey = TRUE;
  16610. }
  16611. if(isEmpty || strcmp(keyReq, "isEnableLocalPowerSharing") == 0 )
  16612. {
  16613. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_isEnableLocalPowerSharing].Item, "isEnableLocalPowerSharing");
  16614. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_isEnableLocalPowerSharing].Key, "isEnableLocalPowerSharing");
  16615. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[isEnableLocalPowerSharing].ItemAccessibility == 1)
  16616. {
  16617. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_isEnableLocalPowerSharing].ReadOnly, "0"/*"FALSE"*/);
  16618. }
  16619. else
  16620. {
  16621. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_isEnableLocalPowerSharing].ReadOnly, "1"/*"TRUE"*/);
  16622. }
  16623. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_isEnableLocalPowerSharing].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[isEnableLocalPowerSharing].ItemData );
  16624. isKnowKey = TRUE;
  16625. }
  16626. if(isEmpty || strcmp(keyReq, "PowerSharingServerIP") == 0 )
  16627. {
  16628. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_PowerSharingServerIP].Item, "PowerSharingServerIP");
  16629. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_PowerSharingServerIP].Key, "PowerSharingServerIP");
  16630. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[PowerSharingServerIP].ItemAccessibility == 1)
  16631. {
  16632. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_PowerSharingServerIP].ReadOnly, "0"/*"FALSE"*/);
  16633. }
  16634. else
  16635. {
  16636. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_PowerSharingServerIP].ReadOnly, "1"/*"TRUE"*/);
  16637. }
  16638. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_PowerSharingServerIP].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[PowerSharingServerIP].ItemData );
  16639. isKnowKey = TRUE;
  16640. }
  16641. if(isEmpty || strcmp(keyReq, "EVCCID_PREFIX") == 0 )
  16642. {
  16643. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_EVCCID_PREFIX].Item, "EVCCID_PREFIX");
  16644. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_EVCCID_PREFIX].Key, "EVCCID_PREFIX");
  16645. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[EVCCID_PREFIX].ItemAccessibility == 1)
  16646. {
  16647. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_EVCCID_PREFIX].ReadOnly, "0"/*"FALSE"*/);
  16648. }
  16649. else
  16650. {
  16651. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_EVCCID_PREFIX].ReadOnly, "1"/*"TRUE"*/);
  16652. }
  16653. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_EVCCID_PREFIX].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[EVCCID_PREFIX].ItemData );
  16654. isKnowKey = TRUE;
  16655. }
  16656. if(isEmpty || strcmp(keyReq, "OffLineMaxChargingPower") == 0 )
  16657. {
  16658. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_OffLineMaxChargingPower].Item, "OffLineMaxChargingPower");
  16659. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_OffLineMaxChargingPower].Key, "OffLineMaxChargingPower");
  16660. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[OffLineMaxChargingPower].ItemAccessibility == 1)
  16661. {
  16662. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_OffLineMaxChargingPower].ReadOnly, "0"/*"FALSE"*/);
  16663. }
  16664. else
  16665. {
  16666. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_OffLineMaxChargingPower].ReadOnly, "1"/*"TRUE"*/);
  16667. }
  16668. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_OffLineMaxChargingPower].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[OffLineMaxChargingPower].ItemData );
  16669. isKnowKey = TRUE;
  16670. }
  16671. if(isEmpty || strcmp(keyReq, "ConfigurationVersion") == 0 )
  16672. {
  16673. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_ConfigurationVersion].Item, "ConfigurationVersion");
  16674. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConfigurationVersion].Key, "ConfigurationVersion");
  16675. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[ConfigurationVersion].ItemAccessibility == 1)
  16676. {
  16677. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConfigurationVersion].ReadOnly, "0"/*"FALSE"*/);
  16678. }
  16679. else
  16680. {
  16681. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConfigurationVersion].ReadOnly, "1"/*"TRUE"*/);
  16682. }
  16683. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConfigurationVersion].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConfigurationVersion].ItemData );
  16684. isKnowKey = TRUE;
  16685. }
  16686. if(isEmpty || strcmp(keyReq, "CharingProfileRefreshInterval") == 0 )
  16687. {
  16688. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_CharingProfileRefreshInterval].Item, "CharingProfileRefreshInterval");
  16689. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_CharingProfileRefreshInterval].Key, "CharingProfileRefreshInterval");
  16690. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[CharingProfileRefreshInterval].ItemAccessibility == 1)
  16691. {
  16692. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_CharingProfileRefreshInterval].ReadOnly, "0"/*"FALSE"*/);
  16693. }
  16694. else
  16695. {
  16696. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_CharingProfileRefreshInterval].ReadOnly, "1"/*"TRUE"*/);
  16697. }
  16698. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_CharingProfileRefreshInterval].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CharingProfileRefreshInterval].ItemData );
  16699. isKnowKey = TRUE;
  16700. }
  16701. if(isEmpty || strcmp(keyReq, "OcppSoftwareVersion") == 0 )
  16702. {
  16703. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_OcppSoftwareVersion].Item, "OcppSoftwareVersion");
  16704. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_OcppSoftwareVersion].Key, "OcppSoftwareVersion");
  16705. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[OcppSoftwareVersion].ItemAccessibility == 1)
  16706. {
  16707. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_OcppSoftwareVersion].ReadOnly, "0"/*"FALSE"*/);
  16708. }
  16709. else
  16710. {
  16711. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_OcppSoftwareVersion].ReadOnly, "1"/*"TRUE"*/);
  16712. }
  16713. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_OcppSoftwareVersion].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[OcppSoftwareVersion].ItemData );
  16714. isKnowKey = TRUE;
  16715. }
  16716. #if 1
  16717. if(isEmpty || strcmp(keyReq, "LocalAuthListEnabled") == 0 )
  16718. {
  16719. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_LocalAuthListEnabled].Item, "LocalAuthListEnabled");
  16720. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListEnabled].Key, "LocalAuthListEnabled");
  16721. if(ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemAccessibility == 1)
  16722. {
  16723. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListEnabled].ReadOnly, "0"/*"FALSE"*/);
  16724. }
  16725. else
  16726. {
  16727. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListEnabled].ReadOnly, "1"/*"TRUE"*/);
  16728. }
  16729. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListEnabled].Value, (const char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData );
  16730. isKnowKey = TRUE;
  16731. }
  16732. #endif
  16733. if(isEmpty || strcmp(keyReq, "LocalAuthListMaxLength") == 0 )
  16734. {
  16735. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_LocalAuthListMaxLength].Item, "LocalAuthListMaxLength");
  16736. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListMaxLength].Key, "LocalAuthListMaxLength");
  16737. if(ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemAccessibility == 1)
  16738. {
  16739. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListMaxLength].ReadOnly, "0"/*"FALSE"*/);
  16740. }
  16741. else
  16742. {
  16743. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListMaxLength].ReadOnly, "1"/*"TRUE"*/);
  16744. }
  16745. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListMaxLength].Value, (const char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemData );
  16746. isKnowKey = TRUE;
  16747. }
  16748. if(isEmpty || strcmp(keyReq, "SendLocalListMaxLength") == 0 )
  16749. {
  16750. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_SendLocalListMaxLength].Item, "SendLocalListMaxLength");
  16751. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SendLocalListMaxLength].Key, "SendLocalListMaxLength");
  16752. if(ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemAccessibility == 1)
  16753. {
  16754. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SendLocalListMaxLength].ReadOnly, "0"/*"FALSE"*/);
  16755. }
  16756. else
  16757. {
  16758. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SendLocalListMaxLength].ReadOnly, "1"/*"TRUE"*/);
  16759. }
  16760. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SendLocalListMaxLength].Value, (const char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemData );
  16761. isKnowKey = TRUE;
  16762. }
  16763. if(isEmpty || strcmp(keyReq, "ReserveConnectorZeroSupported") == 0 )
  16764. {
  16765. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_ReserveConnectorZeroSupported].Item, "ReserveConnectorZeroSupported");
  16766. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ReserveConnectorZeroSupported].Key, "ReserveConnectorZeroSupported");
  16767. if(ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemAccessibility == 1)
  16768. {
  16769. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ReserveConnectorZeroSupported].ReadOnly, "0"/*"FALSE"*/);
  16770. }
  16771. else
  16772. {
  16773. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ReserveConnectorZeroSupported].ReadOnly, "1"/*"TRUE"*/);
  16774. }
  16775. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ReserveConnectorZeroSupported].Value,(const char *)ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemData);
  16776. isKnowKey = TRUE;
  16777. }
  16778. if(isEmpty || strcmp(keyReq, "ChargeProfileMaxStackLevel") == 0 )
  16779. {
  16780. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_ChargeProfileMaxStackLevel].Item, "ChargeProfileMaxStackLevel");
  16781. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargeProfileMaxStackLevel].Key, "ChargeProfileMaxStackLevel");
  16782. if(ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemAccessibility == 1)
  16783. {
  16784. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargeProfileMaxStackLevel].ReadOnly, "0"/*"FALSE"*/);
  16785. }
  16786. else
  16787. {
  16788. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargeProfileMaxStackLevel].ReadOnly, "1"/*"TRUE"*/);
  16789. }
  16790. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargeProfileMaxStackLevel].Value, (const char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemData);
  16791. isKnowKey = TRUE;
  16792. }
  16793. if(isEmpty || strcmp(keyReq, "ChargingScheduleAllowedChargingRateUnit") == 0 )
  16794. {
  16795. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_ChargingScheduleAllowedChargingRateUnit].Item, "ChargingScheduleAllowedChargingRateUnit");
  16796. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargingScheduleAllowedChargingRateUnit].Key, "ChargingScheduleAllowedChargingRateUnit");
  16797. if(ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemAccessibility == 1)
  16798. {
  16799. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargingScheduleAllowedChargingRateUnit].ReadOnly, "0"/*"FALSE"*/);
  16800. }
  16801. else
  16802. {
  16803. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargingScheduleAllowedChargingRateUnit].ReadOnly, "1"/*"TRUE"*/);
  16804. }
  16805. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargingScheduleAllowedChargingRateUnit].Value, (const char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemData);
  16806. isKnowKey = TRUE;
  16807. }
  16808. if(isEmpty || strcmp(keyReq, "ChargingScheduleMaxPeriods") == 0 )
  16809. {
  16810. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_ChargingScheduleMaxPeriods].Item, "ChargingScheduleMaxPeriods");
  16811. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargingScheduleMaxPeriods].Key, "ChargingScheduleMaxPeriods");
  16812. if(ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemAccessibility == 1)
  16813. {
  16814. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargingScheduleMaxPeriods].ReadOnly, "0"/*"FALSE"*/);
  16815. }
  16816. else
  16817. {
  16818. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargingScheduleMaxPeriods].ReadOnly, "1"/*"TRUE"*/);
  16819. }
  16820. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargingScheduleMaxPeriods].Value, (const char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemData);
  16821. isKnowKey = TRUE;
  16822. }
  16823. if(isEmpty || strcmp(keyReq, "ConnectorSwitch3to1PhaseSupported") == 0 )
  16824. {
  16825. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_ConnectorSwitch3to1PhaseSupported].Item, "ConnectorSwitch3to1PhaseSupported");
  16826. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorSwitch3to1PhaseSupported].Key, "ConnectorSwitch3to1PhaseSupported");
  16827. if(ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemAccessibility == 1)
  16828. {
  16829. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorSwitch3to1PhaseSupported].ReadOnly, "0"/*"FALSE"*/);
  16830. }
  16831. else
  16832. {
  16833. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorSwitch3to1PhaseSupported].ReadOnly, "1"/*"TRUE"*/);
  16834. }
  16835. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorSwitch3to1PhaseSupported].Value, (const char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemData);
  16836. isKnowKey = TRUE;
  16837. }
  16838. if(isEmpty || strcmp(keyReq, "MaxChargingProfilesInstalled") == 0 )
  16839. {
  16840. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_MaxChargingProfilesInstalled].Item, "MaxChargingProfilesInstalled");
  16841. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaxChargingProfilesInstalled].Key, "MaxChargingProfilesInstalled");
  16842. if(ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemAccessibility == 1)
  16843. {
  16844. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaxChargingProfilesInstalled].ReadOnly, "0"/*"FLASE"*/);
  16845. }
  16846. else
  16847. {
  16848. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaxChargingProfilesInstalled].ReadOnly, "1"/*"TRUE"*/);
  16849. }
  16850. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaxChargingProfilesInstalled].Value, (const char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemData);
  16851. isKnowKey = TRUE;
  16852. }
  16853. //=========================================================
  16854. if(!isEmpty && !isKnowKey)
  16855. {
  16856. DEBUG_INFO("unKnowIndex =%d\n", UnknownKeynum);
  16857. strcpy(unknownkey[UnknownKeynum], keyReq);
  16858. UnknownKeynum = UnknownKeynum + 1;
  16859. }
  16860. }
  16861. void processUnkownKey(void)
  16862. {
  16863. DEBUG_INFO("processUnkownKey...\n");
  16864. memset(ShmOCPP16Data->GetConfiguration.ResponseUnknownKey, 0 , sizeof(struct StructConfigurationKeyItems)* 10);
  16865. for(int index=0; index < UnknownKeynum; index++)
  16866. {
  16867. if(ShmOCPP16Data->GetConfiguration.ResponseUnknownKey[index].Item[0] == 0)
  16868. {
  16869. strcpy((char *)(ShmOCPP16Data->GetConfiguration.ResponseUnknownKey[index].Item), unknownkey[index]);
  16870. }
  16871. }
  16872. }
  16873. int setKeyValue(char *key, char *value)
  16874. {
  16875. int isSuccess = NotSupported;
  16876. int check_ascii=0;
  16877. char str[501]={0};
  16878. DEBUG_INFO(" setKeyValue %s = %s\n", key, value);
  16879. if(strcmp(key, "AllowOfflineTxForUnknownId") == 0)
  16880. {
  16881. //Charger.AllowOfflineTxForUnknownId = (value.toLowerCase().equals("true")?true:false);
  16882. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemAccessibility == 1)
  16883. {
  16884. strcpy(str, (const char*)value);
  16885. for(int i = 0; str[i]; i++){
  16886. str[i] = tolower(str[i]);
  16887. }
  16888. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  16889. isSuccess = ConfigurationStatus_Accepted;
  16890. }
  16891. else
  16892. {
  16893. isSuccess = ConfigurationStatus_Rejected;
  16894. }
  16895. }
  16896. if(strcmp(key, "AuthorizationCacheEnabled") == 0)
  16897. {
  16898. //Charger.AuthorizationCacheEnabled = (value.toLowerCase().equals("true")?true:false);
  16899. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemAccessibility == 1)
  16900. {
  16901. strcpy(str, (const char*)value);
  16902. for(int i = 0; str[i]; i++){
  16903. str[i] = tolower(str[i]);
  16904. }
  16905. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  16906. isSuccess = ConfigurationStatus_Accepted;
  16907. //updateSetting("AuthorizationCacheEnabled",(char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[1].ItemData);
  16908. }
  16909. else
  16910. {
  16911. isSuccess = ConfigurationStatus_Rejected;
  16912. }
  16913. }
  16914. if(strcmp(key, "AuthorizeRemoteTxRequests") == 0)
  16915. {
  16916. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemAccessibility == 1)
  16917. {
  16918. strcpy(str, (const char*)value);
  16919. for(int i = 0; str[i]; i++)
  16920. {
  16921. str[i] = tolower(str[i]);
  16922. }
  16923. //Charger.AuthorizeRemoteTxRequests = (value.toLowerCase().equals("true")?true:false);
  16924. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  16925. isSuccess = ConfigurationStatus_Accepted;
  16926. }
  16927. else
  16928. {
  16929. isSuccess = ConfigurationStatus_Rejected;
  16930. }
  16931. }
  16932. if(strcmp(key, "BlinkRepeat") == 0)
  16933. {
  16934. //Charger.BlinkRepeat = Integer.parseInt(value);
  16935. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemAccessibility == 1)
  16936. {
  16937. check_ascii = value[0];
  16938. if( (check_ascii < 48) || (check_ascii > 57) )
  16939. {
  16940. isSuccess = ConfigurationStatus_Rejected;
  16941. }
  16942. else
  16943. {
  16944. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemData, "%d", atoi(value) );
  16945. isSuccess = ConfigurationStatus_Accepted;
  16946. }
  16947. }
  16948. else
  16949. {
  16950. isSuccess = ConfigurationStatus_Rejected;
  16951. }
  16952. }
  16953. if(strcmp(key, "ClockAlignedDataInterval") == 0)
  16954. {
  16955. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemAccessibility == 1)
  16956. {
  16957. check_ascii = value[0];
  16958. if( (check_ascii < 48) || (check_ascii > 57) )
  16959. {
  16960. isSuccess = ConfigurationStatus_Rejected;
  16961. }
  16962. else
  16963. {
  16964. if((atoi(value) == 0) || (atoi(value) >= 5))
  16965. {
  16966. //Charger.ClockAlignedDataInterval = Integer.parseInt(value)*1000;
  16967. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemData, "%d", atoi(value) );
  16968. isSuccess = ConfigurationStatus_Accepted;
  16969. }
  16970. else
  16971. isSuccess = ConfigurationStatus_Rejected;
  16972. }
  16973. }
  16974. else
  16975. {
  16976. isSuccess = ConfigurationStatus_Rejected;
  16977. }
  16978. }
  16979. if(strcmp(key, "ConnectionTimeOut") == 0 )
  16980. {
  16981. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemAccessibility == 1)
  16982. {
  16983. check_ascii = value[0];
  16984. if( (check_ascii < 48) || (check_ascii > 57) )
  16985. {
  16986. isSuccess = ConfigurationStatus_Rejected;
  16987. }
  16988. else
  16989. {
  16990. //Charger.ConnectionTimeOut = Integer.parseInt(value)*1000;
  16991. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemData, "%d", atoi(value));
  16992. isSuccess = ConfigurationStatus_Accepted;
  16993. }
  16994. }
  16995. else
  16996. {
  16997. isSuccess = ConfigurationStatus_Rejected;
  16998. }
  16999. }
  17000. if(strcmp(key, "GetConfigurationMaxKeys") == 0)
  17001. {
  17002. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemAccessibility == 1)
  17003. {
  17004. check_ascii = value[0];
  17005. if( (check_ascii < 48) || (check_ascii > 57) )
  17006. {
  17007. isSuccess = ConfigurationStatus_Rejected;
  17008. }
  17009. else
  17010. {
  17011. //Charger.HeartbeatInterval = Integer.parseInt(value)*1000;
  17012. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemData, "%d", atoi(value) );
  17013. isSuccess = ConfigurationStatus_Accepted;
  17014. }
  17015. }
  17016. else
  17017. {
  17018. isSuccess = ConfigurationStatus_Rejected;
  17019. }
  17020. }
  17021. if(strcmp(key, "HeartbeatInterval") == 0)
  17022. {
  17023. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemAccessibility == 1)
  17024. {
  17025. check_ascii = value[0];
  17026. if( (check_ascii < 48) || (check_ascii > 57) )
  17027. {
  17028. isSuccess = ConfigurationStatus_Rejected;
  17029. }
  17030. else
  17031. {
  17032. if((atoi(value) == 0) || (atoi(value) >= 10))
  17033. {
  17034. //Charger.HeartbeatInterval = Integer.parseInt(value)*1000;
  17035. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemData, "%d", atoi(value));
  17036. HeartBeatWaitTime = atoi(value);
  17037. isSuccess = ConfigurationStatus_Accepted;
  17038. }
  17039. else
  17040. {
  17041. isSuccess = ConfigurationStatus_Rejected;
  17042. }
  17043. }
  17044. }
  17045. else
  17046. {
  17047. isSuccess = ConfigurationStatus_Rejected;
  17048. }
  17049. }
  17050. if(strcmp(key, "LightIntensity") == 0)
  17051. {
  17052. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemAccessibility == 1)
  17053. {
  17054. check_ascii = value[0];
  17055. if( (check_ascii < 48) || (check_ascii > 57) )
  17056. {
  17057. isSuccess = ConfigurationStatus_Rejected;
  17058. }
  17059. else
  17060. {
  17061. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemData, "%d", atoi(value) );
  17062. isSuccess = ConfigurationStatus_Accepted;
  17063. }
  17064. }
  17065. else
  17066. {
  17067. isSuccess = ConfigurationStatus_Rejected;
  17068. }
  17069. }
  17070. if(strcmp(key, "LocalAuthorizeOffline") == 0)
  17071. {
  17072. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemAccessibility == 1)
  17073. {
  17074. strcpy(str, (const char*)value);
  17075. for(int i = 0; str[i]; i++)
  17076. {
  17077. str[i] = tolower(str[i]);
  17078. }
  17079. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  17080. isSuccess = ConfigurationStatus_Accepted;
  17081. //updateSetting("LocalAuthorizeOffline", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemData);
  17082. }
  17083. else
  17084. {
  17085. isSuccess = ConfigurationStatus_Rejected;
  17086. }
  17087. }
  17088. if(strcmp(key, "LocalPreAuthorize") == 0)
  17089. {
  17090. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemAccessibility == 1)
  17091. {
  17092. strcpy(str, (const char*)value);
  17093. for(int i = 0; str[i]; i++)
  17094. {
  17095. str[i] = tolower(str[i]);
  17096. }
  17097. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  17098. isSuccess = ConfigurationStatus_Accepted;
  17099. }
  17100. else
  17101. {
  17102. isSuccess = ConfigurationStatus_Rejected;
  17103. }
  17104. }
  17105. if(strcmp(key, "MaxEnergyOnInvalidId") == 0)
  17106. {
  17107. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].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. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemData, "%d", atoi(value) );
  17117. isSuccess = ConfigurationStatus_Accepted;
  17118. }
  17119. }
  17120. else
  17121. {
  17122. isSuccess = ConfigurationStatus_Rejected;
  17123. }
  17124. }
  17125. if(strcmp(key, "MeterValuesAlignedData") == 0)
  17126. {
  17127. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemAccessibility == 1)
  17128. {
  17129. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, "%s", value );
  17130. isSuccess = ConfigurationStatus_Accepted;
  17131. }
  17132. else
  17133. {
  17134. isSuccess = ConfigurationStatus_Rejected;
  17135. }
  17136. }
  17137. if(strcmp(key, "MeterValuesAlignedDataMaxLength") == 0)
  17138. {
  17139. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemAccessibility == 1)
  17140. {
  17141. check_ascii = value[0];
  17142. if( (check_ascii < 48) || (check_ascii > 57) )
  17143. {
  17144. isSuccess = ConfigurationStatus_Rejected;
  17145. }
  17146. else
  17147. {
  17148. //Charger.MeterValueSampleInterval = Integer.parseInt(value)*1000;
  17149. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemData, "%d", atoi(value));
  17150. isSuccess = ConfigurationStatus_Accepted;
  17151. }
  17152. }
  17153. else
  17154. {
  17155. isSuccess = ConfigurationStatus_Rejected;
  17156. }
  17157. }
  17158. if(strcmp(key, "MeterValuesSampledData") == 0 )
  17159. {
  17160. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemAccessibility == 1)
  17161. {
  17162. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, "%s", value );
  17163. isSuccess = ConfigurationStatus_Accepted;
  17164. }
  17165. else
  17166. {
  17167. isSuccess = ConfigurationStatus_Rejected;
  17168. }
  17169. }
  17170. if(strcmp(key, "MeterValuesSampledDataMaxLength") == 0)
  17171. {
  17172. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemAccessibility == 1)
  17173. {
  17174. check_ascii = value[0];
  17175. if( (check_ascii < 48) || (check_ascii > 57) )
  17176. {
  17177. isSuccess = ConfigurationStatus_Rejected;
  17178. }
  17179. else
  17180. {
  17181. //Charger.MeterValueSampleInterval = Integer.parseInt(value)*1000;
  17182. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemData, "%d", atoi(value));
  17183. isSuccess = ConfigurationStatus_Accepted;
  17184. }
  17185. }
  17186. else
  17187. {
  17188. isSuccess = ConfigurationStatus_Rejected;
  17189. }
  17190. }
  17191. if(strcmp(key, "MeterValueSampleInterval") == 0)
  17192. {
  17193. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemAccessibility == 1)
  17194. {
  17195. check_ascii = value[0];
  17196. if( (check_ascii < 48) || (check_ascii > 57) )
  17197. {
  17198. isSuccess = ConfigurationStatus_Rejected;
  17199. }
  17200. else
  17201. {
  17202. if((atoi(value) == 0) || (atoi(value) >= 3))
  17203. {
  17204. //Charger.MeterValueSampleInterval = Integer.parseInt(value)*1000;
  17205. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemData, "%d", atoi(value));
  17206. isSuccess = ConfigurationStatus_Accepted;
  17207. }
  17208. else
  17209. {
  17210. isSuccess = ConfigurationStatus_Rejected;
  17211. }
  17212. }
  17213. }
  17214. else
  17215. {
  17216. isSuccess = ConfigurationStatus_Rejected;
  17217. }
  17218. }
  17219. if(strcmp(key, "MinimumStatusDuration") == 0)
  17220. {
  17221. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemAccessibility == 1)
  17222. {
  17223. check_ascii = value[0];
  17224. if( (check_ascii < 48) || (check_ascii > 57) )
  17225. {
  17226. isSuccess = ConfigurationStatus_Rejected;
  17227. }
  17228. else
  17229. {
  17230. if(atoi(value) == 0) // MinimumStatusDuration's value can not be 0
  17231. {
  17232. isSuccess = ConfigurationStatus_Rejected;
  17233. }
  17234. else
  17235. {
  17236. //Charger.MinimumStatusDuration = Integer.parseInt(value);
  17237. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemData, "%d", atoi(value) );
  17238. server_cycle_Status = atoi(value); //StatusNotification Cycle
  17239. isSuccess = ConfigurationStatus_Accepted;
  17240. }
  17241. }
  17242. }
  17243. else
  17244. {
  17245. isSuccess = ConfigurationStatus_Rejected;
  17246. }
  17247. }
  17248. if(strcmp(key, "NumberOfConnectors") == 0)
  17249. {
  17250. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemAccessibility == 1)
  17251. {
  17252. check_ascii = value[0];
  17253. if( (check_ascii < 48) || (check_ascii > 57) )
  17254. {
  17255. isSuccess = ConfigurationStatus_Rejected;
  17256. }
  17257. else
  17258. {
  17259. //Charger.ResetRetries = Integer.parseInt(value);
  17260. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData, "%d", atoi(value) );
  17261. isSuccess = ConfigurationStatus_Accepted;
  17262. }
  17263. }
  17264. else
  17265. {
  17266. isSuccess = ConfigurationStatus_Rejected;
  17267. }
  17268. }
  17269. if(strcmp(key, "ResetRetries") == 0)
  17270. {
  17271. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemAccessibility == 1)
  17272. {
  17273. check_ascii = value[0];
  17274. if( (check_ascii < 48) || (check_ascii > 57) )
  17275. {
  17276. isSuccess = ConfigurationStatus_Rejected;
  17277. }
  17278. else
  17279. {
  17280. //Charger.ResetRetries = Integer.parseInt(value);
  17281. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemData, "%d", atoi(value) );
  17282. isSuccess = ConfigurationStatus_Accepted;
  17283. }
  17284. }
  17285. else
  17286. {
  17287. isSuccess = ConfigurationStatus_Rejected;
  17288. }
  17289. }
  17290. if(strcmp(key, "ConnectorPhaseRotation") == 0)
  17291. {
  17292. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemAccessibility == 1)
  17293. {
  17294. strcpy(str, (const char*)value);
  17295. for(int i = 0; str[i]; i++)
  17296. {
  17297. str[i] = tolower(str[i]);
  17298. }
  17299. if(strcmp(str, "notapplicable")== 0)
  17300. {
  17301. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "%s", "NotApplicable" );
  17302. isSuccess = ConfigurationStatus_Accepted;
  17303. }
  17304. else if(strcmp(str, "unknown")== 0)
  17305. {
  17306. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "%s", "Unknown" );
  17307. isSuccess = ConfigurationStatus_Accepted;
  17308. }
  17309. else if(strcmp(str, "rst")== 0)
  17310. {
  17311. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "%s", "RST" );
  17312. isSuccess = ConfigurationStatus_Accepted;
  17313. }
  17314. else if(strcmp(str, "rts")== 0)
  17315. {
  17316. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "%s", "RTS" );
  17317. isSuccess = ConfigurationStatus_Accepted;
  17318. }
  17319. else if(strcmp(str, "srt")== 0)
  17320. {
  17321. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "%s", "SRT" );
  17322. isSuccess = ConfigurationStatus_Accepted;
  17323. }
  17324. else if(strcmp(str, "str")== 0)
  17325. {
  17326. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "%s", "STR" );
  17327. isSuccess = ConfigurationStatus_Accepted;
  17328. }
  17329. else if(strcmp(str, "trs")== 0)
  17330. {
  17331. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "%s", "TRS" );
  17332. isSuccess = ConfigurationStatus_Accepted;
  17333. }
  17334. else if(strcmp(str, "tsr")== 0)
  17335. {
  17336. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "%s", "TSR" );
  17337. isSuccess = ConfigurationStatus_Accepted;
  17338. }
  17339. else
  17340. {
  17341. isSuccess = ConfigurationStatus_Rejected;
  17342. }
  17343. }
  17344. else
  17345. {
  17346. isSuccess = ConfigurationStatus_Rejected;
  17347. }
  17348. }
  17349. if(strcmp(key, "ConnectorPhaseRotationMaxLength") == 0)
  17350. {
  17351. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemAccessibility == 1)
  17352. {
  17353. check_ascii = value[0];
  17354. if( (check_ascii < 48) || (check_ascii > 57) )
  17355. {
  17356. isSuccess = ConfigurationStatus_Rejected;
  17357. }
  17358. else
  17359. {
  17360. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemData, "%d", atoi(value) );
  17361. isSuccess = ConfigurationStatus_Accepted;
  17362. }
  17363. }
  17364. else
  17365. {
  17366. isSuccess = ConfigurationStatus_Rejected;
  17367. }
  17368. }
  17369. if(strcmp(key, "StopTransactionOnEVSideDisconnect") == 0)
  17370. {
  17371. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemAccessibility == 1)
  17372. {
  17373. strcpy(str, (const char*)value);
  17374. for(int i = 0; str[i]; i++)
  17375. {
  17376. str[i] = tolower(str[i]);
  17377. }
  17378. //Charger.StopTransactionOnEVSideDisconnect = (value.toLowerCase().equals("true")?true:false);
  17379. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  17380. isSuccess = ConfigurationStatus_Accepted;
  17381. }
  17382. else
  17383. {
  17384. isSuccess = ConfigurationStatus_Rejected;
  17385. }
  17386. }
  17387. if(strcmp(key, "StopTransactionOnInvalidId") == 0)
  17388. {
  17389. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemAccessibility == 1)
  17390. {
  17391. strcpy(str, (const char*)value);
  17392. for(int i = 0; str[i]; i++)
  17393. {
  17394. str[i] = tolower(str[i]);
  17395. }
  17396. //Charger.StopTransactionOnInvalidId = (value.toLowerCase().equals("true")?true:false);
  17397. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  17398. isSuccess = ConfigurationStatus_Accepted;
  17399. }
  17400. else
  17401. {
  17402. isSuccess = ConfigurationStatus_Rejected;
  17403. }
  17404. }
  17405. if(strcmp(key, "StopTxnAlignedData") == 0)
  17406. {
  17407. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemAccessibility == 1)
  17408. {
  17409. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemData, "%s", value );
  17410. isSuccess = ConfigurationStatus_Accepted;
  17411. }
  17412. else
  17413. {
  17414. isSuccess = ConfigurationStatus_Rejected;
  17415. }
  17416. }
  17417. if(strcmp(key, "StopTxnAlignedDataMaxLength") == 0)
  17418. {
  17419. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemAccessibility == 1)
  17420. {
  17421. check_ascii = value[0];
  17422. if( (check_ascii < 48) || (check_ascii > 57) )
  17423. {
  17424. isSuccess = ConfigurationStatus_Rejected;
  17425. }
  17426. else
  17427. {
  17428. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemData, "%d", atoi(value) );
  17429. isSuccess = ConfigurationStatus_Accepted;
  17430. }
  17431. }
  17432. else
  17433. {
  17434. isSuccess = ConfigurationStatus_Rejected;
  17435. }
  17436. }
  17437. if(strcmp(key, "StopTxnSampledData") == 0)
  17438. {
  17439. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemAccessibility == 1)
  17440. {
  17441. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "%s", value );
  17442. isSuccess = ConfigurationStatus_Accepted;
  17443. }
  17444. else
  17445. {
  17446. isSuccess = ConfigurationStatus_Rejected;
  17447. }
  17448. }
  17449. if(strcmp(key, "StopTxnSampledDataMaxLength") == 0)
  17450. {
  17451. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].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. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemData, "%d", atoi(value) );
  17461. isSuccess = ConfigurationStatus_Accepted;
  17462. }
  17463. }
  17464. else
  17465. {
  17466. isSuccess = ConfigurationStatus_Rejected;
  17467. }
  17468. }
  17469. if(strcmp(key, "SupportedFeatureProfiles") == 0)
  17470. {
  17471. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemAccessibility == 1)
  17472. {
  17473. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemData, "%s", value );
  17474. isSuccess = ConfigurationStatus_Accepted;
  17475. }
  17476. else
  17477. {
  17478. isSuccess = ConfigurationStatus_Rejected;
  17479. }
  17480. }
  17481. if(strcmp(key, "SupportedFeatureProfilesMaxLength") == 0)
  17482. {
  17483. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemAccessibility == 1)
  17484. {
  17485. check_ascii = value[0];
  17486. if( (check_ascii < 48) || (check_ascii > 57) )
  17487. {
  17488. isSuccess = ConfigurationStatus_Rejected;
  17489. }
  17490. else
  17491. {
  17492. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemData, "%d", atoi(value) );
  17493. isSuccess = ConfigurationStatus_Accepted;
  17494. }
  17495. }
  17496. else
  17497. {
  17498. isSuccess = ConfigurationStatus_Rejected;
  17499. }
  17500. }
  17501. if(strcmp(key, "TransactionMessageAttempts") == 0)
  17502. {
  17503. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemAccessibility == 1)
  17504. {
  17505. check_ascii = value[0];
  17506. if( (check_ascii < 48) || (check_ascii > 57) )
  17507. {
  17508. isSuccess = ConfigurationStatus_Rejected;
  17509. }
  17510. else
  17511. {
  17512. //Charger.TransactionMessageAttempts = Integer.parseInt(value);
  17513. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData, "%d", atoi(value) );
  17514. TransactionMessageAttemptsValue = atoi(value);
  17515. isSuccess = ConfigurationStatus_Accepted;
  17516. }
  17517. }
  17518. else
  17519. {
  17520. isSuccess = ConfigurationStatus_Rejected;
  17521. }
  17522. }
  17523. if(strcmp(key, "TransactionMessageRetryInterval") == 0)
  17524. {
  17525. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemAccessibility == 1)
  17526. {
  17527. check_ascii = value[0];
  17528. if( (check_ascii < 48) || (check_ascii > 57) )
  17529. {
  17530. isSuccess = ConfigurationStatus_Rejected;
  17531. }
  17532. else
  17533. {
  17534. //Charger.TransactionMessageRetryInterval = Integer.parseInt(value)*1000;
  17535. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData, "%d", atoi(value) );
  17536. TransactionMessageRetryIntervalValue = atoi(value);
  17537. isSuccess = ConfigurationStatus_Accepted;
  17538. }
  17539. }
  17540. else
  17541. {
  17542. isSuccess = ConfigurationStatus_Rejected;
  17543. }
  17544. }
  17545. if(strcmp(key, "UnlockConnectorOnEVSideDisconnect") == 0)
  17546. {
  17547. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemAccessibility == 1)
  17548. {
  17549. strcpy(str, (const char*)value);
  17550. for(int i = 0; str[i]; i++)
  17551. {
  17552. str[i] = tolower(str[i]);
  17553. }
  17554. //Charger.UnlockConnectorOnEVSideDisconnect = (value.toLowerCase().equals("true")?true:false);
  17555. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  17556. isSuccess = ConfigurationStatus_Accepted;
  17557. }
  17558. else
  17559. {
  17560. isSuccess = ConfigurationStatus_Rejected;
  17561. }
  17562. }
  17563. if(strcmp(key, "WebSocketPingInterval") == 0)
  17564. {
  17565. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemAccessibility == 1)
  17566. {
  17567. check_ascii = value[0];
  17568. if( (check_ascii < 48) || (check_ascii > 57) )
  17569. {
  17570. isSuccess = ConfigurationStatus_Rejected;
  17571. }
  17572. else
  17573. {
  17574. if((atoi(value) == 0) || (atoi(value) >= 10))
  17575. {
  17576. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemData, "%d", atoi(value) );
  17577. isSuccess = ConfigurationStatus_Accepted;
  17578. }
  17579. else
  17580. isSuccess = ConfigurationStatus_Rejected;
  17581. }
  17582. }
  17583. else
  17584. {
  17585. isSuccess = ConfigurationStatus_Rejected;
  17586. }
  17587. }
  17588. if(strcmp(key, "QueueOffLineMeterValues") == 0)
  17589. {
  17590. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[QueueOffLineMeterValues].ItemAccessibility == 1)
  17591. {
  17592. strcpy(str, (const char*)value);
  17593. for(int i = 0; str[i]; i++)
  17594. {
  17595. str[i] = tolower(str[i]);
  17596. }
  17597. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[QueueOffLineMeterValues].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  17598. isSuccess = ConfigurationStatus_Accepted;
  17599. }
  17600. else
  17601. {
  17602. isSuccess = ConfigurationStatus_Rejected;
  17603. }
  17604. }
  17605. if(strcmp(key, "AuthorizationKey") == 0)
  17606. {
  17607. if((ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationKey].ItemAccessibility == 1) && (strlen(value) <= 40))
  17608. {
  17609. strcpy(str, (const char*)value);
  17610. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationKey].ItemData, "%s", str);
  17611. strcpy((char*)ShmSysConfigAndInfo->SysConfig.OcppSecurityPassword, (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationKey].ItemData);
  17612. isSuccess = ConfigurationStatus_Accepted;
  17613. }
  17614. else
  17615. {
  17616. isSuccess = ConfigurationStatus_Rejected;
  17617. }
  17618. }
  17619. if(strcmp(key, "SecurityProfile") == 0)
  17620. {
  17621. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[SecurityProfile].ItemAccessibility == 1)
  17622. {
  17623. check_ascii = value[0];
  17624. if( (check_ascii < 0x30) || (check_ascii > 0x33) )
  17625. {
  17626. isSuccess = ConfigurationStatus_Rejected;
  17627. }
  17628. else if(check_ascii == 0x33)
  17629. {
  17630. isSuccess = NotSupported;
  17631. }
  17632. else
  17633. {
  17634. if(atoi((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SecurityProfile].ItemData) <= (check_ascii - 0x30))
  17635. {
  17636. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SecurityProfile].ItemData, "%d", atoi(value) );
  17637. ShmSysConfigAndInfo->SysConfig.OcppSecurityProfile = atoi(value);
  17638. isSuccess = ConfigurationStatus_Accepted;
  17639. }
  17640. else
  17641. isSuccess = ConfigurationStatus_Rejected;
  17642. }
  17643. }
  17644. else
  17645. {
  17646. isSuccess = ConfigurationStatus_Rejected;
  17647. }
  17648. }
  17649. if(strcmp(key, "DefaultPrice") == 0)
  17650. {
  17651. if((ShmOCPP16Data->ConfigurationTable.CoreProfile[DefaultPrice].ItemAccessibility == 1))
  17652. {
  17653. strcpy(str, (const char*)value);
  17654. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[DefaultPrice].ItemData, "%s", str);
  17655. isSuccess = ConfigurationStatus_Accepted;
  17656. }
  17657. else
  17658. {
  17659. isSuccess = ConfigurationStatus_Rejected;
  17660. }
  17661. }
  17662. if(strcmp(key, "CustomDisplayCostAndPrice") == 0)
  17663. {
  17664. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemAccessibility == 1)
  17665. {
  17666. strcpy(str, (const char*)value);
  17667. for(int i = 0; str[i]; i++)
  17668. {
  17669. str[i] = tolower(str[i]);
  17670. }
  17671. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  17672. isSuccess = ConfigurationStatus_Accepted;
  17673. }
  17674. else
  17675. {
  17676. isSuccess = ConfigurationStatus_Rejected;
  17677. }
  17678. }
  17679. if(strcmp(key, "CustomIdleFeeAfterStop") == 0)
  17680. {
  17681. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemAccessibility == 1)
  17682. {
  17683. strcpy(str, (const char*)value);
  17684. for(int i = 0; str[i]; i++)
  17685. {
  17686. str[i] = tolower(str[i]);
  17687. }
  17688. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  17689. isSuccess = ConfigurationStatus_Accepted;
  17690. }
  17691. else
  17692. {
  17693. isSuccess = ConfigurationStatus_Rejected;
  17694. }
  17695. }
  17696. if(strcmp(key, "TimeOffset") == 0)
  17697. {
  17698. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffset].ItemAccessibility == 1)
  17699. {
  17700. strcpy(str, (const char*)value);
  17701. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffset].ItemData, "%s", str);
  17702. isSuccess = ConfigurationStatus_Accepted;
  17703. }
  17704. else
  17705. {
  17706. isSuccess = ConfigurationStatus_Rejected;
  17707. }
  17708. }
  17709. if(strcmp(key, "NextTimeOffsetTransitionDateTime") == 0)
  17710. {
  17711. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[NextTimeOffsetTransitionDateTime].ItemAccessibility == 1)
  17712. {
  17713. strcpy(str, (const char*)value);
  17714. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NextTimeOffsetTransitionDateTime].ItemData, "%s", str);
  17715. isSuccess = ConfigurationStatus_Accepted;
  17716. }
  17717. else
  17718. {
  17719. isSuccess = ConfigurationStatus_Rejected;
  17720. }
  17721. }
  17722. if(strcmp(key, "TimeOffsetNextTransition") == 0)
  17723. {
  17724. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffsetNextTransition].ItemAccessibility == 1)
  17725. {
  17726. strcpy(str, (const char*)value);
  17727. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffsetNextTransition].ItemData, "%s", str);
  17728. isSuccess = ConfigurationStatus_Accepted;
  17729. }
  17730. else
  17731. {
  17732. isSuccess = ConfigurationStatus_Rejected;
  17733. }
  17734. }
  17735. if(strcmp(key, "SystemUptimeSec") == 0)
  17736. {
  17737. isSuccess = NotSupported;
  17738. }
  17739. if(strcmp(key, "FreeVend") == 0)
  17740. {
  17741. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[FreeVend].ItemAccessibility == 1)
  17742. {
  17743. strcpy(str, (const char*)value);
  17744. for(int i = 0; str[i]; i++)
  17745. {
  17746. str[i] = tolower(str[i]);
  17747. }
  17748. ShmSysConfigAndInfo->SysConfig.AuthorisationMode = ((strcmp(str, "true")==0) ? 1 : 0 );
  17749. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[FreeVend].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  17750. isSuccess = ConfigurationStatus_Accepted;
  17751. }
  17752. else
  17753. {
  17754. isSuccess = ConfigurationStatus_Rejected;
  17755. }
  17756. }
  17757. if(strcmp(key, "FreeVendIdtag") == 0)
  17758. {
  17759. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[FreeVendIdtag].ItemAccessibility == 1)
  17760. {
  17761. strcpy(str, (const char*)value);
  17762. if(strlen(str) <= 20)
  17763. {
  17764. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[FreeVendIdtag].ItemData, "%s", str );
  17765. isSuccess = ConfigurationStatus_Accepted;
  17766. }
  17767. else
  17768. {
  17769. DEBUG_WARN("FreeVendIdtag(%s) length over 20 bytes.\n", str);
  17770. isSuccess = ConfigurationStatus_Rejected;
  17771. }
  17772. }
  17773. else
  17774. {
  17775. isSuccess = ConfigurationStatus_Rejected;
  17776. }
  17777. }
  17778. if(strcmp(key, "OcppServer") == 0)
  17779. {
  17780. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[OcppServer].ItemAccessibility == 1)
  17781. {
  17782. strcpy(str, (const char*)value);
  17783. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[OcppServer].ItemData, "%s", str );
  17784. sprintf((char *)ShmSysConfigAndInfo->SysConfig.OcppServerURL, "%s", str );
  17785. isSuccess = ConfigurationStatus_Accepted;
  17786. }
  17787. else
  17788. {
  17789. isSuccess = ConfigurationStatus_Rejected;
  17790. }
  17791. }
  17792. if(strcmp(key, "MaintainServer") == 0)
  17793. {
  17794. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MaintainServer].ItemAccessibility == 1)
  17795. {
  17796. strcpy(str, (const char*)value);
  17797. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MaintainServer].ItemData, "%s", str );
  17798. sprintf((char *)ShmSysConfigAndInfo->SysConfig.MaintainServerURL, "%s", str );
  17799. isSuccess = ConfigurationStatus_Accepted;
  17800. }
  17801. else
  17802. {
  17803. isSuccess = ConfigurationStatus_Rejected;
  17804. }
  17805. }
  17806. if(strcmp(key, "StatusNotificationPeriodically") == 0)
  17807. {
  17808. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StatusNotificationPeriodically].ItemAccessibility == 1)
  17809. {
  17810. strcpy(str, (const char*)value);
  17811. for(int i = 0; str[i]; i++)
  17812. {
  17813. str[i] = tolower(str[i]);
  17814. }
  17815. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StatusNotificationPeriodically].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE");
  17816. isSuccess = ConfigurationStatus_Accepted;
  17817. }
  17818. else
  17819. {
  17820. isSuccess = ConfigurationStatus_Rejected;
  17821. }
  17822. }
  17823. if(strcmp(key, "StatusNotificationInterval") == 0)
  17824. {
  17825. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StatusNotificationInterval].ItemAccessibility == 1)
  17826. {
  17827. check_ascii = value[0];
  17828. if( (check_ascii < 48) || (check_ascii > 57) )
  17829. {
  17830. isSuccess = ConfigurationStatus_Rejected;
  17831. }
  17832. else
  17833. {
  17834. if((atoi(value) == 0) || (atoi(value) >= 10))
  17835. {
  17836. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StatusNotificationInterval].ItemData, "%d", atoi(value) );
  17837. isSuccess = ConfigurationStatus_Accepted;
  17838. }
  17839. else
  17840. isSuccess = ConfigurationStatus_Rejected;
  17841. }
  17842. }
  17843. else
  17844. {
  17845. isSuccess = ConfigurationStatus_Rejected;
  17846. }
  17847. }
  17848. if(strcmp(key, "PreAuthAmount") == 0)
  17849. {
  17850. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[PreAuthAmount].ItemAccessibility == 1)
  17851. {
  17852. check_ascii = value[0];
  17853. if( (check_ascii < 48) || (check_ascii > 57) )
  17854. {
  17855. isSuccess = ConfigurationStatus_Rejected;
  17856. }
  17857. else
  17858. {
  17859. if(atof(value) >= 0)
  17860. {
  17861. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[PreAuthAmount].ItemData, "%.2f", atof(value) );
  17862. isSuccess = ConfigurationStatus_Accepted;
  17863. }
  17864. else
  17865. isSuccess = ConfigurationStatus_Rejected;
  17866. }
  17867. }
  17868. else
  17869. {
  17870. isSuccess = ConfigurationStatus_Rejected;
  17871. }
  17872. }
  17873. if(strcmp(key, "isEnableLocalPowerSharing") == 0)
  17874. {
  17875. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[isEnableLocalPowerSharing].ItemAccessibility == 1)
  17876. {
  17877. check_ascii = value[0];
  17878. if( (check_ascii < 48) || (check_ascii > 57) )
  17879. {
  17880. isSuccess = ConfigurationStatus_Rejected;
  17881. }
  17882. else
  17883. {
  17884. if(atoi(value) >= 0)
  17885. {
  17886. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[isEnableLocalPowerSharing].ItemData, "%d", atoi(value));
  17887. ShmSysConfigAndInfo->SysConfig.isEnableLocalPowerSharing = (unsigned char)atoi(value);
  17888. isSuccess = ConfigurationStatus_Accepted;
  17889. }
  17890. else
  17891. isSuccess = ConfigurationStatus_Rejected;
  17892. }
  17893. }
  17894. else
  17895. {
  17896. isSuccess = ConfigurationStatus_Rejected;
  17897. }
  17898. }
  17899. if(strcmp(key, "PowerSharingServerIP") == 0)
  17900. {
  17901. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[PowerSharingServerIP].ItemAccessibility == 1)
  17902. {
  17903. strcpy(str, (const char*)value);
  17904. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[PowerSharingServerIP].ItemData, "%s", str );
  17905. sprintf((char *)ShmSysConfigAndInfo->SysConfig.PowerSharingServerIP, "%s", str );
  17906. isSuccess = ConfigurationStatus_Accepted;
  17907. }
  17908. else
  17909. {
  17910. isSuccess = ConfigurationStatus_Rejected;
  17911. }
  17912. }
  17913. if(strcmp(key, "EVCCID_PREFIX") == 0)
  17914. {
  17915. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[EVCCID_PREFIX].ItemAccessibility == 1)
  17916. {
  17917. strcpy(str, (const char*)value);
  17918. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[EVCCID_PREFIX].ItemData, "%s", str );
  17919. isSuccess = ConfigurationStatus_Accepted;
  17920. }
  17921. else
  17922. {
  17923. isSuccess = ConfigurationStatus_Rejected;
  17924. }
  17925. }
  17926. if(strcmp(key, "OffLineMaxChargingPower") == 0)
  17927. {
  17928. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[OffLineMaxChargingPower].ItemAccessibility == 1)
  17929. {
  17930. if(atoi(value) > modelnameInfo.ratedPower)
  17931. {
  17932. isSuccess = ConfigurationStatus_Rejected;
  17933. }
  17934. else{
  17935. strcpy(str, (const char*)value);
  17936. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[OffLineMaxChargingPower].ItemData, "%s", str );
  17937. isSuccess = ConfigurationStatus_Accepted;
  17938. }
  17939. }
  17940. else
  17941. {
  17942. isSuccess = ConfigurationStatus_Rejected;
  17943. }
  17944. }
  17945. if(strcmp(key, "CharingProfileRefreshInterval") == 0)
  17946. {
  17947. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[CharingProfileRefreshInterval].ItemAccessibility == 1)
  17948. {
  17949. if((atoi(value) != 0) && (atoi(value) < 5))
  17950. {
  17951. isSuccess = ConfigurationStatus_Rejected;
  17952. }
  17953. else{
  17954. strcpy(str, (const char*)value);
  17955. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CharingProfileRefreshInterval].ItemData, "%s", str );
  17956. isSuccess = ConfigurationStatus_Accepted;
  17957. }
  17958. }
  17959. else
  17960. {
  17961. isSuccess = ConfigurationStatus_Rejected;
  17962. }
  17963. }
  17964. #if 0
  17965. //For OCPP Test Case
  17966. if(strcmp(key, "LocalAuthorizationListEnabled") == 0)
  17967. {
  17968. if(ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemAccessibility == 1)
  17969. {
  17970. strcpy(str, (const char*)value);
  17971. for(int i = 0; str[i]; i++)
  17972. {
  17973. str[i] = tolower(str[i]);
  17974. }
  17975. sprintf((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  17976. isSuccess = ConfigurationStatus_Accepted;
  17977. //updateSetting("LocalAuthorizationListEnabled", (char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData);
  17978. }
  17979. else
  17980. {
  17981. isSuccess = ConfigurationStatus_Rejected;
  17982. }
  17983. }
  17984. #endif
  17985. #if 1
  17986. if(strcmp(key, "LocalAuthListEnabled") == 0)
  17987. {
  17988. if(ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemAccessibility == 1)
  17989. {
  17990. strcpy(str, (const char*)value);
  17991. for(int i = 0; str[i]; i++)
  17992. {
  17993. str[i] = tolower(str[i]);
  17994. }
  17995. sprintf((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  17996. isSuccess = ConfigurationStatus_Accepted;
  17997. //updateSetting("LocalAuthListEnabled", (char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData);
  17998. }
  17999. else
  18000. {
  18001. isSuccess = ConfigurationStatus_Rejected;
  18002. }
  18003. }
  18004. #endif
  18005. if(strcmp(key, "LocalAuthListMaxLength") == 0)
  18006. {
  18007. if(ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemAccessibility == 1)
  18008. {
  18009. check_ascii = value[0];
  18010. if( (check_ascii < 48) || (check_ascii > 57) )
  18011. {
  18012. isSuccess = ConfigurationStatus_Rejected;
  18013. }
  18014. else
  18015. {
  18016. sprintf((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemData, "%d", atoi(value) );
  18017. isSuccess = ConfigurationStatus_Accepted;
  18018. }
  18019. }
  18020. else
  18021. {
  18022. isSuccess = ConfigurationStatus_Rejected;
  18023. }
  18024. }
  18025. if(strcmp(key, "SendLocalListMaxLength") == 0)
  18026. {
  18027. if(ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemAccessibility == 1)
  18028. {
  18029. check_ascii = value[0];
  18030. if( (check_ascii < 48) || (check_ascii > 57) )
  18031. {
  18032. isSuccess = ConfigurationStatus_Rejected;
  18033. }
  18034. else
  18035. {
  18036. sprintf((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemData, "%d", atoi(value) );
  18037. isSuccess = ConfigurationStatus_Accepted;
  18038. }
  18039. }
  18040. else
  18041. {
  18042. isSuccess = ConfigurationStatus_Rejected;
  18043. }
  18044. }
  18045. if(strcmp(key, "ReserveConnectorZeroSupported") == 0)
  18046. {
  18047. if(ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemAccessibility == 1)
  18048. {
  18049. strcpy(str, (const char*)value);
  18050. for(int i = 0; str[i]; i++)
  18051. {
  18052. str[i] = tolower(str[i]);
  18053. }
  18054. sprintf((char *)ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  18055. isSuccess = ConfigurationStatus_Accepted;
  18056. }
  18057. else
  18058. {
  18059. isSuccess = ConfigurationStatus_Rejected;
  18060. }
  18061. }
  18062. if(strcmp(key, "ChargeProfileMaxStackLevel") == 0)
  18063. {
  18064. if(ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemAccessibility == 1)
  18065. {
  18066. check_ascii = value[0];
  18067. if( (check_ascii < 48) || (check_ascii > 57) )
  18068. {
  18069. isSuccess = ConfigurationStatus_Rejected;
  18070. }
  18071. else
  18072. {
  18073. sprintf((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemData, "%d", atoi(value) );
  18074. isSuccess = ConfigurationStatus_Accepted;
  18075. }
  18076. }
  18077. else
  18078. {
  18079. isSuccess = ConfigurationStatus_Rejected;
  18080. }
  18081. }
  18082. if(strcmp(key, "ChargingScheduleAllowedChargingRateUnit") == 0)
  18083. {
  18084. if(ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemAccessibility == 1)
  18085. {
  18086. sprintf((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemData, "%s", value );
  18087. isSuccess = ConfigurationStatus_Accepted;
  18088. }
  18089. else
  18090. {
  18091. isSuccess = ConfigurationStatus_Rejected;
  18092. }
  18093. }
  18094. if(strcmp(key, "ChargingScheduleMaxPeriods") == 0)
  18095. {
  18096. if(ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemAccessibility == 1)
  18097. {
  18098. check_ascii = value[0];
  18099. if( (check_ascii < 48) || (check_ascii > 57) )
  18100. {
  18101. isSuccess = ConfigurationStatus_Rejected;
  18102. }
  18103. else
  18104. {
  18105. sprintf((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemData, "%d", atoi(value) );
  18106. isSuccess = ConfigurationStatus_Accepted;
  18107. }
  18108. }
  18109. else
  18110. {
  18111. isSuccess = ConfigurationStatus_Rejected;
  18112. }
  18113. }
  18114. if(strcmp(key, "ConnectorSwitch3to1PhaseSupported") == 0)
  18115. {
  18116. if(ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemAccessibility == 1)
  18117. {
  18118. strcpy(str, (const char*)value);
  18119. for(int i = 0; str[i]; i++)
  18120. {
  18121. str[i] = tolower(str[i]);
  18122. }
  18123. sprintf((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  18124. isSuccess = ConfigurationStatus_Accepted;
  18125. }
  18126. else
  18127. {
  18128. isSuccess = ConfigurationStatus_Rejected;
  18129. }
  18130. }
  18131. if(strcmp(key, "MaxChargingProfilesInstalled") == 0)
  18132. {
  18133. if(ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemAccessibility == 1)
  18134. {
  18135. check_ascii = value[0];
  18136. if( (check_ascii < 48) || (check_ascii > 57) )
  18137. {
  18138. isSuccess = ConfigurationStatus_Rejected;
  18139. }
  18140. else
  18141. {
  18142. sprintf((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemData, "%d", atoi(value) );
  18143. isSuccess = ConfigurationStatus_Accepted;
  18144. }
  18145. }
  18146. else
  18147. {
  18148. isSuccess = ConfigurationStatus_Rejected;
  18149. }
  18150. }
  18151. system("/bin/fsync -d /dev/mtdblock13;/bin/sync &");
  18152. return isSuccess;
  18153. }
  18154. int TransactionMessageAttemptsGet(void)
  18155. {
  18156. return TransactionMessageAttemptsValue;
  18157. }
  18158. int FirstHeartBeatResponse(void)
  18159. {
  18160. return FirstHeartBeat;
  18161. }
  18162. int TransactionMessageRetryIntervalGet(void)
  18163. {
  18164. return TransactionMessageRetryIntervalValue;//atoi((const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData);
  18165. }
  18166. int ReadHttpStatus(int sock)
  18167. {
  18168. //char c;
  18169. char buff[1024]="",*ptr=buff+1;
  18170. int bytes_received, status;
  18171. DEBUG_INFO("Begin Response ..\n");
  18172. while((bytes_received = recv(sock, ptr, 1, 0))){
  18173. if(bytes_received==-1){
  18174. perror("ReadHttpStatus");
  18175. exit(1);
  18176. }
  18177. if((ptr[-1]=='\r') && (*ptr=='\n' )) break;
  18178. ptr++;
  18179. }
  18180. *ptr=0;
  18181. ptr=buff+1;
  18182. sscanf(ptr,"%*s %d ", &status);
  18183. DEBUG_INFO("%s\n",ptr);
  18184. DEBUG_INFO("status=%d\n",status);
  18185. DEBUG_INFO("End Response ..\n");
  18186. return (bytes_received>0)?status:0;
  18187. }
  18188. //the only filed that it parsed is 'Content-Length'
  18189. int ParseHeader(int sock)
  18190. {
  18191. //char c;
  18192. char buff[1024]="",*ptr=buff+4;
  18193. int bytes_received;
  18194. DEBUG_INFO("Begin HEADER ..\n");
  18195. while((bytes_received = recv(sock, ptr, 1, 0))){
  18196. if(bytes_received==-1){
  18197. perror("Parse Header");
  18198. exit(1);
  18199. }
  18200. if(
  18201. (ptr[-3]=='\r') && (ptr[-2]=='\n' ) &&
  18202. (ptr[-1]=='\r') && (*ptr=='\n' )
  18203. ) break;
  18204. ptr++;
  18205. }
  18206. *ptr=0;
  18207. ptr=buff+4;
  18208. //printf("%s",ptr);
  18209. if(bytes_received){
  18210. ptr=strstr(ptr,"Content-Length:");
  18211. if(ptr){
  18212. sscanf(ptr,"%*s %d",&bytes_received);
  18213. }else
  18214. bytes_received=-1; //unknown size
  18215. DEBUG_INFO("Content-Length: %d\n",bytes_received);
  18216. }
  18217. DEBUG_INFO("End HEADER ..\n");
  18218. return bytes_received ;
  18219. }
  18220. int httpDownLoadFile(char *location, char *path, char *filename,char *url)
  18221. {
  18222. int result = TRUE;
  18223. char rmFileCmd[100]={0};
  18224. char FilePath[100]={0};
  18225. char ftpbuf[200];
  18226. int systemresult;
  18227. sprintf(FilePath,"/mnt/%s",filename);
  18228. system("ping 8.8.8.8 &");
  18229. if((access(FilePath,F_OK))!=-1)
  18230. {
  18231. DEBUG_INFO("filename=%s exist.\n",FilePath);
  18232. sprintf(rmFileCmd,"rm -f %s",FilePath);
  18233. system(rmFileCmd);
  18234. }
  18235. memset(ftpbuf, 0, ARRAY_SIZE(ftpbuf));
  18236. sprintf(ftpbuf, "wget --tries=1 -O /mnt/%s -c %s -T 120 --no-check-certificate",filename, url);
  18237. DEBUG_INFO("Download command: %s\n",ftpbuf);
  18238. systemresult = system(ftpbuf);
  18239. if(systemresult != 0)
  18240. {
  18241. DEBUG_INFO("HTTP/HTTPS downLoad fail!\n");
  18242. result = FALSE;
  18243. }
  18244. system("pkill ping");
  18245. return result;
  18246. }
  18247. int sftpDownLoadFile(char *location, char *user, int port, char *path, char *filename,char *url)
  18248. {
  18249. int result = TRUE;
  18250. char rmFileCmd[100]={0};
  18251. char FilePath[100]={0};
  18252. char ftpbuf[200];
  18253. int systemresult;
  18254. sprintf(FilePath,"/mnt/%s",filename);
  18255. system("ping 8.8.8.8 &");
  18256. if((access(FilePath,F_OK))!=-1)
  18257. {
  18258. DEBUG_INFO("filename=%s exist.\n",FilePath);
  18259. sprintf(rmFileCmd,"rm -f %s",FilePath);
  18260. system(rmFileCmd);
  18261. }
  18262. memset(ftpbuf, 0, ARRAY_SIZE(ftpbuf));
  18263. sprintf(ftpbuf,"timeout -t 360 scp -i /root/.ssh/id_rsa_bear -P %d %s@%s%s /mnt/%s", port, user, path, filename, filename);
  18264. DEBUG_INFO("Download command: %s\n",ftpbuf);
  18265. systemresult = system(ftpbuf);
  18266. if(systemresult != 0)
  18267. {
  18268. DEBUG_WARN("scp error!\n");
  18269. result = FALSE;
  18270. }
  18271. system("pkill ping");
  18272. return result;
  18273. }
  18274. int ftpDownLoadFile(char *location, char *user, char *password, int port, char *path, char *filename,char *url)
  18275. {
  18276. int result = TRUE;
  18277. char rmFileCmd[100]={0};
  18278. char FilePath[100]={0};
  18279. char ftpbuf[200];
  18280. int systemresult;
  18281. sprintf(FilePath,"/mnt/%s",filename);
  18282. system("ping 8.8.8.8 &");
  18283. if((access(FilePath,F_OK))!=-1)
  18284. {
  18285. DEBUG_INFO("filename=%s exist.\n",FilePath);
  18286. sprintf(rmFileCmd,"rm -f %s",FilePath);
  18287. system(rmFileCmd);
  18288. }
  18289. memset(ftpbuf, 0, ARRAY_SIZE(ftpbuf));
  18290. sprintf(ftpbuf, "wget --tries=1 -O /mnt/%s -c %s -T 120",filename, url);
  18291. DEBUG_INFO("Download command: %s\n",ftpbuf);
  18292. systemresult = system(ftpbuf);
  18293. if(systemresult != 0)
  18294. {
  18295. sprintf(ftpbuf, "wget --tries=1 -O /mnt/%s -c %s -T 120 --no-passive-ftp",filename, url);
  18296. DEBUG_INFO("Download command: %s\n",ftpbuf);
  18297. systemresult = system(ftpbuf);
  18298. if(systemresult != 0)
  18299. {
  18300. DEBUG_WARN("FTP download fail!\n");
  18301. result = FALSE;
  18302. }
  18303. }
  18304. system("pkill ping");
  18305. return result;
  18306. }
  18307. int httpUploadFile(char *location, char *path, char *filename,char *url)
  18308. {
  18309. char rmFileCmd[100]={0};
  18310. char FilePath[100]={0};
  18311. char buf[512];
  18312. int systemresult = 0;
  18313. //DEBUG_INFO("filename=%s\n",filename);
  18314. //DEBUG_INFO("url=%s\n",url);
  18315. sprintf(FilePath,"%s","/mnt/upload_file.txt");
  18316. if((access(FilePath,F_OK))!=-1)
  18317. {
  18318. DEBUG_INFO("filename=%s exist.\n",FilePath);
  18319. sprintf(rmFileCmd,"rm -f %s",FilePath);
  18320. system(rmFileCmd);
  18321. }
  18322. FILE *fp = fopen("/mnt/upload_file.txt", "w+");
  18323. if(fp == NULL)
  18324. {
  18325. DEBUG_INFO("log is NULL\n");
  18326. return FALSE;
  18327. }
  18328. else
  18329. {
  18330. fprintf(fp, "%s\n", url);
  18331. fprintf(fp, "%s\n", filename);
  18332. fclose(fp);
  18333. }
  18334. FILE *phpFP = popen("/bin/php-cgi /var/www/ocpp_upload.php", "r");
  18335. if(phpFP == NULL)
  18336. {
  18337. DEBUG_INFO("PHP upload fail.\n");
  18338. return FALSE;
  18339. }
  18340. else
  18341. {
  18342. while(fgets(buf, sizeof(buf), phpFP) != NULL)
  18343. {
  18344. if(strstr(buf, "result") != NULL)
  18345. {
  18346. sscanf(buf, "result: %d", &systemresult);
  18347. DEBUG_INFO("PHP HTTP upload result: %d\n", systemresult);
  18348. }
  18349. }
  18350. pclose(phpFP);
  18351. }
  18352. if(systemresult != 1)
  18353. {
  18354. DEBUG_WARN("HTTP POST upload error, change to PUT method\n");
  18355. FILE *phpFP = popen("/bin/php-cgi /var/www/ocpp_upload_put.php", "r");
  18356. if(phpFP == NULL)
  18357. {
  18358. DEBUG_WARN("PHP PUT upload fail.\n");
  18359. return FALSE;
  18360. }
  18361. else
  18362. {
  18363. while(fgets(buf, sizeof(buf), phpFP) != NULL)
  18364. {
  18365. if(strstr(buf, "result") != NULL)
  18366. {
  18367. sscanf(buf, "result: %d", &systemresult);
  18368. DEBUG_INFO("PHP HTTP PUT upload result: %d\n", systemresult);
  18369. }
  18370. }
  18371. pclose(phpFP);
  18372. }
  18373. }
  18374. if(systemresult != 1)
  18375. {
  18376. DEBUG_WARN("PHP PUT upload fail.\n");
  18377. return FALSE;
  18378. }
  18379. return TRUE;
  18380. }
  18381. int ftpUploadFile(char *location, char *user, char *password, int port, char *path, char *fnamePlusPath,char *filename)
  18382. {
  18383. int result = FALSE;
  18384. char ftpbuf[200];
  18385. int systemresult;
  18386. /*
  18387. // Domaind name transfer to IP address
  18388. struct hostent* server;
  18389. char *IPbuffer;
  18390. server = gethostbyname(location);
  18391. IPbuffer = inet_ntoa(*((struct in_addr*)server->h_addr_list[0]));*/
  18392. memset(ftpbuf, 0, ARRAY_SIZE(ftpbuf));
  18393. sprintf(ftpbuf, "ftpput -u %s -p %s %s -P %d %s%s %s", user, password, location, port/*21*/, path, filename, fnamePlusPath);
  18394. DEBUG_INFO("ftp command: %s\n",ftpbuf);
  18395. systemresult = system(ftpbuf);
  18396. if(systemresult != 0)
  18397. {
  18398. DEBUG_INFO("ftpput error!\n");
  18399. }
  18400. else
  18401. {
  18402. result = TRUE;
  18403. DEBUG_INFO("ftpput OK!\n");
  18404. }
  18405. return result;
  18406. }
  18407. int GetOcppServerURL()
  18408. {
  18409. int result = FALSE;
  18410. memset(OcppProtocol, 0, ARRAY_SIZE(OcppProtocol));
  18411. memset(OcppHost, 0, ARRAY_SIZE(OcppHost));
  18412. memset(OcppTempPath, 0, ARRAY_SIZE(OcppTempPath));
  18413. struct yuarel url;
  18414. char urlStr[512];
  18415. if((ShmSysConfigAndInfo->SysConfig.OcppServerURL != NULL) && (strcmp((const char *)ShmSysConfigAndInfo->SysConfig.OcppServerURL,"") != 0) )
  18416. {
  18417. /*sscanf((const char *)ShmSysConfigAndInfo->SysConfig.OcppServerURL,
  18418. "%[^:]:%*2[/]%[^:]:%i/%[a-zA-Z0-9._/-]",
  18419. OcppProtocol, OcppHost, &OcppPort, OcppTempPath);*/
  18420. memcpy(urlStr, ShmSysConfigAndInfo->SysConfig.OcppServerURL, ARRAY_SIZE(ShmSysConfigAndInfo->SysConfig.OcppServerURL));
  18421. if(yuarel_parse(&url, urlStr) != -1)
  18422. {
  18423. sprintf(OcppProtocol, "%s", url.scheme);
  18424. sprintf(OcppHost, "%s", url.host);
  18425. if(url.path == NULL)
  18426. OcppTempPath[0] = '\0';
  18427. else
  18428. {
  18429. if((url.path[strlen(url.path)-1] != '/') && (strlen(url.path) > 0))
  18430. {
  18431. sprintf(OcppTempPath, "%s/", url.path);
  18432. }
  18433. else
  18434. {
  18435. sprintf(OcppTempPath, "%s", url.path);
  18436. }
  18437. }
  18438. if(url.port == 0)
  18439. {
  18440. if(strcmp(OcppProtocol, "wss") == 0)
  18441. OcppPort = 443;
  18442. else
  18443. OcppPort = 80;
  18444. }
  18445. else
  18446. OcppPort = url.port;
  18447. result = TRUE;
  18448. }
  18449. }
  18450. else if((ShmOCPP16Data->OcppServerURL != NULL) && (strcmp((const char *)ShmOCPP16Data->OcppServerURL,"") != 0))
  18451. {
  18452. /*sscanf((const char *)ShmOCPP16Data->OcppServerURL,
  18453. "%[^:]:%*2[/]%[^:]:%i/%[a-zA-Z0-9._/-]",
  18454. OcppProtocol, OcppHost, &OcppPort, OcppTempPath);*/
  18455. memcpy(urlStr, ShmOCPP16Data->OcppServerURL, ARRAY_SIZE(ShmOCPP16Data->OcppServerURL));
  18456. if(yuarel_parse(&url, urlStr) != -1)
  18457. {
  18458. sprintf(OcppProtocol, "%s", url.scheme);
  18459. sprintf(OcppHost, "%s", url.host);
  18460. if(url.path == NULL)
  18461. OcppTempPath[0] = '\0';
  18462. else
  18463. sprintf(OcppTempPath, "%s", url.path);
  18464. if(url.port == 0)
  18465. {
  18466. if(strcmp(OcppProtocol, "wss") == 0)
  18467. OcppPort = 443;
  18468. else
  18469. OcppPort = 80;
  18470. }
  18471. else
  18472. OcppPort = url.port;
  18473. result = TRUE;
  18474. }
  18475. }
  18476. else
  18477. {
  18478. strcpy(OcppHost,"");
  18479. }
  18480. return result;
  18481. }
  18482. int GetOcppPath()
  18483. {
  18484. int result = FALSE;
  18485. if((ShmSysConfigAndInfo->SysConfig.ChargeBoxId != NULL) && (strcmp((const char *)ShmSysConfigAndInfo->SysConfig.ChargeBoxId,"") != 0) )
  18486. {
  18487. if(OcppTempPath == NULL)
  18488. {
  18489. sprintf(OcppPath,"/%s",ShmSysConfigAndInfo->SysConfig.ChargeBoxId);
  18490. }
  18491. else
  18492. {
  18493. sprintf(OcppPath,"/%s%s",OcppTempPath,ShmSysConfigAndInfo->SysConfig.ChargeBoxId);
  18494. }
  18495. result = TRUE;
  18496. goto End;
  18497. }
  18498. else if((ShmOCPP16Data->ChargeBoxId != NULL) && (strcmp((const char *)ShmOCPP16Data->ChargeBoxId,"") != 0))
  18499. {
  18500. if(OcppTempPath == NULL)
  18501. {
  18502. sprintf(OcppPath,"/%s",ShmOCPP16Data->ChargeBoxId);
  18503. }
  18504. else
  18505. {
  18506. sprintf(OcppPath,"/%s%s",OcppTempPath,ShmOCPP16Data->ChargeBoxId);
  18507. }
  18508. result = TRUE;
  18509. goto End;
  18510. }
  18511. else
  18512. {
  18513. strcpy(OcppPath,"");
  18514. }
  18515. End:
  18516. return result;
  18517. }
  18518. int GetOcppPort()
  18519. {
  18520. return OcppPort;
  18521. }
  18522. int GetOcppConnStatus(void)
  18523. {
  18524. return ShmOCPP16Data->OcppConnStatus;
  18525. }
  18526. void SetOcppConnStatus(uint8_t status)
  18527. {
  18528. ShmOCPP16Data->OcppConnStatus = status;
  18529. ShmSysConfigAndInfo->SysInfo.OcppConnStatus = status;
  18530. }
  18531. int GetHeartBeatWithNOResponse(void)
  18532. {
  18533. return HeartBeatWithNOResponse;
  18534. }
  18535. void SetHeartBeatWithNOResponse(void)
  18536. {
  18537. HeartBeatWithNOResponse = 0;
  18538. }
  18539. void GetStartTransactionIdTag(int gun_index)
  18540. {
  18541. memset(StartTransactionIdTagTemp, 0 ,ARRAY_SIZE(StartTransactionIdTagTemp));
  18542. strcpy((char *)StartTransactionIdTagTemp, (const char *)ShmOCPP16Data->StartTransaction[gun_index].IdTag);
  18543. }
  18544. int GetStartTransactionId(int gun_index)
  18545. {
  18546. return ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId;
  18547. }
  18548. int GetTransactionId(int gunindex, unsigned char idTag[], uint8_t isStopTransaction)
  18549. {
  18550. char ch;
  18551. FILE *fptr1;
  18552. int temptransactionId;
  18553. char str[100]={0};
  18554. temptransactionId = 0;
  18555. if(((strcmp((const char*)idTag, "")==0)||(idTag[0]=='\0')) && isStopTransaction)
  18556. {
  18557. DEBUG_INFO("IdTag is empty.\n");
  18558. return temptransactionId;
  18559. }
  18560. /*------ Read the file ----------------*/
  18561. fptr1=fopen("/Storage/OCPP/QueueTransactionId","r");
  18562. if (!fptr1)
  18563. {
  18564. DEBUG_INFO("QueueTransactionId file open error.\n");
  18565. //printf(" File not found or unable to open the input file!!\n");
  18566. return temptransactionId;
  18567. }
  18568. ch=fgetc(fptr1);
  18569. //printf(" Now the content of the file %s is : \n","/Storage/OCPP/QueueTransactionId");
  18570. rewind(fptr1);
  18571. if(ch!=EOF)
  18572. {
  18573. // printf("%c",ch);
  18574. while (fgets(str, 100, fptr1) != NULL)
  18575. {
  18576. str[strlen(str) - 1] = '\0'; // eat the newline fgets() stores
  18577. if(str[0]=='\0')
  18578. {
  18579. break;
  18580. }
  18581. char *revbuf[8] = {0}; // Variable store string split
  18582. int num = 0;// Quantity after string split
  18583. DEBUG_INFO("Transaction queue data= %s\n", str);
  18584. splitstring(str,",",revbuf,&num); // String split
  18585. DEBUG_INFO(" revbuf[0]= %s\n", revbuf[0]);
  18586. DEBUG_INFO(" revbuf[1]= %s\n", revbuf[1]);
  18587. DEBUG_INFO(" revbuf[2]= %s\n", revbuf[2]);
  18588. DEBUG_INFO("------------------------------\n");
  18589. if((revbuf[1][0] != '\0')&&(revbuf[2][0] != '\0'))
  18590. {
  18591. if(isStopTransaction)
  18592. {
  18593. if((atoi(revbuf[0])==gunindex) && (strcmp(revbuf[1],(const char *)idTag)==0))
  18594. {
  18595. temptransactionId = atoi(revbuf[2]);
  18596. //break;
  18597. }
  18598. }
  18599. else
  18600. {
  18601. if((atoi(revbuf[0])==gunindex) || (strcmp(revbuf[1],(const char *)idTag)==0))
  18602. {
  18603. temptransactionId = atoi(revbuf[2]);
  18604. //break;
  18605. }
  18606. }
  18607. }
  18608. }
  18609. }
  18610. else
  18611. DEBUG_INFO("EOF\n");
  18612. fclose(fptr1);
  18613. /*------- End of reading ---------------*/
  18614. return temptransactionId;
  18615. }
  18616. void SetTransactionIdZero(int transactionId)
  18617. {
  18618. char ch;
  18619. FILE *fptr1, *fptr2;
  18620. int temptransactionId = 0;
  18621. char str[100]={0}, strtemp[100]={0}, temp[] = "/Storage/OCPP/QueueTransactionIdtemp.json";
  18622. fptr1 = fopen("/Storage/OCPP/QueueTransactionId", "r");
  18623. if (!fptr1)
  18624. {
  18625. //printf(" File not found or unable to open the input file!!\n");
  18626. return ;
  18627. }
  18628. fptr2 = fopen(temp, "w"); // open the temporary file in write mode
  18629. if (!fptr2)
  18630. {
  18631. DEBUG_INFO("Unable to open a temporary file to write!!\n");
  18632. fclose(fptr1);
  18633. return ;
  18634. }
  18635. ch=fgetc(fptr1);
  18636. rewind(fptr1);
  18637. if(ch!=EOF)
  18638. {
  18639. // copy all contents to the temporary file except the specific line
  18640. while (fgets(str, 100, fptr1) != NULL)
  18641. {
  18642. str[strlen(str) - 1] = '\0'; // eat the newline fgets() stores
  18643. if(str[0]=='\0')
  18644. {
  18645. break;
  18646. }
  18647. char *revbuf[8] = {0};
  18648. int num = 0;
  18649. strcpy(strtemp, str);
  18650. splitstring(str,",",revbuf,&num);
  18651. if(revbuf[2][0] != '\0')
  18652. {
  18653. temptransactionId = atoi(revbuf[2]);
  18654. if(transactionId != temptransactionId)
  18655. {
  18656. fprintf(fptr2, "%s\n", strtemp);
  18657. }
  18658. }
  18659. }
  18660. }
  18661. fclose(fptr1);
  18662. fclose(fptr2);
  18663. remove("/Storage/OCPP/QueueTransactionId"); // remove the original file
  18664. rename(temp, "/Storage/OCPP/QueueTransactionId"); // rename the temporary file to original name
  18665. /*------ Read the file ----------------*/
  18666. }
  18667. int InternetDisconnect(void)
  18668. {
  18669. return (ShmStatusCodeData->InfoCode.InfoEvents.bits.InternetDisconnectVia4Gi && ShmStatusCodeData->InfoCode.InfoEvents.bits.InternetDisconnectViaEthernet && ShmStatusCodeData->InfoCode.InfoEvents.bits.InternetDisconnectViaWiFi );
  18670. }
  18671. //Note: It is not real StopTransaction. It is temporary StopTransaction.
  18672. void storeTempStopTransaction(int gun_index)
  18673. {
  18674. char guid[37]={0};
  18675. int tempIndex = 0;
  18676. char TempStopTransaction[256];
  18677. sprintf(TempStopTransaction, "/Storage/OCPP/TempStopTransaction_%d", (gun_index+1));
  18678. DEBUG_INFO("storeTempStopTransaction...\n");
  18679. memset(queuedata, 0, ARRAY_SIZE(queuedata));
  18680. memset(&ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0], 0, ARRAY_SIZE(ShmOCPP16Data->StopTransaction[gun_index].TransactionData));
  18681. //======================== ENERGY_ACTIVE_IMPORT_REGISTER =======================================
  18682. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DCcc
  18683. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  18684. {
  18685. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  18686. {
  18687. tempIndex = ((gun_index==2) ? 1: 0);
  18688. }
  18689. else
  18690. {
  18691. tempIndex = gun_index;
  18692. }
  18693. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  18694. {
  18695. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  18696. {
  18697. ShmOCPP16Data->StopTransaction[gun_index].MeterStop = (int)(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PowerConsumption*1000);
  18698. }
  18699. }// END OF CHAdeMO_QUANTITY
  18700. }
  18701. else if(gunType[gun_index] == GUN_TYPE_CCS)
  18702. {
  18703. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  18704. {
  18705. tempIndex = ((gun_index==2) ? 1: 0);
  18706. }
  18707. else
  18708. {
  18709. tempIndex = gun_index;
  18710. }
  18711. for (int index = 0; index < CCS_QUANTITY; index++)
  18712. {
  18713. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  18714. {
  18715. ShmOCPP16Data->StopTransaction[gun_index].MeterStop = (int)(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PowerConsumption*1000);
  18716. }
  18717. }// END OF CCS_QUANTITY
  18718. }
  18719. else if(gunType[gun_index] == GUN_TYPE_GBT)
  18720. {
  18721. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  18722. {
  18723. tempIndex = ((gun_index==2) ? 1: 0);
  18724. }
  18725. else
  18726. {
  18727. tempIndex = gun_index;
  18728. }
  18729. for (int index = 0; index < GB_QUANTITY; index++)
  18730. {
  18731. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  18732. {
  18733. ShmOCPP16Data->StopTransaction[gun_index].MeterStop = (int)(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PowerConsumption*1000);
  18734. }
  18735. }// END OF GB_QUANTITY
  18736. }
  18737. else if(gunType[gun_index] == GUN_TYPE_DO)
  18738. {
  18739. tempIndex = gun_index;
  18740. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  18741. {
  18742. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  18743. {
  18744. ShmOCPP16Data->StopTransaction[gun_index].MeterStop = (int)(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PowerConsumption*1000);
  18745. }
  18746. }
  18747. }
  18748. else
  18749. {
  18750. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  18751. {
  18752. tempIndex = 2;
  18753. }
  18754. else
  18755. {
  18756. tempIndex = gun_index;
  18757. }
  18758. for (int index = 0; index < AC_QUANTITY; index++)
  18759. {
  18760. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  18761. {
  18762. ShmOCPP16Data->StopTransaction[gun_index].MeterStop = (int)(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PowerConsumption*1000);
  18763. }
  18764. }// END OF AC_QUANTITY
  18765. }
  18766. //Stop Transaction Time
  18767. struct timeval tmnow;
  18768. struct tm *tm;
  18769. char buf[28];//, usec_buf[6];
  18770. gettimeofday(&tmnow, NULL);
  18771. time_t t;
  18772. t = time(NULL);
  18773. /*UTC time and date*/
  18774. tm = gmtime(&t);
  18775. strftime(buf,28,"%Y-%m-%dT%H:%M:%SZ", tm);
  18776. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].Timestamp,buf);
  18777. ShmOCPP16Data->StopTransaction[gun_index].TransactionId = ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId;
  18778. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].IdTag, (const char*)ShmOCPP16Data->StartTransaction[gun_index].IdTag);
  18779. random_uuid(guid);
  18780. /***********************************transactionData******************************************************/
  18781. memset(ShmOCPP16Data->StopTransaction[gun_index].TransactionData, 0, sizeof(struct StructMeterValue));
  18782. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].TimeStamp, buf);
  18783. //=================================
  18784. //1. Transaction_Begin
  18785. //=================================
  18786. //============================== Energy.Active.Import.Interval ===========================================
  18787. //=================================
  18788. //2. Transaction_End
  18789. //=================================
  18790. //2.1====================================== Current.Import L1 ==============================================
  18791. if(strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Current.Import") != NULL)
  18792. {
  18793. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G : GBT DC
  18794. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  18795. {
  18796. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  18797. {
  18798. tempIndex = ((gun_index==2) ? 1: 0);
  18799. }
  18800. else
  18801. {
  18802. tempIndex = gun_index;
  18803. }
  18804. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  18805. {
  18806. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  18807. {
  18808. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargingCurrent );// PresentChargingCurrent is 0~6553.5 amp
  18809. }
  18810. }// End of for CHAdeMO_QUANTITY
  18811. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase,PhaseStr[L3_N]);
  18812. }
  18813. else if(gunType[gun_index] == GUN_TYPE_CCS)
  18814. {
  18815. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  18816. {
  18817. tempIndex = ((gun_index==2) ? 1: 0);
  18818. }
  18819. else
  18820. {
  18821. tempIndex = gun_index;
  18822. }
  18823. for (int index = 0; index < CCS_QUANTITY; index++)
  18824. {
  18825. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  18826. {
  18827. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargingCurrent );// PresentChargingCurrent is 0~6553.5 amp
  18828. }
  18829. }// End of for CCS_QUANTITY
  18830. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase,PhaseStr[L3_N]);
  18831. }
  18832. else if(gunType[gun_index] == GUN_TYPE_GBT)
  18833. {
  18834. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  18835. {
  18836. tempIndex = ((gun_index==2) ? 1: 0);
  18837. }
  18838. else
  18839. {
  18840. tempIndex = gun_index;
  18841. }
  18842. for (int index = 0; index < GB_QUANTITY; index++)
  18843. {
  18844. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  18845. {
  18846. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingCurrent );// PresentChargingCurrent is 0~6553.5 amp
  18847. }
  18848. }// End of for GB_QUANTITY
  18849. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase,PhaseStr[L3_N]);
  18850. }
  18851. else if(gunType[gun_index] == GUN_TYPE_DO)
  18852. {
  18853. tempIndex = gun_index;
  18854. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  18855. {
  18856. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  18857. {
  18858. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PresentChargingCurrent );// PresentChargingCurrent is 0~6553.5 amp
  18859. }
  18860. }
  18861. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase,PhaseStr[L3_N]);
  18862. }
  18863. else
  18864. {
  18865. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  18866. {
  18867. tempIndex = 2;
  18868. }
  18869. else
  18870. {
  18871. tempIndex = gun_index;
  18872. }
  18873. for (int index = 0; index < AC_QUANTITY; index++)
  18874. {
  18875. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  18876. {
  18877. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingCurrent );// 0~6553.5 amp for EVSE
  18878. }
  18879. }// End of for AC_QUANTITY
  18880. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase,PhaseStr[L1_N]);
  18881. }
  18882. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  18883. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Format,ValueFormatStr[Raw]);
  18884. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Measurand,MeasurandStr[Current_Import]);
  18885. //strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase,PhaseStr[L1_N]);
  18886. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Location,LocationStr[Location_Outlet]);
  18887. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Unit,UnitOfMeasureStr[UnitOfMeasure_A]);
  18888. }
  18889. //2.2===================================== Energy.Active.Import.Interval ==========================================
  18890. if(strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Energy.Active.Import.Interval") != NULL)
  18891. {
  18892. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  18893. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  18894. {
  18895. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  18896. {
  18897. tempIndex = ((gun_index==2) ? 1: 0);
  18898. }
  18899. else
  18900. {
  18901. tempIndex = gun_index;
  18902. }
  18903. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  18904. {
  18905. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  18906. {
  18907. 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
  18908. }
  18909. }// END OF CHAdeMO_QUANTITY
  18910. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase,PhaseStr[L3_N]);
  18911. }
  18912. else if(gunType[gun_index] == GUN_TYPE_CCS)
  18913. {
  18914. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  18915. {
  18916. tempIndex = ((gun_index==2) ? 1: 0);
  18917. }
  18918. else
  18919. {
  18920. tempIndex = gun_index;
  18921. }
  18922. for (int index = 0; index < CCS_QUANTITY; index++)
  18923. {
  18924. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  18925. {
  18926. 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
  18927. }
  18928. }// END OF CCS_QUANTITY
  18929. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase,PhaseStr[L3_N]);
  18930. }
  18931. else if(gunType[gun_index] == GUN_TYPE_GBT)
  18932. {
  18933. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  18934. {
  18935. tempIndex = ((gun_index==2) ? 1: 0);
  18936. }
  18937. else
  18938. {
  18939. tempIndex = gun_index;
  18940. }
  18941. for (int index = 0; index < GB_QUANTITY; index++)
  18942. {
  18943. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  18944. {
  18945. 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
  18946. }
  18947. }// END OF GB_QUANTITY
  18948. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase,PhaseStr[L3_N]);
  18949. }
  18950. else if(gunType[gun_index] == GUN_TYPE_DO)
  18951. {
  18952. tempIndex = gun_index;
  18953. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  18954. {
  18955. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  18956. {
  18957. 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
  18958. }
  18959. }
  18960. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase,PhaseStr[L3_N]);
  18961. }
  18962. else
  18963. {
  18964. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  18965. {
  18966. tempIndex = 2;
  18967. }
  18968. else
  18969. {
  18970. tempIndex = gun_index;
  18971. }
  18972. for (int index = 0; index < AC_QUANTITY; index++)
  18973. {
  18974. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  18975. {
  18976. 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
  18977. }
  18978. }// END OF AC_QUANTITY
  18979. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase,PhaseStr[L1_N]);
  18980. }
  18981. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  18982. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Format,ValueFormatStr[Raw]);
  18983. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Measurand,MeasurandStr[Energy_Active_Import_Interval]);
  18984. //strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase,PhaseStr[L1_N]);
  18985. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Location,LocationStr[Location_Outlet]);
  18986. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Unit,UnitOfMeasureStr[UnitOfMeasure_kWh]);
  18987. }
  18988. //2.3====================================== Power.Active.Import =========================================
  18989. if(strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Power.Active.Import") != NULL)
  18990. {
  18991. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  18992. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  18993. {
  18994. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  18995. {
  18996. tempIndex = ((gun_index==2) ? 1: 0);
  18997. }
  18998. else
  18999. {
  19000. tempIndex = gun_index;
  19001. }
  19002. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  19003. {
  19004. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  19005. {
  19006. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargingPower );// PresentChargingPower is 0~6553.5 kW
  19007. }
  19008. } // End for CHAdeMO_QUANTITY
  19009. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase,PhaseStr[L3_N]);
  19010. }
  19011. else if(gunType[gun_index] == GUN_TYPE_CCS)
  19012. {
  19013. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  19014. {
  19015. tempIndex = ((gun_index==2) ? 1: 0);
  19016. }
  19017. else
  19018. {
  19019. tempIndex = gun_index;
  19020. }
  19021. for (int index = 0; index < CCS_QUANTITY; index++)
  19022. {
  19023. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  19024. {
  19025. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargingPower );// PresentChargingPower is 0~6553.5 kW
  19026. }
  19027. } // END for CCS_QUANTITY
  19028. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase,PhaseStr[L3_N]);
  19029. }
  19030. else if(gunType[gun_index] == GUN_TYPE_GBT)
  19031. {
  19032. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  19033. {
  19034. tempIndex = ((gun_index==2) ? 1: 0);
  19035. }
  19036. else
  19037. {
  19038. tempIndex = gun_index;
  19039. }
  19040. for (int index = 0; index < GB_QUANTITY; index++)
  19041. {
  19042. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  19043. {
  19044. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingPower );// PresentChargingPower is 0~6553.5 kW
  19045. }
  19046. }// END for GB_QUANTITY
  19047. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase,PhaseStr[L3_N]);
  19048. }
  19049. else if(gunType[gun_index] == GUN_TYPE_DO)
  19050. {
  19051. tempIndex = gun_index;
  19052. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  19053. {
  19054. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  19055. {
  19056. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PresentChargingPower );// PresentChargingPower is 0~6553.5 kW
  19057. }
  19058. }
  19059. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase,PhaseStr[L3_N]);
  19060. }
  19061. else
  19062. {
  19063. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  19064. {
  19065. tempIndex = 2;
  19066. }
  19067. else
  19068. {
  19069. tempIndex = gun_index;
  19070. }
  19071. for (int index = 0; index < AC_QUANTITY; index++)
  19072. {
  19073. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  19074. {
  19075. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingPower );// PresentChargingPower is 0~6553.5 kW
  19076. }
  19077. } // END for AC_QUANTITY
  19078. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase,PhaseStr[L1_N]);
  19079. }
  19080. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  19081. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Format,ValueFormatStr[Raw]);
  19082. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Measurand,MeasurandStr[Power_Active_Import]);
  19083. //strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase,PhaseStr[L1_N]);
  19084. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Location,LocationStr[Location_Outlet]);
  19085. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Unit,UnitOfMeasureStr[UnitOfMeasure_kW/*UnitOfMeasure_kWh*/]);
  19086. }
  19087. //2.4====================================== Voltage L1 ====================================================
  19088. if(strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Voltage") != NULL)
  19089. {
  19090. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  19091. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  19092. {
  19093. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  19094. {
  19095. tempIndex = ((gun_index==2) ? 1: 0);
  19096. }
  19097. else
  19098. {
  19099. tempIndex = gun_index;
  19100. }
  19101. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  19102. {
  19103. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  19104. {
  19105. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargingVoltage );// PresentChargingVoltage is 0~6553.5 volt
  19106. }
  19107. } // END OF FOR CHAdeMO_QUANTITY
  19108. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase,PhaseStr[L3_N]);
  19109. }
  19110. else if(gunType[gun_index] == GUN_TYPE_CCS)
  19111. {
  19112. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  19113. {
  19114. tempIndex = ((gun_index==2) ? 1: 0);
  19115. }
  19116. else
  19117. {
  19118. tempIndex = gun_index;
  19119. }
  19120. for (int index = 0; index < CCS_QUANTITY; index++)
  19121. {
  19122. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  19123. {
  19124. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargingVoltage );// PresentChargingVoltage is 0~6553.5 volt
  19125. }
  19126. } // END OF FOR CCS_QUANTITY
  19127. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase,PhaseStr[L3_N]);
  19128. }
  19129. else if(gunType[gun_index] == GUN_TYPE_GBT)
  19130. {
  19131. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  19132. {
  19133. tempIndex = ((gun_index==2) ? 1: 0);
  19134. }
  19135. else
  19136. {
  19137. tempIndex = gun_index;
  19138. }
  19139. for (int index = 0; index < GB_QUANTITY; index++)
  19140. {
  19141. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  19142. {
  19143. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingVoltage );// PresentChargingVoltage is 0~6553.5 volt
  19144. }
  19145. } // END OF FOR GB_QUANTITY
  19146. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase,PhaseStr[L3_N]);
  19147. }
  19148. else if(gunType[gun_index] == GUN_TYPE_DO)
  19149. {
  19150. tempIndex = gun_index;
  19151. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  19152. {
  19153. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  19154. {
  19155. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PresentChargingVoltage );// PresentChargingVoltage is 0~6553.5 volt
  19156. }
  19157. }
  19158. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase,PhaseStr[L3_N]);
  19159. }
  19160. else
  19161. {
  19162. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  19163. {
  19164. tempIndex = 2;
  19165. }
  19166. else
  19167. {
  19168. tempIndex = gun_index;
  19169. }
  19170. for (int index = 0; index < AC_QUANTITY; index++)
  19171. {
  19172. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  19173. {
  19174. 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
  19175. }
  19176. } // END OF FOR AC_QUANTITY
  19177. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase,PhaseStr[L1_N]);
  19178. }
  19179. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  19180. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Format,ValueFormatStr[Raw]);
  19181. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Measurand,MeasurandStr[Voltage]);
  19182. //strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase,PhaseStr[L1_N]);
  19183. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Location,LocationStr[Location_Outlet]);
  19184. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Unit,UnitOfMeasureStr[UnitOfMeasure_V]);
  19185. }
  19186. //2.5============================================== End SoC =========================================================
  19187. if(strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, MeasurandStr[SoC]) != NULL)
  19188. {
  19189. //J : CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  19190. 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))
  19191. {
  19192. if((ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0') && (gunType[gun_index] != GUN_TYPE_DO))
  19193. {
  19194. tempIndex = ((gun_index==2) ? 1: 0);
  19195. }
  19196. else
  19197. {
  19198. tempIndex = gun_index;
  19199. }
  19200. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  19201. {
  19202. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  19203. {
  19204. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  19205. {
  19206. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].EvBatterySoc );// 0~100%
  19207. }
  19208. }
  19209. }
  19210. else if(gunType[gun_index] == GUN_TYPE_CCS)
  19211. {
  19212. for (int index = 0; index < CCS_QUANTITY; index++)
  19213. {
  19214. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  19215. {
  19216. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].EvBatterySoc );// 0~100%
  19217. }
  19218. }
  19219. }
  19220. else if(gunType[gun_index] == GUN_TYPE_GBT)
  19221. {
  19222. for (int index = 0; index < GB_QUANTITY; index++)
  19223. {
  19224. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  19225. {
  19226. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].EvBatterySoc );// 0~100%
  19227. }
  19228. }
  19229. }
  19230. else if(gunType[gun_index] == GUN_TYPE_DO)
  19231. {
  19232. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  19233. {
  19234. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  19235. {
  19236. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.EvBatterySoc );// 0~100%
  19237. }
  19238. }
  19239. }
  19240. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  19241. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Format,ValueFormatStr[Raw]);
  19242. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Measurand,MeasurandStr[SoC/*Energy_Reactive_Export_Register*/]);
  19243. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Phase,PhaseStr[L3_N]);
  19244. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Location,LocationStr[Location_EV]);
  19245. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Unit,UnitOfMeasureStr[UnitOfMeasure_Percent/*UnitOfMeasure_kWh*/]);
  19246. } // END FOR DC CASE
  19247. }
  19248. //2.6====================================== Current.Import L2 ==============================================
  19249. if(strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Current.Import") != NULL)
  19250. {
  19251. // AC 3 phase L2 current
  19252. if((gunType[gun_index] == GUN_TYPE_AC) && ((ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'W') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='D')))
  19253. {
  19254. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  19255. {
  19256. tempIndex = 2;
  19257. }
  19258. else
  19259. {
  19260. tempIndex = gun_index;
  19261. }
  19262. for (int index = 0; index < AC_QUANTITY; index++)
  19263. {
  19264. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  19265. {
  19266. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingCurrentL2);// 0~6553.5 amp for EVSE
  19267. }
  19268. }// End of for AC_QUANTITY
  19269. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Phase,PhaseStr[L2_N]);
  19270. }
  19271. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  19272. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Format,ValueFormatStr[Raw]);
  19273. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Measurand,MeasurandStr[Current_Import]);
  19274. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Location,LocationStr[Location_Outlet]);
  19275. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Unit,UnitOfMeasureStr[UnitOfMeasure_A]);
  19276. }
  19277. //2.7====================================== Current.Import L3 ==============================================
  19278. if(strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Current.Import") != NULL)
  19279. {
  19280. // AC 3 phase L3 current
  19281. if((gunType[gun_index] == GUN_TYPE_AC) && ((ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'W') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='D')))
  19282. {
  19283. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  19284. {
  19285. tempIndex = 2;
  19286. }
  19287. else
  19288. {
  19289. tempIndex = gun_index;
  19290. }
  19291. for (int index = 0; index < AC_QUANTITY; index++)
  19292. {
  19293. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  19294. {
  19295. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingCurrentL3);// 0~6553.5 amp for EVSE
  19296. }
  19297. }// End of for AC_QUANTITY
  19298. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Phase,PhaseStr[L3_N]);
  19299. }
  19300. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  19301. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Format,ValueFormatStr[Raw]);
  19302. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Measurand,MeasurandStr[Current_Import]);
  19303. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Location,LocationStr[Location_Outlet]);
  19304. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Unit,UnitOfMeasureStr[UnitOfMeasure_A]);
  19305. }
  19306. //2.9====================================== Voltage L2 ====================================================
  19307. if(strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Voltage") != NULL)
  19308. {
  19309. // AC 3 phase L2 volatge
  19310. if((gunType[gun_index] == GUN_TYPE_AC) && ((ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'W') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='D')))
  19311. {
  19312. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  19313. {
  19314. tempIndex = 2;
  19315. }
  19316. else
  19317. {
  19318. tempIndex = gun_index;
  19319. }
  19320. for (int index = 0; index < AC_QUANTITY; index++)
  19321. {
  19322. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  19323. {
  19324. 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
  19325. }
  19326. } // END OF FOR AC_QUANTITY
  19327. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Phase,PhaseStr[L2_N]);
  19328. }
  19329. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  19330. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Format,ValueFormatStr[Raw]);
  19331. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Measurand,MeasurandStr[Voltage]);
  19332. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Location,LocationStr[Location_Outlet]);
  19333. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Unit,UnitOfMeasureStr[UnitOfMeasure_V]);
  19334. }
  19335. //2.10====================================== Voltage L3 ====================================================
  19336. if(strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Voltage") != NULL)
  19337. {
  19338. // AC 3 phase L3 volatge
  19339. if((gunType[gun_index] == GUN_TYPE_AC) && ((ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'W') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='D')))
  19340. {
  19341. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  19342. {
  19343. tempIndex = 2;
  19344. }
  19345. else
  19346. {
  19347. tempIndex = gun_index;
  19348. }
  19349. for (int index = 0; index < AC_QUANTITY; index++)
  19350. {
  19351. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  19352. {
  19353. 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
  19354. }
  19355. } // END OF FOR AC_QUANTITY
  19356. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Phase,PhaseStr[L3_N]);
  19357. }
  19358. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  19359. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Format,ValueFormatStr[Raw]);
  19360. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Measurand,MeasurandStr[Voltage]);
  19361. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Location,LocationStr[Location_Outlet]);
  19362. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Unit,UnitOfMeasureStr[UnitOfMeasure_V]);
  19363. }
  19364. //====================== Start SoC ================================
  19365. if(strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, MeasurandStr[SoC]) != NULL)
  19366. {
  19367. //J : CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  19368. 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))
  19369. {
  19370. if((ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0') && (gunType[gun_index] != GUN_TYPE_DO))
  19371. {
  19372. tempIndex = ((gun_index==2) ? 1: 0);
  19373. }
  19374. else
  19375. {
  19376. tempIndex = gun_index;
  19377. }
  19378. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  19379. {
  19380. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  19381. {
  19382. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  19383. {
  19384. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].EvBatteryStartSoc );// 0~100%
  19385. }
  19386. }
  19387. }
  19388. else if(gunType[gun_index] == GUN_TYPE_CCS)
  19389. {
  19390. for (int index = 0; index < CCS_QUANTITY; index++)
  19391. {
  19392. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  19393. {
  19394. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].EvBatteryStartSoc );// 0~100%
  19395. }
  19396. }
  19397. }
  19398. else if(gunType[gun_index] == GUN_TYPE_GBT)
  19399. {
  19400. for (int index = 0; index < GB_QUANTITY; index++)
  19401. {
  19402. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  19403. {
  19404. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].EvBatteryStartSoc );// 0~100%
  19405. }
  19406. }
  19407. }
  19408. else if(gunType[gun_index] == GUN_TYPE_DO)
  19409. {
  19410. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  19411. {
  19412. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  19413. {
  19414. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.EvBatteryStartSoc );// 0~100%
  19415. }
  19416. }
  19417. }
  19418. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Context,ReadingContextStr[ReadingContext_Transaction_Begin]);
  19419. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Format,ValueFormatStr[Raw]);
  19420. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Measurand,MeasurandStr[SoC/*Energy_Reactive_Export_Register*/]);
  19421. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Phase,PhaseStr[L3_N]);
  19422. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Location,LocationStr[Location_EV]);
  19423. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Unit,UnitOfMeasureStr[UnitOfMeasure_Percent/*UnitOfMeasure_kWh*/]);
  19424. } // END FOR DC CASE
  19425. }
  19426. //======================================== Message create ==============================================
  19427. json_object *StopTransaction = json_object_new_object();
  19428. json_object *transactionDatas = json_object_new_array();
  19429. json_object *sampledValues = json_object_new_array();
  19430. if(strlen((char*)ShmOCPP16Data->StopTransaction[gun_index].IdTag) > 0)
  19431. json_object_object_add(StopTransaction, "idTag", json_object_new_string((char*)ShmOCPP16Data->StopTransaction[gun_index].IdTag));
  19432. json_object_object_add(StopTransaction, "meterStop", json_object_new_int(ShmOCPP16Data->StopTransaction[gun_index].MeterStop));
  19433. json_object_object_add(StopTransaction, "transactionId", json_object_new_int(ShmOCPP16Data->StopTransaction[gun_index].TransactionId));
  19434. json_object_object_add(StopTransaction, "timestamp", json_object_new_string((char*)ShmOCPP16Data->StopTransaction[gun_index].Timestamp));
  19435. json_object_object_add(StopTransaction, "reason", json_object_new_string("PowerLoss"));
  19436. for(int idxTrans = 0;idxTrans<ARRAY_SIZE(ShmOCPP16Data->StopTransaction[gun_index].TransactionData);idxTrans++)
  19437. {
  19438. json_object *transactionData = json_object_new_object();
  19439. json_object_object_add(transactionData, "timestamp", json_object_new_string((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].TimeStamp));
  19440. for(int idx=0;idx<ARRAY_SIZE(ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue);idx++)
  19441. {
  19442. if(strlen((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Value) > 0)
  19443. {
  19444. json_object *sampledValue = json_object_new_object();
  19445. json_object_object_add(sampledValue, "value", json_object_new_string((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Value));
  19446. if(strlen((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Context) > 0)
  19447. json_object_object_add(sampledValue, "context", json_object_new_string((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Context));
  19448. if(strlen((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Format) > 0)
  19449. json_object_object_add(sampledValue, "format", json_object_new_string((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Format));
  19450. if(strlen((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Measurand) > 0)
  19451. json_object_object_add(sampledValue, "measurand", json_object_new_string((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Measurand));
  19452. if(strlen((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Phase) > 0)
  19453. json_object_object_add(sampledValue, "phase", json_object_new_string((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Phase));
  19454. if(strlen((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Location) > 0)
  19455. json_object_object_add(sampledValue, "location", json_object_new_string((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Location));
  19456. if(strlen((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Unit) > 0)
  19457. json_object_object_add(sampledValue, "unit", json_object_new_string((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Unit));
  19458. json_object_array_add(sampledValues, sampledValue);
  19459. }
  19460. }
  19461. json_object_object_add(transactionData, "sampledValue", sampledValues);
  19462. json_object_array_add(transactionDatas, transactionData);
  19463. }
  19464. json_object_object_add(StopTransaction, "transactionData", transactionDatas);
  19465. sprintf(queuedata, "%d,[%d,\"%s\",\"StopTransaction\",%s]",(gun_index+1)
  19466. ,MESSAGE_TYPE_CALL
  19467. ,guid
  19468. ,json_object_to_json_string_ext(StopTransaction, JSON_C_TO_STRING_PLAIN));
  19469. json_object_put(StopTransaction);
  19470. // Check File "TempStopTransaction" Exist
  19471. if((access(TempStopTransaction,F_OK))!=-1)
  19472. {
  19473. //DEBUG_INFO("TransactionRelatedQueue exist.\n");
  19474. fclose(fopen(TempStopTransaction, "w"));
  19475. }
  19476. else
  19477. {
  19478. //DEBUG_INFO("TransactionRelatedQueue not exist\n");
  19479. FILE *log = fopen(TempStopTransaction, "w+");
  19480. if(log == NULL)
  19481. {
  19482. //DEBUG_INFO("Can't Create File TransactionRelatedQueue \n");
  19483. return ;
  19484. }
  19485. else
  19486. {
  19487. fclose(log);
  19488. }
  19489. }
  19490. //Add TempStopTransaction | Update TempStopTransaction
  19491. // open file for writing
  19492. FILE *outfile;
  19493. outfile = fopen (TempStopTransaction, "a");
  19494. //DEBUG_INFO("data = %s\n", queuedata);
  19495. fputs(queuedata, outfile);
  19496. fputs("\n", outfile);
  19497. fclose (outfile);
  19498. system("/bin/fsync -d /dev/mtdblock13;/bin/sync &");
  19499. OCPP_updatePeriodEnergy(gun_index);
  19500. }
  19501. void checkTempStopTransaction(int gun_index)
  19502. {
  19503. FILE *fptr1;
  19504. char ch;
  19505. char str[QUEUE_MESSAGE_LENGTH]={0};
  19506. char guid[37]={0};
  19507. char tempdata[65]={0};
  19508. char connectorStr[2]={0};
  19509. char TempStopTransaction[256];
  19510. sprintf(TempStopTransaction, "/Storage/OCPP/TempStopTransaction_%d", (gun_index+1));
  19511. fptr1 = fopen(TempStopTransaction, "r");
  19512. //TempStopTransaction格式: 槍號,StopTransaction封包
  19513. if (!fptr1)
  19514. {
  19515. //printf(" File not found or unable to open the input file!!\n");
  19516. return ;
  19517. }
  19518. ch=fgetc(fptr1);
  19519. //printf(" Now the content of the file %s is : \n",fname);
  19520. rewind(fptr1);
  19521. if(ch!=EOF)
  19522. {
  19523. // copy all contents to the temporary file except the specific line
  19524. while (fgets(str, QUEUE_MESSAGE_LENGTH, fptr1) != NULL)
  19525. {
  19526. str[strlen(str) - 1] = '\0'; // eat the newline fgets() stores
  19527. if(str[0]=='\0')
  19528. {
  19529. break;
  19530. }
  19531. //TempStopTransaction格式: 槍號,StopTransaction封包
  19532. strncpy(connectorStr, str, 1);
  19533. if(atoi(connectorStr) != (gun_index+1))
  19534. {
  19535. DEBUG_INFO("atoi(connectorStr) = %d, gun_index = %d\n", atoi(connectorStr), gun_index);
  19536. fclose(fptr1);
  19537. return ;
  19538. }
  19539. //random_uuid(guid);
  19540. strncpy(guid, str+6, 36); //copy guid
  19541. sprintf(tempdata, "StopTransaction,%d", (gun_index));
  19542. if(hashmap_operation(HASH_OP_ADD, guid, tempdata) == 1)
  19543. {
  19544. //DEBUG_INFO("StopTransaction mapitem pass\n");
  19545. }
  19546. queue_operation(QUEUE_OPERATION_ADD, guid, str);//addq(guid, queuedata); ---> remove temporally
  19547. OCPP_insert_transaction_msg(NO, str);
  19548. memset(str,0,ARRAY_SIZE(str));
  19549. }
  19550. }
  19551. // fptr1=freopen(NULL,"w",fptr1); // reset the fptr1 again
  19552. fclose(fptr1);
  19553. remove(TempStopTransaction); // remove the original file
  19554. system("/bin/fsync -d /dev/mtdblock13;/bin/sync &");
  19555. }
  19556. void FillStartTransaction(int ConnectorId, unsigned char IdTag[], int MeterStart,int ReservationId,unsigned char Timestamp[])
  19557. {
  19558. ShmOCPP16Data->StartTransaction[ConnectorId-1].ConnectorId = ConnectorId;
  19559. ShmOCPP16Data->StartTransaction[ConnectorId-1].ReservationId = ReservationId;
  19560. ShmOCPP16Data->StartTransaction[ConnectorId-1].MeterStart = MeterStart;
  19561. strcpy((char *)ShmOCPP16Data->StartTransaction[ConnectorId-1].IdTag, (char *)IdTag);
  19562. strcpy((char *)ShmOCPP16Data->StartTransaction[ConnectorId-1].Timestamp,(char *) Timestamp);
  19563. }
  19564. int GetWebSocketPingInterval(void)
  19565. {
  19566. return atoi((const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemData);
  19567. }
  19568. int GetServerSign(void)
  19569. {
  19570. return server_sign;
  19571. }
  19572. uint8_t GetOcppSecurityProfile()
  19573. {
  19574. return atoi((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[SecurityProfile].ItemData);
  19575. }
  19576. void GetOcppChargerBoxId(uint8_t *data)
  19577. {
  19578. sprintf((char*)data, "%s", ShmSysConfigAndInfo->SysConfig.ChargeBoxId);
  19579. }
  19580. void GetOcppSecurityPassword(uint8_t *data)
  19581. {
  19582. sprintf((char*)data, "%s", ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationKey].ItemData);
  19583. }
  19584. void SetOcppVersion(uint8_t *version)
  19585. {
  19586. for (uint8_t idx=0; idx<strlen((char*)version); idx++) version[idx] = tolower(version[idx]);
  19587. DEBUG_INFO("ocpp version: %s\n", version);
  19588. if(strstr((char*)version, "ocpp1.6") != NULL)
  19589. {
  19590. ShmSysConfigAndInfo->SysInfo.OcppRunningVer = OCPP_RUNNING_VERSION_16;
  19591. }
  19592. else if(strstr((char*)version, "ocpp2.0") != NULL)
  19593. {
  19594. ShmSysConfigAndInfo->SysInfo.OcppRunningVer = OCPP_RUNNING_VERSION_20;
  19595. system("pkill OcppBackend");
  19596. }
  19597. }
  19598. void SetServerSign(int value)
  19599. {
  19600. server_sign = value;
  19601. }
  19602. int GetBootNotificationInterval(void)
  19603. {
  19604. return BootNotificationInterval;
  19605. }
  19606. int GetInternetConn(void)
  19607. {
  19608. return ShmSysConfigAndInfo->SysInfo.InternetConn;
  19609. }
  19610. int GetBackendConnectionTimeout(void)
  19611. {
  19612. return ShmSysConfigAndInfo->SysConfig.BackendConnTimeout>=0?ShmSysConfigAndInfo->SysConfig.BackendConnTimeout:300;
  19613. }
  19614. int isConnectorInitMode(int gun_index)
  19615. {
  19616. int tempIndex = 0;
  19617. int result = TRUE;
  19618. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DCcc
  19619. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  19620. {
  19621. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  19622. {
  19623. tempIndex = ((gun_index==2) ? 1: 0);
  19624. }
  19625. else
  19626. {
  19627. tempIndex = gun_index;
  19628. }
  19629. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  19630. {
  19631. if ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex))
  19632. {
  19633. result = (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus==SYS_MODE_BOOTING)?TRUE:FALSE;
  19634. } //end of the same index
  19635. }//end of for CHAdeMO_QUANTITY
  19636. }
  19637. else if(gunType[gun_index] == GUN_TYPE_CCS)
  19638. {
  19639. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  19640. {
  19641. tempIndex = ((gun_index==2) ? 1: 0);
  19642. }
  19643. else
  19644. {
  19645. tempIndex = gun_index;
  19646. }
  19647. for (int index = 0; index < CCS_QUANTITY; index++)
  19648. {
  19649. if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  19650. {
  19651. result = (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus==SYS_MODE_BOOTING)?TRUE:FALSE;
  19652. } //end of the same index
  19653. } // end of for CCS_QUANTITY
  19654. }
  19655. else if(gunType[gun_index] == GUN_TYPE_GBT)
  19656. {
  19657. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  19658. {
  19659. tempIndex = ((gun_index==2) ? 1: 0);
  19660. }
  19661. else
  19662. {
  19663. tempIndex = gun_index;
  19664. }
  19665. for (int index = 0; index < GB_QUANTITY; index++)
  19666. {
  19667. if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  19668. {
  19669. result = (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus==SYS_MODE_BOOTING)?TRUE:FALSE;
  19670. } //end of the same index
  19671. } // end of for GB_QUANTITY
  19672. }
  19673. else if(gunType[gun_index] == GUN_TYPE_DO)
  19674. {
  19675. tempIndex = gun_index;
  19676. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  19677. {
  19678. if(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  19679. {
  19680. result = (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus==SYS_MODE_BOOTING)?TRUE:FALSE;
  19681. } //end of the same index
  19682. }
  19683. }
  19684. else
  19685. {
  19686. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  19687. {
  19688. tempIndex = 2;
  19689. }
  19690. else
  19691. {
  19692. tempIndex = gun_index;
  19693. }
  19694. for (int index = 0; index < AC_QUANTITY; index++)
  19695. {
  19696. if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  19697. {
  19698. result = (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus==SYS_MODE_BOOTING)?TRUE:FALSE;
  19699. }//end of the same index
  19700. }//end of for AC_QUANTITY
  19701. }
  19702. return result;
  19703. }
  19704. void refreshProcDogTimer()
  19705. {
  19706. ShmOCPP16Data->procDogTime = time((time_t*)NULL);
  19707. }
  19708. void InitialSystemValue(void)
  19709. {
  19710. server_cycle_Status = atoi((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemData);
  19711. locallistVersion=0;
  19712. BootNotificationInterval = 0;
  19713. authorizeRetryTimes = 0;
  19714. GunStatusInterval = 10;
  19715. TransactionMessageAttemptsValue = atoi((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData);
  19716. TransactionMessageRetryIntervalValue = atoi((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData);
  19717. //Hear Beat
  19718. HeartBeatWithNOResponse = 0;
  19719. HeartBeatWaitTime = atoi((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemData);;
  19720. FirstHeartBeat = 0;
  19721. FirmwareStatusNotificationStatus = FIRMWARE_STATUS_IDLE; // Idle
  19722. DiagnosticsStatusNotificationStatus = DIAGNOSTIC_STATUS_IDLE; // Idle
  19723. memset(CurrentChargingProfileScheduleStr, 0, ARRAY_SIZE(CurrentChargingProfileScheduleStr));
  19724. memset(ChademoPreviousSystemStatus, 0, ARRAY_SIZE(ChademoPreviousSystemStatus));
  19725. memset(CcsPreviousSystemStatus, 0, ARRAY_SIZE(CcsPreviousSystemStatus));
  19726. memset(GbPreviousSystemStatus, 0, ARRAY_SIZE(GbPreviousSystemStatus));
  19727. memset(AcPreviousSystemStatus, 0, ARRAY_SIZE(AcPreviousSystemStatus));
  19728. memset(ChademoPreviousConnectorPlugIn, 0, ARRAY_SIZE(ChademoPreviousConnectorPlugIn));
  19729. memset(CcsPreviousConnectorPlugIn, 0, ARRAY_SIZE(CcsPreviousConnectorPlugIn));
  19730. memset(GbPreviousConnectorPlugIn, 0, ARRAY_SIZE(GbPreviousConnectorPlugIn));
  19731. memset(AcPreviousConnectorPlugIn, 0, ARRAY_SIZE(AcPreviousConnectorPlugIn));
  19732. //Status && ConnectorPlugIn Setting
  19733. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  19734. {
  19735. ChademoPreviousSystemStatus[index] = 99; //ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PreviousSystemStatus;
  19736. ChademoPreviousConnectorPlugIn[index] = ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ConnectorPlugIn;
  19737. }
  19738. for (int index = 0; index < CCS_QUANTITY; index++)
  19739. {
  19740. CcsPreviousSystemStatus[index] = 99; //ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PreviousSystemStatus;
  19741. CcsPreviousConnectorPlugIn[index] = ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ConnectorPlugIn;
  19742. }
  19743. for (int index = 0; index < GB_QUANTITY; index++)
  19744. {
  19745. GbPreviousSystemStatus[index] = 99; //ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PreviousSystemStatus;
  19746. GbPreviousConnectorPlugIn[index] = ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ConnectorPlugIn;
  19747. }
  19748. for (int index = 0; index < AC_QUANTITY; index++)
  19749. {
  19750. AcPreviousSystemStatus[index] = 99; //ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PreviousSystemStatus;
  19751. AcPreviousConnectorPlugIn[index] = ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PilotState;
  19752. }
  19753. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  19754. {
  19755. DoPreviousSystemStatus[index] = 99; //ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PreviousSystemStatus;
  19756. DoPreviousConnectorPlugIn[index] = ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PilotState;
  19757. }
  19758. for(int gun_index=0; gun_index < gunTotalNumber; gun_index++ )
  19759. {
  19760. cpinitateMsg.bits[gun_index].TriggerStatusNotificationReq = 0;
  19761. cpinitateMsg.bits[gun_index].StatusNotificationReq = 0;
  19762. cpinitateMsg.bits[gun_index].StatusNotificationConf = 0;
  19763. //clientTime.MeterValues[gun_index] = time((time_t*)NULL);
  19764. //memset(&ShmOCPP16Data->StatusNotification[gun_index], 0x00, sizeof(struct StructStatusNotification));
  19765. memset(&ShmOCPP16Data->StatusNotification[gun_index].Status, 0x00, sizeof(ShmOCPP16Data->StatusNotification[gun_index].Status));
  19766. }
  19767. memset( (void *)unknownkey, 0, sizeof(unknownkey));
  19768. refreshStartTimer(&clientTime.Heartbeat);
  19769. sleep(1);
  19770. }
  19771. void LWS_Send(char *str)
  19772. {
  19773. //=====================================================
  19774. // Check InternetConn 0: disconnected, 1: connected
  19775. //====================================================
  19776. if(GetOcppConnStatus() == 0)
  19777. {
  19778. DEBUG_INFO("offline now !!!\n");
  19779. return;
  19780. }
  19781. // Only disable isWebsocketSendable operation initiated by charger
  19782. if((strstr((char*)str, "\"Authorize\"") != NULL)
  19783. || (strstr((char*)str, "\"BootNotification\"") != NULL)
  19784. || (strstr((char*)str, "\"DataTransfer\"") != NULL)
  19785. || (strstr((char*)str, "\"DiagnosticsStatusNotification\"") != NULL)
  19786. || (strstr((char*)str, "\"FirmwareStatusNotification\"") != NULL)
  19787. || (strstr((char*)str, "\"Heartbeat\"") != NULL)
  19788. || (strstr((char*)str, "\"MeterValues\"") != NULL)
  19789. || (strstr((char*)str, "\"StartTransaction\"") != NULL)
  19790. || (strstr((char*)str, "\"StatusNotification\"") != NULL)
  19791. || (strstr((char*)str, "\"StopTransaction\"") != NULL)
  19792. || (strstr((char*)str, "\"LogStatusNotification\"") != NULL)
  19793. || (strstr((char*)str, "\"SecurityEventNotification\"") != NULL)
  19794. || (strstr((char*)str, "\"SignCertificate\"") != NULL)
  19795. || (strstr((char*)str, "\"SignedFirmwareStatusNotification\"") != NULL))
  19796. {
  19797. isWebsocketSendable = 0;
  19798. }
  19799. pthread_mutex_lock(&lock_send);
  19800. memset(SendBuffer, 0, ARRAY_SIZE(SendBuffer));
  19801. sprintf((char *)SendBuffer, "%s", str);
  19802. SendBufLen = strlen(str);
  19803. pthread_mutex_unlock(&lock_send);
  19804. lws_callback_on_writable(wsi_client);
  19805. //lws_service(context, 0);
  19806. //sleep(1);
  19807. }
  19808. void LWS_SendNow(char *str)
  19809. {
  19810. //=====================================================
  19811. // Check InternetConn 0: disconnected, 1: connected
  19812. //====================================================
  19813. if(GetOcppConnStatus() == 0)
  19814. {
  19815. DEBUG_INFO("offline now !!!\n");
  19816. return;
  19817. }
  19818. // Only disable isWebsocketSendable operation initiated by charger
  19819. if((strstr((char*)str, "\"Authorize\"") != NULL)
  19820. || (strstr((char*)str, "\"BootNotification\"") != NULL)
  19821. || (strstr((char*)str, "\"DataTransfer\"") != NULL)
  19822. || (strstr((char*)str, "\"DiagnosticsStatusNotification\"") != NULL)
  19823. || (strstr((char*)str, "\"FirmwareStatusNotification\"") != NULL)
  19824. || (strstr((char*)str, "\"Heartbeat\"") != NULL)
  19825. || (strstr((char*)str, "\"MeterValues\"") != NULL)
  19826. || (strstr((char*)str, "\"StartTransaction\"") != NULL)
  19827. || (strstr((char*)str, "\"StatusNotification\"") != NULL)
  19828. || (strstr((char*)str, "\"StopTransaction\"") != NULL)
  19829. || (strstr((char*)str, "\"LogStatusNotification\"") != NULL)
  19830. || (strstr((char*)str, "\"SecurityEventNotification\"") != NULL)
  19831. || (strstr((char*)str, "\"SignCertificate\"") != NULL)
  19832. || (strstr((char*)str, "\"SignedFirmwareStatusNotification\"") != NULL))
  19833. {
  19834. isWebsocketSendable = 0;
  19835. }
  19836. pthread_mutex_lock(&lock_send);
  19837. memset(SendBuffer, 0, ARRAY_SIZE(SendBuffer));
  19838. sprintf((char *)SendBuffer, "%s", str);
  19839. SendBufLen = strlen(str);
  19840. pthread_mutex_unlock(&lock_send);
  19841. lws_callback_on_writable(wsi_client);
  19842. lws_service(context, 0);
  19843. //sleep(1);
  19844. }