MessageHandler.c 935 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086308730883089309030913092309330943095309630973098309931003101310231033104310531063107310831093110311131123113311431153116311731183119312031213122312331243125312631273128312931303131313231333134313531363137313831393140314131423143314431453146314731483149315031513152315331543155315631573158315931603161316231633164316531663167316831693170317131723173317431753176317731783179318031813182318331843185318631873188318931903191319231933194319531963197319831993200320132023203320432053206320732083209321032113212321332143215321632173218321932203221322232233224322532263227322832293230323132323233323432353236323732383239324032413242324332443245324632473248324932503251325232533254325532563257325832593260326132623263326432653266326732683269327032713272327332743275327632773278327932803281328232833284328532863287328832893290329132923293329432953296329732983299330033013302330333043305330633073308330933103311331233133314331533163317331833193320332133223323332433253326332733283329333033313332333333343335333633373338333933403341334233433344334533463347334833493350335133523353335433553356335733583359336033613362336333643365336633673368336933703371337233733374337533763377337833793380338133823383338433853386338733883389339033913392339333943395339633973398339934003401340234033404340534063407340834093410341134123413341434153416341734183419342034213422342334243425342634273428342934303431343234333434343534363437343834393440344134423443344434453446344734483449345034513452345334543455345634573458345934603461346234633464346534663467346834693470347134723473347434753476347734783479348034813482348334843485348634873488348934903491349234933494349534963497349834993500350135023503350435053506350735083509351035113512351335143515351635173518351935203521352235233524352535263527352835293530353135323533353435353536353735383539354035413542354335443545354635473548354935503551355235533554355535563557355835593560356135623563356435653566356735683569357035713572357335743575357635773578357935803581358235833584358535863587358835893590359135923593359435953596359735983599360036013602360336043605360636073608360936103611361236133614361536163617361836193620362136223623362436253626362736283629363036313632363336343635363636373638363936403641364236433644364536463647364836493650365136523653365436553656365736583659366036613662366336643665366636673668366936703671367236733674367536763677367836793680368136823683368436853686368736883689369036913692369336943695369636973698369937003701370237033704370537063707370837093710371137123713371437153716371737183719372037213722372337243725372637273728372937303731373237333734373537363737373837393740374137423743374437453746374737483749375037513752375337543755375637573758375937603761376237633764376537663767376837693770377137723773377437753776377737783779378037813782378337843785378637873788378937903791379237933794379537963797379837993800380138023803380438053806380738083809381038113812381338143815381638173818381938203821382238233824382538263827382838293830383138323833383438353836383738383839384038413842384338443845384638473848384938503851385238533854385538563857385838593860386138623863386438653866386738683869387038713872387338743875387638773878387938803881388238833884388538863887388838893890389138923893389438953896389738983899390039013902390339043905390639073908390939103911391239133914391539163917391839193920392139223923392439253926392739283929393039313932393339343935393639373938393939403941394239433944394539463947394839493950395139523953395439553956395739583959396039613962396339643965396639673968396939703971397239733974397539763977397839793980398139823983398439853986398739883989399039913992399339943995399639973998399940004001400240034004400540064007400840094010401140124013401440154016401740184019402040214022402340244025402640274028402940304031403240334034403540364037403840394040404140424043404440454046404740484049405040514052405340544055405640574058405940604061406240634064406540664067406840694070407140724073407440754076407740784079408040814082408340844085408640874088408940904091409240934094409540964097409840994100410141024103410441054106410741084109411041114112411341144115411641174118411941204121412241234124412541264127412841294130413141324133413441354136413741384139414041414142414341444145414641474148414941504151415241534154415541564157415841594160416141624163416441654166416741684169417041714172417341744175417641774178417941804181418241834184418541864187418841894190419141924193419441954196419741984199420042014202420342044205420642074208420942104211421242134214421542164217421842194220422142224223422442254226422742284229423042314232423342344235423642374238423942404241424242434244424542464247424842494250425142524253425442554256425742584259426042614262426342644265426642674268426942704271427242734274427542764277427842794280428142824283428442854286428742884289429042914292429342944295429642974298429943004301430243034304430543064307430843094310431143124313431443154316431743184319432043214322432343244325432643274328432943304331433243334334433543364337433843394340434143424343434443454346434743484349435043514352435343544355435643574358435943604361436243634364436543664367436843694370437143724373437443754376437743784379438043814382438343844385438643874388438943904391439243934394439543964397439843994400440144024403440444054406440744084409441044114412441344144415441644174418441944204421442244234424442544264427442844294430443144324433443444354436443744384439444044414442444344444445444644474448444944504451445244534454445544564457445844594460446144624463446444654466446744684469447044714472447344744475447644774478447944804481448244834484448544864487448844894490449144924493449444954496449744984499450045014502450345044505450645074508450945104511451245134514451545164517451845194520452145224523452445254526452745284529453045314532453345344535453645374538453945404541454245434544454545464547454845494550455145524553455445554556455745584559456045614562456345644565456645674568456945704571457245734574457545764577457845794580458145824583458445854586458745884589459045914592459345944595459645974598459946004601460246034604460546064607460846094610461146124613461446154616461746184619462046214622462346244625462646274628462946304631463246334634463546364637463846394640464146424643464446454646464746484649465046514652465346544655465646574658465946604661466246634664466546664667466846694670467146724673467446754676467746784679468046814682468346844685468646874688468946904691469246934694469546964697469846994700470147024703470447054706470747084709471047114712471347144715471647174718471947204721472247234724472547264727472847294730473147324733473447354736473747384739474047414742474347444745474647474748474947504751475247534754475547564757475847594760476147624763476447654766476747684769477047714772477347744775477647774778477947804781478247834784478547864787478847894790479147924793479447954796479747984799480048014802480348044805480648074808480948104811481248134814481548164817481848194820482148224823482448254826482748284829483048314832483348344835483648374838483948404841484248434844484548464847484848494850485148524853485448554856485748584859486048614862486348644865486648674868486948704871487248734874487548764877487848794880488148824883488448854886488748884889489048914892489348944895489648974898489949004901490249034904490549064907490849094910491149124913491449154916491749184919492049214922492349244925492649274928492949304931493249334934493549364937493849394940494149424943494449454946494749484949495049514952495349544955495649574958495949604961496249634964496549664967496849694970497149724973497449754976497749784979498049814982498349844985498649874988498949904991499249934994499549964997499849995000500150025003500450055006500750085009501050115012501350145015501650175018501950205021502250235024502550265027502850295030503150325033503450355036503750385039504050415042504350445045504650475048504950505051505250535054505550565057505850595060506150625063506450655066506750685069507050715072507350745075507650775078507950805081508250835084508550865087508850895090509150925093509450955096509750985099510051015102510351045105510651075108510951105111511251135114511551165117511851195120512151225123512451255126512751285129513051315132513351345135513651375138513951405141514251435144514551465147514851495150515151525153515451555156515751585159516051615162516351645165516651675168516951705171517251735174517551765177517851795180518151825183518451855186518751885189519051915192519351945195519651975198519952005201520252035204520552065207520852095210521152125213521452155216521752185219522052215222522352245225522652275228522952305231523252335234523552365237523852395240524152425243524452455246524752485249525052515252525352545255525652575258525952605261526252635264526552665267526852695270527152725273527452755276527752785279528052815282528352845285528652875288528952905291529252935294529552965297529852995300530153025303530453055306530753085309531053115312531353145315531653175318531953205321532253235324532553265327532853295330533153325333533453355336533753385339534053415342534353445345534653475348534953505351535253535354535553565357535853595360536153625363536453655366536753685369537053715372537353745375537653775378537953805381538253835384538553865387538853895390539153925393539453955396539753985399540054015402540354045405540654075408540954105411541254135414541554165417541854195420542154225423542454255426542754285429543054315432543354345435543654375438543954405441544254435444544554465447544854495450545154525453545454555456545754585459546054615462546354645465546654675468546954705471547254735474547554765477547854795480548154825483548454855486548754885489549054915492549354945495549654975498549955005501550255035504550555065507550855095510551155125513551455155516551755185519552055215522552355245525552655275528552955305531553255335534553555365537553855395540554155425543554455455546554755485549555055515552555355545555555655575558555955605561556255635564556555665567556855695570557155725573557455755576557755785579558055815582558355845585558655875588558955905591559255935594559555965597559855995600560156025603560456055606560756085609561056115612561356145615561656175618561956205621562256235624562556265627562856295630563156325633563456355636563756385639564056415642564356445645564656475648564956505651565256535654565556565657565856595660566156625663566456655666566756685669567056715672567356745675567656775678567956805681568256835684568556865687568856895690569156925693569456955696569756985699570057015702570357045705570657075708570957105711571257135714571557165717571857195720572157225723572457255726572757285729573057315732573357345735573657375738573957405741574257435744574557465747574857495750575157525753575457555756575757585759576057615762576357645765576657675768576957705771577257735774577557765777577857795780578157825783578457855786578757885789579057915792579357945795579657975798579958005801580258035804580558065807580858095810581158125813581458155816581758185819582058215822582358245825582658275828582958305831583258335834583558365837583858395840584158425843584458455846584758485849585058515852585358545855585658575858585958605861586258635864586558665867586858695870587158725873587458755876587758785879588058815882588358845885588658875888588958905891589258935894589558965897589858995900590159025903590459055906590759085909591059115912591359145915591659175918591959205921592259235924592559265927592859295930593159325933593459355936593759385939594059415942594359445945594659475948594959505951595259535954595559565957595859595960596159625963596459655966596759685969597059715972597359745975597659775978597959805981598259835984598559865987598859895990599159925993599459955996599759985999600060016002600360046005600660076008600960106011601260136014601560166017601860196020602160226023602460256026602760286029603060316032603360346035603660376038603960406041604260436044604560466047604860496050605160526053605460556056605760586059606060616062606360646065606660676068606960706071607260736074607560766077607860796080608160826083608460856086608760886089609060916092609360946095609660976098609961006101610261036104610561066107610861096110611161126113611461156116611761186119612061216122612361246125612661276128612961306131613261336134613561366137613861396140614161426143614461456146614761486149615061516152615361546155615661576158615961606161616261636164616561666167616861696170617161726173617461756176617761786179618061816182618361846185618661876188618961906191619261936194619561966197619861996200620162026203620462056206620762086209621062116212621362146215621662176218621962206221622262236224622562266227622862296230623162326233623462356236623762386239624062416242624362446245624662476248624962506251625262536254625562566257625862596260626162626263626462656266626762686269627062716272627362746275627662776278627962806281628262836284628562866287628862896290629162926293629462956296629762986299630063016302630363046305630663076308630963106311631263136314631563166317631863196320632163226323632463256326632763286329633063316332633363346335633663376338633963406341634263436344634563466347634863496350635163526353635463556356635763586359636063616362636363646365636663676368636963706371637263736374637563766377637863796380638163826383638463856386638763886389639063916392639363946395639663976398639964006401640264036404640564066407640864096410641164126413641464156416641764186419642064216422642364246425642664276428642964306431643264336434643564366437643864396440644164426443644464456446644764486449645064516452645364546455645664576458645964606461646264636464646564666467646864696470647164726473647464756476647764786479648064816482648364846485648664876488648964906491649264936494649564966497649864996500650165026503650465056506650765086509651065116512651365146515651665176518651965206521652265236524652565266527652865296530653165326533653465356536653765386539654065416542654365446545654665476548654965506551655265536554655565566557655865596560656165626563656465656566656765686569657065716572657365746575657665776578657965806581658265836584658565866587658865896590659165926593659465956596659765986599660066016602660366046605660666076608660966106611661266136614661566166617661866196620662166226623662466256626662766286629663066316632663366346635663666376638663966406641664266436644664566466647664866496650665166526653665466556656665766586659666066616662666366646665666666676668666966706671667266736674667566766677667866796680668166826683668466856686668766886689669066916692669366946695669666976698669967006701670267036704670567066707670867096710671167126713671467156716671767186719672067216722672367246725672667276728672967306731673267336734673567366737673867396740674167426743674467456746674767486749675067516752675367546755675667576758675967606761676267636764676567666767676867696770677167726773677467756776677767786779678067816782678367846785678667876788678967906791679267936794679567966797679867996800680168026803680468056806680768086809681068116812681368146815681668176818681968206821682268236824682568266827682868296830683168326833683468356836683768386839684068416842684368446845684668476848684968506851685268536854685568566857685868596860686168626863686468656866686768686869687068716872687368746875687668776878687968806881688268836884688568866887688868896890689168926893689468956896689768986899690069016902690369046905690669076908690969106911691269136914691569166917691869196920692169226923692469256926692769286929693069316932693369346935693669376938693969406941694269436944694569466947694869496950695169526953695469556956695769586959696069616962696369646965696669676968696969706971697269736974697569766977697869796980698169826983698469856986698769886989699069916992699369946995699669976998699970007001700270037004700570067007700870097010701170127013701470157016701770187019702070217022702370247025702670277028702970307031703270337034703570367037703870397040704170427043704470457046704770487049705070517052705370547055705670577058705970607061706270637064706570667067706870697070707170727073707470757076707770787079708070817082708370847085708670877088708970907091709270937094709570967097709870997100710171027103710471057106710771087109711071117112711371147115711671177118711971207121712271237124712571267127712871297130713171327133713471357136713771387139714071417142714371447145714671477148714971507151715271537154715571567157715871597160716171627163716471657166716771687169717071717172717371747175717671777178717971807181718271837184718571867187718871897190719171927193719471957196719771987199720072017202720372047205720672077208720972107211721272137214721572167217721872197220722172227223722472257226722772287229723072317232723372347235723672377238723972407241724272437244724572467247724872497250725172527253725472557256725772587259726072617262726372647265726672677268726972707271727272737274727572767277727872797280728172827283728472857286728772887289729072917292729372947295729672977298729973007301730273037304730573067307730873097310731173127313731473157316731773187319732073217322732373247325732673277328732973307331733273337334733573367337733873397340734173427343734473457346734773487349735073517352735373547355735673577358735973607361736273637364736573667367736873697370737173727373737473757376737773787379738073817382738373847385738673877388738973907391739273937394739573967397739873997400740174027403740474057406740774087409741074117412741374147415741674177418741974207421742274237424742574267427742874297430743174327433743474357436743774387439744074417442744374447445744674477448744974507451745274537454745574567457745874597460746174627463746474657466746774687469747074717472747374747475747674777478747974807481748274837484748574867487748874897490749174927493749474957496749774987499750075017502750375047505750675077508750975107511751275137514751575167517751875197520752175227523752475257526752775287529753075317532753375347535753675377538753975407541754275437544754575467547754875497550755175527553755475557556755775587559756075617562756375647565756675677568756975707571757275737574757575767577757875797580758175827583758475857586758775887589759075917592759375947595759675977598759976007601760276037604760576067607760876097610761176127613761476157616761776187619762076217622762376247625762676277628762976307631763276337634763576367637763876397640764176427643764476457646764776487649765076517652765376547655765676577658765976607661766276637664766576667667766876697670767176727673767476757676767776787679768076817682768376847685768676877688768976907691769276937694769576967697769876997700770177027703770477057706770777087709771077117712771377147715771677177718771977207721772277237724772577267727772877297730773177327733773477357736773777387739774077417742774377447745774677477748774977507751775277537754775577567757775877597760776177627763776477657766776777687769777077717772777377747775777677777778777977807781778277837784778577867787778877897790779177927793779477957796779777987799780078017802780378047805780678077808780978107811781278137814781578167817781878197820782178227823782478257826782778287829783078317832783378347835783678377838783978407841784278437844784578467847784878497850785178527853785478557856785778587859786078617862786378647865786678677868786978707871787278737874787578767877787878797880788178827883788478857886788778887889789078917892789378947895789678977898789979007901790279037904790579067907790879097910791179127913791479157916791779187919792079217922792379247925792679277928792979307931793279337934793579367937793879397940794179427943794479457946794779487949795079517952795379547955795679577958795979607961796279637964796579667967796879697970797179727973797479757976797779787979798079817982798379847985798679877988798979907991799279937994799579967997799879998000800180028003800480058006800780088009801080118012801380148015801680178018801980208021802280238024802580268027802880298030803180328033803480358036803780388039804080418042804380448045804680478048804980508051805280538054805580568057805880598060806180628063806480658066806780688069807080718072807380748075807680778078807980808081808280838084808580868087808880898090809180928093809480958096809780988099810081018102810381048105810681078108810981108111811281138114811581168117811881198120812181228123812481258126812781288129813081318132813381348135813681378138813981408141814281438144814581468147814881498150815181528153815481558156815781588159816081618162816381648165816681678168816981708171817281738174817581768177817881798180818181828183818481858186818781888189819081918192819381948195819681978198819982008201820282038204820582068207820882098210821182128213821482158216821782188219822082218222822382248225822682278228822982308231823282338234823582368237823882398240824182428243824482458246824782488249825082518252825382548255825682578258825982608261826282638264826582668267826882698270827182728273827482758276827782788279828082818282828382848285828682878288828982908291829282938294829582968297829882998300830183028303830483058306830783088309831083118312831383148315831683178318831983208321832283238324832583268327832883298330833183328333833483358336833783388339834083418342834383448345834683478348834983508351835283538354835583568357835883598360836183628363836483658366836783688369837083718372837383748375837683778378837983808381838283838384838583868387838883898390839183928393839483958396839783988399840084018402840384048405840684078408840984108411841284138414841584168417841884198420842184228423842484258426842784288429843084318432843384348435843684378438843984408441844284438444844584468447844884498450845184528453845484558456845784588459846084618462846384648465846684678468846984708471847284738474847584768477847884798480848184828483848484858486848784888489849084918492849384948495849684978498849985008501850285038504850585068507850885098510851185128513851485158516851785188519852085218522852385248525852685278528852985308531853285338534853585368537853885398540854185428543854485458546854785488549855085518552855385548555855685578558855985608561856285638564856585668567856885698570857185728573857485758576857785788579858085818582858385848585858685878588858985908591859285938594859585968597859885998600860186028603860486058606860786088609861086118612861386148615861686178618861986208621862286238624862586268627862886298630863186328633863486358636863786388639864086418642864386448645864686478648864986508651865286538654865586568657865886598660866186628663866486658666866786688669867086718672867386748675867686778678867986808681868286838684868586868687868886898690869186928693869486958696869786988699870087018702870387048705870687078708870987108711871287138714871587168717871887198720872187228723872487258726872787288729873087318732873387348735873687378738873987408741874287438744874587468747874887498750875187528753875487558756875787588759876087618762876387648765876687678768876987708771877287738774877587768777877887798780878187828783878487858786878787888789879087918792879387948795879687978798879988008801880288038804880588068807880888098810881188128813881488158816881788188819882088218822882388248825882688278828882988308831883288338834883588368837883888398840884188428843884488458846884788488849885088518852885388548855885688578858885988608861886288638864886588668867886888698870887188728873887488758876887788788879888088818882888388848885888688878888888988908891889288938894889588968897889888998900890189028903890489058906890789088909891089118912891389148915891689178918891989208921892289238924892589268927892889298930893189328933893489358936893789388939894089418942894389448945894689478948894989508951895289538954895589568957895889598960896189628963896489658966896789688969897089718972897389748975897689778978897989808981898289838984898589868987898889898990899189928993899489958996899789988999900090019002900390049005900690079008900990109011901290139014901590169017901890199020902190229023902490259026902790289029903090319032903390349035903690379038903990409041904290439044904590469047904890499050905190529053905490559056905790589059906090619062906390649065906690679068906990709071907290739074907590769077907890799080908190829083908490859086908790889089909090919092909390949095909690979098909991009101910291039104910591069107910891099110911191129113911491159116911791189119912091219122912391249125912691279128912991309131913291339134913591369137913891399140914191429143914491459146914791489149915091519152915391549155915691579158915991609161916291639164916591669167916891699170917191729173917491759176917791789179918091819182918391849185918691879188918991909191919291939194919591969197919891999200920192029203920492059206920792089209921092119212921392149215921692179218921992209221922292239224922592269227922892299230923192329233923492359236923792389239924092419242924392449245924692479248924992509251925292539254925592569257925892599260926192629263926492659266926792689269927092719272927392749275927692779278927992809281928292839284928592869287928892899290929192929293929492959296929792989299930093019302930393049305930693079308930993109311931293139314931593169317931893199320932193229323932493259326932793289329933093319332933393349335933693379338933993409341934293439344934593469347934893499350935193529353935493559356935793589359936093619362936393649365936693679368936993709371937293739374937593769377937893799380938193829383938493859386938793889389939093919392939393949395939693979398939994009401940294039404940594069407940894099410941194129413941494159416941794189419942094219422942394249425942694279428942994309431943294339434943594369437943894399440944194429443944494459446944794489449945094519452945394549455945694579458945994609461946294639464946594669467946894699470947194729473947494759476947794789479948094819482948394849485948694879488948994909491949294939494949594969497949894999500950195029503950495059506950795089509951095119512951395149515951695179518951995209521952295239524952595269527952895299530953195329533953495359536953795389539954095419542954395449545954695479548954995509551955295539554955595569557955895599560956195629563956495659566956795689569957095719572957395749575957695779578957995809581958295839584958595869587958895899590959195929593959495959596959795989599960096019602960396049605960696079608960996109611961296139614961596169617961896199620962196229623962496259626962796289629963096319632963396349635963696379638963996409641964296439644964596469647964896499650965196529653965496559656965796589659966096619662966396649665966696679668966996709671967296739674967596769677967896799680968196829683968496859686968796889689969096919692969396949695969696979698969997009701970297039704970597069707970897099710971197129713971497159716971797189719972097219722972397249725972697279728972997309731973297339734973597369737973897399740974197429743974497459746974797489749975097519752975397549755975697579758975997609761976297639764976597669767976897699770977197729773977497759776977797789779978097819782978397849785978697879788978997909791979297939794979597969797979897999800980198029803980498059806980798089809981098119812981398149815981698179818981998209821982298239824982598269827982898299830983198329833983498359836983798389839984098419842984398449845984698479848984998509851985298539854985598569857985898599860986198629863986498659866986798689869987098719872987398749875987698779878987998809881988298839884988598869887988898899890989198929893989498959896989798989899990099019902990399049905990699079908990999109911991299139914991599169917991899199920992199229923992499259926992799289929993099319932993399349935993699379938993999409941994299439944994599469947994899499950995199529953995499559956995799589959996099619962996399649965996699679968996999709971997299739974997599769977997899799980998199829983998499859986998799889989999099919992999399949995999699979998999910000100011000210003100041000510006100071000810009100101001110012100131001410015100161001710018100191002010021100221002310024100251002610027100281002910030100311003210033100341003510036100371003810039100401004110042100431004410045100461004710048100491005010051100521005310054100551005610057100581005910060100611006210063100641006510066100671006810069100701007110072100731007410075100761007710078100791008010081100821008310084100851008610087100881008910090100911009210093100941009510096100971009810099101001010110102101031010410105101061010710108101091011010111101121011310114101151011610117101181011910120101211012210123101241012510126101271012810129101301013110132101331013410135101361013710138101391014010141101421014310144101451014610147101481014910150101511015210153101541015510156101571015810159101601016110162101631016410165101661016710168101691017010171101721017310174101751017610177101781017910180101811018210183101841018510186101871018810189101901019110192101931019410195101961019710198101991020010201102021020310204102051020610207102081020910210102111021210213102141021510216102171021810219102201022110222102231022410225102261022710228102291023010231102321023310234102351023610237102381023910240102411024210243102441024510246102471024810249102501025110252102531025410255102561025710258102591026010261102621026310264102651026610267102681026910270102711027210273102741027510276102771027810279102801028110282102831028410285102861028710288102891029010291102921029310294102951029610297102981029910300103011030210303103041030510306103071030810309103101031110312103131031410315103161031710318103191032010321103221032310324103251032610327103281032910330103311033210333103341033510336103371033810339103401034110342103431034410345103461034710348103491035010351103521035310354103551035610357103581035910360103611036210363103641036510366103671036810369103701037110372103731037410375103761037710378103791038010381103821038310384103851038610387103881038910390103911039210393103941039510396103971039810399104001040110402104031040410405104061040710408104091041010411104121041310414104151041610417104181041910420104211042210423104241042510426104271042810429104301043110432104331043410435104361043710438104391044010441104421044310444104451044610447104481044910450104511045210453104541045510456104571045810459104601046110462104631046410465104661046710468104691047010471104721047310474104751047610477104781047910480104811048210483104841048510486104871048810489104901049110492104931049410495104961049710498104991050010501105021050310504105051050610507105081050910510105111051210513105141051510516105171051810519105201052110522105231052410525105261052710528105291053010531105321053310534105351053610537105381053910540105411054210543105441054510546105471054810549105501055110552105531055410555105561055710558105591056010561105621056310564105651056610567105681056910570105711057210573105741057510576105771057810579105801058110582105831058410585105861058710588105891059010591105921059310594105951059610597105981059910600106011060210603106041060510606106071060810609106101061110612106131061410615106161061710618106191062010621106221062310624106251062610627106281062910630106311063210633106341063510636106371063810639106401064110642106431064410645106461064710648106491065010651106521065310654106551065610657106581065910660106611066210663106641066510666106671066810669106701067110672106731067410675106761067710678106791068010681106821068310684106851068610687106881068910690106911069210693106941069510696106971069810699107001070110702107031070410705107061070710708107091071010711107121071310714107151071610717107181071910720107211072210723107241072510726107271072810729107301073110732107331073410735107361073710738107391074010741107421074310744107451074610747107481074910750107511075210753107541075510756107571075810759107601076110762107631076410765107661076710768107691077010771107721077310774107751077610777107781077910780107811078210783107841078510786107871078810789107901079110792107931079410795107961079710798107991080010801108021080310804108051080610807108081080910810108111081210813108141081510816108171081810819108201082110822108231082410825108261082710828108291083010831108321083310834108351083610837108381083910840108411084210843108441084510846108471084810849108501085110852108531085410855108561085710858108591086010861108621086310864108651086610867108681086910870108711087210873108741087510876108771087810879108801088110882108831088410885108861088710888108891089010891108921089310894108951089610897108981089910900109011090210903109041090510906109071090810909109101091110912109131091410915109161091710918109191092010921109221092310924109251092610927109281092910930109311093210933109341093510936109371093810939109401094110942109431094410945109461094710948109491095010951109521095310954109551095610957109581095910960109611096210963109641096510966109671096810969109701097110972109731097410975109761097710978109791098010981109821098310984109851098610987109881098910990109911099210993109941099510996109971099810999110001100111002110031100411005110061100711008110091101011011110121101311014110151101611017110181101911020110211102211023110241102511026110271102811029110301103111032110331103411035110361103711038110391104011041110421104311044110451104611047110481104911050110511105211053110541105511056110571105811059110601106111062110631106411065110661106711068110691107011071110721107311074110751107611077110781107911080110811108211083110841108511086110871108811089110901109111092110931109411095110961109711098110991110011101111021110311104111051110611107111081110911110111111111211113111141111511116111171111811119111201112111122111231112411125111261112711128111291113011131111321113311134111351113611137111381113911140111411114211143111441114511146111471114811149111501115111152111531115411155111561115711158111591116011161111621116311164111651116611167111681116911170111711117211173111741117511176111771117811179111801118111182111831118411185111861118711188111891119011191111921119311194111951119611197111981119911200112011120211203112041120511206112071120811209112101121111212112131121411215112161121711218112191122011221112221122311224112251122611227112281122911230112311123211233112341123511236112371123811239112401124111242112431124411245112461124711248112491125011251112521125311254112551125611257112581125911260112611126211263112641126511266112671126811269112701127111272112731127411275112761127711278112791128011281112821128311284112851128611287112881128911290112911129211293112941129511296112971129811299113001130111302113031130411305113061130711308113091131011311113121131311314113151131611317113181131911320113211132211323113241132511326113271132811329113301133111332113331133411335113361133711338113391134011341113421134311344113451134611347113481134911350113511135211353113541135511356113571135811359113601136111362113631136411365113661136711368113691137011371113721137311374113751137611377113781137911380113811138211383113841138511386113871138811389113901139111392113931139411395113961139711398113991140011401114021140311404114051140611407114081140911410114111141211413114141141511416114171141811419114201142111422114231142411425114261142711428114291143011431114321143311434114351143611437114381143911440114411144211443114441144511446114471144811449114501145111452114531145411455114561145711458114591146011461114621146311464114651146611467114681146911470114711147211473114741147511476114771147811479114801148111482114831148411485114861148711488114891149011491114921149311494114951149611497114981149911500115011150211503115041150511506115071150811509115101151111512115131151411515115161151711518115191152011521115221152311524115251152611527115281152911530115311153211533115341153511536115371153811539115401154111542115431154411545115461154711548115491155011551115521155311554115551155611557115581155911560115611156211563115641156511566115671156811569115701157111572115731157411575115761157711578115791158011581115821158311584115851158611587115881158911590115911159211593115941159511596115971159811599116001160111602116031160411605116061160711608116091161011611116121161311614116151161611617116181161911620116211162211623116241162511626116271162811629116301163111632116331163411635116361163711638116391164011641116421164311644116451164611647116481164911650116511165211653116541165511656116571165811659116601166111662116631166411665116661166711668116691167011671116721167311674116751167611677116781167911680116811168211683116841168511686116871168811689116901169111692116931169411695116961169711698116991170011701117021170311704117051170611707117081170911710117111171211713117141171511716117171171811719117201172111722117231172411725117261172711728117291173011731117321173311734117351173611737117381173911740117411174211743117441174511746117471174811749117501175111752117531175411755117561175711758117591176011761117621176311764117651176611767117681176911770117711177211773117741177511776117771177811779117801178111782117831178411785117861178711788117891179011791117921179311794117951179611797117981179911800118011180211803118041180511806118071180811809118101181111812118131181411815118161181711818118191182011821118221182311824118251182611827118281182911830118311183211833118341183511836118371183811839118401184111842118431184411845118461184711848118491185011851118521185311854118551185611857118581185911860118611186211863118641186511866118671186811869118701187111872118731187411875118761187711878118791188011881118821188311884118851188611887118881188911890118911189211893118941189511896118971189811899119001190111902119031190411905119061190711908119091191011911119121191311914119151191611917119181191911920119211192211923119241192511926119271192811929119301193111932119331193411935119361193711938119391194011941119421194311944119451194611947119481194911950119511195211953119541195511956119571195811959119601196111962119631196411965119661196711968119691197011971119721197311974119751197611977119781197911980119811198211983119841198511986119871198811989119901199111992119931199411995119961199711998119991200012001120021200312004120051200612007120081200912010120111201212013120141201512016120171201812019120201202112022120231202412025120261202712028120291203012031120321203312034120351203612037120381203912040120411204212043120441204512046120471204812049120501205112052120531205412055120561205712058120591206012061120621206312064120651206612067120681206912070120711207212073120741207512076120771207812079120801208112082120831208412085120861208712088120891209012091120921209312094120951209612097120981209912100121011210212103121041210512106121071210812109121101211112112121131211412115121161211712118121191212012121121221212312124121251212612127121281212912130121311213212133121341213512136121371213812139121401214112142121431214412145121461214712148121491215012151121521215312154121551215612157121581215912160121611216212163121641216512166121671216812169121701217112172121731217412175121761217712178121791218012181121821218312184121851218612187121881218912190121911219212193121941219512196121971219812199122001220112202122031220412205122061220712208122091221012211122121221312214122151221612217122181221912220122211222212223122241222512226122271222812229122301223112232122331223412235122361223712238122391224012241122421224312244122451224612247122481224912250122511225212253122541225512256122571225812259122601226112262122631226412265122661226712268122691227012271122721227312274122751227612277122781227912280122811228212283122841228512286122871228812289122901229112292122931229412295122961229712298122991230012301123021230312304123051230612307123081230912310123111231212313123141231512316123171231812319123201232112322123231232412325123261232712328123291233012331123321233312334123351233612337123381233912340123411234212343123441234512346123471234812349123501235112352123531235412355123561235712358123591236012361123621236312364123651236612367123681236912370123711237212373123741237512376123771237812379123801238112382123831238412385123861238712388123891239012391123921239312394123951239612397123981239912400124011240212403124041240512406124071240812409124101241112412124131241412415124161241712418124191242012421124221242312424124251242612427124281242912430124311243212433124341243512436124371243812439124401244112442124431244412445124461244712448124491245012451124521245312454124551245612457124581245912460124611246212463124641246512466124671246812469124701247112472124731247412475124761247712478124791248012481124821248312484124851248612487124881248912490124911249212493124941249512496124971249812499125001250112502125031250412505125061250712508125091251012511125121251312514125151251612517125181251912520125211252212523125241252512526125271252812529125301253112532125331253412535125361253712538125391254012541125421254312544125451254612547125481254912550125511255212553125541255512556125571255812559125601256112562125631256412565125661256712568125691257012571125721257312574125751257612577125781257912580125811258212583125841258512586125871258812589125901259112592125931259412595125961259712598125991260012601126021260312604126051260612607126081260912610126111261212613126141261512616126171261812619126201262112622126231262412625126261262712628126291263012631126321263312634126351263612637126381263912640126411264212643126441264512646126471264812649126501265112652126531265412655126561265712658126591266012661126621266312664126651266612667126681266912670126711267212673126741267512676126771267812679126801268112682126831268412685126861268712688126891269012691126921269312694126951269612697126981269912700127011270212703127041270512706127071270812709127101271112712127131271412715127161271712718127191272012721127221272312724127251272612727127281272912730127311273212733127341273512736127371273812739127401274112742127431274412745127461274712748127491275012751127521275312754127551275612757127581275912760127611276212763127641276512766127671276812769127701277112772127731277412775127761277712778127791278012781127821278312784127851278612787127881278912790127911279212793127941279512796127971279812799128001280112802128031280412805128061280712808128091281012811128121281312814128151281612817128181281912820128211282212823128241282512826128271282812829128301283112832128331283412835128361283712838128391284012841128421284312844128451284612847128481284912850128511285212853128541285512856128571285812859128601286112862128631286412865128661286712868128691287012871128721287312874128751287612877128781287912880128811288212883128841288512886128871288812889128901289112892128931289412895128961289712898128991290012901129021290312904129051290612907129081290912910129111291212913129141291512916129171291812919129201292112922129231292412925129261292712928129291293012931129321293312934129351293612937129381293912940129411294212943129441294512946129471294812949129501295112952129531295412955129561295712958129591296012961129621296312964129651296612967129681296912970129711297212973129741297512976129771297812979129801298112982129831298412985129861298712988129891299012991129921299312994129951299612997129981299913000130011300213003130041300513006130071300813009130101301113012130131301413015130161301713018130191302013021130221302313024130251302613027130281302913030130311303213033130341303513036130371303813039130401304113042130431304413045130461304713048130491305013051130521305313054130551305613057130581305913060130611306213063130641306513066130671306813069130701307113072130731307413075130761307713078130791308013081130821308313084130851308613087130881308913090130911309213093130941309513096130971309813099131001310113102131031310413105131061310713108131091311013111131121311313114131151311613117131181311913120131211312213123131241312513126131271312813129131301313113132131331313413135131361313713138131391314013141131421314313144131451314613147131481314913150131511315213153131541315513156131571315813159131601316113162131631316413165131661316713168131691317013171131721317313174131751317613177131781317913180131811318213183131841318513186131871318813189131901319113192131931319413195131961319713198131991320013201132021320313204132051320613207132081320913210132111321213213132141321513216132171321813219132201322113222132231322413225132261322713228132291323013231132321323313234132351323613237132381323913240132411324213243132441324513246132471324813249132501325113252132531325413255132561325713258132591326013261132621326313264132651326613267132681326913270132711327213273132741327513276132771327813279132801328113282132831328413285132861328713288132891329013291132921329313294132951329613297132981329913300133011330213303133041330513306133071330813309133101331113312133131331413315133161331713318133191332013321133221332313324133251332613327133281332913330133311333213333133341333513336133371333813339133401334113342133431334413345133461334713348133491335013351133521335313354133551335613357133581335913360133611336213363133641336513366133671336813369133701337113372133731337413375133761337713378133791338013381133821338313384133851338613387133881338913390133911339213393133941339513396133971339813399134001340113402134031340413405134061340713408134091341013411134121341313414134151341613417134181341913420134211342213423134241342513426134271342813429134301343113432134331343413435134361343713438134391344013441134421344313444134451344613447134481344913450134511345213453134541345513456134571345813459134601346113462134631346413465134661346713468134691347013471134721347313474134751347613477134781347913480134811348213483134841348513486134871348813489134901349113492134931349413495134961349713498134991350013501135021350313504135051350613507135081350913510135111351213513135141351513516135171351813519135201352113522135231352413525135261352713528135291353013531135321353313534135351353613537135381353913540135411354213543135441354513546135471354813549135501355113552135531355413555135561355713558135591356013561135621356313564135651356613567135681356913570135711357213573135741357513576135771357813579135801358113582135831358413585135861358713588135891359013591135921359313594135951359613597135981359913600136011360213603136041360513606136071360813609136101361113612136131361413615136161361713618136191362013621136221362313624136251362613627136281362913630136311363213633136341363513636136371363813639136401364113642136431364413645136461364713648136491365013651136521365313654136551365613657136581365913660136611366213663136641366513666136671366813669136701367113672136731367413675136761367713678136791368013681136821368313684136851368613687136881368913690136911369213693136941369513696136971369813699137001370113702137031370413705137061370713708137091371013711137121371313714137151371613717137181371913720137211372213723137241372513726137271372813729137301373113732137331373413735137361373713738137391374013741137421374313744137451374613747137481374913750137511375213753137541375513756137571375813759137601376113762137631376413765137661376713768137691377013771137721377313774137751377613777137781377913780137811378213783137841378513786137871378813789137901379113792137931379413795137961379713798137991380013801138021380313804138051380613807138081380913810138111381213813138141381513816138171381813819138201382113822138231382413825138261382713828138291383013831138321383313834138351383613837138381383913840138411384213843138441384513846138471384813849138501385113852138531385413855138561385713858138591386013861138621386313864138651386613867138681386913870138711387213873138741387513876138771387813879138801388113882138831388413885138861388713888138891389013891138921389313894138951389613897138981389913900139011390213903139041390513906139071390813909139101391113912139131391413915139161391713918139191392013921139221392313924139251392613927139281392913930139311393213933139341393513936139371393813939139401394113942139431394413945139461394713948139491395013951139521395313954139551395613957139581395913960139611396213963139641396513966139671396813969139701397113972139731397413975139761397713978139791398013981139821398313984139851398613987139881398913990139911399213993139941399513996139971399813999140001400114002140031400414005140061400714008140091401014011140121401314014140151401614017140181401914020140211402214023140241402514026140271402814029140301403114032140331403414035140361403714038140391404014041140421404314044140451404614047140481404914050140511405214053140541405514056140571405814059140601406114062140631406414065140661406714068140691407014071140721407314074140751407614077140781407914080140811408214083140841408514086140871408814089140901409114092140931409414095140961409714098140991410014101141021410314104141051410614107141081410914110141111411214113141141411514116141171411814119141201412114122141231412414125141261412714128141291413014131141321413314134141351413614137141381413914140141411414214143141441414514146141471414814149141501415114152141531415414155141561415714158141591416014161141621416314164141651416614167141681416914170141711417214173141741417514176141771417814179141801418114182141831418414185141861418714188141891419014191141921419314194141951419614197141981419914200142011420214203142041420514206142071420814209142101421114212142131421414215142161421714218142191422014221142221422314224142251422614227142281422914230142311423214233142341423514236142371423814239142401424114242142431424414245142461424714248142491425014251142521425314254142551425614257142581425914260142611426214263142641426514266142671426814269142701427114272142731427414275142761427714278142791428014281142821428314284142851428614287142881428914290142911429214293142941429514296142971429814299143001430114302143031430414305143061430714308143091431014311143121431314314143151431614317143181431914320143211432214323143241432514326143271432814329143301433114332143331433414335143361433714338143391434014341143421434314344143451434614347143481434914350143511435214353143541435514356143571435814359143601436114362143631436414365143661436714368143691437014371143721437314374143751437614377143781437914380143811438214383143841438514386143871438814389143901439114392143931439414395143961439714398143991440014401144021440314404144051440614407144081440914410144111441214413144141441514416144171441814419144201442114422144231442414425144261442714428144291443014431144321443314434144351443614437144381443914440144411444214443144441444514446144471444814449144501445114452144531445414455144561445714458144591446014461144621446314464144651446614467144681446914470144711447214473144741447514476144771447814479144801448114482144831448414485144861448714488144891449014491144921449314494144951449614497144981449914500145011450214503145041450514506145071450814509145101451114512145131451414515145161451714518145191452014521145221452314524145251452614527145281452914530145311453214533145341453514536145371453814539145401454114542145431454414545145461454714548145491455014551145521455314554145551455614557145581455914560145611456214563145641456514566145671456814569145701457114572145731457414575145761457714578145791458014581145821458314584145851458614587145881458914590145911459214593145941459514596145971459814599146001460114602146031460414605146061460714608146091461014611146121461314614146151461614617146181461914620146211462214623146241462514626146271462814629146301463114632146331463414635146361463714638146391464014641146421464314644146451464614647146481464914650146511465214653146541465514656146571465814659146601466114662146631466414665146661466714668146691467014671146721467314674146751467614677146781467914680146811468214683146841468514686146871468814689146901469114692146931469414695146961469714698146991470014701147021470314704147051470614707147081470914710147111471214713147141471514716147171471814719147201472114722147231472414725147261472714728147291473014731147321473314734147351473614737147381473914740147411474214743147441474514746147471474814749147501475114752147531475414755147561475714758147591476014761147621476314764147651476614767147681476914770147711477214773147741477514776147771477814779147801478114782147831478414785147861478714788147891479014791147921479314794147951479614797147981479914800148011480214803148041480514806148071480814809148101481114812148131481414815148161481714818148191482014821148221482314824148251482614827148281482914830148311483214833148341483514836148371483814839148401484114842148431484414845148461484714848148491485014851148521485314854148551485614857148581485914860148611486214863148641486514866148671486814869148701487114872148731487414875148761487714878148791488014881148821488314884148851488614887148881488914890148911489214893148941489514896148971489814899149001490114902149031490414905149061490714908149091491014911149121491314914149151491614917149181491914920149211492214923149241492514926149271492814929149301493114932149331493414935149361493714938149391494014941149421494314944149451494614947149481494914950149511495214953149541495514956149571495814959149601496114962149631496414965149661496714968149691497014971149721497314974149751497614977149781497914980149811498214983149841498514986149871498814989149901499114992149931499414995149961499714998149991500015001150021500315004150051500615007150081500915010150111501215013150141501515016150171501815019150201502115022150231502415025150261502715028150291503015031150321503315034150351503615037150381503915040150411504215043150441504515046150471504815049150501505115052150531505415055150561505715058150591506015061150621506315064150651506615067150681506915070150711507215073150741507515076150771507815079150801508115082150831508415085150861508715088150891509015091150921509315094150951509615097150981509915100151011510215103151041510515106151071510815109151101511115112151131511415115151161511715118151191512015121151221512315124151251512615127151281512915130151311513215133151341513515136151371513815139151401514115142151431514415145151461514715148151491515015151151521515315154151551515615157151581515915160151611516215163151641516515166151671516815169151701517115172151731517415175151761517715178151791518015181151821518315184151851518615187151881518915190151911519215193151941519515196151971519815199152001520115202152031520415205152061520715208152091521015211152121521315214152151521615217152181521915220152211522215223152241522515226152271522815229152301523115232152331523415235152361523715238152391524015241152421524315244152451524615247152481524915250152511525215253152541525515256152571525815259152601526115262152631526415265152661526715268152691527015271152721527315274152751527615277152781527915280152811528215283152841528515286152871528815289152901529115292152931529415295152961529715298152991530015301153021530315304153051530615307153081530915310153111531215313153141531515316153171531815319153201532115322153231532415325153261532715328153291533015331153321533315334153351533615337153381533915340153411534215343153441534515346153471534815349153501535115352153531535415355153561535715358153591536015361153621536315364153651536615367153681536915370153711537215373153741537515376153771537815379153801538115382153831538415385153861538715388153891539015391153921539315394153951539615397153981539915400154011540215403154041540515406154071540815409154101541115412154131541415415154161541715418154191542015421154221542315424154251542615427154281542915430154311543215433154341543515436154371543815439154401544115442154431544415445154461544715448154491545015451154521545315454154551545615457154581545915460154611546215463154641546515466154671546815469154701547115472154731547415475154761547715478154791548015481154821548315484154851548615487154881548915490154911549215493154941549515496154971549815499155001550115502155031550415505155061550715508155091551015511155121551315514155151551615517155181551915520155211552215523155241552515526155271552815529155301553115532155331553415535155361553715538155391554015541155421554315544155451554615547155481554915550155511555215553155541555515556155571555815559155601556115562155631556415565155661556715568155691557015571155721557315574155751557615577155781557915580155811558215583155841558515586155871558815589155901559115592155931559415595155961559715598155991560015601156021560315604156051560615607156081560915610156111561215613156141561515616156171561815619156201562115622156231562415625156261562715628156291563015631156321563315634156351563615637156381563915640156411564215643156441564515646156471564815649156501565115652156531565415655156561565715658156591566015661156621566315664156651566615667156681566915670156711567215673156741567515676156771567815679156801568115682156831568415685156861568715688156891569015691156921569315694156951569615697156981569915700157011570215703157041570515706157071570815709157101571115712157131571415715157161571715718157191572015721157221572315724157251572615727157281572915730157311573215733157341573515736157371573815739157401574115742157431574415745157461574715748157491575015751157521575315754157551575615757157581575915760157611576215763157641576515766157671576815769157701577115772157731577415775157761577715778157791578015781157821578315784157851578615787157881578915790157911579215793157941579515796157971579815799158001580115802158031580415805158061580715808158091581015811158121581315814158151581615817158181581915820158211582215823158241582515826158271582815829158301583115832158331583415835158361583715838158391584015841158421584315844158451584615847158481584915850158511585215853158541585515856158571585815859158601586115862158631586415865158661586715868158691587015871158721587315874158751587615877158781587915880158811588215883158841588515886158871588815889158901589115892158931589415895158961589715898158991590015901159021590315904159051590615907159081590915910159111591215913159141591515916159171591815919159201592115922159231592415925159261592715928159291593015931159321593315934159351593615937159381593915940159411594215943159441594515946159471594815949159501595115952159531595415955159561595715958159591596015961159621596315964159651596615967159681596915970159711597215973159741597515976159771597815979159801598115982159831598415985159861598715988159891599015991159921599315994159951599615997159981599916000160011600216003160041600516006160071600816009160101601116012160131601416015160161601716018160191602016021160221602316024160251602616027160281602916030160311603216033160341603516036160371603816039160401604116042160431604416045160461604716048160491605016051160521605316054160551605616057160581605916060160611606216063160641606516066160671606816069160701607116072160731607416075160761607716078160791608016081160821608316084160851608616087160881608916090160911609216093160941609516096160971609816099161001610116102161031610416105161061610716108161091611016111161121611316114161151611616117161181611916120161211612216123161241612516126161271612816129161301613116132161331613416135161361613716138161391614016141161421614316144161451614616147161481614916150161511615216153161541615516156161571615816159161601616116162161631616416165161661616716168161691617016171161721617316174161751617616177161781617916180161811618216183161841618516186161871618816189161901619116192161931619416195161961619716198161991620016201162021620316204162051620616207162081620916210162111621216213162141621516216162171621816219162201622116222162231622416225162261622716228162291623016231162321623316234162351623616237162381623916240162411624216243162441624516246162471624816249162501625116252162531625416255162561625716258162591626016261162621626316264162651626616267162681626916270162711627216273162741627516276162771627816279162801628116282162831628416285162861628716288162891629016291162921629316294162951629616297162981629916300163011630216303163041630516306163071630816309163101631116312163131631416315163161631716318163191632016321163221632316324163251632616327163281632916330163311633216333163341633516336163371633816339163401634116342163431634416345163461634716348163491635016351163521635316354163551635616357163581635916360163611636216363163641636516366163671636816369163701637116372163731637416375163761637716378163791638016381163821638316384163851638616387163881638916390163911639216393163941639516396163971639816399164001640116402164031640416405164061640716408164091641016411164121641316414164151641616417164181641916420164211642216423164241642516426164271642816429164301643116432164331643416435164361643716438164391644016441164421644316444164451644616447164481644916450164511645216453164541645516456164571645816459164601646116462164631646416465164661646716468164691647016471164721647316474164751647616477164781647916480164811648216483164841648516486164871648816489164901649116492164931649416495164961649716498164991650016501165021650316504165051650616507165081650916510165111651216513165141651516516165171651816519165201652116522165231652416525165261652716528165291653016531165321653316534165351653616537165381653916540165411654216543165441654516546165471654816549165501655116552165531655416555165561655716558165591656016561165621656316564165651656616567165681656916570165711657216573165741657516576165771657816579165801658116582165831658416585165861658716588165891659016591165921659316594165951659616597165981659916600166011660216603166041660516606166071660816609166101661116612166131661416615166161661716618166191662016621166221662316624166251662616627166281662916630166311663216633166341663516636166371663816639166401664116642166431664416645166461664716648166491665016651166521665316654166551665616657166581665916660166611666216663166641666516666166671666816669166701667116672166731667416675166761667716678166791668016681166821668316684166851668616687166881668916690166911669216693166941669516696166971669816699167001670116702167031670416705167061670716708167091671016711167121671316714167151671616717167181671916720167211672216723167241672516726167271672816729167301673116732167331673416735167361673716738167391674016741167421674316744167451674616747167481674916750167511675216753167541675516756167571675816759167601676116762167631676416765167661676716768167691677016771167721677316774167751677616777167781677916780167811678216783167841678516786167871678816789167901679116792167931679416795167961679716798167991680016801168021680316804168051680616807168081680916810168111681216813168141681516816168171681816819168201682116822168231682416825168261682716828168291683016831168321683316834168351683616837168381683916840168411684216843168441684516846168471684816849168501685116852168531685416855168561685716858168591686016861168621686316864168651686616867168681686916870168711687216873168741687516876168771687816879168801688116882168831688416885168861688716888168891689016891168921689316894168951689616897168981689916900169011690216903169041690516906169071690816909169101691116912169131691416915169161691716918169191692016921169221692316924169251692616927169281692916930169311693216933169341693516936169371693816939169401694116942169431694416945169461694716948169491695016951169521695316954169551695616957169581695916960169611696216963169641696516966169671696816969169701697116972169731697416975169761697716978169791698016981169821698316984169851698616987169881698916990169911699216993169941699516996169971699816999170001700117002170031700417005170061700717008170091701017011170121701317014170151701617017170181701917020170211702217023170241702517026170271702817029170301703117032170331703417035170361703717038170391704017041170421704317044170451704617047170481704917050170511705217053170541705517056170571705817059170601706117062170631706417065170661706717068170691707017071170721707317074170751707617077170781707917080170811708217083170841708517086170871708817089170901709117092170931709417095170961709717098170991710017101171021710317104171051710617107171081710917110171111711217113171141711517116171171711817119171201712117122171231712417125171261712717128171291713017131171321713317134171351713617137171381713917140171411714217143171441714517146171471714817149171501715117152171531715417155171561715717158171591716017161171621716317164171651716617167171681716917170171711717217173171741717517176171771717817179171801718117182171831718417185171861718717188171891719017191171921719317194171951719617197171981719917200172011720217203172041720517206172071720817209172101721117212172131721417215172161721717218172191722017221172221722317224172251722617227172281722917230172311723217233172341723517236172371723817239172401724117242172431724417245172461724717248172491725017251172521725317254172551725617257172581725917260172611726217263172641726517266172671726817269172701727117272172731727417275172761727717278172791728017281172821728317284172851728617287172881728917290172911729217293172941729517296172971729817299173001730117302173031730417305173061730717308173091731017311173121731317314173151731617317173181731917320173211732217323173241732517326173271732817329173301733117332173331733417335173361733717338173391734017341173421734317344173451734617347173481734917350173511735217353173541735517356173571735817359173601736117362173631736417365173661736717368173691737017371173721737317374173751737617377173781737917380173811738217383173841738517386173871738817389173901739117392173931739417395173961739717398173991740017401174021740317404174051740617407174081740917410174111741217413174141741517416174171741817419174201742117422174231742417425174261742717428174291743017431174321743317434174351743617437174381743917440174411744217443174441744517446174471744817449174501745117452174531745417455174561745717458174591746017461174621746317464174651746617467174681746917470174711747217473174741747517476174771747817479174801748117482174831748417485174861748717488174891749017491174921749317494174951749617497174981749917500175011750217503175041750517506175071750817509175101751117512175131751417515175161751717518175191752017521175221752317524175251752617527175281752917530175311753217533175341753517536175371753817539175401754117542175431754417545175461754717548175491755017551175521755317554175551755617557175581755917560175611756217563175641756517566175671756817569175701757117572175731757417575175761757717578175791758017581175821758317584175851758617587175881758917590175911759217593175941759517596175971759817599176001760117602176031760417605176061760717608176091761017611176121761317614176151761617617176181761917620176211762217623176241762517626176271762817629176301763117632176331763417635176361763717638176391764017641176421764317644176451764617647176481764917650176511765217653176541765517656176571765817659176601766117662176631766417665176661766717668176691767017671176721767317674176751767617677176781767917680176811768217683176841768517686176871768817689176901769117692176931769417695176961769717698176991770017701177021770317704177051770617707177081770917710177111771217713177141771517716177171771817719177201772117722177231772417725177261772717728177291773017731177321773317734177351773617737177381773917740177411774217743177441774517746177471774817749177501775117752177531775417755177561775717758177591776017761177621776317764177651776617767177681776917770177711777217773177741777517776177771777817779177801778117782177831778417785177861778717788177891779017791177921779317794177951779617797177981779917800178011780217803178041780517806178071780817809178101781117812178131781417815178161781717818178191782017821178221782317824178251782617827178281782917830178311783217833178341783517836178371783817839178401784117842178431784417845178461784717848178491785017851178521785317854178551785617857178581785917860178611786217863178641786517866178671786817869178701787117872178731787417875178761787717878178791788017881178821788317884178851788617887178881788917890178911789217893178941789517896178971789817899179001790117902179031790417905179061790717908179091791017911179121791317914179151791617917179181791917920179211792217923179241792517926179271792817929179301793117932179331793417935179361793717938179391794017941179421794317944179451794617947179481794917950179511795217953179541795517956179571795817959179601796117962179631796417965179661796717968179691797017971179721797317974179751797617977179781797917980179811798217983179841798517986179871798817989179901799117992179931799417995179961799717998179991800018001180021800318004180051800618007180081800918010180111801218013180141801518016180171801818019180201802118022180231802418025180261802718028180291803018031180321803318034180351803618037180381803918040180411804218043180441804518046180471804818049180501805118052180531805418055180561805718058180591806018061180621806318064180651806618067180681806918070180711807218073180741807518076180771807818079180801808118082180831808418085180861808718088180891809018091180921809318094180951809618097180981809918100181011810218103181041810518106181071810818109181101811118112181131811418115181161811718118181191812018121181221812318124181251812618127181281812918130181311813218133181341813518136181371813818139181401814118142181431814418145181461814718148181491815018151181521815318154181551815618157181581815918160181611816218163181641816518166181671816818169181701817118172181731817418175181761817718178181791818018181181821818318184181851818618187181881818918190181911819218193181941819518196181971819818199182001820118202182031820418205182061820718208182091821018211182121821318214182151821618217182181821918220182211822218223182241822518226182271822818229182301823118232182331823418235182361823718238182391824018241182421824318244182451824618247182481824918250182511825218253182541825518256182571825818259182601826118262182631826418265182661826718268182691827018271182721827318274182751827618277182781827918280182811828218283182841828518286182871828818289182901829118292182931829418295182961829718298182991830018301183021830318304183051830618307183081830918310183111831218313183141831518316183171831818319183201832118322183231832418325183261832718328183291833018331183321833318334183351833618337183381833918340183411834218343183441834518346183471834818349183501835118352183531835418355183561835718358183591836018361183621836318364183651836618367183681836918370183711837218373183741837518376183771837818379183801838118382183831838418385183861838718388183891839018391183921839318394183951839618397183981839918400184011840218403184041840518406184071840818409184101841118412184131841418415184161841718418184191842018421184221842318424184251842618427184281842918430184311843218433184341843518436184371843818439184401844118442184431844418445184461844718448184491845018451184521845318454184551845618457184581845918460184611846218463184641846518466184671846818469184701847118472184731847418475184761847718478184791848018481184821848318484184851848618487184881848918490184911849218493184941849518496184971849818499185001850118502185031850418505185061850718508185091851018511185121851318514185151851618517185181851918520185211852218523185241852518526185271852818529185301853118532185331853418535185361853718538185391854018541185421854318544185451854618547185481854918550185511855218553185541855518556185571855818559185601856118562185631856418565185661856718568185691857018571185721857318574185751857618577185781857918580185811858218583185841858518586185871858818589185901859118592185931859418595185961859718598185991860018601186021860318604186051860618607186081860918610186111861218613186141861518616186171861818619186201862118622186231862418625186261862718628186291863018631186321863318634186351863618637186381863918640186411864218643186441864518646186471864818649186501865118652186531865418655186561865718658186591866018661186621866318664186651866618667186681866918670186711867218673186741867518676186771867818679186801868118682186831868418685186861868718688186891869018691186921869318694186951869618697186981869918700187011870218703187041870518706187071870818709187101871118712187131871418715187161871718718187191872018721187221872318724187251872618727187281872918730187311873218733187341873518736187371873818739187401874118742187431874418745187461874718748187491875018751187521875318754187551875618757187581875918760187611876218763187641876518766187671876818769187701877118772187731877418775187761877718778187791878018781187821878318784187851878618787187881878918790187911879218793187941879518796187971879818799188001880118802188031880418805188061880718808188091881018811188121881318814188151881618817188181881918820188211882218823188241882518826188271882818829188301883118832188331883418835188361883718838188391884018841188421884318844188451884618847188481884918850188511885218853188541885518856188571885818859188601886118862188631886418865188661886718868188691887018871188721887318874188751887618877188781887918880188811888218883188841888518886188871888818889188901889118892188931889418895188961889718898188991890018901189021890318904189051890618907189081890918910189111891218913189141891518916189171891818919189201892118922189231892418925189261892718928189291893018931189321893318934189351893618937189381893918940189411894218943189441894518946189471894818949189501895118952189531895418955189561895718958189591896018961189621896318964189651896618967189681896918970189711897218973189741897518976189771897818979189801898118982189831898418985189861898718988189891899018991189921899318994189951899618997189981899919000190011900219003190041900519006190071900819009190101901119012190131901419015190161901719018190191902019021190221902319024190251902619027190281902919030190311903219033190341903519036190371903819039190401904119042190431904419045190461904719048190491905019051190521905319054190551905619057190581905919060190611906219063190641906519066190671906819069190701907119072190731907419075190761907719078190791908019081190821908319084190851908619087190881908919090190911909219093190941909519096190971909819099191001910119102191031910419105191061910719108191091911019111191121911319114191151911619117191181911919120191211912219123191241912519126191271912819129191301913119132191331913419135191361913719138191391914019141191421914319144191451914619147191481914919150191511915219153191541915519156191571915819159191601916119162191631916419165191661916719168191691917019171191721917319174191751917619177191781917919180191811918219183191841918519186191871918819189191901919119192191931919419195191961919719198191991920019201192021920319204192051920619207192081920919210192111921219213192141921519216192171921819219192201922119222192231922419225192261922719228192291923019231192321923319234192351923619237192381923919240192411924219243192441924519246192471924819249192501925119252192531925419255192561925719258192591926019261192621926319264192651926619267192681926919270192711927219273192741927519276192771927819279192801928119282192831928419285192861928719288192891929019291192921929319294192951929619297192981929919300193011930219303193041930519306193071930819309193101931119312193131931419315193161931719318193191932019321193221932319324193251932619327193281932919330193311933219333193341933519336193371933819339193401934119342193431934419345193461934719348193491935019351193521935319354193551935619357193581935919360193611936219363193641936519366193671936819369193701937119372193731937419375193761937719378193791938019381193821938319384193851938619387193881938919390193911939219393193941939519396193971939819399194001940119402194031940419405194061940719408194091941019411194121941319414194151941619417194181941919420194211942219423194241942519426194271942819429194301943119432194331943419435194361943719438194391944019441194421944319444194451944619447194481944919450194511945219453194541945519456194571945819459194601946119462194631946419465194661946719468194691947019471194721947319474194751947619477194781947919480194811948219483194841948519486194871948819489194901949119492194931949419495194961949719498194991950019501195021950319504195051950619507195081950919510195111951219513195141951519516195171951819519195201952119522195231952419525195261952719528195291953019531195321953319534195351953619537195381953919540195411954219543195441954519546195471954819549195501955119552195531955419555195561955719558195591956019561195621956319564195651956619567195681956919570195711957219573195741957519576195771957819579195801958119582195831958419585195861958719588195891959019591195921959319594195951959619597195981959919600196011960219603196041960519606196071960819609196101961119612196131961419615196161961719618196191962019621196221962319624196251962619627196281962919630196311963219633196341963519636196371963819639196401964119642196431964419645196461964719648196491965019651196521965319654196551965619657196581965919660196611966219663196641966519666196671966819669196701967119672196731967419675196761967719678196791968019681196821968319684196851968619687196881968919690196911969219693196941969519696196971969819699197001970119702197031970419705197061970719708197091971019711197121971319714197151971619717197181971919720197211972219723197241972519726197271972819729197301973119732197331973419735197361973719738197391974019741197421974319744197451974619747197481974919750197511975219753197541975519756197571975819759197601976119762197631976419765197661976719768197691977019771197721977319774197751977619777197781977919780197811978219783197841978519786197871978819789197901979119792197931979419795197961979719798197991980019801198021980319804198051980619807198081980919810198111981219813198141981519816198171981819819198201982119822198231982419825198261982719828198291983019831198321983319834198351983619837198381983919840198411984219843198441984519846198471984819849198501985119852198531985419855198561985719858198591986019861198621986319864198651986619867198681986919870198711987219873198741987519876198771987819879198801988119882198831988419885198861988719888198891989019891198921989319894198951989619897198981989919900199011990219903199041990519906199071990819909199101991119912199131991419915199161991719918199191992019921199221992319924199251992619927199281992919930199311993219933199341993519936199371993819939199401994119942199431994419945199461994719948199491995019951199521995319954199551995619957199581995919960199611996219963199641996519966199671996819969199701997119972199731997419975199761997719978199791998019981199821998319984199851998619987199881998919990199911999219993199941999519996199971999819999200002000120002200032000420005200062000720008200092001020011200122001320014200152001620017200182001920020200212002220023200242002520026200272002820029200302003120032200332003420035200362003720038200392004020041200422004320044200452004620047200482004920050200512005220053200542005520056200572005820059200602006120062200632006420065200662006720068200692007020071200722007320074200752007620077200782007920080200812008220083200842008520086200872008820089200902009120092200932009420095200962009720098200992010020101201022010320104201052010620107201082010920110201112011220113201142011520116201172011820119201202012120122201232012420125201262012720128201292013020131201322013320134201352013620137201382013920140201412014220143201442014520146201472014820149201502015120152201532015420155201562015720158201592016020161201622016320164201652016620167201682016920170201712017220173201742017520176201772017820179201802018120182201832018420185201862018720188201892019020191201922019320194201952019620197201982019920200202012020220203202042020520206202072020820209202102021120212202132021420215202162021720218202192022020221202222022320224202252022620227202282022920230202312023220233202342023520236202372023820239202402024120242202432024420245202462024720248202492025020251202522025320254202552025620257202582025920260202612026220263202642026520266202672026820269202702027120272202732027420275202762027720278202792028020281202822028320284202852028620287202882028920290202912029220293202942029520296202972029820299203002030120302203032030420305203062030720308203092031020311203122031320314203152031620317203182031920320203212032220323203242032520326203272032820329203302033120332203332033420335203362033720338203392034020341203422034320344203452034620347203482034920350203512035220353203542035520356203572035820359203602036120362203632036420365203662036720368203692037020371203722037320374203752037620377203782037920380203812038220383203842038520386203872038820389203902039120392203932039420395203962039720398203992040020401204022040320404204052040620407204082040920410204112041220413204142041520416204172041820419204202042120422204232042420425204262042720428204292043020431204322043320434204352043620437204382043920440204412044220443204442044520446204472044820449204502045120452204532045420455204562045720458204592046020461204622046320464204652046620467204682046920470204712047220473204742047520476204772047820479204802048120482204832048420485204862048720488204892049020491204922049320494204952049620497204982049920500205012050220503205042050520506205072050820509205102051120512205132051420515205162051720518205192052020521205222052320524205252052620527205282052920530205312053220533205342053520536205372053820539205402054120542205432054420545205462054720548205492055020551205522055320554205552055620557205582055920560205612056220563205642056520566205672056820569205702057120572205732057420575205762057720578205792058020581205822058320584205852058620587205882058920590205912059220593205942059520596205972059820599206002060120602206032060420605206062060720608206092061020611206122061320614206152061620617206182061920620206212062220623206242062520626206272062820629206302063120632206332063420635206362063720638206392064020641206422064320644206452064620647206482064920650206512065220653206542065520656206572065820659206602066120662206632066420665206662066720668206692067020671206722067320674206752067620677206782067920680206812068220683206842068520686206872068820689206902069120692206932069420695206962069720698206992070020701207022070320704207052070620707207082070920710207112071220713207142071520716207172071820719207202072120722207232072420725207262072720728207292073020731207322073320734207352073620737207382073920740207412074220743207442074520746207472074820749207502075120752207532075420755207562075720758207592076020761207622076320764207652076620767207682076920770207712077220773207742077520776207772077820779207802078120782207832078420785207862078720788207892079020791207922079320794207952079620797207982079920800208012080220803208042080520806208072080820809208102081120812208132081420815208162081720818208192082020821208222082320824208252082620827208282082920830208312083220833208342083520836208372083820839208402084120842208432084420845208462084720848208492085020851208522085320854208552085620857208582085920860208612086220863208642086520866208672086820869208702087120872208732087420875208762087720878208792088020881208822088320884208852088620887208882088920890208912089220893208942089520896208972089820899209002090120902209032090420905209062090720908209092091020911209122091320914209152091620917209182091920920209212092220923209242092520926209272092820929209302093120932209332093420935209362093720938209392094020941209422094320944209452094620947209482094920950209512095220953209542095520956209572095820959209602096120962209632096420965209662096720968209692097020971209722097320974209752097620977209782097920980209812098220983209842098520986209872098820989209902099120992209932099420995209962099720998209992100021001210022100321004210052100621007210082100921010210112101221013210142101521016210172101821019210202102121022210232102421025210262102721028210292103021031210322103321034210352103621037210382103921040210412104221043210442104521046210472104821049210502105121052210532105421055210562105721058210592106021061210622106321064210652106621067210682106921070210712107221073210742107521076210772107821079210802108121082210832108421085210862108721088210892109021091210922109321094210952109621097210982109921100211012110221103211042110521106211072110821109211102111121112211132111421115211162111721118211192112021121211222112321124211252112621127211282112921130211312113221133211342113521136211372113821139211402114121142211432114421145211462114721148211492115021151211522115321154211552115621157211582115921160211612116221163211642116521166211672116821169211702117121172211732117421175211762117721178211792118021181211822118321184211852118621187211882118921190211912119221193211942119521196211972119821199212002120121202212032120421205212062120721208212092121021211212122121321214212152121621217212182121921220212212122221223212242122521226212272122821229212302123121232212332123421235212362123721238212392124021241212422124321244212452124621247212482124921250212512125221253212542125521256212572125821259212602126121262212632126421265212662126721268212692127021271212722127321274212752127621277212782127921280212812128221283212842128521286212872128821289212902129121292212932129421295212962129721298212992130021301213022130321304213052130621307213082130921310213112131221313213142131521316213172131821319213202132121322213232132421325213262132721328213292133021331213322133321334213352133621337213382133921340
  1. #include "Module_OcppBackend.h"
  2. #include "define.h"
  3. //ChargePointMaxProfile
  4. #define ChargePointMaxProfile_JSON "/Storage/OCPP/ChargePointMaxProfile.json"
  5. //TxDefaultProfile
  6. #define TxDefaultProfile_0_JSON "/Storage/OCPP/TxDefaultProfile_0.json"
  7. struct SysConfigAndInfo *ShmSysConfigAndInfo;
  8. struct StatusCodeData *ShmStatusCodeData;
  9. struct PsuData *ShmPsuData ;
  10. struct OCPP16Data *ShmOCPP16Data;
  11. //ConfigurationMaxKeys
  12. #define GetConfigurationMaxKeysNUM _GetConfiguration_CNT
  13. pthread_mutex_t lock_send = PTHREAD_MUTEX_INITIALIZER;
  14. char queuedata[QUEUE_MESSAGE_LENGTH] = {0};
  15. //=================================
  16. // StatusNotification cycle
  17. //=================================
  18. static int server_cycle_Status = 120;
  19. //===============================
  20. // Configuration: unknown key
  21. //===============================
  22. static char unknownkey[10][36] = {0};
  23. static int UnknownKeynum = 0;
  24. //===============================
  25. // Gun Total Numbers
  26. //===============================
  27. static ParsingRatedCur modelnameInfo = {0};
  28. static int gunTotalNumber = 0;
  29. static uint8_t gunType[4] = {0};
  30. //===============================
  31. // Local List Version
  32. //===============================
  33. static int locallistVersion=0;
  34. static char idTagAuthorization[32] = {0};
  35. //===============================
  36. // OCPP sign variable
  37. //===============================
  38. static int server_sign = FALSE;
  39. int server_pending = FALSE;
  40. static int BootNotificationInterval = 0;
  41. static int SystemInitial = 0;//= CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY; // System Boot UP
  42. //===============================
  43. // OCPP auth variable
  44. //===============================
  45. static int authorizeRetryTimes = 0; //number of Retry times
  46. //===============================
  47. // OCPP other variables
  48. //===============================
  49. static int HeartBeatWaitTime = 10;
  50. static int FirstHeartBeat = 0;
  51. static int FirmwareStatusNotificationStatus = FIRMWARE_STATUS_IDLE; // Idle
  52. static int DiagnosticsStatusNotificationStatus = DIAGNOSTIC_STATUS_IDLE; // Idle
  53. static char CurrentChargingProfileScheduleStr[30] = {0};
  54. //========================================
  55. // OCPP status/previous related variables
  56. //========================================
  57. static int GunStatusInterval = 10;
  58. static uint8_t ChademoPreviousSystemStatus[(CHAdeMO_QUANTITY>0?CHAdeMO_QUANTITY:1)];
  59. static uint8_t CcsPreviousSystemStatus[(CCS_QUANTITY>0?CCS_QUANTITY:1)];
  60. static uint8_t GbPreviousSystemStatus[(GB_QUANTITY>0?GB_QUANTITY:1)];
  61. static uint8_t AcPreviousSystemStatus[(AC_QUANTITY>0?AC_QUANTITY:1)];
  62. static uint8_t DoPreviousSystemStatus[(CONNECTOR_QUANTITY>0?CONNECTOR_QUANTITY:1)];
  63. static uint8_t ChademoPreviousConnectorPlugIn[(CHAdeMO_QUANTITY>0?CHAdeMO_QUANTITY:1)];
  64. static uint8_t CcsPreviousConnectorPlugIn[(CCS_QUANTITY>0?CCS_QUANTITY:1)];
  65. static uint8_t GbPreviousConnectorPlugIn[(GB_QUANTITY>0?GB_QUANTITY:1)];
  66. static uint8_t AcPreviousConnectorPlugIn[(AC_QUANTITY>0?AC_QUANTITY:1)];
  67. static uint8_t DoPreviousConnectorPlugIn[(CONNECTOR_QUANTITY>0?CONNECTOR_QUANTITY:1)];
  68. static int TransactionMessageAttemptsValue = 0;
  69. static int TransactionMessageRetryIntervalValue = 0;
  70. static int TempMeterValueInterval = 0;
  71. static struct OCPPAuthLocalElemet
  72. {
  73. int listVersionInt;
  74. char idTagstr[21];
  75. char parentIdTag[21];
  76. char expiryDate[36];
  77. char idTagstatus[16];
  78. }idTagQuery;
  79. //============================================
  80. // OCPP MeterValue request flag
  81. //============================================
  82. uint8_t reqSampleMeter[CONNECTOR_QUANTITY]={0};
  83. uint8_t reqClockAlignMeter[CONNECTOR_QUANTITY]={0};
  84. //=============================================
  85. // OCPP HeartBeat Response Not Receive Counts
  86. //============================================
  87. static int HeartBeatWithNOResponse = 0;
  88. extern sqlite3 *db;
  89. int TransactionMessageAttemptsGet(void);
  90. int TransactionMessageRetryIntervalGet(void);
  91. int GetOcppConnStatus(void);
  92. void SetOcppConnStatus(uint8_t status);
  93. int setKeyValue(char *key, char *value);
  94. void OCPP_get_TableAuthlocalAllData(void);
  95. void processUnkownKey(void);
  96. struct InterLock
  97. {
  98. unsigned char isGetDiagnosticGoing:1;
  99. unsigned char isUpdateFirmwareGoing:1;
  100. }interLock;
  101. struct ClientTime
  102. {
  103. struct timespec Heartbeat;
  104. struct timespec StatusNotification[CONNECTOR_QUANTITY];
  105. struct timespec StartTransaction;
  106. struct timespec StopTransaction;
  107. struct timespec MeterValues[CONNECTOR_QUANTITY];
  108. struct timespec RemoteStartWait;
  109. struct timespec YesCustomCallReader;
  110. }clientTime;
  111. typedef union
  112. {
  113. //Operations Initiated by Central System
  114. unsigned char CsMsgValue[CONNECTOR_QUANTITY];
  115. struct
  116. {
  117. //CsMsgValue[0]
  118. unsigned char StatusNotificationReq:1; //bit 0,
  119. unsigned char StatusNotificationConf:1; //bit 1,
  120. unsigned char TriggerMeterValue:1; //bit 2,
  121. unsigned char TriggerStatusNotificationReq:1; //bit 3,
  122. unsigned char isOnCharging:1; //bit 4,
  123. unsigned char :3; //bit5~7
  124. }bits[CONNECTOR_QUANTITY];
  125. }CpinitiateMsg;
  126. CpinitiateMsg cpinitateMsg;
  127. //GetConfiguration Array
  128. struct StructConfigurationKeyItems staticKeyArray[GetConfigurationMaxKeysNUM]={0};
  129. struct StructConfigurationKey staticResponseConfigurationKeyArray[GetConfigurationMaxKeysNUM]={0};
  130. struct StructConfigurationKeyItems staticResponseUnknownKey[10]={0};
  131. struct StructLocalAuthorizationList staticLocalAuthorizationList[1]={0};
  132. #if 0
  133. static char *ChargePointErrorCodeStr[] = {
  134. MACROSTR(ConnectorLockFailure),
  135. MACROSTR(EVCommunicationError),
  136. MACROSTR(GroundFailure),
  137. MACROSTR(HighTemperature),
  138. MACROSTR(InternalError),
  139. MACROSTR(LocalListConflict),
  140. MACROSTR(NoError),
  141. MACROSTR(OtherError),
  142. MACROSTR(OverCurrentFailure),
  143. MACROSTR(OverVoltage),
  144. MACROSTR(PowerMeterFailure),
  145. MACROSTR(PowerSwitchFailure),
  146. MACROSTR(ReaderFailure),
  147. MACROSTR(ResetFailure),
  148. MACROSTR(UnderVoltage),
  149. MACROSTR(WeakSignal)
  150. };
  151. #endif
  152. static char * ChargePointStatusStr[] = {
  153. MACROSTR(Available),
  154. MACROSTR(Preparing),
  155. MACROSTR(Charging),
  156. MACROSTR(SuspendedEVSE),
  157. MACROSTR(SuspendedEV),
  158. MACROSTR(Finishing),
  159. MACROSTR(Reserved),
  160. MACROSTR(Unavailable),
  161. MACROSTR(Faulted)
  162. };
  163. static char *RegistrationStatusStr[] = {
  164. MACROSTR(Accepted),
  165. MACROSTR(Pending),
  166. MACROSTR(Rejected)
  167. };
  168. static char *AvailabilityTypeStr[] = {
  169. MACROSTR(Inoperative),
  170. MACROSTR(Operative)
  171. };
  172. static char *AvailabilityStatusStr[] = {
  173. MACROSTR(Accepted),
  174. MACROSTR(Rejected),
  175. MACROSTR(Scheduled)
  176. };
  177. static char *ConfigurationStatusStr[] = {
  178. MACROSTR(Accepted),
  179. MACROSTR(Rejected),
  180. MACROSTR(RebootRequired),
  181. MACROSTR(NotSupported)
  182. };
  183. static char *ClearCacheStatusStr[] = {
  184. MACROSTR(Accepted),
  185. MACROSTR(Rejected)
  186. };
  187. static char *ChargingProfilePurposeTypeStr[] = {
  188. MACROSTR(ChargePointMaxProfile),
  189. MACROSTR(TxDefaultProfile),
  190. MACROSTR(TxProfile)
  191. };
  192. static char *ChargingProfileStatusStr[] = {
  193. MACROSTR(Accepted),
  194. MACROSTR(Rejected),
  195. MACROSTR(NotSupported)
  196. };
  197. static char *ClearChargingProfileStatusStr[] = {
  198. MACROSTR(Accepted),
  199. MACROSTR(Unknown)
  200. };
  201. static char *GetCompositeScheduleStatusStr[] = {
  202. MACROSTR(Accepted),
  203. MACROSTR(Rejected)
  204. };
  205. static char *UpdateTypeStr[] = {
  206. MACROSTR(Differential),
  207. MACROSTR(Full)
  208. };
  209. static char *UpdateStatusStr[] = {
  210. MACROSTR(Accepted),
  211. MACROSTR(Failed),
  212. MACROSTR(NotSupported),
  213. MACROSTR(VersionMismatch)
  214. };
  215. static char *RemoteStartStopStatusStr[] = {
  216. MACROSTR(Accepted),
  217. MACROSTR(Rejected)
  218. };
  219. static char *ReservationStatusStr[] = {
  220. MACROSTR(Accepted),
  221. MACROSTR(Faulted),
  222. MACROSTR(Occupied),
  223. MACROSTR(Rejected),
  224. MACROSTR(Unavailable)
  225. };
  226. static char *ResetTypeStr[] = {
  227. MACROSTR(Hard),
  228. MACROSTR(Soft)
  229. };
  230. static char *ResetStatusStr[] = {
  231. MACROSTR(Accepted),
  232. MACROSTR(Rejected)
  233. };
  234. static char * DiagnosticsStatusStr[] = {
  235. MACROSTR(Idle),
  236. MACROSTR(Uploaded),
  237. MACROSTR(UploadFailed),
  238. MACROSTR(Uploading)
  239. };
  240. static char * FirmwareStatusStr[] = {
  241. MACROSTR(Downloaded),
  242. MACROSTR(DownloadFailed),
  243. MACROSTR(Downloading),
  244. MACROSTR(Idle),
  245. MACROSTR(InstallationFailed),
  246. MACROSTR(Installing),
  247. MACROSTR(Installed)
  248. };
  249. static char * MessageTriggerStr[] = {
  250. MACROSTR(BootNotification),
  251. MACROSTR(DiagnosticsStatusNotification),
  252. MACROSTR(FirmwareStatusNotification),
  253. MACROSTR(Heartbeat),
  254. MACROSTR(MeterValues),
  255. MACROSTR(StatusNotification)
  256. };
  257. static char * TriggerMessageStatusStr[] = {
  258. MACROSTR(Accepted),
  259. MACROSTR(Rejected),
  260. MACROSTR(NotImplemented)
  261. };
  262. static char * UnlockStatusStr[] = {
  263. MACROSTR(Unlocked),
  264. MACROSTR(UnlockFailed),
  265. MACROSTR(NotSupported)
  266. };
  267. #if 0
  268. static char * StopTransactionReasonStr[] = {
  269. MACROSTR(EmergencyStop),
  270. MACROSTR(EVDisconnected),
  271. MACROSTR(HardReset),
  272. MACROSTR(Local),
  273. MACROSTR(Other),
  274. MACROSTR(PowerLoss),
  275. MACROSTR(Reboot),
  276. MACROSTR(Remote),
  277. MACROSTR(SoftReset),
  278. MACROSTR(UnlockCommand),
  279. MACROSTR(DeAuthorized)
  280. };
  281. #endif
  282. static char * CancelReservationStatusStr[] = {
  283. MACROSTR(Accepted),
  284. MACROSTR(Rejected)
  285. };
  286. static char * ReadingContextStr[] = {
  287. MACROSTR(Interruption.Begin),
  288. MACROSTR(Interruption.End),
  289. MACROSTR(Other),
  290. MACROSTR(Sample.Clock),
  291. MACROSTR(Sample.Periodic),
  292. MACROSTR(Transaction.Begin),
  293. MACROSTR(Transaction.End),
  294. MACROSTR(Trigger)
  295. };
  296. static char * ValueFormatStr[] = {
  297. MACROSTR(Raw),
  298. MACROSTR(SignedData)
  299. };
  300. static char * MeasurandStr[] = {
  301. MACROSTR(Current.Export),
  302. MACROSTR(Current.Import),
  303. MACROSTR(Current.Offered),
  304. MACROSTR(Energy.Active.Export.Register),
  305. MACROSTR(Energy.Active.Import.Register),
  306. MACROSTR(Energy.Reactive.Export.Register),
  307. MACROSTR(Energy.Reactive.Import.Register),
  308. MACROSTR(Energy.Active.Export.Interval),
  309. MACROSTR(Energy.Active.Import.Interval),
  310. MACROSTR(Energy.Reactive.Export.Interval),
  311. MACROSTR(Energy.Reactive.Import.Interval),
  312. MACROSTR(Frequency),
  313. MACROSTR(Power.Active.Export),
  314. MACROSTR(Power.Active.Import),
  315. MACROSTR(Power.Factor),
  316. MACROSTR(Power.Offered),
  317. MACROSTR(Power.Reactive.ExportMACROSTR),
  318. MACROSTR(Power.Reactive.Import),
  319. MACROSTR(RPM),
  320. MACROSTR(SoC),
  321. MACROSTR(Temperature),
  322. MACROSTR(Voltage)
  323. };
  324. static char * LocationStr[] = {
  325. MACROSTR(Body),
  326. MACROSTR(Cable),
  327. MACROSTR(EV),
  328. MACROSTR(Inlet),
  329. MACROSTR(Outlet)
  330. };
  331. static char * PhaseStr[] = {
  332. MACROSTR(L1),
  333. MACROSTR(L2),
  334. MACROSTR(L3),
  335. MACROSTR(N),
  336. MACROSTR(L1-N),
  337. MACROSTR(L2-N),
  338. MACROSTR(L3-N),
  339. MACROSTR(L1-L2),
  340. MACROSTR(L2-L3),
  341. MACROSTR(L3-L1)
  342. };
  343. static char * UnitOfMeasureStr[] = {
  344. MACROSTR(Wh),
  345. MACROSTR(kWh),
  346. MACROSTR(varh),
  347. MACROSTR(kvarh),
  348. MACROSTR(W),
  349. MACROSTR(kW),
  350. MACROSTR(VA),
  351. MACROSTR(kVA),
  352. MACROSTR(var),
  353. MACROSTR(kvar),
  354. MACROSTR(A),
  355. MACROSTR(V),
  356. MACROSTR(Celsius),
  357. MACROSTR(Fahrenheit),
  358. MACROSTR(K),
  359. MACROSTR(Percent)
  360. };
  361. //=========================================
  362. // TTIA routine
  363. //=========================================
  364. int sendTTIAInfo(uint8_t gun_index)
  365. {
  366. static int sn = 0;
  367. int result = FAIL;
  368. struct hostent *server;
  369. int udp_socket_fd;
  370. struct sockaddr_in dest_addr = {0};
  371. uint8_t tx_buf[80] = {0};
  372. uint8_t logBuf[256]= {0};
  373. uint8_t tx_len, tempIndex, socStart, socEnd;
  374. uint16_t PresentChargedEnergy;
  375. struct tm tmStart, tmEnd;
  376. DEBUG_INFO("sendTTIAInfo...\n");
  377. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  378. {
  379. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  380. {
  381. tempIndex = ((gun_index==2) ? 1: 0);
  382. }
  383. else
  384. {
  385. tempIndex = gun_index;
  386. }
  387. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  388. {
  389. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  390. {
  391. socStart = ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].EvBatteryStartSoc;
  392. socEnd = ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].EvBatterySoc;
  393. PresentChargedEnergy = (uint16_t)(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargedEnergy*10);
  394. }
  395. }
  396. }
  397. else if(gunType[gun_index] == GUN_TYPE_CCS)
  398. {
  399. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  400. {
  401. tempIndex = ((gun_index==2) ? 1: 0);
  402. }
  403. else
  404. {
  405. tempIndex = gun_index;
  406. }
  407. for (int index = 0; index < CCS_QUANTITY; index++)
  408. {
  409. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  410. {
  411. socStart = ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].EvBatteryStartSoc;
  412. socEnd = ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].EvBatterySoc;
  413. PresentChargedEnergy = (uint16_t)(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargedEnergy*10);
  414. }
  415. }
  416. }
  417. else if(gunType[gun_index] == GUN_TYPE_GBT)
  418. {
  419. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  420. {
  421. tempIndex = ((gun_index==2) ? 1: 0);
  422. }
  423. else
  424. {
  425. tempIndex = gun_index;
  426. }
  427. for (int index = 0; index < GB_QUANTITY; index++)
  428. {
  429. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  430. {
  431. socStart = ShmSysConfigAndInfo->SysInfo.GbChargingData[index].EvBatteryStartSoc;
  432. socEnd = ShmSysConfigAndInfo->SysInfo.GbChargingData[index].EvBatterySoc;
  433. PresentChargedEnergy = (uint16_t)(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargedEnergy*10);
  434. }
  435. }
  436. }
  437. else if(gunType[gun_index] == GUN_TYPE_DO)
  438. {
  439. tempIndex = gun_index;
  440. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  441. {
  442. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  443. {
  444. socStart = ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.EvBatteryStartSoc;
  445. socEnd = ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.EvBatterySoc;
  446. PresentChargedEnergy = (uint16_t)(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PresentChargedEnergy*10);
  447. }
  448. }
  449. }
  450. else
  451. {
  452. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  453. {
  454. tempIndex = 2;
  455. }
  456. else
  457. {
  458. tempIndex = gun_index;
  459. }
  460. for (int index = 0; index < AC_QUANTITY; index++)
  461. {
  462. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  463. {
  464. socStart = ShmSysConfigAndInfo->SysInfo.AcChargingData[index].EvBatteryStartSoc;
  465. socEnd = ShmSysConfigAndInfo->SysInfo.AcChargingData[index].EvBatterySoc;
  466. PresentChargedEnergy = (uint16_t)(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargedEnergy*10);
  467. }
  468. }// END
  469. }
  470. // Message assembly
  471. sprintf((char*)&tx_buf[0], "APTS"); // Protocol ID
  472. tx_buf[4] = 0x02; // Protocol Version
  473. tx_buf[5] = 0xb0; // Message ID
  474. tx_buf[6] = ShmSysConfigAndInfo->SysConfig.TTIA_Info.busVenderId & 0xff; // CustomerID low byte
  475. tx_buf[7] = (ShmSysConfigAndInfo->SysConfig.TTIA_Info.busVenderId>>8) & 0xff; // CustomerID high byte
  476. tx_buf[8] = 0x00; // CarID low byte
  477. tx_buf[9] = 0x00; // CarID high byte
  478. tx_buf[10] = 0x00; // ID Storage
  479. tx_buf[11] = 0x00; // Driver lowest byte
  480. tx_buf[12] = 0x00; // Driver 2nd byte
  481. tx_buf[13] = 0x00; // Driver 3rd byte
  482. tx_buf[14] = 0x00; // Driver highest byte
  483. tx_buf[15] = sn & 0xff; // Sequence SN low byte
  484. tx_buf[16] = (sn>>8) & 0xff; // Sequence SN high byte
  485. tx_buf[17] = 0x00; // Reserve
  486. tx_buf[18] = 60 & 0xff; // Payload length low byte
  487. tx_buf[19] = (60>>8) & 0xff; // Payload length high byte
  488. // EVSE provider
  489. memcpy((char*)&tx_buf[20], ShmSysConfigAndInfo->SysConfig.TTIA_Info.EquipmentProvider, 15);
  490. // EVSE provider
  491. tx_buf[35] = ShmSysConfigAndInfo->SysConfig.TTIA_Info.TransportationCompanyNo;
  492. // EVSE id
  493. tx_buf[36] = ShmSysConfigAndInfo->SysConfig.TTIA_Info.ChargeBoxId;
  494. // Connector id
  495. tx_buf[37] = gun_index;
  496. // EVSE station
  497. memcpy((char*)&tx_buf[38], ShmSysConfigAndInfo->SysConfig.TTIA_Info.evseStation, 15);
  498. // Vehicle SN
  499. memcpy(&tx_buf[53], &ShmOCPP16Data->StartTransaction[gun_index].IdTag, 8);
  500. // Mileage
  501. tx_buf[61] = 0x00; // lowest byte
  502. tx_buf[62] = 0x00; // 2nd byte
  503. tx_buf[63] = 0x00; // highest byte
  504. // Start date time 6 bytes
  505. 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))
  506. {
  507. struct tm *tmTarget;
  508. struct timeb tbTarget;
  509. tmStart.tm_year -= 1900;
  510. tmStart.tm_mon -= 1;
  511. tmStart.tm_gmtoff = 0;
  512. tbTarget.time = mktime(&tmStart);
  513. tbTarget.timezone = 0;
  514. tbTarget.time += (8*3600);
  515. tmTarget = gmtime(&tbTarget.time);
  516. tx_buf[64] = ((tmTarget->tm_year+1900)-2000);
  517. tx_buf[65] = (tmTarget->tm_mon+1);
  518. tx_buf[66] = tmTarget->tm_mday;
  519. tx_buf[67] = tmTarget->tm_hour;
  520. tx_buf[68] = tmTarget->tm_min;
  521. tx_buf[69] = tmTarget->tm_sec;
  522. }
  523. // Stop date time 6 bytes
  524. 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))
  525. {
  526. struct tm *tmTarget;
  527. struct timeb tbTarget;
  528. tmEnd.tm_year -= 1900;
  529. tmEnd.tm_mon -= 1;
  530. tmEnd.tm_gmtoff = 0;
  531. tbTarget.time = mktime(&tmEnd);
  532. tbTarget.timezone = 0;
  533. tbTarget.time += (8*3600);
  534. tmTarget = gmtime(&tbTarget.time);
  535. tx_buf[70] = ((tmTarget->tm_year+1900)-2000);
  536. tx_buf[71] = (tmTarget->tm_mon+1);
  537. tx_buf[72] = tmTarget->tm_mday;
  538. tx_buf[73] = tmTarget->tm_hour;
  539. tx_buf[74] = tmTarget->tm_min;
  540. tx_buf[75] = tmTarget->tm_sec;
  541. }
  542. // Session energy 2 bytes
  543. tx_buf[76] = PresentChargedEnergy & 0xff;
  544. tx_buf[77] = (PresentChargedEnergy>>8) & 0xff;
  545. // Start SOC 1 byte
  546. tx_buf[78] = socStart;
  547. // Stop SOC 1 byte
  548. tx_buf[79] = socEnd;
  549. // Open socket
  550. udp_socket_fd = socket(AF_INET, SOCK_DGRAM, 0);
  551. if(udp_socket_fd == -1)
  552. {
  553. DEBUG_ERROR("UDP socket create failed!\n");
  554. }
  555. else
  556. {
  557. // Get server DNS entry
  558. server = gethostbyname((char*)ShmSysConfigAndInfo->SysConfig.TTIA_Info.server_addr);
  559. if (server == NULL)
  560. {
  561. DEBUG_ERROR("ERROR, no such host as %s\n", ShmSysConfigAndInfo->SysConfig.TTIA_Info.server_addr);
  562. }
  563. else
  564. {
  565. // Build the server's Internet address
  566. bzero((char *) &dest_addr, sizeof(dest_addr));
  567. dest_addr.sin_family = AF_INET;
  568. bcopy((char *)server->h_addr, (char *)&dest_addr.sin_addr.s_addr, server->h_length);
  569. dest_addr.sin_port = htons(ShmSysConfigAndInfo->SysConfig.TTIA_Info.server_port);
  570. if((tx_len = sendto(udp_socket_fd, tx_buf, ARRAY_SIZE(tx_buf), 0, &dest_addr, sizeof(dest_addr))) >= 0)
  571. {
  572. for(uint8_t idx=0;idx<ARRAY_SIZE(tx_buf);idx++)
  573. {
  574. sprintf((char*)logBuf, "%s %02X", logBuf, tx_buf[idx]);
  575. }
  576. DEBUG_TTIA_INFO("TX raw data length: %d\n", tx_len);
  577. DEBUG_TTIA_INFO("Message raw: %s\n", logBuf);
  578. DEBUG_TTIA_INFO("OCPP Transaction ID: %d\n", ShmOCPP16Data->StopTransaction[gun_index].TransactionId);
  579. DEBUG_TTIA_INFO("TTIA server address: %s\n", ShmSysConfigAndInfo->SysConfig.TTIA_Info.server_addr);
  580. DEBUG_TTIA_INFO("TTIA server port: %d\n", ShmSysConfigAndInfo->SysConfig.TTIA_Info.server_port);
  581. DEBUG_TTIA_INFO("---------- Header ----------\n");
  582. DEBUG_TTIA_INFO("ProtocolID: APTS\n");
  583. DEBUG_TTIA_INFO("ProtocolVer: 0x02\n");
  584. DEBUG_TTIA_INFO("MessageID: 0xB0\n");
  585. DEBUG_TTIA_INFO("CustomerID: 0x%04X\n", ShmSysConfigAndInfo->SysConfig.TTIA_Info.busVenderId);
  586. DEBUG_TTIA_INFO("CarID: 0x0000\n");
  587. DEBUG_TTIA_INFO("IDStorage: 0x00\n");
  588. DEBUG_TTIA_INFO("DriverID: 0x00000000\n");
  589. DEBUG_TTIA_INFO("Sequence: %d\n", sn);
  590. DEBUG_TTIA_INFO("Reserved: 0x00\n");
  591. DEBUG_TTIA_INFO("Len: 0x3C\n");
  592. DEBUG_TTIA_INFO("--------- Payload ---------\n");
  593. DEBUG_TTIA_INFO("EquipmentProvider: %s\n", ShmSysConfigAndInfo->SysConfig.TTIA_Info.EquipmentProvider);
  594. DEBUG_TTIA_INFO("TransportationCompanyNo: %d\n", ShmSysConfigAndInfo->SysConfig.TTIA_Info.TransportationCompanyNo);
  595. DEBUG_TTIA_INFO("ChargeBoxId: %d\n", ShmSysConfigAndInfo->SysConfig.TTIA_Info.ChargeBoxId);
  596. DEBUG_TTIA_INFO("Gun index: %d\n", gun_index);
  597. DEBUG_TTIA_INFO("evseStation: %s\n", ShmSysConfigAndInfo->SysConfig.TTIA_Info.evseStation);
  598. DEBUG_TTIA_INFO("EV vehicle: %s\n", ShmOCPP16Data->StartTransaction[gun_index].IdTag);
  599. DEBUG_TTIA_INFO("EV mileage: 000000\n");
  600. DEBUG_TTIA_INFO("Session start data time: %s\n", ShmOCPP16Data->StartTransaction[gun_index].Timestamp);
  601. DEBUG_TTIA_INFO("Session stop data time: %s\n", ShmOCPP16Data->StopTransaction[gun_index].Timestamp);
  602. DEBUG_TTIA_INFO("Session charged energy (kwh): %f\n", (PresentChargedEnergy/10.0));
  603. DEBUG_TTIA_INFO("Session start SOC: %d\n", socStart);
  604. DEBUG_TTIA_INFO("Session end SOC: %d\n", socEnd);
  605. DEBUG_TTIA_INFO("=========================================\n");
  606. sn++;
  607. result = PASS;
  608. }
  609. else
  610. {
  611. DEBUG_ERROR("UDP sent out fail.\n");
  612. }
  613. }
  614. }
  615. return result;
  616. }
  617. //=========================================
  618. // Save configuration
  619. //=========================================
  620. int runShellCmd(const char*cmd)
  621. {
  622. int result = FAIL;
  623. char buf[256];
  624. FILE *fp;
  625. fp = popen(cmd, "r");
  626. if(fp != NULL)
  627. {
  628. while(fgets(buf, sizeof(buf), fp) != NULL)
  629. {
  630. DEBUG_INFO("%s\n", buf);
  631. }
  632. result = PASS;
  633. }
  634. pclose(fp);
  635. return result;
  636. }
  637. int StoreUsrConfigData(struct SysConfigData *UsrData)
  638. {
  639. int result = PASS;
  640. int fd,wrd;
  641. unsigned int i,Chk;
  642. unsigned char *ptr, *BufTmp;
  643. int MtdBlockSize = 0x300000;
  644. Chk=0;
  645. ptr=(unsigned char *)UsrData;
  646. if((BufTmp=malloc(MtdBlockSize))!=NULL)
  647. {
  648. memset(BufTmp,0,MtdBlockSize);
  649. memcpy(BufTmp,ptr,sizeof(struct SysConfigData));
  650. for(i=ARRAY_SIZE(UsrData->CsuBootLoadFwRev);i<MtdBlockSize-4;i++)
  651. Chk+=*(BufTmp+i);
  652. memcpy(BufTmp+MtdBlockSize-4, &Chk, 4);
  653. // Output configuration to file.
  654. fd = open("/mnt/EvseConfig.bin", O_RDWR|O_CREAT);
  655. if (fd < 0)
  656. {
  657. DEBUG_ERROR("open /mnt/EvseConfig.bin NG\n");
  658. free(BufTmp);
  659. return 0;
  660. }
  661. wrd=write(fd, BufTmp, MtdBlockSize);
  662. close(fd);
  663. if(wrd<MtdBlockSize)
  664. {
  665. DEBUG_ERROR("write /mnt/EvseConfig.bin NG\n");
  666. free(BufTmp);
  667. return 0;
  668. }
  669. DEBUG_INFO("EvseConfig write to file in /mnt OK.\n");
  670. DEBUG_INFO("Erase /dev/mtd10.\n");
  671. runShellCmd("flash_erase /dev/mtd10 0 0");
  672. DEBUG_INFO("Write /dev/mtd10.\n");
  673. runShellCmd("nandwrite -p /dev/mtd10 /mnt/EvseConfig.bin");
  674. DEBUG_INFO("Erase /dev/mtd11.\n");
  675. runShellCmd("flash_erase /dev/mtd11 0 0");
  676. DEBUG_INFO("Write /dev/mtd11.\n");
  677. runShellCmd("nandwrite -p /dev/mtd11 /mnt/EvseConfig.bin");
  678. system("rm -f /mnt/EvseConfig.bin");
  679. DEBUG_INFO("EvseConfig write to flash OK\n");
  680. }
  681. else
  682. {
  683. DEBUG_ERROR("alloc BlockSize NG\r\n");
  684. result = FAIL;
  685. }
  686. if(BufTmp!=NULL)
  687. free(BufTmp);
  688. return result;
  689. }
  690. //=========================================
  691. // Sqlite3 related function
  692. //=========================================
  693. static int selectSqlCount = 0;
  694. static int callback(void *data, int argc, char **argv, char **azColName){
  695. int i;
  696. //printf("%s: ", (const char*)data);
  697. selectSqlCount = argc;
  698. for(i = 0; i<argc; i++){
  699. // printf("%s = %s\n", azColName[i], argv[i] ? argv[i] : "NULL");
  700. }
  701. //printf("\n");
  702. return 0;
  703. }
  704. static int versioncallback(void *data, int argc, char **argv, char **azColName){
  705. //int i;
  706. //printf("%s:\n", (const char*)data);
  707. locallistVersion = (argv[5] ? atoi(argv[5]) : 0);
  708. DEBUG_INFO("Callback query locallistVersion : %d\n", locallistVersion);
  709. return 0;
  710. }
  711. static int IdTagcallback(void *data, int columenCount, char **columnValue, char **columnName){
  712. //printf("%s:\n", (const char*)data);
  713. //idTag
  714. sprintf(idTagAuthorization,"%s", columnValue[1] ? columnValue[1] : "NULL");
  715. sprintf(idTagQuery.idTagstr,"%s", columnValue[1] ? columnValue[1] : "NULL");
  716. //parentIdTag
  717. sprintf(idTagQuery.parentIdTag,"%s", columnValue[2] ? columnValue[2] : "NULL");
  718. //expir_date
  719. sprintf(idTagQuery.expiryDate,"%s", columnValue[3] ? columnValue[3] : "NULL");
  720. //status
  721. sprintf(idTagQuery.idTagstatus,"%s", columnValue[4] ? columnValue[4] : "NULL");
  722. //version
  723. if(columenCount > 5)
  724. idTagQuery.listVersionInt = atoi(columnValue[5]);
  725. //DEBUG_INFO("IdTag=%s\n", idTagAuthorization);
  726. return 0;
  727. }
  728. static int deleteIdTagcallback(void *data, int argc, char **argv, char **azColName)
  729. {
  730. // localversion = argv[5] ? atoi(argv[5]) : 0;
  731. // printf("localversion=%d\n", localversion);
  732. return 0;
  733. }
  734. int sqlite3_exec_callback(void *data, int n_columns, char **col_values, char **col_names)
  735. {
  736. for (int i = 0; i < n_columns; i++)
  737. {
  738. DEBUG_INFO("%s\t", col_values[i]);
  739. }
  740. DEBUG_INFO("\n");
  741. return 0;
  742. }
  743. int OCPP_cleanLocalCache()
  744. {
  745. char * sqlcleanLocalList = "delete from ocpp_auth_cache";
  746. char *errMsg = 0;
  747. int rc =sqlite3_exec(db, sqlcleanLocalList, 0, 0, &errMsg);
  748. if (SQLITE_OK != rc)
  749. {
  750. DEBUG_INFO("SQL error: %s\n",errMsg);
  751. return FALSE;
  752. }
  753. return TRUE;
  754. }
  755. int OCPP_addLocalCache(char *idTag, char *parentTage, char *expiryDate, char *status)
  756. {
  757. int isSuccess = TRUE;
  758. int ret = 0;
  759. //const char* data = "Callback function called";
  760. char sql[300];
  761. char zErrMsg[200];
  762. memset(sql, 0, 300);
  763. memset(zErrMsg, 0, 200);
  764. 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);
  765. //* Execute SQL statement */
  766. ret = sqlite3_exec(db, sql, callback, 0, (char **)&zErrMsg);
  767. if( ret != SQLITE_OK )
  768. {
  769. DEBUG_INFO("SQL error: %s\n", zErrMsg);
  770. isSuccess = FALSE;
  771. }
  772. return isSuccess;
  773. }
  774. void OCPP_getIdTagFromLocalCache(char idTag[])
  775. {
  776. int rc = 0;
  777. char sql[100];
  778. char zErrMsg[100];
  779. memset(sql, 0, 100);
  780. memset(zErrMsg, 0, 100);
  781. memset(idTagAuthorization, 0, ARRAY_SIZE(idTagAuthorization));
  782. memset(&idTagQuery, 0, sizeof(idTagQuery));
  783. sprintf(sql,"select * from ocpp_auth_cache where idtag='%s'", idTag);
  784. /* Execute SQL statement */
  785. rc = sqlite3_exec(db, sql, IdTagcallback, 0, (char **)&zErrMsg);
  786. if( rc != SQLITE_OK )
  787. {
  788. DEBUG_INFO("SQL error: %s\n", zErrMsg);
  789. }
  790. }
  791. void OCPP_getListVerion()
  792. {
  793. int rc = 0;
  794. // const char* data = "Callback function called";
  795. char sql[100];
  796. char zErrMsg[100];
  797. memset(sql, 0, 100);
  798. memset(zErrMsg, 0, 100);
  799. strcpy(sql, "select * from ocpp_auth_local order by version desc, idx desc limit 1");
  800. /* Execute SQL statement */
  801. rc = sqlite3_exec(db, sql, versioncallback, 0, (char **)&zErrMsg);
  802. if( rc != SQLITE_OK )
  803. {
  804. DEBUG_INFO("SQL error: %s\n", zErrMsg);
  805. }
  806. }
  807. void OCPP_get_TableAuthlocalAllData(void)
  808. {
  809. int rc = 0;
  810. char sql[100];
  811. char zErrMsg[100];
  812. memset(sql, 0, 100);
  813. memset(zErrMsg, 0, 100);
  814. sprintf(sql,"select * from ocpp_auth_local ");
  815. /* Execute SQL statement */
  816. rc = sqlite3_exec(db, sql, &sqlite3_exec_callback, 0,(char **)&zErrMsg);
  817. if( rc != SQLITE_OK )
  818. {
  819. DEBUG_INFO("SQL error: %s\n", zErrMsg);
  820. }
  821. //return ver;
  822. }
  823. int OCPP_cleanLocalList()
  824. {
  825. char * sqlcleanLocalList = "delete from ocpp_auth_local";
  826. char *errMsg = 0;
  827. int rc =sqlite3_exec(db, sqlcleanLocalList, 0, 0, &errMsg);
  828. if (SQLITE_OK != rc)
  829. {
  830. DEBUG_INFO("%s\n",errMsg);
  831. return FALSE;
  832. }
  833. return TRUE;
  834. }
  835. int OCPP_addLocalList(int version, char *idTag, char *parentTage, char *expiryDate, char *status)
  836. {
  837. int isSuccess = FALSE;
  838. int ret = 0;
  839. //const char* data = "Callback function called";
  840. char sql[300];
  841. char zErrMsg[200];
  842. memset(sql, 0, 300);
  843. memset(zErrMsg, 0, 200);
  844. 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);
  845. //* Execute SQL statement */
  846. ret = sqlite3_exec(db, sql, callback, 0, (char **)&zErrMsg);
  847. if( ret != SQLITE_OK )
  848. {
  849. DEBUG_INFO("SQL error: %s\n", zErrMsg);
  850. return isSuccess;
  851. }
  852. memset(sql, 0, 300);
  853. sprintf(sql, "UPDATE ocpp_auth_local SET version=%d",version);
  854. ret = sqlite3_exec(db, sql, NULL, NULL, (char **)&zErrMsg);
  855. if( ret != SQLITE_OK )
  856. {
  857. DEBUG_INFO("SQL error: %s\n", zErrMsg);
  858. return isSuccess;
  859. }
  860. isSuccess = TRUE;
  861. return isSuccess;
  862. }
  863. void OCPP_getIdTagFromLocalList(char idTag[])
  864. {
  865. int rc = 0;
  866. // const char* data = "Callback function called";
  867. char sql[100];
  868. char zErrMsg[100];
  869. memset(sql, 0, 100);
  870. memset(zErrMsg, 0, 100);
  871. memset(idTagAuthorization, 0, ARRAY_SIZE(idTagAuthorization));
  872. memset(&idTagQuery, 0, sizeof(idTagQuery));
  873. //DEBUG_INFO("look up card: %s in ocpp_auth_local table", idTag);
  874. sprintf(sql,"select * from ocpp_auth_local where idtag='%s'", idTag);
  875. /* Execute SQL statement */
  876. rc = sqlite3_exec(db, sql, IdTagcallback, 0, (char **)&zErrMsg);
  877. if( rc != SQLITE_OK )
  878. {
  879. DEBUG_INFO("SQL error: %s\n", zErrMsg);
  880. }
  881. //return ver;
  882. }
  883. void OCPP_deleteIdTagFromLocalList(char idTag[])
  884. {
  885. //int ver = 0;
  886. //int isSuccess = FALSE;
  887. int rc = 0;
  888. char sql[100];
  889. char zErrMsg[100];
  890. memset(sql, 0, 100);
  891. memset(zErrMsg, 0, 100);
  892. sprintf(sql,"DELETE from ocpp_auth_local where idtag='%s'; SELECT * from ocpp_auth_local;", idTag);
  893. //* Execute SQL statement */
  894. rc = sqlite3_exec(db, sql, deleteIdTagcallback, 0,(char **)&zErrMsg);
  895. if( rc != SQLITE_OK )
  896. {
  897. DEBUG_INFO("SQL error: %s\n", zErrMsg);
  898. }
  899. }
  900. int getCurrentYear()
  901. {
  902. int result = 0;
  903. time_t CurrentTime;
  904. struct tm *tm;
  905. CurrentTime = time(NULL);
  906. tm=localtime(&CurrentTime);
  907. result = (tm->tm_year + 1900);
  908. return result;
  909. }
  910. int OCPP_insert_transaction_msg(uint8_t isStartTransaction, char *transactionMsg)
  911. {
  912. int result = PASS;
  913. char* errMsg = NULL;
  914. char sqlStr[8192];
  915. sprintf(sqlStr, "insert into ocpp_transaction_record(occurDatetime, message_type, message_content) values(CURRENT_TIMESTAMP, '%s', '%s');", (isStartTransaction?"startTransaction":"stopTransaction"), transactionMsg);
  916. if (sqlite3_exec(db, sqlStr, 0, 0, &errMsg) != SQLITE_OK)
  917. {
  918. result = FAIL;
  919. DEBUG_WARN( "Insert local transaction record error message: %s\n", errMsg);
  920. }
  921. 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));
  922. if (sqlite3_exec(db, sqlStr, 0, 0, &errMsg) != SQLITE_OK)
  923. {
  924. result = FAIL;
  925. DEBUG_WARN( "delete local transaction record error message: %s\n", errMsg);
  926. }
  927. return result;
  928. }
  929. int OCPP_updatePeriodEnergy(uint8_t gun_index)
  930. {
  931. int isSuccess = TRUE;
  932. int tempIndex;
  933. json_object *EnergyDataTransfer = json_object_new_object();
  934. json_object *periodEnergys = json_object_new_object();
  935. char sql[1024];
  936. char zErrMsg[200];
  937. memset(sql, 0, ARRAY_SIZE(sql));
  938. memset(zErrMsg, 0, ARRAY_SIZE(zErrMsg));
  939. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  940. {
  941. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  942. {
  943. tempIndex = ((gun_index==2) ? 1: 0);
  944. }
  945. else
  946. {
  947. tempIndex = gun_index;
  948. }
  949. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  950. {
  951. if ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex))
  952. {
  953. json_object_object_add(EnergyDataTransfer, "txId", json_object_new_int(ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId));
  954. for(uint8_t idxPeriod=0;idxPeriod<ARRAY_SIZE(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].presentChargedEnergyPeriod);idxPeriod++)
  955. {
  956. uint8_t period[3];
  957. sprintf((char*)period, "%d", idxPeriod);
  958. json_object_object_add(periodEnergys, (const char *)period, json_object_new_double(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].presentChargedEnergyPeriod[idxPeriod]));
  959. }
  960. json_object_object_add(EnergyDataTransfer, "periodEnergy", periodEnergys);
  961. } //end of the same index
  962. }//end of for CHAdeMO_QUANTITY
  963. }
  964. else if(gunType[gun_index] == GUN_TYPE_CCS)
  965. {
  966. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  967. {
  968. tempIndex = ((gun_index==2) ? 1: 0);
  969. }
  970. else
  971. {
  972. tempIndex = gun_index;
  973. }
  974. for (int index = 0; index < CCS_QUANTITY; index++)
  975. {
  976. if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  977. {
  978. json_object_object_add(EnergyDataTransfer, "txId", json_object_new_int(ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId));
  979. for(uint8_t idxPeriod=0;idxPeriod<ARRAY_SIZE(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].presentChargedEnergyPeriod);idxPeriod++)
  980. {
  981. uint8_t period[3];
  982. sprintf((char*)period, "%d", idxPeriod);
  983. json_object_object_add(periodEnergys, (const char *)period, json_object_new_double(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].presentChargedEnergyPeriod[idxPeriod]));
  984. }
  985. json_object_object_add(EnergyDataTransfer, "periodEnergy", periodEnergys);
  986. } //end of the same index
  987. } // end of for CCS_QUANTITY
  988. }
  989. else if(gunType[gun_index] == GUN_TYPE_GBT)
  990. {
  991. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  992. {
  993. tempIndex = ((gun_index==2) ? 1: 0);
  994. }
  995. else
  996. {
  997. tempIndex = gun_index;
  998. }
  999. for (int index = 0; index < GB_QUANTITY; index++)
  1000. {
  1001. if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  1002. {
  1003. json_object_object_add(EnergyDataTransfer, "txId", json_object_new_int(ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId));
  1004. for(uint8_t idxPeriod=0;idxPeriod<ARRAY_SIZE(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].presentChargedEnergyPeriod);idxPeriod++)
  1005. {
  1006. uint8_t period[3];
  1007. sprintf((char*)period, "%d", idxPeriod);
  1008. json_object_object_add(periodEnergys, (const char *)period, json_object_new_double(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].presentChargedEnergyPeriod[idxPeriod]));
  1009. }
  1010. json_object_object_add(EnergyDataTransfer, "periodEnergy", periodEnergys);
  1011. } //end of the same index
  1012. } // end of for GB_QUANTITY
  1013. }
  1014. else if(gunType[gun_index] == GUN_TYPE_DO)
  1015. {
  1016. tempIndex = gun_index;
  1017. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  1018. {
  1019. if(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  1020. {
  1021. json_object_object_add(EnergyDataTransfer, "txId", json_object_new_int(ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId));
  1022. for(uint8_t idxPeriod=0;idxPeriod<ARRAY_SIZE(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.presentChargedEnergyPeriod);idxPeriod++)
  1023. {
  1024. uint8_t period[3];
  1025. sprintf((char*)period, "%d", idxPeriod);
  1026. json_object_object_add(periodEnergys, (const char *)period, json_object_new_double(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.presentChargedEnergyPeriod[idxPeriod]));
  1027. }
  1028. json_object_object_add(EnergyDataTransfer, "periodEnergy", periodEnergys);
  1029. } //end of the same index
  1030. }
  1031. }
  1032. else
  1033. {
  1034. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  1035. {
  1036. tempIndex = 2;
  1037. }
  1038. else
  1039. {
  1040. tempIndex = gun_index;
  1041. }
  1042. for (int index = 0; index < AC_QUANTITY; index++)
  1043. {
  1044. if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  1045. {
  1046. json_object_object_add(EnergyDataTransfer, "txId", json_object_new_int(ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId));
  1047. for(uint8_t idxPeriod=0;idxPeriod<ARRAY_SIZE(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].presentChargedEnergyPeriod);idxPeriod++)
  1048. {
  1049. uint8_t period[3];
  1050. sprintf((char*)period, "%d", idxPeriod);
  1051. json_object_object_add(periodEnergys, (const char *)period, json_object_new_double(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].presentChargedEnergyPeriod[idxPeriod]));
  1052. }
  1053. json_object_object_add(EnergyDataTransfer, "periodEnergy", periodEnergys);
  1054. }//end of the same index
  1055. }//end of for AC_QUANTITY
  1056. }
  1057. 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));
  1058. json_object_put(EnergyDataTransfer);
  1059. //* Execute SQL statement */
  1060. if( sqlite3_exec(db, sql, callback, 0, (char **)&zErrMsg) != SQLITE_OK )
  1061. {
  1062. DEBUG_WARN("SQL error: %s\n", zErrMsg);
  1063. isSuccess = FALSE;
  1064. }
  1065. sprintf(sql, "delete from ocpp_period_energy where (occurDatetime < '%04d-01-01 00:00:00');", (getCurrentYear()-3));
  1066. if (sqlite3_exec(db, sql, 0, 0, (char **)&zErrMsg) != SQLITE_OK)
  1067. {
  1068. DEBUG_WARN( "delete period energy record error message: %s\n", zErrMsg);
  1069. isSuccess = FALSE;
  1070. }
  1071. return isSuccess;
  1072. }
  1073. int OCPP_getPeriodEnergyToDataTransfer(int32_t transactionId)
  1074. {
  1075. int isSuccess = TRUE;
  1076. char sql[512];
  1077. char zErrMsg[200];
  1078. int rows, cols;
  1079. char **resultData;
  1080. sprintf(sql, "select * from ocpp_period_energy where transactionId=%d;", transactionId);
  1081. /* Execute SQL statement */
  1082. if( sqlite3_get_table(db, sql, &resultData, &rows, &cols, (char **)&zErrMsg) != SQLITE_OK)
  1083. {
  1084. DEBUG_WARN("SQL error: %s\n", zErrMsg);
  1085. isSuccess = FALSE;
  1086. }
  1087. else
  1088. {
  1089. if((rows > 0) && (atoi(resultData[4]) > 0))
  1090. {
  1091. sprintf((char*)ShmOCPP16Data->DataTransfer[0].ResponseData, "%s", resultData[7]);
  1092. }
  1093. else
  1094. {
  1095. DEBUG_WARN("There is not match transaction data.\n");
  1096. isSuccess = FALSE;
  1097. }
  1098. }
  1099. return isSuccess;
  1100. }
  1101. //==========================================
  1102. // Check time passed since today
  1103. //==========================================
  1104. long long DiffTimebWithNow(struct timeb ST)
  1105. {
  1106. //return milli-second
  1107. struct timeb ET;
  1108. long long StartTime,StopTime;
  1109. ftime(&ET);
  1110. StartTime=(long long)ST.time;
  1111. StopTime=(long long)ET.time;
  1112. return ((StopTime-StartTime)*1000) + (ET.millitm-ST.millitm);
  1113. }
  1114. int getTimePassSinceToday(uint8_t gun_index)
  1115. {
  1116. int result = -1;
  1117. static time_t lastTime[4];
  1118. time_t t;
  1119. struct tm *tmStartToday;
  1120. struct timeb tbStartToday;
  1121. t=time(NULL);
  1122. if(difftime(t, lastTime[gun_index])>0)
  1123. {
  1124. tmStartToday=localtime(&t);
  1125. tmStartToday->tm_hour = 0;
  1126. tmStartToday->tm_min = 0;
  1127. tmStartToday->tm_sec = 0;
  1128. tbStartToday.time = mktime(tmStartToday);
  1129. tbStartToday.millitm = 0;
  1130. result = DiffTimebWithNow(tbStartToday)/1000;
  1131. lastTime[gun_index] = t;
  1132. }
  1133. return result;
  1134. }
  1135. void getNowDatetime(uint8_t *data)
  1136. {
  1137. time_t t = time(NULL);
  1138. struct tm tm = *localtime(&t);
  1139. 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);
  1140. }
  1141. int syncDateTimeRTC(uint8_t *data)
  1142. {
  1143. struct ParsingResult
  1144. {
  1145. int result;
  1146. int scanedElement;
  1147. int year;
  1148. int month;
  1149. int mday;
  1150. int hour;
  1151. int min;
  1152. int sec;
  1153. int tz_hour;
  1154. int tz_min;
  1155. float minSec;
  1156. }result;
  1157. struct tm tmOrg;
  1158. struct tm *tmTarget;
  1159. struct timeb tbTarget;
  1160. char buf[128];
  1161. memset(&result, 0x00, sizeof(struct ParsingResult));
  1162. result.result = PASS;
  1163. if(strstr((char*)data, ".") != NULL)
  1164. {
  1165. // Original data with mini second
  1166. if(strstr((char*)data, "Z") != NULL)
  1167. {
  1168. // Original data with Z
  1169. result.scanedElement = sscanf((char*)data, "%d-%d-%dT%d:%d:%d.%fZ",
  1170. &result.year,
  1171. &result.month,
  1172. &result.mday,
  1173. &result.hour,
  1174. &result.min,
  1175. &result.sec,
  1176. &result.minSec);
  1177. }
  1178. else
  1179. {
  1180. // Original data without Z
  1181. result.scanedElement = sscanf((char*)data, "%d-%d-%dT%d:%d:%d.%f%d:%d",
  1182. &result.year,
  1183. &result.month,
  1184. &result.mday,
  1185. &result.hour,
  1186. &result.min,
  1187. &result.sec,
  1188. &result.minSec,
  1189. &result.tz_hour,
  1190. &result.tz_min);
  1191. }
  1192. }
  1193. else
  1194. {
  1195. // Original data without mini second
  1196. if(strstr((char*)data, "Z") != NULL)
  1197. {
  1198. // Original data with Z
  1199. result.scanedElement = sscanf((char*)data, "%d-%d-%dT%d:%d:%dZ",
  1200. &result.year,
  1201. &result.month,
  1202. &result.mday,
  1203. &result.hour,
  1204. &result.min,
  1205. &result.sec);
  1206. }
  1207. else
  1208. {
  1209. // Original data without Z
  1210. result.scanedElement = sscanf((char*)data, "%d-%d-%dT%d:%d:%d%d:%d",
  1211. &result.year,
  1212. &result.month,
  1213. &result.mday,
  1214. &result.hour,
  1215. &result.min,
  1216. &result.sec,
  1217. &result.tz_hour,
  1218. &result.tz_min);
  1219. }
  1220. }
  1221. tmOrg.tm_year = result.year - 1900;
  1222. tmOrg.tm_mon = result.month - 1;
  1223. tmOrg.tm_mday = result.mday;
  1224. tmOrg.tm_hour = result.hour;
  1225. tmOrg.tm_min = result.min;
  1226. tmOrg.tm_sec = result.sec;
  1227. tmOrg.tm_gmtoff = 0;
  1228. tbTarget.time = mktime(&tmOrg);
  1229. tbTarget.timezone = 0;
  1230. tbTarget.time -= (result.tz_hour*3600) + (result.tz_min*60*(result.tz_hour>=0?1:-1));
  1231. tmTarget = gmtime(&tbTarget.time);
  1232. 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);
  1233. //DEBUG_INFO(" org date time: %s\n", data);
  1234. //DEBUG_INFO("parse date time: %s\n", buf);
  1235. system(buf);
  1236. system("/sbin/hwclock -w --systohc");
  1237. if(result.scanedElement < 6)
  1238. result.result = FAIL;
  1239. return result.result;
  1240. }
  1241. //==========================================
  1242. // GetCompositeSchedule logic related function
  1243. //==========================================
  1244. int DiffTimebSec(struct timeb ST, struct timeb ET)
  1245. {
  1246. //return milli-second
  1247. unsigned int StartTime,StopTime;
  1248. StartTime=(unsigned int)ST.time;
  1249. StopTime=(unsigned int)ET.time;
  1250. return (StopTime-StartTime);
  1251. }
  1252. int DiffTimebWithNowSec(struct timeb ST)
  1253. {
  1254. //return milli-second
  1255. struct timeb ET;
  1256. unsigned int StartTime,StopTime;
  1257. ftime(&ET);
  1258. StartTime=(unsigned int)ST.time;
  1259. StopTime=(unsigned int)ET.time;
  1260. return (StopTime-StartTime);
  1261. }
  1262. int getStartStop(uint8_t *start, uint8_t *stop)
  1263. {
  1264. int result = -1;
  1265. struct tm tmStart;
  1266. struct timeb tbStart;
  1267. struct tm tmStop;
  1268. struct timeb tbStop;
  1269. if((sscanf((char*)start, "%4d-%2d-%2dT%2d:%2d:%2d", &tmStart.tm_year, &tmStart.tm_mon, &tmStart.tm_mday, &tmStart.tm_hour, &tmStart.tm_min, &tmStart.tm_sec) == 6) &&
  1270. (sscanf((char*)stop, "%4d-%2d-%2dT%2d:%2d:%2d", &tmStop.tm_year, &tmStop.tm_mon, &tmStop.tm_mday, &tmStop.tm_hour, &tmStop.tm_min, &tmStop.tm_sec) == 6))
  1271. {
  1272. //DEBUG_INFO("Start: %d-%d-%d %d:%d:%d\n", tmStart.tm_year, tmStart.tm_mon, tmStart.tm_mday, tmStart.tm_hour, tmStart.tm_min, tmStart.tm_sec);
  1273. //DEBUG_INFO("Stop: %d-%d-%d %d:%d:%d\n", tmStop.tm_year, tmStop.tm_mon, tmStop.tm_mday, tmStop.tm_hour, tmStop.tm_min, tmStop.tm_sec);
  1274. tmStart.tm_year -= 1900;
  1275. tmStart.tm_mon -= 1;
  1276. tbStart.time = mktime(&tmStart);
  1277. tbStart.millitm = 0;
  1278. tmStop.tm_year -= 1900;
  1279. tmStop.tm_mon -= 1;
  1280. tbStop.time = mktime(&tmStop);
  1281. tbStop.millitm = 0;
  1282. result = DiffTimebSec(tbStart, tbStop);
  1283. //DEBUG_INFO("getStartStop(): %d\n", result);
  1284. }
  1285. else
  1286. {
  1287. DEBUG_WARN("Start or stop date parsing error.\r\n");
  1288. }
  1289. return result;
  1290. }
  1291. int isOvertNow(uint8_t *start)
  1292. {
  1293. int result = NO;
  1294. struct ParsingResult
  1295. {
  1296. int result;
  1297. int scanedElement;
  1298. int year;
  1299. int month;
  1300. int mday;
  1301. int hour;
  1302. int min;
  1303. int sec;
  1304. int tz_hour;
  1305. int tz_min;
  1306. float minSec;
  1307. }parsingResult;
  1308. struct tm tmStart;
  1309. struct timeb tbStart;
  1310. memset(&parsingResult, 0x00, sizeof(struct ParsingResult));
  1311. if(strstr((char*)start, ".") != NULL)
  1312. {
  1313. // Original data with mini second
  1314. if(strstr((char*)start, "Z") != NULL)
  1315. {
  1316. // Original data with Z
  1317. parsingResult.scanedElement = sscanf((char*)start, "%d-%d-%dT%d:%d:%d.%fZ",
  1318. &parsingResult.year,
  1319. &parsingResult.month,
  1320. &parsingResult.mday,
  1321. &parsingResult.hour,
  1322. &parsingResult.min,
  1323. &parsingResult.sec,
  1324. &parsingResult.minSec);
  1325. }
  1326. else
  1327. {
  1328. // Original data without Z
  1329. parsingResult.scanedElement = sscanf((char*)start, "%d-%d-%dT%d:%d:%d.%f%d:%d",
  1330. &parsingResult.year,
  1331. &parsingResult.month,
  1332. &parsingResult.mday,
  1333. &parsingResult.hour,
  1334. &parsingResult.min,
  1335. &parsingResult.sec,
  1336. &parsingResult.minSec,
  1337. &parsingResult.tz_hour,
  1338. &parsingResult.tz_min);
  1339. }
  1340. }
  1341. else
  1342. {
  1343. // Original data without mini second
  1344. if(strstr((char*)start, "Z") != NULL)
  1345. {
  1346. // Original data with Z
  1347. parsingResult.scanedElement = sscanf((char*)start, "%d-%d-%dT%d:%d:%dZ",
  1348. &parsingResult.year,
  1349. &parsingResult.month,
  1350. &parsingResult.mday,
  1351. &parsingResult.hour,
  1352. &parsingResult.min,
  1353. &parsingResult.sec);
  1354. }
  1355. else
  1356. {
  1357. // Original data without Z
  1358. parsingResult.scanedElement = sscanf((char*)start, "%d-%d-%dT%d:%d:%d%d:%d",
  1359. &parsingResult.year,
  1360. &parsingResult.month,
  1361. &parsingResult.mday,
  1362. &parsingResult.hour,
  1363. &parsingResult.min,
  1364. &parsingResult.sec,
  1365. &parsingResult.tz_hour,
  1366. &parsingResult.tz_min);
  1367. }
  1368. }
  1369. if(parsingResult.scanedElement >= 6)
  1370. {
  1371. tmStart.tm_year = parsingResult.year - 1900;
  1372. tmStart.tm_mon = parsingResult.month - 1;
  1373. tmStart.tm_mday = parsingResult.mday;
  1374. tmStart.tm_hour = parsingResult.hour;
  1375. tmStart.tm_min = parsingResult.min;
  1376. tmStart.tm_sec = parsingResult.sec;
  1377. tmStart.tm_gmtoff = 0;
  1378. tbStart.time = mktime(&tmStart);
  1379. tbStart.timezone = 0;
  1380. tbStart.millitm = 0;
  1381. tbStart.time -= (parsingResult.tz_hour*3600) + (parsingResult.tz_min*60*(parsingResult.tz_hour>=0?1:-1));
  1382. if(DiffTimebWithNowSec(tbStart) <= 0)
  1383. result = NO;
  1384. else
  1385. result = YES;
  1386. }
  1387. else
  1388. {
  1389. DEBUG_WARN("Start date parsing error.\n");
  1390. }
  1391. return result;
  1392. }
  1393. int getStartSinceRecurring(uint8_t *start, uint8_t *stop, uint8_t isDaily)
  1394. {
  1395. int result = -1;
  1396. struct tm tmStart;
  1397. struct timeb tbStart;
  1398. struct tm tmStop;
  1399. struct timeb tbStop;
  1400. if((sscanf((char*)start, "%4d-%2d-%2dT%2d:%2d:%2d", &tmStart.tm_year, &tmStart.tm_mon, &tmStart.tm_mday, &tmStart.tm_hour, &tmStart.tm_min, &tmStart.tm_sec) == 6) &&
  1401. (sscanf((char*)stop, "%4d-%2d-%2dT%2d:%2d:%2d", &tmStop.tm_year, &tmStop.tm_mon, &tmStop.tm_mday, &tmStop.tm_hour, &tmStop.tm_min, &tmStop.tm_sec) == 6))
  1402. {
  1403. tmStart.tm_year -= 1900;
  1404. tmStart.tm_mon -= 1;
  1405. tbStart.time = mktime(&tmStart);
  1406. tbStart.millitm = 0;
  1407. tmStop.tm_year -= 1900;
  1408. tmStop.tm_mon -= 1;
  1409. tbStop.time = mktime(&tmStop);
  1410. tbStop.millitm = 0;
  1411. result = DiffTimebSec(tbStart, tbStop)%(isDaily?86400:604800);
  1412. }
  1413. return result;
  1414. }
  1415. void checkChargePointMaxProfile(uint32_t durationReq, struct StructChargingProfile *compositeProfile, uint8_t isUnitA)
  1416. {
  1417. FILE *fp;
  1418. char profileFileName[128];
  1419. char *line = NULL;
  1420. size_t len = 0;
  1421. time_t CurrentTime;
  1422. struct tm *tmComposite;
  1423. struct StructChargingProfile maxProfile;
  1424. uint8_t limitMax=0;
  1425. int compositePeriodIdx = 0;
  1426. CurrentTime = time(NULL);
  1427. tmComposite=localtime(&CurrentTime);
  1428. 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);
  1429. if(isUnitA)
  1430. sprintf((char*)compositeProfile->ChargingSchedule.ChargingRateUnit, "A");
  1431. else
  1432. sprintf((char*)compositeProfile->ChargingSchedule.ChargingRateUnit, "W");
  1433. compositeProfile->ChargingSchedule.Duration = durationReq;
  1434. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(compositeProfile->ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  1435. {
  1436. compositeProfile->ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = -1;
  1437. compositeProfile->ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit = -1;
  1438. compositeProfile->ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases = 3;
  1439. }
  1440. compositeProfile->ChargingProfileId = 0;
  1441. compositeProfile->StackLevel = 99 ;
  1442. sprintf((char*)compositeProfile->ChargingProfileKind ,"Absolute");
  1443. maxProfile.ChargingProfileId = -1;
  1444. maxProfile.ChargingSchedule.Duration = -1;
  1445. system("rm -f /tmp/*.json");
  1446. system("cp /Storage/OCPP/*.json /tmp 2>/dev/null");
  1447. // Search max profile
  1448. sprintf(profileFileName, "/tmp/ChargePointMaxProfile.json");
  1449. if((access(profileFileName, F_OK))!=-1)
  1450. {
  1451. fp = fopen(profileFileName, "r");
  1452. while(getline(&line, &len, fp) != -1)
  1453. {
  1454. json_object *obj = NULL;
  1455. obj = json_tokener_parse(line);
  1456. if(is_error(obj))
  1457. {
  1458. DEBUG_ERROR("Parse MaxProfile from file error.\n");
  1459. }
  1460. else
  1461. {
  1462. if((json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileId")) != maxProfile.ChargingProfileId) &&
  1463. (json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "stackLevel")) >= maxProfile.StackLevel)
  1464. )
  1465. {
  1466. if((json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom") != NULL) &&
  1467. (json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo") != NULL)
  1468. )
  1469. {
  1470. struct tm tmFrom, tmTo;
  1471. struct timeb tbFrom, tbTo;
  1472. 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) &&
  1473. (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))
  1474. {
  1475. tmFrom.tm_year -= 1900;
  1476. tmFrom.tm_mon -= 1;
  1477. tbFrom.time = mktime(&tmFrom);
  1478. tmTo.tm_year -= 1900;
  1479. tmTo.tm_mon -= 1;
  1480. tbTo.time = mktime(&tmTo);
  1481. if((DiffTimebWithNowSec(tbFrom)>=0) && (DiffTimebWithNowSec(tbTo)<=0))
  1482. {
  1483. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  1484. {
  1485. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = -1;
  1486. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit = -1;
  1487. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases = 3;
  1488. }
  1489. maxProfile.ChargingProfileId = -1;
  1490. maxProfile.StackLevel = -1;
  1491. if(maxProfile.ChargingProfileId == -1)
  1492. DEBUG_INFO("MaxProfile found.\n");
  1493. else
  1494. DEBUG_INFO("MaxProfile updated.\n");
  1495. // Required item
  1496. maxProfile.ChargingProfileId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileId"));
  1497. maxProfile.StackLevel = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "stackLevel"));
  1498. sprintf((char*)maxProfile.ChargingProfileKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileKind")));
  1499. if(isUnitA)
  1500. {
  1501. sprintf((char*)maxProfile.ChargingSchedule.ChargingRateUnit, "A");
  1502. 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++)
  1503. {
  1504. 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"));
  1505. 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?
  1506. 3:
  1507. 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")));
  1508. 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")));
  1509. }
  1510. }
  1511. else
  1512. {
  1513. sprintf((char*)maxProfile.ChargingSchedule.ChargingRateUnit, "W");
  1514. 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++)
  1515. {
  1516. 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"));
  1517. 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?
  1518. 3:
  1519. 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")));
  1520. 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));
  1521. }
  1522. }
  1523. // Optional item
  1524. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom") != NULL)
  1525. {
  1526. sprintf((char*)maxProfile.ValidFrom, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom")));
  1527. }
  1528. else
  1529. {
  1530. sprintf((char*)maxProfile.ValidFrom, " ");
  1531. }
  1532. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo") != NULL)
  1533. {
  1534. sprintf((char*)maxProfile.ValidTo, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo")));
  1535. }
  1536. else
  1537. {
  1538. sprintf((char*)maxProfile.ValidTo, " ");
  1539. }
  1540. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "recurrencyKind") != NULL)
  1541. {
  1542. sprintf((char*)maxProfile.RecurrencyKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "recurrencyKind")));
  1543. }
  1544. else
  1545. {
  1546. sprintf((char*)maxProfile.RecurrencyKind, " ");
  1547. }
  1548. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId") != NULL)
  1549. {
  1550. maxProfile.TransactionId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId"));
  1551. }
  1552. else
  1553. {
  1554. maxProfile.TransactionId = -1;
  1555. }
  1556. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration") != NULL)
  1557. {
  1558. maxProfile.ChargingSchedule.Duration = json_object_get_int(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration"));
  1559. }
  1560. else
  1561. {
  1562. maxProfile.ChargingSchedule.Duration = 86400;
  1563. }
  1564. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "startSchedule") != NULL)
  1565. {
  1566. 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")));
  1567. }
  1568. else
  1569. {
  1570. sprintf((char*)maxProfile.ChargingSchedule.StartSchedule, "%s", compositeProfile->ChargingSchedule.StartSchedule);
  1571. }
  1572. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate") != NULL)
  1573. {
  1574. maxProfile.ChargingSchedule.MinChargingRate = json_object_get_double(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate"));
  1575. }
  1576. else
  1577. {
  1578. maxProfile.ChargingSchedule.MinChargingRate = -1;
  1579. }
  1580. }
  1581. }
  1582. }
  1583. else
  1584. {
  1585. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  1586. {
  1587. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = -1;
  1588. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit = -1;
  1589. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases = 3;
  1590. }
  1591. maxProfile.ChargingProfileId = -1;
  1592. maxProfile.StackLevel = -1;
  1593. if(maxProfile.ChargingProfileId == -1)
  1594. DEBUG_INFO("MaxProfile found.\n");
  1595. else
  1596. DEBUG_INFO("MaxProfile updated.\n");
  1597. // Required item
  1598. maxProfile.ChargingProfileId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileId"));
  1599. maxProfile.StackLevel = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "stackLevel"));
  1600. sprintf((char*)maxProfile.ChargingProfileKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileKind")));
  1601. if(isUnitA)
  1602. {
  1603. sprintf((char*)maxProfile.ChargingSchedule.ChargingRateUnit, "A");
  1604. 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++)
  1605. {
  1606. 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"));
  1607. 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?
  1608. 3:
  1609. 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")));
  1610. 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")));
  1611. }
  1612. }
  1613. else
  1614. {
  1615. sprintf((char*)maxProfile.ChargingSchedule.ChargingRateUnit, "W");
  1616. 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++)
  1617. {
  1618. 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"));
  1619. 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?
  1620. 3:
  1621. 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")));
  1622. 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));
  1623. }
  1624. }
  1625. // Optional item
  1626. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom") != NULL)
  1627. {
  1628. sprintf((char*)maxProfile.ValidFrom, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom")));
  1629. }
  1630. else
  1631. {
  1632. sprintf((char*)maxProfile.ValidFrom, " ");
  1633. }
  1634. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo") != NULL)
  1635. {
  1636. sprintf((char*)maxProfile.ValidTo, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo")));
  1637. }
  1638. else
  1639. {
  1640. sprintf((char*)maxProfile.ValidTo, " ");
  1641. }
  1642. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "recurrencyKind") != NULL)
  1643. {
  1644. sprintf((char*)maxProfile.RecurrencyKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "recurrencyKind")));
  1645. }
  1646. else
  1647. {
  1648. sprintf((char*)maxProfile.RecurrencyKind, " ");
  1649. }
  1650. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId") != NULL)
  1651. {
  1652. maxProfile.TransactionId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId"));
  1653. }
  1654. else
  1655. {
  1656. maxProfile.TransactionId = -1;
  1657. }
  1658. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration") != NULL)
  1659. {
  1660. maxProfile.ChargingSchedule.Duration = json_object_get_int(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration"));
  1661. }
  1662. else
  1663. {
  1664. maxProfile.ChargingSchedule.Duration = 86400;
  1665. }
  1666. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "startSchedule") != NULL)
  1667. {
  1668. 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")));
  1669. }
  1670. else
  1671. {
  1672. sprintf((char*)maxProfile.ChargingSchedule.StartSchedule, "%s", compositeProfile->ChargingSchedule.StartSchedule);
  1673. }
  1674. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate") != NULL)
  1675. {
  1676. maxProfile.ChargingSchedule.MinChargingRate = json_object_get_double(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate"));
  1677. }
  1678. else
  1679. {
  1680. maxProfile.ChargingSchedule.MinChargingRate = -1;
  1681. }
  1682. }
  1683. }
  1684. }
  1685. json_object_put(obj);
  1686. }
  1687. fclose(fp);
  1688. /*
  1689. if(maxProfile.ChargingProfileId !=-1)
  1690. {
  1691. DEBUG_INFO("Profile ID: %d\n", maxProfile.ChargingProfileId);
  1692. DEBUG_INFO("Profile stackLevel: %d\n", maxProfile.StackLevel);
  1693. DEBUG_INFO("Profile TransactionId: %d\n", maxProfile.TransactionId);
  1694. DEBUG_INFO("Profile valid from: %s\n", maxProfile.ValidFrom);
  1695. DEBUG_INFO("Profile valid to: %s\n", maxProfile.ValidTo);
  1696. DEBUG_INFO("Profile ChargingProfileKind: %s\n", maxProfile.ChargingProfileKind);
  1697. DEBUG_INFO("Profile recurrencyKind: %s\n", maxProfile.RecurrencyKind);
  1698. DEBUG_INFO("Profile start schedule: %s\n", maxProfile.ChargingSchedule.StartSchedule);
  1699. DEBUG_INFO("Profile schedule duration: %d\n", maxProfile.ChargingSchedule.Duration);
  1700. DEBUG_INFO("Profile charging rate unit: %s\n", maxProfile.ChargingSchedule.ChargingRateUnit);
  1701. DEBUG_INFO("Profile charging min rate: %f\n", maxProfile.ChargingSchedule.MinChargingRate);
  1702. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  1703. {
  1704. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod >= 0)
  1705. {
  1706. DEBUG_INFO("Period-%02d startPeriod: %d\n", idxPeriod, maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod);
  1707. DEBUG_INFO("Period-%02d limit: %f\n", idxPeriod, maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit);
  1708. DEBUG_INFO("Period-%02d NumberPhases: %d\n", idxPeriod, maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases);
  1709. }
  1710. }
  1711. }
  1712. else
  1713. DEBUG_INFO("MaxProfile not found.\n");
  1714. DEBUG_INFO("------------------------------------\n");*/
  1715. }
  1716. if(maxProfile.ChargingProfileId != -1)
  1717. {
  1718. if(strstr((char*)maxProfile.ChargingProfileKind, "Absolute") != NULL)
  1719. {
  1720. if(maxProfile.ChargingSchedule.Duration != -1)
  1721. {
  1722. maxProfile.ChargingSchedule.Duration = ((maxProfile.ChargingSchedule.Duration-getStartStop(maxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule))<0?
  1723. 0:
  1724. (maxProfile.ChargingSchedule.Duration-getStartStop(maxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule)));
  1725. }
  1726. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  1727. {
  1728. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  1729. {
  1730. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = ((maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartStop(maxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule))<0?
  1731. 0:
  1732. (maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartStop(maxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule)));
  1733. if(idxPeriod > 0)
  1734. {
  1735. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
  1736. {
  1737. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit = maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit;
  1738. }
  1739. }
  1740. }
  1741. }
  1742. }
  1743. else if(strstr((char*)maxProfile.ChargingProfileKind, "Relative") != NULL)
  1744. {
  1745. if(maxProfile.ChargingSchedule.Duration != -1)
  1746. {
  1747. maxProfile.ChargingSchedule.Duration = maxProfile.ChargingSchedule.Duration;
  1748. }
  1749. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  1750. {
  1751. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  1752. {
  1753. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod;
  1754. if(idxPeriod > 0)
  1755. {
  1756. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
  1757. {
  1758. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit = maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit;
  1759. }
  1760. }
  1761. }
  1762. }
  1763. }
  1764. else
  1765. {
  1766. if(strstr((char*)maxProfile.RecurrencyKind, "Weekly") != NULL)
  1767. {
  1768. if(maxProfile.ChargingSchedule.Duration != -1)
  1769. {
  1770. maxProfile.ChargingSchedule.Duration = ((maxProfile.ChargingSchedule.Duration-getStartSinceRecurring(maxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, FALSE))<0?
  1771. 0:
  1772. (maxProfile.ChargingSchedule.Duration-getStartSinceRecurring(maxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, FALSE)));
  1773. }
  1774. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  1775. {
  1776. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  1777. {
  1778. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = ((maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceRecurring(maxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, FALSE))<0?
  1779. 0:
  1780. (maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceRecurring(maxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, FALSE)));
  1781. if(idxPeriod > 0)
  1782. {
  1783. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
  1784. {
  1785. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit = maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit;
  1786. }
  1787. }
  1788. }
  1789. }
  1790. }
  1791. else
  1792. {
  1793. if(maxProfile.ChargingSchedule.Duration != -1)
  1794. {
  1795. maxProfile.ChargingSchedule.Duration = ((maxProfile.ChargingSchedule.Duration-getStartSinceRecurring(maxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, TRUE))<0?
  1796. 0:
  1797. (maxProfile.ChargingSchedule.Duration-getStartSinceRecurring(maxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, TRUE)));
  1798. }
  1799. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  1800. {
  1801. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  1802. {
  1803. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = ((maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceRecurring(maxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, TRUE))<0?
  1804. 0:
  1805. (maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceRecurring(maxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, TRUE)));
  1806. if(idxPeriod > 0)
  1807. {
  1808. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
  1809. {
  1810. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit = maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit;
  1811. }
  1812. }
  1813. }
  1814. }
  1815. }
  1816. }
  1817. /*
  1818. DEBUG_INFO("MaxProfile after align.\n");
  1819. DEBUG_INFO("Profile ID: %d\n", maxProfile.ChargingProfileId);
  1820. DEBUG_INFO("Profile stackLevel: %d\n", maxProfile.StackLevel);
  1821. DEBUG_INFO("Profile TransactionId: %d\n", maxProfile.TransactionId);
  1822. DEBUG_INFO("Profile valid from: %s\n", maxProfile.ValidFrom);
  1823. DEBUG_INFO("Profile valid to: %s\n", maxProfile.ValidTo);
  1824. DEBUG_INFO("Profile ChargingProfileKind: %s\n", maxProfile.ChargingProfileKind);
  1825. DEBUG_INFO("Profile RecurrencyKind: %s\n", maxProfile.RecurrencyKind);
  1826. DEBUG_INFO("Profile start schedule: %s\n", compositeProfile->ChargingSchedule.StartSchedule);
  1827. DEBUG_INFO("Profile schedule duration: %d\n", maxProfile.ChargingSchedule.Duration);
  1828. DEBUG_INFO("Profile charging rate unit: %s\n", maxProfile.ChargingSchedule.ChargingRateUnit);
  1829. DEBUG_INFO("Profile charging min rate: %f\n", maxProfile.ChargingSchedule.MinChargingRate);
  1830. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  1831. {
  1832. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod >= 0)
  1833. {
  1834. DEBUG_INFO("Period-%02d startPeriod: %d\n", idxPeriod, maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod);
  1835. DEBUG_INFO("Period-%02d limit: %f\n", idxPeriod, maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit);
  1836. DEBUG_INFO("Period-%02d NumberPhases: %d\n", idxPeriod, maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases);
  1837. }
  1838. }
  1839. DEBUG_INFO("------------------------------------\n");*/
  1840. }
  1841. // Find each profile period quantity
  1842. for(int idx=0;idx<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idx++)
  1843. {
  1844. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idx].Limit != -1)
  1845. limitMax = idx+1;
  1846. }
  1847. if(maxProfile.ChargingProfileId != -1)
  1848. {
  1849. for(int idxMaxPeriod=0;idxMaxPeriod<limitMax;idxMaxPeriod++)
  1850. {
  1851. if((maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].Limit != -1) &&
  1852. (maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].StartPeriod < durationReq) &&
  1853. (maxProfile.ChargingSchedule.Duration > 0))
  1854. {
  1855. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].StartPeriod != compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].StartPeriod)
  1856. {
  1857. memcpy(&compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx], &maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod],sizeof(struct StructChargingSchedulePeriod));
  1858. compositePeriodIdx++;
  1859. }
  1860. else
  1861. {
  1862. memcpy(&compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)], &maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod],sizeof(struct StructChargingSchedulePeriod));
  1863. }
  1864. }
  1865. }
  1866. }
  1867. DEBUG_INFO("ChargePointMaxProfile ready.\n");
  1868. DEBUG_INFO("Schedule start: %s\n", compositeProfile->ChargingSchedule.StartSchedule);
  1869. DEBUG_INFO("Schedule duration: %d\n", compositeProfile->ChargingSchedule.Duration);
  1870. DEBUG_INFO("Rate unit: %s\n", compositeProfile->ChargingSchedule.ChargingRateUnit);
  1871. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(compositeProfile->ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  1872. {
  1873. if(compositeProfile->ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod >= 0)
  1874. {
  1875. compositeProfile->ChargingProfileId = 1;
  1876. DEBUG_INFO("Period-%02d startPeriod: %d\n", idxPeriod, compositeProfile->ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod);
  1877. DEBUG_INFO("Period-%02d limit: %f\n", idxPeriod, compositeProfile->ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit);
  1878. DEBUG_INFO("Period-%02d NumberPhases: %d\n", idxPeriod, compositeProfile->ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases);
  1879. }
  1880. if(compositeProfile->ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit == -1)
  1881. compositeProfile->ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit =0;
  1882. if(compositeProfile->ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod == -1)
  1883. compositeProfile->ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod =0;
  1884. }
  1885. if(line)
  1886. free(line);
  1887. }
  1888. void checkCompositeSchedule(uint8_t connectorId, uint32_t durationReq, struct StructChargingProfile *compositeProfile, uint8_t isUnitA)
  1889. {
  1890. FILE *fp;
  1891. char profileFileName[128];
  1892. char *line = NULL;
  1893. size_t len = 0;
  1894. time_t CurrentTime;
  1895. struct tm *tmComposite;
  1896. struct StructChargingProfile maxProfile;
  1897. struct StructChargingProfile defaultTxProfile;
  1898. struct StructChargingProfile txProfile;
  1899. struct StructChargingSchedulePeriod tmpPeriod;
  1900. uint8_t limitMax=0;
  1901. uint8_t limitDef=0;
  1902. uint8_t limitTx=0;
  1903. int compositePeriodIdx = 0;
  1904. CurrentTime = time(NULL);
  1905. tmComposite=localtime(&CurrentTime);
  1906. 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);
  1907. if(isUnitA)
  1908. sprintf((char*)compositeProfile->ChargingSchedule.ChargingRateUnit, "A");
  1909. else
  1910. sprintf((char*)compositeProfile->ChargingSchedule.ChargingRateUnit, "W");
  1911. compositeProfile->ChargingSchedule.Duration = durationReq;
  1912. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(compositeProfile->ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  1913. {
  1914. compositeProfile->ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = -1;
  1915. compositeProfile->ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit = -1;
  1916. compositeProfile->ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases = 3;
  1917. }
  1918. compositeProfile->ChargingProfileId = 0;
  1919. compositeProfile->StackLevel = 99 ;
  1920. sprintf((char*)compositeProfile->ChargingProfileKind ,"Absolute");
  1921. maxProfile.ChargingProfileId = -1;
  1922. defaultTxProfile.ChargingProfileId = -1;
  1923. txProfile.ChargingProfileId = -1;
  1924. maxProfile.ChargingSchedule.Duration = -1;
  1925. defaultTxProfile.ChargingSchedule.Duration = -1;
  1926. txProfile.ChargingSchedule.Duration = -1;
  1927. system("rm -f /tmp/*.json");
  1928. system("cp /Storage/OCPP/*.json /tmp 2>/dev/null");
  1929. /*
  1930. * Search valid charging profile
  1931. */
  1932. //DEBUG_INFO("====================================\n");
  1933. // Search tx profile
  1934. sprintf(profileFileName, "/tmp/TxProfile_%d.json", connectorId);
  1935. if((access(profileFileName, F_OK))!=-1)
  1936. {
  1937. fp = fopen(profileFileName, "r");
  1938. while(getline(&line, &len, fp) != -1)
  1939. {
  1940. json_object *obj = NULL;
  1941. obj = json_tokener_parse(line);
  1942. if(is_error(obj))
  1943. {
  1944. DEBUG_ERROR("Parse txProfile from file error.\n");
  1945. }
  1946. else
  1947. {
  1948. if((json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileId")) != txProfile.ChargingProfileId) &&
  1949. (json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "stackLevel")) >= txProfile.StackLevel)
  1950. )
  1951. {
  1952. if((json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom") != NULL) &&
  1953. (json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo") != NULL)
  1954. )
  1955. {
  1956. struct tm tmFrom, tmTo;
  1957. struct timeb tbFrom, tbTo;
  1958. 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) &&
  1959. (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))
  1960. {
  1961. tmFrom.tm_year -= 1900;
  1962. tmFrom.tm_mon -= 1;
  1963. tbFrom.time = mktime(&tmFrom);
  1964. tmTo.tm_year -= 1900;
  1965. tmTo.tm_mon -= 1;
  1966. tbTo.time = mktime(&tmTo);
  1967. if((DiffTimebWithNowSec(tbFrom)>=0) && (DiffTimebWithNowSec(tbTo)<=0))
  1968. {
  1969. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(txProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  1970. {
  1971. txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = -1;
  1972. txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit = -1;
  1973. txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases = 3;
  1974. }
  1975. txProfile.ChargingProfileId = -1;
  1976. txProfile.StackLevel = -1;
  1977. if(txProfile.ChargingProfileId == -1)
  1978. DEBUG_INFO("TxProfile found.\n");
  1979. else
  1980. DEBUG_INFO("TxProfile updated.\n");
  1981. // Required item
  1982. txProfile.ChargingProfileId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileId"));
  1983. txProfile.StackLevel = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "stackLevel"));
  1984. sprintf((char*)txProfile.ChargingProfileKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileKind")));
  1985. if(isUnitA)
  1986. {
  1987. sprintf((char*)txProfile.ChargingSchedule.ChargingRateUnit, "A");
  1988. 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++)
  1989. {
  1990. 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"));
  1991. 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?
  1992. 3:
  1993. 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")));
  1994. 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")));
  1995. }
  1996. }
  1997. else
  1998. {
  1999. sprintf((char*)txProfile.ChargingSchedule.ChargingRateUnit, "W");
  2000. 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++)
  2001. {
  2002. 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"));
  2003. 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?
  2004. 3:
  2005. 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")));
  2006. 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));
  2007. }
  2008. }
  2009. // Optional item
  2010. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom") != NULL)
  2011. {
  2012. sprintf((char*)txProfile.ValidFrom, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom")));
  2013. }
  2014. else
  2015. {
  2016. sprintf((char*)txProfile.ValidFrom, " ");
  2017. }
  2018. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo") != NULL)
  2019. {
  2020. sprintf((char*)txProfile.ValidTo, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo")));
  2021. }
  2022. else
  2023. {
  2024. sprintf((char*)txProfile.ValidTo, " ");
  2025. }
  2026. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "recurrencyKind") != NULL)
  2027. {
  2028. sprintf((char*)txProfile.RecurrencyKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "recurrencyKind")));
  2029. }
  2030. else
  2031. {
  2032. sprintf((char*)txProfile.RecurrencyKind, " ");
  2033. }
  2034. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId") != NULL)
  2035. {
  2036. txProfile.TransactionId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId"));
  2037. }
  2038. else
  2039. {
  2040. txProfile.TransactionId = -1;
  2041. }
  2042. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration") != NULL)
  2043. {
  2044. txProfile.ChargingSchedule.Duration = json_object_get_int(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration"));
  2045. }
  2046. else
  2047. {
  2048. txProfile.ChargingSchedule.Duration = 86400;
  2049. }
  2050. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "startSchedule") != NULL)
  2051. {
  2052. 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")));
  2053. }
  2054. else
  2055. {
  2056. 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));
  2057. }
  2058. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate") != NULL)
  2059. {
  2060. txProfile.ChargingSchedule.MinChargingRate = json_object_get_double(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate"));
  2061. }
  2062. else
  2063. {
  2064. txProfile.ChargingSchedule.MinChargingRate = -1;
  2065. }
  2066. }
  2067. }
  2068. }
  2069. else
  2070. {
  2071. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(txProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  2072. {
  2073. txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = -1;
  2074. txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit = -1;
  2075. txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases = 3;
  2076. }
  2077. txProfile.ChargingProfileId = -1;
  2078. txProfile.StackLevel = -1;
  2079. if(txProfile.ChargingProfileId == -1)
  2080. DEBUG_INFO("TxProfile found.\n");
  2081. else
  2082. DEBUG_INFO("TxProfile updated.\n");
  2083. // Required item
  2084. txProfile.ChargingProfileId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileId"));
  2085. txProfile.StackLevel = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "stackLevel"));
  2086. sprintf((char*)txProfile.ChargingProfileKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileKind")));
  2087. if(isUnitA)
  2088. {
  2089. sprintf((char*)txProfile.ChargingSchedule.ChargingRateUnit, "A");
  2090. 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++)
  2091. {
  2092. 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"));
  2093. 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?
  2094. 3:
  2095. 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")));
  2096. 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")));
  2097. }
  2098. }
  2099. else
  2100. {
  2101. sprintf((char*)txProfile.ChargingSchedule.ChargingRateUnit, "W");
  2102. 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++)
  2103. {
  2104. 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"));
  2105. 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?
  2106. 3:
  2107. 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")));
  2108. 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));
  2109. }
  2110. }
  2111. // Optional item
  2112. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom") != NULL)
  2113. {
  2114. sprintf((char*)txProfile.ValidFrom, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom")));
  2115. }
  2116. else
  2117. {
  2118. sprintf((char*)txProfile.ValidFrom, " ");
  2119. }
  2120. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo") != NULL)
  2121. {
  2122. sprintf((char*)txProfile.ValidTo, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo")));
  2123. }
  2124. else
  2125. {
  2126. sprintf((char*)txProfile.ValidTo, " ");
  2127. }
  2128. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "recurrencyKind") != NULL)
  2129. {
  2130. sprintf((char*)txProfile.RecurrencyKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "recurrencyKind")));
  2131. }
  2132. else
  2133. {
  2134. sprintf((char*)txProfile.RecurrencyKind, " ");
  2135. }
  2136. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId") != NULL)
  2137. {
  2138. txProfile.TransactionId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId"));
  2139. }
  2140. else
  2141. {
  2142. txProfile.TransactionId = -1;
  2143. }
  2144. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration") != NULL)
  2145. {
  2146. txProfile.ChargingSchedule.Duration = json_object_get_int(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration"));
  2147. }
  2148. else
  2149. {
  2150. txProfile.ChargingSchedule.Duration = 86400;
  2151. }
  2152. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "startSchedule") != NULL)
  2153. {
  2154. 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")));
  2155. }
  2156. else
  2157. {
  2158. 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));
  2159. }
  2160. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate") != NULL)
  2161. {
  2162. txProfile.ChargingSchedule.MinChargingRate = json_object_get_double(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate"));
  2163. }
  2164. else
  2165. {
  2166. txProfile.ChargingSchedule.MinChargingRate = -1;
  2167. }
  2168. }
  2169. }
  2170. }
  2171. json_object_put(obj);
  2172. }
  2173. fclose(fp);
  2174. /*
  2175. if(txProfile.ChargingProfileId != -1)
  2176. {
  2177. DEBUG_INFO("Profile ID: %d\n", txProfile.ChargingProfileId);
  2178. DEBUG_INFO("Profile stackLevel: %d\n", txProfile.StackLevel);
  2179. DEBUG_INFO("Profile TransactionId: %d\n", txProfile.TransactionId);
  2180. DEBUG_INFO("Profile valid from: %s\n", txProfile.ValidFrom);
  2181. DEBUG_INFO("Profile valid to: %s\n", txProfile.ValidTo);
  2182. DEBUG_INFO("Profile ChargingProfileKind: %s\n", txProfile.ChargingProfileKind);
  2183. DEBUG_INFO("Profile recurrencyKind: %s\n", txProfile.RecurrencyKind);
  2184. DEBUG_INFO("Profile start schedule: %s\n", txProfile.ChargingSchedule.StartSchedule);
  2185. DEBUG_INFO("Profile schedule duration: %d\n", txProfile.ChargingSchedule.Duration);
  2186. DEBUG_INFO("Profile charging rate unit: %s\n", txProfile.ChargingSchedule.ChargingRateUnit);
  2187. DEBUG_INFO("Profile charging min rate: %f\n", txProfile.ChargingSchedule.MinChargingRate);
  2188. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(txProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  2189. {
  2190. if(txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod >= 0)
  2191. {
  2192. DEBUG_INFO("Period-%02d startPeriod: %d\n", idxPeriod, txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod);
  2193. DEBUG_INFO("Period-%02d limit: %f\n", idxPeriod, txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit);
  2194. DEBUG_INFO("Period-%02d NumberPhases: %d\n", idxPeriod, txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases);
  2195. }
  2196. }
  2197. }
  2198. else
  2199. DEBUG_INFO("TxProfile not found.\n");*/
  2200. }
  2201. // Search default tx profile
  2202. sprintf(profileFileName, "/tmp/TxDefaultProfile_%d.json", connectorId);
  2203. if((access(profileFileName, F_OK))==-1)
  2204. sprintf(profileFileName, "/tmp/TxDefaultProfile_0.json");
  2205. if((access(profileFileName, F_OK))!=-1)
  2206. {
  2207. fp = fopen(profileFileName, "r");
  2208. while(getline(&line, &len, fp) != -1)
  2209. {
  2210. json_object *obj = NULL;
  2211. obj = json_tokener_parse(line);
  2212. if(is_error(obj))
  2213. {
  2214. DEBUG_ERROR("Parse TxDefaultProfile from file error.\n");
  2215. }
  2216. else
  2217. {
  2218. if((json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileId")) != defaultTxProfile.ChargingProfileId) &&
  2219. (json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "stackLevel")) >= defaultTxProfile.StackLevel)
  2220. )
  2221. {
  2222. if((json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom") != NULL) &&
  2223. (json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo") != NULL)
  2224. )
  2225. {
  2226. struct tm tmFrom, tmTo;
  2227. struct timeb tbFrom, tbTo;
  2228. 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) &&
  2229. (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))
  2230. {
  2231. tmFrom.tm_year -= 1900;
  2232. tmFrom.tm_mon -= 1;
  2233. tbFrom.time = mktime(&tmFrom);
  2234. tmTo.tm_year -= 1900;
  2235. tmTo.tm_mon -= 1;
  2236. tbTo.time = mktime(&tmTo);
  2237. if((DiffTimebWithNowSec(tbFrom)>=0) && (DiffTimebWithNowSec(tbTo)<=0))
  2238. {
  2239. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  2240. {
  2241. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = -1;
  2242. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit = -1;
  2243. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases = 3;
  2244. }
  2245. defaultTxProfile.ChargingProfileId = -1;
  2246. defaultTxProfile.StackLevel = -1;
  2247. if(defaultTxProfile.ChargingProfileId == -1)
  2248. DEBUG_INFO("TxDefaultProfile found.\n");
  2249. else
  2250. DEBUG_INFO("TxDefaultProfile updated.\n");
  2251. // Required item
  2252. defaultTxProfile.ChargingProfileId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileId"));
  2253. defaultTxProfile.StackLevel = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "stackLevel"));
  2254. sprintf((char*)defaultTxProfile.ChargingProfileKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileKind")));
  2255. if(isUnitA)
  2256. {
  2257. sprintf((char*)defaultTxProfile.ChargingSchedule.ChargingRateUnit, "A");
  2258. 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++)
  2259. {
  2260. 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"));
  2261. 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?
  2262. 3:
  2263. 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")));
  2264. 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")));
  2265. }
  2266. }
  2267. else
  2268. {
  2269. sprintf((char*)defaultTxProfile.ChargingSchedule.ChargingRateUnit, "W");
  2270. 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++)
  2271. {
  2272. 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"));
  2273. 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?
  2274. 3:
  2275. 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")));
  2276. 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));
  2277. }
  2278. }
  2279. // Optional item
  2280. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom") != NULL)
  2281. {
  2282. sprintf((char*)defaultTxProfile.ValidFrom, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom")));
  2283. }
  2284. else
  2285. {
  2286. sprintf((char*)defaultTxProfile.ValidFrom, " ");
  2287. }
  2288. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo") != NULL)
  2289. {
  2290. sprintf((char*)defaultTxProfile.ValidTo, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo")));
  2291. }
  2292. else
  2293. {
  2294. sprintf((char*)defaultTxProfile.ValidTo, " ");
  2295. }
  2296. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "recurrencyKind") != NULL)
  2297. {
  2298. sprintf((char*)defaultTxProfile.RecurrencyKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "recurrencyKind")));
  2299. }
  2300. else
  2301. {
  2302. sprintf((char*)defaultTxProfile.RecurrencyKind, " ");
  2303. }
  2304. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId") != NULL)
  2305. {
  2306. defaultTxProfile.TransactionId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId"));
  2307. }
  2308. else
  2309. {
  2310. defaultTxProfile.TransactionId = -1;
  2311. }
  2312. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration") != NULL)
  2313. {
  2314. defaultTxProfile.ChargingSchedule.Duration = json_object_get_int(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration"));
  2315. }
  2316. else
  2317. {
  2318. defaultTxProfile.ChargingSchedule.Duration = 86400;
  2319. }
  2320. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "startSchedule") != NULL)
  2321. {
  2322. 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")));
  2323. }
  2324. else
  2325. {
  2326. 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));
  2327. }
  2328. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate") != NULL)
  2329. {
  2330. defaultTxProfile.ChargingSchedule.MinChargingRate = json_object_get_double(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate"));
  2331. }
  2332. else
  2333. {
  2334. defaultTxProfile.ChargingSchedule.MinChargingRate = -1;
  2335. }
  2336. }
  2337. }
  2338. }
  2339. else
  2340. {
  2341. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  2342. {
  2343. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = -1;
  2344. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit = -1;
  2345. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases = 3;
  2346. }
  2347. defaultTxProfile.ChargingProfileId = -1;
  2348. defaultTxProfile.StackLevel = -1;
  2349. if(defaultTxProfile.ChargingProfileId == -1)
  2350. DEBUG_INFO("TxDefaultProfile found.\n");
  2351. else
  2352. DEBUG_INFO("TxDefaultProfile updated.\n");
  2353. // Required item
  2354. defaultTxProfile.ChargingProfileId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileId"));
  2355. defaultTxProfile.StackLevel = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "stackLevel"));
  2356. sprintf((char*)defaultTxProfile.ChargingProfileKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileKind")));
  2357. if(isUnitA)
  2358. {
  2359. sprintf((char*)defaultTxProfile.ChargingSchedule.ChargingRateUnit, "A");
  2360. 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++)
  2361. {
  2362. 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"));
  2363. 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?
  2364. 3:
  2365. 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")));
  2366. 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")));
  2367. }
  2368. }
  2369. else
  2370. {
  2371. sprintf((char*)defaultTxProfile.ChargingSchedule.ChargingRateUnit, "W");
  2372. 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++)
  2373. {
  2374. 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"));
  2375. 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?
  2376. 3:
  2377. 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")));
  2378. 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));
  2379. }
  2380. }
  2381. // Optional item
  2382. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom") != NULL)
  2383. {
  2384. sprintf((char*)defaultTxProfile.ValidFrom, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom")));
  2385. }
  2386. else
  2387. {
  2388. sprintf((char*)defaultTxProfile.ValidFrom, " ");
  2389. }
  2390. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo") != NULL)
  2391. {
  2392. sprintf((char*)defaultTxProfile.ValidTo, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo")));
  2393. }
  2394. else
  2395. {
  2396. sprintf((char*)defaultTxProfile.ValidTo, " ");
  2397. }
  2398. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "recurrencyKind") != NULL)
  2399. {
  2400. sprintf((char*)defaultTxProfile.RecurrencyKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "recurrencyKind")));
  2401. }
  2402. else
  2403. {
  2404. sprintf((char*)defaultTxProfile.RecurrencyKind, " ");
  2405. }
  2406. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId") != NULL)
  2407. {
  2408. defaultTxProfile.TransactionId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId"));
  2409. }
  2410. else
  2411. {
  2412. defaultTxProfile.TransactionId = -1;
  2413. }
  2414. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration") != NULL)
  2415. {
  2416. defaultTxProfile.ChargingSchedule.Duration = json_object_get_int(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration"));
  2417. }
  2418. else
  2419. {
  2420. defaultTxProfile.ChargingSchedule.Duration = 86400;
  2421. }
  2422. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "startSchedule") != NULL)
  2423. {
  2424. 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")));
  2425. }
  2426. else
  2427. {
  2428. 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));
  2429. }
  2430. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate") != NULL)
  2431. {
  2432. defaultTxProfile.ChargingSchedule.MinChargingRate = json_object_get_double(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate"));
  2433. }
  2434. else
  2435. {
  2436. defaultTxProfile.ChargingSchedule.MinChargingRate = -1;
  2437. }
  2438. }
  2439. }
  2440. }
  2441. json_object_put(obj);
  2442. }
  2443. fclose(fp);
  2444. /*
  2445. if(defaultTxProfile.ChargingProfileId != -1)
  2446. {
  2447. DEBUG_INFO("Profile ID: %d\n", defaultTxProfile.ChargingProfileId);
  2448. DEBUG_INFO("Profile stackLevel: %d\n", defaultTxProfile.StackLevel);
  2449. DEBUG_INFO("Profile TransactionId: %d\n", defaultTxProfile.TransactionId);
  2450. DEBUG_INFO("Profile valid from: %s\n", defaultTxProfile.ValidFrom);
  2451. DEBUG_INFO("Profile valid to: %s\n", defaultTxProfile.ValidTo);
  2452. DEBUG_INFO("Profile ChargingProfileKind: %s\n", defaultTxProfile.ChargingProfileKind);
  2453. DEBUG_INFO("Profile recurrencyKind: %s\n", defaultTxProfile.RecurrencyKind);
  2454. DEBUG_INFO("Profile start schedule: %s\n", defaultTxProfile.ChargingSchedule.StartSchedule);
  2455. DEBUG_INFO("Profile schedule duration: %d\n", defaultTxProfile.ChargingSchedule.Duration);
  2456. DEBUG_INFO("Profile charging rate unit: %s\n", defaultTxProfile.ChargingSchedule.ChargingRateUnit);
  2457. DEBUG_INFO("Profile charging min rate: %f\n", defaultTxProfile.ChargingSchedule.MinChargingRate);
  2458. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  2459. {
  2460. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod >= 0)
  2461. {
  2462. DEBUG_INFO("Period-%02d startPeriod: %d\n", idxPeriod, defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod);
  2463. DEBUG_INFO("Period-%02d limit: %f\n", idxPeriod, defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit);
  2464. DEBUG_INFO("Period-%02d NumberPhases: %d\n", idxPeriod, defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases);
  2465. }
  2466. }
  2467. }
  2468. else
  2469. DEBUG_INFO("TxDefaultProfile not found.\n");
  2470. DEBUG_INFO("------------------------------------\n");*/
  2471. }
  2472. // Search max profile
  2473. sprintf(profileFileName, "/tmp/ChargePointMaxProfile.json");
  2474. if((access(profileFileName, F_OK))!=-1)
  2475. {
  2476. fp = fopen(profileFileName, "r");
  2477. while(getline(&line, &len, fp) != -1)
  2478. {
  2479. json_object *obj = NULL;
  2480. obj = json_tokener_parse(line);
  2481. if(is_error(obj))
  2482. {
  2483. DEBUG_ERROR("Parse MaxProfile from file error.\n");
  2484. }
  2485. else
  2486. {
  2487. if((json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileId")) != maxProfile.ChargingProfileId) &&
  2488. (json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "stackLevel")) >= maxProfile.StackLevel)
  2489. )
  2490. {
  2491. if((json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom") != NULL) &&
  2492. (json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo") != NULL)
  2493. )
  2494. {
  2495. struct tm tmFrom, tmTo;
  2496. struct timeb tbFrom, tbTo;
  2497. 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) &&
  2498. (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))
  2499. {
  2500. tmFrom.tm_year -= 1900;
  2501. tmFrom.tm_mon -= 1;
  2502. tbFrom.time = mktime(&tmFrom);
  2503. tmTo.tm_year -= 1900;
  2504. tmTo.tm_mon -= 1;
  2505. tbTo.time = mktime(&tmTo);
  2506. if((DiffTimebWithNowSec(tbFrom)>=0) && (DiffTimebWithNowSec(tbTo)<=0))
  2507. {
  2508. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  2509. {
  2510. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = -1;
  2511. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit = -1;
  2512. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases = 3;
  2513. }
  2514. maxProfile.ChargingProfileId = -1;
  2515. maxProfile.StackLevel = -1;
  2516. if(maxProfile.ChargingProfileId == -1)
  2517. DEBUG_INFO("MaxProfile found.\n");
  2518. else
  2519. DEBUG_INFO("MaxProfile updated.\n");
  2520. // Required item
  2521. maxProfile.ChargingProfileId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileId"));
  2522. maxProfile.StackLevel = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "stackLevel"));
  2523. sprintf((char*)maxProfile.ChargingProfileKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileKind")));
  2524. if(isUnitA)
  2525. {
  2526. sprintf((char*)maxProfile.ChargingSchedule.ChargingRateUnit, "A");
  2527. 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++)
  2528. {
  2529. 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"));
  2530. 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?
  2531. 3:
  2532. 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")));
  2533. 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")));
  2534. }
  2535. }
  2536. else
  2537. {
  2538. sprintf((char*)maxProfile.ChargingSchedule.ChargingRateUnit, "W");
  2539. 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++)
  2540. {
  2541. 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"));
  2542. 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?
  2543. 3:
  2544. 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")));
  2545. 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));
  2546. }
  2547. }
  2548. // Optional item
  2549. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom") != NULL)
  2550. {
  2551. sprintf((char*)maxProfile.ValidFrom, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom")));
  2552. }
  2553. else
  2554. {
  2555. sprintf((char*)maxProfile.ValidFrom, " ");
  2556. }
  2557. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo") != NULL)
  2558. {
  2559. sprintf((char*)maxProfile.ValidTo, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo")));
  2560. }
  2561. else
  2562. {
  2563. sprintf((char*)maxProfile.ValidTo, " ");
  2564. }
  2565. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "recurrencyKind") != NULL)
  2566. {
  2567. sprintf((char*)maxProfile.RecurrencyKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "recurrencyKind")));
  2568. }
  2569. else
  2570. {
  2571. sprintf((char*)maxProfile.RecurrencyKind, " ");
  2572. }
  2573. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId") != NULL)
  2574. {
  2575. maxProfile.TransactionId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId"));
  2576. }
  2577. else
  2578. {
  2579. maxProfile.TransactionId = -1;
  2580. }
  2581. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration") != NULL)
  2582. {
  2583. maxProfile.ChargingSchedule.Duration = json_object_get_int(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration"));
  2584. }
  2585. else
  2586. {
  2587. maxProfile.ChargingSchedule.Duration = 86400;
  2588. }
  2589. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "startSchedule") != NULL)
  2590. {
  2591. 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")));
  2592. }
  2593. else
  2594. {
  2595. 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));
  2596. }
  2597. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate") != NULL)
  2598. {
  2599. maxProfile.ChargingSchedule.MinChargingRate = json_object_get_double(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate"));
  2600. }
  2601. else
  2602. {
  2603. maxProfile.ChargingSchedule.MinChargingRate = -1;
  2604. }
  2605. }
  2606. }
  2607. }
  2608. else
  2609. {
  2610. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  2611. {
  2612. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = -1;
  2613. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit = -1;
  2614. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases = 3;
  2615. }
  2616. maxProfile.ChargingProfileId = -1;
  2617. maxProfile.StackLevel = -1;
  2618. if(maxProfile.ChargingProfileId == -1)
  2619. DEBUG_INFO("MaxProfile found.\n");
  2620. else
  2621. DEBUG_INFO("MaxProfile updated.\n");
  2622. // Required item
  2623. maxProfile.ChargingProfileId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileId"));
  2624. maxProfile.StackLevel = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "stackLevel"));
  2625. sprintf((char*)maxProfile.ChargingProfileKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileKind")));
  2626. if(isUnitA)
  2627. {
  2628. sprintf((char*)maxProfile.ChargingSchedule.ChargingRateUnit, "A");
  2629. 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++)
  2630. {
  2631. 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"));
  2632. 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?
  2633. 3:
  2634. 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")));
  2635. 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")));
  2636. }
  2637. }
  2638. else
  2639. {
  2640. sprintf((char*)maxProfile.ChargingSchedule.ChargingRateUnit, "W");
  2641. 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++)
  2642. {
  2643. 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"));
  2644. 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?
  2645. 3:
  2646. 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")));
  2647. 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));
  2648. }
  2649. }
  2650. // Optional item
  2651. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom") != NULL)
  2652. {
  2653. sprintf((char*)maxProfile.ValidFrom, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom")));
  2654. }
  2655. else
  2656. {
  2657. sprintf((char*)maxProfile.ValidFrom, " ");
  2658. }
  2659. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo") != NULL)
  2660. {
  2661. sprintf((char*)maxProfile.ValidTo, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo")));
  2662. }
  2663. else
  2664. {
  2665. sprintf((char*)maxProfile.ValidTo, " ");
  2666. }
  2667. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "recurrencyKind") != NULL)
  2668. {
  2669. sprintf((char*)maxProfile.RecurrencyKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "recurrencyKind")));
  2670. }
  2671. else
  2672. {
  2673. sprintf((char*)maxProfile.RecurrencyKind, " ");
  2674. }
  2675. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId") != NULL)
  2676. {
  2677. maxProfile.TransactionId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId"));
  2678. }
  2679. else
  2680. {
  2681. maxProfile.TransactionId = -1;
  2682. }
  2683. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration") != NULL)
  2684. {
  2685. maxProfile.ChargingSchedule.Duration = json_object_get_int(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration"));
  2686. }
  2687. else
  2688. {
  2689. maxProfile.ChargingSchedule.Duration = 86400;
  2690. }
  2691. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "startSchedule") != NULL)
  2692. {
  2693. 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")));
  2694. }
  2695. else
  2696. {
  2697. 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));
  2698. }
  2699. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate") != NULL)
  2700. {
  2701. maxProfile.ChargingSchedule.MinChargingRate = json_object_get_double(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate"));
  2702. }
  2703. else
  2704. {
  2705. maxProfile.ChargingSchedule.MinChargingRate = -1;
  2706. }
  2707. }
  2708. }
  2709. }
  2710. json_object_put(obj);
  2711. }
  2712. fclose(fp);
  2713. /*
  2714. if(maxProfile.ChargingProfileId !=-1)
  2715. {
  2716. DEBUG_INFO("Profile ID: %d\n", maxProfile.ChargingProfileId);
  2717. DEBUG_INFO("Profile stackLevel: %d\n", maxProfile.StackLevel);
  2718. DEBUG_INFO("Profile TransactionId: %d\n", maxProfile.TransactionId);
  2719. DEBUG_INFO("Profile valid from: %s\n", maxProfile.ValidFrom);
  2720. DEBUG_INFO("Profile valid to: %s\n", maxProfile.ValidTo);
  2721. DEBUG_INFO("Profile ChargingProfileKind: %s\n", maxProfile.ChargingProfileKind);
  2722. DEBUG_INFO("Profile recurrencyKind: %s\n", maxProfile.RecurrencyKind);
  2723. DEBUG_INFO("Profile start schedule: %s\n", maxProfile.ChargingSchedule.StartSchedule);
  2724. DEBUG_INFO("Profile schedule duration: %d\n", maxProfile.ChargingSchedule.Duration);
  2725. DEBUG_INFO("Profile charging rate unit: %s\n", maxProfile.ChargingSchedule.ChargingRateUnit);
  2726. DEBUG_INFO("Profile charging min rate: %f\n", maxProfile.ChargingSchedule.MinChargingRate);
  2727. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  2728. {
  2729. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod >= 0)
  2730. {
  2731. DEBUG_INFO("Period-%02d startPeriod: %d\n", idxPeriod, maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod);
  2732. DEBUG_INFO("Period-%02d limit: %f\n", idxPeriod, maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit);
  2733. DEBUG_INFO("Period-%02d NumberPhases: %d\n", idxPeriod, maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases);
  2734. }
  2735. }
  2736. }
  2737. else
  2738. DEBUG_INFO("MaxProfile not found.\n");
  2739. DEBUG_INFO("------------------------------------\n");*/
  2740. }
  2741. /*
  2742. * Align found profile start schedule & periods
  2743. */
  2744. //DEBUG_INFO("====================================\n");
  2745. /*
  2746. // For local test usage, force modify found profile start schedule info
  2747. 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);
  2748. 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);
  2749. 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);
  2750. */
  2751. if(txProfile.ChargingProfileId != -1)
  2752. {
  2753. if(strstr((char*)txProfile.ChargingProfileKind, "Absolute") != NULL)
  2754. {
  2755. if(txProfile.ChargingSchedule.Duration != -1)
  2756. {
  2757. txProfile.ChargingSchedule.Duration = ((txProfile.ChargingSchedule.Duration-getStartStop(txProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule))<0?
  2758. 0:
  2759. (txProfile.ChargingSchedule.Duration-getStartStop(txProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule)));
  2760. }
  2761. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(txProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  2762. {
  2763. if(txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  2764. {
  2765. txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = ((txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartStop(txProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule))<0?
  2766. 0:
  2767. (txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartStop(txProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule)));
  2768. if(idxPeriod > 0)
  2769. {
  2770. if(txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
  2771. {
  2772. txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit = txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit;
  2773. }
  2774. }
  2775. }
  2776. }
  2777. }
  2778. else if(strstr((char*)txProfile.ChargingProfileKind, "Relative") != NULL)
  2779. {
  2780. if(txProfile.ChargingSchedule.Duration != -1)
  2781. {
  2782. 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?
  2783. 0:
  2784. (txProfile.ChargingSchedule.Duration-getStartStop(ShmOCPP16Data->StartTransaction[(connectorId==0?0:connectorId-1)].Timestamp, compositeProfile->ChargingSchedule.StartSchedule)));
  2785. }
  2786. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(txProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  2787. {
  2788. if(txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  2789. {
  2790. 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?
  2791. 0:
  2792. (txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartStop(ShmOCPP16Data->StartTransaction[(connectorId==0?0:connectorId-1)].Timestamp, compositeProfile->ChargingSchedule.StartSchedule)));
  2793. if(idxPeriod > 0)
  2794. {
  2795. if(txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
  2796. {
  2797. txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit = txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit;
  2798. }
  2799. }
  2800. }
  2801. }
  2802. }
  2803. else
  2804. {
  2805. if(strstr((char*)txProfile.RecurrencyKind, "Weekly") != NULL)
  2806. {
  2807. if(txProfile.ChargingSchedule.Duration != -1)
  2808. {
  2809. txProfile.ChargingSchedule.Duration = ((txProfile.ChargingSchedule.Duration-getStartSinceRecurring(txProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, FALSE))<0?
  2810. 0:
  2811. (txProfile.ChargingSchedule.Duration-getStartSinceRecurring(txProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, FALSE)));
  2812. }
  2813. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(txProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  2814. {
  2815. if(txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  2816. {
  2817. txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = ((txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceRecurring(txProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, FALSE))<0?
  2818. 0:
  2819. (txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceRecurring(txProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, FALSE)));
  2820. if(idxPeriod > 0)
  2821. {
  2822. if(txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
  2823. {
  2824. txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit = txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit;
  2825. }
  2826. }
  2827. }
  2828. }
  2829. }
  2830. else
  2831. {
  2832. if(txProfile.ChargingSchedule.Duration != -1)
  2833. {
  2834. txProfile.ChargingSchedule.Duration = ((txProfile.ChargingSchedule.Duration-getStartSinceRecurring(txProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, TRUE))<0?
  2835. 0:
  2836. (txProfile.ChargingSchedule.Duration-getStartSinceRecurring(txProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, TRUE)));
  2837. }
  2838. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(txProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  2839. {
  2840. if(txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  2841. {
  2842. txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = ((txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceRecurring(txProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, TRUE))<0?
  2843. 0:
  2844. (txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceRecurring(txProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, TRUE)));
  2845. if(idxPeriod > 0)
  2846. {
  2847. if(txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
  2848. {
  2849. txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit = txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit;
  2850. }
  2851. }
  2852. }
  2853. }
  2854. }
  2855. }
  2856. /*
  2857. DEBUG_INFO("txProfile after align.\n");
  2858. DEBUG_INFO("Profile ID: %d\n", txProfile.ChargingProfileId);
  2859. DEBUG_INFO("Profile stackLevel: %d\n", txProfile.StackLevel);
  2860. DEBUG_INFO("Profile TransactionId: %d\n", txProfile.TransactionId);
  2861. DEBUG_INFO("Profile valid from: %s\n", txProfile.ValidFrom);
  2862. DEBUG_INFO("Profile valid to: %s\n", txProfile.ValidTo);
  2863. DEBUG_INFO("Profile ChargingProfileKind: %s\n", txProfile.ChargingProfileKind);
  2864. DEBUG_INFO("Profile recurrencyKind: %s\n", txProfile.RecurrencyKind);
  2865. DEBUG_INFO("Profile start schedule: %s\n", compositeProfile->ChargingSchedule.StartSchedule);
  2866. DEBUG_INFO("Profile schedule duration: %d\n", txProfile.ChargingSchedule.Duration);
  2867. DEBUG_INFO("Profile charging rate unit: %s\n", txProfile.ChargingSchedule.ChargingRateUnit);
  2868. DEBUG_INFO("Profile charging min rate: %f\n", txProfile.ChargingSchedule.MinChargingRate);
  2869. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(txProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  2870. {
  2871. if(txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod >= 0)
  2872. {
  2873. DEBUG_INFO("Period-%02d startPeriod: %d\n", idxPeriod, txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod);
  2874. DEBUG_INFO("Period-%02d limit: %f\n", idxPeriod, txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit);
  2875. DEBUG_INFO("Period-%02d NumberPhases: %d\n", idxPeriod, txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases);
  2876. }
  2877. }*/
  2878. }
  2879. if(defaultTxProfile.ChargingProfileId != -1)
  2880. {
  2881. if(strstr((char*)defaultTxProfile.ChargingProfileKind, "Absolute") != NULL)
  2882. {
  2883. if(defaultTxProfile.ChargingSchedule.Duration != -1)
  2884. {
  2885. defaultTxProfile.ChargingSchedule.Duration = ((defaultTxProfile.ChargingSchedule.Duration-getStartStop(defaultTxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule))<0?
  2886. 0:
  2887. (defaultTxProfile.ChargingSchedule.Duration-getStartStop(defaultTxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule)));
  2888. }
  2889. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  2890. {
  2891. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  2892. {
  2893. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = ((defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartStop(defaultTxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule))<0?
  2894. 0:
  2895. (defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartStop(defaultTxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule)));
  2896. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod < txProfile.ChargingSchedule.Duration)
  2897. {
  2898. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod += (txProfile.ChargingSchedule.Duration-defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod);
  2899. }
  2900. if(idxPeriod > 0)
  2901. {
  2902. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
  2903. {
  2904. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit = defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit;
  2905. }
  2906. }
  2907. }
  2908. }
  2909. }
  2910. else if(strstr((char*)defaultTxProfile.ChargingProfileKind, "Relative") != NULL)
  2911. {
  2912. if(defaultTxProfile.ChargingSchedule.Duration != -1)
  2913. {
  2914. 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?
  2915. 0:
  2916. (defaultTxProfile.ChargingSchedule.Duration-getStartStop(ShmOCPP16Data->StartTransaction[(connectorId==0?0:connectorId-1)].Timestamp, compositeProfile->ChargingSchedule.StartSchedule)));
  2917. }
  2918. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  2919. {
  2920. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  2921. {
  2922. 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?
  2923. 0:
  2924. (defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartStop(ShmOCPP16Data->StartTransaction[(connectorId==0?0:connectorId-1)].Timestamp, compositeProfile->ChargingSchedule.StartSchedule)));
  2925. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod < txProfile.ChargingSchedule.Duration)
  2926. {
  2927. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod += (txProfile.ChargingSchedule.Duration-defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod);
  2928. }
  2929. if(idxPeriod > 0)
  2930. {
  2931. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
  2932. {
  2933. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit = defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit;
  2934. }
  2935. }
  2936. }
  2937. }
  2938. }
  2939. else
  2940. {
  2941. if(strstr((char*)defaultTxProfile.RecurrencyKind, "Weekly") != NULL)
  2942. {
  2943. if(defaultTxProfile.ChargingSchedule.Duration != -1)
  2944. {
  2945. defaultTxProfile.ChargingSchedule.Duration = ((defaultTxProfile.ChargingSchedule.Duration-getStartSinceRecurring(defaultTxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, FALSE))<0?
  2946. 0:
  2947. (defaultTxProfile.ChargingSchedule.Duration-getStartSinceRecurring(defaultTxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, FALSE)));
  2948. }
  2949. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  2950. {
  2951. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  2952. {
  2953. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = ((defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceRecurring(defaultTxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, FALSE))<0?
  2954. 0:
  2955. (defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceRecurring(defaultTxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, FALSE)));
  2956. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod < txProfile.ChargingSchedule.Duration)
  2957. {
  2958. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod += (txProfile.ChargingSchedule.Duration-defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod);
  2959. }
  2960. if(idxPeriod > 0)
  2961. {
  2962. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
  2963. {
  2964. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit = defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit;
  2965. }
  2966. }
  2967. }
  2968. }
  2969. }
  2970. else
  2971. {
  2972. if(defaultTxProfile.ChargingSchedule.Duration != -1)
  2973. {
  2974. defaultTxProfile.ChargingSchedule.Duration = ((defaultTxProfile.ChargingSchedule.Duration-getStartSinceRecurring(defaultTxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, TRUE))<0?
  2975. 0:
  2976. (defaultTxProfile.ChargingSchedule.Duration-getStartSinceRecurring(defaultTxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, TRUE)));
  2977. }
  2978. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  2979. {
  2980. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  2981. {
  2982. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = ((defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceRecurring(defaultTxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, TRUE))<0?
  2983. 0:
  2984. (defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceRecurring(defaultTxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, TRUE)));
  2985. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod < txProfile.ChargingSchedule.Duration)
  2986. {
  2987. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod += (txProfile.ChargingSchedule.Duration-defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod);
  2988. }
  2989. if(idxPeriod > 0)
  2990. {
  2991. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
  2992. {
  2993. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit = defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit;
  2994. }
  2995. }
  2996. }
  2997. }
  2998. }
  2999. }
  3000. /*
  3001. DEBUG_INFO("defaultTxProfile after align.\n");
  3002. DEBUG_INFO("Profile ID: %d\n", defaultTxProfile.ChargingProfileId);
  3003. DEBUG_INFO("Profile stackLevel: %d\n", defaultTxProfile.StackLevel);
  3004. DEBUG_INFO("Profile TransactionId: %d\n", defaultTxProfile.TransactionId);
  3005. DEBUG_INFO("Profile valid from: %s\n", defaultTxProfile.ValidFrom);
  3006. DEBUG_INFO("Profile valid to: %s\n", defaultTxProfile.ValidTo);
  3007. DEBUG_INFO("Profile ChargingProfileKind: %s\n", defaultTxProfile.ChargingProfileKind);
  3008. DEBUG_INFO("Profile recurrencyKind: %s\n", defaultTxProfile.RecurrencyKind);
  3009. DEBUG_INFO("Profile start schedule: %s\n", compositeProfile->ChargingSchedule.StartSchedule);
  3010. DEBUG_INFO("Profile schedule duration: %d\n", defaultTxProfile.ChargingSchedule.Duration);
  3011. DEBUG_INFO("Profile charging rate unit: %s\n", defaultTxProfile.ChargingSchedule.ChargingRateUnit);
  3012. DEBUG_INFO("Profile charging min rate: %f\n", defaultTxProfile.ChargingSchedule.MinChargingRate);
  3013. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  3014. {
  3015. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod >= 0)
  3016. {
  3017. DEBUG_INFO("Period-%02d startPeriod: %d\n", idxPeriod, defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod);
  3018. DEBUG_INFO("Period-%02d limit: %f\n", idxPeriod, defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit);
  3019. DEBUG_INFO("Period-%02d NumberPhases: %d\n", idxPeriod, defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases);
  3020. }
  3021. }
  3022. DEBUG_INFO("------------------------------------\n");*/
  3023. }
  3024. if(maxProfile.ChargingProfileId != -1)
  3025. {
  3026. if(strstr((char*)maxProfile.ChargingProfileKind, "Absolute") != NULL)
  3027. {
  3028. if(maxProfile.ChargingSchedule.Duration != -1)
  3029. {
  3030. maxProfile.ChargingSchedule.Duration = ((maxProfile.ChargingSchedule.Duration-getStartStop(maxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule))<0?
  3031. 0:
  3032. (maxProfile.ChargingSchedule.Duration-getStartStop(maxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule)));
  3033. }
  3034. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  3035. {
  3036. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  3037. {
  3038. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = ((maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartStop(maxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule))<0?
  3039. 0:
  3040. (maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartStop(maxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule)));
  3041. if(idxPeriod > 0)
  3042. {
  3043. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
  3044. {
  3045. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit = maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit;
  3046. }
  3047. }
  3048. }
  3049. }
  3050. }
  3051. else if(strstr((char*)maxProfile.ChargingProfileKind, "Relative") != NULL)
  3052. {
  3053. if(maxProfile.ChargingSchedule.Duration != -1)
  3054. {
  3055. 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?
  3056. 0:
  3057. (maxProfile.ChargingSchedule.Duration-getStartStop(ShmOCPP16Data->StartTransaction[(connectorId==0?0:connectorId-1)].Timestamp, compositeProfile->ChargingSchedule.StartSchedule)));
  3058. }
  3059. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  3060. {
  3061. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  3062. {
  3063. 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?
  3064. 0:
  3065. (maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartStop(ShmOCPP16Data->StartTransaction[(connectorId==0?0:connectorId-1)].Timestamp, compositeProfile->ChargingSchedule.StartSchedule)));
  3066. if(idxPeriod > 0)
  3067. {
  3068. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
  3069. {
  3070. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit = maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit;
  3071. }
  3072. }
  3073. }
  3074. }
  3075. }
  3076. else
  3077. {
  3078. if(strstr((char*)maxProfile.RecurrencyKind, "Weekly") != NULL)
  3079. {
  3080. if(maxProfile.ChargingSchedule.Duration != -1)
  3081. {
  3082. maxProfile.ChargingSchedule.Duration = ((maxProfile.ChargingSchedule.Duration-getStartSinceRecurring(maxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, FALSE))<0?
  3083. 0:
  3084. (maxProfile.ChargingSchedule.Duration-getStartSinceRecurring(maxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, FALSE)));
  3085. }
  3086. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  3087. {
  3088. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  3089. {
  3090. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = ((maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceRecurring(maxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, FALSE))<0?
  3091. 0:
  3092. (maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceRecurring(maxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, FALSE)));
  3093. if(idxPeriod > 0)
  3094. {
  3095. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
  3096. {
  3097. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit = maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit;
  3098. }
  3099. }
  3100. }
  3101. }
  3102. }
  3103. else
  3104. {
  3105. if(maxProfile.ChargingSchedule.Duration != -1)
  3106. {
  3107. maxProfile.ChargingSchedule.Duration = ((maxProfile.ChargingSchedule.Duration-getStartSinceRecurring(maxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, TRUE))<0?
  3108. 0:
  3109. (maxProfile.ChargingSchedule.Duration-getStartSinceRecurring(maxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, TRUE)));
  3110. }
  3111. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  3112. {
  3113. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  3114. {
  3115. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = ((maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceRecurring(maxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, TRUE))<0?
  3116. 0:
  3117. (maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceRecurring(maxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, TRUE)));
  3118. if(idxPeriod > 0)
  3119. {
  3120. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
  3121. {
  3122. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit = maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit;
  3123. }
  3124. }
  3125. }
  3126. }
  3127. }
  3128. }
  3129. /*
  3130. DEBUG_INFO("MaxProfile after align.\n");
  3131. DEBUG_INFO("Profile ID: %d\n", maxProfile.ChargingProfileId);
  3132. DEBUG_INFO("Profile stackLevel: %d\n", maxProfile.StackLevel);
  3133. DEBUG_INFO("Profile TransactionId: %d\n", maxProfile.TransactionId);
  3134. DEBUG_INFO("Profile valid from: %s\n", maxProfile.ValidFrom);
  3135. DEBUG_INFO("Profile valid to: %s\n", maxProfile.ValidTo);
  3136. DEBUG_INFO("Profile ChargingProfileKind: %s\n", maxProfile.ChargingProfileKind);
  3137. DEBUG_INFO("Profile recurrencyKind: %s\n", maxProfile.RecurrencyKind);
  3138. DEBUG_INFO("Profile start schedule: %s\n", compositeProfile->ChargingSchedule.StartSchedule);
  3139. DEBUG_INFO("Profile schedule duration: %d\n", maxProfile.ChargingSchedule.Duration);
  3140. DEBUG_INFO("Profile charging rate unit: %s\n", maxProfile.ChargingSchedule.ChargingRateUnit);
  3141. DEBUG_INFO("Profile charging min rate: %f\n", maxProfile.ChargingSchedule.MinChargingRate);
  3142. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  3143. {
  3144. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod >= 0)
  3145. {
  3146. DEBUG_INFO("Period-%02d startPeriod: %d\n", idxPeriod, maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod);
  3147. DEBUG_INFO("Period-%02d limit: %f\n", idxPeriod, maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit);
  3148. DEBUG_INFO("Period-%02d NumberPhases: %d\n", idxPeriod, maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases);
  3149. }
  3150. }
  3151. DEBUG_INFO("------------------------------------\n");*/
  3152. }
  3153. /*
  3154. * Merge to conposite schedule
  3155. */
  3156. //DEBUG_INFO("====================================\n");
  3157. // Find each profile period quantity
  3158. for(int idx=0;idx<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idx++)
  3159. {
  3160. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idx].Limit != -1)
  3161. limitMax = idx+1;
  3162. }
  3163. for(int idx=0;idx<ARRAY_SIZE(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod);idx++)
  3164. {
  3165. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idx].Limit != -1)
  3166. limitDef = idx+1;
  3167. }
  3168. for(int idx=0;idx<ARRAY_SIZE(txProfile.ChargingSchedule.ChargingSchedulePeriod);idx++)
  3169. {
  3170. if(txProfile.ChargingSchedule.ChargingSchedulePeriod[idx].Limit != -1)
  3171. limitTx = idx+1;
  3172. }
  3173. // TxProfile found, composite schedule based on it
  3174. if(txProfile.ChargingProfileId != -1)
  3175. {
  3176. compositeProfile->ChargingSchedule.Duration = txProfile.ChargingSchedule.Duration;
  3177. for(int idxTxPeriod=0;idxTxPeriod<limitTx;idxTxPeriod++)
  3178. {
  3179. if((txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod].Limit != -1) &&
  3180. (txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod].StartPeriod < durationReq) &&
  3181. (txProfile.ChargingSchedule.Duration > 0))
  3182. {
  3183. if(maxProfile.ChargingProfileId != -1)
  3184. {
  3185. for(int idxMaxPeriod=0;idxMaxPeriod<limitMax;idxMaxPeriod++)
  3186. {
  3187. if((txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod].StartPeriod >= maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].StartPeriod))
  3188. {
  3189. if((maxProfile.ChargingSchedule.Duration > 0))
  3190. {
  3191. tmpPeriod.StartPeriod = txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod].StartPeriod;
  3192. tmpPeriod.NumberPhases = txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod].NumberPhases;
  3193. tmpPeriod.Limit = (txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod].Limit>maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].Limit?maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].Limit:txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod].Limit);
  3194. }
  3195. else
  3196. {
  3197. tmpPeriod.StartPeriod = txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod].StartPeriod;
  3198. tmpPeriod.NumberPhases = txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod].NumberPhases;
  3199. tmpPeriod.Limit = txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod].Limit;
  3200. }
  3201. }
  3202. if(idxMaxPeriod == (limitMax-1))
  3203. {
  3204. if(tmpPeriod.Limit != compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].Limit)
  3205. {
  3206. if(tmpPeriod.StartPeriod != compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].StartPeriod)
  3207. {
  3208. memcpy(&compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx], &tmpPeriod , sizeof(struct StructChargingSchedulePeriod));
  3209. compositePeriodIdx++;
  3210. }
  3211. else
  3212. {
  3213. memcpy(&compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)], &tmpPeriod , sizeof(struct StructChargingSchedulePeriod));
  3214. }
  3215. }
  3216. }
  3217. }
  3218. }
  3219. else
  3220. {
  3221. if(txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod].StartPeriod != compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].StartPeriod)
  3222. {
  3223. memcpy(&compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx], &txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod],sizeof(struct StructChargingSchedulePeriod));
  3224. compositePeriodIdx++;
  3225. }
  3226. else
  3227. {
  3228. memcpy(&compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)], &txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod],sizeof(struct StructChargingSchedulePeriod));
  3229. }
  3230. }
  3231. }
  3232. if(idxTxPeriod == (limitTx-1))
  3233. {
  3234. if(defaultTxProfile.ChargingProfileId != -1)
  3235. {
  3236. compositeProfile->ChargingSchedule.Duration = (defaultTxProfile.ChargingSchedule.Duration>compositeProfile->ChargingSchedule.Duration)?defaultTxProfile.ChargingSchedule.Duration:compositeProfile->ChargingSchedule.Duration;
  3237. for(int idxDefPeriod=0;idxDefPeriod<limitDef;idxDefPeriod++)
  3238. {
  3239. if((defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].StartPeriod >= (txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod].StartPeriod + (txProfile.ChargingSchedule.Duration-defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].StartPeriod))) &&
  3240. (defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].StartPeriod < durationReq) &&
  3241. (defaultTxProfile.ChargingSchedule.Duration>0))
  3242. {
  3243. if(maxProfile.ChargingProfileId != -1)
  3244. {
  3245. for(int idxMaxPeriod=0;idxMaxPeriod<limitMax;idxMaxPeriod++)
  3246. {
  3247. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].StartPeriod >= maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].StartPeriod)
  3248. {
  3249. if((maxProfile.ChargingSchedule.Duration > 0))
  3250. {
  3251. tmpPeriod.StartPeriod = defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].StartPeriod;
  3252. tmpPeriod.NumberPhases = defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].NumberPhases;
  3253. tmpPeriod.Limit = (defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].Limit>maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].Limit?maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].Limit:defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod].Limit);
  3254. }
  3255. else
  3256. {
  3257. tmpPeriod.StartPeriod = defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].StartPeriod;
  3258. tmpPeriod.NumberPhases = defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].NumberPhases;
  3259. tmpPeriod.Limit = defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].Limit;
  3260. }
  3261. if(tmpPeriod.Limit != compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].Limit)
  3262. {
  3263. if(tmpPeriod.StartPeriod != compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].StartPeriod)
  3264. {
  3265. memcpy(&compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx], &tmpPeriod , sizeof(struct StructChargingSchedulePeriod));
  3266. compositePeriodIdx++;
  3267. }
  3268. else
  3269. {
  3270. memcpy(&compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)], &tmpPeriod , sizeof(struct StructChargingSchedulePeriod));
  3271. }
  3272. }
  3273. // Delete duplicate period
  3274. if(compositePeriodIdx > 1)
  3275. {
  3276. if(compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx-1].Limit == compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx-2].Limit)
  3277. {
  3278. compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx-1].StartPeriod = -1;
  3279. compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx-1].Limit = -1;
  3280. compositePeriodIdx -= 1;
  3281. }
  3282. }
  3283. }
  3284. else
  3285. {
  3286. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].StartPeriod != compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].StartPeriod)
  3287. {
  3288. memcpy(&compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx], &defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod],sizeof(struct StructChargingSchedulePeriod));
  3289. compositePeriodIdx++;
  3290. }
  3291. else
  3292. {
  3293. memcpy(&compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)], &defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod],sizeof(struct StructChargingSchedulePeriod));
  3294. }
  3295. break;
  3296. }
  3297. }
  3298. }
  3299. else
  3300. {
  3301. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].StartPeriod != compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].StartPeriod)
  3302. {
  3303. memcpy(&compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx], &defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod],sizeof(struct StructChargingSchedulePeriod));
  3304. compositePeriodIdx++;
  3305. }
  3306. else
  3307. {
  3308. memcpy(&compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)], &defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod],sizeof(struct StructChargingSchedulePeriod));
  3309. }
  3310. }
  3311. }
  3312. }
  3313. }
  3314. }
  3315. }
  3316. }
  3317. // TxProfile not found but defaultTxProfile found, composite schedule based on it
  3318. else if(defaultTxProfile.ChargingProfileId != -1)
  3319. {
  3320. compositeProfile->ChargingSchedule.Duration = defaultTxProfile.ChargingSchedule.Duration;
  3321. for(int idxDefPeriod=0;idxDefPeriod<limitDef;idxDefPeriod++)
  3322. {
  3323. if((defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].Limit != -1) &&
  3324. (defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].StartPeriod < durationReq) &&
  3325. (defaultTxProfile.ChargingSchedule.Duration > 0))
  3326. {
  3327. if(maxProfile.ChargingProfileId != -1)
  3328. {
  3329. for(int idxMaxPeriod=0;idxMaxPeriod<limitMax;idxMaxPeriod++)
  3330. {
  3331. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].StartPeriod >= maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].StartPeriod)
  3332. {
  3333. tmpPeriod.StartPeriod = defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].StartPeriod;
  3334. tmpPeriod.NumberPhases = defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].NumberPhases;
  3335. if((maxProfile.ChargingSchedule.Duration > 0))
  3336. {
  3337. tmpPeriod.Limit = (defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].Limit>maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].Limit?maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].Limit:defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].Limit);
  3338. }
  3339. else
  3340. {
  3341. tmpPeriod.Limit = defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].Limit;
  3342. }
  3343. if(tmpPeriod.Limit != compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].Limit)
  3344. {
  3345. if(tmpPeriod.StartPeriod != compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].StartPeriod)
  3346. {
  3347. memcpy(&compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx], &tmpPeriod , sizeof(struct StructChargingSchedulePeriod));
  3348. compositePeriodIdx++;
  3349. }
  3350. else
  3351. {
  3352. memcpy(&compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)], &tmpPeriod , sizeof(struct StructChargingSchedulePeriod));
  3353. }
  3354. }
  3355. // Delete duplicate period
  3356. if(compositePeriodIdx > 1)
  3357. {
  3358. if(compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx-1].Limit == compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx-2].Limit)
  3359. {
  3360. compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx-1].StartPeriod = -1;
  3361. compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx-1].Limit = -1;
  3362. compositePeriodIdx -= 1;
  3363. }
  3364. }
  3365. }
  3366. else
  3367. {
  3368. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].StartPeriod != compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].StartPeriod)
  3369. {
  3370. memcpy(&compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx], &defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod],sizeof(struct StructChargingSchedulePeriod));
  3371. compositePeriodIdx++;
  3372. }
  3373. else
  3374. {
  3375. memcpy(&compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)], &defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod],sizeof(struct StructChargingSchedulePeriod));
  3376. }
  3377. break;
  3378. }
  3379. }
  3380. }
  3381. else
  3382. {
  3383. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].StartPeriod != compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].StartPeriod)
  3384. {
  3385. memcpy(&compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx], &defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod],sizeof(struct StructChargingSchedulePeriod));
  3386. compositePeriodIdx++;
  3387. }
  3388. else
  3389. {
  3390. memcpy(&compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)], &defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod],sizeof(struct StructChargingSchedulePeriod));
  3391. }
  3392. }
  3393. }
  3394. }
  3395. }
  3396. // Fill other period by MaxProfile
  3397. if(maxProfile.ChargingProfileId != -1)
  3398. {
  3399. if(compositePeriodIdx==0)
  3400. {
  3401. compositeProfile->ChargingSchedule.Duration = maxProfile.ChargingSchedule.Duration;
  3402. for(int idxMaxPeriod=0;idxMaxPeriod<limitDef;idxMaxPeriod++)
  3403. {
  3404. if((maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].Limit != -1) &&
  3405. (maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].StartPeriod < durationReq) &&
  3406. (maxProfile.ChargingSchedule.Duration > 0))
  3407. {
  3408. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].StartPeriod != compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].StartPeriod)
  3409. {
  3410. memcpy(&compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx], &maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod],sizeof(struct StructChargingSchedulePeriod));
  3411. compositePeriodIdx++;
  3412. }
  3413. else
  3414. {
  3415. memcpy(&compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)], &maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod],sizeof(struct StructChargingSchedulePeriod));
  3416. }
  3417. }
  3418. }
  3419. }
  3420. else
  3421. {
  3422. int lastCompositePeriodIdx = compositePeriodIdx;
  3423. for(int idxMaxPeriod=0;idxMaxPeriod<limitMax;idxMaxPeriod++)
  3424. {
  3425. if((maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].Limit != -1) &&
  3426. (maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].StartPeriod < durationReq) &&
  3427. (maxProfile.ChargingSchedule.Duration > 0))
  3428. {
  3429. if((maxProfile.ChargingSchedule.Duration >= compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx-1].StartPeriod))
  3430. {
  3431. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].Limit > compositeProfile->ChargingSchedule.ChargingSchedulePeriod[lastCompositePeriodIdx-1].Limit)
  3432. {
  3433. tmpPeriod.StartPeriod = maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].StartPeriod;
  3434. tmpPeriod.NumberPhases = maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].NumberPhases;
  3435. tmpPeriod.Limit = compositeProfile->ChargingSchedule.ChargingSchedulePeriod[lastCompositePeriodIdx-1].Limit;
  3436. }
  3437. else
  3438. {
  3439. tmpPeriod.StartPeriod = maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].StartPeriod;
  3440. tmpPeriod.NumberPhases = maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].NumberPhases;
  3441. tmpPeriod.Limit = maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].Limit;
  3442. }
  3443. }
  3444. if(tmpPeriod.Limit != -1)
  3445. {
  3446. if(tmpPeriod.Limit != compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx-1].Limit)
  3447. {
  3448. if(tmpPeriod.StartPeriod != compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx-1].StartPeriod)
  3449. {
  3450. memcpy(&compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx], &tmpPeriod , sizeof(struct StructChargingSchedulePeriod));
  3451. compositePeriodIdx++;
  3452. }
  3453. else
  3454. {
  3455. memcpy(&compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx-1], &tmpPeriod , sizeof(struct StructChargingSchedulePeriod));
  3456. }
  3457. }
  3458. // Delete duplicate period
  3459. if(compositePeriodIdx > 1)
  3460. {
  3461. if(compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx-1].Limit == compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx-2].Limit)
  3462. {
  3463. compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx-1].StartPeriod = -1;
  3464. compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx-1].Limit = -1;
  3465. compositePeriodIdx -= 1;
  3466. }
  3467. }
  3468. }
  3469. }
  3470. }
  3471. }
  3472. }
  3473. compositeProfile->ChargingSchedule.Duration = durationReq;
  3474. DEBUG_INFO("Connector-%d composite schedule ready.\n", connectorId);
  3475. DEBUG_INFO("Schedule start: %s\n", compositeProfile->ChargingSchedule.StartSchedule);
  3476. DEBUG_INFO("Schedule duration: %d\n", compositeProfile->ChargingSchedule.Duration);
  3477. DEBUG_INFO("Rate unit: %s\n", compositeProfile->ChargingSchedule.ChargingRateUnit);
  3478. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(compositeProfile->ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  3479. {
  3480. if(compositeProfile->ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod >= 0)
  3481. {
  3482. compositeProfile->ChargingProfileId = 1;
  3483. DEBUG_INFO("Period-%02d startPeriod: %d\n", idxPeriod, compositeProfile->ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod);
  3484. DEBUG_INFO("Period-%02d limit: %f\n", idxPeriod, compositeProfile->ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit);
  3485. DEBUG_INFO("Period-%02d NumberPhases: %d\n", idxPeriod, compositeProfile->ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases);
  3486. }
  3487. if(compositeProfile->ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit == -1)
  3488. compositeProfile->ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit =0;
  3489. if(compositeProfile->ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod == -1)
  3490. compositeProfile->ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod =0;
  3491. }
  3492. if(line)
  3493. free(line);
  3494. checkChargePointMaxProfile(durationReq, &ShmOCPP16Data->MaxChargingProfile, isUnitA);
  3495. ShmOCPP16Data->CSUMsg.bits[(connectorId==0?0:connectorId-1)].ChargingProfileConf = 1;
  3496. }
  3497. //==========================================
  3498. // Init all share memory
  3499. //==========================================
  3500. int InitShareMemory()
  3501. {
  3502. int result = PASS;
  3503. int MeterSMId;
  3504. //creat ShmSysConfigAndInfo
  3505. if ((MeterSMId = shmget(ShmSysConfigAndInfoKey, sizeof(struct SysConfigAndInfo), 0777)) < 0)
  3506. {
  3507. DEBUG_ERROR("shmget ShmSysConfigAndInfo NG\n");
  3508. result = FAIL;
  3509. }
  3510. else if ((ShmSysConfigAndInfo = shmat(MeterSMId, NULL, 0)) == (void *) -1)
  3511. {
  3512. DEBUG_ERROR("shmat ShmSysConfigAndInfo NG\n");
  3513. result = FAIL;
  3514. }
  3515. else
  3516. {}
  3517. if ((MeterSMId = shmget(ShmStatusCodeKey, sizeof(struct StatusCodeData), 0777)) < 0)
  3518. {
  3519. DEBUG_ERROR("shmget ShmStatusCodeData NG\n");
  3520. result = FAIL;
  3521. }
  3522. else if ((ShmStatusCodeData = shmat(MeterSMId, NULL, 0)) == (void *) -1)
  3523. {
  3524. DEBUG_ERROR("shmat ShmStatusCodeData NG\n");
  3525. result = FAIL;
  3526. }
  3527. else
  3528. {}
  3529. //creat ShmPsuData
  3530. if ((MeterSMId = shmget(ShmPsuKey, sizeof(struct PsuData), 0777)) < 0)
  3531. {
  3532. DEBUG_ERROR("shmget ShmPsuData NG\n");
  3533. result = FAIL;
  3534. }
  3535. else if ((ShmPsuData = shmat(MeterSMId, NULL, 0)) == (void *) -1)
  3536. {
  3537. DEBUG_ERROR("shmat ShmPsuData NG\n");
  3538. result = FAIL;
  3539. }
  3540. else
  3541. {}
  3542. //creat ShmOCPP16Data
  3543. if ((MeterSMId = shmget(ShmOcppModuleKey, sizeof(struct OCPP16Data), 0777)) < 0)
  3544. {
  3545. DEBUG_ERROR("shmget ShmOCPP16Data NG\n");
  3546. result = FAIL;
  3547. }
  3548. else if ((ShmOCPP16Data = shmat(MeterSMId, NULL, 0)) == (void *) -1)
  3549. {
  3550. DEBUG_ERROR("shmat ShmOCPP16Data NG\n");
  3551. result = FAIL;
  3552. }
  3553. else
  3554. {}
  3555. /****************************** For Initial Settings************************************************/
  3556. ShmOCPP16Data->GetConfiguration.ResponseUnknownKey = NULL;
  3557. ShmOCPP16Data->SendLocalList.LocalAuthorizationList = NULL;
  3558. // allocate Configuration memory address
  3559. ShmOCPP16Data->GetConfiguration.Key = staticKeyArray;
  3560. ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey = staticResponseConfigurationKeyArray;
  3561. ShmOCPP16Data->GetConfiguration.ResponseUnknownKey = staticResponseUnknownKey;
  3562. ShmOCPP16Data->SendLocalList.LocalAuthorizationList = staticLocalAuthorizationList;
  3563. //offline MeterValue Interval
  3564. TempMeterValueInterval = 0;
  3565. return result;
  3566. }
  3567. int ProcessShareMemory()
  3568. {
  3569. int result = PASS;
  3570. if(InitShareMemory() == FAIL)
  3571. {
  3572. DEBUG_ERROR("InitShareMemory NG\n");
  3573. if(ShmStatusCodeData!=NULL)
  3574. {
  3575. ShmStatusCodeData->AlarmCode.AlarmEvents.bits.FailToCreateShareMemory=1;
  3576. }
  3577. result = FAIL;
  3578. }
  3579. // Model name parsing
  3580. if(RatedCurrentParsing((char*)ShmSysConfigAndInfo->SysConfig.ModelName, &modelnameInfo) != -1)
  3581. {
  3582. DEBUG_INFO("Model name rated power: %d\n", modelnameInfo.ratedPower);
  3583. if((ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D') &&
  3584. ((ShmSysConfigAndInfo->SysConfig.ModelName[1]=='B') ||
  3585. (ShmSysConfigAndInfo->SysConfig.ModelName[1]=='K') ||
  3586. (ShmSysConfigAndInfo->SysConfig.ModelName[1]=='O'))
  3587. ) // 'D' means DC
  3588. {
  3589. // DO series
  3590. for(int gun_index=0; gun_index<GENERAL_GUN_QUANTITY ; gun_index++)
  3591. {
  3592. SystemInitial += 1;
  3593. gunTotalNumber += 1;
  3594. gunType[gun_index] = GUN_TYPE_DO;
  3595. switch(modelnameInfo.ParsingInfo[gun_index].GunType)
  3596. {
  3597. case Gun_Type_Chademo:
  3598. DEBUG_INFO("Gun-%02d type: Cabinet CHAdeMO\n", gun_index);
  3599. break;
  3600. case Gun_Type_CCS_2:
  3601. DEBUG_INFO("Gun-%02d type: Cabinet CCS\n", gun_index);
  3602. break;
  3603. case Gun_Type_GB:
  3604. DEBUG_INFO("Gun-%02d type: Cabinet GBT\n", gun_index);
  3605. break;
  3606. case Gun_Type_AC:
  3607. DEBUG_INFO("Gun-%02d type: Cabinet AC\n", gun_index);
  3608. break;
  3609. default:
  3610. DEBUG_WARN("Gun-%02d type: Cabinet unknown\n", gun_index);
  3611. break;
  3612. }
  3613. }
  3614. }
  3615. else
  3616. {
  3617. for(int gun_index=0;gun_index<modelnameInfo.GetGunCount;gun_index++)
  3618. {
  3619. SystemInitial += 1;
  3620. gunTotalNumber += 1;
  3621. switch(modelnameInfo.ParsingInfo[gun_index].GunType)
  3622. {
  3623. case Gun_Type_Chademo:
  3624. gunType[gun_index] = GUN_TYPE_CHAdeMO;
  3625. DEBUG_INFO("Gun-%02d type: CHAdeMO\n", gun_index);
  3626. break;
  3627. case Gun_Type_CCS_2:
  3628. gunType[gun_index] = GUN_TYPE_CCS;
  3629. DEBUG_INFO("Gun-%02d type: CCS\n", gun_index);
  3630. break;
  3631. case Gun_Type_GB:
  3632. gunType[gun_index] = GUN_TYPE_GBT;
  3633. DEBUG_INFO("Gun-%02d type: GBT\n", gun_index);
  3634. break;
  3635. case Gun_Type_AC:
  3636. gunType[gun_index] = GUN_TYPE_AC;
  3637. DEBUG_INFO("Gun-%02d type: AC\n", gun_index);
  3638. break;
  3639. default:
  3640. DEBUG_WARN("Gun-%02d type: Unknown\n", gun_index);
  3641. break;
  3642. }
  3643. }
  3644. }
  3645. }
  3646. else
  3647. {
  3648. DEBUG_ERROR("Model name parsing fail.\n");
  3649. result = FAIL;
  3650. }
  3651. if(result != PASS)sleep(5);
  3652. return result;
  3653. }
  3654. void checkRemoteStart(uint8_t connectorIdInt)
  3655. {
  3656. uint8_t tempIndex;
  3657. int result = PASS;
  3658. char cmdBuf[512];
  3659. //check Transaction active
  3660. if(gunType[connectorIdInt -1] == GUN_TYPE_CHAdeMO)
  3661. {
  3662. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  3663. {
  3664. tempIndex = ((connectorIdInt -1) == 2) ? 1: 0;
  3665. }
  3666. else
  3667. {
  3668. tempIndex = connectorIdInt -1;
  3669. }
  3670. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  3671. {
  3672. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  3673. {
  3674. if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ReservationId != -1) &&
  3675. (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ReservationId >= 0) &&
  3676. (strcmp((const char *)ShmOCPP16Data->ReserveNow[index].IdTag, (char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag) == 0))
  3677. {
  3678. //Reserved
  3679. DEBUG_INFO("CHAdeMO connector already reserved and idTag match.\n");
  3680. }
  3681. else if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ReservationId != -1) &&
  3682. (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ReservationId >= 0) &&
  3683. (strcmp((const char *)ShmOCPP16Data->ReserveNow[index].IdTag, (char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag) != 0))
  3684. {
  3685. //Reserved
  3686. DEBUG_INFO("CHAdeMO connector already reserved and idTag does not match.\n");
  3687. result = FAIL;
  3688. goto end;
  3689. }
  3690. else
  3691. {
  3692. if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  3693. && (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_PREPARING ) //S_PRECHARGE
  3694. && (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EV ) //S_PREPARING_FOR_EV
  3695. && (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EVSE )) // S_PREPARING_FOR_EVSE
  3696. {
  3697. DEBUG_WARN("CHAdeMO connector not allow start cause busy.\n");
  3698. result = FAIL;
  3699. goto end;
  3700. }
  3701. }//END FOR ELSE
  3702. }
  3703. }// END FOR CHAdeMO_QUANTITY
  3704. }
  3705. else if(gunType[connectorIdInt -1] == GUN_TYPE_CCS)
  3706. {
  3707. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  3708. {
  3709. tempIndex = ((connectorIdInt -1) == 2) ? 1: 0;
  3710. }
  3711. else
  3712. {
  3713. tempIndex = connectorIdInt -1;
  3714. }
  3715. for (int index = 0; index < CCS_QUANTITY; index++)
  3716. {
  3717. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  3718. {
  3719. if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ReservationId != -1) &&
  3720. (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ReservationId >= 0) &&
  3721. (strcmp((const char *)ShmOCPP16Data->ReserveNow[index].IdTag, (char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag) == 0))
  3722. {
  3723. //Reserved
  3724. DEBUG_INFO("CCS connector already reserved and idTag match.\n");
  3725. }
  3726. else if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ReservationId != -1) &&
  3727. (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ReservationId >= 0) &&
  3728. (strcmp((const char *)ShmOCPP16Data->ReserveNow[index].IdTag, (char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag) != 0))
  3729. {
  3730. //Reserved
  3731. DEBUG_INFO("CCS connector already reserved and idTag does not match.\n");
  3732. result = FAIL;
  3733. goto end;
  3734. }
  3735. else
  3736. {
  3737. if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  3738. && (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_PREPARING) //S_PRECHARGE
  3739. && (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EV) //S_PREPARING_FOR_EV
  3740. && (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EVSE)) // S_PREPARING_FOR_EVSE
  3741. {
  3742. DEBUG_WARN("CCS connector not allow start cause busy.\n.");
  3743. result = FAIL;
  3744. goto end;
  3745. }
  3746. }// END FOR ELSE
  3747. }
  3748. }// END FOR CCS_QUANTITY
  3749. }
  3750. else if(gunType[connectorIdInt -1] == GUN_TYPE_GBT)
  3751. {
  3752. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  3753. {
  3754. tempIndex = ((connectorIdInt -1) == 2) ? 1: 0;
  3755. }
  3756. else
  3757. {
  3758. tempIndex = connectorIdInt -1;
  3759. }
  3760. for (int index = 0; index < GB_QUANTITY; index++)
  3761. {
  3762. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex )
  3763. {
  3764. if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ReservationId != -1) &&
  3765. (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ReservationId >= 0) &&
  3766. (strcmp((const char *)ShmOCPP16Data->ReserveNow[index].IdTag, (char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag) == 0))
  3767. {
  3768. //Reserved
  3769. DEBUG_INFO("GBT connector already reserved and idTag match.\n");
  3770. }
  3771. else if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ReservationId != -1) &&
  3772. (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ReservationId >= 0) &&
  3773. (strcmp((const char *)ShmOCPP16Data->ReserveNow[index].IdTag, (char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag) != 0))
  3774. {
  3775. //Reserved
  3776. DEBUG_INFO("GBT connector already reserved and idTag does not match.\n");
  3777. result = FAIL;
  3778. goto end;
  3779. }
  3780. else
  3781. {
  3782. if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  3783. && (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_PREPARING) //S_PRECHARGE
  3784. && (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EV) //S_PREPARING_FOR_EV
  3785. && (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EVSE)) // S_PREPARING_FOR_EVSE
  3786. {
  3787. DEBUG_WARN("GBT connector not allow start cause busy.\n");
  3788. result = FAIL;
  3789. goto end;
  3790. }
  3791. }// END FOR ELSE
  3792. }
  3793. } // END FOR GB_QUANTITY
  3794. }
  3795. else if(gunType[connectorIdInt -1] == GUN_TYPE_DO)
  3796. {
  3797. tempIndex = connectorIdInt -1;
  3798. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  3799. {
  3800. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex )
  3801. {
  3802. if((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.ReservationId != -1) &&
  3803. (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.ReservationId >= 0) &&
  3804. (strcmp((const char *)ShmOCPP16Data->ReserveNow[index].IdTag, (char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag) == 0))
  3805. {
  3806. //Reserved
  3807. DEBUG_INFO("Dispenser connector already reserved and idTag match.\n");
  3808. }
  3809. else if((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.ReservationId != -1) &&
  3810. (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.ReservationId >= 0) &&
  3811. (strcmp((const char *)ShmOCPP16Data->ReserveNow[index].IdTag, (char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag) != 0))
  3812. {
  3813. //Reserved
  3814. DEBUG_INFO("Dispenser connector already reserved and idTag does not match.\n");
  3815. result = FAIL;
  3816. goto end;
  3817. }
  3818. else
  3819. {
  3820. if((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus != SYS_MODE_IDLE) //S_IDLE
  3821. && (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus != SYS_MODE_PREPARING) //S_PRECHARGE
  3822. && (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus != SYS_MODE_PREPARE_FOR_EV) //S_PREPARING_FOR_EV
  3823. && (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus != SYS_MODE_PREPARE_FOR_EVSE)) // S_PREPARING_FOR_EVSE
  3824. {
  3825. DEBUG_WARN("Dispenser connector not allow start cause busy.\n");
  3826. result = FAIL;
  3827. goto end;
  3828. }
  3829. }// END FOR ELSE
  3830. }
  3831. } // END FOR GB_QUANTITY
  3832. }
  3833. else
  3834. {
  3835. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D') // 'D' means DC
  3836. {
  3837. tempIndex = 2;
  3838. }
  3839. else
  3840. {
  3841. tempIndex = connectorIdInt -1;
  3842. }
  3843. for (int index = 0; index < AC_QUANTITY; index++)
  3844. {
  3845. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex )
  3846. {
  3847. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].ReservationId != -1) &&
  3848. (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].ReservationId >= 0) &&
  3849. (strcmp((const char *)ShmOCPP16Data->ReserveNow[index].IdTag, (char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag) == 0))
  3850. {
  3851. //Reserved
  3852. DEBUG_INFO("AC connector already reserved and idTag match.\n");
  3853. }
  3854. else if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].ReservationId != -1) &&
  3855. (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].ReservationId >= 0) &&
  3856. (strcmp((const char *)ShmOCPP16Data->ReserveNow[index].IdTag, (char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag) != 0))
  3857. {
  3858. //Reserved
  3859. DEBUG_INFO("AC connector already reserved and idTag does not match.\n");
  3860. result = FAIL;
  3861. goto end;
  3862. }
  3863. else
  3864. {
  3865. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  3866. && (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_PREPARING) //S_PRECHARGE
  3867. && (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EV) //S_PREPARING_FOR_EV
  3868. && (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EVSE)) // S_PREPARING_FOR_EVSE
  3869. {
  3870. DEBUG_WARN("AC connector not allow start cause busy.\n");
  3871. result = FAIL;
  3872. goto end;
  3873. }
  3874. }//END FOR ELSE
  3875. }
  3876. }// END FOR AC_QUANTITY
  3877. }
  3878. if(ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingProfileId > -1)
  3879. {
  3880. if(strcmp((char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingProfilePurpose, ChargingProfilePurposeTypeStr[TxProfile]) == 0)
  3881. {
  3882. if((access("/Storage/OCPP/TxProfile_Tmp.json", F_OK))!=-1)
  3883. {
  3884. sprintf(cmdBuf, "mv /Storage/OCPP/TxProfile_Tmp.json /Storage/OCPP/TxProfile_%d.json", connectorIdInt);
  3885. system(cmdBuf);
  3886. }
  3887. }
  3888. else
  3889. {
  3890. DEBUG_WARN("Profile purpose not TxProfile.\n.");
  3891. result = FAIL;
  3892. }
  3893. }
  3894. end:
  3895. if(result == PASS)
  3896. {
  3897. ShmOCPP16Data->CsMsg.bits[connectorIdInt -1].RemoteStartTransactionReq = 1;
  3898. memset((char *)ShmOCPP16Data->StartTransaction[connectorIdInt -1].IdTag, 0, 20);
  3899. strcpy((char *)ShmOCPP16Data->StartTransaction[connectorIdInt -1].IdTag, (char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag);
  3900. memset((char *)ShmOCPP16Data->StopTransaction[connectorIdInt -1].IdTag, 0, 20);
  3901. strcpy((char *)ShmOCPP16Data->StopTransaction[connectorIdInt -1].IdTag, (char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag);
  3902. }
  3903. }
  3904. void CheckSystemValue(void)
  3905. {
  3906. char filenmae[100]={0};
  3907. char str[100]={0};
  3908. int tempIndex = 0;
  3909. //===============================
  3910. // send Heartbeat
  3911. //===============================
  3912. if((server_sign == TRUE) && (getDiffSecNow(clientTime.Heartbeat) >= (HeartBeatWaitTime + HeartBeatWithNOResponse)))
  3913. {
  3914. //parameter for test
  3915. sendHeartbeatRequest(0);
  3916. //==============================================
  3917. // Reset Waiting Time
  3918. //==============================================
  3919. HeartBeatWithNOResponse += 1;
  3920. }
  3921. //===============================
  3922. // send YES CallReader
  3923. //===============================
  3924. if(isWebsocketSendable && (server_sign == TRUE) && (ShmOCPP16Data->YesCustomData.CallReaderReq == 1) && (getDiffSecNow(clientTime.YesCustomCallReader) >= 5))
  3925. {
  3926. sprintf((char*)ShmOCPP16Data->DataTransfer[0].VendorId, "%s", ShmSysConfigAndInfo->SysConfig.chargePointVendor);
  3927. sprintf((char*)ShmOCPP16Data->DataTransfer[0].MessageId,"call_reader");
  3928. sprintf((char*)ShmOCPP16Data->DataTransfer[0].Data," ");
  3929. ShmOCPP16Data->CsMsg.bits[0].DataTransferReq = 1;
  3930. //ShmOCPP16Data->YesCustomData.CallReaderReq = 0;
  3931. refreshStartTimer(&clientTime.YesCustomCallReader);
  3932. }
  3933. for(int gun_index=0;gun_index < gunTotalNumber;gun_index++)
  3934. {
  3935. // ClockAlign MeterValue
  3936. if(isWebsocketSendable && (server_sign == TRUE) && ((atoi((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemData) > 0)?((getTimePassSinceToday(gun_index)%(atoi((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemData)))==0):FALSE))
  3937. {
  3938. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  3939. {
  3940. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  3941. {
  3942. tempIndex = ((gun_index==2) ? 1: 0);
  3943. }
  3944. else
  3945. {
  3946. tempIndex = gun_index;
  3947. }
  3948. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  3949. {
  3950. // 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault
  3951. if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  3952. {
  3953. reqClockAlignMeter[gun_index] = 1;
  3954. }
  3955. }// End for CHAdeMO
  3956. }
  3957. else if(gunType[gun_index] == GUN_TYPE_CCS)
  3958. {
  3959. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  3960. {
  3961. tempIndex = ((gun_index==2) ? 1: 0);
  3962. }
  3963. else
  3964. {
  3965. tempIndex = gun_index;
  3966. }
  3967. for (int index = 0; index < CCS_QUANTITY; index++)
  3968. {
  3969. // 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault
  3970. if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  3971. {
  3972. reqClockAlignMeter[gun_index] = 1;
  3973. }
  3974. } // End for CCS
  3975. }
  3976. else if(gunType[gun_index] == GUN_TYPE_GBT)
  3977. {
  3978. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  3979. {
  3980. tempIndex = ((gun_index==2) ? 1: 0);
  3981. }
  3982. else
  3983. {
  3984. tempIndex = gun_index;
  3985. }
  3986. for (int index = 0; index < GB_QUANTITY; index++)
  3987. {
  3988. // 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault
  3989. if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  3990. {
  3991. reqClockAlignMeter[gun_index] = 1;
  3992. }
  3993. }// End for GB
  3994. }
  3995. else if(gunType[gun_index] == GUN_TYPE_DO)
  3996. {
  3997. tempIndex = gun_index;
  3998. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  3999. {
  4000. // 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault
  4001. if(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  4002. {
  4003. reqClockAlignMeter[gun_index] = 1;
  4004. }
  4005. }
  4006. }
  4007. else
  4008. {
  4009. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  4010. {
  4011. tempIndex = 2;
  4012. }
  4013. else
  4014. {
  4015. tempIndex = gun_index;
  4016. }
  4017. for (int index = 0; index < AC_QUANTITY; index++)
  4018. {
  4019. // 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault
  4020. if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  4021. {
  4022. reqClockAlignMeter[gun_index] = 1;
  4023. }
  4024. }//End for AC
  4025. }
  4026. }
  4027. }
  4028. for(int gun_index=0;gun_index < gunTotalNumber ;gun_index++)
  4029. {
  4030. //==========================================
  4031. // Check remote start without connector id
  4032. //==========================================
  4033. if(ShmOCPP16Data->MsMsg.bits.isRemoteStartWaitReq)
  4034. {
  4035. int connectorIdInt = -1;
  4036. for(uint8_t gun_index=0;gun_index<gunTotalNumber;gun_index++)
  4037. {
  4038. if(!cpinitateMsg.bits[gun_index].isOnCharging && (strstr((char*)ShmOCPP16Data->StatusNotification[gun_index].Status, "Preparing") != NULL))
  4039. {
  4040. connectorIdInt = (gun_index+1);
  4041. DEBUG_INFO("Detect connector-%02d connected ready to start.\n", connectorIdInt);
  4042. checkRemoteStart(connectorIdInt);
  4043. ShmOCPP16Data->MsMsg.bits.isRemoteStartWaitReq = 0;
  4044. break;
  4045. }
  4046. }
  4047. if(getDiffSecNow(clientTime.RemoteStartWait) > atoi((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemData))
  4048. {
  4049. DEBUG_WARN("Remote start request without connector id wait link over %s seconds.\n", ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemData);
  4050. ShmOCPP16Data->MsMsg.bits.isRemoteStartWaitReq = 0;
  4051. }
  4052. }
  4053. //==========================================
  4054. // csu trigger DataTransferReq
  4055. //==========================================
  4056. if(isWebsocketSendable && (server_sign == TRUE) && (ShmOCPP16Data->CsMsg.bits[gun_index].DataTransferReq == 1))
  4057. {
  4058. sendDataTransferRequest(gun_index);
  4059. ShmOCPP16Data->CsMsg.bits[gun_index].DataTransferReq = 0;
  4060. }
  4061. //==========================================
  4062. // CSU Trigger Authorize Request
  4063. //==========================================
  4064. if(isWebsocketSendable && (server_sign == TRUE) && (ShmOCPP16Data->SpMsg.bits.AuthorizeReq == 1)&&(authorizeRetryTimes < 3))
  4065. {
  4066. sendAuthorizeRequest(0);
  4067. authorizeRetryTimes = authorizeRetryTimes + 1;
  4068. if(authorizeRetryTimes < 3)
  4069. ShmOCPP16Data->SpMsg.bits.AuthorizeReq = 0;
  4070. }
  4071. else if((server_sign == TRUE) && (ShmOCPP16Data->SpMsg.bits.AuthorizeReq == 1) && (authorizeRetryTimes >= 3))
  4072. {
  4073. authorizeRetryTimes = 0;
  4074. SetOcppConnStatus(FALSE);
  4075. server_sign = FALSE;
  4076. }
  4077. 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))
  4078. {
  4079. sendAuthorizeRequest(0);
  4080. }
  4081. //==========================================
  4082. // Charger start transaction
  4083. //==========================================
  4084. if(/*(server_sign == TRUE) &&*/ (ShmOCPP16Data->CpMsg.bits[gun_index].StartTransactionReq == 1))
  4085. {
  4086. ShmOCPP16Data->CpMsg.bits[gun_index].StartTransactionReq = 0;
  4087. sendStartTransactionRequest(gun_index);
  4088. refreshStartTimer(&clientTime.StartTransaction);
  4089. refreshStartTimer(&clientTime.MeterValues[gun_index]);
  4090. storeTempStopTransaction(gun_index);
  4091. }
  4092. //==========================================
  4093. // Charger stop transaction
  4094. //==========================================
  4095. if(/*(server_sign == TRUE) &&*/ ((ShmOCPP16Data->CpMsg.bits[gun_index].StopTransactionReq == 1)))
  4096. {
  4097. ShmOCPP16Data->CpMsg.bits[gun_index].StopTransactionReq = 0;
  4098. sendStopTransactionRequest(gun_index);
  4099. OCPP_updatePeriodEnergy(gun_index);
  4100. if(ShmSysConfigAndInfo->SysConfig.TTIA_Info.isEnableTTIA && (gunType[gun_index] != GUN_TYPE_AC) )sendTTIAInfo(gun_index);
  4101. refreshStartTimer(&clientTime.StopTransaction);
  4102. memset(&ShmOCPP16Data->SessionTarget[gun_index], 0x00, sizeof(struct StructSessionTarget));
  4103. }
  4104. //==========================================
  4105. // Charger status report
  4106. //==========================================
  4107. //--- Check Mode Change ---//
  4108. // J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DCcc
  4109. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  4110. {
  4111. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4112. {
  4113. tempIndex = ((gun_index==2) ? 1: 0);
  4114. }
  4115. else
  4116. {
  4117. tempIndex = gun_index;
  4118. }
  4119. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  4120. {
  4121. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  4122. {
  4123. if((SystemInitial > 0) || (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != ChademoPreviousSystemStatus[index]) || (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ConnectorPlugIn != ChademoPreviousConnectorPlugIn[index]) )
  4124. {
  4125. // Sent unplug message for California pricing logic
  4126. if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_COMPLETE) && (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ConnectorPlugIn == 0))
  4127. {
  4128. uint8_t ts[20];
  4129. getNowDatetime(ts);
  4130. sprintf((char*)ShmOCPP16Data->DataTransfer[gun_index].VendorId, "org.openchargealliance.costmsg");
  4131. sprintf((char*)ShmOCPP16Data->DataTransfer[gun_index].MessageId, "ConnectorUnplugged");
  4132. sprintf((char*)ShmOCPP16Data->DataTransfer[gun_index].Data, "{\\\"idTx\\\":%d,\\\"timestamp\\\":\\\"%s\\\"}", ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId, ts);
  4133. ShmOCPP16Data->CsMsg.bits[gun_index].DataTransferReq = 1;
  4134. }
  4135. ChademoPreviousSystemStatus[index] = ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus;
  4136. ChademoPreviousConnectorPlugIn[index] = ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ConnectorPlugIn;
  4137. cpinitateMsg.bits[gun_index].StatusNotificationReq = 1;
  4138. if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex) && ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_COMPLETE) || (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus <= SYS_MODE_IDLE))) // complete
  4139. {
  4140. sprintf(filenmae,"/Storage/OCPP/TxProfile_%d.json",(gun_index+1));
  4141. if((access(filenmae,F_OK))!=-1)
  4142. {
  4143. DEBUG_INFO("TxProfile exist. OCPP will delete TX Charging Profile\n");
  4144. sprintf(str,"rm -f %s",filenmae);
  4145. system(str);
  4146. }
  4147. }
  4148. }
  4149. cpinitateMsg.bits[gun_index].isOnCharging = ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_TERMINATING)?1:0);
  4150. #if 1 // for TempStopTransaction
  4151. if(((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_BOOTING) || (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_IDLE)) &&
  4152. (ShmOCPP16Data->CpMsg.bits[gun_index].StopTransactionReq == 0))
  4153. {
  4154. checkTempStopTransaction(gun_index);
  4155. }
  4156. #endif
  4157. }
  4158. }
  4159. }
  4160. else if(gunType[gun_index] == GUN_TYPE_CCS)
  4161. {
  4162. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4163. {
  4164. tempIndex = ((gun_index==2) ? 1: 0);
  4165. }
  4166. else
  4167. {
  4168. tempIndex = gun_index;
  4169. }
  4170. for (int index = 0; index < CCS_QUANTITY; index++)
  4171. {
  4172. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  4173. {
  4174. if((SystemInitial > 0) || (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != CcsPreviousSystemStatus[index]) || (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ConnectorPlugIn != CcsPreviousConnectorPlugIn[index]) )//if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != CcsPreviousSystemStatus[index]/*PRE_SYS_MODE[gun_index]*/ )
  4175. {
  4176. // Sent unplug message for California pricing logic
  4177. if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_COMPLETE) && (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ConnectorPlugIn == 0))
  4178. {
  4179. uint8_t ts[20];
  4180. getNowDatetime(ts);
  4181. sprintf((char*)ShmOCPP16Data->DataTransfer[gun_index].VendorId, "org.openchargealliance.costmsg");
  4182. sprintf((char*)ShmOCPP16Data->DataTransfer[gun_index].MessageId, "ConnectorUnplugged");
  4183. sprintf((char*)ShmOCPP16Data->DataTransfer[gun_index].Data, "{\\\"idTx\\\":%d,\\\"timestamp\\\":\\\"%s\\\"}", ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId, ts);
  4184. ShmOCPP16Data->CsMsg.bits[gun_index].DataTransferReq = 1;
  4185. }
  4186. CcsPreviousSystemStatus[index] = ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus;
  4187. CcsPreviousConnectorPlugIn[index] = ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ConnectorPlugIn;
  4188. cpinitateMsg.bits[gun_index].StatusNotificationReq = 1;
  4189. if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex) && ((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_COMPLETE) || (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus <= SYS_MODE_IDLE))) // complete
  4190. {
  4191. sprintf(filenmae,"/Storage/OCPP/TxProfile_%d.json",(gun_index+1));
  4192. if((access(filenmae,F_OK))!=-1)
  4193. {
  4194. DEBUG_INFO("TxProfile exist. OCPP will delete TX Charging Profile\n");
  4195. sprintf(str,"rm -f %s",filenmae);
  4196. system(str);
  4197. }
  4198. }
  4199. }
  4200. cpinitateMsg.bits[gun_index].isOnCharging = ((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_TERMINATING)?1:0);
  4201. #if 1 // for TempStopTransaction
  4202. if(((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_BOOTING) || (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_IDLE)) &&
  4203. (ShmOCPP16Data->CpMsg.bits[gun_index].StopTransactionReq == 0))
  4204. {
  4205. checkTempStopTransaction(gun_index);
  4206. }
  4207. #endif
  4208. }
  4209. }
  4210. }
  4211. else if(gunType[gun_index] == GUN_TYPE_GBT)
  4212. {
  4213. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4214. {
  4215. tempIndex = ((gun_index==2) ? 1: 0);
  4216. }
  4217. else
  4218. {
  4219. tempIndex = gun_index;
  4220. }
  4221. for (int index = 0; index < GB_QUANTITY; index++)
  4222. {
  4223. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  4224. {
  4225. if((SystemInitial > 0) || (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != GbPreviousSystemStatus[index]) || (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ConnectorPlugIn != GbPreviousConnectorPlugIn[index]) )
  4226. {
  4227. // Sent unplug message for California pricing logic
  4228. if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_COMPLETE) && (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ConnectorPlugIn == 0))
  4229. {
  4230. uint8_t ts[20];
  4231. getNowDatetime(ts);
  4232. sprintf((char*)ShmOCPP16Data->DataTransfer[gun_index].VendorId, "org.openchargealliance.costmsg");
  4233. sprintf((char*)ShmOCPP16Data->DataTransfer[gun_index].MessageId, "ConnectorUnplugged");
  4234. sprintf((char*)ShmOCPP16Data->DataTransfer[gun_index].Data, "{\\\"idTx\\\":%d,\\\"timestamp\\\":\\\"%s\\\"}", ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId, ts);
  4235. ShmOCPP16Data->CsMsg.bits[gun_index].DataTransferReq = 1;
  4236. }
  4237. GbPreviousSystemStatus[index] = ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus;
  4238. GbPreviousConnectorPlugIn[index] = ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ConnectorPlugIn;
  4239. cpinitateMsg.bits[gun_index].StatusNotificationReq = 1;
  4240. if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex) && ((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_COMPLETE) || (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus <= SYS_MODE_IDLE))) // complete
  4241. {
  4242. sprintf(filenmae,"/Storage/OCPP/TxProfile_%d.json",(gun_index+1));
  4243. if((access(filenmae,F_OK))!=-1)
  4244. {
  4245. DEBUG_INFO("TxProfile exist. OCPP will delete TX Charging Profile\n");
  4246. sprintf(str,"rm -f %s",filenmae);
  4247. system(str);
  4248. }
  4249. }
  4250. }
  4251. cpinitateMsg.bits[gun_index].isOnCharging = ((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_TERMINATING)?1:0);
  4252. #if 1 // for TempStopTransaction
  4253. if(((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_BOOTING) || (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_IDLE)) &&
  4254. (ShmOCPP16Data->CpMsg.bits[gun_index].StopTransactionReq == 0))
  4255. {
  4256. checkTempStopTransaction(gun_index);
  4257. }
  4258. #endif
  4259. }
  4260. }
  4261. }
  4262. else if(gunType[gun_index] == GUN_TYPE_DO)
  4263. {
  4264. tempIndex = gun_index;
  4265. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  4266. {
  4267. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  4268. {
  4269. if((SystemInitial > 0) || (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus != DoPreviousSystemStatus[index]) || (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.ConnectorPlugIn != DoPreviousConnectorPlugIn[index]) )
  4270. {
  4271. // Sent unplug message for California pricing logic
  4272. if((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_COMPLETE) && (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.ConnectorPlugIn == 0))
  4273. {
  4274. uint8_t ts[20];
  4275. getNowDatetime(ts);
  4276. sprintf((char*)ShmOCPP16Data->DataTransfer[gun_index].VendorId, "org.openchargealliance.costmsg");
  4277. sprintf((char*)ShmOCPP16Data->DataTransfer[gun_index].MessageId, "ConnectorUnplugged");
  4278. sprintf((char*)ShmOCPP16Data->DataTransfer[gun_index].Data, "{\\\"idTx\\\":%d,\\\"timestamp\\\":\\\"%s\\\"}", ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId, ts);
  4279. ShmOCPP16Data->CsMsg.bits[gun_index].DataTransferReq = 1;
  4280. }
  4281. DoPreviousSystemStatus[index] = ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus;
  4282. DoPreviousConnectorPlugIn[index] = ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.ConnectorPlugIn;
  4283. cpinitateMsg.bits[gun_index].StatusNotificationReq = 1;
  4284. 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
  4285. {
  4286. sprintf(filenmae,"/Storage/OCPP/TxProfile_%d.json",(gun_index+1));
  4287. if((access(filenmae,F_OK))!=-1)
  4288. {
  4289. DEBUG_INFO("TxProfile exist. OCPP will delete TX Charging Profile\n");
  4290. sprintf(str,"rm -f %s",filenmae);
  4291. system(str);
  4292. }
  4293. }
  4294. }
  4295. 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);
  4296. #if 1 // for TempStopTransaction
  4297. if(((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_BOOTING) || (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_IDLE)) &&
  4298. (ShmOCPP16Data->CpMsg.bits[gun_index].StopTransactionReq == 0))
  4299. {
  4300. checkTempStopTransaction(gun_index);
  4301. }
  4302. #endif
  4303. }
  4304. }
  4305. }
  4306. else
  4307. {
  4308. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  4309. {
  4310. tempIndex = 2;
  4311. }
  4312. else
  4313. {
  4314. tempIndex = gun_index;
  4315. }
  4316. for (int index = 0; index < AC_QUANTITY; index++)
  4317. {
  4318. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  4319. {
  4320. if((SystemInitial > 0) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != AcPreviousSystemStatus[index]) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PilotState != AcPreviousConnectorPlugIn[index]) )
  4321. {
  4322. // Sent unplug message for California pricing logic
  4323. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_COMPLETE) && (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PilotState == CP_STATE_A))
  4324. {
  4325. uint8_t ts[20];
  4326. getNowDatetime(ts);
  4327. sprintf((char*)ShmOCPP16Data->DataTransfer[gun_index].VendorId, "org.openchargealliance.costmsg");
  4328. sprintf((char*)ShmOCPP16Data->DataTransfer[gun_index].MessageId, "ConnectorUnplugged");
  4329. sprintf((char*)ShmOCPP16Data->DataTransfer[gun_index].Data, "{\\\"idTx\\\":%d,\\\"timestamp\\\":\\\"%s\\\"}", ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId, ts);
  4330. ShmOCPP16Data->CsMsg.bits[gun_index].DataTransferReq = 1;
  4331. }
  4332. AcPreviousSystemStatus[index] = ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus;
  4333. AcPreviousConnectorPlugIn[index] = ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PilotState;
  4334. cpinitateMsg.bits[gun_index].StatusNotificationReq = 1;
  4335. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex) && ((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_COMPLETE) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus <= SYS_MODE_IDLE))) // complete
  4336. {
  4337. sprintf(filenmae,"/Storage/OCPP/TxProfile_%d.json",(gun_index+1));
  4338. if((access(filenmae,F_OK))!=-1)
  4339. {
  4340. DEBUG_INFO("TxProfile exist. OCPP will delete TX Charging Profile\n");
  4341. sprintf(str,"rm -f %s",filenmae);
  4342. system(str);
  4343. }
  4344. }
  4345. }
  4346. cpinitateMsg.bits[gun_index].isOnCharging = ((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_TERMINATING)?1:0);
  4347. #if 1 // for TempStopTransaction
  4348. if(((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_BOOTING) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_IDLE)) &&
  4349. (ShmOCPP16Data->CpMsg.bits[gun_index].StopTransactionReq == 0))
  4350. {
  4351. checkTempStopTransaction(gun_index);
  4352. }
  4353. #endif
  4354. }
  4355. }// END
  4356. }
  4357. if(isWebsocketSendable && (server_sign == TRUE) && (getDiffSecNow(clientTime.StatusNotification[gun_index]) >= 5) &&
  4358. (
  4359. (cpinitateMsg.bits[gun_index].StatusNotificationReq == 1) || (cpinitateMsg.bits[gun_index].TriggerStatusNotificationReq == 1) ||
  4360. ((strcmp((const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StatusNotificationPeriodically].ItemData, "TRUE") == 0) && (getDiffSecNow(clientTime.StatusNotification[gun_index]) >= atoi((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[StatusNotificationInterval].ItemData)))
  4361. )
  4362. )
  4363. {
  4364. if(SystemInitial > 0)
  4365. SystemInitial -= 1;
  4366. sendStatusNotificationRequest(gun_index);
  4367. refreshStartTimer(&clientTime.StatusNotification[gun_index]);
  4368. }
  4369. //==============================================
  4370. // CSU Trigger Smart Charging Profile
  4371. //==============================================
  4372. if(ShmOCPP16Data->CSUMsg.bits[gun_index].ChargingProfileReq == 1)
  4373. {
  4374. checkCompositeSchedule(gun_index+1, 86400, &ShmOCPP16Data->SmartChargingProfile[gun_index], TRUE);
  4375. ShmOCPP16Data->CSUMsg.bits[gun_index].ChargingProfileReq = 0;
  4376. }
  4377. //==============================================
  4378. // Meter report
  4379. //==============================================
  4380. // Trigger MeterValue
  4381. if(isWebsocketSendable && (server_sign == TRUE) && cpinitateMsg.bits[gun_index].TriggerMeterValue)
  4382. {
  4383. sendMeterValuesRequest(gun_index, ReadingContext_Trigger);
  4384. cpinitateMsg.bits[gun_index].TriggerMeterValue = 0;
  4385. }
  4386. // Clock-aligned Meter value
  4387. if(isWebsocketSendable && (reqClockAlignMeter[gun_index] == 1))
  4388. {
  4389. sendMeterValuesRequest(gun_index, ReadingContext_Sample_Clock);
  4390. reqClockAlignMeter[gun_index] = 0;
  4391. }
  4392. // Sample period MeterValue
  4393. 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))))
  4394. {
  4395. //check Transaction active
  4396. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  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 < CHAdeMO_QUANTITY; index++)
  4407. {
  4408. // 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault
  4409. if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  4410. {
  4411. if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_CHARGING)
  4412. {
  4413. reqSampleMeter[gun_index] = 1;
  4414. }
  4415. }
  4416. }// End for CHAdeMO
  4417. }
  4418. else if(gunType[gun_index] == GUN_TYPE_CCS)
  4419. {
  4420. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4421. {
  4422. tempIndex = ((gun_index==2) ? 1: 0);
  4423. }
  4424. else
  4425. {
  4426. tempIndex = gun_index;
  4427. }
  4428. for (int index = 0; index < CCS_QUANTITY; index++)
  4429. {
  4430. // 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault
  4431. if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  4432. {
  4433. if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_CHARGING)
  4434. {
  4435. reqSampleMeter[gun_index] = 1;
  4436. }
  4437. }
  4438. } // End for CCS
  4439. }
  4440. else if(gunType[gun_index] == GUN_TYPE_GBT)
  4441. {
  4442. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4443. {
  4444. tempIndex = ((gun_index==2) ? 1: 0);
  4445. }
  4446. else
  4447. {
  4448. tempIndex = gun_index;
  4449. }
  4450. for (int index = 0; index < GB_QUANTITY; index++)
  4451. {
  4452. // 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault
  4453. if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  4454. {
  4455. if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_CHARGING)
  4456. {
  4457. reqSampleMeter[gun_index] = 1;
  4458. }
  4459. }
  4460. }// End for GB
  4461. }
  4462. else if(gunType[gun_index] == GUN_TYPE_DO)
  4463. {
  4464. tempIndex = gun_index;
  4465. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  4466. {
  4467. // 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault
  4468. if(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  4469. {
  4470. if(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_CHARGING)
  4471. {
  4472. reqSampleMeter[gun_index] = 1;
  4473. }
  4474. }
  4475. }
  4476. }
  4477. else
  4478. {
  4479. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  4480. {
  4481. tempIndex = 2;
  4482. }
  4483. else
  4484. {
  4485. tempIndex = gun_index;
  4486. }
  4487. for (int index = 0; index < AC_QUANTITY; index++)
  4488. {
  4489. // 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault
  4490. if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  4491. {
  4492. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_TERMINATING))
  4493. {
  4494. reqSampleMeter[gun_index] = 1;
  4495. }
  4496. }
  4497. }//End for AC
  4498. }
  4499. if(reqSampleMeter[gun_index] == 1)
  4500. {
  4501. if(atoi((const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemData)>0)
  4502. sendMeterValuesRequest(gun_index, ReadingContext_Sample_Periodic);
  4503. storeTempStopTransaction(gun_index);
  4504. reqSampleMeter[gun_index] = 0;
  4505. }
  4506. refreshStartTimer(&clientTime.MeterValues[gun_index]);
  4507. }
  4508. //==============================================
  4509. // Check Connector reserved
  4510. //==============================================
  4511. //===============================
  4512. // Check if Reserve is expired
  4513. //===============================
  4514. if((server_sign == TRUE) && (ShmOCPP16Data->ReserveNow[gun_index].ExpiryDate[0] != 0))
  4515. {
  4516. if(isOvertNow(ShmOCPP16Data->ReserveNow[gun_index].ExpiryDate))
  4517. {
  4518. DEBUG_INFO("reserve expired.\n");
  4519. memset(ShmOCPP16Data->ReserveNow[gun_index].ExpiryDate,0,ARRAY_SIZE(ShmOCPP16Data->ReserveNow[gun_index].ExpiryDate));
  4520. }
  4521. }//END OF Check if Reserve is expired
  4522. //==========================================
  4523. // csu trigger FirmwareStatusNotificationReq
  4524. //==========================================
  4525. if(isWebsocketSendable && (server_sign == TRUE) && (ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationReq == 1))
  4526. {
  4527. sendFirmwareStatusNotificationRequest((char *)ShmOCPP16Data->FirmwareStatusNotification.Status);
  4528. }
  4529. //==========================================
  4530. // csu trigger DiagnosticsStatusNotificationReq
  4531. //==========================================
  4532. if(isWebsocketSendable && (server_sign == TRUE) && (ShmOCPP16Data->SpMsg.bits.DiagnosticsStatusNotificationReq == 1))
  4533. {
  4534. sendDiagnosticsStatusNotificationRequest((char *)ShmOCPP16Data->DiagnosticsStatusNotification.Status);
  4535. }
  4536. //==========================================
  4537. // csu trigger CancelReservationConf
  4538. //==========================================
  4539. if(isWebsocketSendable && (server_sign == TRUE) && (ShmOCPP16Data->CsMsg.bits[gun_index].CancelReservationConf == 1))
  4540. {
  4541. sendCancelReservationConfirmation((char *)ShmOCPP16Data->CancelReservation[gun_index].guid,(char *)ShmOCPP16Data->CancelReservation[gun_index].ResponseStatus);
  4542. ShmOCPP16Data->CsMsg.bits[gun_index].CancelReservationConf = 0;
  4543. }
  4544. //==========================================
  4545. // csu trigger ChangeAvailabilityConf
  4546. //==========================================
  4547. if(isWebsocketSendable && (server_sign == TRUE) && (ShmOCPP16Data->CsMsg.bits[gun_index].ChangeAvailabilityConf == 1))
  4548. {
  4549. //sendChangeAvailabilityConfirmation(,(char *)ShmOCPP16Data->ChangeAvailability[gun_index].ResponseStatus);
  4550. }
  4551. //==========================================
  4552. // csu trigger UnlockConnectorConf
  4553. //==========================================
  4554. if(isWebsocketSendable && (server_sign == TRUE) && (ShmOCPP16Data->CsMsg.bits[gun_index].UnlockConnectorConf == 1))
  4555. {
  4556. sendUnlockConnectorConfirmation((char *)ShmOCPP16Data->UnlockConnector[gun_index].guid, (char *)ShmOCPP16Data->UnlockConnector[gun_index].ResponseStatus);
  4557. ShmOCPP16Data->CsMsg.bits[gun_index].UnlockConnectorConf = 0;
  4558. }
  4559. //==========================================
  4560. // csu trigger ReserveNowConf
  4561. //==========================================
  4562. if(isWebsocketSendable && (server_sign == TRUE) && (ShmOCPP16Data->CsMsg.bits[gun_index].ReserveNowConf == 1))
  4563. {
  4564. sendReserveNowTransactionConfirmation((char *)ShmOCPP16Data->ReserveNow[gun_index].guid, (char *)ShmOCPP16Data->ReserveNow[gun_index].ResponseStatus);
  4565. ShmOCPP16Data->CsMsg.bits[gun_index].ReserveNowConf = 0;
  4566. }
  4567. if(isWebsocketSendable && (server_sign == TRUE) && (ShmOCPP16Data->SpMsg.bits.SignCertificateReq == 1) && (access("/Storage/OCPP/certCP.csr",F_OK) != -1))
  4568. {
  4569. sendSignCertificateRequest();
  4570. }
  4571. }
  4572. }
  4573. //==========================================
  4574. // send request routine
  4575. //==========================================
  4576. int sendAuthorizeRequest(int gun_index)
  4577. {
  4578. mtrace();
  4579. int result = FAIL;
  4580. char message[100]={0};
  4581. char guid[37];
  4582. char tempdata[65]={0};
  4583. DEBUG_INFO("sendAuthorizeRequest...\n");
  4584. memset(&(ShmOCPP16Data->Authorize.ResponseIdTagInfo),0,sizeof(struct StructIdTagInfo));
  4585. //Local Authorize
  4586. if((strcmp((const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemData , "TRUE")==0) &&(ShmOCPP16Data->OcppConnStatus == 0))
  4587. {
  4588. DEBUG_INFO("Allow OfflineTx UnknownId Pass.\n");
  4589. strcpy((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.ExpiryDate, "");
  4590. strcpy((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.ParentIdTag, "");
  4591. strcpy((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.Status, "Accepted");
  4592. result = PASS;
  4593. ShmOCPP16Data->SpMsg.bits.AuthorizeReq = 0;
  4594. ShmOCPP16Data->SpMsg.bits.AuthorizeConf = 1; // inform csu
  4595. authorizeRetryTimes = 0;
  4596. return result;
  4597. }
  4598. 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))||
  4599. ((strcmp((const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemData, "TRUE") == 0)&&(strcmp((const char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "TRUE") == 0)))
  4600. {
  4601. // Query from cache
  4602. DEBUG_INFO("Authorize from cache.\n");
  4603. OCPP_getIdTagFromLocalCache((char *)ShmSysConfigAndInfo->SysConfig.UserId);
  4604. // Query from list
  4605. if((strcmp(idTagQuery.idTagstr,"") == 0) || (strcmp(idTagQuery.idTagstatus,"Accepted") != 0) )
  4606. {
  4607. DEBUG_INFO("Authorize from list.\n");
  4608. OCPP_getIdTagFromLocalList((char *)ShmSysConfigAndInfo->SysConfig.UserId);
  4609. }
  4610. if((strcmp(idTagQuery.idTagstr,"") == 0) || (strcmp(idTagQuery.idTagstatus,"Accepted") != 0) )
  4611. {
  4612. if(strcmp(idTagQuery.idTagstr,"") == 0)
  4613. {
  4614. DEBUG_INFO("Local Authorization Fail, Card %s is not in local cache and list.\n", ShmSysConfigAndInfo->SysConfig.UserId);
  4615. }
  4616. else if(strcmp(idTagQuery.idTagstatus,"Accepted") != 0)
  4617. {
  4618. DEBUG_INFO("Local Authorization Fail, Card %s is not Accepted.\n", idTagQuery.idTagstr);
  4619. }
  4620. if(!GetOcppConnStatus())
  4621. {
  4622. DEBUG_INFO("off-line Local Authorization Fail.\n");
  4623. strcpy((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.ExpiryDate, idTagQuery.expiryDate);
  4624. strcpy((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.ParentIdTag, idTagQuery.parentIdTag);
  4625. strcpy((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.Status, "Invalid");
  4626. DEBUG_INFO("ShmOCPP16Data->Authorize.ResponseIdTagInfo.Status: %s \n", ShmOCPP16Data->Authorize.ResponseIdTagInfo.Status);
  4627. ShmOCPP16Data->SpMsg.bits.AuthorizeReq = 0;
  4628. ShmOCPP16Data->SpMsg.bits.AuthorizeConf = 1; // inform csu
  4629. authorizeRetryTimes = 0;
  4630. return result;
  4631. }
  4632. }
  4633. else
  4634. {
  4635. DEBUG_INFO("off-line Local Authorization get result !!!!\n");
  4636. strcpy((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.ExpiryDate, idTagQuery.expiryDate);
  4637. strcpy((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.ParentIdTag, idTagQuery.parentIdTag);
  4638. if(isOvertNow((uint8_t*)&idTagQuery.expiryDate[0]))
  4639. sprintf((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.Status, "Expired");
  4640. else
  4641. strcpy((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.Status, idTagQuery.idTagstatus);
  4642. DEBUG_INFO("ShmOCPP16Data->Authorize.ResponseIdTagInfo.Status: %s \n", ShmOCPP16Data->Authorize.ResponseIdTagInfo.Status);
  4643. result = PASS;
  4644. ShmOCPP16Data->SpMsg.bits.AuthorizeReq = 0;
  4645. ShmOCPP16Data->SpMsg.bits.AuthorizeConf = 1; // inform csu
  4646. authorizeRetryTimes = 0;
  4647. return result;
  4648. }
  4649. }
  4650. //initialize struct Authorize
  4651. memset(&(ShmOCPP16Data->Authorize), 0 , sizeof(struct StructAuthorize));
  4652. //get data from shared memory
  4653. strcpy((char *)ShmOCPP16Data->Authorize.IdTag, (const char *)ShmSysConfigAndInfo->SysConfig.UserId);
  4654. random_uuid(guid);
  4655. sprintf(message,"[%d,\"%s\",\"Authorize\",{\"idTag\":\"%s\"}]",MESSAGE_TYPE_CALL, guid, ShmOCPP16Data->Authorize.IdTag);
  4656. LWS_Send(message);
  4657. sprintf(tempdata, "Authorize,%d", gun_index);
  4658. if(hashmap_operation(HASH_OP_ADD, guid, tempdata) == 1)
  4659. {
  4660. result = PASS;
  4661. DEBUG_INFO("Authorize mapItem pass\n");
  4662. }
  4663. ShmOCPP16Data->SpMsg.bits.AuthorizeReq = 0;
  4664. return result;
  4665. }
  4666. int sendBootNotificationRequest(void)
  4667. {
  4668. mtrace();
  4669. int result = FAIL;
  4670. char message[500]={0}, payload[700]={0};
  4671. char guid[37]={0};
  4672. char tempdata[65]={0};
  4673. // Fill BootNotification fields
  4674. strcpy((char *)ShmOCPP16Data->BootNotification.CbSN,(const char *)ShmOCPP16Data->ChargeBoxId);
  4675. strcpy((char *)ShmOCPP16Data->BootNotification.CpModel,(const char *)ShmSysConfigAndInfo->SysConfig.ModelName);
  4676. strcpy((char *)ShmOCPP16Data->BootNotification.CpSN,(const char *)ShmSysConfigAndInfo->SysConfig.SerialNumber);
  4677. strcpy((char *)ShmOCPP16Data->BootNotification.CpVendor,(const char *)ShmSysConfigAndInfo->SysConfig.chargePointVendor);
  4678. strcpy((char *)ShmOCPP16Data->BootNotification.CpFwVersion,(const char *)ShmSysConfigAndInfo->SysInfo.CsuRootFsFwRev);
  4679. strcpy((char *)ShmOCPP16Data->BootNotification.CpIccid,(const char *)ShmSysConfigAndInfo->SysConfig.TelecomInterface.TelcomSimIccid);
  4680. strcpy((char *)ShmOCPP16Data->BootNotification.CpImsi,(const char *)ShmSysConfigAndInfo->SysConfig.TelecomInterface.TelcomSimImsi);
  4681. sprintf(payload, "{\"chargeBoxSerialNumber\":\"%s\",\"chargePointModel\":\"%s\",\"chargePointSerialNumber\":\"%s\",\"chargePointVendor\":\"%s\",\"firmwareVersion\":\"%s\",\"iccid\":\"%s\",\"imsi\":\"%s\"} ",
  4682. ShmOCPP16Data->ChargeBoxId
  4683. ,ShmSysConfigAndInfo->SysConfig.ModelName
  4684. ,ShmSysConfigAndInfo->SysConfig.SerialNumber
  4685. ,ShmSysConfigAndInfo->SysConfig.chargePointVendor
  4686. ,ShmOCPP16Data->BootNotification.CpFwVersion
  4687. ,ShmOCPP16Data->BootNotification.CpIccid
  4688. ,ShmOCPP16Data->BootNotification.CpImsi);
  4689. random_uuid(guid);
  4690. sprintf(message,"[%d,\"%s\",\"%s\",%s]",MESSAGE_TYPE_CALL, guid, "BootNotification", payload);
  4691. LWS_Send(message);
  4692. sprintf(tempdata, "BootNotification,0");
  4693. 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*/)
  4694. {
  4695. result = PASS;
  4696. }
  4697. memset(queuedata, 0, ARRAY_SIZE(queuedata));
  4698. strcpy(queuedata,message);
  4699. return result;
  4700. }
  4701. int sendDataTransferRequest(int gun_index)
  4702. {
  4703. mtrace();
  4704. char message[1000]={0};
  4705. char guid[37]={0};
  4706. char tempdata[65]={0};
  4707. int result = FAIL;
  4708. random_uuid(guid);
  4709. sprintf(message,"[%d,\"%s\",\"DataTransfer\",{\"vendorId\":\"%s\",\"messageId\":\"%s\",\"data\":\"%s\"}]",
  4710. MESSAGE_TYPE_CALL,
  4711. guid,
  4712. ShmOCPP16Data->DataTransfer[gun_index].VendorId,
  4713. ShmOCPP16Data->DataTransfer[gun_index].MessageId,
  4714. ShmOCPP16Data->DataTransfer[gun_index].Data);
  4715. LWS_Send(message);
  4716. sprintf(tempdata, "DataTransfer,%d", (gun_index + 1));
  4717. if(hashmap_operation(HASH_OP_ADD, guid, tempdata) == 1)
  4718. {
  4719. result = PASS;
  4720. DEBUG_INFO("DataTransfer mapItem pass\n");
  4721. }
  4722. return result;
  4723. }
  4724. int sendDiagnosticsStatusNotificationRequest(char *status)
  4725. {
  4726. mtrace();
  4727. int result = FAIL;
  4728. char message[110]={0};
  4729. char guid[37]={0};
  4730. char tempdata[65]={0};
  4731. //[ 2, "9f7bced1-b8b1-40ec-b3bb-2e15630e3cdc", "DiagnosticsStatusNotification", { "status": "Idle" } ]
  4732. DEBUG_INFO("sendDiagnosticsStatusNotificationRequest...\n");
  4733. sprintf((char *)ShmOCPP16Data->DiagnosticsStatusNotification.Status,"%s",(const char *)status);
  4734. random_uuid(guid);
  4735. sprintf(message,"[%d,\"%s\",\"DiagnosticsStatusNotification\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALL, guid,status);
  4736. LWS_SendNow(message);
  4737. sprintf(tempdata, "DiagnosticsStatusNotification,%d", 0);
  4738. if(hashmap_operation(HASH_OP_ADD, guid, tempdata) == 1)
  4739. {
  4740. result = PASS;
  4741. //DEBUG_INFO("DiagnosticsStatusNotification mapItem pass\n");
  4742. }
  4743. //#ifdef SystemLogMessage
  4744. //DEBUG_INFO(">>>>>DiagnosticsStatusNotification request\n");
  4745. //DEBUG_INFO("Message: %s\n", SendBuffer);
  4746. //DEBUG_INFO("After push hash length: %d\n", hashmapForMessageLength()/*hashmap_length(hashMap)*/);
  4747. //#endif
  4748. ShmOCPP16Data->SpMsg.bits.DiagnosticsStatusNotificationReq = 0;
  4749. ShmOCPP16Data->SpMsg.bits.DiagnosticsStatusNotificationConf = 0;
  4750. //record status
  4751. if(strcmp(status,"Idle")==0)
  4752. {
  4753. DiagnosticsStatusNotificationStatus = DIAGNOSTIC_STATUS_IDLE;
  4754. }
  4755. else if(strcmp(status,"Uploaded")==0)
  4756. {
  4757. DiagnosticsStatusNotificationStatus = DIAGNOSTIC_STATUS_UPLOADED;
  4758. }
  4759. else if(strcmp(status,"UploadFailed")==0)
  4760. {
  4761. DiagnosticsStatusNotificationStatus = DIAGNOSTIC_STATUS_UPLOAD_FAIL;
  4762. }
  4763. else if(strcmp(status,"Uploading")==0)
  4764. {
  4765. DiagnosticsStatusNotificationStatus = DIAGNOSTIC_STATUS_UPLOADING;
  4766. }
  4767. return result;
  4768. }
  4769. int sendFirmwareStatusNotificationRequest(char *status)
  4770. {
  4771. mtrace();
  4772. int result = FAIL;
  4773. char message[110]={0};
  4774. char guid[37]={0};
  4775. char tempdata[65]={0};
  4776. // [ 2, "eb841424-ae56-42b0-8c84-d5296018c33c", "FirmwareStatusNotification", { "status": "Downloaded" } ]
  4777. DEBUG_INFO("sendFirmwareStatusNotificationRequest \n");
  4778. sprintf((char *)ShmOCPP16Data->FirmwareStatusNotification.Status, "%s", (const char *)status);
  4779. random_uuid(guid);
  4780. sprintf(message,"[%d,\"%s\",\"FirmwareStatusNotification\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALL, guid, status);
  4781. LWS_SendNow(message);
  4782. sprintf(tempdata, "FirmwareStatusNotification,%d", 0);
  4783. 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*/)
  4784. {
  4785. result = PASS;
  4786. DEBUG_INFO("FirmwareStatusNotification mapItem pass\n");
  4787. }
  4788. //#ifdef SystemLogMessage
  4789. //DEBUG_INFO(">>>>>FirmwareStatusNotification request\n");
  4790. //DEBUG_INFO("Message: %s\n", SendBuffer);
  4791. //#endif
  4792. ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationReq = 0;
  4793. ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationConf = 0;
  4794. //record status
  4795. if(strcmp(status,"Downloaded")==0)
  4796. {
  4797. FirmwareStatusNotificationStatus = FIRMWARE_STATUS_DOWNLOADED;
  4798. }
  4799. else if(strcmp(status,"DownloadFailed")==0)
  4800. {
  4801. FirmwareStatusNotificationStatus = FIRMWARE_STATUS_DOWNLOAD_FAILED;
  4802. }
  4803. else if(strcmp(status,"Downloading")==0)
  4804. {
  4805. FirmwareStatusNotificationStatus = FIRMWARE_STATUS_DOWNLOADING;
  4806. }
  4807. else if(strcmp(status,"Idle")==0)
  4808. {
  4809. FirmwareStatusNotificationStatus = FIRMWARE_STATUS_IDLE;
  4810. }
  4811. else if(strcmp(status,"InstallationFailed")==0)
  4812. {
  4813. FirmwareStatusNotificationStatus = FIRMWARE_STATUS_INSTALLATION_FAILED;
  4814. }
  4815. else if(strcmp(status,"Installing")==0)
  4816. {
  4817. FirmwareStatusNotificationStatus = FIRMWARE_STATUS_INSTALLING;
  4818. }
  4819. else if(strcmp(status,"Installed")==0)
  4820. {
  4821. FirmwareStatusNotificationStatus = FIRMWARE_STATUS_INSTALLED;
  4822. }
  4823. return result;
  4824. }
  4825. int sendHeartbeatRequest(int gun_index)
  4826. {
  4827. mtrace();
  4828. int result = FAIL;
  4829. char message[80]={0};
  4830. char guid[37]={0};
  4831. char tempdata[65]={0};
  4832. random_uuid(guid);
  4833. sprintf(message, "[%d,\"%s\",\"Heartbeat\",{ }]"
  4834. , MESSAGE_TYPE_CALL
  4835. , guid );
  4836. LWS_Send(message);
  4837. sprintf(tempdata, "Heartbeat,%d", 0);
  4838. 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*/)
  4839. {
  4840. result = PASS;
  4841. }
  4842. return result;
  4843. }
  4844. int sendStartTransactionRequest(int gun_index)
  4845. {
  4846. mtrace();
  4847. int result = FAIL;
  4848. char message[250]={0};
  4849. char guid[37]={0};
  4850. struct timeval tmnow;
  4851. struct tm *tm;
  4852. char buf[28];//, usec_buf[6];
  4853. char tempdata[65]={0};
  4854. int tempIndex = 0;
  4855. DEBUG_INFO("sendStartTransactionRequest...\n");
  4856. gettimeofday(&tmnow, NULL);
  4857. time_t t;
  4858. t = time(NULL);
  4859. /*UTC time and date*/
  4860. tm = gmtime(&t);
  4861. strftime(buf,28,"%Y-%m-%dT%H:%M:%SZ", tm);
  4862. #if 0 // remove temporally
  4863. strftime(buf,30,"%Y-%m-%dT%H:%M:%S", tm);
  4864. strcat(buf,".");
  4865. sprintf(usec_buf,"%dZ",(int)tmnow.tv_usec);
  4866. strcat(buf,usec_buf);
  4867. #endif
  4868. ShmOCPP16Data->StartTransaction[gun_index].ConnectorId = gun_index +1 ; // gun start from 1~
  4869. strcpy((char *)ShmOCPP16Data->StartTransaction[gun_index].Timestamp, buf);
  4870. //strcpy((char *)ShmOCPP16Data->StartTransaction[gun_index].IdTag, (const char *)ShmSysConfigAndInfo->SysConfig.UserId);
  4871. // clear StartTransaction Response
  4872. strcpy((char *)ShmOCPP16Data->StartTransaction[gun_index].ResponseIdTagInfo.ExpiryDate, "");
  4873. strcpy((char *)ShmOCPP16Data->StartTransaction[gun_index].ResponseIdTagInfo.ParentIdTag, "");
  4874. strcpy((char *)ShmOCPP16Data->StartTransaction[gun_index].ResponseIdTagInfo.Status, "");
  4875. ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId = 0;
  4876. refreshStartTimer(&clientTime.MeterValues[gun_index]);
  4877. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DCcc
  4878. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  4879. {
  4880. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4881. {
  4882. tempIndex = ((gun_index==2) ? 1: 0);
  4883. }
  4884. else
  4885. {
  4886. tempIndex = gun_index;
  4887. }
  4888. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  4889. {
  4890. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  4891. {
  4892. ShmOCPP16Data->StartTransaction[gun_index].MeterStart = (int)(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PowerConsumption*1000);
  4893. ShmOCPP16Data->StartTransaction[gun_index].ReservationId = ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ReservationId;
  4894. }
  4895. }
  4896. }
  4897. else if(gunType[gun_index] == GUN_TYPE_CCS)
  4898. {
  4899. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4900. {
  4901. tempIndex = ((gun_index==2) ? 1: 0);
  4902. }
  4903. else
  4904. {
  4905. tempIndex = gun_index;
  4906. }
  4907. for (int index = 0; index < CCS_QUANTITY; index++)
  4908. {
  4909. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  4910. {
  4911. ShmOCPP16Data->StartTransaction[gun_index].MeterStart = (int)(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PowerConsumption*1000);
  4912. ShmOCPP16Data->StartTransaction[gun_index].ReservationId = ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ReservationId;
  4913. }
  4914. }
  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. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  4929. {
  4930. ShmOCPP16Data->StartTransaction[gun_index].MeterStart = (int)(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PowerConsumption*1000);
  4931. ShmOCPP16Data->StartTransaction[gun_index].ReservationId = ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ReservationId;
  4932. }
  4933. }
  4934. }
  4935. else if(gunType[gun_index] == GUN_TYPE_DO)
  4936. {
  4937. tempIndex = gun_index;
  4938. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  4939. {
  4940. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  4941. {
  4942. ShmOCPP16Data->StartTransaction[gun_index].MeterStart = (int)(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PowerConsumption*1000);
  4943. ShmOCPP16Data->StartTransaction[gun_index].ReservationId = ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.ReservationId;
  4944. }
  4945. }
  4946. }
  4947. else
  4948. {
  4949. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  4950. {
  4951. tempIndex = 2;
  4952. }
  4953. else
  4954. {
  4955. tempIndex = gun_index;
  4956. }
  4957. for (int index = 0; index < AC_QUANTITY; index++)
  4958. {
  4959. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  4960. {
  4961. ShmOCPP16Data->StartTransaction[gun_index].MeterStart = (int)(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PowerConsumption*1000);
  4962. ShmOCPP16Data->StartTransaction[gun_index].ReservationId = ShmSysConfigAndInfo->SysInfo.AcChargingData[index].ReservationId;
  4963. }
  4964. }
  4965. }
  4966. random_uuid(guid);
  4967. if(ShmOCPP16Data->StartTransaction[gun_index].ReservationId == -1) // No Reservation
  4968. {
  4969. sprintf(message, "%d,[%d,\"%s\",\"StartTransaction\",{\"connectorId\":%d,\"idTag\":\"%s\",\"meterStart\":%d,\"timestamp\":\"%s\"}]"
  4970. , gun_index +1
  4971. , MESSAGE_TYPE_CALL
  4972. , guid
  4973. , ShmOCPP16Data->StartTransaction[gun_index].ConnectorId
  4974. , ShmOCPP16Data->StartTransaction[gun_index].IdTag
  4975. , ShmOCPP16Data->StartTransaction[gun_index].MeterStart
  4976. , ShmOCPP16Data->StartTransaction[gun_index].Timestamp );
  4977. }
  4978. else
  4979. {
  4980. sprintf(message, "%d,[%d,\"%s\",\"StartTransaction\",{\"connectorId\":%d,\"idTag\":\"%s\",\"meterStart\":%d,\"reservationId\":%d,\"timestamp\":\"%s\"}]"
  4981. , gun_index +1
  4982. , MESSAGE_TYPE_CALL
  4983. , guid
  4984. , ShmOCPP16Data->StartTransaction[gun_index].ConnectorId
  4985. , ShmOCPP16Data->StartTransaction[gun_index].IdTag
  4986. , ShmOCPP16Data->StartTransaction[gun_index].MeterStart
  4987. , ShmOCPP16Data->StartTransaction[gun_index].ReservationId
  4988. , ShmOCPP16Data->StartTransaction[gun_index].Timestamp );
  4989. }
  4990. #if 1
  4991. sprintf(tempdata, "StartTransaction,%d", (gun_index));
  4992. 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*/)
  4993. {
  4994. result = PASS;
  4995. }
  4996. #endif
  4997. strcpy(queuedata, message);
  4998. queue_operation(QUEUE_OPERATION_ADD, guid, queuedata );//addq(guid, queuedata); ---> remove temporally
  4999. OCPP_insert_transaction_msg(YES, queuedata);
  5000. return result;
  5001. }
  5002. int sendStatusNotificationRequest(int gun_index)
  5003. {
  5004. mtrace();
  5005. int result = FAIL;
  5006. char message[600]={0};
  5007. char guid[37];
  5008. int currentStatus = 0;
  5009. struct timeval tmnow;
  5010. struct tm *tm;
  5011. char buf[28];//, usec_buf[6];
  5012. char tempdata[65]={0};
  5013. int tempIndex = 0;
  5014. uint8_t isStateChanged = TRUE;
  5015. DEBUG_INFO("sendStatusNotificationRequest...\n");
  5016. gettimeofday(&tmnow, NULL);
  5017. time_t t;
  5018. t = time(NULL);
  5019. /*UTC time and date*/
  5020. tm = gmtime(&t);
  5021. strftime(buf,28,"%Y-%m-%dT%H:%M:%SZ", tm);
  5022. #if 0 // remove temporally
  5023. strftime(buf,30,"%Y-%m-%dT%H:%M:%S", tm);
  5024. strcat(buf,".");
  5025. sprintf(usec_buf,"%dZ",(int)tmnow.tv_usec);
  5026. strcat(buf,usec_buf);
  5027. #endif
  5028. //printf("%s",buf);
  5029. ShmOCPP16Data->StatusNotification[gun_index].ConnectorId = (gun_index + 1);
  5030. //strcpy(ShmOCPP16Data->StatusNotification[gun_index].ErrorCode, "NoError"); --- CSU Setting
  5031. // it's option
  5032. strcpy((char *)ShmOCPP16Data->StatusNotification[gun_index].Info, "");
  5033. /*
  5034. enum _SYSTEM_STATUS
  5035. {
  5036. S_BOOTING = 0,
  5037. S_IDLE, = 1
  5038. S_AUTHORIZING, =2
  5039. S_REASSIGN_CHECK, =3
  5040. S_REASSIGN, =4
  5041. S_PRECHARGE, =5
  5042. S_PREPARING_FOR_EV, =6
  5043. S_PREPARING_FOR_EVSE, =7
  5044. S_CHARGING, =8
  5045. S_TERMINATING, =9
  5046. S_COMPLETE, =10
  5047. S_ALARM, =11
  5048. S_FAULT =12
  5049. }
  5050. */
  5051. //check Transaction active
  5052. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DCcc
  5053. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  5054. {
  5055. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  5056. {
  5057. tempIndex = ((gun_index==2) ? 1: 0);
  5058. }
  5059. else
  5060. {
  5061. tempIndex = gun_index;
  5062. }
  5063. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  5064. {
  5065. if ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex))
  5066. {
  5067. if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_IDLE)//S_IDLE
  5068. {
  5069. if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ConnectorPlugIn == 1) // //0: unplug, 1: Plug-in
  5070. {
  5071. currentStatus = Preparing; //OCPP Status: Preparing
  5072. }
  5073. else
  5074. {
  5075. currentStatus = Available; //OCPP Status: Available
  5076. }
  5077. }
  5078. else if ( ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus >= SYS_MODE_AUTHORIZING)&&( ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus <= SYS_MODE_PREPARE_FOR_EVSE)) ||
  5079. ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus >= SYS_MODE_CCS_PRECHARGE_STEP0) && ( ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus <= SYS_MODE_CCS_PRECHARGE_STEP1) )
  5080. ) //S_PRECHARGE
  5081. {
  5082. currentStatus = Preparing; //OCPP Status: Preparing
  5083. }
  5084. else if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_CHARGING) //S_CHARGING
  5085. {
  5086. currentStatus = Charging; //OCPP Status: Charging
  5087. }
  5088. else if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_COMPLETE) //S_COMPLETE
  5089. {
  5090. currentStatus = Finishing; //OCPP Status: Finishing
  5091. }
  5092. else if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_TERMINATING) // S_TERMINATING ---> SuspendedEV
  5093. {
  5094. currentStatus = SuspendedEV; //OCPP Status: SuspendedEV
  5095. }
  5096. 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
  5097. {
  5098. currentStatus = Unavailable; //OCPP Status: Unavailable
  5099. }
  5100. else if ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_FAULT) || (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_ALARM)) //S_ALARM,S_FAULT ---> Faulted
  5101. {
  5102. currentStatus = Faulted; //OCPP Status: Faulted
  5103. }
  5104. else if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_RESERVATION) // ---> Reserved
  5105. {
  5106. currentStatus = Reserved; //OCPP Status: Reserved
  5107. }
  5108. } //end of the same index
  5109. }//end of for CHAdeMO_QUANTITY
  5110. }
  5111. else if(gunType[gun_index] == GUN_TYPE_CCS)
  5112. {
  5113. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  5114. {
  5115. tempIndex = ((gun_index==2) ? 1: 0);
  5116. }
  5117. else
  5118. {
  5119. tempIndex = gun_index;
  5120. }
  5121. for (int index = 0; index < CCS_QUANTITY; index++)
  5122. {
  5123. if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  5124. {
  5125. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_IDLE) //S_IDLE
  5126. {
  5127. if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ConnectorPlugIn == 1) //0: unplug, 1: Plug-in
  5128. {
  5129. currentStatus = Preparing; //OCPP Status: Preparing
  5130. }
  5131. else
  5132. {
  5133. currentStatus = Available; //OCPP Status: Available
  5134. }
  5135. }
  5136. else if ( ((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus >= SYS_MODE_AUTHORIZING)&&( ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus <= SYS_MODE_PREPARE_FOR_EVSE)) ||
  5137. ((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus >= SYS_MODE_CCS_PRECHARGE_STEP0) && ( ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus <= SYS_MODE_CCS_PRECHARGE_STEP1) )
  5138. ) //S_PRECHARGE
  5139. {
  5140. currentStatus = Preparing; //OCPP Status: Preparing
  5141. }
  5142. else if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_CHARGING) //S_CHARGING
  5143. {
  5144. currentStatus = Charging; //OCPP Status: Charging
  5145. }
  5146. else if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_COMPLETE) //S_COMPLETE
  5147. {
  5148. currentStatus = Finishing; //OCPP Status: Finishing
  5149. }
  5150. else if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_TERMINATING) //S_TERMINATING ---> SuspendedEV
  5151. {
  5152. currentStatus = SuspendedEV; //OCPP Status: SuspendedEV
  5153. }
  5154. 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
  5155. {
  5156. currentStatus = Unavailable; //OCPP Status : Unavailable
  5157. }
  5158. else if ((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_FAULT) || (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_ALARM)) //S_ALARM ,S_FAULT ---> Faulted
  5159. {
  5160. currentStatus = Faulted; //OCPP Status: Faulted
  5161. }
  5162. else if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_RESERVATION) // ---> Reserved
  5163. {
  5164. currentStatus = Reserved; //OCPP Status: Reserved
  5165. }
  5166. } //end of the same index
  5167. } // end of for CCS_QUANTITY
  5168. }
  5169. else if(gunType[gun_index] == GUN_TYPE_GBT)
  5170. {
  5171. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  5172. {
  5173. tempIndex = ((gun_index==2) ? 1: 0);
  5174. }
  5175. else
  5176. {
  5177. tempIndex = gun_index;
  5178. }
  5179. for (int index = 0; index < GB_QUANTITY; index++)
  5180. {
  5181. if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  5182. {
  5183. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_IDLE) //S_IDLE
  5184. {
  5185. if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ConnectorPlugIn == 1) // //0: unplug, 1: Plug-in
  5186. {
  5187. currentStatus = Preparing; //OCPP Status: Preparing
  5188. }
  5189. else
  5190. {
  5191. currentStatus = Available; //OCPP Status: Available
  5192. }
  5193. }
  5194. else if ( ((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus >= SYS_MODE_AUTHORIZING)&&( ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus <= SYS_MODE_PREPARE_FOR_EVSE)) ||
  5195. ((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus >= SYS_MODE_CCS_PRECHARGE_STEP0) && ( ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus <= SYS_MODE_CCS_PRECHARGE_STEP1) )
  5196. ) //S_PRECHARGE
  5197. {
  5198. currentStatus = Preparing; //OCPP Status: Preparing
  5199. }
  5200. else if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_CHARGING) //S_CHARGING
  5201. {
  5202. currentStatus = Charging; //OCPP Status: Charging
  5203. }
  5204. else if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_COMPLETE) //S_COMPLETE
  5205. {
  5206. currentStatus = Finishing; //OCPP Status: Finishing
  5207. }
  5208. else if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_TERMINATING) // S_TERMINATING ---> SuspendedEV
  5209. {
  5210. currentStatus = SuspendedEV; //OCPP Status: SuspendedEV
  5211. }
  5212. 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
  5213. {
  5214. currentStatus = Unavailable; //OCPP Status: Unavailable
  5215. }
  5216. else if ((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_FAULT) || (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_ALARM)) //S_ALARM ,S_FAULT ---> Faulted
  5217. {
  5218. currentStatus = Faulted; //OCPP Status: Faulted
  5219. }
  5220. else if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_RESERVATION) // ---> Reserved
  5221. {
  5222. currentStatus = Reserved; //OCPP Status: Reserved
  5223. }
  5224. } //end of the same index
  5225. } // end of for GB_QUANTITY
  5226. }
  5227. else if(gunType[gun_index] == GUN_TYPE_DO)
  5228. {
  5229. tempIndex = gun_index;
  5230. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  5231. {
  5232. if(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  5233. {
  5234. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_IDLE) //S_IDLE
  5235. {
  5236. if(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.ConnectorPlugIn == 1) // //0: unplug, 1: Plug-in
  5237. {
  5238. currentStatus = Preparing; //OCPP Status: Preparing
  5239. }
  5240. else
  5241. {
  5242. currentStatus = Available; //OCPP Status: Available
  5243. }
  5244. }
  5245. else if ( ((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus >= SYS_MODE_AUTHORIZING) && (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus <= SYS_MODE_PREPARE_FOR_EVSE)) ||
  5246. ((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus >= SYS_MODE_CCS_PRECHARGE_STEP0) && (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus <= SYS_MODE_CCS_PRECHARGE_STEP1) )
  5247. ) //S_PRECHARGE
  5248. {
  5249. currentStatus = Preparing; //OCPP Status: Preparing
  5250. }
  5251. else if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_CHARGING) //S_CHARGING
  5252. {
  5253. currentStatus = Charging; //OCPP Status: Charging
  5254. }
  5255. else if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_COMPLETE) //S_COMPLETE
  5256. {
  5257. currentStatus = Finishing; //OCPP Status: Finishing
  5258. }
  5259. else if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_TERMINATING) // S_TERMINATING ---> SuspendedEV
  5260. {
  5261. currentStatus = SuspendedEV; //OCPP Status: SuspendedEV
  5262. }
  5263. 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
  5264. {
  5265. currentStatus = Unavailable; //OCPP Status: Unavailable
  5266. }
  5267. 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
  5268. {
  5269. currentStatus = Faulted; //OCPP Status: Faulted
  5270. }
  5271. else if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_RESERVATION) // ---> Reserved
  5272. {
  5273. currentStatus = Reserved; //OCPP Status: Reserved
  5274. }
  5275. } //end of the same index
  5276. }
  5277. }
  5278. else
  5279. {
  5280. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  5281. {
  5282. tempIndex = 2;
  5283. }
  5284. else
  5285. {
  5286. tempIndex = gun_index;
  5287. }
  5288. for (int index = 0; index < AC_QUANTITY; index++)
  5289. {
  5290. if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  5291. {
  5292. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_IDLE) //SYS_MODE_IDLE
  5293. {
  5294. 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))
  5295. {
  5296. currentStatus = Preparing; //OCPP Status: Preparing
  5297. }
  5298. else
  5299. {
  5300. currentStatus = Available; //OCPP Status: Available
  5301. }
  5302. }
  5303. else if ((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_AUTHORIZING) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_PREPARING)) //SYS_MODE_PREPARING
  5304. {
  5305. currentStatus = Preparing; //OCPP Status: Preparing
  5306. }
  5307. else if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_CHARGING) //SYS_MODE_CHARGING
  5308. {
  5309. currentStatus = Charging; //OCPP Status: Charging
  5310. }
  5311. else if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_COMPLETE) //SYS_MODE_COMPLETE
  5312. {
  5313. currentStatus = Finishing; //OCPP Status: Finishing
  5314. }
  5315. else if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_TERMINATING) // S_TERMINATING ---> SuspendedEV
  5316. {
  5317. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PilotState == CP_STATE_B))
  5318. currentStatus = SuspendedEV; //OCPP Status: SuspendedEV
  5319. else
  5320. currentStatus = SuspendedEVSE; //OCPP Status: SuspendedEVSE
  5321. }
  5322. 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
  5323. {
  5324. currentStatus = Unavailable; //OCPP Status: Unavailable
  5325. }
  5326. else if ((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_FAULT) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_ALARM)) //S_ALARM,S_FAULT ---> Faulted
  5327. {
  5328. currentStatus = Faulted; //OCPP Status: Faulted
  5329. }
  5330. else if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_RESERVATION) // ---> Reserved
  5331. {
  5332. currentStatus = Reserved; //OCPP Status: Reserved
  5333. }
  5334. }//end of the same index
  5335. }//end of for AC_QUANTITY
  5336. }
  5337. //it's option
  5338. if(((strstr((char *)ShmOCPP16Data->StatusNotification[gun_index].Status, ChargePointStatusStr[currentStatus]) != NULL) || (((currentStatus == SuspendedEV) || (currentStatus == SuspendedEVSE)) && ShmOCPP16Data->CsMsg.bits[gun_index].RemoteStopTransactionReq)) &&
  5339. !cpinitateMsg.bits[gun_index].TriggerStatusNotificationReq &&
  5340. (strcmp((const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StatusNotificationPeriodically].ItemData, "TRUE") != 0))
  5341. {
  5342. isStateChanged = FALSE;
  5343. }
  5344. cpinitateMsg.bits[gun_index].TriggerStatusNotificationReq = 0;
  5345. strcpy((char *)ShmOCPP16Data->StatusNotification[gun_index].Timestamp, buf);
  5346. strcpy((char *)ShmOCPP16Data->StatusNotification[gun_index].VendorId, (char*)ShmSysConfigAndInfo->SysConfig.chargePointVendor);
  5347. strcpy((char *)ShmOCPP16Data->StatusNotification[gun_index].Status, ChargePointStatusStr[currentStatus]);
  5348. random_uuid(guid);
  5349. sprintf(message, "[%d,\"%s\",\"StatusNotification\",{\"connectorId\":%d,\"errorCode\":\"%s\",\"info\":\"%s\",\"status\":\"%s\",\"timestamp\":\"%s\",\"vendorId\":\"%s\",\"vendorErrorCode\":\"%s\"}]"
  5350. , MESSAGE_TYPE_CALL
  5351. , guid
  5352. , ShmOCPP16Data->StatusNotification[gun_index].ConnectorId
  5353. , ShmOCPP16Data->StatusNotification[gun_index].ErrorCode
  5354. , ShmOCPP16Data->StatusNotification[gun_index].Info
  5355. , ShmOCPP16Data->StatusNotification[gun_index].Status
  5356. , ShmOCPP16Data->StatusNotification[gun_index].Timestamp
  5357. , ShmOCPP16Data->StatusNotification[gun_index].VendorId
  5358. , ShmOCPP16Data->StatusNotification[gun_index].VendorErrorCode);
  5359. if((server_sign == TRUE) && isStateChanged)
  5360. {
  5361. LWS_Send(message);
  5362. sprintf(tempdata, "StatusNotification,%d", (gun_index));
  5363. 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*/)
  5364. {
  5365. //DEBUG_ERROR("statusNotification mapitem pass");
  5366. result = PASS;
  5367. }
  5368. }
  5369. else
  5370. {
  5371. cpinitateMsg.bits[gun_index].StatusNotificationReq = 0;
  5372. cpinitateMsg.bits[gun_index].TriggerStatusNotificationReq = 0;
  5373. result = PASS;
  5374. }
  5375. return result;
  5376. }
  5377. int sendStopTransactionRequest(int gun_index)
  5378. {
  5379. mtrace();
  5380. int result = FAIL;
  5381. //char message[1500]={0};
  5382. char guid[37]={0};
  5383. char tempdata[65]={0};
  5384. int tempIndex = 0;
  5385. char TempStopTransaction[256];
  5386. sprintf(TempStopTransaction, "/Storage/OCPP/TempStopTransaction_%d", (gun_index+1));
  5387. //int idx_sample=0;
  5388. DEBUG_INFO("sendStopTransactionRequest \n");
  5389. memset(queuedata, 0, ARRAY_SIZE(queuedata));
  5390. memset(&ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0], 0, ARRAY_SIZE(ShmOCPP16Data->StopTransaction[gun_index].TransactionData));
  5391. //=========================== ENERGY_ACTIVE_IMPORT_REGISTER =======================================
  5392. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DCcc
  5393. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  5394. {
  5395. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  5396. {
  5397. tempIndex = ((gun_index==2) ? 1: 0);
  5398. }
  5399. else
  5400. {
  5401. tempIndex = gun_index;
  5402. }
  5403. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  5404. {
  5405. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  5406. {
  5407. ShmOCPP16Data->StopTransaction[gun_index].MeterStop = (int)(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PowerConsumption*1000);
  5408. }
  5409. }// END OF CHAdeMO_QUANTITY
  5410. }
  5411. else if(gunType[gun_index] == GUN_TYPE_CCS)
  5412. {
  5413. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  5414. {
  5415. tempIndex = ((gun_index==2) ? 1: 0);
  5416. }
  5417. else
  5418. {
  5419. tempIndex = gun_index;
  5420. }
  5421. for (int index = 0; index < CCS_QUANTITY; index++)
  5422. {
  5423. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  5424. {
  5425. ShmOCPP16Data->StopTransaction[gun_index].MeterStop = (int)(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PowerConsumption*1000);
  5426. }
  5427. }// END OF CCS_QUANTITY
  5428. }
  5429. else if(gunType[gun_index] == GUN_TYPE_GBT)
  5430. {
  5431. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  5432. {
  5433. tempIndex = ((gun_index==2) ? 1: 0);
  5434. }
  5435. else
  5436. {
  5437. tempIndex = gun_index;
  5438. }
  5439. for (int index = 0; index < GB_QUANTITY; index++)
  5440. {
  5441. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  5442. {
  5443. ShmOCPP16Data->StopTransaction[gun_index].MeterStop = (int)(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PowerConsumption*1000);
  5444. }
  5445. }// END OF GB_QUANTITY
  5446. }
  5447. else if(gunType[gun_index] == GUN_TYPE_DO)
  5448. {
  5449. tempIndex = gun_index;
  5450. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  5451. {
  5452. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  5453. {
  5454. ShmOCPP16Data->StopTransaction[gun_index].MeterStop = (int)(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PowerConsumption*1000);
  5455. }
  5456. }// END OF GB_QUANTITY
  5457. }
  5458. else
  5459. {
  5460. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  5461. {
  5462. tempIndex = 2;
  5463. }
  5464. else
  5465. {
  5466. tempIndex = gun_index;
  5467. }
  5468. for (int index = 0; index < AC_QUANTITY; index++)
  5469. {
  5470. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  5471. {
  5472. ShmOCPP16Data->StopTransaction[gun_index].MeterStop = (int)(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PowerConsumption*1000);
  5473. }
  5474. }// END OF AC_QUANTITY
  5475. }
  5476. //====================================== Stop Transaction Time =====================================================
  5477. struct timeval tmnow;
  5478. struct tm *tm;
  5479. char buf[28];//, usec_buf[6];
  5480. gettimeofday(&tmnow, NULL);
  5481. time_t t;
  5482. t = time(NULL);
  5483. /*UTC time and date*/
  5484. tm = gmtime(&t);
  5485. strftime(buf,28,"%Y-%m-%dT%H:%M:%SZ", tm);
  5486. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].Timestamp,buf);
  5487. ShmOCPP16Data->StopTransaction[gun_index].TransactionId = ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId;
  5488. random_uuid(guid);
  5489. /***********************************transactionData******************************************************/
  5490. memset(ShmOCPP16Data->StopTransaction[gun_index].TransactionData, 0, sizeof(struct StructMeterValue));
  5491. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].TimeStamp, buf);
  5492. //=================================
  5493. // Transaction_Begin
  5494. //=================================
  5495. if(strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Energy.Active.Import.Interval") != NULL)
  5496. {
  5497. //============================================ Energy.Active.Import.Interval ================================
  5498. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Value, "%.3f", 0.0); // MeterStart is 0~6553.5 kWh
  5499. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Context,ReadingContextStr[ReadingContext_Transaction_Begin]);
  5500. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Format,ValueFormatStr[Raw]);
  5501. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Measurand,MeasurandStr[Energy_Active_Import_Interval]);//MeasurandStr[Energy_Active_Export_Interval/*Energy_Reactive_Export_Register*/]);
  5502. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DCcc
  5503. 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))
  5504. {
  5505. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Phase,PhaseStr[L3_N]);
  5506. }
  5507. else
  5508. {
  5509. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Phase,PhaseStr[L1_N]);
  5510. }
  5511. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Location,LocationStr[Location_Outlet]);
  5512. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Unit,UnitOfMeasureStr[UnitOfMeasure_kWh]);
  5513. }
  5514. //=================================
  5515. // Transaction_End
  5516. //=================================
  5517. // ================================= Current.Import L1 ===============================================
  5518. if(strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Current.Import") != NULL)
  5519. {
  5520. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G : GBT DC
  5521. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  5522. {
  5523. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  5524. {
  5525. tempIndex = ((gun_index==2) ? 1: 0);
  5526. }
  5527. else
  5528. {
  5529. tempIndex = gun_index;
  5530. }
  5531. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  5532. {
  5533. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  5534. {
  5535. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargingCurrent );// PresentChargingCurrent is 0~6553.5 amp
  5536. }
  5537. }// End of for CHAdeMO_QUANTITY
  5538. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase,PhaseStr[L3_N]);
  5539. }
  5540. else if(gunType[gun_index] == GUN_TYPE_CCS)
  5541. {
  5542. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  5543. {
  5544. tempIndex = ((gun_index==2) ? 1: 0);
  5545. }
  5546. else
  5547. {
  5548. tempIndex = gun_index;
  5549. }
  5550. for (int index = 0; index < CCS_QUANTITY; index++)
  5551. {
  5552. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  5553. {
  5554. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargingCurrent );// PresentChargingCurrent is 0~6553.5 amp
  5555. }
  5556. }// End of for CCS_QUANTITY
  5557. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase,PhaseStr[L3_N]);
  5558. }
  5559. else if(gunType[gun_index] == GUN_TYPE_GBT)
  5560. {
  5561. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  5562. {
  5563. tempIndex = ((gun_index==2) ? 1: 0);
  5564. }
  5565. else
  5566. {
  5567. tempIndex = gun_index;
  5568. }
  5569. for (int index = 0; index < GB_QUANTITY; index++)
  5570. {
  5571. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  5572. {
  5573. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingCurrent );// PresentChargingCurrent is 0~6553.5 amp
  5574. }
  5575. }// End of for GB_QUANTITY
  5576. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase,PhaseStr[L3_N]);
  5577. }
  5578. else if(gunType[gun_index] == GUN_TYPE_DO)
  5579. {
  5580. tempIndex = gun_index;
  5581. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  5582. {
  5583. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  5584. {
  5585. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PresentChargingCurrent );// PresentChargingCurrent is 0~6553.5 amp
  5586. }
  5587. }
  5588. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase,PhaseStr[L3_N]);
  5589. }
  5590. else
  5591. {
  5592. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  5593. {
  5594. tempIndex = 2;
  5595. }
  5596. else
  5597. {
  5598. tempIndex = gun_index;
  5599. }
  5600. for (int index = 0; index < AC_QUANTITY; index++)
  5601. {
  5602. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  5603. {
  5604. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingCurrent );// 0~6553.5 amp for EVSE
  5605. }
  5606. }// End of for AC_QUANTITY
  5607. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase,PhaseStr[L1_N]);
  5608. }
  5609. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  5610. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Format,ValueFormatStr[Raw]);
  5611. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Measurand,MeasurandStr[Current_Import]);
  5612. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Location,LocationStr[Location_Outlet]);
  5613. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Unit,UnitOfMeasureStr[UnitOfMeasure_A]);
  5614. }
  5615. // ================================= Energy.Active.Import.Interval ==============================================
  5616. if(strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Energy.Active.Import.Interval") != NULL)
  5617. {
  5618. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  5619. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  5620. {
  5621. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  5622. {
  5623. tempIndex = ((gun_index==2) ? 1: 0);
  5624. }
  5625. else
  5626. {
  5627. tempIndex = gun_index;
  5628. }
  5629. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  5630. {
  5631. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  5632. {
  5633. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargedEnergy );// PresentChargedEnergy is 0~6553.5 kWh
  5634. }
  5635. }// END OF CHAdeMO_QUANTITY
  5636. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase,PhaseStr[L3_N]);
  5637. }
  5638. else if(gunType[gun_index] == GUN_TYPE_CCS)
  5639. {
  5640. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  5641. {
  5642. tempIndex = ((gun_index==2) ? 1: 0);
  5643. }
  5644. else
  5645. {
  5646. tempIndex = gun_index;
  5647. }
  5648. for (int index = 0; index < CCS_QUANTITY; index++)
  5649. {
  5650. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  5651. {
  5652. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargedEnergy );// PresentChargedEnergy is 0~6553.5 kWh
  5653. }
  5654. }// END OF CCS_QUANTITY
  5655. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase,PhaseStr[L3_N]);
  5656. }
  5657. else if(gunType[gun_index] == GUN_TYPE_GBT)
  5658. {
  5659. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  5660. {
  5661. tempIndex = ((gun_index==2) ? 1: 0);
  5662. }
  5663. else
  5664. {
  5665. tempIndex = gun_index;
  5666. }
  5667. for (int index = 0; index < GB_QUANTITY; index++)
  5668. {
  5669. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  5670. {
  5671. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargedEnergy );// PresentChargedEnergy is 0~6553.5 kWh
  5672. }
  5673. }// END OF GB_QUANTITY
  5674. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase,PhaseStr[L3_N]);
  5675. }
  5676. else if(gunType[gun_index] == GUN_TYPE_DO)
  5677. {
  5678. tempIndex = gun_index;
  5679. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  5680. {
  5681. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  5682. {
  5683. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PresentChargedEnergy );// PresentChargedEnergy is 0~6553.5 kWh
  5684. }
  5685. }
  5686. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase,PhaseStr[L3_N]);
  5687. }
  5688. else
  5689. {
  5690. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  5691. {
  5692. tempIndex = 2;
  5693. }
  5694. else
  5695. {
  5696. tempIndex = gun_index;
  5697. }
  5698. for (int index = 0; index < AC_QUANTITY; index++)
  5699. {
  5700. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  5701. {
  5702. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargedEnergy );// PresentChargedEnergy is 0~6553.5 kWh
  5703. }
  5704. }// END OF AC_QUANTITY
  5705. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase,PhaseStr[L1_N]);
  5706. }
  5707. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  5708. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Format,ValueFormatStr[Raw]);
  5709. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Measurand,MeasurandStr[Energy_Active_Import_Interval]);
  5710. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Location,LocationStr[Location_Outlet]);
  5711. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Unit,UnitOfMeasureStr[UnitOfMeasure_kWh]);
  5712. }
  5713. //=================================== Power.Active.Import ==================================================
  5714. if(strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Power.Active.Import") != NULL)
  5715. {
  5716. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  5717. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  5718. {
  5719. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  5720. {
  5721. tempIndex = ((gun_index==2) ? 1: 0);
  5722. }
  5723. else
  5724. {
  5725. tempIndex = gun_index;
  5726. }
  5727. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  5728. {
  5729. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  5730. {
  5731. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargingPower );// PresentChargingPower is 0~6553.5 kW
  5732. }
  5733. } // End for CHAdeMO_QUANTITY
  5734. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase,PhaseStr[L3_N]);
  5735. }
  5736. else if(gunType[gun_index] == GUN_TYPE_CCS)
  5737. {
  5738. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  5739. {
  5740. tempIndex = ((gun_index==2) ? 1: 0);
  5741. }
  5742. else
  5743. {
  5744. tempIndex = gun_index;
  5745. }
  5746. for (int index = 0; index < CCS_QUANTITY; index++)
  5747. {
  5748. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  5749. {
  5750. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargingPower );// PresentChargingPower is 0~6553.5 kW
  5751. }
  5752. } // END for CCS_QUANTITY
  5753. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase,PhaseStr[L3_N]);
  5754. }
  5755. else if(gunType[gun_index] == GUN_TYPE_GBT)
  5756. {
  5757. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  5758. {
  5759. tempIndex = ((gun_index==2) ? 1: 0);
  5760. }
  5761. else
  5762. {
  5763. tempIndex = gun_index;
  5764. }
  5765. for (int index = 0; index < GB_QUANTITY; index++)
  5766. {
  5767. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  5768. {
  5769. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingPower );// PresentChargingPower is 0~6553.5 kW
  5770. }
  5771. }// END for GB_QUANTITY
  5772. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase,PhaseStr[L3_N]);
  5773. }
  5774. else if(gunType[gun_index] == GUN_TYPE_DO)
  5775. {
  5776. tempIndex = gun_index;
  5777. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  5778. {
  5779. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  5780. {
  5781. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PresentChargingPower );// PresentChargingPower is 0~6553.5 kW
  5782. }
  5783. }
  5784. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase,PhaseStr[L3_N]);
  5785. }
  5786. else
  5787. {
  5788. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  5789. {
  5790. tempIndex = 2;
  5791. }
  5792. else
  5793. {
  5794. tempIndex = gun_index;
  5795. }
  5796. for (int index = 0; index < AC_QUANTITY; index++)
  5797. {
  5798. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  5799. {
  5800. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingPower );// PresentChargingPower is 0~6553.5 kW
  5801. }
  5802. } // END for AC_QUANTITY
  5803. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase,PhaseStr[L1_N]);
  5804. }
  5805. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  5806. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Format,ValueFormatStr[Raw]);
  5807. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Measurand,MeasurandStr[Power_Active_Import]);
  5808. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Location,LocationStr[Location_Outlet]);
  5809. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Unit,UnitOfMeasureStr[UnitOfMeasure_kW/*UnitOfMeasure_kWh*/]);
  5810. }
  5811. //============================ Voltage L1 ====================================
  5812. if(strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Voltage") != NULL)
  5813. {
  5814. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  5815. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  5816. {
  5817. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  5818. {
  5819. tempIndex = ((gun_index==2) ? 1: 0);
  5820. }
  5821. else
  5822. {
  5823. tempIndex = gun_index;
  5824. }
  5825. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  5826. {
  5827. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  5828. {
  5829. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargingVoltage );// PresentChargingVoltage is 0~6553.5 volt
  5830. }
  5831. } // END OF FOR CHAdeMO_QUANTITY
  5832. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase,PhaseStr[L3_N]);
  5833. }
  5834. else if(gunType[gun_index] == GUN_TYPE_CCS)
  5835. {
  5836. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  5837. {
  5838. tempIndex = ((gun_index==2) ? 1: 0);
  5839. }
  5840. else
  5841. {
  5842. tempIndex = gun_index;
  5843. }
  5844. for (int index = 0; index < CCS_QUANTITY; index++)
  5845. {
  5846. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  5847. {
  5848. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargingVoltage );// PresentChargingVoltage is 0~6553.5 volt
  5849. }
  5850. } // END OF FOR CCS_QUANTITY
  5851. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase,PhaseStr[L3_N]);
  5852. }
  5853. else if(gunType[gun_index] == GUN_TYPE_GBT)
  5854. {
  5855. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  5856. {
  5857. tempIndex = ((gun_index==2) ? 1: 0);
  5858. }
  5859. else
  5860. {
  5861. tempIndex = gun_index;
  5862. }
  5863. for (int index = 0; index < GB_QUANTITY; index++)
  5864. {
  5865. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  5866. {
  5867. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingVoltage );// PresentChargingVoltage is 0~6553.5 volt
  5868. }
  5869. } // END OF FOR GB_QUANTITY
  5870. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase,PhaseStr[L3_N]);
  5871. }
  5872. else if(gunType[gun_index] == GUN_TYPE_DO)
  5873. {
  5874. tempIndex = gun_index;
  5875. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  5876. {
  5877. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  5878. {
  5879. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PresentChargingVoltage );// PresentChargingVoltage is 0~6553.5 volt
  5880. }
  5881. }
  5882. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase,PhaseStr[L3_N]);
  5883. }
  5884. else
  5885. {
  5886. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  5887. {
  5888. tempIndex = 2;
  5889. }
  5890. else
  5891. {
  5892. tempIndex = gun_index;
  5893. }
  5894. for (int index = 0; index < AC_QUANTITY; index++)
  5895. {
  5896. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  5897. {
  5898. 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
  5899. }
  5900. } // END OF FOR AC_QUANTITY
  5901. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase,PhaseStr[L1_N]);
  5902. }
  5903. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  5904. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Format,ValueFormatStr[Raw]);
  5905. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Measurand,MeasurandStr[Voltage]);
  5906. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Location,LocationStr[Location_Outlet]);
  5907. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Unit,UnitOfMeasureStr[UnitOfMeasure_V]);
  5908. }
  5909. //====================== End SoC ================================
  5910. if(strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, MeasurandStr[SoC]) != NULL)
  5911. {
  5912. //J : CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  5913. 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))
  5914. {
  5915. if((ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0') && (gunType[gun_index] != GUN_TYPE_DO))
  5916. {
  5917. tempIndex = ((gun_index==2) ? 1: 0);
  5918. }
  5919. else
  5920. {
  5921. tempIndex = gun_index;
  5922. }
  5923. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  5924. {
  5925. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  5926. {
  5927. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  5928. {
  5929. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].EvBatterySoc );// 0~100%
  5930. }
  5931. }
  5932. }
  5933. else if(gunType[gun_index] == GUN_TYPE_CCS)
  5934. {
  5935. for (int index = 0; index < CCS_QUANTITY; index++)
  5936. {
  5937. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  5938. {
  5939. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].EvBatterySoc );// 0~100%
  5940. }
  5941. }
  5942. }
  5943. else if(gunType[gun_index] == GUN_TYPE_GBT)
  5944. {
  5945. for (int index = 0; index < GB_QUANTITY; index++)
  5946. {
  5947. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  5948. {
  5949. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].EvBatterySoc );// 0~100%
  5950. }
  5951. }
  5952. }
  5953. else if(gunType[gun_index] == GUN_TYPE_DO)
  5954. {
  5955. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  5956. {
  5957. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  5958. {
  5959. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.EvBatterySoc );// 0~100%
  5960. }
  5961. }
  5962. }
  5963. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  5964. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Format,ValueFormatStr[Raw]);
  5965. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Measurand,MeasurandStr[SoC/*Energy_Reactive_Export_Register*/]);
  5966. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Phase,PhaseStr[L3_N]);
  5967. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Location,LocationStr[Location_EV]);
  5968. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Unit,UnitOfMeasureStr[UnitOfMeasure_Percent/*UnitOfMeasure_kWh*/]);
  5969. } // END FOR DC CASE
  5970. }
  5971. // ================================= Current.Import L2 ===============================================
  5972. if(strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Current.Import") != NULL)
  5973. {
  5974. // AC 3 phse L2 current
  5975. if((gunType[gun_index] == GUN_TYPE_AC) && ((ShmSysConfigAndInfo->SysConfig.ModelName[2]=='Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='W') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='D')))
  5976. {
  5977. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  5978. {
  5979. tempIndex = 2;
  5980. }
  5981. else
  5982. {
  5983. tempIndex = gun_index;
  5984. }
  5985. for (int index = 0; index < AC_QUANTITY; index++)
  5986. {
  5987. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  5988. {
  5989. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingCurrentL2 );// 0~6553.5 amp for EVSE
  5990. }
  5991. }// End of for AC_QUANTITY
  5992. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Phase,PhaseStr[L2_N]);
  5993. }
  5994. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  5995. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Format,ValueFormatStr[Raw]);
  5996. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Measurand,MeasurandStr[Current_Import]);
  5997. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Location,LocationStr[Location_Outlet]);
  5998. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Unit,UnitOfMeasureStr[UnitOfMeasure_A]);
  5999. }
  6000. // ================================= Current.Import L3 ===============================================
  6001. if(strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Current.Import") != NULL)
  6002. {
  6003. // AC 3 phse L3 current
  6004. if((gunType[gun_index] == GUN_TYPE_AC) && ((ShmSysConfigAndInfo->SysConfig.ModelName[2]=='Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='W') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='D')))
  6005. {
  6006. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  6007. {
  6008. tempIndex = 2;
  6009. }
  6010. else
  6011. {
  6012. tempIndex = gun_index;
  6013. }
  6014. for (int index = 0; index < AC_QUANTITY; index++)
  6015. {
  6016. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  6017. {
  6018. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingCurrentL3 );// 0~6553.5 amp for EVSE
  6019. }
  6020. }// End of for AC_QUANTITY
  6021. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Phase,PhaseStr[L3_N]);
  6022. }
  6023. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  6024. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Format,ValueFormatStr[Raw]);
  6025. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Measurand,MeasurandStr[Current_Import]);
  6026. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Location,LocationStr[Location_Outlet]);
  6027. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Unit,UnitOfMeasureStr[UnitOfMeasure_A]);
  6028. }
  6029. //============================ Voltage L2 ====================================
  6030. if(strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Voltage") != NULL)
  6031. {
  6032. // AC 3 phse L2 voltage
  6033. if((gunType[gun_index] == GUN_TYPE_AC) && ((ShmSysConfigAndInfo->SysConfig.ModelName[2]=='Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='W') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='D')))
  6034. {
  6035. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  6036. {
  6037. tempIndex = 2;
  6038. }
  6039. else
  6040. {
  6041. tempIndex = gun_index;
  6042. }
  6043. for (int index = 0; index < AC_QUANTITY; index++)
  6044. {
  6045. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  6046. {
  6047. 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
  6048. }
  6049. } // END OF FOR AC_QUANTITY
  6050. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Phase,PhaseStr[L2_N]);
  6051. }
  6052. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  6053. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Format,ValueFormatStr[Raw]);
  6054. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Measurand,MeasurandStr[Voltage]);
  6055. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Location,LocationStr[Location_Outlet]);
  6056. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Unit,UnitOfMeasureStr[UnitOfMeasure_V]);
  6057. }
  6058. //============================ Voltage L3 ====================================
  6059. if(strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Voltage") != NULL)
  6060. {
  6061. // AC 3 phse L3 voltage
  6062. if((gunType[gun_index] == GUN_TYPE_AC) && ((ShmSysConfigAndInfo->SysConfig.ModelName[2]=='Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='W') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='D')))
  6063. {
  6064. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  6065. {
  6066. tempIndex = 2;
  6067. }
  6068. else
  6069. {
  6070. tempIndex = gun_index;
  6071. }
  6072. for (int index = 0; index < AC_QUANTITY; index++)
  6073. {
  6074. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  6075. {
  6076. 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
  6077. }
  6078. } // END OF FOR AC_QUANTITY
  6079. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Phase,PhaseStr[L3_N]);
  6080. }
  6081. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  6082. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Format,ValueFormatStr[Raw]);
  6083. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Measurand,MeasurandStr[Voltage]);
  6084. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Location,LocationStr[Location_Outlet]);
  6085. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Unit,UnitOfMeasureStr[UnitOfMeasure_V]);
  6086. }
  6087. //====================== Start SoC ================================
  6088. if(strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, MeasurandStr[SoC]) != NULL)
  6089. {
  6090. //J : CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  6091. 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))
  6092. {
  6093. if((ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0') && (gunType[gun_index] != GUN_TYPE_DO))
  6094. {
  6095. tempIndex = ((gun_index==2) ? 1: 0);
  6096. }
  6097. else
  6098. {
  6099. tempIndex = gun_index;
  6100. }
  6101. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  6102. {
  6103. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  6104. {
  6105. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  6106. {
  6107. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].EvBatteryStartSoc );// 0~100%
  6108. }
  6109. }
  6110. }
  6111. else if(gunType[gun_index] == GUN_TYPE_CCS)
  6112. {
  6113. for (int index = 0; index < CCS_QUANTITY; index++)
  6114. {
  6115. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  6116. {
  6117. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].EvBatteryStartSoc );// 0~100%
  6118. }
  6119. }
  6120. }
  6121. else if(gunType[gun_index] == GUN_TYPE_GBT)
  6122. {
  6123. for (int index = 0; index < GB_QUANTITY; index++)
  6124. {
  6125. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  6126. {
  6127. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].EvBatteryStartSoc );// 0~100%
  6128. }
  6129. }
  6130. }
  6131. else if(gunType[gun_index] == GUN_TYPE_DO)
  6132. {
  6133. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  6134. {
  6135. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  6136. {
  6137. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.EvBatteryStartSoc );// 0~100%
  6138. }
  6139. }
  6140. }
  6141. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Context,ReadingContextStr[ReadingContext_Transaction_Begin]);
  6142. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Format,ValueFormatStr[Raw]);
  6143. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Measurand,MeasurandStr[SoC/*Energy_Reactive_Export_Register*/]);
  6144. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Phase,PhaseStr[L3_N]);
  6145. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Location,LocationStr[Location_EV]);
  6146. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Unit,UnitOfMeasureStr[UnitOfMeasure_Percent/*UnitOfMeasure_kWh*/]);
  6147. } // END FOR DC CASE
  6148. }
  6149. //================================================ Message create ====================================================
  6150. json_object *StopTransaction = json_object_new_object();
  6151. json_object *transactionDatas = json_object_new_array();
  6152. json_object *sampledValues = json_object_new_array();
  6153. if(strlen((char*)ShmOCPP16Data->StopTransaction[gun_index].IdTag) > 0)
  6154. json_object_object_add(StopTransaction, "idTag", json_object_new_string((char*)ShmOCPP16Data->StopTransaction[gun_index].IdTag));
  6155. json_object_object_add(StopTransaction, "meterStop", json_object_new_int(ShmOCPP16Data->StopTransaction[gun_index].MeterStop));
  6156. json_object_object_add(StopTransaction, "transactionId", json_object_new_int(ShmOCPP16Data->StopTransaction[gun_index].TransactionId));
  6157. json_object_object_add(StopTransaction, "timestamp", json_object_new_string((char*)ShmOCPP16Data->StopTransaction[gun_index].Timestamp));
  6158. if(strlen((char*)ShmOCPP16Data->StopTransaction[gun_index].StopReason) > 0)
  6159. json_object_object_add(StopTransaction, "reason", json_object_new_string((char*)ShmOCPP16Data->StopTransaction[gun_index].StopReason));
  6160. for(int idxTrans = 0;idxTrans<ARRAY_SIZE(ShmOCPP16Data->StopTransaction[gun_index].TransactionData);idxTrans++)
  6161. {
  6162. json_object *transactionData = json_object_new_object();
  6163. json_object_object_add(transactionData, "timestamp", json_object_new_string((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].TimeStamp));
  6164. for(int idx=0;idx<ARRAY_SIZE(ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue);idx++)
  6165. {
  6166. if(strlen((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Value) > 0)
  6167. {
  6168. json_object *sampledValue = json_object_new_object();
  6169. json_object_object_add(sampledValue, "value", json_object_new_string((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Value));
  6170. if(strlen((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Context) > 0)
  6171. json_object_object_add(sampledValue, "context", json_object_new_string((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Context));
  6172. if(strlen((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Format) > 0)
  6173. json_object_object_add(sampledValue, "format", json_object_new_string((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Format));
  6174. if(strlen((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Measurand) > 0)
  6175. json_object_object_add(sampledValue, "measurand", json_object_new_string((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Measurand));
  6176. if(strlen((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Phase) > 0)
  6177. json_object_object_add(sampledValue, "phase", json_object_new_string((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Phase));
  6178. if(strlen((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Location) > 0)
  6179. json_object_object_add(sampledValue, "location", json_object_new_string((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Location));
  6180. if(strlen((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Unit) > 0)
  6181. json_object_object_add(sampledValue, "unit", json_object_new_string((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Unit));
  6182. json_object_array_add(sampledValues, sampledValue);
  6183. }
  6184. }
  6185. json_object_object_add(transactionData, "sampledValue", sampledValues);
  6186. json_object_array_add(transactionDatas, transactionData);
  6187. }
  6188. json_object_object_add(StopTransaction, "transactionData", transactionDatas);
  6189. sprintf(queuedata, "%d,[%d,\"%s\",\"StopTransaction\",%s]",(gun_index+1)
  6190. ,MESSAGE_TYPE_CALL
  6191. ,guid
  6192. ,json_object_to_json_string_ext(StopTransaction, JSON_C_TO_STRING_PLAIN));
  6193. json_object_put(StopTransaction);
  6194. #if 1 // for TempStopTransaction
  6195. //Delete TempStopTransaction
  6196. if((access(TempStopTransaction,F_OK))!=-1)
  6197. {
  6198. remove(TempStopTransaction); // remove file "TempStopTransaction"
  6199. }
  6200. #endif
  6201. #if 1
  6202. sprintf(tempdata, "StopTransaction,%d", (gun_index));
  6203. if(hashmap_operation(HASH_OP_ADD, guid, tempdata) == 1)
  6204. {
  6205. result = PASS;
  6206. //DEBUG_INFO("StopTransaction mapitem pass\n");
  6207. }
  6208. #endif
  6209. queue_operation(QUEUE_OPERATION_ADD, guid, queuedata );//addq(guid, queuedata); ---> remove temporally
  6210. OCPP_insert_transaction_msg(NO, queuedata);
  6211. //----------------------------replace queue StopTransaction TransactionId ---------------------------//
  6212. //int gettransactionId = GetTransactionId(gun_index+1, ShmOCPP16Data->StopTransaction[gun_index].IdTag);
  6213. int gettransactionId = GetTransactionId(gun_index+1, ShmOCPP16Data->StartTransaction[gun_index].IdTag, TRUE);
  6214. if((ShmOCPP16Data->StopTransaction[gun_index].TransactionId != 0) && (gettransactionId != 0))
  6215. {
  6216. SetTransactionIdZero(ShmOCPP16Data->StopTransaction[gun_index].TransactionId);
  6217. }
  6218. //for test
  6219. //ShmOCPP16Data->CpMsg.bits[gun_index].StopTransactionReq = 0;
  6220. return result;
  6221. }
  6222. int sendMeterValuesRequest(int gun_index, ReadingContext dataType)
  6223. {
  6224. mtrace();
  6225. int result = FAIL;
  6226. char guid[37]={0};
  6227. char tempdata[65]={0};
  6228. int tempIndex = 0;
  6229. DEBUG_INFO("sendMeterValuesRequest ...\n");
  6230. memset(queuedata, 0, ARRAY_SIZE(queuedata));
  6231. memset(&ShmOCPP16Data->MeterValues[gun_index], 0, sizeof(struct StructMeterValues));
  6232. //set value
  6233. ShmOCPP16Data->MeterValues[gun_index].ConnectorId = gun_index + 1; // gun start from 1~
  6234. ShmOCPP16Data->MeterValues[gun_index].TransactionId = (cpinitateMsg.bits[gun_index].isOnCharging?
  6235. ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId :
  6236. -1);
  6237. random_uuid(guid);
  6238. //UTC Date time
  6239. struct timeval tmnow;
  6240. struct tm *tm;
  6241. char buf[28];//, usec_buf[6];
  6242. gettimeofday(&tmnow, NULL);
  6243. time_t t;
  6244. t = time(NULL);
  6245. /*UTC time and date*/
  6246. tm = gmtime(&t);
  6247. strftime(buf,28,"%Y-%m-%dT%H:%M:%SZ", tm);
  6248. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].TimeStamp, buf);
  6249. //DEBUG_INFO("ShmSysConfigAndInfo->SysConfig.ModelName[0]=%c\n", ShmSysConfigAndInfo->SysConfig.ModelName[0]);
  6250. //********************************(1)Current.Import L1************************************************/
  6251. if(((dataType == ReadingContext_Sample_Clock) && (strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, MeasurandStr[Current_Import]) != NULL)) ||
  6252. ((dataType == ReadingContext_Sample_Periodic) && (strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, MeasurandStr[Current_Import]) != NULL)) ||
  6253. (dataType == ReadingContext_Trigger))
  6254. {
  6255. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  6256. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  6257. {
  6258. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  6259. {
  6260. tempIndex = ((gun_index==2) ? 1: 0);
  6261. }
  6262. else
  6263. {
  6264. tempIndex = gun_index;
  6265. }
  6266. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  6267. {
  6268. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  6269. {
  6270. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargingCurrent );
  6271. }
  6272. }
  6273. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Phase, PhaseStr[L3_N]);
  6274. }
  6275. else if(gunType[gun_index] == GUN_TYPE_CCS)
  6276. {
  6277. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  6278. {
  6279. tempIndex = ((gun_index==2) ? 1: 0);
  6280. }
  6281. else
  6282. {
  6283. tempIndex = gun_index;
  6284. }
  6285. for (int index = 0; index < CCS_QUANTITY; index++)
  6286. {
  6287. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  6288. {
  6289. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargingCurrent );
  6290. }
  6291. }
  6292. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Phase, PhaseStr[L3_N]);
  6293. }
  6294. else if(gunType[gun_index] == GUN_TYPE_GBT)
  6295. {
  6296. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  6297. {
  6298. tempIndex = ((gun_index==2) ? 1: 0);
  6299. }
  6300. else
  6301. {
  6302. tempIndex = gun_index;
  6303. }
  6304. for (int index = 0; index < GB_QUANTITY; index++)
  6305. {
  6306. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  6307. {
  6308. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingCurrent );
  6309. }
  6310. }
  6311. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Phase, PhaseStr[L3_N]);
  6312. }
  6313. else if(gunType[gun_index] == GUN_TYPE_DO)
  6314. {
  6315. tempIndex = gun_index;
  6316. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  6317. {
  6318. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  6319. {
  6320. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PresentChargingCurrent );
  6321. }
  6322. }
  6323. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Phase, PhaseStr[L3_N]);
  6324. }
  6325. else
  6326. {
  6327. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  6328. {
  6329. tempIndex = 2;
  6330. }
  6331. else
  6332. {
  6333. tempIndex = gun_index;
  6334. }
  6335. for (int index = 0; index < AC_QUANTITY; index++)
  6336. {
  6337. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  6338. {
  6339. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingCurrent );
  6340. }
  6341. }
  6342. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Phase, PhaseStr[L1_N]);
  6343. }
  6344. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Context, ReadingContextStr[dataType]);
  6345. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Format, ValueFormatStr[Raw]);
  6346. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Measurand, MeasurandStr[Current_Import]);
  6347. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Location, LocationStr[Location_Outlet]);
  6348. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Unit,UnitOfMeasureStr[UnitOfMeasure_A]);
  6349. }
  6350. //********************************(2)Energy.Active.Import.Register ************************************************/
  6351. if(((dataType == ReadingContext_Sample_Clock) && (strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, MeasurandStr[Energy_Active_Import_Register]) != NULL)) ||
  6352. ((dataType == ReadingContext_Sample_Periodic) && (strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, MeasurandStr[Energy_Active_Import_Register]) != NULL)) ||
  6353. (dataType == ReadingContext_Trigger))
  6354. {
  6355. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  6356. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  6357. {
  6358. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  6359. {
  6360. tempIndex = ((gun_index==2) ? 1: 0);
  6361. }
  6362. else
  6363. {
  6364. tempIndex = gun_index;
  6365. }
  6366. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  6367. {
  6368. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  6369. {
  6370. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PowerConsumption );
  6371. }
  6372. }
  6373. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Phase, PhaseStr[L3_N]);
  6374. }
  6375. else if(gunType[gun_index] == GUN_TYPE_CCS)
  6376. {
  6377. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  6378. {
  6379. tempIndex = ((gun_index==2) ? 1: 0);
  6380. }
  6381. else
  6382. {
  6383. tempIndex = gun_index;
  6384. }
  6385. for (int index = 0; index < CCS_QUANTITY; index++)
  6386. {
  6387. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  6388. {
  6389. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PowerConsumption );
  6390. }
  6391. }
  6392. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Phase, PhaseStr[L3_N]);
  6393. }
  6394. else if(gunType[gun_index] == GUN_TYPE_GBT)
  6395. {
  6396. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  6397. {
  6398. tempIndex = ((gun_index==2) ? 1: 0);
  6399. }
  6400. else
  6401. {
  6402. tempIndex = gun_index;
  6403. }
  6404. for (int index = 0; index < GB_QUANTITY; index++)
  6405. {
  6406. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  6407. {
  6408. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PowerConsumption );
  6409. }
  6410. }
  6411. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Phase, PhaseStr[L3_N]);
  6412. }
  6413. else if(gunType[gun_index] == GUN_TYPE_DO)
  6414. {
  6415. tempIndex = gun_index;
  6416. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  6417. {
  6418. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  6419. {
  6420. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PowerConsumption );
  6421. }
  6422. }
  6423. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Phase, PhaseStr[L3_N]);
  6424. }
  6425. else
  6426. {
  6427. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  6428. {
  6429. tempIndex = 2;
  6430. }
  6431. else
  6432. {
  6433. tempIndex = gun_index;
  6434. }
  6435. for (int index = 0; index < AC_QUANTITY; index++)
  6436. {
  6437. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  6438. {
  6439. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PowerConsumption );
  6440. }
  6441. }
  6442. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Phase, PhaseStr[L1_N]);
  6443. }
  6444. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Context, ReadingContextStr[dataType]);
  6445. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Format, ValueFormatStr[Raw]);
  6446. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Measurand, MeasurandStr[Energy_Active_Import_Register]);
  6447. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Location, LocationStr[Location_Outlet]);
  6448. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Unit,UnitOfMeasureStr[UnitOfMeasure_kWh]);
  6449. }
  6450. //****************************************************(3)Energy.Active.Import.Interval*********************************************/
  6451. if(((dataType == ReadingContext_Sample_Clock) && (strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, MeasurandStr[Energy_Active_Import_Interval]) != NULL)) ||
  6452. ((dataType == ReadingContext_Sample_Periodic) && (strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, MeasurandStr[Energy_Active_Import_Interval]) != NULL)) ||
  6453. (dataType == ReadingContext_Trigger))
  6454. {
  6455. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  6456. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  6457. {
  6458. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  6459. {
  6460. tempIndex = ((gun_index==2) ? 1: 0);
  6461. }
  6462. else
  6463. {
  6464. tempIndex = gun_index;
  6465. }
  6466. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  6467. {
  6468. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  6469. {
  6470. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargedEnergy );
  6471. }
  6472. } // END OF FOR CHAdeMO_QUANTITY
  6473. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Phase, PhaseStr[L3_N]);
  6474. }
  6475. else if(gunType[gun_index] == GUN_TYPE_CCS)
  6476. {
  6477. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  6478. {
  6479. tempIndex = ((gun_index==2) ? 1: 0);
  6480. }
  6481. else
  6482. {
  6483. tempIndex = gun_index;
  6484. }
  6485. for (int index = 0; index < CCS_QUANTITY; index++)
  6486. {
  6487. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  6488. {
  6489. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargedEnergy );
  6490. }
  6491. } // END OF CCS_QUANTITY
  6492. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Phase, PhaseStr[L3_N]);
  6493. }
  6494. else if(gunType[gun_index] == GUN_TYPE_GBT)
  6495. {
  6496. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  6497. {
  6498. tempIndex = ((gun_index==2) ? 1: 0);
  6499. }
  6500. else
  6501. {
  6502. tempIndex = gun_index;
  6503. }
  6504. for (int index = 0; index < GB_QUANTITY; index++)
  6505. {
  6506. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  6507. {
  6508. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargedEnergy);
  6509. }
  6510. } // END OF GB_QUANTITY
  6511. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Phase, PhaseStr[L3_N]);
  6512. }
  6513. else if(gunType[gun_index] == GUN_TYPE_DO)
  6514. {
  6515. tempIndex = gun_index;
  6516. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  6517. {
  6518. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  6519. {
  6520. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PresentChargedEnergy);
  6521. }
  6522. }
  6523. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Phase, PhaseStr[L3_N]);
  6524. }
  6525. else
  6526. {
  6527. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  6528. {
  6529. tempIndex = 2;
  6530. }
  6531. else
  6532. {
  6533. tempIndex = gun_index;
  6534. }
  6535. for (int index = 0; index < AC_QUANTITY; index++)
  6536. {
  6537. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  6538. {
  6539. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargedEnergy );
  6540. }
  6541. }
  6542. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Phase, PhaseStr[L1_N]);
  6543. }
  6544. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Context, ReadingContextStr[dataType]);
  6545. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Format, ValueFormatStr[Raw]);
  6546. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Measurand, MeasurandStr[Energy_Active_Import_Interval]);
  6547. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Location, LocationStr[Location_Outlet]);
  6548. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Unit,UnitOfMeasureStr[UnitOfMeasure_kWh]);
  6549. }
  6550. //********************************(4)Power.Active.Import************************************************/
  6551. if(((dataType == ReadingContext_Sample_Clock) && (strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, MeasurandStr[Power_Active_Import]) != NULL)) ||
  6552. ((dataType == ReadingContext_Sample_Periodic) && (strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, MeasurandStr[Power_Active_Import]) != NULL)) ||
  6553. (dataType == ReadingContext_Trigger))
  6554. {
  6555. //J : CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  6556. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  6557. {
  6558. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  6559. {
  6560. tempIndex = ((gun_index==2) ? 1: 0);
  6561. }
  6562. else
  6563. {
  6564. tempIndex = gun_index;
  6565. }
  6566. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  6567. {
  6568. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  6569. {
  6570. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Value, "%.1f" , ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargingPower);
  6571. }
  6572. } // END OF FOR
  6573. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Phase, PhaseStr[L3_N]);
  6574. }
  6575. else if(gunType[gun_index] == GUN_TYPE_CCS)
  6576. {
  6577. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  6578. {
  6579. tempIndex = ((gun_index==2) ? 1: 0);
  6580. }
  6581. else
  6582. {
  6583. tempIndex = gun_index;
  6584. }
  6585. for (int index = 0; index < CCS_QUANTITY; index++)
  6586. {
  6587. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  6588. {
  6589. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Value, "%.1f" , ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargingPower);
  6590. }
  6591. }
  6592. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Phase, PhaseStr[L3_N]);
  6593. }
  6594. else if(gunType[gun_index] == GUN_TYPE_GBT)
  6595. {
  6596. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  6597. {
  6598. tempIndex = ((gun_index==2) ? 1: 0);
  6599. }
  6600. else
  6601. {
  6602. tempIndex = gun_index;
  6603. }
  6604. for (int index = 0; index < GB_QUANTITY; index++)
  6605. {
  6606. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  6607. {
  6608. //ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingPower = 100.0;
  6609. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Value, "%.1f" , ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingPower);
  6610. }
  6611. }
  6612. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Phase, PhaseStr[L3_N]);
  6613. }
  6614. else if(gunType[gun_index] == GUN_TYPE_DO)
  6615. {
  6616. tempIndex = gun_index;
  6617. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  6618. {
  6619. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  6620. {
  6621. //ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingPower = 100.0;
  6622. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Value, "%.1f" , ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PresentChargingPower);
  6623. }
  6624. }
  6625. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Phase, PhaseStr[L3_N]);
  6626. }
  6627. else
  6628. {
  6629. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  6630. {
  6631. tempIndex = 2;
  6632. }
  6633. else
  6634. {
  6635. tempIndex = gun_index;
  6636. }
  6637. for (int index = 0; index < AC_QUANTITY; index++)
  6638. {
  6639. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  6640. {
  6641. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Value, "%.1f" , ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingPower);
  6642. }
  6643. }
  6644. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Phase, PhaseStr[L1_N]);
  6645. }
  6646. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Context, ReadingContextStr[dataType]);
  6647. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Format, ValueFormatStr[Raw]);
  6648. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Measurand, MeasurandStr[Power_Active_Import]);
  6649. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Location, LocationStr[Location_Outlet]);
  6650. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Unit,UnitOfMeasureStr[UnitOfMeasure_kW]);
  6651. }
  6652. //***********************************************(5)VOLTAGE L1******************************************************/
  6653. if(((dataType == ReadingContext_Sample_Clock) && (strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, MeasurandStr[Voltage]) != NULL)) ||
  6654. ((dataType == ReadingContext_Sample_Periodic) && (strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, MeasurandStr[Voltage]) != NULL)) ||
  6655. (dataType == ReadingContext_Trigger))
  6656. {
  6657. //J : CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  6658. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  6659. {
  6660. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  6661. {
  6662. tempIndex = ((gun_index==2) ? 1: 0);
  6663. }
  6664. else
  6665. {
  6666. tempIndex = gun_index;
  6667. }
  6668. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  6669. {
  6670. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  6671. {
  6672. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargingVoltage );
  6673. }
  6674. }
  6675. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Phase, PhaseStr[L3_N]);
  6676. }
  6677. else if(gunType[gun_index] == GUN_TYPE_CCS)
  6678. {
  6679. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  6680. {
  6681. tempIndex = ((gun_index==2) ? 1: 0);
  6682. }
  6683. else
  6684. {
  6685. tempIndex = gun_index;
  6686. }
  6687. for (int index = 0; index < CCS_QUANTITY; index++)
  6688. {
  6689. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  6690. {
  6691. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargingVoltage );
  6692. }
  6693. }
  6694. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Phase, PhaseStr[L3_N]);
  6695. }
  6696. else if(gunType[gun_index] == GUN_TYPE_GBT)
  6697. {
  6698. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  6699. {
  6700. tempIndex = ((gun_index==2) ? 1: 0);
  6701. }
  6702. else
  6703. {
  6704. tempIndex = gun_index;
  6705. }
  6706. for (int index = 0; index < GB_QUANTITY; index++)
  6707. {
  6708. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  6709. {
  6710. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingVoltage );
  6711. }
  6712. }
  6713. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Phase, PhaseStr[L3_N]);
  6714. }
  6715. else if(gunType[gun_index] == GUN_TYPE_DO)
  6716. {
  6717. tempIndex = gun_index;
  6718. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  6719. {
  6720. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  6721. {
  6722. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PresentChargingVoltage );
  6723. }
  6724. }
  6725. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Phase, PhaseStr[L3_N]);
  6726. }
  6727. else
  6728. {
  6729. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  6730. {
  6731. tempIndex = 2;
  6732. }
  6733. else
  6734. {
  6735. tempIndex = gun_index;
  6736. }
  6737. for (int index = 0; index < AC_QUANTITY; index++)
  6738. {
  6739. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  6740. {
  6741. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingVoltage );
  6742. }
  6743. }
  6744. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Phase, PhaseStr[L1_N]);
  6745. }
  6746. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Context, ReadingContextStr[dataType]);
  6747. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Format, ValueFormatStr[Raw]);
  6748. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Measurand, MeasurandStr[Voltage]);
  6749. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Location, LocationStr[Location_Outlet]);
  6750. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Unit,UnitOfMeasureStr[UnitOfMeasure_V]);
  6751. }
  6752. //***********************************************(6)SOC******************************************************/
  6753. if(((dataType == ReadingContext_Sample_Clock) && (strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, MeasurandStr[SoC]) != NULL)) ||
  6754. ((dataType == ReadingContext_Sample_Periodic) && (strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, MeasurandStr[SoC]) != NULL)) ||
  6755. (dataType == ReadingContext_Trigger))
  6756. {
  6757. 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))
  6758. {
  6759. //idx_sample=5;
  6760. //sampledValue = NULL;
  6761. if((ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0') && (gunType[gun_index] != GUN_TYPE_DO))
  6762. {
  6763. tempIndex = ((gun_index==2) ? 1: 0);
  6764. }
  6765. else
  6766. {
  6767. tempIndex = gun_index;
  6768. }
  6769. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  6770. {
  6771. //tempIndex = ((gun_index==2) ? 1: 0);
  6772. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  6773. {
  6774. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  6775. {
  6776. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].EvBatterySoc );
  6777. }
  6778. }
  6779. }
  6780. else if(gunType[gun_index] == GUN_TYPE_CCS)
  6781. {
  6782. //tempIndex = ((gun_index==2) ? 1: 0);
  6783. for (int index = 0; index < CCS_QUANTITY; index++)
  6784. {
  6785. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  6786. {
  6787. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].EvBatterySoc );
  6788. }
  6789. }
  6790. }
  6791. else if(gunType[gun_index] == GUN_TYPE_GBT)
  6792. {
  6793. //tempIndex = ((gun_index==2) ? 1: 0);
  6794. for (int index = 0; index < GB_QUANTITY; index++)
  6795. {
  6796. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  6797. {
  6798. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].EvBatterySoc );
  6799. }
  6800. }
  6801. }
  6802. else if(gunType[gun_index] == GUN_TYPE_DO)
  6803. {
  6804. //tempIndex = ((gun_index==2) ? 1: 0);
  6805. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  6806. {
  6807. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  6808. {
  6809. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.EvBatterySoc );
  6810. }
  6811. }
  6812. }
  6813. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[5].Context, ReadingContextStr[dataType]);
  6814. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[5].Format, ValueFormatStr[Raw]);
  6815. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[5].Measurand, MeasurandStr[SoC]);
  6816. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[5].Phase, PhaseStr[L3_N]);
  6817. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[5].Location, LocationStr[Location_EV]);
  6818. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[5].Unit,UnitOfMeasureStr[UnitOfMeasure_Percent]);
  6819. }
  6820. }
  6821. //********************************(7)Current.Import L2************************************************/
  6822. if(((dataType == ReadingContext_Sample_Clock) && (strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, MeasurandStr[Current_Import]) != NULL)) ||
  6823. ((dataType == ReadingContext_Sample_Periodic) && (strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, MeasurandStr[Current_Import]) != NULL)) ||
  6824. (dataType == ReadingContext_Trigger))
  6825. {
  6826. // Only for AC 3 phase
  6827. if((gunType[gun_index] == GUN_TYPE_AC) && ((ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'W') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='D')))
  6828. {
  6829. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  6830. {
  6831. tempIndex = 2;
  6832. }
  6833. else
  6834. {
  6835. tempIndex = gun_index;
  6836. }
  6837. for (int index = 0; index < AC_QUANTITY; index++)
  6838. {
  6839. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  6840. {
  6841. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[6].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingCurrentL2);
  6842. }
  6843. }
  6844. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[6].Phase, PhaseStr[L2_N]);
  6845. }
  6846. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[6].Context, ReadingContextStr[dataType]);
  6847. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[6].Format, ValueFormatStr[Raw]);
  6848. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[6].Measurand, MeasurandStr[Current_Import]);
  6849. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[6].Location, LocationStr[Location_Outlet]);
  6850. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[6].Unit,UnitOfMeasureStr[UnitOfMeasure_A]);
  6851. }
  6852. //********************************(8)Current.Import L3************************************************/
  6853. if(((dataType == ReadingContext_Sample_Clock) && (strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, MeasurandStr[Current_Import]) != NULL)) ||
  6854. ((dataType == ReadingContext_Sample_Periodic) && (strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, MeasurandStr[Current_Import]) != NULL)) ||
  6855. (dataType == ReadingContext_Trigger))
  6856. {
  6857. // Only for AC 3 phase
  6858. if((gunType[gun_index] == GUN_TYPE_AC) && ((ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'W') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='D')))
  6859. {
  6860. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  6861. {
  6862. tempIndex = 2;
  6863. }
  6864. else
  6865. {
  6866. tempIndex = gun_index;
  6867. }
  6868. for (int index = 0; index < AC_QUANTITY; index++)
  6869. {
  6870. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  6871. {
  6872. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[7].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingCurrentL3);
  6873. }
  6874. }
  6875. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[7].Phase, PhaseStr[L3_N]);
  6876. }
  6877. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[7].Context, ReadingContextStr[dataType]);
  6878. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[7].Format, ValueFormatStr[Raw]);
  6879. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[7].Measurand, MeasurandStr[Current_Import]);
  6880. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[7].Location, LocationStr[Location_Outlet]);
  6881. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[7].Unit,UnitOfMeasureStr[UnitOfMeasure_A]);
  6882. }
  6883. //***********************************************(9)VOLTAGE L2******************************************************/
  6884. if(((dataType == ReadingContext_Sample_Clock) && (strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, MeasurandStr[Voltage]) != NULL)) ||
  6885. ((dataType == ReadingContext_Sample_Periodic) && (strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, MeasurandStr[Voltage]) != NULL)) ||
  6886. (dataType == ReadingContext_Trigger))
  6887. {
  6888. if((gunType[gun_index] == GUN_TYPE_AC) && ((ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'W') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='D')))
  6889. {
  6890. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  6891. {
  6892. tempIndex = 2;
  6893. }
  6894. else
  6895. {
  6896. tempIndex = gun_index;
  6897. }
  6898. for (int index = 0; index < AC_QUANTITY; index++)
  6899. {
  6900. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  6901. {
  6902. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[8].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingVoltageL2);
  6903. }
  6904. }
  6905. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[8].Phase, PhaseStr[L2_N]);
  6906. }
  6907. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[8].Context, ReadingContextStr[dataType]);
  6908. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[8].Format, ValueFormatStr[Raw]);
  6909. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[8].Measurand, MeasurandStr[Voltage]);
  6910. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[8].Location, LocationStr[Location_Outlet]);
  6911. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[8].Unit,UnitOfMeasureStr[UnitOfMeasure_V]);
  6912. }
  6913. //***********************************************(10)VOLTAGE L3******************************************************/
  6914. if(((dataType == ReadingContext_Sample_Clock) && (strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, MeasurandStr[Voltage]) != NULL)) ||
  6915. ((dataType == ReadingContext_Sample_Periodic) && (strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, MeasurandStr[Voltage]) != NULL)) ||
  6916. (dataType == ReadingContext_Trigger))
  6917. {
  6918. if((gunType[gun_index] == GUN_TYPE_AC) && ((ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'W') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='D')))
  6919. {
  6920. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  6921. {
  6922. tempIndex = 2;
  6923. }
  6924. else
  6925. {
  6926. tempIndex = gun_index;
  6927. }
  6928. for (int index = 0; index < AC_QUANTITY; index++)
  6929. {
  6930. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  6931. {
  6932. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[9].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingVoltageL3);
  6933. }
  6934. }
  6935. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[9].Phase, PhaseStr[L3_N]);
  6936. }
  6937. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[9].Context, ReadingContextStr[dataType]);
  6938. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[9].Format, ValueFormatStr[Raw]);
  6939. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[9].Measurand, MeasurandStr[Voltage]);
  6940. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[9].Location, LocationStr[Location_Outlet]);
  6941. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[9].Unit,UnitOfMeasureStr[UnitOfMeasure_V]);
  6942. }
  6943. //***********************************************(11)Current.Offered******************************************************/
  6944. if(((dataType == ReadingContext_Sample_Clock) && (strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, MeasurandStr[Current_Offered]) != NULL)) ||
  6945. ((dataType == ReadingContext_Sample_Periodic) && (strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, MeasurandStr[Current_Offered]) != NULL)) ||
  6946. (dataType == ReadingContext_Trigger))
  6947. {
  6948. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  6949. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  6950. {
  6951. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  6952. {
  6953. tempIndex = ((gun_index==2) ? 1: 0);
  6954. }
  6955. else
  6956. {
  6957. tempIndex = gun_index;
  6958. }
  6959. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  6960. {
  6961. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  6962. {
  6963. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[10].Value, "%d", (uint16_t) (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].CurrentOffered/10));
  6964. }
  6965. } // END OF FOR CHAdeMO_QUANTITY
  6966. }
  6967. else if(gunType[gun_index] == GUN_TYPE_CCS)
  6968. {
  6969. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  6970. {
  6971. tempIndex = ((gun_index==2) ? 1: 0);
  6972. }
  6973. else
  6974. {
  6975. tempIndex = gun_index;
  6976. }
  6977. for (int index = 0; index < CCS_QUANTITY; index++)
  6978. {
  6979. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  6980. {
  6981. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[10].Value, "%d", (uint16_t) (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].CurrentOffered/10));
  6982. }
  6983. } // END OF CCS_QUANTITY
  6984. }
  6985. else if(gunType[gun_index] == GUN_TYPE_GBT)
  6986. {
  6987. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  6988. {
  6989. tempIndex = ((gun_index==2) ? 1: 0);
  6990. }
  6991. else
  6992. {
  6993. tempIndex = gun_index;
  6994. }
  6995. for (int index = 0; index < GB_QUANTITY; index++)
  6996. {
  6997. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  6998. {
  6999. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[10].Value, "%d", (uint16_t) (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].CurrentOffered/10));
  7000. }
  7001. } // END OF GB_QUANTITY
  7002. }
  7003. else if(gunType[gun_index] == GUN_TYPE_DO)
  7004. {
  7005. tempIndex = gun_index;
  7006. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  7007. {
  7008. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  7009. {
  7010. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[10].Value, "%d", (uint16_t) (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.CurrentOffered/10));
  7011. }
  7012. }
  7013. }
  7014. else
  7015. {
  7016. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  7017. {
  7018. tempIndex = 2;
  7019. }
  7020. else
  7021. {
  7022. tempIndex = gun_index;
  7023. }
  7024. for (int index = 0; index < AC_QUANTITY; index++)
  7025. {
  7026. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  7027. {
  7028. uint16_t currentOffer;
  7029. if(ShmSysConfigAndInfo->SysConfig.MaxChargingCurrent == 0)
  7030. {
  7031. currentOffer = ShmSysConfigAndInfo->SysConfig.RatingCurrent;
  7032. }
  7033. else
  7034. {
  7035. currentOffer = ((ShmSysConfigAndInfo->SysConfig.MaxChargingCurrent>ShmSysConfigAndInfo->SysConfig.RatingCurrent)?ShmSysConfigAndInfo->SysConfig.RatingCurrent:ShmSysConfigAndInfo->SysConfig.MaxChargingCurrent);
  7036. }
  7037. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[10].Value, "%d", currentOffer);
  7038. }
  7039. }
  7040. }
  7041. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[10].Context, ReadingContextStr[dataType]);
  7042. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[10].Format, ValueFormatStr[Raw]);
  7043. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[10].Measurand, MeasurandStr[Current_Offered]);
  7044. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[10].Location, LocationStr[Location_Outlet]);
  7045. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[10].Unit,UnitOfMeasureStr[UnitOfMeasure_A]);
  7046. }
  7047. //***********************************************(12)Power.Offered******************************************************/
  7048. if(((dataType == ReadingContext_Sample_Clock) && (strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, MeasurandStr[Power_Offered]) != NULL) && (gunType[gun_index] != GUN_TYPE_AC)) ||
  7049. ((dataType == ReadingContext_Sample_Periodic) && (strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, MeasurandStr[Power_Offered]) != NULL) && (gunType[gun_index] != GUN_TYPE_AC)) ||
  7050. ((dataType == ReadingContext_Trigger) && (gunType[gun_index] != GUN_TYPE_AC)))
  7051. {
  7052. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  7053. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  7054. {
  7055. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  7056. {
  7057. tempIndex = ((gun_index==2) ? 1: 0);
  7058. }
  7059. else
  7060. {
  7061. tempIndex = gun_index;
  7062. }
  7063. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  7064. {
  7065. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  7066. {
  7067. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[11].Value, "%d", (uint16_t) (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PowerOffered*100));
  7068. }
  7069. } // END OF FOR CHAdeMO_QUANTITY
  7070. }
  7071. else if(gunType[gun_index] == GUN_TYPE_CCS)
  7072. {
  7073. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  7074. {
  7075. tempIndex = ((gun_index==2) ? 1: 0);
  7076. }
  7077. else
  7078. {
  7079. tempIndex = gun_index;
  7080. }
  7081. for (int index = 0; index < CCS_QUANTITY; index++)
  7082. {
  7083. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  7084. {
  7085. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[11].Value, "%d", (uint16_t) (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PowerOffered*100));
  7086. }
  7087. } // END OF CCS_QUANTITY
  7088. }
  7089. else if(gunType[gun_index] == GUN_TYPE_GBT)
  7090. {
  7091. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  7092. {
  7093. tempIndex = ((gun_index==2) ? 1: 0);
  7094. }
  7095. else
  7096. {
  7097. tempIndex = gun_index;
  7098. }
  7099. for (int index = 0; index < GB_QUANTITY; index++)
  7100. {
  7101. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  7102. {
  7103. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[11].Value, "%d", (uint16_t) (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PowerOffered*100));
  7104. }
  7105. } // END OF GB_QUANTITY
  7106. }
  7107. else if(gunType[gun_index] == GUN_TYPE_DO)
  7108. {
  7109. tempIndex = gun_index;
  7110. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  7111. {
  7112. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  7113. {
  7114. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[11].Value, "%d", (uint16_t) (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PowerOffered*100));
  7115. }
  7116. }
  7117. }
  7118. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[11].Context, ReadingContextStr[dataType]);
  7119. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[11].Format, ValueFormatStr[Raw]);
  7120. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[11].Measurand, MeasurandStr[Power_Offered]);
  7121. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[11].Location, LocationStr[Location_Outlet]);
  7122. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[11].Unit,UnitOfMeasureStr[UnitOfMeasure_W]);
  7123. }
  7124. // Message create ====================================================================================================
  7125. if(TRUE)
  7126. {
  7127. json_object *MeterValueReq = json_object_new_object();
  7128. json_object *MeterValues = json_object_new_array();
  7129. json_object *sampledValues = json_object_new_array();
  7130. json_object_object_add(MeterValueReq, "connectorId", json_object_new_int(ShmOCPP16Data->MeterValues[gun_index].ConnectorId));
  7131. if(ShmOCPP16Data->MeterValues[gun_index].TransactionId != -1)
  7132. json_object_object_add(MeterValueReq, "transactionId", json_object_new_int(ShmOCPP16Data->MeterValues[gun_index].TransactionId));
  7133. for(uint8_t idxMeter=0;idxMeter<ARRAY_SIZE(ShmOCPP16Data->MeterValues[gun_index].MeterValue);idxMeter++)
  7134. {
  7135. json_object *MeterValue = json_object_new_object();
  7136. for(int idxSample=0;idxSample<ARRAY_SIZE(ShmOCPP16Data->MeterValues[gun_index].MeterValue[idxMeter].SampledValue);idxSample++)
  7137. {
  7138. if(strlen((char*)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Value) > 0)
  7139. {
  7140. json_object *sampledValue = json_object_new_object();
  7141. json_object_object_add(sampledValue, "value", json_object_new_string((char*)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Value));
  7142. if(strlen((char*)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Context) > 0)
  7143. json_object_object_add(sampledValue, "context", json_object_new_string((char*)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Context));
  7144. if(strlen((char*)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Format) > 0)
  7145. json_object_object_add(sampledValue, "format", json_object_new_string((char*)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Format));
  7146. if(strlen((char*)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Measurand) > 0)
  7147. json_object_object_add(sampledValue, "measurand", json_object_new_string((char*)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Measurand));
  7148. if(strlen((char*)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Phase) > 0)
  7149. json_object_object_add(sampledValue, "phase", json_object_new_string((char*)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Phase));
  7150. if(strlen((char*)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Location) > 0)
  7151. json_object_object_add(sampledValue, "location", json_object_new_string((char*)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Location));
  7152. if(strlen((char*)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Unit) > 0)
  7153. json_object_object_add(sampledValue, "unit", json_object_new_string((char*)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Unit));
  7154. json_object_array_add(sampledValues, sampledValue);
  7155. }
  7156. }
  7157. json_object_object_add(MeterValue, "timestamp", json_object_new_string((char*)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idxMeter].TimeStamp));
  7158. json_object_object_add(MeterValue, "sampledValue", sampledValues);
  7159. json_object_array_add(MeterValues, MeterValue);
  7160. }
  7161. json_object_object_add(MeterValueReq, "meterValue", MeterValues);
  7162. sprintf(queuedata,"%d,[%d,\"%s\",\"MeterValues\",%s]"
  7163. ,gun_index + 1
  7164. ,MESSAGE_TYPE_CALL
  7165. ,guid
  7166. ,json_object_to_json_string_ext(MeterValueReq, JSON_C_TO_STRING_PLAIN));
  7167. json_object_put(MeterValueReq);
  7168. }
  7169. // Put request guid to hash map
  7170. sprintf(tempdata, "MeterValues,%d", (gun_index));
  7171. 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*/)
  7172. {
  7173. result = PASS;
  7174. //DEBUG_INFO("MeterValues mapitem pass\n");
  7175. }
  7176. if((dataType != ReadingContext_Trigger) &&
  7177. (dataType != ReadingContext_Sample_Clock) &&
  7178. ((ShmOCPP16Data->MeterValues[gun_index].TransactionId > 0) || (strstr((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[QueueOffLineMeterValues].ItemData, "TRUE"))))
  7179. queue_operation(QUEUE_OPERATION_ADD, guid, queuedata );
  7180. else
  7181. {
  7182. if(FirstHeartBeat)
  7183. LWS_Send(queuedata +2);
  7184. }
  7185. return result;
  7186. }
  7187. int sendLogStatusNotificationRequest(char *status)
  7188. {
  7189. mtrace();
  7190. int result = PASS;
  7191. char message[4096]={0};
  7192. char guid[37]={0};
  7193. char tempdata[128]={0};
  7194. json_object *LogStatusNotification = json_object_new_object();
  7195. DEBUG_INFO("sendLogStatusNotificationRequest...\n");
  7196. ShmOCPP16Data->LogStatusNotification.requestId = ShmOCPP16Data->GetLog.requestId;
  7197. sprintf((char *)ShmOCPP16Data->LogStatusNotification.status,"%s",(const char *)status);
  7198. json_object_object_add(LogStatusNotification, "status", json_object_new_string((char*)ShmOCPP16Data->LogStatusNotification.status));
  7199. json_object_object_add(LogStatusNotification, "requestId", json_object_new_int(ShmOCPP16Data->LogStatusNotification.requestId));
  7200. random_uuid(guid);
  7201. sprintf(message,"[%d,\"%s\",\"LogStatusNotification\",%s]",MESSAGE_TYPE_CALL, guid, json_object_to_json_string_ext(LogStatusNotification, JSON_C_TO_STRING_PLAIN));
  7202. json_object_put(LogStatusNotification);
  7203. LWS_Send(message);
  7204. sprintf(tempdata, "LogStatusNotification,%d", 0);
  7205. if(hashmap_operation(HASH_OP_ADD, guid, tempdata) == PASS)
  7206. {
  7207. result = PASS;
  7208. }
  7209. ShmOCPP16Data->SpMsg.bits.LogStatusNotificationReq = 0;
  7210. ShmOCPP16Data->SpMsg.bits.LogStatusNotificationConf = 0;
  7211. return result;
  7212. }
  7213. int sendSecurityEventNotificationRequest()
  7214. {
  7215. mtrace();
  7216. int result = PASS;
  7217. char message[4096]={0};
  7218. char guid[37]={0};
  7219. char tempdata[128]={0};
  7220. json_object *SecurityEventNotification = json_object_new_object();
  7221. DEBUG_INFO("sendSecurityEventNotificationRequest...\n");
  7222. json_object_object_add(SecurityEventNotification, "type", json_object_new_string((char*)ShmOCPP16Data->SecurityEventNotification.type));
  7223. json_object_object_add(SecurityEventNotification, "timestamp", json_object_new_string((char*)ShmOCPP16Data->SecurityEventNotification.timestamp));
  7224. json_object_object_add(SecurityEventNotification, "techInfo", json_object_new_string((char*)ShmOCPP16Data->SecurityEventNotification.techInfo));
  7225. random_uuid(guid);
  7226. sprintf(message,"[%d,\"%s\",\"%s\",%s]",MESSAGE_TYPE_CALL, guid, "SecurityEventNotification", json_object_to_json_string_ext(SecurityEventNotification, JSON_C_TO_STRING_PLAIN));
  7227. json_object_put(SecurityEventNotification);
  7228. LWS_Send(message);
  7229. sprintf(tempdata, "SecurityEventNotification,0");
  7230. if(hashmap_operation(HASH_OP_ADD, guid, tempdata) == PASS)
  7231. {
  7232. result = PASS;
  7233. }
  7234. ShmOCPP16Data->SpMsg.bits.SecurityEventNotificationReq = 0;
  7235. ShmOCPP16Data->SpMsg.bits.SecurityEventNotificationConf = 0;
  7236. return result;
  7237. }
  7238. int sendSignCertificateRequest()
  7239. {
  7240. mtrace();
  7241. int result = PASS;
  7242. char message[4096]={0};
  7243. char guid[37]={0};
  7244. char tempdata[128]={0};
  7245. json_object *SignCertificate = json_object_new_object();
  7246. DEBUG_INFO("sendSignCertificateRequest...\n");
  7247. // Read csr file content
  7248. memset(ShmOCPP16Data->SignCertificate.csr, 0x00, ARRAY_SIZE(ShmOCPP16Data->SignCertificate.csr));
  7249. FILE *fp=fopen("/Storage/OCPP/certCP.csr","r");
  7250. char *line = NULL;
  7251. size_t len = 0;
  7252. while(getline(&line, &len, fp) != -1)
  7253. {
  7254. if((strstr(line, "BEGIN CERTIFICATE REQUEST") == NULL) && (strstr(line, "END CERTIFICATE REQUEST") == NULL))
  7255. {
  7256. memcpy(&ShmOCPP16Data->SignCertificate.csr[strlen((char*)ShmOCPP16Data->SignCertificate.csr)], line, (strlen(line)-1));
  7257. }
  7258. }
  7259. fclose(fp);
  7260. json_object_object_add(SignCertificate, "csr", json_object_new_string((char*)ShmOCPP16Data->SignCertificate.csr));
  7261. random_uuid(guid);
  7262. sprintf(message,"[%d,\"%s\",\"%s\",%s]",MESSAGE_TYPE_CALL, guid, "SignCertificate", json_object_to_json_string_ext(SignCertificate, JSON_C_TO_STRING_PLAIN));
  7263. json_object_put(SignCertificate);
  7264. LWS_Send(message);
  7265. sprintf(tempdata, "SignCertificate,0");
  7266. if(hashmap_operation(HASH_OP_ADD, guid, tempdata) == PASS)
  7267. {
  7268. result = PASS;
  7269. }
  7270. ShmOCPP16Data->SpMsg.bits.SignCertificateReq = 0;
  7271. ShmOCPP16Data->SpMsg.bits.SignCertificateConf = 0;
  7272. return result;
  7273. }
  7274. int sendSignedFirmwareStatusNotificationRequest(char *status)
  7275. {
  7276. mtrace();
  7277. int result = PASS;
  7278. char message[110]={0};
  7279. char guid[37]={0};
  7280. char tempdata[65]={0};
  7281. json_object *FirmwareStatusNotification = json_object_new_object();
  7282. DEBUG_INFO("sendSignedFirmwareStatusNotificationRequest...\n");
  7283. sprintf((char *)ShmOCPP16Data->SignedFirmwareStatusNotification.status , "%s", (const char *)status);
  7284. ShmOCPP16Data->SignedFirmwareStatusNotification.requestId = ShmOCPP16Data->SignedUpdateFirmware.requestId;
  7285. json_object_object_add(FirmwareStatusNotification, "status", json_object_new_string((char*)ShmOCPP16Data->SignedFirmwareStatusNotification.status));
  7286. json_object_object_add(FirmwareStatusNotification, "requestId", json_object_new_int(ShmOCPP16Data->SignedFirmwareStatusNotification.requestId));
  7287. random_uuid(guid);
  7288. sprintf(message,"[%d,\"%s\",\"FirmwareStatusNotification\",%s]",MESSAGE_TYPE_CALL, guid, json_object_to_json_string_ext(FirmwareStatusNotification, JSON_C_TO_STRING_PLAIN));
  7289. json_object_put(FirmwareStatusNotification);
  7290. LWS_Send(message);
  7291. sprintf(tempdata, "FirmwareStatusNotification,%d", 0);
  7292. if(hashmap_operation(HASH_OP_ADD, guid, tempdata) == PASS)
  7293. {
  7294. result = PASS;
  7295. }
  7296. ShmOCPP16Data->SpMsg.bits.SignedFirmwareStatusNotificationReq = 0;
  7297. ShmOCPP16Data->SpMsg.bits.SignedFirmwareStatusNotificationConf = 0;
  7298. return result;
  7299. }
  7300. //==========================================
  7301. // send confirm routine
  7302. //==========================================
  7303. int sendCancelReservationConfirmation(char *uuid,char *payload)
  7304. {
  7305. mtrace();
  7306. int result = FAIL;
  7307. char message[100]={0};
  7308. DEBUG_INFO("sendCancelReservationConfirmation...\n");
  7309. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT,uuid, payload);
  7310. LWS_Send(message);
  7311. result = TRUE;
  7312. return result;
  7313. }
  7314. int sendChangeAvailabilityConfirmation(char *uuid,char *payload)
  7315. {
  7316. mtrace();
  7317. int result = FAIL;
  7318. char message[100]={0};
  7319. DEBUG_INFO("sendChangeAvailabilityConfirmation...\n");
  7320. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT,uuid, payload);
  7321. LWS_Send(message);
  7322. result = TRUE;
  7323. return result;
  7324. }
  7325. int sendChangeConfigurationConfirmation(char *uuid,char *payload)
  7326. {
  7327. mtrace();
  7328. int result = FAIL;
  7329. char message[100]={0};
  7330. DEBUG_INFO("sendChangeConfigurationConfirmation...\n");
  7331. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT,uuid, payload);
  7332. LWS_Send(message);
  7333. result = TRUE;
  7334. return result;
  7335. }
  7336. int sendClearCacheConfirmation(char *uuid,char *payload)
  7337. {
  7338. mtrace();
  7339. int result = FAIL;
  7340. char message[500]={0};
  7341. DEBUG_INFO("sendClearCacheConfirmation...\n");
  7342. sprintf(message,"[%d,\"%s\",{\"%s\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, "status", payload);
  7343. LWS_Send(message);
  7344. return result;
  7345. }
  7346. int sendClearChargingProfileConfirmation(char *uuid,char *payload)
  7347. {
  7348. mtrace();
  7349. int result = FAIL;
  7350. char message[500]={0};
  7351. DEBUG_INFO("sendClearChargingProfileConfirmation...\n");
  7352. sprintf(message,"[%d,\"%s\",{\"%s\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, "status", payload);
  7353. LWS_Send(message);
  7354. return result;
  7355. }
  7356. int sendDataTransferConfirmation(char *uuid,char *payload)
  7357. {
  7358. mtrace();
  7359. char statusStr[20]={0};
  7360. char dataStr[10]={0};
  7361. char sstr[20]={0};
  7362. int c = 0;
  7363. char *loc;
  7364. int result = FAIL;
  7365. DEBUG_INFO("sendDataTransferConfirmation...\n");
  7366. /**********************status**************************/
  7367. loc = strstr(payload, "status");
  7368. memset(sstr ,0, ARRAY_SIZE(sstr) );
  7369. c = 0;
  7370. while (loc[3+strlen("status")+c] != '\"')
  7371. {
  7372. sstr[c] = loc[3+strlen("status")+c];
  7373. c++;
  7374. }
  7375. sstr[c] = '\0';
  7376. strcpy(statusStr, sstr);
  7377. /**********************data**************************/
  7378. loc = strstr(payload, "data");
  7379. memset(sstr ,0, ARRAY_SIZE(sstr) );
  7380. c = 0;
  7381. while (loc[3+strlen("data")+c] != '\"')
  7382. {
  7383. sstr[c] = loc[3+strlen("data")+c];
  7384. c++;
  7385. }
  7386. sstr[c] = '\0';
  7387. strcpy(dataStr, sstr);
  7388. return result;
  7389. }
  7390. int sendGetCompositeScheduleConfirmation(char *uuid, char *payload, int connectorIdInt, int nPeriod)
  7391. {
  7392. mtrace();
  7393. int result = FAIL;
  7394. char message[1000]={0};
  7395. int CompositeScheduleIndex = 0;
  7396. DEBUG_INFO("sendGetCompositeScheduleConfirmation...\n");
  7397. CompositeScheduleIndex = (connectorIdInt > 0) ?(connectorIdInt -1) : 0;
  7398. if(nPeriod == 0)
  7399. {
  7400. if(strcmp((const char *)ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.StartSchedule,"")==0)
  7401. {
  7402. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\",\"connectorId\":%d}]"
  7403. ,MESSAGE_TYPE_CALLRESULT
  7404. ,uuid
  7405. ,payload
  7406. ,connectorIdInt);
  7407. }
  7408. else
  7409. {
  7410. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\",\"connectorId\":%d,\"scheduleStart\":\"%s\",\"chargingSchedule\":{\"duration\":%d,\"startSchedule\":\"%s\",\"chargingRateUnit\":\"%s\",\"chargingSchedulePeriod\":[{\"startPeriod\":0,\"limit\":%d,\"numberPhases\":3}]}}]"
  7411. ,MESSAGE_TYPE_CALLRESULT
  7412. ,uuid
  7413. ,payload
  7414. ,connectorIdInt
  7415. ,ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.StartSchedule
  7416. ,ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.Duration
  7417. ,ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.StartSchedule
  7418. ,ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.ChargingRateUnit
  7419. ,(ShmSysConfigAndInfo->SysConfig.MaxChargingCurrent==0?ShmSysConfigAndInfo->SysConfig.RatingCurrent:ShmSysConfigAndInfo->SysConfig.MaxChargingCurrent));
  7420. }
  7421. }
  7422. else
  7423. {
  7424. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\",\"connectorId\":%d,\"scheduleStart\":\"%s\",\"chargingSchedule\":{\"duration\":%d,\"startSchedule\":\"%s\",\"chargingRateUnit\":\"%s\",\"chargingSchedulePeriod\":["
  7425. ,MESSAGE_TYPE_CALLRESULT
  7426. ,uuid
  7427. ,payload
  7428. ,connectorIdInt
  7429. ,ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.StartSchedule
  7430. ,ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.Duration
  7431. ,ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.StartSchedule
  7432. ,ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.ChargingRateUnit);
  7433. for(int idx_sample=0;idx_sample< nPeriod;idx_sample++)
  7434. {
  7435. if (idx_sample == 0)
  7436. {
  7437. sprintf(message + strlen(message), "{\"startPeriod\":%d,\"limit\":%.1f,\"numberPhases\":%d}"
  7438. , ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[idx_sample].StartPeriod
  7439. , ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[idx_sample].Limit
  7440. , ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[idx_sample].NumberPhases );
  7441. }
  7442. else
  7443. {
  7444. sprintf(message + strlen(message), ",{\"startPeriod\":%d,\"limit\":%.1f,\"numberPhases\":%d}"
  7445. , ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[idx_sample].StartPeriod
  7446. , ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[idx_sample].Limit
  7447. , ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[idx_sample].NumberPhases );
  7448. }
  7449. }
  7450. sprintf(message + strlen(message), "]}}]");
  7451. }
  7452. LWS_Send(message);
  7453. result = TRUE;
  7454. return result;
  7455. }
  7456. int sendGetConfigurationConfirmation(char *uuid)
  7457. {
  7458. mtrace();
  7459. int result = FAIL;
  7460. int MaxKeySupported = 0;
  7461. int sentConfigurationNumber= 0;
  7462. int sentunConfigurationNumber= 0;
  7463. char message[1024*10]={0};
  7464. DEBUG_INFO("sendGetConfigurationConfirmation...\n");
  7465. MaxKeySupported = atoi((const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemData);
  7466. sprintf(message,"[%d,\"%s\",{\"configurationKey\":["
  7467. ,MESSAGE_TYPE_CALLRESULT
  7468. ,uuid );
  7469. //configuration key
  7470. for(int idx_sample=0;idx_sample< MaxKeySupported/*43*/;idx_sample++)
  7471. {
  7472. if(strcmp((const char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[idx_sample].Key, "")!= 0)
  7473. {
  7474. if (sentConfigurationNumber == 0)
  7475. {
  7476. sprintf(message + strlen(message), "{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}"
  7477. , ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[idx_sample].Key
  7478. , atoi((const char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[idx_sample].ReadOnly) == 1 ? "true":"false"
  7479. , ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[idx_sample].Value );
  7480. }
  7481. else
  7482. {
  7483. sprintf(message + strlen(message), ", {\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}"
  7484. , ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[idx_sample].Key
  7485. , atoi((const char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[idx_sample].ReadOnly) == 1 ? "true":"false"
  7486. , ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[idx_sample].Value );
  7487. }
  7488. sentConfigurationNumber = sentConfigurationNumber + 1;
  7489. }
  7490. }
  7491. sprintf(message + strlen(message), "]");
  7492. if(UnknownKeynum != 0)
  7493. {
  7494. sprintf(message + strlen(message), ",\"unknownKey\":[");
  7495. //unkown key
  7496. for(int idx_sample=0;idx_sample< UnknownKeynum ;idx_sample++)
  7497. {
  7498. // json_object *jstring1 = json_object_new_string((const char *)((ShmOCPP16Data->GetConfiguration.ResponseUnknownKey + idx_sample)->Item));
  7499. DEBUG_INFO("unkown key:%s\n", ShmOCPP16Data->GetConfiguration.ResponseUnknownKey[idx_sample].Item);
  7500. if(sentunConfigurationNumber == 0)
  7501. {
  7502. sprintf(message + strlen(message), "\"%s\""
  7503. , ShmOCPP16Data->GetConfiguration.ResponseUnknownKey[idx_sample].Item );
  7504. }
  7505. else
  7506. {
  7507. sprintf(message + strlen(message), ",\"%s\""
  7508. , ShmOCPP16Data->GetConfiguration.ResponseUnknownKey[idx_sample].Item );
  7509. }
  7510. sentunConfigurationNumber = sentunConfigurationNumber + 1;
  7511. }
  7512. sprintf(message + strlen(message), "]");
  7513. }
  7514. sprintf(message + strlen(message), "}]");
  7515. LWS_Send(message);
  7516. return result;
  7517. }
  7518. int sendGetDiagnosticsConfirmation(char *uuid,char *payload)
  7519. {
  7520. mtrace();
  7521. int result = FAIL;
  7522. char message[400]={0};
  7523. DEBUG_INFO("sendGetDiagnosticsConfirmation...\n");
  7524. if(strcmp(payload,"")==0)
  7525. {
  7526. sprintf(message,"[%d,\"%s\",{}]",MESSAGE_TYPE_CALLRESULT, uuid);
  7527. }
  7528. else
  7529. {
  7530. sprintf(message,"[%d,\"%s\",{\"fileName\":\"%s\"}]", MESSAGE_TYPE_CALLRESULT, uuid, payload);
  7531. }
  7532. LWS_Send(message);
  7533. result = TRUE;
  7534. return result;
  7535. }
  7536. int sendGetLocalListVersionConfirmation(char *uuid,char *payload)
  7537. {
  7538. mtrace();
  7539. int result = FAIL;
  7540. char message[80]={0};
  7541. DEBUG_INFO("sendGetLocalListVersionConfirmation...\n");
  7542. sprintf(message,"[%d,\"%s\",{\"listVersion\":%d}]",MESSAGE_TYPE_CALLRESULT, uuid, ShmOCPP16Data->GetLocalListVersion.ResponseListVersion);
  7543. LWS_Send(message);
  7544. result = TRUE;
  7545. return result;
  7546. }
  7547. int sendRemoteStartConfirmation(char *uuid,char *payload)
  7548. {
  7549. mtrace();
  7550. int result = FAIL;
  7551. char message[80]={0};
  7552. DEBUG_INFO("sendRemoteStartConfirmation...\n");
  7553. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, payload);
  7554. LWS_Send(message);
  7555. result = TRUE;
  7556. return result;
  7557. }
  7558. int sendRemoteStopTransactionConfirmation(char *uuid,char *payload)
  7559. {
  7560. mtrace();
  7561. int result = FAIL;
  7562. char message[80]={0};
  7563. DEBUG_INFO("sendRemoteStopTransactionConfirmation...\n");
  7564. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, payload);
  7565. LWS_Send(message);
  7566. result = TRUE;
  7567. return result;
  7568. }
  7569. int sendReserveNowTransactionConfirmation(char *uuid,char *payload)
  7570. {
  7571. mtrace();
  7572. int result = FAIL;
  7573. char message[80]={0};
  7574. // [3,"287d837d-809e-41ea-8385-fdab7f72a01c",{"status":"Accepted"}]
  7575. DEBUG_INFO("sendReserveNowTransactionConfirmation...\n");
  7576. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, payload);
  7577. LWS_Send(message);
  7578. result = TRUE;
  7579. return result;
  7580. }
  7581. int sendResetConfirmation(char *uuid,char *payload)
  7582. {
  7583. mtrace();
  7584. int result = FAIL;
  7585. //[ 3, "6f88d461-4d17-462c-a69b-1f7a8c5b12df", { "status": 0 } ]
  7586. char message[80]={0};
  7587. ShmOCPP16Data->MsMsg.bits.ResetConf = 0;
  7588. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, payload);
  7589. LWS_Send(message);
  7590. result = TRUE;
  7591. return result;
  7592. }
  7593. int sendSendLocalListConfirmation(char *uuid,char *payload)
  7594. {
  7595. mtrace();
  7596. int result = FAIL;
  7597. char message[500]={0};
  7598. // [ 3, "1571284266109", { "status": "Accepted" } ]
  7599. sprintf(message,"[%d,\"%s\",{\"%s\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, "status", payload);
  7600. LWS_Send(message);
  7601. result = TRUE;
  7602. return result;
  7603. }
  7604. int sendSetChargingProfileConfirmation(char *uuid,char *payload)
  7605. {
  7606. mtrace();
  7607. int result = FAIL;
  7608. //[3,"5748585f-8524-4fa6-9b4f-4a7eca750b90",{"status":"NotSupported"}]
  7609. char message[80]={0};
  7610. DEBUG_INFO("sendSetChargingProfileConfirmation...\n");
  7611. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, payload);
  7612. LWS_Send(message);
  7613. result = TRUE;
  7614. return result;
  7615. }
  7616. int sendTriggerMessageConfirmation(char *uuid,char *payload)
  7617. {
  7618. mtrace();
  7619. int result = FAIL;
  7620. char message[80]={0};
  7621. DEBUG_INFO("sendTriggerMessageConfirmation...\n");
  7622. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, payload);
  7623. LWS_Send(message);
  7624. result = TRUE;
  7625. return result;
  7626. }
  7627. int sendUnlockConnectorConfirmation(char *uuid,char *payload)
  7628. {
  7629. mtrace();
  7630. int result = FAIL;
  7631. char message[80]={0};
  7632. //[ 3, "ba1cbd49-2a76-493a-8f76-fa23e7606532", { "status": "Unlocked" } ]
  7633. DEBUG_INFO("sendUnlockConnectorConfirmation...\n");
  7634. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, payload);
  7635. LWS_Send(message);
  7636. result = TRUE;
  7637. return result;
  7638. }
  7639. int sendUpdateFirmwareConfirmation(char *uuid)
  7640. {
  7641. mtrace();
  7642. int result = FAIL;
  7643. char message[60]={0};
  7644. //[ 3, "ba1cbd49-2a76-493a-8f76-fa23e7606532", { "status": "Unlocked" } ]
  7645. DEBUG_INFO("sendUpdateFirmwareConfirmation...\n");
  7646. sprintf(message,"[%d,\"%s\",{}]",MESSAGE_TYPE_CALLRESULT, uuid);
  7647. LWS_Send(message);
  7648. result = TRUE;
  7649. return result;
  7650. }
  7651. int sendCertificateSignedConfirmation(char *uuid)
  7652. {
  7653. mtrace();
  7654. int result = PASS;
  7655. char message[4096]={0};
  7656. json_object *CertificateSigned = json_object_new_object();
  7657. DEBUG_INFO("sendCertificateSignedConfirmation...\n");
  7658. json_object_object_add(CertificateSigned, "status", json_object_new_string((char*)ShmOCPP16Data->CertificateSigned.Response_status));
  7659. sprintf(message,"[%d,\"%s\",%s]"
  7660. ,MESSAGE_TYPE_CALLRESULT
  7661. ,uuid
  7662. ,json_object_to_json_string_ext(CertificateSigned, JSON_C_TO_STRING_PLAIN));
  7663. json_object_put(CertificateSigned);
  7664. LWS_Send(message);
  7665. return result;
  7666. }
  7667. int sendDeleteCertificateConfirmation(char *uuid)
  7668. {
  7669. mtrace();
  7670. int result = PASS;
  7671. char message[4096]={0};
  7672. json_object *DeleteCertificate = json_object_new_object();
  7673. DEBUG_INFO("sendDeleteCertificateConfirmation...\n");
  7674. json_object_object_add(DeleteCertificate, "status", json_object_new_string((char*)ShmOCPP16Data->DeleteCertificate.Response_status));
  7675. sprintf(message,"[%d,\"%s\",%s]"
  7676. ,MESSAGE_TYPE_CALLRESULT
  7677. ,uuid
  7678. ,json_object_to_json_string_ext(DeleteCertificate, JSON_C_TO_STRING_PLAIN));
  7679. json_object_put(DeleteCertificate);
  7680. LWS_Send(message);
  7681. return result;
  7682. }
  7683. int sendExtendedTriggerMessageConfirmation(char *uuid)
  7684. {
  7685. mtrace();
  7686. int result = PASS;
  7687. char message[4096]={0};
  7688. json_object *ExtendedTriggerMessage = json_object_new_object();
  7689. DEBUG_INFO("sendExtendedTriggerMessageConfirmation...\n");
  7690. json_object_object_add(ExtendedTriggerMessage, "status", json_object_new_string((char*)ShmOCPP16Data->ExtendedTriggerMessage.Response_status));
  7691. sprintf(message,"[%d,\"%s\",%s]"
  7692. ,MESSAGE_TYPE_CALLRESULT
  7693. ,uuid
  7694. ,json_object_to_json_string_ext(ExtendedTriggerMessage, JSON_C_TO_STRING_PLAIN));
  7695. json_object_put(ExtendedTriggerMessage);
  7696. LWS_Send(message);
  7697. return result;
  7698. }
  7699. int sendGetInstalledCertificateIdsConfirmation(char *uuid)
  7700. {
  7701. mtrace();
  7702. int result = PASS;
  7703. char message[4096]={0};
  7704. json_object *GetInstalledCertificateIds = json_object_new_object();
  7705. json_object *certificateHashDataDatas = json_object_new_array();
  7706. DEBUG_INFO("sendGetInstalledCertificateIdsConfirmation...\n");
  7707. json_object_object_add(GetInstalledCertificateIds, "status", json_object_new_string((char*)ShmOCPP16Data->GetInstalledCertificateIds.Response_status));
  7708. if(strlen((char*)ShmOCPP16Data->GetInstalledCertificateIds.Response_certificateHashData[0].hashAlgorithm) > 0)
  7709. {
  7710. for(int idx=0;idx<ARRAY_SIZE(ShmOCPP16Data->GetInstalledCertificateIds.Response_certificateHashData);idx++)
  7711. {
  7712. json_object *certificateHashData = json_object_new_object();
  7713. json_object_object_add(certificateHashData, "hashAlgorithm", json_object_new_string((char*)ShmOCPP16Data->GetInstalledCertificateIds.Response_certificateHashData[idx].hashAlgorithm));
  7714. json_object_object_add(certificateHashData, "issuerNameHash", json_object_new_string((char*)ShmOCPP16Data->GetInstalledCertificateIds.Response_certificateHashData[idx].issuerNameHash));
  7715. json_object_object_add(certificateHashData, "issuerKeyHash", json_object_new_string((char*)ShmOCPP16Data->GetInstalledCertificateIds.Response_certificateHashData[idx].issuerKeyHash));
  7716. json_object_object_add(certificateHashData, "serialNumber", json_object_new_string((char*)ShmOCPP16Data->GetInstalledCertificateIds.Response_certificateHashData[idx].serialNumber));
  7717. json_object_array_add(certificateHashDataDatas, certificateHashData);
  7718. }
  7719. json_object_object_add(GetInstalledCertificateIds , "certificateHashData", certificateHashDataDatas);
  7720. }
  7721. else
  7722. {
  7723. json_object_put(certificateHashDataDatas);
  7724. }
  7725. sprintf(message,"[%d,\"%s\",%s]"
  7726. ,MESSAGE_TYPE_CALLRESULT
  7727. ,uuid
  7728. ,json_object_to_json_string_ext(GetInstalledCertificateIds, JSON_C_TO_STRING_PLAIN));
  7729. json_object_put(GetInstalledCertificateIds);
  7730. LWS_Send(message);
  7731. return result;
  7732. }
  7733. int sendGetLogConfirmation(char *uuid)
  7734. {
  7735. mtrace();
  7736. int result = PASS;
  7737. char message[4096]={0};
  7738. json_object *GetLog = json_object_new_object();
  7739. DEBUG_INFO("sendGetLogConfirmation...\n");
  7740. json_object_object_add(GetLog, "status", json_object_new_string((char*)ShmOCPP16Data->GetLog.Response_status));
  7741. if(strlen((char*)ShmOCPP16Data->GetLog.Response_filename) > 0)
  7742. json_object_object_add(GetLog, "filename", json_object_new_string((char*)ShmOCPP16Data->GetLog.Response_filename));
  7743. sprintf(message,"[%d,\"%s\",%s]"
  7744. ,MESSAGE_TYPE_CALLRESULT
  7745. ,uuid
  7746. ,json_object_to_json_string_ext(GetLog, JSON_C_TO_STRING_PLAIN));
  7747. json_object_put(GetLog);
  7748. LWS_Send(message);
  7749. return result;
  7750. }
  7751. int sendInstallCertificateConfirmation(char *uuid)
  7752. {
  7753. mtrace();
  7754. int result = PASS;
  7755. char message[4096]={0};
  7756. json_object *InstallCertificate = json_object_new_object();
  7757. DEBUG_INFO("sendInstallCertificateConfirmation...\n");
  7758. json_object_object_add(InstallCertificate, "status", json_object_new_string((char*)ShmOCPP16Data->InstallCertificate.Response_status));
  7759. sprintf(message,"[%d,\"%s\",%s]"
  7760. ,MESSAGE_TYPE_CALLRESULT
  7761. ,uuid
  7762. ,json_object_to_json_string_ext(InstallCertificate, JSON_C_TO_STRING_PLAIN));
  7763. json_object_put(InstallCertificate);
  7764. LWS_Send(message);
  7765. return result;
  7766. }
  7767. int sendSignedUpdateFirmwareConfirmation(char *uuid)
  7768. {
  7769. mtrace();
  7770. int result = PASS;
  7771. char message[4096]={0};
  7772. json_object *SignedUpdateFirmware = json_object_new_object();
  7773. DEBUG_INFO("sendSignedUpdateFirmwareConfirmation...\n");
  7774. json_object_object_add(SignedUpdateFirmware, "status", json_object_new_string((char*)ShmOCPP16Data->SignedUpdateFirmware.Response_status));
  7775. sprintf(message,"[%d,\"%s\",%s]"
  7776. ,MESSAGE_TYPE_CALLRESULT
  7777. ,uuid
  7778. ,json_object_to_json_string_ext(SignedUpdateFirmware, JSON_C_TO_STRING_PLAIN));
  7779. json_object_put(SignedUpdateFirmware);
  7780. LWS_Send(message);
  7781. return result;
  7782. }
  7783. int sendUnknownConfirmation(char *uuid)
  7784. {
  7785. mtrace();
  7786. int result = PASS;
  7787. char message[256]={0};
  7788. DEBUG_INFO("sendUnknownConfirmation...\n");
  7789. sprintf(message,"[%d,\"%s\",\"NotImplemented\",\"Requested Action is not known by receiver\",{}]", MESSAGE_TYPE_CALLERROR, uuid);
  7790. LWS_Send(message);
  7791. return result;
  7792. }
  7793. //==========================================
  7794. // Handle server request routine Start
  7795. //==========================================
  7796. int handleCancelReservationRequest(char *uuid, char *payload)
  7797. {
  7798. mtrace();
  7799. int result = FAIL;
  7800. int gunNO = 0;
  7801. int reservationIdInt = -1;
  7802. char comfirmstr[20];
  7803. DEBUG_INFO("handleCancelReservationRequest...\n");
  7804. json_object *CancelReservation;
  7805. CancelReservation = json_tokener_parse(payload);
  7806. if(!is_error(CancelReservation))
  7807. {
  7808. // Required data
  7809. if(json_object_object_get(CancelReservation, "reservationId") != NULL)
  7810. reservationIdInt = json_object_get_int(json_object_object_get(CancelReservation, "reservationId"));
  7811. }
  7812. json_object_put(CancelReservation);
  7813. DEBUG_INFO("reservationIdInt = %d\n", reservationIdInt);
  7814. memset(comfirmstr, 0, ARRAY_SIZE(comfirmstr));
  7815. sprintf(comfirmstr, "%s", CancelReservationStatusStr[CancelReservationStatus_Rejected]);
  7816. if(reservationIdInt != -1)
  7817. {
  7818. //0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault, 8: Reserved, 9: maintain
  7819. //check Transaction active
  7820. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  7821. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  7822. {
  7823. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ReservationId == reservationIdInt)
  7824. {
  7825. sprintf(comfirmstr, "%s", CancelReservationStatusStr[CancelReservationStatus_Accepted] );
  7826. sprintf((char *)ShmOCPP16Data->CancelReservation[ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index].ResponseStatus, "%s", comfirmstr );
  7827. if(gunType[2] == GUN_TYPE_CHAdeMO)
  7828. {
  7829. gunNO = ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index + 1;
  7830. }
  7831. else
  7832. {
  7833. gunNO = ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index;
  7834. }
  7835. ShmOCPP16Data->CsMsg.bits[gunNO].CancelReservationReq = 1;
  7836. goto end;
  7837. }
  7838. }
  7839. for (int index = 0; index < CCS_QUANTITY; index++)
  7840. {
  7841. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ReservationId == reservationIdInt)
  7842. {
  7843. sprintf(comfirmstr, "%s", CancelReservationStatusStr[CancelReservationStatus_Accepted] );
  7844. sprintf((char *)ShmOCPP16Data->CancelReservation[ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index].ResponseStatus, "%s", comfirmstr );
  7845. if(gunType[2] == GUN_TYPE_CCS)
  7846. {
  7847. gunNO = ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index + 1;
  7848. }
  7849. else
  7850. {
  7851. gunNO = ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index;
  7852. }
  7853. ShmOCPP16Data->CsMsg.bits[gunNO].CancelReservationReq = 1;
  7854. goto end;
  7855. }
  7856. }
  7857. for (int index = 0; index < GB_QUANTITY; index++)
  7858. {
  7859. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ReservationId == reservationIdInt)
  7860. {
  7861. sprintf(comfirmstr, "%s", CancelReservationStatusStr[CancelReservationStatus_Accepted] );
  7862. sprintf((char *)ShmOCPP16Data->CancelReservation[ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index].ResponseStatus, "%s", comfirmstr );
  7863. if(gunType[2] == GUN_TYPE_GBT)
  7864. {
  7865. gunNO = ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index + 1;
  7866. }
  7867. else
  7868. {
  7869. gunNO = ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index;
  7870. }
  7871. ShmOCPP16Data->CsMsg.bits[gunNO].CancelReservationReq = 1;
  7872. goto end;
  7873. }
  7874. }
  7875. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  7876. {
  7877. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.ReservationId == reservationIdInt)
  7878. {
  7879. sprintf(comfirmstr, "%s", CancelReservationStatusStr[CancelReservationStatus_Accepted] );
  7880. sprintf((char *)ShmOCPP16Data->CancelReservation[ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index].ResponseStatus, "%s", comfirmstr );
  7881. gunNO = ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index;
  7882. ShmOCPP16Data->CsMsg.bits[gunNO].CancelReservationReq = 1;
  7883. goto end;
  7884. }
  7885. }
  7886. for (int index = 0; index < AC_QUANTITY; index++)
  7887. {
  7888. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].ReservationId == reservationIdInt)
  7889. {
  7890. sprintf(comfirmstr, "%s", CancelReservationStatusStr[CancelReservationStatus_Accepted] );
  7891. sprintf((char *)ShmOCPP16Data->CancelReservation[ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index].ResponseStatus, "%s", comfirmstr );
  7892. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  7893. {
  7894. gunNO = 1; //ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index ;
  7895. }
  7896. else
  7897. {
  7898. gunNO = ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index;
  7899. }
  7900. ShmOCPP16Data->CsMsg.bits[gunNO].CancelReservationReq = 1;
  7901. goto end;
  7902. }
  7903. }
  7904. }
  7905. //The reservationId does NOT match the reservationId
  7906. sendCancelReservationConfirmation(uuid, comfirmstr);
  7907. end:
  7908. // Fill in ocpp packet uuid
  7909. strcpy((char *)ShmOCPP16Data->CancelReservation[gunNO].guid, uuid);
  7910. return result;
  7911. }
  7912. int handleChangeAvailabilityRequest(char *uuid, char *payload)
  7913. {
  7914. mtrace();
  7915. int result = FAIL;
  7916. int gunIndex = -1;
  7917. char typeStr[16]={0};
  7918. char comfirmstr[20];
  7919. int specificId = FALSE;
  7920. DEBUG_INFO("handleChangeAvailabilityRequest...\n");
  7921. json_object *ChangeAvailability;
  7922. ChangeAvailability = json_tokener_parse(payload);
  7923. if(!is_error(ChangeAvailability))
  7924. {
  7925. // Required data
  7926. if((json_object_object_get(ChangeAvailability, "connectorId") != NULL) && (json_object_get_type(json_object_object_get(ChangeAvailability, "connectorId")) == json_type_int))
  7927. gunIndex = json_object_get_int(json_object_object_get(ChangeAvailability, "connectorId"));
  7928. if(json_object_object_get(ChangeAvailability, "type") != NULL)
  7929. sprintf((char*)typeStr, "%s", json_object_get_string(json_object_object_get(ChangeAvailability, "type")));
  7930. }
  7931. json_object_put(ChangeAvailability);
  7932. if((gunIndex > 0) && (gunIndex <= gunTotalNumber))
  7933. {
  7934. ShmOCPP16Data->ChangeAvailability[gunIndex - 1].ConnectorId= gunIndex;
  7935. sprintf((char *)ShmOCPP16Data->ChangeAvailability[gunIndex - 1].Type, "%s", typeStr);
  7936. }
  7937. else if(gunIndex == 0)
  7938. {
  7939. for(int i=0; i < gunTotalNumber; i++)
  7940. {
  7941. ShmOCPP16Data->ChangeAvailability[i].ConnectorId= gunIndex;
  7942. sprintf((char *)ShmOCPP16Data->ChangeAvailability[i].Type, "%s", typeStr);
  7943. }
  7944. }
  7945. memset(comfirmstr, 0, ARRAY_SIZE(comfirmstr));
  7946. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  7947. if((gunIndex == 0) || ((gunIndex > 0) && (gunIndex <= gunTotalNumber)))
  7948. {
  7949. specificId = TRUE;
  7950. }
  7951. if(specificId == FALSE)
  7952. goto end;
  7953. if(strcmp((const char *)typeStr, AvailabilityTypeStr[Inoperative]) == 0)
  7954. {
  7955. //----------------------gunIndex is 0 ------------------------------------------------//
  7956. if(gunIndex == 0)
  7957. {
  7958. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D') // 'D' means DC
  7959. {
  7960. for(int i=0; i < gunTotalNumber; i++)
  7961. {
  7962. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  7963. {
  7964. if ((gunType[i] == GUN_TYPE_CHAdeMO)&&(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == i))
  7965. {
  7966. if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_RESERVATION) // S_PRECHARGE
  7967. {
  7968. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  7969. goto end;
  7970. }
  7971. else if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_AUTHORIZING) ||
  7972. (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_PREPARING) ||
  7973. (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_CHARGING) ||
  7974. (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_TERMINATING) ||
  7975. (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_COMPLETE)) // S_CHARGING
  7976. {
  7977. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  7978. goto end;
  7979. }
  7980. }
  7981. }//END FOR CHAdeMO_QUANTITY
  7982. for (int index = 0; index < CCS_QUANTITY; index++)
  7983. {
  7984. if ((gunType[i] == GUN_TYPE_CCS)&&(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == i))
  7985. {
  7986. if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_RESERVATION)// S_PRECHARGE
  7987. {
  7988. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  7989. goto end;
  7990. }
  7991. else if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_AUTHORIZING) ||
  7992. (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_PREPARING) ||
  7993. (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_CHARGING) ||
  7994. (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_TERMINATING) ||
  7995. (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_COMPLETE)) // S_CHARGING
  7996. {
  7997. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  7998. goto end;
  7999. }
  8000. }
  8001. }//END FOR CCS_QUANTITY
  8002. for (int index = 0; index < GB_QUANTITY; index++)
  8003. {
  8004. if ((gunType[i] == GUN_TYPE_GBT)&&(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == i))
  8005. {
  8006. if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_RESERVATION) // S_PRECHARGE
  8007. {
  8008. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  8009. goto end;
  8010. }
  8011. else if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_AUTHORIZING) ||
  8012. (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_PREPARING) ||
  8013. (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_CHARGING) ||
  8014. (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_TERMINATING) ||
  8015. (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_COMPLETE)) // S_CHARGING
  8016. {
  8017. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  8018. goto end;
  8019. }
  8020. }
  8021. }// END FOR GB_QUANTITY
  8022. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  8023. {
  8024. if ((gunType[i] == GUN_TYPE_DO)&&(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == i))
  8025. {
  8026. if(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_RESERVATION) // S_PRECHARGE
  8027. {
  8028. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  8029. goto end;
  8030. }
  8031. else if((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_AUTHORIZING) ||
  8032. (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_PREPARING) ||
  8033. (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_CHARGING) ||
  8034. (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_TERMINATING) ||
  8035. (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_COMPLETE)) // S_CHARGING
  8036. {
  8037. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  8038. goto end;
  8039. }
  8040. }
  8041. }// END FOR GENERAL_GUN_QUANTITY
  8042. for (int index = 0; index < AC_QUANTITY; index++)
  8043. {
  8044. if ((gunType[i] == GUN_TYPE_AC)&&(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == i))
  8045. {
  8046. if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_RESERVATION) // S_PRECHARGE
  8047. {
  8048. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  8049. goto end;
  8050. }
  8051. else if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_AUTHORIZING) ||
  8052. (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_PREPARING) ||
  8053. (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_CHARGING) ||
  8054. (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_TERMINATING) ||
  8055. (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_COMPLETE)) // S_CHARGING
  8056. {
  8057. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  8058. goto end;
  8059. }
  8060. }
  8061. }//END FOR AC_QUANTITY
  8062. }// END FOR gunTotalNumber
  8063. }
  8064. else if (ShmSysConfigAndInfo->SysConfig.ModelName[0]=='A') //'A' means AC
  8065. {
  8066. for(int i=0; i < gunTotalNumber; i++)
  8067. {
  8068. if(ShmSysConfigAndInfo->SysInfo.AcChargingData[i].SystemStatus == SYS_MODE_RESERVATION) // S_PRECHARGE
  8069. {
  8070. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  8071. goto end;
  8072. }
  8073. else if((ShmSysConfigAndInfo->SysInfo.AcChargingData[i].SystemStatus == SYS_MODE_AUTHORIZING) ||
  8074. (ShmSysConfigAndInfo->SysInfo.AcChargingData[i].SystemStatus == SYS_MODE_PREPARING) ||
  8075. (ShmSysConfigAndInfo->SysInfo.AcChargingData[i].SystemStatus == SYS_MODE_CHARGING) ||
  8076. (ShmSysConfigAndInfo->SysInfo.AcChargingData[i].SystemStatus == SYS_MODE_TERMINATING) ||
  8077. (ShmSysConfigAndInfo->SysInfo.AcChargingData[i].SystemStatus == SYS_MODE_COMPLETE)) // S_CHARGING
  8078. {
  8079. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  8080. goto end;
  8081. }
  8082. }
  8083. }
  8084. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  8085. goto end;
  8086. }
  8087. //----------------------gunIndex is not 0 ------------------------------------------------//
  8088. //check Transaction active
  8089. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  8090. {
  8091. if ((gunIndex > 0)&&(gunType[gunIndex-1] == GUN_TYPE_CHAdeMO))
  8092. {
  8093. if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_RESERVATION) ) // S_PRECHARGE
  8094. {
  8095. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  8096. goto end;
  8097. }
  8098. else if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_AUTHORIZING) ||
  8099. (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_PREPARING) ||
  8100. (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_CHARGING) ||
  8101. (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_TERMINATING) ||
  8102. (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_COMPLETE)) // S_CHARGING
  8103. {
  8104. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  8105. goto end;
  8106. }
  8107. else
  8108. {
  8109. DEBUG_INFO("ShmSysConfigAndInfo->SysInfo.ChademoChargingData[%d].SystemStatus = %d\n",index, ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus);
  8110. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  8111. goto end;
  8112. }
  8113. }
  8114. }//END FOR CHAdeMO_QUANTITY
  8115. for (int index = 0; index < CCS_QUANTITY; index++)
  8116. {
  8117. if ((gunIndex > 0)&&(gunType[gunIndex - 1] == GUN_TYPE_CCS))
  8118. {
  8119. if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_RESERVATION) )// S_PRECHARGE
  8120. {
  8121. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  8122. goto end;
  8123. }
  8124. else if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_AUTHORIZING) ||
  8125. (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_PREPARING) ||
  8126. (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_CHARGING) ||
  8127. (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_TERMINATING) ||
  8128. (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_COMPLETE)) // S_CHARGING
  8129. {
  8130. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  8131. goto end;
  8132. }
  8133. else
  8134. {
  8135. DEBUG_INFO("ShmSysConfigAndInfo->SysInfo.CcsChargingData[%d].SystemStatus=%d\n",index, ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus);
  8136. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  8137. goto end;
  8138. }
  8139. }
  8140. }//END FOR CCS_QUANTITY
  8141. for (int index = 0; index < GB_QUANTITY; index++)
  8142. {
  8143. if ((gunIndex > 0)&&(gunType[gunIndex-1] == GUN_TYPE_GBT))
  8144. {
  8145. if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_RESERVATION)) // S_PRECHARGE
  8146. {
  8147. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  8148. goto end;
  8149. }
  8150. else if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_AUTHORIZING) ||
  8151. (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_PREPARING) ||
  8152. (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_CHARGING) ||
  8153. (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_TERMINATING) ||
  8154. (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_COMPLETE)) // S_CHARGING
  8155. {
  8156. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  8157. goto end;
  8158. }
  8159. else
  8160. {
  8161. DEBUG_INFO("ShmSysConfigAndInfo->SysInfo.GbChargingData[%d].SystemStatus=%d\n",index,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus);
  8162. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  8163. goto end;
  8164. }
  8165. }
  8166. }// END FOR GB_QUANTITY
  8167. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  8168. {
  8169. if ((gunIndex > 0)&&(gunType[gunIndex-1] == GUN_TYPE_DO))
  8170. {
  8171. if((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_RESERVATION)) // S_PRECHARGE
  8172. {
  8173. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  8174. goto end;
  8175. }
  8176. else if((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_AUTHORIZING) ||
  8177. (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_PREPARING) ||
  8178. (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_CHARGING) ||
  8179. (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_TERMINATING) ||
  8180. (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_COMPLETE)) // S_CHARGING
  8181. {
  8182. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  8183. goto end;
  8184. }
  8185. else
  8186. {
  8187. DEBUG_INFO("ShmSysConfigAndInfo->SysInfo.GbChargingData[%d].SystemStatus=%d\n",index,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus);
  8188. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  8189. goto end;
  8190. }
  8191. }
  8192. }// END FOR GENERAL_GUN_QUANTITY
  8193. for (int index = 0; index < AC_QUANTITY; index++)
  8194. {
  8195. if ((gunIndex > 0)&&(gunType[gunIndex-1] ==GUN_TYPE_AC))
  8196. {
  8197. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_RESERVATION)) // S_PRECHARGE
  8198. {
  8199. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  8200. goto end;
  8201. }
  8202. else if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_AUTHORIZING) ||
  8203. (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_PREPARING) ||
  8204. (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_CHARGING) ||
  8205. (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_TERMINATING) ||
  8206. (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_COMPLETE)) // S_CHARGING
  8207. {
  8208. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  8209. goto end;
  8210. }
  8211. else
  8212. {
  8213. DEBUG_INFO("ShmSysConfigAndInfo->SysInfo.AcChargingData[%d].SystemStatus=%d\n",index, ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus);
  8214. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  8215. goto end;
  8216. }
  8217. }
  8218. }//END FOR AC_QUANTITY
  8219. }//END FOR AvailabilityTypeStr[Inoperative]
  8220. if(strcmp((const char *)typeStr, AvailabilityTypeStr[Operative]) == 0)
  8221. {
  8222. //----------------------gunIndex is 0 ------------------------------------------------//
  8223. if(gunIndex == 0)
  8224. {
  8225. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D') // 'D' means DC
  8226. {
  8227. for(int i=0; i < gunTotalNumber; i++)
  8228. {
  8229. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  8230. {
  8231. 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
  8232. {
  8233. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  8234. goto end;
  8235. }
  8236. }//END FOR CHAdeMO_QUANTITY
  8237. for (int index = 0; index < CCS_QUANTITY; index++)
  8238. {
  8239. 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
  8240. {
  8241. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  8242. goto end;
  8243. }
  8244. }//END FOR CCS_QUANTITY
  8245. for (int index = 0; index < GB_QUANTITY; index++)
  8246. {
  8247. 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
  8248. {
  8249. //ShmOCPP16Data->CsMsg.bits[gunIndex - 1].ChangeAvailabilityReq = 1;
  8250. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  8251. goto end;
  8252. }
  8253. }// END FOR GB_QUANTITY
  8254. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  8255. {
  8256. 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
  8257. {
  8258. //ShmOCPP16Data->CsMsg.bits[gunIndex - 1].ChangeAvailabilityReq = 1;
  8259. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  8260. goto end;
  8261. }
  8262. }// END FOR GENERAL_GUN_QUANTITY
  8263. for (int index = 0; index < AC_QUANTITY; index++)
  8264. {
  8265. 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
  8266. {
  8267. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  8268. goto end;
  8269. }
  8270. }//END FOR CHAdeMO_QUANTITY
  8271. }// END FOR gunTotalNumber
  8272. }
  8273. else if (ShmSysConfigAndInfo->SysConfig.ModelName[0]=='A') //'A' means AC
  8274. {
  8275. for(int i=0; i < gunTotalNumber; i++)
  8276. {
  8277. for (int index = 0; index < AC_QUANTITY; index++)
  8278. {
  8279. 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
  8280. {
  8281. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  8282. goto end;
  8283. }
  8284. }//END FOR CHAdeMO_QUANTITY
  8285. } // END FOR gunTotalNumber
  8286. }
  8287. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  8288. goto end;
  8289. }
  8290. //----------------------gunIndex is not 0 ------------------------------------------------//
  8291. //check Transaction active
  8292. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  8293. {
  8294. if (((gunIndex > 0)&&(gunType[gunIndex-1] == GUN_TYPE_CHAdeMO) ) &&(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_FAULT)) //S_FAULT
  8295. {
  8296. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  8297. goto end;
  8298. }
  8299. }//END FOR CHAdeMO_QUANTITY
  8300. for (int index = 0; index < CCS_QUANTITY; index++)
  8301. {
  8302. if ((((gunIndex > 0)&&(gunType[gunIndex - 1] == GUN_TYPE_CCS)) )&&(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_FAULT)) //S_FAULT
  8303. {
  8304. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  8305. goto end;
  8306. }
  8307. }//END FOR CCS_QUANTITY
  8308. for (int index = 0; index < GB_QUANTITY; index++)
  8309. {
  8310. if (((gunIndex > 0)&&(gunType[gunIndex-1] == GUN_TYPE_GBT))&&(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_FAULT)) //S_FAULT
  8311. {
  8312. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  8313. goto end;
  8314. }
  8315. }// END FOR GB_QUANTITY
  8316. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  8317. {
  8318. if (((gunIndex > 0)&&(gunType[gunIndex-1] == GUN_TYPE_DO))&&(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus != SYS_MODE_FAULT)) //S_FAULT
  8319. {
  8320. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  8321. goto end;
  8322. }
  8323. }// END FOR GENERAL_GUN_QUANTITY
  8324. for (int index = 0; index < AC_QUANTITY; index++)
  8325. {
  8326. if (((gunIndex > 0)&&(gunType[gunIndex-1] == GUN_TYPE_AC)) &&(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_FAULT)) //S_FAULT
  8327. {
  8328. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  8329. goto end;
  8330. }
  8331. }//END FOR AC_QUANTITY
  8332. }//END FOR AvailabilityTypeStr[Operative]
  8333. end:
  8334. if((gunIndex != 0) && (gunIndex <= gunTotalNumber))
  8335. {
  8336. sprintf((char *)ShmOCPP16Data->ChangeAvailability[gunIndex - 1].ResponseStatus, "%s", comfirmstr );
  8337. }
  8338. else
  8339. {
  8340. sprintf((char *)ShmOCPP16Data->ChangeAvailability[0].ResponseStatus, "%s", comfirmstr );
  8341. }
  8342. if((gunIndex != 0) && (gunIndex <= gunTotalNumber))
  8343. {
  8344. if(strstr(comfirmstr, AvailabilityStatusStr[Rejected]) == NULL)
  8345. ShmOCPP16Data->CsMsg.bits[gunIndex - 1].ChangeAvailabilityReq = 1;
  8346. }
  8347. else if(gunIndex == 0)
  8348. {
  8349. if(strstr(comfirmstr, AvailabilityStatusStr[Rejected]) == NULL)
  8350. {
  8351. for(int i=0; i < gunTotalNumber/*(CHAdeMO_QUANTITY+ CCS_QUANTITY + GB_QUANTITY)*/; i++)
  8352. ShmOCPP16Data->CsMsg.bits[i].ChangeAvailabilityReq = 1;
  8353. }
  8354. }
  8355. sendChangeAvailabilityConfirmation(uuid, comfirmstr);
  8356. system("/bin/fsync -d /dev/mtdblock13;/bin/sync &");
  8357. return result;
  8358. }
  8359. int handleChangeConfigurationRequest(char *uuid, char *payload)
  8360. {
  8361. mtrace();
  8362. int valueInvalid = NO;
  8363. int result = FAIL;
  8364. char keystr[40]={0};
  8365. char valuestr[501]={0}; //value should be limited in 500 bytes
  8366. char comfirmstr[20]={0};
  8367. DEBUG_INFO("handleChangeConfigurationRequest...\n");
  8368. json_object *ChangeConfiguration;
  8369. ChangeConfiguration = json_tokener_parse(payload);
  8370. if(!is_error(ChangeConfiguration))
  8371. {
  8372. // Required data
  8373. if(json_object_object_get(ChangeConfiguration, "key") != NULL)
  8374. sprintf((char*)keystr, "%s", json_object_get_string(json_object_object_get(ChangeConfiguration, "key")));
  8375. if((json_object_object_get(ChangeConfiguration, "value") != NULL) && (strlen(json_object_get_string(json_object_object_get(ChangeConfiguration, "value"))) < ARRAY_SIZE(valuestr)))
  8376. {
  8377. sprintf((char*)valuestr, "%s", json_object_get_string(json_object_object_get(ChangeConfiguration, "value")));
  8378. }
  8379. else
  8380. {
  8381. valueInvalid = YES;
  8382. DEBUG_ERROR("The ChangeConfiguration value is NULL or OVER SIZE.\n");
  8383. }
  8384. }
  8385. json_object_put(ChangeConfiguration);
  8386. if((uuid==NULL) || (payload ==NULL) || (valueInvalid==YES))
  8387. {
  8388. DEBUG_ERROR("Payload is null or value is invalid.\n");
  8389. sprintf(comfirmstr, "%s", ConfigurationStatusStr[ConfigurationStatus_Rejected] );
  8390. }
  8391. else
  8392. {
  8393. int status = setKeyValue(keystr, valuestr);
  8394. switch(status)
  8395. {
  8396. case ConfigurationStatus_Accepted:
  8397. sprintf(comfirmstr, "%s", ConfigurationStatusStr[ConfigurationStatus_Accepted]);
  8398. ShmOCPP16Data->MsMsg.bits.ChangeConfigurationReq = 1;
  8399. StoreConfigurationTable();
  8400. break;
  8401. case RebootRequired:
  8402. sprintf(comfirmstr, "%s", ConfigurationStatusStr[RebootRequired]);
  8403. StoreConfigurationTable();
  8404. break;
  8405. case NotSupported:
  8406. sprintf(comfirmstr, "%s", ConfigurationStatusStr[NotSupported] );
  8407. break;
  8408. case ConfigurationStatus_Rejected:
  8409. default:
  8410. sprintf(comfirmstr, "%s", ConfigurationStatusStr[ConfigurationStatus_Rejected] );
  8411. break;
  8412. }
  8413. }
  8414. sendChangeConfigurationConfirmation(uuid, comfirmstr);
  8415. ShmOCPP16Data->MsMsg.bits.ChangeConfigurationConf = 1;
  8416. if(((strcmp(keystr,"AuthorizationKey")==0) || (strcmp(keystr,"SecurityProfile")==0) || (strcmp(keystr,"OcppServer")==0) || (strcmp(keystr,"MaintainServer")==0)) && (strcmp(comfirmstr,"Accepted")==0))
  8417. {
  8418. StoreUsrConfigData(&ShmSysConfigAndInfo->SysConfig);
  8419. SetOcppConnStatus(FALSE);
  8420. }
  8421. if(((strcmp(keystr,"FreeVend")==0)) && (strcmp(comfirmstr,"Accepted")==0))
  8422. {
  8423. StoreUsrConfigData(&ShmSysConfigAndInfo->SysConfig);
  8424. }
  8425. return result;
  8426. }
  8427. int handleClearCacheRequest(char *uuid, char *payload)
  8428. {
  8429. mtrace();
  8430. int result = FAIL;
  8431. char comfirmstr[20];
  8432. char rmFileCmd[100]={0};
  8433. struct stat stats;
  8434. DEBUG_INFO("handleClearCacheRequest...\n");
  8435. stat("/Storage/OCPP", &stats);
  8436. // Check for directory existence
  8437. if (S_ISDIR(stats.st_mode) == 1)
  8438. {}
  8439. else
  8440. {
  8441. DEBUG_INFO("\n OCPP directory not exist, create dir \n");
  8442. sprintf(rmFileCmd,"mkdir -p %s","/Storage/OCPP");
  8443. system(rmFileCmd);
  8444. }
  8445. if(OCPP_cleanLocalCache())
  8446. {
  8447. sprintf(comfirmstr, "%s", ClearCacheStatusStr[ClearCacheStatus_Accepted] );
  8448. }
  8449. else
  8450. {
  8451. sprintf(comfirmstr, "%s", ClearCacheStatusStr[ClearCacheStatus_Rejected] );
  8452. }
  8453. sendClearCacheConfirmation(uuid, comfirmstr);
  8454. system("/bin/fsync -d /dev/mtdblock13;/bin/sync &");
  8455. return result;
  8456. }
  8457. int handleClearChargingProfileRequest(char *uuid, char *payload)
  8458. {
  8459. mtrace();
  8460. int result = FAIL;
  8461. int resultRename;
  8462. int connectorIdInt, chargingProfileIdInt, stackLevelInt;
  8463. char chargingProfilePurposeStr[26]={0};
  8464. int tempconnectorIdInt, tempchargingProfileIdInt, tempstackLevelInt;
  8465. char tempchargingProfilePurposeStr[26]={0};
  8466. char str[100]={0};
  8467. char fname[200]={0};
  8468. char comfirmstr[20]={0};
  8469. char word[1600]={0};
  8470. int clearflag = FALSE;
  8471. int chargingProfileIdIsNULL = FALSE;
  8472. int connectorIsNULL = FALSE;
  8473. int chargingProfilePurposeIsNULL = FALSE;
  8474. int stackLevelIsNULL = FALSE;
  8475. //int GotoEnd = FALSE;
  8476. FILE *fptr1, *fptr2;
  8477. char temp[] = "/Storage/OCPP/ClearChargingProfiletemp.json"; // Create temp file
  8478. int n_chargingProfile=0;
  8479. int isEmptyFile = FALSE;
  8480. char sLineWord[1600]={0};
  8481. char chargingProfiles[10][100]={0};
  8482. int ChargeProfileCount = 0;
  8483. int ch;
  8484. connectorIdInt = chargingProfileIdInt = stackLevelInt = 0;
  8485. DEBUG_INFO("handleClearChargingProfileRequest...\n");
  8486. json_object *ClearChargingProfile;
  8487. ClearChargingProfile = json_tokener_parse(payload);
  8488. if(!is_error(ClearChargingProfile))
  8489. {
  8490. // Optional data
  8491. if(json_object_object_get(ClearChargingProfile, "id") != NULL)
  8492. chargingProfileIdInt = json_object_get_int(json_object_object_get(ClearChargingProfile, "id"));
  8493. else
  8494. chargingProfileIdIsNULL = TRUE;
  8495. if(json_object_object_get(ClearChargingProfile, "connectorId") != NULL)
  8496. connectorIdInt = json_object_get_int(json_object_object_get(ClearChargingProfile, "connectorId"));
  8497. else
  8498. connectorIsNULL = TRUE;
  8499. if(json_object_object_get(ClearChargingProfile, "chargingProfilePurpose") != NULL)
  8500. sprintf((char*)chargingProfilePurposeStr, "%s", json_object_get_string(json_object_object_get(ClearChargingProfile, "chargingProfilePurpose")));
  8501. else
  8502. chargingProfilePurposeIsNULL = TRUE;
  8503. if(json_object_object_get(ClearChargingProfile, "stackLevel") != NULL)
  8504. stackLevelInt = json_object_get_int(json_object_object_get(ClearChargingProfile, "stackLevel"));
  8505. else
  8506. stackLevelIsNULL = TRUE;
  8507. }
  8508. json_object_put(ClearChargingProfile);
  8509. if(connectorIsNULL == FALSE)
  8510. {
  8511. switch(connectorIdInt)
  8512. {
  8513. case 0:
  8514. if(chargingProfilePurposeIsNULL == TRUE)
  8515. {
  8516. int l = 0;
  8517. strcpy(fname, ChargePointMaxProfile_JSON);
  8518. if((access(fname,F_OK))!=-1)
  8519. {
  8520. strcpy(chargingProfiles[l], fname);
  8521. l = l + 1;
  8522. }
  8523. strcpy(fname, TxDefaultProfile_0_JSON);
  8524. if((access(fname,F_OK))!=-1)
  8525. {
  8526. strcpy(chargingProfiles[l], fname);
  8527. l = l + 1;
  8528. }
  8529. ChargeProfileCount = l;
  8530. }
  8531. else if((chargingProfilePurposeIsNULL == FALSE)&&(strcmp(chargingProfilePurposeStr,"ChargePointMaxProfile")==0))
  8532. {
  8533. strcpy(fname, ChargePointMaxProfile_JSON);
  8534. if((access(fname,F_OK))!=-1)
  8535. {
  8536. strcpy(chargingProfiles[0], fname);
  8537. ChargeProfileCount = 1;
  8538. }
  8539. }
  8540. else if((chargingProfilePurposeIsNULL == FALSE)&&(strcmp(chargingProfilePurposeStr,"TxDefaultProfile")==0))
  8541. {
  8542. strcpy(fname, TxDefaultProfile_0_JSON);
  8543. if((access(fname,F_OK))!=-1)
  8544. {
  8545. strcpy(chargingProfiles[0], fname);
  8546. ChargeProfileCount = 1;
  8547. }
  8548. }
  8549. break;
  8550. default:
  8551. if(chargingProfilePurposeIsNULL == TRUE)
  8552. {
  8553. int m = 0;
  8554. memset(fname, 0, ARRAY_SIZE(fname));
  8555. sprintf(fname, "/Storage/OCPP/TxDefaultProfile_%d.json", connectorIdInt);
  8556. if((access(fname,F_OK))!=-1)
  8557. {
  8558. strcpy(chargingProfiles[m], fname);
  8559. m = m + 1;
  8560. }
  8561. memset(fname, 0, ARRAY_SIZE(fname));
  8562. sprintf(fname, "/Storage/OCPP/TxProfile_%d.json", connectorIdInt);
  8563. if((access(fname,F_OK))!=-1)
  8564. {
  8565. strcpy(chargingProfiles[m], fname);
  8566. m = m + 1;
  8567. }
  8568. ChargeProfileCount = m;
  8569. }
  8570. else if((chargingProfilePurposeIsNULL == FALSE)&&(strcmp(chargingProfilePurposeStr,"TxDefaultProfile")==0))
  8571. {
  8572. //strcpy(fname, TxDefaultProfile_1_JSON);
  8573. sprintf(fname, "/Storage/OCPP/TxDefaultProfile_%d.json", connectorIdInt);
  8574. if((access(fname,F_OK))!=-1)
  8575. {
  8576. strcpy(chargingProfiles[0], fname);
  8577. ChargeProfileCount = 1;
  8578. }
  8579. }
  8580. else if((chargingProfilePurposeIsNULL == FALSE)&&(strcmp(chargingProfilePurposeStr,"TxProfile")==0))
  8581. {
  8582. sprintf(fname, "/Storage/OCPP/TxProfile_%d.json", connectorIdInt);
  8583. if((access(fname,F_OK))!=-1)
  8584. {
  8585. strcpy(chargingProfiles[0], fname);
  8586. ChargeProfileCount = 1;
  8587. }
  8588. //strcpy(fname, TxProfile_1_JSON);
  8589. }
  8590. //strcpy(fname, ChargePointMaxProfile_JSON );
  8591. break;
  8592. }
  8593. }
  8594. else // Check all Charging Profiles
  8595. {
  8596. int i = 0;
  8597. char fnametemp[200]={0};
  8598. ChargeProfileCount = 0;
  8599. //Check ChargePointMaxProfile.json exit
  8600. if((access("/Storage/OCPP/ChargePointMaxProfile.json",F_OK))!=-1)
  8601. {
  8602. strcpy(chargingProfiles[i], "/Storage/OCPP/ChargePointMaxProfile.json");
  8603. i = i + 1;
  8604. }
  8605. //Check TxDefaultProfile_0.json exit
  8606. if((access("/Storage/OCPP/TxDefaultProfile_0.json",F_OK))!=-1)
  8607. {
  8608. strcpy(chargingProfiles[i], "/Storage/OCPP/TxDefaultProfile_0.json");
  8609. i = i + 1;
  8610. }
  8611. //Check TxDefaultProfile_%d.json
  8612. for(int j=1; j <= gunTotalNumber; j++)
  8613. {
  8614. memset(fnametemp, 0, ARRAY_SIZE(fnametemp));
  8615. sprintf(fnametemp, "/Storage/OCPP/TxDefaultProfile_%d.json", j);
  8616. if((access(fnametemp,F_OK))!=-1)
  8617. {
  8618. strcpy(chargingProfiles[i], fnametemp);
  8619. i = i + 1;
  8620. }
  8621. }
  8622. //Check TxProfile_%d.json
  8623. for(int j=1; j <= gunTotalNumber; j++)
  8624. {
  8625. memset(fnametemp, 0, ARRAY_SIZE(fnametemp));
  8626. sprintf(fnametemp, "/Storage/OCPP/TxProfile_%d.json", j);
  8627. if((access(fnametemp,F_OK))!=-1)
  8628. {
  8629. strcpy(chargingProfiles[i], fnametemp);
  8630. i = i + 1;
  8631. }
  8632. }
  8633. ChargeProfileCount = i;
  8634. }// End connectorIsNULL is TRUE
  8635. if(ChargeProfileCount == 0)
  8636. {
  8637. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Unknown] );
  8638. goto end;
  8639. }
  8640. if(connectorIsNULL == FALSE && (connectorIdInt != 0) && ( (connectorIdInt-1) > gunTotalNumber) )
  8641. {
  8642. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Unknown] );
  8643. goto end;
  8644. }
  8645. if((connectorIsNULL == FALSE) && (connectorIdInt == 0) )
  8646. {
  8647. memset(str, 0, ARRAY_SIZE(str));
  8648. // clear temp file
  8649. sprintf(str,"rm -f %s",temp);
  8650. system(str);
  8651. for(int k=0; k < ChargeProfileCount; k++)
  8652. {
  8653. memset(str, 0, ARRAY_SIZE(str));
  8654. //clear file in C
  8655. sprintf(str,"rm -f %s",chargingProfiles[k]);
  8656. system(str);
  8657. }
  8658. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Accepted] );
  8659. goto end;
  8660. }
  8661. else if(connectorIsNULL == TRUE)
  8662. {
  8663. for(int k=0; k < ChargeProfileCount; k++)
  8664. {
  8665. fptr1 = fopen(chargingProfiles[k], "r");
  8666. fptr2 = fopen("/Storage/OCPP/ClearChargingProfiletemp.json", "w+");
  8667. //Check Charging Profile Count
  8668. while(fscanf(fptr1, "%s", word) != EOF)
  8669. {
  8670. //DEBUG_INFO("word=%s\n",word);
  8671. if(strstr(word, "chargingProfileId")!= NULL)
  8672. {
  8673. //DEBUG_INFO("test chargingProfileId \n");
  8674. n_chargingProfile = n_chargingProfile + 1;
  8675. //DEBUG_INFO("chargingProfileId Found\n");
  8676. }
  8677. }
  8678. rewind(fptr1);
  8679. //search Charging Profile Element
  8680. //int i= 0;
  8681. while ( fgets( sLineWord, sizeof sLineWord, fptr1 ) != NULL )
  8682. {
  8683. json_object *tmpProfilee;
  8684. tmpProfilee = json_tokener_parse(sLineWord);
  8685. if(!is_error(tmpProfilee))
  8686. {
  8687. if(json_object_object_get(tmpProfilee, "connectorId") != NULL)
  8688. {
  8689. tempconnectorIdInt = json_object_get_int(json_object_object_get(tmpProfilee, "connectorId"));
  8690. DEBUG_INFO("file's gun number: %d\n", tempconnectorIdInt);
  8691. }
  8692. if(json_object_object_get(json_object_object_get(tmpProfilee, "csChargingProfiles"), "chargingProfileId") != NULL)
  8693. {
  8694. tempchargingProfileIdInt = json_object_get_int(json_object_object_get(json_object_object_get(tmpProfilee, "csChargingProfiles"), "chargingProfileId"));
  8695. DEBUG_INFO("file's chargingProfileId: %d\n", tempchargingProfileIdInt);
  8696. }
  8697. if(json_object_object_get(json_object_object_get(tmpProfilee, "csChargingProfiles"), "stackLevel") != NULL)
  8698. {
  8699. tempstackLevelInt = json_object_get_int(json_object_object_get(json_object_object_get(tmpProfilee, "csChargingProfiles"), "stackLevel"));
  8700. DEBUG_INFO("file's stackLevel: %d\n", tempstackLevelInt);
  8701. }
  8702. if(json_object_object_get(json_object_object_get(tmpProfilee, "csChargingProfiles"), "chargingProfilePurpose") != NULL)
  8703. {
  8704. sprintf((char*)tempchargingProfilePurposeStr, "%s", json_object_get_string(json_object_object_get(json_object_object_get(tmpProfilee, "csChargingProfiles"), "chargingProfilePurpose")));
  8705. DEBUG_INFO("file's chargingProfilePurpose: %s\n", tempchargingProfilePurposeStr);
  8706. }
  8707. }
  8708. json_object_put(tmpProfilee);
  8709. if((chargingProfileIdIsNULL == FALSE)&&(tempchargingProfileIdInt == chargingProfileIdInt))
  8710. {
  8711. //------- not write to fptr2-------//
  8712. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Accepted] );
  8713. //clearflag = TRUE;
  8714. }
  8715. else if((chargingProfilePurposeIsNULL == FALSE)&&(strcmp(tempchargingProfilePurposeStr, chargingProfilePurposeStr) == 0))
  8716. {
  8717. //------- not write to fptr2-------//
  8718. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Accepted] );
  8719. }
  8720. else if((stackLevelIsNULL == FALSE) &&(tempstackLevelInt == stackLevelInt))
  8721. {
  8722. //------- not write to fptr2-------//
  8723. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Accepted] );
  8724. }
  8725. else if(chargingProfileIdIsNULL && chargingProfilePurposeIsNULL && stackLevelIsNULL)
  8726. {
  8727. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Accepted] );
  8728. }
  8729. else
  8730. {
  8731. fprintf(fptr2, sLineWord);//writing data into file
  8732. }
  8733. memset(sLineWord, 0, ARRAY_SIZE(sLineWord));
  8734. } //End of while ( fgets( sLineWord, sizeof sLineWord, fptr1 ) != NULL )
  8735. if(clearflag == TRUE)
  8736. {
  8737. fclose(fptr1);
  8738. fclose(fptr2);
  8739. sprintf(str,"rm -f %s",chargingProfiles[k]);
  8740. system(str);
  8741. // clear temp file
  8742. sprintf(str,"rm -f %s",temp);
  8743. system(str);
  8744. }
  8745. else
  8746. {
  8747. fclose(fptr1);
  8748. fclose(fptr2);
  8749. memset(str, 0, ARRAY_SIZE(str));
  8750. sprintf(str,"rm -f %s",chargingProfiles[k]);
  8751. system(str);
  8752. resultRename = rename(temp, chargingProfiles[k]);
  8753. if(resultRename == 0)
  8754. {
  8755. DEBUG_INFO("File ChargingProfile renamed successfully\n");
  8756. }
  8757. else
  8758. {
  8759. DEBUG_INFO("Error: unable to rename the ChargingProfile file\n");
  8760. }
  8761. if(comfirmstr[0]== 0)
  8762. {
  8763. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Unknown] );
  8764. }
  8765. //Check chargingProfile is empty file
  8766. /*------ Read the file ----------------*/
  8767. fptr1=fopen(chargingProfiles[k],"r");
  8768. ch=fgetc(fptr1);
  8769. rewind(fptr1);
  8770. memset(sLineWord, 0, ARRAY_SIZE(sLineWord));
  8771. if(ch!=EOF)
  8772. {
  8773. while (fgets( sLineWord, sizeof sLineWord, fptr1) != NULL)
  8774. {
  8775. str[strlen(sLineWord) - 1] = '\0'; // eat the newline fgets() stores
  8776. if(sLineWord[0]=='\0')
  8777. {
  8778. isEmptyFile = TRUE;
  8779. break;
  8780. }
  8781. else
  8782. {
  8783. isEmptyFile = FALSE;
  8784. break;
  8785. }
  8786. }
  8787. }
  8788. else
  8789. isEmptyFile = TRUE;
  8790. fclose(fptr1);
  8791. if(isEmptyFile == TRUE)
  8792. {
  8793. memset(str, 0, ARRAY_SIZE(str));
  8794. sprintf(str,"rm -f %s",chargingProfiles[k]);
  8795. system(str);
  8796. }
  8797. }
  8798. }// End of while(int k=0; k < ChargePointCount; k++)
  8799. }
  8800. else if((connectorIsNULL == FALSE) && (connectorIdInt != 0) )
  8801. {
  8802. DEBUG_INFO("ChargeProfileCount = %d\n", ChargeProfileCount);
  8803. for(int k=0; k < ChargeProfileCount; k++)
  8804. {
  8805. fptr1 = fopen(chargingProfiles[k], "r");
  8806. fptr2 = fopen(temp, "w+");
  8807. //Check Charging Profile Count
  8808. while(fscanf(fptr1, "%s", word) != EOF)
  8809. {
  8810. //DEBUG_INFO("word=%s\n",word);
  8811. if(strstr(word, "chargingProfileId")!= NULL)
  8812. {
  8813. n_chargingProfile = n_chargingProfile + 1;
  8814. }
  8815. }
  8816. rewind(fptr1);
  8817. //search Charging Profile Element
  8818. //int i= 0;
  8819. while ( fgets( sLineWord, sizeof sLineWord, fptr1 ) != NULL )
  8820. {
  8821. json_object *tmpProfilee;
  8822. tmpProfilee = json_tokener_parse(sLineWord);
  8823. if(!is_error(tmpProfilee))
  8824. {
  8825. if(json_object_object_get(tmpProfilee, "connectorId") != NULL)
  8826. {
  8827. tempconnectorIdInt = json_object_get_int(json_object_object_get(tmpProfilee, "connectorId"));
  8828. DEBUG_INFO("file's gun number: %d\n", tempconnectorIdInt);
  8829. }
  8830. if(json_object_object_get(json_object_object_get(tmpProfilee, "csChargingProfiles"), "chargingProfileId") != NULL)
  8831. {
  8832. tempchargingProfileIdInt = json_object_get_int(json_object_object_get(json_object_object_get(tmpProfilee, "csChargingProfiles"), "chargingProfileId"));
  8833. DEBUG_INFO("file's chargingProfileId: %d\n", tempchargingProfileIdInt);
  8834. }
  8835. if(json_object_object_get(json_object_object_get(tmpProfilee, "csChargingProfiles"), "stackLevel") != NULL)
  8836. {
  8837. tempstackLevelInt = json_object_get_int(json_object_object_get(json_object_object_get(tmpProfilee, "csChargingProfiles"), "stackLevel"));
  8838. DEBUG_INFO("file's stackLevel: %d\n", tempstackLevelInt);
  8839. }
  8840. if(json_object_object_get(json_object_object_get(tmpProfilee, "csChargingProfiles"), "chargingProfilePurpose") != NULL)
  8841. {
  8842. sprintf((char*)tempchargingProfilePurposeStr, "%s", json_object_get_string(json_object_object_get(json_object_object_get(tmpProfilee, "csChargingProfiles"), "chargingProfilePurpose")));
  8843. DEBUG_INFO("file's chargingProfilePurpose: %s\n", tempchargingProfilePurposeStr);
  8844. }
  8845. }
  8846. json_object_put(tmpProfilee);
  8847. if((chargingProfileIdIsNULL == FALSE)&&(tempchargingProfileIdInt == chargingProfileIdInt))
  8848. {
  8849. //------- not write to fptr2-------//
  8850. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Accepted] );
  8851. //clearflag = TRUE;
  8852. }
  8853. else if((stackLevelIsNULL == FALSE) &&(tempstackLevelInt == stackLevelInt))
  8854. {
  8855. //------- not write to fptr2-------//
  8856. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Accepted] );
  8857. }
  8858. else if(stackLevelIsNULL == TRUE)
  8859. {
  8860. //Clear Whole File
  8861. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Accepted] );
  8862. clearflag = TRUE;
  8863. break;
  8864. }
  8865. else
  8866. {
  8867. fprintf(fptr2, sLineWord);//writing data into file
  8868. }
  8869. memset(sLineWord, 0, ARRAY_SIZE(sLineWord));
  8870. }
  8871. if(clearflag == TRUE)
  8872. {
  8873. fclose(fptr1);
  8874. fclose(fptr2);
  8875. sprintf(str,"rm -f %s",chargingProfiles[k]);
  8876. system(str);
  8877. // clear temp file
  8878. sprintf(str,"rm -f %s",temp);
  8879. system(str);
  8880. }
  8881. else
  8882. {
  8883. fclose(fptr1);
  8884. fclose(fptr2);
  8885. sprintf(str,"rm -f %s",chargingProfiles[k]);
  8886. system(str);
  8887. resultRename = rename(temp, chargingProfiles[k]);
  8888. if(resultRename == 0)
  8889. {
  8890. DEBUG_INFO("File ChargingProfile renamed successfully");
  8891. }
  8892. else
  8893. {
  8894. DEBUG_INFO("Error: unable to rename the ChargingProfile file");
  8895. }
  8896. if(comfirmstr[0]== 0)
  8897. {
  8898. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Unknown] );
  8899. }
  8900. //Check chargingProfile is empty file
  8901. /*------ Read the file ----------------*/
  8902. fptr1=fopen(chargingProfiles[k],"r");
  8903. ch=fgetc(fptr1);
  8904. rewind(fptr1);
  8905. memset(sLineWord, 0, ARRAY_SIZE(sLineWord));
  8906. if(ch!=EOF)
  8907. {
  8908. while (fgets( sLineWord, sizeof sLineWord, fptr1) != NULL)
  8909. {
  8910. str[strlen(sLineWord) - 1] = '\0'; // eat the newline fgets() stores
  8911. if(sLineWord[0]=='\0')
  8912. {
  8913. isEmptyFile = TRUE;
  8914. break;
  8915. }
  8916. else
  8917. {
  8918. isEmptyFile = FALSE;
  8919. break;
  8920. }
  8921. }
  8922. }
  8923. else
  8924. isEmptyFile = TRUE;
  8925. fclose(fptr1);
  8926. if(isEmptyFile == TRUE)
  8927. {
  8928. memset(str, 0, ARRAY_SIZE(str));
  8929. sprintf(str,"rm -f %s",chargingProfiles[k]);
  8930. system(str);
  8931. }
  8932. /*------- End of reading ---------------*/
  8933. }
  8934. } // while(int k=0; k < ChargeProfileCount; k++)
  8935. }// (connectorIsNULL == FALSE) && (connectorIdInt != 0)
  8936. end:
  8937. if(strcmp(comfirmstr, ClearChargingProfileStatusStr[ClearChargingProfileStatus_Accepted]) == 0)
  8938. {
  8939. if(connectorIdInt == 0)
  8940. {
  8941. for(uint8_t idx=0;idx<gunTotalNumber;idx++)
  8942. {
  8943. checkCompositeSchedule((idx+1), 86400, &ShmOCPP16Data->SmartChargingProfile[idx], TRUE);
  8944. }
  8945. }
  8946. else
  8947. checkCompositeSchedule(connectorIdInt, 86400, &ShmOCPP16Data->SmartChargingProfile[connectorIdInt-1], TRUE);
  8948. }
  8949. sendClearChargingProfileConfirmation(uuid, comfirmstr);
  8950. system("/bin/fsync -d /dev/mtdblock13;/bin/sync &");
  8951. return result;
  8952. }
  8953. void createFirmwareVersionByDataTransfer(void)
  8954. {
  8955. json_object *FirmwareDataTransfer = json_object_new_object();
  8956. // AC & DC model
  8957. json_object_object_add(FirmwareDataTransfer, "CsuBootLoadFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.CsuBootLoadFwRev));
  8958. json_object_object_add(FirmwareDataTransfer, "CsuKernelFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.CsuKernelFwRev));
  8959. json_object_object_add(FirmwareDataTransfer, "CsuRootFsFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.CsuRootFsFwRev));
  8960. json_object_object_add(FirmwareDataTransfer, "CsuPrimFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.CsuPrimFwRev));
  8961. // DC model
  8962. if((ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D'))
  8963. {
  8964. if((gunType[1] != GUN_TYPE_UNKNOWN) ||
  8965. (gunType[2] != GUN_TYPE_UNKNOWN) ||
  8966. (gunType[3] != GUN_TYPE_UNKNOWN))
  8967. {
  8968. json_object_object_add(FirmwareDataTransfer, "Connector2FwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.Connector2FwRev));
  8969. }
  8970. if((ShmSysConfigAndInfo->SysConfig.ModelName[1]!='B') && (ShmSysConfigAndInfo->SysConfig.ModelName[1]!='K') && (ShmSysConfigAndInfo->SysConfig.ModelName[1]!='O'))
  8971. {
  8972. // DS DM DW
  8973. json_object_object_add(FirmwareDataTransfer, "FanModuleFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.FanModuleFwRev));
  8974. json_object_object_add(FirmwareDataTransfer, "RelayModuleFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.RelayModuleFwRev));
  8975. json_object_object_add(FirmwareDataTransfer, "LedModuleFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.LedModuleFwRev));
  8976. json_object_object_add(FirmwareDataTransfer, "Connector1FwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.Connector1FwRev));
  8977. json_object_object_add(FirmwareDataTransfer, "PsuPrimFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.PsuPrimFwRev));
  8978. json_object_object_add(FirmwareDataTransfer, "PsuSecFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.PsuSecFwRev));
  8979. }
  8980. else
  8981. {
  8982. json_object_object_add(FirmwareDataTransfer, "FanModuleFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.FanModuleFwRev));
  8983. json_object_object_add(FirmwareDataTransfer, "RelayModuleFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.RelayModuleFwRev));
  8984. json_object_object_add(FirmwareDataTransfer, "PsuPrimFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.PsuPrimFwRev));
  8985. json_object_object_add(FirmwareDataTransfer, "PsuSecFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.PsuSecFwRev));
  8986. json_object_object_add(FirmwareDataTransfer, "DD0_CsuBootLoadFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[0].CsuBootLoadFwRev));
  8987. json_object_object_add(FirmwareDataTransfer, "DD0_CsuKernelFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[0].CsuKernelFwRev));
  8988. json_object_object_add(FirmwareDataTransfer, "DD0_CsuRootFsFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[0].CsuRootFsFwRev));
  8989. json_object_object_add(FirmwareDataTransfer, "DD0_CsuPrimFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[0].CsuPrimFwRev));
  8990. json_object_object_add(FirmwareDataTransfer, "DD0_FanModuleFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[0].FanModuleFwRev));
  8991. json_object_object_add(FirmwareDataTransfer, "DD0_RelayModuleFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[0].RelayModuleFwRev));
  8992. json_object_object_add(FirmwareDataTransfer, "DD0_LedModuleFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[0].LedModuleFwRev));
  8993. json_object_object_add(FirmwareDataTransfer, "DD0_Connector1FwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[0].Connector1FwRev));
  8994. json_object_object_add(FirmwareDataTransfer, "DD0_Connector2FwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[0].Connector2FwRev));
  8995. if(strlen((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].CsuBootLoadFwRev) > 0)
  8996. json_object_object_add(FirmwareDataTransfer, "DD1_CsuBootLoadFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].CsuBootLoadFwRev));
  8997. if(strlen((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].CsuKernelFwRev) > 0)
  8998. json_object_object_add(FirmwareDataTransfer, "DD1_CsuKernelFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].CsuKernelFwRev));
  8999. if(strlen((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].CsuRootFsFwRev) > 0)
  9000. json_object_object_add(FirmwareDataTransfer, "DD1_CsuRootFsFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].CsuRootFsFwRev));
  9001. if(strlen((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].CsuPrimFwRev) > 0)
  9002. json_object_object_add(FirmwareDataTransfer, "DD1_CsuPrimFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].CsuPrimFwRev));
  9003. if(strlen((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].FanModuleFwRev) > 0)
  9004. json_object_object_add(FirmwareDataTransfer, "DD1_FanModuleFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].FanModuleFwRev));
  9005. if(strlen((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].RelayModuleFwRev) > 0)
  9006. json_object_object_add(FirmwareDataTransfer, "DD1_RelayModuleFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].RelayModuleFwRev));
  9007. if(strlen((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].LedModuleFwRev) > 0)
  9008. json_object_object_add(FirmwareDataTransfer, "DD1_LedModuleFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].LedModuleFwRev));
  9009. if(strlen((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].Connector1FwRev) > 0)
  9010. json_object_object_add(FirmwareDataTransfer, "DD1_Connector1FwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].Connector1FwRev));
  9011. if(strlen((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].Connector2FwRev) > 0)
  9012. json_object_object_add(FirmwareDataTransfer, "D11_Connector2FwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].Connector2FwRev));
  9013. }
  9014. }
  9015. // 4G model
  9016. if((ShmSysConfigAndInfo->SysConfig.ModelName[10]=='T')||(ShmSysConfigAndInfo->SysConfig.ModelName[10]=='D'))
  9017. {
  9018. json_object_object_add(FirmwareDataTransfer, "TelcomModemFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysConfig.TelecomInterface.TelcomSoftwareVer));
  9019. }
  9020. sprintf((char*)ShmOCPP16Data->DataTransfer[0].ResponseData, json_object_to_json_string_ext(FirmwareDataTransfer, JSON_C_TO_STRING_PLAIN));
  9021. json_object_put(FirmwareDataTransfer);
  9022. }
  9023. int handleDataTransferRequest(char *uuid, char *payload)
  9024. {
  9025. mtrace();
  9026. json_object *response = json_object_new_object();
  9027. int result = FAIL;
  9028. char tempvendorId[255]={0};
  9029. char tempmessageId[50]={0};
  9030. char tempdata[512]={0};
  9031. char message[2048]={0};
  9032. DEBUG_INFO("handleDataTransferRequest...\n");
  9033. if((uuid != NULL) && (payload != NULL))
  9034. {
  9035. json_object *DataTransfer;
  9036. DataTransfer = json_tokener_parse(payload);
  9037. if(!is_error(DataTransfer))
  9038. {
  9039. // Required data
  9040. if(json_object_object_get(DataTransfer, "vendorId") != NULL)
  9041. sprintf((char*)tempvendorId, "%s", json_object_get_string(json_object_object_get(DataTransfer, "vendorId")));
  9042. // Optional data
  9043. if(json_object_object_get(DataTransfer, "messageId") != NULL)
  9044. sprintf((char*)tempmessageId, "%s", json_object_get_string(json_object_object_get(DataTransfer, "messageId")));
  9045. if(json_object_object_get(DataTransfer, "data") != NULL)
  9046. sprintf((char*)tempdata, "%s", json_object_get_string(json_object_object_get(DataTransfer, "data")));
  9047. result = PASS;
  9048. }
  9049. json_object_put(DataTransfer);
  9050. if(strstr(tempmessageId, "ID_FirmwareVersion") != NULL)
  9051. {
  9052. // Send all moudle firmware version on EVSE
  9053. createFirmwareVersionByDataTransfer();
  9054. json_object_object_add(response, "status", json_object_new_string("Accepted"));
  9055. json_object_object_add(response, "data", json_object_new_string((char*)ShmOCPP16Data->DataTransfer[0].ResponseData));
  9056. sprintf(message,"[%d,\"%s\",%s]",MESSAGE_TYPE_CALLRESULT, uuid, json_object_to_json_string_ext(response, JSON_C_TO_STRING_PLAIN));
  9057. json_object_put(response);
  9058. }
  9059. else if(strstr(tempmessageId, "ID_Tmate") != NULL)
  9060. {
  9061. system("/usr/bin/run_tmate_restart.sh &");
  9062. json_object_object_add(response, "status", json_object_new_string("Accepted"));
  9063. sprintf(message,"[%d,\"%s\",%s]",MESSAGE_TYPE_CALLRESULT, uuid, json_object_to_json_string_ext(response, JSON_C_TO_STRING_PLAIN));
  9064. json_object_put(response);
  9065. }
  9066. else if(strstr(tempmessageId, "ID_ChargingPreference") != NULL)
  9067. {
  9068. json_object *data;
  9069. data = json_tokener_parse(tempdata);
  9070. if(!is_error(data))
  9071. {
  9072. 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))
  9073. {
  9074. DEBUG_INFO("ChargeingPreference connector id: %d\n", json_object_get_int(json_object_object_get(data, "ConnectorId")));
  9075. memset(&ShmOCPP16Data->SessionTarget[json_object_get_int(json_object_object_get(data, "ConnectorId"))], 0x00, sizeof(struct StructSessionTarget));
  9076. if(json_object_object_get(data, "SOC") != NULL)
  9077. {
  9078. ShmOCPP16Data->SessionTarget[json_object_get_int(json_object_object_get(data, "ConnectorId"))].targetSoc = json_object_get_int(json_object_object_get(data, "SOC"));
  9079. DEBUG_INFO("ChargeingPreference target soc: %d\n", json_object_get_int(json_object_object_get(data, "SOC")));
  9080. }
  9081. if(json_object_object_get(data, "Energy") != NULL)
  9082. {
  9083. ShmOCPP16Data->SessionTarget[json_object_get_int(json_object_object_get(data, "ConnectorId"))].targetEnergy = json_object_get_int(json_object_object_get(data, "Energy"));
  9084. DEBUG_INFO("ChargeingPreference target energy: %d KWH\n", json_object_get_int(json_object_object_get(data, "Energy")));
  9085. }
  9086. if(json_object_object_get(data, "Duration") != NULL)
  9087. {
  9088. ShmOCPP16Data->SessionTarget[json_object_get_int(json_object_object_get(data, "ConnectorId"))].targetDuration = json_object_get_int(json_object_object_get(data, "Duration"));
  9089. DEBUG_INFO("ChargeingPreference target duration: %d minutes\n", json_object_get_int(json_object_object_get(data, "Duration")));
  9090. }
  9091. json_object_object_add(response, "status", json_object_new_string("Accepted"));
  9092. }
  9093. else
  9094. {
  9095. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  9096. json_object_object_add(response, "data", json_object_new_string("Connector id must > 0."));
  9097. }
  9098. }
  9099. else
  9100. {
  9101. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  9102. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  9103. }
  9104. json_object_put(data);
  9105. sprintf(message,"[%d,\"%s\",%s]",MESSAGE_TYPE_CALLRESULT, uuid, json_object_to_json_string_ext(response, JSON_C_TO_STRING_PLAIN));
  9106. json_object_put(response);
  9107. }
  9108. else if(strstr(tempmessageId, "SetLEDBar") != NULL)
  9109. {
  9110. json_object *data;
  9111. data = json_tokener_parse(tempdata);
  9112. if(!is_error(data))
  9113. {
  9114. ShmSysConfigAndInfo->SysConfig.LedInfo.Intensity = json_object_get_int(json_object_object_get(data, "Intensity"));
  9115. ShmSysConfigAndInfo->SysConfig.LedInfo.Red[0] = json_object_get_int(json_object_object_get(json_object_object_get(data, "Idle"), "R"));
  9116. ShmSysConfigAndInfo->SysConfig.LedInfo.Green[0]= json_object_get_int(json_object_object_get(json_object_object_get(data, "Idle"), "G"));
  9117. ShmSysConfigAndInfo->SysConfig.LedInfo.Blue[0] = json_object_get_int(json_object_object_get(json_object_object_get(data, "Idle"), "B"));
  9118. ShmSysConfigAndInfo->SysConfig.LedInfo.Red[1] = json_object_get_int(json_object_object_get(json_object_object_get(data, "Charging"), "R"));
  9119. ShmSysConfigAndInfo->SysConfig.LedInfo.Green[1]= json_object_get_int(json_object_object_get(json_object_object_get(data, "Charging"), "G"));
  9120. ShmSysConfigAndInfo->SysConfig.LedInfo.Blue[1] = json_object_get_int(json_object_object_get(json_object_object_get(data, "Charging"), "B"));
  9121. ShmSysConfigAndInfo->SysConfig.LedInfo.Red[2] = json_object_get_int(json_object_object_get(json_object_object_get(data, "Fault"), "R"));
  9122. ShmSysConfigAndInfo->SysConfig.LedInfo.Green[2]= json_object_get_int(json_object_object_get(json_object_object_get(data, "Fault"), "G"));
  9123. ShmSysConfigAndInfo->SysConfig.LedInfo.Blue[2] = json_object_get_int(json_object_object_get(json_object_object_get(data, "Fault"), "B"));
  9124. json_object_object_add(response, "status", json_object_new_string("Accepted"));
  9125. }
  9126. else
  9127. {
  9128. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  9129. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  9130. }
  9131. json_object_put(data);
  9132. sprintf(message,"[%d,\"%s\",%s]",MESSAGE_TYPE_CALLRESULT, uuid, json_object_to_json_string_ext(response, JSON_C_TO_STRING_PLAIN));
  9133. json_object_put(response);
  9134. }
  9135. else if(strstr(tempmessageId, "SetUserPrice") != NULL)
  9136. {
  9137. json_object *data;
  9138. data = json_tokener_parse(tempdata);
  9139. if(!is_error(data))
  9140. {
  9141. memset(&ShmOCPP16Data->Cost.SetUserPrice, 0x00, sizeof(struct StrcutSetUserPrice));
  9142. if(json_object_object_get(data, "idToken") != NULL)
  9143. {
  9144. sprintf((char*)ShmOCPP16Data->Cost.SetUserPrice.idToken, "%s", json_object_get_string(json_object_object_get(data, "idToken")));
  9145. DEBUG_INFO("idToken: %s\n", json_object_get_string(json_object_object_get(data, "idToken")));
  9146. }
  9147. if(json_object_object_get(data, "price") != NULL)
  9148. {
  9149. sprintf((char*)ShmOCPP16Data->Cost.SetUserPrice.price, "%s", json_object_get_string(json_object_object_get(data, "price")));
  9150. DEBUG_INFO("price: %s\n", json_object_get_string(json_object_object_get(data, "price")));
  9151. }
  9152. json_object_object_add(response, "status", json_object_new_string("Accepted"));
  9153. }
  9154. else
  9155. {
  9156. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  9157. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  9158. }
  9159. json_object_put(data);
  9160. sprintf(message,"[%d,\"%s\",%s]",MESSAGE_TYPE_CALLRESULT, uuid, json_object_to_json_string_ext(response, JSON_C_TO_STRING_PLAIN));
  9161. json_object_put(response);
  9162. }
  9163. else if(strstr(tempmessageId, "RunningCost") != NULL)
  9164. {
  9165. json_object *data;
  9166. data = json_tokener_parse(tempdata);
  9167. if(!is_error(data))
  9168. {
  9169. if(json_object_object_get(data, "txId") != NULL)
  9170. {
  9171. DEBUG_INFO("transaction id: %d\n", json_object_get_int(json_object_object_get(data, "txId")));
  9172. for(int idx = 0;idx<gunTotalNumber;idx++)
  9173. {
  9174. if(ShmOCPP16Data->StartTransaction[idx].ResponseTransactionId == json_object_get_int(json_object_object_get(data, "txId")))
  9175. {
  9176. memset(&ShmOCPP16Data->Cost.RunningCost[idx], 0x00, sizeof(struct StrcutRunningCost));
  9177. ShmOCPP16Data->Cost.RunningCost[idx].txId = json_object_get_int(json_object_object_get(data, "txId"));
  9178. if(json_object_object_get(data, "description") != NULL)
  9179. {
  9180. // California pricing V1.0
  9181. DEBUG_INFO("California pricing V1.0\n");
  9182. DEBUG_INFO("description: %s\n", json_object_get_string(json_object_object_get(data, "description")));
  9183. sprintf((char*)ShmOCPP16Data->Cost.RunningCost[idx].description, "%s", json_object_get_string(json_object_object_get(data, "description")));
  9184. }
  9185. else
  9186. {
  9187. // California pricing V1.1
  9188. DEBUG_INFO("California pricing V1.1\n");
  9189. if(json_object_object_get(data, "timestamp") != NULL)
  9190. {
  9191. DEBUG_INFO("timestamp: %s\n", json_object_get_string(json_object_object_get(data, "timestamp")));
  9192. sprintf((char*)ShmOCPP16Data->Cost.RunningCost[idx].timestamp, "%s", json_object_get_string(json_object_object_get(data, "timestamp")));
  9193. }
  9194. if(json_object_object_get(data, "meterValue") != NULL)
  9195. {
  9196. DEBUG_INFO("meterValue: %d\n", json_object_get_int(json_object_object_get(data, "meterValue")));
  9197. ShmOCPP16Data->Cost.RunningCost[idx].meterValue = json_object_get_int(json_object_object_get(data, "meterValue"));
  9198. }
  9199. if(json_object_object_get(data, "cost") != NULL)
  9200. {
  9201. DEBUG_INFO("cost: %f\n", json_object_get_double(json_object_object_get(data, "cost")));
  9202. ShmOCPP16Data->Cost.RunningCost[idx].cost = json_object_get_double(json_object_object_get(data, "cost"));
  9203. }
  9204. if(json_object_object_get(data, "state") != NULL)
  9205. {
  9206. DEBUG_INFO("state: %s\n", json_object_get_string(json_object_object_get(data, "state")));
  9207. sprintf((char*)ShmOCPP16Data->Cost.RunningCost[idx].state, "%s", json_object_get_string(json_object_object_get(data, "state")));
  9208. }
  9209. if(json_object_object_get(data, "chargingPrice") != NULL)
  9210. {
  9211. if(json_object_object_get(json_object_object_get(data, "chargingPrice"), "kWhPrice") != NULL)
  9212. {
  9213. DEBUG_INFO("chargingPrice-kWhPrice: %f\n", json_object_get_double(json_object_object_get(json_object_object_get(data, "chargingPrice"), "kWhPrice")));
  9214. ShmOCPP16Data->Cost.RunningCost[idx].chargingPrice.kWhPrice = json_object_get_double(json_object_object_get(json_object_object_get(data, "chargingPrice"), "kWhPrice"));
  9215. }
  9216. if(json_object_object_get(json_object_object_get(data, "chargingPrice"), "hourPrice") != NULL)
  9217. {
  9218. DEBUG_INFO("chargingPrice-hourPrice: %f\n", json_object_get_double(json_object_object_get(json_object_object_get(data, "chargingPrice"), "hourPrice")));
  9219. ShmOCPP16Data->Cost.RunningCost[idx].chargingPrice.hourPrice = json_object_get_double(json_object_object_get(json_object_object_get(data, "chargingPrice"), "hourPrice"));
  9220. }
  9221. if(json_object_object_get(json_object_object_get(data, "chargingPrice"), "flatFee") != NULL)
  9222. {
  9223. DEBUG_INFO("chargingPrice-flatFee: %f\n", json_object_get_double(json_object_object_get(json_object_object_get(data, "chargingPrice"), "flatFee")));
  9224. ShmOCPP16Data->Cost.RunningCost[idx].chargingPrice.flatFee = json_object_get_double(json_object_object_get(json_object_object_get(data, "chargingPrice"), "flatFee"));
  9225. }
  9226. }
  9227. if(json_object_object_get(data, "idlePrice") != NULL)
  9228. {
  9229. if(json_object_object_get(json_object_object_get(data, "idlePrice"), "graceMinutes") != NULL)
  9230. {
  9231. DEBUG_INFO("idlePrice-graceMinutes: %d\n", json_object_get_int(json_object_object_get(json_object_object_get(data, "idlePrice"), "graceMinutes")));
  9232. ShmOCPP16Data->Cost.RunningCost[idx].idlePrice.graceMinutes = json_object_get_int(json_object_object_get(json_object_object_get(data, "idlePrice"), "graceMinutes"));
  9233. }
  9234. if(json_object_object_get(json_object_object_get(data, "idlePrice"), "hourPrice") != NULL)
  9235. {
  9236. DEBUG_INFO("idlePrice-hourPrice: %f\n", json_object_get_double(json_object_object_get(json_object_object_get(data, "idlePrice"), "hourPrice")));
  9237. ShmOCPP16Data->Cost.RunningCost[idx].idlePrice.hourPrice = json_object_get_double(json_object_object_get(json_object_object_get(data, "idlePrice"), "hourPrice"));
  9238. }
  9239. }
  9240. if(json_object_object_get(data, "nextPeriod") != NULL)
  9241. {
  9242. if(json_object_object_get(json_object_object_get(data, "nextPeriod"), "atTime") != NULL)
  9243. {
  9244. DEBUG_INFO("nextPeriod-atTime: %s\n", json_object_get_string(json_object_object_get(json_object_object_get(data, "nextPeriod"), "atTime")));
  9245. sprintf((char*)ShmOCPP16Data->Cost.RunningCost[idx].nextPeriod.atTime, "%s", json_object_get_string(json_object_object_get(json_object_object_get(data, "nextPeriod"), "atTime")));
  9246. }
  9247. if(json_object_object_get(json_object_object_get(data, "nextPeriod"), "chargingPrice") != NULL)
  9248. {
  9249. if(json_object_object_get(json_object_object_get(json_object_object_get(data, "nextPeriod"), "chargingPrice"), "kWhPrice") != NULL)
  9250. {
  9251. 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")));
  9252. 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"));
  9253. }
  9254. if(json_object_object_get(json_object_object_get(json_object_object_get(data, "nextPeriod"), "chargingPrice"), "hourPrice") != NULL)
  9255. {
  9256. 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")));
  9257. 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"));
  9258. }
  9259. if(json_object_object_get(json_object_object_get(json_object_object_get(data, "nextPeriod"), "chargingPrice"), "flatFee") != NULL)
  9260. {
  9261. 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")));
  9262. 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"));
  9263. }
  9264. }
  9265. if(json_object_object_get(json_object_object_get(data, "nextPeriod"), "idlePrice") != NULL)
  9266. {
  9267. if(json_object_object_get(json_object_object_get(json_object_object_get(data, "nextPeriod"), "idlePrice"), "graceMinutes") != NULL)
  9268. {
  9269. 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")));
  9270. 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"));
  9271. }
  9272. if(json_object_object_get(json_object_object_get(json_object_object_get(data, "nextPeriod"), "idlePrice"), "hourPrice") != NULL)
  9273. {
  9274. 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")));
  9275. 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"));
  9276. }
  9277. }
  9278. }
  9279. if(json_object_object_get(data, "triggerMeterValue") != NULL)
  9280. {
  9281. if(json_object_object_get(json_object_object_get(data, "triggerMeterValue"), "atTime") != NULL)
  9282. {
  9283. DEBUG_INFO("triggerMeterValue-atTime: %s\n", json_object_get_string(json_object_object_get(json_object_object_get(data, "triggerMeterValue"), "atTime")));
  9284. sprintf((char*)ShmOCPP16Data->Cost.RunningCost[idx].triggerMeterValue.atTime, "%s", json_object_get_string(json_object_object_get(json_object_object_get(data, "triggerMeterValue"), "atTime")));
  9285. }
  9286. if(json_object_object_get(json_object_object_get(data, "triggerMeterValue"), "atEnergykWh") != NULL)
  9287. {
  9288. DEBUG_INFO("triggerMeterValue-atEnergykWh: %f\n", json_object_get_double(json_object_object_get(json_object_object_get(data, "triggerMeterValue"), "atEnergykWh")));
  9289. ShmOCPP16Data->Cost.RunningCost[idx].triggerMeterValue.atEnergykWh = json_object_get_double(json_object_object_get(json_object_object_get(data, "triggerMeterValue"), "atEnergykWh"));
  9290. }
  9291. if(json_object_object_get(json_object_object_get(data, "triggerMeterValue"), "atPowerkW") != NULL)
  9292. {
  9293. DEBUG_INFO("triggerMeterValue-atPowerkW: %f\n", json_object_get_double(json_object_object_get(json_object_object_get(data, "triggerMeterValue"), "atPowerkW")));
  9294. ShmOCPP16Data->Cost.RunningCost[idx].triggerMeterValue.atPowerkW = json_object_get_double(json_object_object_get(json_object_object_get(data, "triggerMeterValue"), "atPowerkW"));
  9295. }
  9296. }
  9297. }
  9298. }
  9299. }
  9300. }
  9301. json_object_object_add(response, "status", json_object_new_string("Accepted"));
  9302. }
  9303. else
  9304. {
  9305. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  9306. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  9307. }
  9308. json_object_put(data);
  9309. sprintf(message,"[%d,\"%s\",%s]",MESSAGE_TYPE_CALLRESULT, uuid, json_object_to_json_string_ext(response, JSON_C_TO_STRING_PLAIN));
  9310. json_object_put(response);
  9311. }
  9312. else if(strstr(tempmessageId, "FinalCost") != NULL)
  9313. {
  9314. json_object *data;
  9315. data = json_tokener_parse(tempdata);
  9316. if(!is_error(data))
  9317. {
  9318. if(json_object_object_get(data, "txId") != NULL)
  9319. {
  9320. DEBUG_INFO("transaction id: %d\n", json_object_get_int(json_object_object_get(data, "txId")));
  9321. for(int idx = 0;idx<gunTotalNumber;idx++)
  9322. {
  9323. if(ShmOCPP16Data->StartTransaction[idx].ResponseTransactionId == json_object_get_int(json_object_object_get(data, "txId")))
  9324. {
  9325. memset(&ShmOCPP16Data->Cost.FinalCost[idx], 0x00, sizeof(struct StrcutFinalCost));
  9326. ShmOCPP16Data->Cost.FinalCost[idx].txId = json_object_get_int(json_object_object_get(data, "txId"));
  9327. if(json_object_object_get(data, "description") != NULL)
  9328. {
  9329. DEBUG_INFO("description: %s\n", json_object_get_string(json_object_object_get(data, "description")));
  9330. sprintf((char*)ShmOCPP16Data->Cost.FinalCost[idx].description, "%s", json_object_get_string(json_object_object_get(data, "description")));
  9331. }
  9332. }
  9333. }
  9334. }
  9335. json_object_object_add(response, "status", json_object_new_string("Accepted"));
  9336. }
  9337. else
  9338. {
  9339. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  9340. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  9341. }
  9342. json_object_put(data);
  9343. sprintf(message,"[%d,\"%s\",%s]",MESSAGE_TYPE_CALLRESULT, uuid, json_object_to_json_string_ext(response, JSON_C_TO_STRING_PLAIN));
  9344. json_object_put(response);
  9345. }
  9346. else if(strstr(tempmessageId, "ID_ConfigQR") != NULL)
  9347. {
  9348. json_object *data;
  9349. data = json_tokener_parse(tempdata);
  9350. if(!is_error(data))
  9351. {
  9352. json_object_object_add(response, "status", json_object_new_string("Accepted"));
  9353. if(json_object_object_get(data, "Content_Type") != NULL)
  9354. {
  9355. 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))
  9356. {
  9357. ShmSysConfigAndInfo->SysConfig.QRCodeMadeMode = json_object_get_int(json_object_object_get(data, "Content_Type"));
  9358. if(json_object_object_get(data, "Customization_Conent") != NULL)
  9359. {
  9360. sprintf((char*)ShmSysConfigAndInfo->SysConfig.QRCodeContent, "%s", json_object_get_string(json_object_object_get(data, "Customization_Conent")));
  9361. }
  9362. }
  9363. else
  9364. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  9365. }
  9366. StoreUsrConfigData(&ShmSysConfigAndInfo->SysConfig);
  9367. }
  9368. else
  9369. {
  9370. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  9371. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  9372. }
  9373. json_object_put(data);
  9374. sprintf(message,"[%d,\"%s\",%s]",MESSAGE_TYPE_CALLRESULT, uuid, json_object_to_json_string_ext(response, JSON_C_TO_STRING_PLAIN));
  9375. json_object_put(response);
  9376. }
  9377. else if(strstr(tempmessageId, "ID_DsiplayLcdPage") != NULL)
  9378. {
  9379. json_object *data;
  9380. data = json_tokener_parse(tempdata);
  9381. if(!is_error(data))
  9382. {
  9383. json_object_object_add(response, "status", json_object_new_string("Accepted"));
  9384. if(json_object_object_get(data, "Page_Index") != NULL)
  9385. {
  9386. ShmSysConfigAndInfo->SysConfig.LcdOveride.page_index = json_object_get_int(json_object_object_get(data, "Page_Index"));
  9387. }
  9388. if(json_object_object_get(data, "Duration") != NULL)
  9389. {
  9390. ShmSysConfigAndInfo->SysConfig.LcdOveride.duration = json_object_get_int(json_object_object_get(data, "Duration"));
  9391. }
  9392. ShmSysConfigAndInfo->SysConfig.LcdOveride.isOverideReq = 1;
  9393. }
  9394. else
  9395. {
  9396. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  9397. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  9398. }
  9399. json_object_put(data);
  9400. sprintf(message,"[%d,\"%s\",%s]",MESSAGE_TYPE_CALLRESULT, uuid, json_object_to_json_string_ext(response, JSON_C_TO_STRING_PLAIN));
  9401. json_object_put(response);
  9402. }
  9403. else if(strstr(tempmessageId, "ID_CpConfiguration") != NULL)
  9404. {
  9405. json_object *data;
  9406. data = json_tokener_parse(tempdata);
  9407. if(!is_error(data))
  9408. {
  9409. json_object_object_add(response, "status", json_object_new_string("Accepted"));
  9410. if(json_object_object_get(data, "MaxChargingCurrent") != NULL)
  9411. {
  9412. if(json_object_get_int(json_object_object_get(data, "MaxChargingCurrent")) >= 0)
  9413. ShmSysConfigAndInfo->SysConfig.MaxChargingCurrent = json_object_get_int(json_object_object_get(data, "MaxChargingCurrent"));
  9414. else
  9415. {
  9416. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  9417. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  9418. }
  9419. }
  9420. if(json_object_object_get(data, "MaxChargingDuration") != NULL)
  9421. {
  9422. if(json_object_get_int(json_object_object_get(data, "MaxChargingDuration")) >= 0)
  9423. ShmSysConfigAndInfo->SysConfig.MaxChargingDuration = json_object_get_int(json_object_object_get(data, "MaxChargingDuration"));
  9424. else
  9425. {
  9426. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  9427. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  9428. }
  9429. }
  9430. if(json_object_object_get(data, "MaxChargingEnergy") != NULL)
  9431. {
  9432. if(json_object_get_int(json_object_object_get(data, "MaxChargingEnergy")) >= 0)
  9433. ShmSysConfigAndInfo->SysConfig.MaxChargingEnergy = json_object_get_int(json_object_object_get(data, "MaxChargingEnergy"));
  9434. else
  9435. {
  9436. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  9437. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  9438. }
  9439. }
  9440. if(json_object_object_get(data, "MaxChargingPower") != NULL)
  9441. {
  9442. if(json_object_get_int(json_object_object_get(data, "MaxChargingPower")) >= 0)
  9443. ShmSysConfigAndInfo->SysConfig.MaxChargingPower = json_object_get_int(json_object_object_get(data, "MaxChargingPower"));
  9444. else
  9445. {
  9446. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  9447. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  9448. }
  9449. }
  9450. if(json_object_object_get(data, "OfflineMaxChargeEnergy") != NULL)
  9451. {
  9452. if(json_object_get_int(json_object_object_get(data, "OfflineMaxChargeEnergy")) >= 0)
  9453. ShmSysConfigAndInfo->SysConfig.OfflineMaxChargeEnergy = json_object_get_int(json_object_object_get(data, "OfflineMaxChargeEnergy"));
  9454. else
  9455. {
  9456. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  9457. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  9458. }
  9459. }
  9460. if(json_object_object_get(data, "OfflinePolicy") != NULL)
  9461. {
  9462. if((json_object_get_int(json_object_object_get(data, "OfflinePolicy")) == 0) ||
  9463. (json_object_get_int(json_object_object_get(data, "OfflinePolicy")) == 2) ||
  9464. (json_object_get_int(json_object_object_get(data, "OfflinePolicy")) == 3))
  9465. ShmSysConfigAndInfo->SysConfig.OfflinePolicy = json_object_get_int(json_object_object_get(data, "OfflinePolicy"));
  9466. else
  9467. {
  9468. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  9469. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  9470. }
  9471. }
  9472. if(json_object_object_get(data, "isAuthentication") != NULL)
  9473. {
  9474. switch(json_object_get_int(json_object_object_get(data, "isAuthentication")))
  9475. {
  9476. case 0:
  9477. case 1:
  9478. ShmSysConfigAndInfo->SysConfig.AuthorisationMode = json_object_get_int(json_object_object_get(data, "isAuthentication"))^1;
  9479. break;
  9480. default:
  9481. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  9482. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  9483. break;
  9484. }
  9485. }
  9486. if(strstr(json_object_get_string(json_object_object_get(response, "status")), "Accepted") != NULL)
  9487. StoreUsrConfigData(&ShmSysConfigAndInfo->SysConfig);
  9488. }
  9489. else
  9490. {
  9491. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  9492. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  9493. }
  9494. json_object_put(data);
  9495. sprintf(message,"[%d,\"%s\",%s]",MESSAGE_TYPE_CALLRESULT, uuid, json_object_to_json_string_ext(response, JSON_C_TO_STRING_PLAIN));
  9496. json_object_put(response);
  9497. }
  9498. else if(strstr(tempmessageId, "ID_TxEnergy") != NULL)
  9499. {
  9500. json_object *data;
  9501. data = json_tokener_parse(tempdata);
  9502. if(!is_error(data))
  9503. {
  9504. if((json_object_object_get(data, "ConnectorId") != NULL) && (json_object_object_get(data, "txId") != NULL))
  9505. {
  9506. if(OCPP_getPeriodEnergyToDataTransfer(json_object_get_int(json_object_object_get(data, "txId"))) == PASS)
  9507. {
  9508. json_object_object_add(response, "status", json_object_new_string("Accepted"));
  9509. json_object_object_add(response, "data", json_object_new_string((char*)ShmOCPP16Data->DataTransfer[0].ResponseData));
  9510. }
  9511. else
  9512. {
  9513. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  9514. json_object_object_add(response, "data", json_object_new_string("Present charged energy data can not get."));
  9515. }
  9516. }
  9517. else
  9518. {
  9519. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  9520. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  9521. }
  9522. }
  9523. else
  9524. {
  9525. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  9526. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  9527. }
  9528. sprintf(message,"[%d,\"%s\",%s]",MESSAGE_TYPE_CALLRESULT, uuid, json_object_to_json_string_ext(response, JSON_C_TO_STRING_PLAIN));
  9529. json_object_put(response);
  9530. }
  9531. else if(strstr(tempmessageId, "refund_status") != NULL)
  9532. {
  9533. json_object *data;
  9534. data = json_tokener_parse(tempdata);
  9535. if(!is_error(data))
  9536. {
  9537. json_object_object_add(response, "status", json_object_new_string("Accepted"));
  9538. if(json_object_object_get(data, "status") != NULL)
  9539. {
  9540. //DEBUG_INFO("status: %s\n", json_object_get_string(json_object_object_get(data, "status")));
  9541. if(strcmp(json_object_get_string(json_object_object_get(data, "status")), "T") || strcmp(json_object_get_string(json_object_object_get(data, "status")), "F"))
  9542. {
  9543. sprintf((char *)ShmOCPP16Data->YesCustomData.RefundStatus.status, "%s", json_object_get_string(json_object_object_get(data, "status")));
  9544. }
  9545. else
  9546. {
  9547. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  9548. json_object_object_add(response, "data", json_object_new_string("status value is invalid."));
  9549. }
  9550. }
  9551. else
  9552. {
  9553. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  9554. json_object_object_add(response, "data", json_object_new_string("status data can not get."));
  9555. }
  9556. if(json_object_object_get(data, "chargeDate") != NULL)
  9557. {
  9558. sprintf((char *)ShmOCPP16Data->YesCustomData.RefundStatus.chargeDate, "%s", json_object_get_string(json_object_object_get(data,"chargeDate")));
  9559. }
  9560. else
  9561. {
  9562. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  9563. json_object_object_add(response, "data", json_object_new_string("chargeDate data can not get."));
  9564. }
  9565. if(json_object_object_get(data, "holdAmt") != NULL)
  9566. {
  9567. if(json_object_get_int(json_object_object_get(data, "holdAmt")) >= 0)
  9568. ShmOCPP16Data->YesCustomData.RefundStatus.holdAmt = json_object_get_int(json_object_object_get(data, "holdAmt"));
  9569. else
  9570. {
  9571. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  9572. json_object_object_add(response, "data", json_object_new_string("holdAmt data is invalid."));
  9573. }
  9574. }
  9575. else
  9576. {
  9577. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  9578. json_object_object_add(response, "data", json_object_new_string("holdAmt data can not get."));
  9579. }
  9580. if(json_object_object_get(data, "chargeAmt") != NULL)
  9581. {
  9582. if(json_object_get_int(json_object_object_get(data, "chargeAmt")) >= 0)
  9583. ShmOCPP16Data->YesCustomData.RefundStatus.chargeAmt = json_object_get_int(json_object_object_get(data, "chargeAmt"));
  9584. else
  9585. {
  9586. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  9587. json_object_object_add(response, "data", json_object_new_string("chargeAmt data is invalid."));
  9588. }
  9589. }
  9590. else
  9591. {
  9592. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  9593. json_object_object_add(response, "data", json_object_new_string("chargeAmt data can not get."));
  9594. }
  9595. if(json_object_object_get(data, "refundAmt") != NULL)
  9596. {
  9597. if(json_object_get_int(json_object_object_get(data, "refundAmt")) >= 0)
  9598. ShmOCPP16Data->YesCustomData.RefundStatus.refundAmt = json_object_get_int(json_object_object_get(data, "refundAmt"));
  9599. else
  9600. {
  9601. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  9602. json_object_object_add(response, "data", json_object_new_string("refundAmt data is invalid."));
  9603. }
  9604. }
  9605. else
  9606. {
  9607. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  9608. json_object_object_add(response, "data", json_object_new_string("refundAmt data can not get."));
  9609. }
  9610. if(json_object_object_get(data, "page") != NULL)
  9611. {
  9612. if(json_object_get_int(json_object_object_get(data, "page")) >= 0 && json_object_get_int(json_object_object_get(data, "page")) <= 3)
  9613. ShmOCPP16Data->YesCustomData.RefundStatus.page = json_object_get_int(json_object_object_get(data, "page"));
  9614. else
  9615. {
  9616. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  9617. json_object_object_add(response, "data", json_object_new_string("page data is invalid."));
  9618. }
  9619. }
  9620. else
  9621. {
  9622. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  9623. json_object_object_add(response, "data", json_object_new_string("page data can not get."));
  9624. }
  9625. if(strcmp(json_object_get_string(json_object_object_get(response,"status")),"Accepted")==0)
  9626. {
  9627. ShmOCPP16Data->YesCustomData.RefundStatusReq = 1;
  9628. DEBUG_INFO("<<< RefundStatus:{status:%s, chargeDate:%s, holdAmt:%d, chargeAmt:%d, refundAmt:%d, page:%d}\n",
  9629. ShmOCPP16Data->YesCustomData.RefundStatus.status,
  9630. ShmOCPP16Data->YesCustomData.RefundStatus.chargeDate,
  9631. ShmOCPP16Data->YesCustomData.RefundStatus.holdAmt,
  9632. ShmOCPP16Data->YesCustomData.RefundStatus.chargeAmt,
  9633. ShmOCPP16Data->YesCustomData.RefundStatus.refundAmt,
  9634. ShmOCPP16Data->YesCustomData.RefundStatus.page);
  9635. }
  9636. }
  9637. else
  9638. {
  9639. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  9640. json_object_object_add(response, "data", json_object_new_string("refund_status content got something wrong."));
  9641. }
  9642. sprintf(message,"[%d,\"%s\",%s]",MESSAGE_TYPE_CALLRESULT, uuid, json_object_to_json_string_ext(response, JSON_C_TO_STRING_PLAIN));
  9643. json_object_put(response);
  9644. }
  9645. else if(strstr(tempmessageId, "deduct_status") != NULL)
  9646. {
  9647. json_object *data;
  9648. data = json_tokener_parse(tempdata);
  9649. if(!is_error(data))
  9650. {
  9651. json_object_object_add(response, "status", json_object_new_string("Accepted"));
  9652. if(json_object_object_get(data, "status") != NULL)
  9653. {
  9654. //DEBUG_INFO("status: %s\n", json_object_get_string(json_object_object_get(data, "status")));
  9655. if((strcmp(json_object_get_string(json_object_object_get(data, "status")), "T")==0) || (strcmp(json_object_get_string(json_object_object_get(data, "status")), "F")==0))
  9656. {
  9657. sprintf((char*)ShmOCPP16Data->YesCustomData.DeductStatus.status, "%s", json_object_get_string(json_object_object_get(data, "status")));
  9658. }
  9659. else
  9660. {
  9661. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  9662. json_object_object_add(response, "data", json_object_new_string("status value is invalid."));
  9663. }
  9664. }
  9665. else
  9666. {
  9667. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  9668. json_object_object_add(response, "data", json_object_new_string("status data can not get."));
  9669. }
  9670. if(json_object_object_get(data, "autoLoadAmt") != NULL)
  9671. {
  9672. if(json_object_get_int(json_object_object_get(data, "autoLoadAmt")) >= 0)
  9673. ShmOCPP16Data->YesCustomData.DeductStatus.autoLoadAmt = json_object_get_int(json_object_object_get(data, "autoLoadAmt"));
  9674. else
  9675. {
  9676. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  9677. json_object_object_add(response, "data", json_object_new_string("autoLoadAmt is invalid."));
  9678. }
  9679. }
  9680. else
  9681. {
  9682. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  9683. json_object_object_add(response, "data", json_object_new_string("autoLoadAmt data can not get."));
  9684. }
  9685. if(json_object_object_get(data, "beforeAmt") != NULL)
  9686. {
  9687. if(json_object_get_int(json_object_object_get(data, "beforeAmt")) >= 0)
  9688. ShmOCPP16Data->YesCustomData.DeductStatus.beforeAmt = json_object_get_int(json_object_object_get(data, "beforeAmt"));
  9689. else
  9690. {
  9691. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  9692. json_object_object_add(response, "data", json_object_new_string("beforeAmt data is invalid."));
  9693. }
  9694. }
  9695. else
  9696. {
  9697. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  9698. json_object_object_add(response, "data", json_object_new_string("beforeAmt data can not get."));
  9699. }
  9700. if(json_object_object_get(data, "chargeAmt") != NULL)
  9701. {
  9702. if(json_object_get_int(json_object_object_get(data, "chargeAmt")) >= 0)
  9703. ShmOCPP16Data->YesCustomData.DeductStatus.chargeAmt = json_object_get_int(json_object_object_get(data, "chargeAmt"));
  9704. else
  9705. {
  9706. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  9707. json_object_object_add(response, "data", json_object_new_string("chargeAmt data is invalid."));
  9708. }
  9709. }
  9710. else
  9711. {
  9712. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  9713. json_object_object_add(response, "data", json_object_new_string("chargeAmt data can not get."));
  9714. }
  9715. if(json_object_object_get(data, "afterAmt") != NULL)
  9716. {
  9717. if(json_object_get_int(json_object_object_get(data, "afterAmt")) >= 0)
  9718. ShmOCPP16Data->YesCustomData.DeductStatus.afterAmt = json_object_get_int(json_object_object_get(data, "afterAmt"));
  9719. else
  9720. {
  9721. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  9722. json_object_object_add(response, "data", json_object_new_string("afterAmt data is invalid."));
  9723. }
  9724. }
  9725. else
  9726. {
  9727. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  9728. json_object_object_add(response, "data", json_object_new_string("afterAmt data can not get."));
  9729. }
  9730. if(json_object_object_get(data, "page") != NULL)
  9731. {
  9732. if(json_object_get_int(json_object_object_get(data, "page")) >= 0)
  9733. ShmOCPP16Data->YesCustomData.DeductStatus.page = json_object_get_int(json_object_object_get(data, "page"));
  9734. else
  9735. {
  9736. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  9737. json_object_object_add(response, "data", json_object_new_string("page data is invalid."));
  9738. }
  9739. }
  9740. else
  9741. {
  9742. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  9743. json_object_object_add(response, "data", json_object_new_string("page data can not get."));
  9744. }
  9745. if(strcmp(json_object_get_string(json_object_object_get(response,"status")),"Accepted")==0)
  9746. {
  9747. ShmOCPP16Data->YesCustomData.DeductStatusReq = 1;
  9748. DEBUG_INFO("<<< deduct_status:{status:%s, autoLoadAmt:%d, beforeAmt:%d, chargeAmt:%d, afterAmt:%d, page:%d}\n",
  9749. ShmOCPP16Data->YesCustomData.DeductStatus.status,
  9750. ShmOCPP16Data->YesCustomData.DeductStatus.autoLoadAmt,
  9751. ShmOCPP16Data->YesCustomData.DeductStatus.beforeAmt,
  9752. ShmOCPP16Data->YesCustomData.DeductStatus.chargeAmt,
  9753. ShmOCPP16Data->YesCustomData.DeductStatus.afterAmt,
  9754. ShmOCPP16Data->YesCustomData.DeductStatus.page);
  9755. }
  9756. }
  9757. else
  9758. {
  9759. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  9760. json_object_object_add(response, "data", json_object_new_string("deduct_status content got something wrong."));
  9761. }
  9762. sprintf(message,"[%d,\"%s\",%s]",MESSAGE_TYPE_CALLRESULT, uuid, json_object_to_json_string_ext(response, JSON_C_TO_STRING_PLAIN));
  9763. json_object_put(response);
  9764. }
  9765. else if(strstr(tempmessageId, "ID_Station_Location") != NULL)
  9766. {
  9767. json_object *data;
  9768. data = json_tokener_parse(tempdata);
  9769. if(!is_error(data))
  9770. {
  9771. json_object_object_add(response, "status", json_object_new_string("Accepted"));
  9772. if(json_object_object_get(data, "stationName") != NULL)
  9773. {
  9774. sprintf((char *)ShmOCPP16Data->YesCustomData.ChargerInfo.station_name, "%s", json_object_get_string(json_object_object_get(data,"stationName")));
  9775. }
  9776. else
  9777. {
  9778. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  9779. json_object_object_add(response, "data", json_object_new_string("station_name data can not get."));
  9780. }
  9781. /*if(json_object_object_get(data, "station_id") != NULL)
  9782. {
  9783. sprintf((char *)ShmOCPP16Data->YesCustomData.ChargerInfo.station_id, "%s", json_object_get_string(json_object_object_get(data,"station_id")));
  9784. }
  9785. else
  9786. {
  9787. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  9788. json_object_object_add(response, "data", json_object_new_string("station_id data can not get."));
  9789. }
  9790. if(json_object_object_get(data, "charge_id") != NULL)
  9791. {
  9792. for(int idx=0;idx<json_object_array_length(json_object_object_get(data, "charge_id"));idx++)
  9793. {
  9794. sprintf((char*)ShmOCPP16Data->YesCustomData.ChargerInfo.charge_id[idx], "%s", json_object_get_string(json_object_array_get_idx(json_object_object_get(data, "charge_id"), idx)));
  9795. }
  9796. }
  9797. else
  9798. {
  9799. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  9800. json_object_object_add(response, "data", json_object_new_string("charge_id data can not get."));
  9801. }*/
  9802. if(strcmp(json_object_get_string(json_object_object_get(response,"status")),"Accepted")==0)
  9803. {
  9804. ShmOCPP16Data->YesCustomData.ChargerInfoReq = 1;
  9805. DEBUG_INFO("<<< ID_Station_Location:{station_name:%s}\n",
  9806. ShmOCPP16Data->YesCustomData.ChargerInfo.station_name);
  9807. }
  9808. }
  9809. else
  9810. {
  9811. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  9812. json_object_object_add(response, "data", json_object_new_string("charger_info content got something wrong."));
  9813. }
  9814. sprintf(message,"[%d,\"%s\",%s]",MESSAGE_TYPE_CALLRESULT, uuid, json_object_to_json_string_ext(response, JSON_C_TO_STRING_PLAIN));
  9815. json_object_put(response);
  9816. }
  9817. else if(strstr(tempmessageId, "ID_Weather_Info") != NULL)
  9818. {
  9819. json_object *data;
  9820. data = json_tokener_parse(tempdata);
  9821. if(!is_error(data))
  9822. {
  9823. json_object_object_add(response, "status", json_object_new_string("Accepted"));
  9824. if(json_object_object_get(data, "weatherId") != NULL)
  9825. {
  9826. ShmOCPP16Data->YesCustomData.WeatherInfo.weatherId = json_object_get_int(json_object_object_get(data, "weatherId"));
  9827. }
  9828. else
  9829. {
  9830. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  9831. json_object_object_add(response, "data", json_object_new_string("weather data can not get."));
  9832. }
  9833. if(json_object_object_get(data, "Temperature") != NULL)
  9834. {
  9835. ShmOCPP16Data->YesCustomData.WeatherInfo.temperature = json_object_get_double(json_object_object_get(data,"Temperature"));
  9836. }
  9837. else
  9838. {
  9839. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  9840. json_object_object_add(response, "data", json_object_new_string("temperature data can not get."));
  9841. }
  9842. if(strcmp(json_object_get_string(json_object_object_get(response,"status")),"Accepted")==0)
  9843. {
  9844. ShmOCPP16Data->YesCustomData.WeatherInfoReq = 1;
  9845. DEBUG_INFO("<<< ID_Weather_Info:{weather:%d, temperature:%.1f}\n",
  9846. ShmOCPP16Data->YesCustomData.WeatherInfo.weatherId,
  9847. ShmOCPP16Data->YesCustomData.WeatherInfo.temperature
  9848. );
  9849. }
  9850. }
  9851. else
  9852. {
  9853. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  9854. json_object_object_add(response, "data", json_object_new_string("weather_info content got something wrong."));
  9855. }
  9856. sprintf(message,"[%d,\"%s\",%s]",MESSAGE_TYPE_CALLRESULT, uuid, json_object_to_json_string_ext(response, JSON_C_TO_STRING_PLAIN));
  9857. json_object_put(response);
  9858. }
  9859. else if(strstr(tempmessageId, "set_qrcode") != NULL)
  9860. {
  9861. json_object *data;
  9862. data = json_tokener_parse(tempdata);
  9863. if(!is_error(data))
  9864. {
  9865. json_object_object_add(response, "status", json_object_new_string("Accepted"));
  9866. if(json_object_object_get(data, "connectorId") != NULL)
  9867. {
  9868. if((json_object_get_int(json_object_object_get(data, "connectorId")) > 0) && (json_object_get_int(json_object_object_get(data, "connectorId")) <= gunTotalNumber))
  9869. {
  9870. int idx = json_object_get_int(json_object_object_get(data, "connectorId"))-1;
  9871. if(json_object_object_get(data, "qrcode") != NULL)
  9872. {
  9873. sprintf((char *)ShmOCPP16Data->YesCustomData.QrCode[idx], "%s", json_object_get_string(json_object_object_get(data,"qrcode")));
  9874. ShmOCPP16Data->YesCustomData.SetQrCodeReq = 1;
  9875. DEBUG_INFO("<<< set_qrcode:{connectorId:%d, qrcode:%s}\n",
  9876. idx,
  9877. ShmOCPP16Data->YesCustomData.QrCode[idx]
  9878. );
  9879. }
  9880. else
  9881. {
  9882. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  9883. json_object_object_add(response, "data", json_object_new_string("qrcode data can not get."));
  9884. }
  9885. }
  9886. else
  9887. {
  9888. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  9889. json_object_object_add(response, "data", json_object_new_string("connectorId data is invalid."));
  9890. }
  9891. }
  9892. else
  9893. {
  9894. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  9895. json_object_object_add(response, "data", json_object_new_string("connectorId data can not get."));
  9896. }
  9897. }
  9898. else
  9899. {
  9900. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  9901. json_object_object_add(response, "data", json_object_new_string("set_qrcode content got something wrong."));
  9902. }
  9903. sprintf(message,"[%d,\"%s\",%s]",MESSAGE_TYPE_CALLRESULT, uuid, json_object_to_json_string_ext(response, JSON_C_TO_STRING_PLAIN));
  9904. json_object_put(response);
  9905. }
  9906. else
  9907. {
  9908. // Can not find valid message id
  9909. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\",\"data\":\"vendorId-%s messageId-%s data-%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, "UnknownMessageId", tempvendorId, tempmessageId, tempdata);
  9910. }
  9911. }
  9912. else
  9913. {
  9914. // Payload is null
  9915. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\",\"data\":\"{}\"}]",MESSAGE_TYPE_CALLRESULT, uuid, "UnknownMessageId");
  9916. }
  9917. LWS_Send(message);
  9918. return result;
  9919. }
  9920. int handleGetCompositeScheduleRequest(char *uuid, char *payload)
  9921. {
  9922. mtrace();
  9923. int result = FAIL;
  9924. int connectorIdInt, durationInt;
  9925. char chargingRateUnitStr[4]={0};
  9926. char comfirmstr[20];
  9927. int confirmPeriods = 0;
  9928. DEBUG_INFO("handleGetCompositeScheduleRequest...\n");
  9929. json_object *GetCompositeSchedule;
  9930. GetCompositeSchedule = json_tokener_parse(payload);
  9931. if(!is_error(GetCompositeSchedule))
  9932. {
  9933. // Required data
  9934. if(json_object_object_get(GetCompositeSchedule, "connectorId") != NULL)
  9935. connectorIdInt = json_object_get_int(json_object_object_get(GetCompositeSchedule, "connectorId"));
  9936. else
  9937. connectorIdInt = -1;
  9938. if(json_object_object_get(GetCompositeSchedule, "duration"))
  9939. durationInt = json_object_get_int(json_object_object_get(GetCompositeSchedule, "duration"));
  9940. else
  9941. durationInt = 86400;
  9942. // Optional data
  9943. if(json_object_object_get(GetCompositeSchedule, "chargingRateUnit") != NULL)
  9944. sprintf((char*)chargingRateUnitStr, "%s", json_object_get_string(json_object_object_get(GetCompositeSchedule, "chargingRateUnit")));
  9945. }
  9946. json_object_put(GetCompositeSchedule);
  9947. memset(ShmOCPP16Data->GetCompositeSchedule, 0, sizeof(struct StructChargingSchedulePeriod)*gunTotalNumber);
  9948. if((connectorIdInt == 0) ||
  9949. ((connectorIdInt > 0) && ((connectorIdInt -1) < gunTotalNumber)))
  9950. {
  9951. int gun_index = (connectorIdInt==0?0:connectorIdInt-1);
  9952. struct StructChargingProfile tmpProfile[1];
  9953. if(strstr(chargingRateUnitStr, "W") != NULL)
  9954. checkCompositeSchedule(connectorIdInt, durationInt, &tmpProfile[0], FALSE);
  9955. else
  9956. checkCompositeSchedule(connectorIdInt, durationInt, &tmpProfile[0], TRUE);
  9957. for(int idx=0;idx<ARRAY_SIZE(ShmOCPP16Data->GetCompositeSchedule[gun_index].ResponseChargingSchedule.ChargingSchedulePeriod);idx++)
  9958. {
  9959. DEBUG_INFO("Smart Period-%02d start: %d\n", idx, tmpProfile[0].ChargingSchedule.ChargingSchedulePeriod[idx].StartPeriod);
  9960. DEBUG_INFO("Smart Period-%02d limit: %f\n", idx, tmpProfile[0].ChargingSchedule.ChargingSchedulePeriod[idx].Limit);
  9961. }
  9962. ShmOCPP16Data->GetCompositeSchedule[gun_index].ResponseConnectorId = connectorIdInt;
  9963. memcpy(&ShmOCPP16Data->GetCompositeSchedule[gun_index].ResponseChargingSchedule, &tmpProfile[0].ChargingSchedule, sizeof(struct StructChargingSchedule));
  9964. memcpy(&ShmOCPP16Data->GetCompositeSchedule[gun_index].ResponseScheduleStart ,&tmpProfile[0].ChargingSchedule.StartSchedule, ARRAY_SIZE(tmpProfile[0].ChargingSchedule.StartSchedule));
  9965. for(int idx=0;idx<ARRAY_SIZE(ShmOCPP16Data->GetCompositeSchedule[gun_index].ResponseChargingSchedule.ChargingSchedulePeriod);idx++)
  9966. {
  9967. DEBUG_INFO("Composite Period-%02d start: %d\n", idx, ShmOCPP16Data->GetCompositeSchedule[gun_index].ResponseChargingSchedule.ChargingSchedulePeriod[idx].StartPeriod);
  9968. DEBUG_INFO("Composite Period-%02d limit: %f\n", idx, ShmOCPP16Data->GetCompositeSchedule[gun_index].ResponseChargingSchedule.ChargingSchedulePeriod[idx].Limit);
  9969. if((ShmOCPP16Data->GetCompositeSchedule[gun_index].ResponseChargingSchedule.ChargingSchedulePeriod[idx].StartPeriod==0) &&
  9970. (ShmOCPP16Data->GetCompositeSchedule[gun_index].ResponseChargingSchedule.ChargingSchedulePeriod[idx].Limit==0) &&
  9971. (idx<(ARRAY_SIZE(ShmOCPP16Data->GetCompositeSchedule[gun_index].ResponseChargingSchedule.ChargingSchedulePeriod)-1)?(ShmOCPP16Data->GetCompositeSchedule[gun_index].ResponseChargingSchedule.ChargingSchedulePeriod[idx+1].StartPeriod==0):TRUE))
  9972. {
  9973. confirmPeriods = idx;
  9974. break;
  9975. }
  9976. }
  9977. if((confirmPeriods == 0) && (tmpProfile[0].ChargingProfileId > 0))
  9978. {
  9979. confirmPeriods += 1;
  9980. }
  9981. sprintf(comfirmstr, "%s", GetCompositeScheduleStatusStr[GetCompositeScheduleStatus_Accepted] );
  9982. }
  9983. else
  9984. {
  9985. sprintf(comfirmstr, "%s", GetCompositeScheduleStatusStr[GetCompositeScheduleStatus_Rejected] );
  9986. }
  9987. sendGetCompositeScheduleConfirmation(uuid, comfirmstr, connectorIdInt, confirmPeriods);
  9988. return result;
  9989. }
  9990. int handleGetConfigurationRequest(char *uuid, char *payload)
  9991. {
  9992. mtrace();
  9993. int result = FAIL;
  9994. int MaxKeySupported = 0;
  9995. int n_keys = 0;
  9996. char requestKey[GetConfigurationMaxKeysNUM][50]={0};
  9997. DEBUG_INFO("handleGetConfigurationRequest...\n");
  9998. json_object *GetConfiguration;
  9999. GetConfiguration = json_tokener_parse(payload);
  10000. if(!is_error(GetConfiguration))
  10001. {
  10002. // Optional data
  10003. if(json_object_object_get(GetConfiguration, "key") != NULL)
  10004. {
  10005. for(int idx=0;idx<json_object_array_length(json_object_object_get(GetConfiguration, "key"));idx++)
  10006. {
  10007. sprintf((char*)requestKey[idx], "%s", json_object_get_string(json_object_array_get_idx(json_object_object_get(GetConfiguration, "key"), idx)));
  10008. n_keys = idx + 1;
  10009. }
  10010. }
  10011. }
  10012. json_object_put(GetConfiguration);
  10013. UnknownKeynum = 0;
  10014. memset( (void *)unknownkey, 0, sizeof(unknownkey));
  10015. MaxKeySupported = GetConfigurationMaxKeysNUM;
  10016. memset(ShmOCPP16Data->GetConfiguration.Key, 0 ,sizeof(struct StructConfigurationKeyItems)*MaxKeySupported);
  10017. memset(ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey, 0, sizeof(struct StructConfigurationKey)*MaxKeySupported);
  10018. if(n_keys != 0)
  10019. {
  10020. for(int i=0;i<n_keys;i++)
  10021. {
  10022. getKeyValue(requestKey[i]);
  10023. }
  10024. }
  10025. else
  10026. {
  10027. DEBUG_INFO("There is no key in Message, get all configuration\n");
  10028. getKeyValue("");
  10029. }
  10030. processUnkownKey();
  10031. sendGetConfigurationConfirmation(uuid);
  10032. return result;
  10033. }
  10034. static char fnamePlusPath[100]={0};
  10035. static char fnamePWithNoPath[60]={0};
  10036. void checkUploadLog(void)
  10037. {
  10038. FILE *fp;
  10039. /* Open the command for reading. */
  10040. fp = popen("find /mnt/ -type f -name \"*.zip\" |xargs ls -t", "r");
  10041. if (fp == NULL) {
  10042. DEBUG_WARN("Failed to run command\n" );
  10043. exit(1);
  10044. }
  10045. int ftppathlen = 0;
  10046. memset(fnamePlusPath, 0, ARRAY_SIZE(fnamePlusPath));
  10047. int i = 0;
  10048. /* Read the output a line at a time - output it. */
  10049. while (fgets(fnamePlusPath, sizeof(fnamePlusPath), fp) != NULL) {
  10050. if(i==0)
  10051. {
  10052. ftppathlen = strlen(fnamePlusPath);
  10053. DEBUG_INFO("%s\n", fnamePlusPath);
  10054. fnamePlusPath[ftppathlen]='\0';
  10055. break;
  10056. }
  10057. i= i+1;
  10058. }
  10059. /* close */
  10060. pclose(fp);
  10061. for(int k=0; k< ARRAY_SIZE(fnamePlusPath); k++)
  10062. {
  10063. if((fnamePlusPath[k]=='\n') || (fnamePlusPath[k]=='\r'))
  10064. {
  10065. fnamePlusPath[k]='\0';
  10066. }
  10067. }
  10068. i=1;
  10069. //char fname[60]={0};
  10070. while(i < ftppathlen)
  10071. {
  10072. int len=ftppathlen-i;
  10073. if(fnamePlusPath[len]== 47) // '/' ascll code: 47
  10074. {
  10075. DEBUG_INFO("compare '/' all right\n");
  10076. break;
  10077. }
  10078. i=i+1;
  10079. }
  10080. memset(fnamePWithNoPath, 0, ARRAY_SIZE(fnamePWithNoPath));
  10081. strncpy(fnamePWithNoPath, fnamePlusPath+(ftppathlen-i+1), i+1);
  10082. fnamePWithNoPath[i+1] = '\0';
  10083. for(int j=0; j< ARRAY_SIZE(fnamePWithNoPath); j++)
  10084. {
  10085. if((fnamePWithNoPath[j]=='\n') || (fnamePWithNoPath[j]=='r'))
  10086. {
  10087. fnamePWithNoPath[j]='\0';
  10088. }
  10089. }
  10090. FILE* fp1 = fopen(fnamePlusPath, "r");
  10091. if (fp1)
  10092. {
  10093. DEBUG_INFO("testfuc : fnamePlusPath=%s exist.\n", fnamePlusPath);
  10094. // file exists
  10095. fclose(fp1);
  10096. }
  10097. else
  10098. {
  10099. // file doesn't exist
  10100. DEBUG_WARN("testfuc : fnamePlusPath=%s not exist!\n", fnamePlusPath);
  10101. }
  10102. }
  10103. int handleGetDiagnosticsRequest(char *uuid, char *payload)
  10104. {
  10105. mtrace();
  10106. int result = FAIL;
  10107. time_t CurrentTime;
  10108. struct tm *tm;
  10109. pthread_t th_Status;
  10110. CurrentTime = time(NULL);
  10111. tm = localtime(&CurrentTime);
  10112. memset(ShmOCPP16Data->GetDiagnostics.ResponseFileName, 0x00, ARRAY_SIZE(ShmOCPP16Data->GetDiagnostics.ResponseFileName));
  10113. 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);
  10114. sendGetDiagnosticsConfirmation(uuid, (char*)ShmOCPP16Data->GetDiagnostics.ResponseFileName);
  10115. if(!interLock.isGetDiagnosticGoing)
  10116. {
  10117. interLock.isGetDiagnosticGoing = 1;
  10118. pthread_create(&th_Status, NULL, GetDiagnosticsProcess, stringtrimspace(payload));
  10119. sleep(1);
  10120. }
  10121. else
  10122. DEBUG_WARN("Other GetDiagnostic request on going.\n");
  10123. return result;
  10124. }
  10125. void* GetDiagnosticsProcess(void* data)
  10126. {
  10127. pthread_detach(pthread_self());
  10128. mtrace();
  10129. int retriesInt=0, retryIntervalInt=0;
  10130. char locationstr[1024]={0}, startTimestr[30]={0}, stopTimestr[30]={0} ;
  10131. 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};
  10132. int port=0;
  10133. int isSuccess = FALSE;
  10134. char cmdBuf[2048];
  10135. struct tm *tmNow;
  10136. time_t CurrentTime;
  10137. struct tm tmStart;
  10138. struct tm tmStop;
  10139. CurrentTime = time(NULL);
  10140. tmNow=localtime(&CurrentTime);
  10141. uint16_t targetYear, targetMonth;
  10142. json_object *GetDiagnostics;
  10143. DEBUG_INFO("GetDiagnosticsProcess...\n");
  10144. GetDiagnostics = json_tokener_parse(data);
  10145. if(!is_error(GetDiagnostics))
  10146. {
  10147. // Required data
  10148. if(json_object_object_get(GetDiagnostics, "location") != NULL)
  10149. sprintf(locationstr, "%s", json_object_get_string(json_object_object_get(GetDiagnostics, "location")));
  10150. // Optional data
  10151. if(json_object_object_get(GetDiagnostics, "retries") != NULL)
  10152. retriesInt = json_object_get_int(json_object_object_get(GetDiagnostics, "retries"));
  10153. else
  10154. retriesInt = 3; // If this field is not present, it is left to Charge Point to decide how many times it wants to retry.
  10155. if(json_object_object_get(GetDiagnostics, "retryInterval") != NULL)
  10156. retryIntervalInt = json_object_get_int(json_object_object_get(GetDiagnostics, "retryInterval"));
  10157. else
  10158. retryIntervalInt = 30;
  10159. if(json_object_object_get(GetDiagnostics, "startTime") != NULL)
  10160. sprintf(startTimestr, "%s", json_object_get_string(json_object_object_get(GetDiagnostics, "startTime")));
  10161. if(json_object_object_get(GetDiagnostics, "stopTime") != NULL)
  10162. sprintf(stopTimestr, "%s", json_object_get_string(json_object_object_get(GetDiagnostics, "stopTime")));
  10163. }
  10164. json_object_put(GetDiagnostics);
  10165. // Pack log to compress file
  10166. 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) &&
  10167. (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))
  10168. {
  10169. // Pack system log
  10170. memset(cmdBuf, 0x00, ARRAY_SIZE(cmdBuf));
  10171. sprintf(cmdBuf, "exec zip -9 --password %04d%02d%s /mnt/system.zip", tmNow->tm_year+1900, tmNow->tm_mon+1, ShmSysConfigAndInfo->SysConfig.SerialNumber);
  10172. targetYear = tmStart.tm_year;
  10173. targetMonth = tmStart.tm_mon;
  10174. do
  10175. {
  10176. sprintf(cmdBuf, "%s /Storage/SystemLog/*%04d*%02d*", cmdBuf, targetYear, targetMonth);
  10177. sprintf(cmdBuf, "%s /Storage/OCPP/*%04d*%02d*SystemLog*", cmdBuf, targetYear, targetMonth);
  10178. if(targetMonth+1>=13)
  10179. {
  10180. targetYear += 1;
  10181. targetMonth = 1;
  10182. }
  10183. else
  10184. {
  10185. targetMonth += 1;
  10186. }
  10187. }while((targetYear < (tmNow->tm_year+1900)) ||
  10188. ((targetYear <= (tmNow->tm_year+1900)) && (targetMonth <= (tmNow->tm_mon+1))));
  10189. sprintf(cmdBuf, "%s /Storage/CCS*.zip", cmdBuf);
  10190. sprintf(cmdBuf, "%s /Storage/OCPP/*.db", cmdBuf);
  10191. system(cmdBuf);
  10192. // Pack charging & event log
  10193. memset(cmdBuf, 0x00, ARRAY_SIZE(cmdBuf));
  10194. sprintf(cmdBuf, "exec zip -9 /mnt/charging_event.zip");
  10195. targetYear = tmStart.tm_year;
  10196. targetMonth = tmStart.tm_mon;
  10197. do
  10198. {
  10199. sprintf(cmdBuf, "%s /Storage/EventLog/*%04d*%02d*", cmdBuf, targetYear, targetMonth);
  10200. sprintf(cmdBuf, "%s /Storage/OCPP/*%04d*%02d*OcppMessageLog*", cmdBuf, targetYear, targetMonth);
  10201. if(targetMonth+1>=13)
  10202. {
  10203. targetYear += 1;
  10204. targetMonth = 1;
  10205. }
  10206. else
  10207. {
  10208. targetMonth += 1;
  10209. }
  10210. }while((targetYear < (tmNow->tm_year+1900)) ||
  10211. ((targetYear <= (tmNow->tm_year+1900)) && (targetMonth <= (tmNow->tm_mon+1))));
  10212. sprintf(cmdBuf, "%s /Storage/ChargeLog/*.db", cmdBuf);
  10213. sprintf(cmdBuf, "%s /Storage/EventLog/*.db", cmdBuf);
  10214. system(cmdBuf);
  10215. // Combine log file
  10216. system("exec zip -9 /mnt/log.zip /mnt/system.zip /mnt/charging_event.zip");
  10217. system("exec rm -f /mnt/system.zip /mnt/charging_event.zip");
  10218. }
  10219. else
  10220. {
  10221. system("exec /root/logPackTools 'log' 6");
  10222. }
  10223. sprintf(cmdBuf, "mv /mnt/log.zip /mnt/%s", ShmOCPP16Data->GetDiagnostics.ResponseFileName);
  10224. system(cmdBuf);
  10225. checkUploadLog();
  10226. //****************location*******************/
  10227. if(strcmp(locationstr,"")==0)
  10228. {
  10229. DEBUG_INFO("location is <Empty>!\n");
  10230. sprintf((char*)ShmOCPP16Data->DiagnosticsStatusNotification.Status, "%s", DiagnosticsStatusStr[DiagnosticsStatus_UploadFailed]);
  10231. ShmOCPP16Data->SpMsg.bits.DiagnosticsStatusNotificationReq = 1;
  10232. goto end;
  10233. }
  10234. memset(protocol, 0, ARRAY_SIZE(protocol));
  10235. memset(user, 0, ARRAY_SIZE(user) );
  10236. memset(password, 0, ARRAY_SIZE(password));
  10237. memset(host, 0, ARRAY_SIZE(host));
  10238. memset(path, 0, ARRAY_SIZE(path));
  10239. memset(ftppath, 0, ARRAY_SIZE(ftppath));
  10240. memset(host1, 0, ARRAY_SIZE(host1));
  10241. memset(path1, 0, ARRAY_SIZE(path1));
  10242. /*location: ftp://user:password@host:port/path*/
  10243. //DEBUG_INFO("fnamePlusPath =%s\n",fnamePlusPath);
  10244. if((access(fnamePlusPath,F_OK))!=-1)
  10245. {
  10246. DEBUG_INFO("fnamePlusPath exist.\n");
  10247. }
  10248. else
  10249. {
  10250. DEBUG_INFO("fnamePlusPath not exist!\n");
  10251. sprintf((char*)ShmOCPP16Data->DiagnosticsStatusNotification.Status, "%s", DiagnosticsStatusStr[DiagnosticsStatus_UploadFailed]);
  10252. ShmOCPP16Data->SpMsg.bits.DiagnosticsStatusNotificationReq = 1;
  10253. goto end;
  10254. }
  10255. if(strchr(locationstr,'@')==NULL)
  10256. {
  10257. sscanf(locationstr,
  10258. "%[^:]:%*2[/]%[^:]:%i/%[a-zA-Z0-9._/-]",
  10259. protocol, host, &port, path);
  10260. strcpy(user,"anonymous");
  10261. strcpy(password,"");
  10262. }
  10263. else
  10264. {
  10265. //DEBUG_INFO("pch=%s\n", pch);
  10266. sscanf(locationstr,"%[^:]:%*2[/]%[^:]:%[^@]@%[^:]:%i/%199[^\n]",
  10267. protocol, user, password, host, &port, path);
  10268. }
  10269. if((strcmp(protocol,"ftp")!=0)&&(strcmp(protocol,"http")!=0)&&(strcmp(protocol,"https")!=0))
  10270. {
  10271. DEBUG_INFO("protocol is not ftp/http ! \n");
  10272. sprintf((char*)ShmOCPP16Data->DiagnosticsStatusNotification.Status, "%s", DiagnosticsStatusStr[DiagnosticsStatus_UploadFailed]);
  10273. ShmOCPP16Data->SpMsg.bits.DiagnosticsStatusNotificationReq = 1;
  10274. goto end;
  10275. }
  10276. if(strncmp(locationstr,"http", 4) == 0)
  10277. {
  10278. sscanf(locationstr,"%[^:]:%*2[/]%[^/]/%199[^\n]", protocol, host, path);
  10279. sprintf(ftppath,"/%s", path);
  10280. do
  10281. {
  10282. sprintf((char*)ShmOCPP16Data->DiagnosticsStatusNotification.Status, "%s", DiagnosticsStatusStr[DiagnosticsStatus_Uploading]);
  10283. ShmOCPP16Data->SpMsg.bits.DiagnosticsStatusNotificationReq = 1;
  10284. sleep(3);
  10285. isSuccess = httpUploadFile(host, ftppath, fnamePlusPath, locationstr);
  10286. if(!isSuccess)
  10287. {
  10288. DEBUG_INFO("Diagnostics fail.\n");
  10289. sprintf((char*)ShmOCPP16Data->DiagnosticsStatusNotification.Status, "%s", DiagnosticsStatusStr[DiagnosticsStatus_UploadFailed]);
  10290. ShmOCPP16Data->SpMsg.bits.DiagnosticsStatusNotificationReq = 1;
  10291. sleep(retryIntervalInt);
  10292. }
  10293. else
  10294. {
  10295. DEBUG_INFO("sendDiagnosticsStatusNotificationRequest Uploaded\n");
  10296. sprintf((char*)ShmOCPP16Data->DiagnosticsStatusNotification.Status, "%s", DiagnosticsStatusStr[DiagnosticsStatus_Uploaded]);
  10297. ShmOCPP16Data->SpMsg.bits.DiagnosticsStatusNotificationReq = 1;
  10298. }
  10299. retriesInt--;
  10300. }while((isSuccess == 0)&&(retriesInt >= 0));
  10301. }
  10302. else
  10303. {
  10304. sscanf(host,"%[^/]%s",host1, path1);
  10305. if(strlen(path) > 0)
  10306. sprintf(ftppath,"/%s", path);
  10307. else
  10308. sprintf(ftppath,"/%s", path1);
  10309. int ftppathlen=strlen(ftppath);
  10310. int i=1;
  10311. char filenametemp[50];
  10312. while(i < ftppathlen)
  10313. {
  10314. int len=ftppathlen-i;
  10315. if(ftppath[len]== 47) // '/' ascll code: 47
  10316. {
  10317. DEBUG_INFO("find '/' all right\n");
  10318. break;
  10319. }
  10320. i=i+1;
  10321. }
  10322. memset(filenametemp, 0, ARRAY_SIZE(filenametemp));
  10323. strncpy(filenametemp, ftppath+(ftppathlen-i+1), i+1);
  10324. filenametemp[i+1] = 0;
  10325. if(port == 0)
  10326. port = 21;
  10327. do
  10328. {
  10329. sprintf((char*)ShmOCPP16Data->DiagnosticsStatusNotification.Status, "%s", DiagnosticsStatusStr[DiagnosticsStatus_Uploading]);
  10330. ShmOCPP16Data->SpMsg.bits.DiagnosticsStatusNotificationReq = 1;
  10331. sleep(3);
  10332. isSuccess = ftpUploadFile(host1, user, password, port, ftppath, fnamePlusPath, fnamePWithNoPath);
  10333. if(!isSuccess)
  10334. {
  10335. DEBUG_INFO("Diagnostics fail.\n");
  10336. sprintf((char*)ShmOCPP16Data->DiagnosticsStatusNotification.Status, "%s", DiagnosticsStatusStr[DiagnosticsStatus_UploadFailed]);
  10337. ShmOCPP16Data->SpMsg.bits.DiagnosticsStatusNotificationReq = 1;
  10338. sleep(retryIntervalInt);
  10339. }
  10340. else
  10341. {
  10342. DEBUG_INFO("sendDiagnosticsStatusNotificationRequest Uploaded\n");
  10343. sprintf((char*)ShmOCPP16Data->DiagnosticsStatusNotification.Status, "%s", DiagnosticsStatusStr[DiagnosticsStatus_Uploaded]);
  10344. ShmOCPP16Data->SpMsg.bits.DiagnosticsStatusNotificationReq = 1;
  10345. }
  10346. retriesInt--;
  10347. }while((!isSuccess)&&(retriesInt >= 0));
  10348. }
  10349. end:
  10350. system("rm -f /mnt/*");
  10351. sleep(5);
  10352. sprintf((char*)ShmOCPP16Data->DiagnosticsStatusNotification.Status, "%s", DiagnosticsStatusStr[DiagnosticsStatus_Idle]);
  10353. ShmOCPP16Data->SpMsg.bits.DiagnosticsStatusNotificationReq = 1;
  10354. interLock.isGetDiagnosticGoing = 0;
  10355. pthread_exit(NULL);
  10356. }
  10357. int handleGetLocalListVersionRequest(char *uuid, char *payload)
  10358. {
  10359. mtrace();
  10360. int result = FAIL;
  10361. DEBUG_INFO("handle GetLocalListVersionRequest\n");
  10362. if(strcmp((const char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "FALSE") == 0)
  10363. {
  10364. DEBUG_INFO("LocalAuthListEnabled is FALSE \n");
  10365. locallistVersion = -1;
  10366. }
  10367. else
  10368. {
  10369. DEBUG_INFO("handle GetLocalListVersionRequest OCPP_getListVerion \n");
  10370. OCPP_getListVerion();
  10371. }
  10372. //from db.OCPP_getListVerion
  10373. ShmOCPP16Data->GetLocalListVersion.ResponseListVersion = locallistVersion;
  10374. //ShmOCPP16Data->MsMsg.bits.GetLocalListVersionReq = 1;
  10375. sendGetLocalListVersionConfirmation(uuid,"");
  10376. //ShmOCPP16Data->MsMsg.bits.GetLocalListVersionConf = 1;
  10377. return result;
  10378. }
  10379. int handleRemoteStartRequestOrg(char *uuid, char *payload)
  10380. {
  10381. mtrace();
  10382. int result = FAIL;
  10383. int connectorIdInt=-1;
  10384. int tempIndex = 0;
  10385. int connectorIdIsNULL, chargingProfileIsNULL;
  10386. char comfirmstr[20]={0};
  10387. char cmdBuf[512];
  10388. json_object *RemoteStartTransaction;
  10389. FILE *fp;
  10390. DEBUG_INFO("handleRemoteStartRequest ...\n");
  10391. if(server_pending == TRUE)
  10392. {
  10393. return 0;
  10394. }
  10395. connectorIdIsNULL = chargingProfileIsNULL= FALSE;
  10396. RemoteStartTransaction = json_tokener_parse(payload);
  10397. if(!is_error(RemoteStartTransaction))
  10398. {
  10399. if(json_object_object_get(RemoteStartTransaction, "connectorId") != NULL)
  10400. {
  10401. connectorIdInt = json_object_get_int(json_object_object_get(RemoteStartTransaction, "connectorId"));
  10402. }
  10403. else
  10404. {
  10405. connectorIdIsNULL = TRUE;
  10406. for(uint8_t gun_index=0;gun_index<gunTotalNumber;gun_index++)
  10407. {
  10408. if(!cpinitateMsg.bits[gun_index].isOnCharging && (strstr((char*)ShmOCPP16Data->StatusNotification[gun_index].Status, "Preparing") != NULL))
  10409. {
  10410. connectorIdIsNULL = FALSE;
  10411. connectorIdInt = (gun_index+1);
  10412. DEBUG_INFO("Remote start without connectorId but detect connector-%02d connected ready to start.\n", connectorIdInt);
  10413. break;
  10414. }
  10415. }
  10416. }
  10417. if((connectorIdInt <= gunTotalNumber) && (connectorIdInt > 0))
  10418. {
  10419. memset(&ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1], 0x00, sizeof(struct StructRemoteStartTransaction));
  10420. // Required data
  10421. sprintf((char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag, "%s", json_object_get_string(json_object_object_get(RemoteStartTransaction, "idTag")));
  10422. // Optional data
  10423. if(json_object_object_get(RemoteStartTransaction, "chargingProfile") != NULL)
  10424. {
  10425. ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingProfileId = json_object_get_int(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingProfileId"));
  10426. ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.StackLevel = json_object_get_int(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "stackLevel"));
  10427. sprintf((char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingProfilePurpose, "%s", json_object_get_string(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingProfilePurpose")));
  10428. sprintf((char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingProfileKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingProfileKind")));
  10429. if(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "transactionId") != NULL)
  10430. ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.TransactionId = json_object_get_int(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "transactionId"));
  10431. if(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "recurrencyKind") != NULL)
  10432. sprintf((char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.RecurrencyKind , "%s", json_object_get_string(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "recurrencyKind")));
  10433. if(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "validFrom") != NULL)
  10434. sprintf((char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ValidFrom , "%s", json_object_get_string(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "validFrom")));
  10435. if(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "validTo") != NULL)
  10436. sprintf((char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ValidTo , "%s", json_object_get_string(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "validTo")));
  10437. if(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingSchedule") != NULL)
  10438. {
  10439. 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")));
  10440. if(json_object_object_get(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingSchedule"), "duration") != NULL)
  10441. 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"));
  10442. if(json_object_object_get(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingSchedule"), "minChargingRate") != NULL)
  10443. 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"));
  10444. if(json_object_object_get(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingSchedule"), "startSchedule") != NULL)
  10445. 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")));
  10446. if(json_object_object_get(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingSchedule"), "chargingSchedulePeriod") != NULL)
  10447. {
  10448. 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++)
  10449. {
  10450. 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"));
  10451. 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"));
  10452. 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)
  10453. 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"));
  10454. }
  10455. }
  10456. }
  10457. }
  10458. else
  10459. {
  10460. chargingProfileIsNULL = TRUE;
  10461. }
  10462. }
  10463. }
  10464. else
  10465. {
  10466. connectorIdIsNULL = TRUE;
  10467. }
  10468. if(connectorIdIsNULL == TRUE) // Number of the connector on which to start the transaction. connectorId SHALL be > 0
  10469. {
  10470. DEBUG_WARN("Connector id is NULL\n.");
  10471. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  10472. goto end;
  10473. }
  10474. /*
  10475. enum _SYSTEM_STATUS
  10476. {
  10477. S_BOOTING = 0,
  10478. S_IDLE, = 1
  10479. S_AUTHORIZING, = 2
  10480. S_REASSIGN_CHECK, = 3
  10481. S_REASSIGN, = 4
  10482. S_PRECHARGE, = 5
  10483. S_PREPARING_FOR_EV, = 6
  10484. S_PREPARING_FOR_EVSE, = 7
  10485. S_CHARGING, = 8
  10486. S_TERMINATING, = 9
  10487. S_COMPLETE, = 10
  10488. S_ALARM, = 11
  10489. S_FAULT = 12
  10490. }
  10491. */
  10492. if((connectorIdIsNULL == FALSE)&&(connectorIdInt > 0) && (connectorIdInt <= gunTotalNumber))
  10493. {
  10494. //check Transaction active
  10495. if(gunType[connectorIdInt -1] == GUN_TYPE_CHAdeMO)
  10496. {
  10497. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  10498. {
  10499. tempIndex = ((connectorIdInt -1) == 2) ? 1: 0;
  10500. }
  10501. else
  10502. {
  10503. tempIndex = connectorIdInt -1;
  10504. }
  10505. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  10506. {
  10507. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex )
  10508. {
  10509. 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))
  10510. {
  10511. //Reserved
  10512. DEBUG_INFO("Reserved now !!!The idTag matches the idTag of Reservation!!!\n");
  10513. }
  10514. 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))
  10515. {
  10516. //Reserved
  10517. DEBUG_INFO("Reserved now !!! The idTag does NOT match the idTag of Reservation!!! Reject it!!!\n");
  10518. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  10519. goto end;
  10520. }
  10521. else
  10522. {
  10523. if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  10524. && (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_PREPARING ) //S_PRECHARGE
  10525. && (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EV ) //S_PREPARING_FOR_EV
  10526. && (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EVSE )) // S_PREPARING_FOR_EVSE
  10527. {
  10528. DEBUG_WARN("CHAdeMO connector not allow start\n.");
  10529. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  10530. goto end;
  10531. }
  10532. }//END FOR ELSE
  10533. }
  10534. }// END FOR CHAdeMO_QUANTITY
  10535. }
  10536. else if(gunType[connectorIdInt -1] == GUN_TYPE_CCS)
  10537. {
  10538. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  10539. {
  10540. tempIndex = ((connectorIdInt -1) == 2) ? 1: 0;
  10541. }
  10542. else
  10543. {
  10544. tempIndex = connectorIdInt -1;
  10545. }
  10546. for (int index = 0; index < CCS_QUANTITY; index++)
  10547. {
  10548. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  10549. {
  10550. 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))
  10551. {
  10552. //Reserved
  10553. DEBUG_INFO("Reserved now !!!The idTag matches the idTag of Reservation!!!\n");
  10554. }
  10555. 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))
  10556. {
  10557. //Reserved
  10558. DEBUG_INFO("Reserved now !!! The idTag does NOT match the idTag of Reservation!!! Reject it!!!\n");
  10559. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  10560. goto end;
  10561. }
  10562. else
  10563. {
  10564. if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  10565. && (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_PREPARING) //S_PRECHARGE
  10566. && (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EV) //S_PREPARING_FOR_EV
  10567. && (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EVSE)) // S_PREPARING_FOR_EVSE
  10568. {
  10569. DEBUG_WARN("CCS connector not allow start\n.");
  10570. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  10571. goto end;
  10572. }
  10573. }// END FOR ELSE
  10574. }
  10575. }// END FOR CCS_QUANTITY
  10576. }
  10577. else if(gunType[connectorIdInt -1] == GUN_TYPE_GBT)
  10578. {
  10579. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  10580. {
  10581. tempIndex = ((connectorIdInt -1) == 2) ? 1: 0;
  10582. }
  10583. else
  10584. {
  10585. tempIndex = connectorIdInt -1;
  10586. }
  10587. for (int index = 0; index < GB_QUANTITY; index++)
  10588. {
  10589. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex )
  10590. {
  10591. if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ReservationId != -1)&&(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ReservationId >= 0)&&(strcmp((const char *)ShmOCPP16Data->ReserveNow[index].IdTag, (char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag) == 0))
  10592. {
  10593. //Reserved
  10594. DEBUG_INFO("Reserved now !!!The idTag matches the idTag of Reservation!!!\n");
  10595. }
  10596. 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))
  10597. {
  10598. //Reserved
  10599. DEBUG_INFO("Reserved now !!! The idTag does NOT match the idTag of Reservation!!! Reject it!!!\n");
  10600. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  10601. goto end;
  10602. }
  10603. else
  10604. {
  10605. if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  10606. && (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_PREPARING) //S_PRECHARGE
  10607. && (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EV) //S_PREPARING_FOR_EV
  10608. && (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EVSE)) // S_PREPARING_FOR_EVSE
  10609. {
  10610. DEBUG_WARN("GB connector not allow start\n.");
  10611. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  10612. goto end;
  10613. }
  10614. }// END FOR ELSE
  10615. }
  10616. } // END FOR GB_QUANTITY
  10617. }
  10618. else if(gunType[connectorIdInt -1] == GUN_TYPE_DO)
  10619. {
  10620. tempIndex = connectorIdInt -1;
  10621. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  10622. {
  10623. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex )
  10624. {
  10625. 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))
  10626. {
  10627. //Reserved
  10628. DEBUG_INFO("Reserved now !!!The idTag matches the idTag of Reservation!!!\n");
  10629. }
  10630. 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))
  10631. {
  10632. //Reserved
  10633. DEBUG_INFO("Reserved now !!! The idTag does NOT match the idTag of Reservation!!! Reject it!!!\n");
  10634. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  10635. goto end;
  10636. }
  10637. else
  10638. {
  10639. if((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus != SYS_MODE_IDLE) //S_IDLE
  10640. && (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus != SYS_MODE_PREPARING) //S_PRECHARGE
  10641. && (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus != SYS_MODE_PREPARE_FOR_EV) //S_PREPARING_FOR_EV
  10642. && (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus != SYS_MODE_PREPARE_FOR_EVSE)) // S_PREPARING_FOR_EVSE
  10643. {
  10644. DEBUG_WARN("GB connector not allow start\n.");
  10645. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  10646. goto end;
  10647. }
  10648. }// END FOR ELSE
  10649. }
  10650. } // END FOR GB_QUANTITY
  10651. }
  10652. else
  10653. {
  10654. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D') // 'D' means DC
  10655. {
  10656. tempIndex = 2;
  10657. }
  10658. else
  10659. {
  10660. tempIndex = connectorIdInt -1;
  10661. }
  10662. for (int index = 0; index < AC_QUANTITY; index++)
  10663. {
  10664. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex )
  10665. {
  10666. 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))
  10667. {
  10668. //Reserved
  10669. DEBUG_INFO("Reserved now !!!The idTag matches the idTag of Reservation!!!\n");
  10670. }
  10671. 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))
  10672. {
  10673. //Reserved
  10674. DEBUG_INFO("Reserved now !!! The idTag does NOT match the idTag of Reservation!!! Reject it!!!\n");
  10675. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  10676. goto end;
  10677. }
  10678. else
  10679. {
  10680. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  10681. && (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_PREPARING) //S_PRECHARGE
  10682. && (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EV) //S_PREPARING_FOR_EV
  10683. && (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EVSE)) // S_PREPARING_FOR_EVSE
  10684. {
  10685. DEBUG_WARN("AC connector not allow start\n.");
  10686. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  10687. goto end;
  10688. }
  10689. }//END FOR ELSE
  10690. }
  10691. }// END FOR AC_QUANTITY
  10692. }
  10693. if(chargingProfileIsNULL == FALSE)
  10694. {
  10695. if(strcmp((char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingProfilePurpose, ChargingProfilePurposeTypeStr[TxProfile]) == 0)
  10696. {
  10697. ShmOCPP16Data->CsMsg.bits[connectorIdInt -1].RemoteStartTransactionReq = 1;
  10698. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Accepted]);
  10699. //memset idTag
  10700. memset((char *)ShmOCPP16Data->StartTransaction[connectorIdInt -1].IdTag,0, 20);
  10701. strcpy((char *)ShmOCPP16Data->StartTransaction[connectorIdInt -1].IdTag, (char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag);
  10702. memset((char *)ShmOCPP16Data->StopTransaction[connectorIdInt -1].IdTag,0, 20);
  10703. strcpy((char *)ShmOCPP16Data->StopTransaction[connectorIdInt -1].IdTag, (char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag);
  10704. // Save profile to file
  10705. sprintf(cmdBuf, "rm -f /Storage/OCPP/TxProfile_%d.json", connectorIdInt);
  10706. system(cmdBuf);
  10707. sprintf(cmdBuf, "/Storage/OCPP/TxProfile_%d.json", connectorIdInt);
  10708. fp = fopen(cmdBuf, "w");
  10709. 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));
  10710. fclose(fp);
  10711. }
  10712. else
  10713. {
  10714. DEBUG_WARN("Carging profile purpose not TxProfile.\n.");
  10715. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  10716. }
  10717. }
  10718. else
  10719. {
  10720. ShmOCPP16Data->CsMsg.bits[connectorIdInt -1].RemoteStartTransactionReq = 1;
  10721. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Accepted]);
  10722. //memset idTag
  10723. memset((char *)ShmOCPP16Data->StartTransaction[connectorIdInt -1].IdTag,0, 20);
  10724. strcpy((char *)ShmOCPP16Data->StartTransaction[connectorIdInt -1].IdTag, (char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag);
  10725. memset((char *)ShmOCPP16Data->StopTransaction[connectorIdInt -1].IdTag,0, 20);
  10726. strcpy((char *)ShmOCPP16Data->StopTransaction[connectorIdInt -1].IdTag, (char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag);
  10727. }
  10728. }
  10729. else
  10730. {
  10731. DEBUG_WARN("Connector id over\n.");
  10732. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  10733. //sprintf((char *)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ResponseStatus, "%s" ,comfirmstr);
  10734. }
  10735. end:
  10736. json_object_put(RemoteStartTransaction);
  10737. if((connectorIdIsNULL == FALSE) && (connectorIdInt <= gunTotalNumber))
  10738. {
  10739. ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ConnectorId = connectorIdInt;
  10740. sprintf((char *)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ResponseStatus, "%s" ,comfirmstr);
  10741. }
  10742. //OCPP send RemoteStartConfirmation by first.
  10743. sendRemoteStartConfirmation(uuid, comfirmstr);
  10744. return result;
  10745. }
  10746. int handleRemoteStartRequest(char *uuid, char *payload)
  10747. {
  10748. mtrace();
  10749. int result = PASS;
  10750. int connectorIdInt=-1;
  10751. int tempIndex = 0;
  10752. char comfirmstr[20]={0};
  10753. char cmdBuf[512];
  10754. json_object *RemoteStartTransaction;
  10755. FILE *fp;
  10756. DEBUG_INFO("handleRemoteStartRequest ...\n");
  10757. if(server_pending == TRUE)
  10758. {
  10759. result = FAIL;
  10760. }
  10761. RemoteStartTransaction = json_tokener_parse(payload);
  10762. if(!is_error(RemoteStartTransaction))
  10763. {
  10764. if(json_object_object_get(RemoteStartTransaction, "connectorId") != NULL)
  10765. {
  10766. connectorIdInt = json_object_get_int(json_object_object_get(RemoteStartTransaction, "connectorId"));
  10767. }
  10768. else
  10769. {
  10770. for(uint8_t gun_index=0;gun_index<gunTotalNumber;gun_index++)
  10771. {
  10772. if(!cpinitateMsg.bits[gun_index].isOnCharging && (strstr((char*)ShmOCPP16Data->StatusNotification[gun_index].Status, "Preparing") != NULL))
  10773. {
  10774. connectorIdInt = (gun_index+1);
  10775. DEBUG_INFO("Remote start without connectorId but detect connector-%02d connected ready to start.\n", connectorIdInt);
  10776. break;
  10777. }
  10778. }
  10779. }
  10780. if(connectorIdInt == 0)
  10781. {
  10782. DEBUG_WARN("Connector id shall not equal 0.\n");
  10783. result = FAIL;
  10784. }
  10785. else if(connectorIdInt == -1)
  10786. {
  10787. DEBUG_INFO("Connector id does not specific.\n");
  10788. for(uint8_t gun_index=0;gun_index<gunTotalNumber;gun_index++)
  10789. {
  10790. memset(&ShmOCPP16Data->RemoteStartTransaction[gun_index], 0x00, sizeof(struct StructRemoteStartTransaction));
  10791. // Required data
  10792. sprintf((char*)ShmOCPP16Data->RemoteStartTransaction[gun_index].IdTag, "%s", json_object_get_string(json_object_object_get(RemoteStartTransaction, "idTag")));
  10793. // Optional data
  10794. if(json_object_object_get(RemoteStartTransaction, "chargingProfile") != NULL)
  10795. {
  10796. ShmOCPP16Data->RemoteStartTransaction[gun_index].ChargingProfile.ChargingProfileId = json_object_get_int(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingProfileId"));
  10797. ShmOCPP16Data->RemoteStartTransaction[gun_index].ChargingProfile.StackLevel = json_object_get_int(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "stackLevel"));
  10798. sprintf((char*)ShmOCPP16Data->RemoteStartTransaction[gun_index].ChargingProfile.ChargingProfilePurpose, "%s", json_object_get_string(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingProfilePurpose")));
  10799. sprintf((char*)ShmOCPP16Data->RemoteStartTransaction[gun_index].ChargingProfile.ChargingProfileKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingProfileKind")));
  10800. if(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "transactionId") != NULL)
  10801. ShmOCPP16Data->RemoteStartTransaction[gun_index].ChargingProfile.TransactionId = json_object_get_int(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "transactionId"));
  10802. if(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "recurrencyKind") != NULL)
  10803. sprintf((char*)ShmOCPP16Data->RemoteStartTransaction[gun_index].ChargingProfile.RecurrencyKind , "%s", json_object_get_string(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "recurrencyKind")));
  10804. if(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "validFrom") != NULL)
  10805. sprintf((char*)ShmOCPP16Data->RemoteStartTransaction[gun_index].ChargingProfile.ValidFrom , "%s", json_object_get_string(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "validFrom")));
  10806. if(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "validTo") != NULL)
  10807. sprintf((char*)ShmOCPP16Data->RemoteStartTransaction[gun_index].ChargingProfile.ValidTo , "%s", json_object_get_string(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "validTo")));
  10808. if(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingSchedule") != NULL)
  10809. {
  10810. 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")));
  10811. if(json_object_object_get(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingSchedule"), "duration") != NULL)
  10812. 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"));
  10813. if(json_object_object_get(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingSchedule"), "minChargingRate") != NULL)
  10814. 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"));
  10815. if(json_object_object_get(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingSchedule"), "startSchedule") != NULL)
  10816. 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")));
  10817. if(json_object_object_get(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingSchedule"), "chargingSchedulePeriod") != NULL)
  10818. {
  10819. 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++)
  10820. {
  10821. 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"));
  10822. 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"));
  10823. 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)
  10824. 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"));
  10825. }
  10826. }
  10827. }
  10828. }
  10829. else
  10830. {
  10831. ShmOCPP16Data->RemoteStartTransaction[gun_index].ChargingProfile.ChargingProfileId = -1;
  10832. }
  10833. }
  10834. }
  10835. else if(((0 < connectorIdInt) && (connectorIdInt <= gunTotalNumber)))
  10836. {
  10837. DEBUG_INFO("Connector id: %d\n", connectorIdInt);
  10838. memset(&ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1], 0x00, sizeof(struct StructRemoteStartTransaction));
  10839. // Required data
  10840. sprintf((char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag, "%s", json_object_get_string(json_object_object_get(RemoteStartTransaction, "idTag")));
  10841. // Optional data
  10842. if(json_object_object_get(RemoteStartTransaction, "chargingProfile") != NULL)
  10843. {
  10844. ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingProfileId = json_object_get_int(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingProfileId"));
  10845. ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.StackLevel = json_object_get_int(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "stackLevel"));
  10846. sprintf((char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingProfilePurpose, "%s", json_object_get_string(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingProfilePurpose")));
  10847. sprintf((char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingProfileKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingProfileKind")));
  10848. if(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "transactionId") != NULL)
  10849. ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.TransactionId = json_object_get_int(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "transactionId"));
  10850. if(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "recurrencyKind") != NULL)
  10851. sprintf((char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.RecurrencyKind , "%s", json_object_get_string(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "recurrencyKind")));
  10852. if(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "validFrom") != NULL)
  10853. sprintf((char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ValidFrom , "%s", json_object_get_string(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "validFrom")));
  10854. if(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "validTo") != NULL)
  10855. sprintf((char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ValidTo , "%s", json_object_get_string(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "validTo")));
  10856. if(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingSchedule") != NULL)
  10857. {
  10858. 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")));
  10859. if(json_object_object_get(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingSchedule"), "duration") != NULL)
  10860. 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"));
  10861. if(json_object_object_get(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingSchedule"), "minChargingRate") != NULL)
  10862. 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"));
  10863. if(json_object_object_get(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingSchedule"), "startSchedule") != NULL)
  10864. 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")));
  10865. if(json_object_object_get(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingSchedule"), "chargingSchedulePeriod") != NULL)
  10866. {
  10867. 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++)
  10868. {
  10869. 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"));
  10870. 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"));
  10871. 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)
  10872. 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"));
  10873. }
  10874. }
  10875. }
  10876. }
  10877. else
  10878. {
  10879. ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingProfileId = -1;
  10880. }
  10881. }
  10882. else
  10883. {
  10884. DEBUG_WARN("Connector id is over maximun value.\n");
  10885. result = FAIL;
  10886. }
  10887. }
  10888. if(result == PASS)
  10889. {
  10890. if(connectorIdInt > 0)
  10891. {
  10892. //check Transaction active
  10893. if(gunType[connectorIdInt -1] == GUN_TYPE_CHAdeMO)
  10894. {
  10895. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  10896. {
  10897. tempIndex = ((connectorIdInt -1) == 2) ? 1: 0;
  10898. }
  10899. else
  10900. {
  10901. tempIndex = connectorIdInt -1;
  10902. }
  10903. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  10904. {
  10905. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  10906. {
  10907. if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ReservationId != -1) &&
  10908. (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ReservationId >= 0) &&
  10909. (strcmp((const char *)ShmOCPP16Data->ReserveNow[index].IdTag, (char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag) == 0))
  10910. {
  10911. //Reserved
  10912. DEBUG_INFO("CHAdeMO connector already reserved and idTag match.\n");
  10913. }
  10914. else if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ReservationId != -1) &&
  10915. (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ReservationId >= 0) &&
  10916. (strcmp((const char *)ShmOCPP16Data->ReserveNow[index].IdTag, (char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag) != 0))
  10917. {
  10918. //Reserved
  10919. DEBUG_INFO("CHAdeMO connector already reserved and idTag does not match.\n");
  10920. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  10921. goto end;
  10922. }
  10923. else
  10924. {
  10925. if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  10926. && (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_PREPARING ) //S_PRECHARGE
  10927. && (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EV ) //S_PREPARING_FOR_EV
  10928. && (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EVSE )) // S_PREPARING_FOR_EVSE
  10929. {
  10930. DEBUG_WARN("CHAdeMO connector not allow start cause busy.\n");
  10931. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  10932. goto end;
  10933. }
  10934. }//END FOR ELSE
  10935. }
  10936. }// END FOR CHAdeMO_QUANTITY
  10937. }
  10938. else if(gunType[connectorIdInt -1] == GUN_TYPE_CCS)
  10939. {
  10940. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  10941. {
  10942. tempIndex = ((connectorIdInt -1) == 2) ? 1: 0;
  10943. }
  10944. else
  10945. {
  10946. tempIndex = connectorIdInt -1;
  10947. }
  10948. for (int index = 0; index < CCS_QUANTITY; index++)
  10949. {
  10950. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  10951. {
  10952. if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ReservationId != -1) &&
  10953. (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ReservationId >= 0) &&
  10954. (strcmp((const char *)ShmOCPP16Data->ReserveNow[index].IdTag, (char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag) == 0))
  10955. {
  10956. //Reserved
  10957. DEBUG_INFO("CCS connector already reserved and idTag match.\n");
  10958. }
  10959. else if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ReservationId != -1) &&
  10960. (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ReservationId >= 0) &&
  10961. (strcmp((const char *)ShmOCPP16Data->ReserveNow[index].IdTag, (char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag) != 0))
  10962. {
  10963. //Reserved
  10964. DEBUG_INFO("CCS connector already reserved and idTag does not match.\n");
  10965. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  10966. goto end;
  10967. }
  10968. else
  10969. {
  10970. if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  10971. && (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_PREPARING) //S_PRECHARGE
  10972. && (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EV) //S_PREPARING_FOR_EV
  10973. && (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EVSE)) // S_PREPARING_FOR_EVSE
  10974. {
  10975. DEBUG_WARN("CCS connector not allow start cause busy.\n");
  10976. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  10977. goto end;
  10978. }
  10979. }// END FOR ELSE
  10980. }
  10981. }// END FOR CCS_QUANTITY
  10982. }
  10983. else if(gunType[connectorIdInt -1] == GUN_TYPE_GBT)
  10984. {
  10985. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  10986. {
  10987. tempIndex = ((connectorIdInt -1) == 2) ? 1: 0;
  10988. }
  10989. else
  10990. {
  10991. tempIndex = connectorIdInt -1;
  10992. }
  10993. for (int index = 0; index < GB_QUANTITY; index++)
  10994. {
  10995. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex )
  10996. {
  10997. if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ReservationId != -1) &&
  10998. (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ReservationId >= 0) &&
  10999. (strcmp((const char *)ShmOCPP16Data->ReserveNow[index].IdTag, (char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag) == 0))
  11000. {
  11001. //Reserved
  11002. DEBUG_INFO("GBT connector already reserved and idTag match.\n");
  11003. }
  11004. else if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ReservationId != -1) &&
  11005. (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ReservationId >= 0) &&
  11006. (strcmp((const char *)ShmOCPP16Data->ReserveNow[index].IdTag, (char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag) != 0))
  11007. {
  11008. //Reserved
  11009. DEBUG_INFO("GBT connector already reserved and idTag does not match.\n");
  11010. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  11011. goto end;
  11012. }
  11013. else
  11014. {
  11015. if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  11016. && (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_PREPARING) //S_PRECHARGE
  11017. && (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EV) //S_PREPARING_FOR_EV
  11018. && (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EVSE)) // S_PREPARING_FOR_EVSE
  11019. {
  11020. DEBUG_WARN("GBT connector not allow start cause busy.\n");
  11021. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  11022. goto end;
  11023. }
  11024. }// END FOR ELSE
  11025. }
  11026. } // END FOR GB_QUANTITY
  11027. }
  11028. else if(gunType[connectorIdInt -1] == GUN_TYPE_DO)
  11029. {
  11030. tempIndex = connectorIdInt -1;
  11031. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  11032. {
  11033. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex )
  11034. {
  11035. if((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.ReservationId != -1) &&
  11036. (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.ReservationId >= 0) &&
  11037. (strcmp((const char *)ShmOCPP16Data->ReserveNow[index].IdTag, (char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag) == 0))
  11038. {
  11039. //Reserved
  11040. DEBUG_INFO("Dispenser connector already reserved and idTag match.\n");
  11041. }
  11042. else if((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.ReservationId != -1) &&
  11043. (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.ReservationId >= 0) &&
  11044. (strcmp((const char *)ShmOCPP16Data->ReserveNow[index].IdTag, (char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag) != 0))
  11045. {
  11046. //Reserved
  11047. DEBUG_INFO("Dispenser connector already reserved and idTag does not match.\n");
  11048. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  11049. goto end;
  11050. }
  11051. else
  11052. {
  11053. if((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus != SYS_MODE_IDLE) //S_IDLE
  11054. && (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus != SYS_MODE_PREPARING) //S_PRECHARGE
  11055. && (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus != SYS_MODE_PREPARE_FOR_EV) //S_PREPARING_FOR_EV
  11056. && (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus != SYS_MODE_PREPARE_FOR_EVSE)) // S_PREPARING_FOR_EVSE
  11057. {
  11058. DEBUG_WARN("Dispenser connector not allow start cause busy.\n");
  11059. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  11060. goto end;
  11061. }
  11062. }// END FOR ELSE
  11063. }
  11064. } // END FOR GB_QUANTITY
  11065. }
  11066. else
  11067. {
  11068. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D') // 'D' means DC
  11069. {
  11070. tempIndex = 2;
  11071. }
  11072. else
  11073. {
  11074. tempIndex = connectorIdInt -1;
  11075. }
  11076. for (int index = 0; index < AC_QUANTITY; index++)
  11077. {
  11078. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex )
  11079. {
  11080. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].ReservationId != -1) &&
  11081. (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].ReservationId >= 0) &&
  11082. (strcmp((const char *)ShmOCPP16Data->ReserveNow[index].IdTag, (char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag) == 0))
  11083. {
  11084. //Reserved
  11085. DEBUG_INFO("AC connector already reserved and idTag match.\n");
  11086. }
  11087. else if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].ReservationId != -1) &&
  11088. (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].ReservationId >= 0) &&
  11089. (strcmp((const char *)ShmOCPP16Data->ReserveNow[index].IdTag, (char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag) != 0))
  11090. {
  11091. //Reserved
  11092. DEBUG_INFO("AC connector already reserved and idTag does not match.\n");
  11093. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  11094. goto end;
  11095. }
  11096. else
  11097. {
  11098. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  11099. && (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_PREPARING) //S_PRECHARGE
  11100. && (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EV) //S_PREPARING_FOR_EV
  11101. && (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EVSE)) // S_PREPARING_FOR_EVSE
  11102. {
  11103. DEBUG_WARN("AC connector not allow start cause busy.\n");
  11104. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  11105. goto end;
  11106. }
  11107. }//END FOR ELSE
  11108. }
  11109. }// END FOR AC_QUANTITY
  11110. }
  11111. if(ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingProfileId > -1)
  11112. {
  11113. if(strcmp((char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingProfilePurpose, ChargingProfilePurposeTypeStr[TxProfile]) == 0)
  11114. {
  11115. // Save profile to file
  11116. sprintf(cmdBuf, "rm -f /Storage/OCPP/TxProfile_%d.json", connectorIdInt);
  11117. system(cmdBuf);
  11118. sprintf(cmdBuf, "/Storage/OCPP/TxProfile_%d.json", connectorIdInt);
  11119. fp = fopen(cmdBuf, "w");
  11120. 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));
  11121. fclose(fp);
  11122. }
  11123. else
  11124. {
  11125. DEBUG_WARN("Profile purpose not TxProfile.\n");
  11126. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  11127. goto end;
  11128. }
  11129. }
  11130. ShmOCPP16Data->CsMsg.bits[connectorIdInt -1].RemoteStartTransactionReq = 1;
  11131. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Accepted]);
  11132. memset((char *)ShmOCPP16Data->StartTransaction[connectorIdInt -1].IdTag,0, 20);
  11133. strcpy((char *)ShmOCPP16Data->StartTransaction[connectorIdInt -1].IdTag, (char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag);
  11134. memset((char *)ShmOCPP16Data->StopTransaction[connectorIdInt -1].IdTag,0, 20);
  11135. strcpy((char *)ShmOCPP16Data->StopTransaction[connectorIdInt -1].IdTag, (char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag);
  11136. }
  11137. else
  11138. {
  11139. uint8_t isHasIdleConnector = FALSE;
  11140. for(uint8_t gun_index=0;gun_index<gunTotalNumber;gun_index++)
  11141. {
  11142. if(!cpinitateMsg.bits[gun_index].isOnCharging)
  11143. {
  11144. isHasIdleConnector = TRUE;
  11145. break;
  11146. }
  11147. }
  11148. if(isHasIdleConnector == TRUE)
  11149. {
  11150. DEBUG_INFO("Start wait connector link to EV in %s seconds.\n", ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemData);
  11151. if(ShmOCPP16Data->RemoteStartTransaction[0].ChargingProfile.ChargingProfileId > -1)
  11152. {
  11153. if(strcmp((char*)ShmOCPP16Data->RemoteStartTransaction[0].ChargingProfile.ChargingProfilePurpose, ChargingProfilePurposeTypeStr[TxProfile]) == 0)
  11154. {
  11155. // Save profile to file
  11156. sprintf(cmdBuf, "rm -f /Storage/OCPP/TxProfile_Tmp.json");
  11157. system(cmdBuf);
  11158. sprintf(cmdBuf, "/Storage/OCPP/TxProfile_Tmp.json");
  11159. fp = fopen(cmdBuf, "w");
  11160. fprintf(fp, "{\"connectorId\":0,\"csChargingProfiles\":%s}\n", json_object_to_json_string_ext(json_object_object_get(RemoteStartTransaction, "chargingProfile"), JSON_C_TO_STRING_PLAIN));
  11161. fclose(fp);
  11162. refreshStartTimer(&clientTime.RemoteStartWait);
  11163. ShmOCPP16Data->MsMsg.bits.isRemoteStartWaitReq = 1;
  11164. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Accepted]);
  11165. }
  11166. else
  11167. {
  11168. DEBUG_WARN("Profile purpose not TxProfile.\n");
  11169. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  11170. }
  11171. }
  11172. else
  11173. {
  11174. refreshStartTimer(&clientTime.RemoteStartWait);
  11175. ShmOCPP16Data->MsMsg.bits.isRemoteStartWaitReq = 1;
  11176. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Accepted]);
  11177. }
  11178. }
  11179. else
  11180. {
  11181. DEBUG_INFO("There is not any connector is idle.\n");
  11182. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  11183. }
  11184. }
  11185. }
  11186. else
  11187. {
  11188. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  11189. }
  11190. end:
  11191. json_object_put(RemoteStartTransaction);
  11192. sendRemoteStartConfirmation(uuid, comfirmstr);
  11193. return result;
  11194. }
  11195. int handleRemoteStopTransactionRequest(char *uuid, char *payload)
  11196. {
  11197. mtrace();
  11198. int result = FAIL;
  11199. int match = FALSE;
  11200. int GunNO = 0;
  11201. int tempIndex = 0;
  11202. int transactionIdInt=0;
  11203. int transactionIdIsNULL= TRUE;
  11204. char comfirmstr[20];
  11205. json_object *RemoteStopTransaction;
  11206. //[2,"ff522854-0dea-436e-87ba-23a229269994","RemoteStopTransaction",{"transactionId":1373618380}]
  11207. DEBUG_INFO("handleRemoteStopTransactionRequest...\n");
  11208. if(server_pending == TRUE)
  11209. {
  11210. return 0;
  11211. }
  11212. RemoteStopTransaction = json_tokener_parse(payload);
  11213. if(!is_error(RemoteStopTransaction))
  11214. {
  11215. if(json_object_object_get(RemoteStopTransaction, "transactionId") != NULL)
  11216. {
  11217. transactionIdInt = json_object_get_int(json_object_object_get(RemoteStopTransaction, "transactionId"));
  11218. transactionIdIsNULL = FALSE;
  11219. }
  11220. }
  11221. json_object_put(RemoteStopTransaction);
  11222. if(transactionIdIsNULL == FALSE)
  11223. {
  11224. for(int gun_index=0;gun_index < gunTotalNumber;gun_index++)
  11225. {
  11226. if(ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId == transactionIdInt)
  11227. {
  11228. //check Transaction active
  11229. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  11230. {
  11231. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  11232. {
  11233. tempIndex = ((gun_index==2) ? 1: 0);
  11234. }
  11235. else
  11236. {
  11237. tempIndex = gun_index;
  11238. }
  11239. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  11240. {
  11241. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  11242. {
  11243. if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_TERMINATING)) // SYS_MODE_CHARGING, SYS_MODE_TERMINATING
  11244. {
  11245. match = TRUE;
  11246. GunNO = gun_index;
  11247. }
  11248. }
  11249. }// END FOR CHAdeMO_QUANTITY
  11250. }
  11251. else if(gunType[gun_index] == GUN_TYPE_CCS)
  11252. {
  11253. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  11254. {
  11255. tempIndex = ((gun_index==2) ? 1: 0);
  11256. }
  11257. else
  11258. {
  11259. tempIndex = gun_index;
  11260. }
  11261. for (int index = 0; index < CCS_QUANTITY; index++)
  11262. {
  11263. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  11264. {
  11265. if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_TERMINATING) ) // SYS_MODE_CHARGING, SYS_MODE_TERMINATING
  11266. {
  11267. match = TRUE;
  11268. GunNO = gun_index;
  11269. }
  11270. }
  11271. }// END FOR CCS_QUANTITY
  11272. }
  11273. else if(gunType[gun_index] == GUN_TYPE_GBT)
  11274. {
  11275. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  11276. {
  11277. tempIndex = ((gun_index==2) ? 1: 0);
  11278. }
  11279. else
  11280. {
  11281. tempIndex = gun_index;
  11282. }
  11283. for (int index = 0; index < GB_QUANTITY; index++)
  11284. {
  11285. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  11286. {
  11287. if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_TERMINATING)) // SYS_MODE_CHARGING, SYS_MODE_TERMINATING
  11288. {
  11289. match = TRUE;
  11290. GunNO = gun_index;
  11291. }
  11292. }
  11293. }// END FOR GB_QUANTITY
  11294. }
  11295. else if(gunType[gun_index] == GUN_TYPE_DO)
  11296. {
  11297. tempIndex = gun_index;
  11298. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  11299. {
  11300. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  11301. {
  11302. 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
  11303. {
  11304. match = TRUE;
  11305. GunNO = gun_index;
  11306. }
  11307. }
  11308. }// END FOR GB_QUANTITY
  11309. }
  11310. else
  11311. {
  11312. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D') // 'D' means DC
  11313. {
  11314. tempIndex = 2;
  11315. }
  11316. else
  11317. {
  11318. tempIndex = gun_index;
  11319. }
  11320. for (int index = 0; index < AC_QUANTITY; index++)
  11321. {
  11322. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  11323. {
  11324. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_TERMINATING)) // SYS_MODE_CHARGING, SYS_MODE_TERMINATING
  11325. {
  11326. match = TRUE;
  11327. GunNO = gun_index;
  11328. }
  11329. }
  11330. }// END FOR CHAdeMO_QUANTITY
  11331. } // END FOR AC ELSE
  11332. }// CHECK IF ResponseTransactionId == transactionIdInt
  11333. }//END FOR
  11334. if( match == TRUE)
  11335. {
  11336. ShmOCPP16Data->CsMsg.bits[GunNO].RemoteStopTransactionReq = 1; // inform csu of StopTransaction
  11337. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Accepted]);
  11338. sprintf((char *)ShmOCPP16Data->RemoteStopTransaction[GunNO].ResponseStatus, "%s" ,comfirmstr);
  11339. }
  11340. else
  11341. {
  11342. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  11343. }
  11344. }
  11345. else
  11346. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  11347. sendRemoteStopTransactionConfirmation(uuid, comfirmstr);
  11348. return result;
  11349. }
  11350. int handleReserveNowTransactionRequest(char *uuid, char *payload)
  11351. {
  11352. mtrace();
  11353. int result = FAIL;
  11354. int connectorIdInt=0, reservationIdInt=0;
  11355. int tempIndex = 0;
  11356. char expiryDatestr[30]={0}, idTagstr[20]={0},parentIdTagstr[20]={0};
  11357. char comfirmstr[20]={0};
  11358. char sstr[180]={ 0 },sstrtemp[200]={ 0 };
  11359. int c = 0;
  11360. char *loc;
  11361. //char *ptr;
  11362. DEBUG_INFO("handleReserveNowTransactionRequest ...\n");
  11363. strcpy(sstrtemp, stringtrimspace(payload));
  11364. //***(1)connectorId ****/
  11365. c=0;
  11366. loc = strstr(sstrtemp, "connectorId");
  11367. memset(sstr ,0, ARRAY_SIZE(sstr) );
  11368. while ((loc != NULL) &&(loc[strlen("connectorId")+2+c] != ',') && (loc[strlen("connectorId")+2+c] != '}'))
  11369. {
  11370. sstr[c] = loc[strlen("connectorId")+2+c];
  11371. //printf("i=%d sstr=%c\n",c, sstr[c]);
  11372. c++;
  11373. }
  11374. sstr[c] = '\0';
  11375. connectorIdInt = atoi(sstr);
  11376. //***(2)expiryDate ****/
  11377. loc = strstr(sstrtemp, "expiryDate");
  11378. memset(sstr ,0, ARRAY_SIZE(sstr) );
  11379. c = 0;
  11380. while ((loc != NULL) &&(loc[3+strlen("expiryDate")+c] != '\"'))
  11381. {
  11382. sstr[c] = loc[3+strlen("expiryDate")+c];
  11383. c++;
  11384. }
  11385. sstr[c] = '\0';
  11386. strcpy(expiryDatestr, sstr);
  11387. //***(3)idTag ****/
  11388. loc = strstr(sstrtemp, "idTag");
  11389. memset(sstr ,0, ARRAY_SIZE(sstr) );
  11390. c = 0;
  11391. while ((loc != NULL) &&(loc[3+strlen("idTag")+c] != '\"'))
  11392. {
  11393. sstr[c] = loc[3+strlen("idTag")+c];
  11394. c++;
  11395. }
  11396. sstr[c] = '\0';
  11397. strcpy(idTagstr, sstr);
  11398. //***(4)parentIdTag ****/
  11399. loc = strstr(sstrtemp, "parentIdTag");
  11400. memset(sstr ,0, ARRAY_SIZE(sstr) );
  11401. c = 0;
  11402. if(loc == NULL)
  11403. {
  11404. strcpy(parentIdTagstr, "");
  11405. }
  11406. else
  11407. {
  11408. while ((loc != NULL) &&(loc[3+strlen("parentIdTag")+c] != '\"'))
  11409. {
  11410. sstr[c] = loc[3+strlen("parentIdTag")+c];
  11411. c++;
  11412. }
  11413. sstr[c] = '\0';
  11414. strcpy(parentIdTagstr, sstr);
  11415. }
  11416. //***(5)reservationId ****/
  11417. c=0;
  11418. loc = strstr(sstrtemp, "reservationId");
  11419. memset(sstr ,0, ARRAY_SIZE(sstr) );
  11420. while ((loc != NULL) &&((loc[strlen("reservationId")+2+c] != '}') && (loc[strlen("reservationId")+2+c] != ',')))
  11421. {
  11422. sstr[c] = loc[strlen("reservationId")+2+c];
  11423. //printf("i=%d sstr=%c\n",c, sstr[c]);
  11424. c++;
  11425. }
  11426. sstr[c] = '\0';
  11427. reservationIdInt = atoi(sstr);
  11428. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  11429. /*
  11430. enum SYSTEM_STATUS
  11431. {
  11432. SYS_MODE_BOOTING = 0,
  11433. SYS_MODE_IDLE = 1,
  11434. SYS_MODE_AUTHORIZING = 2,
  11435. SYS_MODE_MODE_REASSIGN_CHECK = 3,
  11436. SYS_MODE_REASSIGN = 4,
  11437. SYS_MODE_PREPARING = 5,
  11438. SYS_MODE_PREPARE_FOR_EV = 6,
  11439. SYS_MODE_PREPARE_FOR_EVSE = 7,
  11440. SYS_MODE_CHARGING = 8,
  11441. SYS_MODE_TERMINATING = 9,
  11442. SYS_MODE_COMPLETE = 10,
  11443. SYS_MODE_ALARM = 11,
  11444. SYS_MODE_FAULT = 12,
  11445. SYS_MODE_RESERVATION = 13,
  11446. SYS_MODE_BOOKING = 14,
  11447. SYS_MODE_MAINTAIN = 15,
  11448. SYS_MODE_DEBUG = 16,
  11449. SYS_MODE_CCS_PRECHARGE_STEP0 = 17,
  11450. SYS_MODE_CCS_PRECHARGE_STEP1 = 18,
  11451. SYS_MODE_UPDATE = 19
  11452. };
  11453. */
  11454. if((connectorIdInt == 0) &&(strcmp((const char *)ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemData, "FALSE") == 0)) //For OCTT Test case
  11455. {
  11456. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  11457. goto end;
  11458. }
  11459. if((connectorIdInt > 0) && ((connectorIdInt -1) <= gunTotalNumber))
  11460. {
  11461. //check Transaction active
  11462. if(gunType[connectorIdInt -1] == GUN_TYPE_CHAdeMO)
  11463. {
  11464. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  11465. {
  11466. tempIndex = (((connectorIdInt -1)==2) ? 1: 0);
  11467. }
  11468. else
  11469. {
  11470. tempIndex = connectorIdInt -1;
  11471. }
  11472. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  11473. {
  11474. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  11475. {
  11476. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ReservationId)
  11477. {
  11478. if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_FAULT)&&(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_ALARM)) //S_FAULT
  11479. {
  11480. if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_IDLE) //S_IDLE
  11481. {
  11482. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  11483. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  11484. }
  11485. 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'))
  11486. {
  11487. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  11488. }
  11489. else if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_PREPARING) || (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_RESERVATION) ) //S_PRECHARGE
  11490. {
  11491. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  11492. }
  11493. else
  11494. {
  11495. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  11496. }
  11497. }
  11498. 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
  11499. {
  11500. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  11501. }
  11502. }
  11503. else
  11504. {
  11505. //replace reservation
  11506. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  11507. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  11508. }
  11509. }
  11510. } // END FOR CHAdeMO_QUANTITY
  11511. }
  11512. else if(gunType[connectorIdInt -1] == GUN_TYPE_CCS)
  11513. {
  11514. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  11515. {
  11516. tempIndex = (((connectorIdInt -1)==2) ? 1: 0);
  11517. }
  11518. else
  11519. {
  11520. tempIndex = connectorIdInt -1;
  11521. }
  11522. for (int index = 0; index < CCS_QUANTITY; index++)
  11523. {
  11524. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  11525. {
  11526. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ReservationId)
  11527. {
  11528. //SystemStatus: 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault, 8: Reserved, 9: maintain
  11529. if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_FAULT)&&(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_ALARM)) //S_FAULT
  11530. {
  11531. if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_IDLE) //S_IDLE
  11532. {
  11533. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  11534. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  11535. }
  11536. 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'))
  11537. {
  11538. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  11539. }
  11540. else if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_PREPARING) || (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_RESERVATION)) //S_PRECHARGE
  11541. {
  11542. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  11543. }
  11544. else
  11545. {
  11546. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  11547. }
  11548. }
  11549. 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
  11550. {
  11551. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  11552. }
  11553. }
  11554. else
  11555. {
  11556. //replace reservation
  11557. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  11558. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  11559. }
  11560. }
  11561. } // END FOR CCS_QUANTITY
  11562. }
  11563. else if(gunType[connectorIdInt -1] == GUN_TYPE_GBT)
  11564. {
  11565. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  11566. {
  11567. tempIndex = (((connectorIdInt -1)==2) ? 1: 0);
  11568. }
  11569. else
  11570. {
  11571. tempIndex = connectorIdInt -1;
  11572. }
  11573. for (int index = 0; index < GB_QUANTITY; index++)
  11574. {
  11575. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  11576. {
  11577. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ReservationId)
  11578. {
  11579. //SystemStatus: 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault, 8: Reserved, 9: maintain
  11580. if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_FAULT)&&(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_ALARM)) //SYS_MODE_FAULT, SYS_MODE_ALARM
  11581. {
  11582. if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_IDLE) //S_IDLE
  11583. {
  11584. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  11585. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  11586. }
  11587. 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'))
  11588. {
  11589. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  11590. }
  11591. else if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_PREPARING) || (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_RESERVATION) ) //S_PRECHARGE
  11592. {
  11593. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  11594. }
  11595. else
  11596. {
  11597. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  11598. }
  11599. }
  11600. 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
  11601. {
  11602. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  11603. }
  11604. }
  11605. else
  11606. {
  11607. //replace reservation
  11608. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  11609. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  11610. }
  11611. }
  11612. }// END FOR GB_QUANTITY
  11613. }
  11614. else if(gunType[connectorIdInt -1] == GUN_TYPE_DO)
  11615. {
  11616. tempIndex = connectorIdInt -1;
  11617. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  11618. {
  11619. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  11620. {
  11621. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.ReservationId)
  11622. {
  11623. //SystemStatus: 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault, 8: Reserved, 9: maintain
  11624. 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
  11625. {
  11626. if(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_IDLE) //S_IDLE
  11627. {
  11628. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  11629. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  11630. }
  11631. 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'))
  11632. {
  11633. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  11634. }
  11635. else if((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_PREPARING) || (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_RESERVATION) ) //S_PRECHARGE
  11636. {
  11637. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  11638. }
  11639. else
  11640. {
  11641. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  11642. }
  11643. }
  11644. 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
  11645. {
  11646. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  11647. }
  11648. }
  11649. else
  11650. {
  11651. //replace reservation
  11652. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  11653. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  11654. }
  11655. }
  11656. }// END FOR GB_QUANTITY
  11657. }
  11658. else
  11659. {
  11660. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D') // 'D' means DC
  11661. {
  11662. tempIndex = 2;
  11663. }
  11664. else
  11665. {
  11666. tempIndex = (connectorIdInt -1);
  11667. }
  11668. for (int index = 0; index < AC_QUANTITY; index++)
  11669. {
  11670. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  11671. {
  11672. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.AcChargingData[index].ReservationId)
  11673. {
  11674. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_FAULT)&&(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_ALARM)) //SYS_MODE_FAULT, SYS_MODE_ALARM
  11675. {
  11676. if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_IDLE) //S_IDLE
  11677. {
  11678. 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))
  11679. {
  11680. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  11681. }
  11682. else
  11683. {
  11684. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  11685. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  11686. }
  11687. }
  11688. 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'))
  11689. {
  11690. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  11691. }
  11692. else if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_PREPARING) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_RESERVATION) ) //S_PRECHARGE
  11693. {
  11694. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  11695. }
  11696. else
  11697. {
  11698. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  11699. }
  11700. }
  11701. 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
  11702. {
  11703. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  11704. }
  11705. }
  11706. else
  11707. {
  11708. //replace reservation
  11709. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  11710. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  11711. }
  11712. }
  11713. } // END FOR AC_QUANTITY
  11714. }
  11715. sprintf((char *)ShmOCPP16Data->ReserveNow[connectorIdInt-1].ResponseStatus, "%s" ,comfirmstr);
  11716. }
  11717. else if(connectorIdInt == 0)
  11718. {
  11719. //check Transaction active
  11720. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  11721. {
  11722. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ReservationId)
  11723. {
  11724. 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'))
  11725. {
  11726. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  11727. goto end;
  11728. }
  11729. else if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_PREPARING) //S_PRECHARGE
  11730. {
  11731. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  11732. goto end;
  11733. }
  11734. 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
  11735. {
  11736. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  11737. goto end;
  11738. }
  11739. else if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  11740. {
  11741. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  11742. goto end;
  11743. }
  11744. }
  11745. }// END FOR CHAdeMO_QUANTITY
  11746. for (int index = 0; index < CCS_QUANTITY; index++)
  11747. {
  11748. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ReservationId)
  11749. {
  11750. 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'))
  11751. {
  11752. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  11753. goto end;
  11754. }
  11755. else if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_PREPARING) //SYS_MODE_PREPARING
  11756. {
  11757. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  11758. goto end;
  11759. }
  11760. 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
  11761. {
  11762. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  11763. goto end;
  11764. }
  11765. else if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  11766. {
  11767. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  11768. goto end;
  11769. }
  11770. }
  11771. } // END FOR CCS_QUANTITY
  11772. for (int index = 0; index < GB_QUANTITY; index++)
  11773. {
  11774. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ReservationId)
  11775. {
  11776. 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'))
  11777. {
  11778. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  11779. goto end;
  11780. }
  11781. else if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_PREPARING) //S_PRECHARGE
  11782. {
  11783. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  11784. goto end;
  11785. }
  11786. 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
  11787. {
  11788. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  11789. goto end;
  11790. }
  11791. else if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  11792. {
  11793. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  11794. goto end;
  11795. }
  11796. }
  11797. } // END FOR GB_QUANTITY
  11798. for (int index = 0; index < AC_QUANTITY; index++)
  11799. {
  11800. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.AcChargingData[index].ReservationId)
  11801. {
  11802. 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'))
  11803. {
  11804. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  11805. goto end;
  11806. }
  11807. else if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_PREPARING) //S_PRECHARGE
  11808. {
  11809. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  11810. goto end;
  11811. }
  11812. 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
  11813. {
  11814. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  11815. goto end;
  11816. }
  11817. if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_IDLE) //S_IDLE
  11818. {
  11819. 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))
  11820. {
  11821. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  11822. goto end;
  11823. }
  11824. }
  11825. else if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  11826. {
  11827. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  11828. goto end;
  11829. }
  11830. }
  11831. }// END FOR AC_QUANTITY
  11832. //The connectorId is 0
  11833. ShmOCPP16Data->CsMsg.bits[0].ReserveNowReq = 1;
  11834. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  11835. sprintf((char *)ShmOCPP16Data->ReserveNow[0].ResponseStatus, "%s" ,comfirmstr);
  11836. ShmOCPP16Data->ReserveNow[0].ConnectorId = connectorIdInt;
  11837. sprintf((char *)ShmOCPP16Data->ReserveNow[0].ExpiryDate, "%s" , expiryDatestr);
  11838. sprintf((char *)ShmOCPP16Data->ReserveNow[0].IdTag, "%s" , idTagstr);
  11839. sprintf((char *)ShmOCPP16Data->ReserveNow[0].ParentIdTag, "%s" , parentIdTagstr);
  11840. ShmOCPP16Data->ReserveNow[0].ReservationId = reservationIdInt;
  11841. strcpy((char *)ShmOCPP16Data->ReserveNow[0].guid, uuid);
  11842. result = TRUE;
  11843. return result;
  11844. }
  11845. else
  11846. {
  11847. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  11848. sprintf((char *)ShmOCPP16Data->ReserveNow[connectorIdInt-1].ResponseStatus, "%s" ,comfirmstr);
  11849. }
  11850. if(strcmp(comfirmstr,"Accepted") == 0)
  11851. {
  11852. ShmOCPP16Data->ReserveNow[connectorIdInt-1].ConnectorId = connectorIdInt;
  11853. sprintf((char *)ShmOCPP16Data->ReserveNow[connectorIdInt-1].ExpiryDate, "%s" , expiryDatestr);
  11854. sprintf((char *)ShmOCPP16Data->ReserveNow[connectorIdInt-1].IdTag, "%s" , idTagstr);
  11855. sprintf((char *)ShmOCPP16Data->ReserveNow[connectorIdInt-1].ParentIdTag, "%s" , parentIdTagstr);
  11856. ShmOCPP16Data->ReserveNow[connectorIdInt-1].ReservationId = reservationIdInt;
  11857. strcpy((char *)ShmOCPP16Data->ReserveNow[connectorIdInt-1].guid, uuid);
  11858. result = TRUE;
  11859. return result;
  11860. }
  11861. end:
  11862. sendReserveNowTransactionConfirmation(uuid,comfirmstr);
  11863. //ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].ReserveNowConf = 1;
  11864. return result;
  11865. }
  11866. int handleResetRequest(char *uuid, char *payload)
  11867. {
  11868. mtrace();
  11869. int result = FAIL;
  11870. char sstr[10]={0},sstrtemp[30]={ 0 };
  11871. char typestr[10]={0};
  11872. char comfirmstr[20]={0};
  11873. int c = 0;
  11874. char *loc;
  11875. DEBUG_INFO("handleResetRequest...\n");
  11876. strcpy(sstrtemp, stringtrimspace(payload));
  11877. loc = strstr(sstrtemp, "type");
  11878. memset(sstr ,0, ARRAY_SIZE(sstr) );
  11879. c = 0;
  11880. while (loc[3+strlen("type")+c] != '\"')
  11881. {
  11882. sstr[c] = loc[3+strlen("type")+c];
  11883. c++;
  11884. }
  11885. sstr[c] = '\0';
  11886. strcpy(typestr,sstr);
  11887. sprintf((char *)ShmOCPP16Data->Reset.Type, "%s" ,typestr);
  11888. if((strcmp(typestr, ResetTypeStr[Hard])==0) || (strcmp(typestr, ResetTypeStr[Soft])==0))
  11889. {
  11890. ShmOCPP16Data->MsMsg.bits.ResetReq = 1;
  11891. strcpy((char *)ShmOCPP16Data->Reset.guid, uuid);
  11892. strcpy(comfirmstr, ResetStatusStr[ResetStatus_Accepted]);
  11893. sprintf((char *)ShmOCPP16Data->Reset.ResponseStatus, "%s" ,comfirmstr);
  11894. }
  11895. else
  11896. {
  11897. strcpy(comfirmstr, ResetStatusStr[ResetStatus_Rejected]);
  11898. sprintf((char *)ShmOCPP16Data->Reset.ResponseStatus, "%s" ,comfirmstr);
  11899. result = PASS;
  11900. }
  11901. sendResetConfirmation(uuid, comfirmstr);
  11902. return result;
  11903. }
  11904. int handleSendLocalListRequest(char *uuid, char *payload)
  11905. {
  11906. mtrace();
  11907. int result = FAIL;
  11908. char comfirmstr[20];
  11909. int checkState_Faulted = FALSE;
  11910. json_object *SendLocalList;
  11911. DEBUG_INFO("handleSendLocalListRequest...\n");
  11912. if(strcmp((const char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "FALSE") == 0) //For OCTT Test case
  11913. {
  11914. strcpy(comfirmstr, UpdateStatusStr[UpdateStatus_NotSupported]);
  11915. goto end;
  11916. }
  11917. //check Charge Point state
  11918. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  11919. {
  11920. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_FAULT) //S_FAULT ---> Faulted
  11921. {
  11922. checkState_Faulted = TRUE; //OCPP Status: Faulted
  11923. }
  11924. }
  11925. for (int index = 0; index < CCS_QUANTITY; index++)
  11926. {
  11927. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_FAULT) //S_FAULT ---> Faulted
  11928. {
  11929. checkState_Faulted = TRUE; //OCPP Status
  11930. }
  11931. }
  11932. for (int index = 0; index < GB_QUANTITY; index++)
  11933. {
  11934. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_FAULT) //S_FAULT ---> Faulted
  11935. {
  11936. checkState_Faulted = TRUE; //OCPP Status: Faulted
  11937. }
  11938. }
  11939. //check Charge Point state
  11940. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  11941. {
  11942. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_FAULT) //S_FAULT ---> Faulted
  11943. {
  11944. checkState_Faulted = TRUE; //OCPP Status: Faulted
  11945. }
  11946. }
  11947. //check Charge Point state
  11948. for (int index = 0; index < AC_QUANTITY; index++)
  11949. {
  11950. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_FAULT) //S_FAULT ---> Faulted
  11951. {
  11952. checkState_Faulted = TRUE; //OCPP Status: Faulted
  11953. }
  11954. }
  11955. if(checkState_Faulted == TRUE)
  11956. {
  11957. strcpy(comfirmstr, UpdateStatusStr[UpdateStatus_Failed]);
  11958. goto end;
  11959. }
  11960. // Parsing payload
  11961. SendLocalList = json_tokener_parse(payload);
  11962. if(!is_error(SendLocalList))
  11963. {
  11964. // Required data
  11965. ShmOCPP16Data->SendLocalList.ListVersion = json_object_get_int(json_object_object_get(SendLocalList, "listVersion"));
  11966. sprintf((char*)ShmOCPP16Data->SendLocalList.UpdateType, "%s", json_object_get_string(json_object_object_get(SendLocalList, "updateType")));
  11967. // Optional data
  11968. if(json_object_object_get(SendLocalList, "localAuthorizationList") != NULL)
  11969. {
  11970. //Check UpdateType
  11971. if(strcmp((char*)ShmOCPP16Data->SendLocalList.UpdateType, UpdateTypeStr[Full]) == 0)
  11972. {
  11973. //Local list full update
  11974. DEBUG_INFO("Local list full update.\n");
  11975. OCPP_getListVerion();
  11976. if(ShmOCPP16Data->SendLocalList.ListVersion < locallistVersion)
  11977. {
  11978. strcpy(comfirmstr, UpdateStatusStr[UpdateStatus_Failed]);
  11979. goto end;
  11980. }
  11981. OCPP_cleanLocalList();
  11982. }
  11983. else if(strcmp((char*)ShmOCPP16Data->SendLocalList.UpdateType, UpdateTypeStr[Differential]) == 0)
  11984. {
  11985. //Local list different update
  11986. DEBUG_INFO("Local list different update.\n");
  11987. OCPP_getListVerion();
  11988. if(ShmOCPP16Data->SendLocalList.ListVersion < locallistVersion)
  11989. {
  11990. strcpy(comfirmstr, UpdateStatusStr[UpdateStatus_VersionMismatch]);
  11991. goto end;
  11992. }
  11993. }
  11994. else
  11995. {
  11996. strcpy(comfirmstr, UpdateStatusStr[UpdateStatus_NotSupported]);
  11997. goto end;
  11998. }
  11999. memset(ShmOCPP16Data->SendLocalList.LocalAuthorizationList, 0 , sizeof(struct StructLocalAuthorizationList)*1);
  12000. for(int idx=0;idx<json_object_array_length(json_object_object_get(SendLocalList, "localAuthorizationList"));idx++)
  12001. {
  12002. 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")));
  12003. if(json_object_object_get(json_object_array_get_idx(json_object_object_get(SendLocalList, "localAuthorizationList"), idx), "idTagInfo") != NULL)
  12004. {
  12005. 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")));
  12006. if(json_object_object_get(json_object_object_get(json_object_array_get_idx(json_object_object_get(SendLocalList, "localAuthorizationList"), idx), "idTagInfo"), "expiryDate") != NULL)
  12007. 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")));
  12008. if(json_object_object_get(json_object_object_get(json_object_array_get_idx(json_object_object_get(SendLocalList, "localAuthorizationList"), idx), "idTagInfo"), "parentIdTag") != NULL)
  12009. 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")));
  12010. }
  12011. // Add to db
  12012. if(strcmp((char*)ShmOCPP16Data->SendLocalList.UpdateType, UpdateTypeStr[Full]) == 0)
  12013. {
  12014. //Local list full update
  12015. DEBUG_INFO("Local list full update item: %d, listVer: %d, %s, %s, %s, %s.\n",
  12016. idx,
  12017. ShmOCPP16Data->SendLocalList.ListVersion,
  12018. ShmOCPP16Data->SendLocalList.LocalAuthorizationList[0].IdTag,
  12019. ShmOCPP16Data->SendLocalList.LocalAuthorizationList[0].IdTagInfo.ParentIdTag,
  12020. ShmOCPP16Data->SendLocalList.LocalAuthorizationList[0].IdTagInfo.ExpiryDate,
  12021. ShmOCPP16Data->SendLocalList.LocalAuthorizationList[0].IdTagInfo.Status);
  12022. // update list
  12023. OCPP_addLocalList(ShmOCPP16Data->SendLocalList.ListVersion,
  12024. (char*)ShmOCPP16Data->SendLocalList.LocalAuthorizationList[0].IdTag,
  12025. (char*)ShmOCPP16Data->SendLocalList.LocalAuthorizationList[0].IdTagInfo.ParentIdTag,
  12026. (char*)ShmOCPP16Data->SendLocalList.LocalAuthorizationList[0].IdTagInfo.ExpiryDate,
  12027. (char*)ShmOCPP16Data->SendLocalList.LocalAuthorizationList[0].IdTagInfo.Status);
  12028. }
  12029. else if(strcmp((char*)ShmOCPP16Data->SendLocalList.UpdateType, UpdateTypeStr[Differential]) == 0)
  12030. {
  12031. DEBUG_INFO("Local list diff update item: %d,listVer: %d, %s, %s, %s, %s.\n",
  12032. idx,
  12033. ShmOCPP16Data->SendLocalList.ListVersion,
  12034. ShmOCPP16Data->SendLocalList.LocalAuthorizationList[0].IdTag,
  12035. ShmOCPP16Data->SendLocalList.LocalAuthorizationList[0].IdTagInfo.ParentIdTag,
  12036. ShmOCPP16Data->SendLocalList.LocalAuthorizationList[0].IdTagInfo.ExpiryDate,
  12037. ShmOCPP16Data->SendLocalList.LocalAuthorizationList[0].IdTagInfo.Status);
  12038. OCPP_addLocalList(ShmOCPP16Data->SendLocalList.ListVersion,
  12039. (char*)ShmOCPP16Data->SendLocalList.LocalAuthorizationList[0].IdTag,
  12040. (char*)ShmOCPP16Data->SendLocalList.LocalAuthorizationList[0].IdTagInfo.ParentIdTag,
  12041. (char*)ShmOCPP16Data->SendLocalList.LocalAuthorizationList[0].IdTagInfo.ExpiryDate,
  12042. (char*)ShmOCPP16Data->SendLocalList.LocalAuthorizationList[0].IdTagInfo.Status);
  12043. }
  12044. }
  12045. }
  12046. else
  12047. {
  12048. //Check UpdateType
  12049. if(strcmp((char*)ShmOCPP16Data->SendLocalList.UpdateType, UpdateTypeStr[Full]) == 0)
  12050. {
  12051. //Local list full update
  12052. DEBUG_INFO("If no (empty) localAuthorizationList is given and the updateType is Full, all identifications are removed from the list. \n");
  12053. OCPP_cleanLocalList();
  12054. strcpy(comfirmstr, UpdateStatusStr[UpdateStatus_Accepted]);
  12055. goto end;
  12056. }
  12057. if(strcmp((char*)ShmOCPP16Data->SendLocalList.UpdateType, UpdateTypeStr[Differential]) == 0)
  12058. {
  12059. //Local list different update
  12060. DEBUG_INFO("Requesting a Differential update without (empty) localAuthorizationList will have no effect on the list\n");
  12061. strcpy(comfirmstr, UpdateStatusStr[UpdateStatus_Accepted]);
  12062. goto end;
  12063. }
  12064. }
  12065. result = PASS;
  12066. }
  12067. strcpy(comfirmstr, UpdateStatusStr[UpdateStatus_Accepted]);
  12068. end:
  12069. json_object_put(SendLocalList);
  12070. sendSendLocalListConfirmation(uuid, comfirmstr);
  12071. return result;
  12072. }
  12073. int handleSetChargingProfileRequest(char *uuid, char *payload)
  12074. {
  12075. mtrace();
  12076. int result = FAIL;
  12077. struct StructSetChargingProfile SetProfileReq = {0};
  12078. int tempchargingProfileIdInt;
  12079. int chargingSchedulePeriodCount = 0;
  12080. char comfirmstr[20]={0};
  12081. char tempfile[] = "/Storage/OCPP/SetChargingProfiletemp.json";
  12082. char rmFileCmd[128]={0};
  12083. int profileQuantity = 0;
  12084. json_object *SetChargingProfile;
  12085. DEBUG_INFO("handleSetChargingProfileRequest\n");
  12086. SetChargingProfile = json_tokener_parse(payload);
  12087. if(!is_error(SetChargingProfile))
  12088. {
  12089. if(json_object_object_get(SetChargingProfile, "connectorId") != NULL)
  12090. {
  12091. SetProfileReq.ConnectorId = json_object_get_int(json_object_object_get(SetChargingProfile, "connectorId"));
  12092. }
  12093. if(json_object_object_get(SetChargingProfile, "csChargingProfiles") != NULL)
  12094. {
  12095. if(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingProfileId") != NULL)
  12096. {
  12097. SetProfileReq.ChargingProfile.ChargingProfileId = json_object_get_int(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingProfileId"));
  12098. }
  12099. if(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "stackLevel") != NULL)
  12100. {
  12101. SetProfileReq.ChargingProfile.StackLevel = json_object_get_int(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "stackLevel"));
  12102. }
  12103. if(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingProfilePurpose") != NULL)
  12104. {
  12105. strcpy((char*)SetProfileReq.ChargingProfile.ChargingProfilePurpose, json_object_get_string(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingProfilePurpose")));
  12106. }
  12107. if(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingProfileKind") != NULL)
  12108. {
  12109. strcpy((char*)SetProfileReq.ChargingProfile.ChargingProfileKind, json_object_get_string(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingProfileKind")));
  12110. }
  12111. if(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "transactionId") != NULL)
  12112. {
  12113. SetProfileReq.ChargingProfile.TransactionId = json_object_get_int(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "transactionId"));
  12114. }
  12115. if(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "recurrencyKind") != NULL)
  12116. {
  12117. strcpy((char*)SetProfileReq.ChargingProfile.RecurrencyKind, json_object_get_string(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "recurrencyKind")));
  12118. }
  12119. if(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "validFrom") != NULL)
  12120. {
  12121. strcpy((char*)SetProfileReq.ChargingProfile.ValidFrom, json_object_get_string(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "validFrom")));
  12122. }
  12123. if(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "validTo") != NULL)
  12124. {
  12125. strcpy((char*)SetProfileReq.ChargingProfile.ValidTo, json_object_get_string(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "validTo")));
  12126. }
  12127. if(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingSchedule") != NULL)
  12128. {
  12129. if(json_object_object_get(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingSchedule"), "chargingRateUnit") != NULL)
  12130. {
  12131. 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")));
  12132. }
  12133. if(json_object_object_get(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingSchedule"), "duration") != NULL)
  12134. {
  12135. SetProfileReq.ChargingProfile.ChargingSchedule.Duration = json_object_get_int(json_object_object_get(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingSchedule"), "duration"));
  12136. }
  12137. if(json_object_object_get(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingSchedule"), "minChargingRate") != NULL)
  12138. {
  12139. SetProfileReq.ChargingProfile.ChargingSchedule.MinChargingRate = json_object_get_double(json_object_object_get(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingSchedule"), "minChargingRate"));
  12140. }
  12141. if(json_object_object_get(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingSchedule"), "startSchedule") != NULL)
  12142. {
  12143. 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")));
  12144. }
  12145. if(json_object_object_get(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod") != NULL)
  12146. {
  12147. chargingSchedulePeriodCount = json_object_array_length(json_object_object_get(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"));
  12148. if(chargingSchedulePeriodCount <= 10)
  12149. {
  12150. 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++)
  12151. {
  12152. 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)
  12153. {
  12154. 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"));
  12155. }
  12156. 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)
  12157. {
  12158. 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"));
  12159. }
  12160. 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)
  12161. {
  12162. 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"));
  12163. }
  12164. }
  12165. }
  12166. }
  12167. }
  12168. }
  12169. }
  12170. // Profile periods quantity check
  12171. if( chargingSchedulePeriodCount > atoi((const char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemData))
  12172. {
  12173. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  12174. DEBUG_WARN("Profile period is over limit %s. \n", ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemData);
  12175. goto end;
  12176. }
  12177. // Check invalid limit
  12178. if(ShmSysConfigAndInfo->SysConfig.ModelName[0] == 'A')
  12179. {
  12180. for(uint8_t idxPeriod=0;idxPeriod<chargingSchedulePeriodCount;idxPeriod++)
  12181. {
  12182. 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)))) ||
  12183. (SetProfileReq.ChargingProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit > (SetProfileReq.ChargingProfile.ChargingSchedule.ChargingRateUnit[0]=='W'?modelnameInfo.ratedPower:ShmSysConfigAndInfo->SysConfig.RatingCurrent)))
  12184. {
  12185. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  12186. DEBUG_WARN("Profile period-%02d is invalid limit: %.2f %s with phase %d.\n", idxPeriod,
  12187. SetProfileReq.ChargingProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit,
  12188. SetProfileReq.ChargingProfile.ChargingSchedule.ChargingRateUnit,
  12189. (SetProfileReq.ChargingProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases==0?3:SetProfileReq.ChargingProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases));
  12190. goto end;
  12191. }
  12192. }
  12193. }
  12194. else
  12195. {
  12196. for(uint8_t idxPeriod=0;idxPeriod<chargingSchedulePeriodCount;idxPeriod++)
  12197. {
  12198. 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))
  12199. {
  12200. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  12201. DEBUG_WARN("Profile period-%02d is invalid limit: %.2f %s with phase %d.\n", idxPeriod,
  12202. SetProfileReq.ChargingProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit,
  12203. SetProfileReq.ChargingProfile.ChargingSchedule.ChargingRateUnit,
  12204. (SetProfileReq.ChargingProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases==0?3:SetProfileReq.ChargingProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases));
  12205. goto end;
  12206. }
  12207. }
  12208. }
  12209. // Profile purpose info check
  12210. if(strcmp((char*)SetProfileReq.ChargingProfile.ChargingProfilePurpose, ChargingProfilePurposeTypeStr[ChargePointMaxProfile]) == 0)
  12211. {
  12212. FILE *fp;
  12213. char dataLine[4096]={0};
  12214. DEBUG_INFO("Profile purpose is ChargePointMaxProfile.\n");
  12215. if(SetProfileReq.ConnectorId != 0)
  12216. {
  12217. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  12218. DEBUG_WARN("Profile connector id is not 0.\n");
  12219. goto end;
  12220. }
  12221. fp = fopen(ChargePointMaxProfile_JSON, "r");
  12222. if (!fp)
  12223. {
  12224. DEBUG_INFO("%s does not create.\n", ChargePointMaxProfile_JSON);
  12225. fp = fopen(ChargePointMaxProfile_JSON, "w+");
  12226. }
  12227. else
  12228. {
  12229. while(fscanf(fp, "%s", dataLine) != EOF)
  12230. {
  12231. if(strstr(dataLine, "chargingProfileId")!= NULL)
  12232. {
  12233. profileQuantity += 1;
  12234. }
  12235. }
  12236. }
  12237. fclose(fp);
  12238. }
  12239. else if(strcmp((char*)SetProfileReq.ChargingProfile.ChargingProfilePurpose, ChargingProfilePurposeTypeStr[TxDefaultProfile]) == 0)
  12240. {
  12241. FILE *fp;
  12242. char dataLine[4096]={0};
  12243. char filename[128]={0};
  12244. int tmpProfileQuantity;
  12245. DEBUG_INFO("Profile purpose is TxDefaultProfile.\n");
  12246. if((SetProfileReq.ConnectorId != 0) && (SetProfileReq.ConnectorId > gunTotalNumber))
  12247. {
  12248. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  12249. DEBUG_WARN("Profile connector id is over max gun number.\n");
  12250. goto end;
  12251. }
  12252. if(SetProfileReq.ConnectorId == 0)
  12253. {
  12254. for(int idxCon=1;idxCon<=gunTotalNumber;idxCon++)
  12255. {
  12256. tmpProfileQuantity = 0;
  12257. memset(filename, 0, ARRAY_SIZE(filename));
  12258. sprintf(filename, "/Storage/OCPP/TxDefaultProfile_%d.json", idxCon);
  12259. fp = fopen(filename, "r");
  12260. if (!fp)
  12261. {
  12262. DEBUG_INFO("%s does not create.\n", filename);
  12263. fp = fopen(filename, "w+");
  12264. }
  12265. else
  12266. {
  12267. while(fscanf(fp, "%s", dataLine) != EOF)
  12268. {
  12269. if(strstr(dataLine, "chargingProfileId")!= NULL)
  12270. {
  12271. tmpProfileQuantity += 1;
  12272. }
  12273. }
  12274. }
  12275. fclose(fp);
  12276. profileQuantity = (profileQuantity < tmpProfileQuantity) ? tmpProfileQuantity : profileQuantity;
  12277. }
  12278. }
  12279. else
  12280. {
  12281. memset(filename, 0, ARRAY_SIZE(filename));
  12282. sprintf(filename, "/Storage/OCPP/TxDefaultProfile_%d.json", SetProfileReq.ConnectorId);
  12283. fp = fopen(filename, "r");
  12284. if (!fp)
  12285. {
  12286. DEBUG_INFO("%s does not create.\n", filename);
  12287. fp = fopen(filename, "w+");
  12288. }
  12289. else
  12290. {
  12291. while(fscanf(fp, "%s", dataLine) != EOF)
  12292. {
  12293. if(strstr(dataLine, "chargingProfileId")!= NULL)
  12294. {
  12295. profileQuantity += 1;
  12296. }
  12297. }
  12298. }
  12299. fclose(fp);
  12300. }
  12301. }
  12302. else if(strcmp((char*)SetProfileReq.ChargingProfile.ChargingProfilePurpose, ChargingProfilePurposeTypeStr[TxProfile]) == 0)
  12303. {
  12304. int isMatchTransactiodId= FALSE;
  12305. FILE *fp;
  12306. char dataLine[4096]={0};
  12307. char filename[128]={0};
  12308. DEBUG_INFO("Profile purposeStr is TxProfile.\n");
  12309. //---TxProfile SHALL only be set at Charge Point ConnectorId > 0. ---//
  12310. if(SetProfileReq.ConnectorId == 0)
  12311. {
  12312. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  12313. DEBUG_WARN("Profile connector id is 0.\n");
  12314. goto end;
  12315. }
  12316. int tempIndex = 0;
  12317. //check Transaction active
  12318. if(gunType[SetProfileReq.ConnectorId -1] == GUN_TYPE_CHAdeMO)
  12319. {
  12320. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  12321. {
  12322. tempIndex = (((SetProfileReq.ConnectorId -1)==2) ? 1: 0);
  12323. }
  12324. else
  12325. {
  12326. tempIndex = SetProfileReq.ConnectorId -1;
  12327. }
  12328. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  12329. {
  12330. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  12331. {
  12332. if((SYS_MODE_PREPARING <= ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus) && (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus <= SYS_MODE_TERMINATING)) // S_CHARGING
  12333. {
  12334. if(SetProfileReq.ChargingProfile.TransactionId == ShmOCPP16Data->StartTransaction[SetProfileReq.ConnectorId -1].ResponseTransactionId)
  12335. {
  12336. isMatchTransactiodId = TRUE;
  12337. break;
  12338. }
  12339. }
  12340. }
  12341. }
  12342. }
  12343. else if(gunType[SetProfileReq.ConnectorId -1] == GUN_TYPE_CCS)
  12344. {
  12345. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  12346. {
  12347. tempIndex = (((SetProfileReq.ConnectorId -1)==2) ? 1: 0);
  12348. }
  12349. else
  12350. {
  12351. tempIndex = SetProfileReq.ConnectorId -1;
  12352. }
  12353. for (int index = 0; index < CCS_QUANTITY; index++)
  12354. {
  12355. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  12356. {
  12357. if(((SYS_MODE_PREPARING <= ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus) && (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus <= SYS_MODE_TERMINATING)) ||
  12358. ((SYS_MODE_CCS_PRECHARGE_STEP0 <= ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus) && (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus <= SYS_MODE_CCS_PRECHARGE_STEP1))) // S_CHARGING
  12359. {
  12360. if(SetProfileReq.ChargingProfile.TransactionId == ShmOCPP16Data->StartTransaction[SetProfileReq.ConnectorId -1].ResponseTransactionId)
  12361. {
  12362. isMatchTransactiodId = TRUE;
  12363. break;
  12364. }
  12365. }
  12366. }
  12367. }
  12368. }
  12369. else if(gunType[SetProfileReq.ConnectorId -1] == GUN_TYPE_GBT)
  12370. {
  12371. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  12372. {
  12373. tempIndex = (((SetProfileReq.ConnectorId -1)==2) ? 1: 0);
  12374. }
  12375. else
  12376. {
  12377. tempIndex = SetProfileReq.ConnectorId -1;
  12378. }
  12379. for (int index = 0; index < GB_QUANTITY; index++)
  12380. {
  12381. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  12382. {
  12383. if((SYS_MODE_PREPARING <= ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus) && (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus <= SYS_MODE_TERMINATING)) // S_CHARGING
  12384. {
  12385. if(SetProfileReq.ChargingProfile.TransactionId == ShmOCPP16Data->StartTransaction[SetProfileReq.ConnectorId -1].ResponseTransactionId)
  12386. {
  12387. isMatchTransactiodId = TRUE;
  12388. break;
  12389. }
  12390. }
  12391. }
  12392. }
  12393. }
  12394. else if(gunType[SetProfileReq.ConnectorId -1] == GUN_TYPE_DO)
  12395. {
  12396. tempIndex = SetProfileReq.ConnectorId -1;
  12397. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  12398. {
  12399. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  12400. {
  12401. if(((SYS_MODE_PREPARING <= ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus) && (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus <= SYS_MODE_TERMINATING)) ||
  12402. ((SYS_MODE_CCS_PRECHARGE_STEP0 <= ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus) && (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus <= SYS_MODE_CCS_PRECHARGE_STEP1))) // S_CHARGING
  12403. {
  12404. if(SetProfileReq.ChargingProfile.TransactionId == ShmOCPP16Data->StartTransaction[SetProfileReq.ConnectorId -1].ResponseTransactionId)
  12405. {
  12406. isMatchTransactiodId = TRUE;
  12407. break;
  12408. }
  12409. }
  12410. }
  12411. }
  12412. }
  12413. else
  12414. {
  12415. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D') // 'D' means DC
  12416. {
  12417. tempIndex = 2;
  12418. }
  12419. else
  12420. {
  12421. tempIndex = (SetProfileReq.ConnectorId -1);
  12422. }
  12423. for (int index = 0; index < AC_QUANTITY; index++)
  12424. {
  12425. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  12426. {
  12427. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_TERMINATING)) // S_CHARGING
  12428. {
  12429. if(SetProfileReq.ChargingProfile.TransactionId == ShmOCPP16Data->StartTransaction[SetProfileReq.ConnectorId -1].ResponseTransactionId)
  12430. {
  12431. isMatchTransactiodId = TRUE;
  12432. break;
  12433. }
  12434. }
  12435. }
  12436. }
  12437. }
  12438. //check Transaction active
  12439. if(isMatchTransactiodId == FALSE)
  12440. {
  12441. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  12442. DEBUG_WARN("Tx profile transaction id is not match.\n");
  12443. goto end;
  12444. }
  12445. if((SetProfileReq.ConnectorId != 0) && (SetProfileReq.ConnectorId > gunTotalNumber))
  12446. {
  12447. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  12448. DEBUG_WARN("Connector id is over max gun number.\n");
  12449. goto end;
  12450. }
  12451. sprintf(filename, "/Storage/OCPP/TxProfile_%d.json", SetProfileReq.ConnectorId);
  12452. fp = fopen(filename, "r");
  12453. if (!fp)
  12454. {
  12455. DEBUG_INFO("%s does not create.\n", filename);
  12456. fp = fopen(filename, "w+");
  12457. }
  12458. else
  12459. {
  12460. //Check Charging Profile Count
  12461. while(fscanf(fp, "%s", dataLine) != EOF)
  12462. {
  12463. //DEBUG_INFO("word=%s\n",word);
  12464. if(strstr(dataLine, "chargingProfileId")!= NULL)
  12465. {
  12466. profileQuantity += 1;
  12467. }
  12468. }
  12469. }
  12470. fclose(fp);
  12471. }
  12472. // Check ChargeProfileMaxStackLevel
  12473. DEBUG_INFO("%s profile quantity: %d\n", SetProfileReq.ChargingProfile.ChargingProfilePurpose, profileQuantity);
  12474. if(profileQuantity >= atoi((const char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemData))
  12475. {
  12476. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  12477. DEBUG_WARN("Purpose profile quantify is over stack limit %s.\n", ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemData);
  12478. goto end;
  12479. }
  12480. //------------------------------Satrt: Check Configuration Key "MaxChargingProfilesInstalled" Logic---------------------------------------//
  12481. {
  12482. FILE *fp;
  12483. char dataLine[4096]={0};
  12484. char fnametemp[128]={0};
  12485. int tmpProfileQuantity;
  12486. //Check ChargePointMaxProfile.json exit
  12487. profileQuantity = 0;
  12488. if((access("/Storage/OCPP/ChargePointMaxProfile.json",F_OK))!=-1)
  12489. {
  12490. fp = fopen("/Storage/OCPP/ChargePointMaxProfile.json", "r");
  12491. //Check Charging Profile Count
  12492. tmpProfileQuantity = 0;
  12493. while(fscanf(fp, "%s", dataLine) != EOF)
  12494. {
  12495. if(strstr(dataLine, "chargingProfileId")!= NULL)
  12496. {
  12497. profileQuantity += 1;
  12498. tmpProfileQuantity += 1;
  12499. }
  12500. memset(dataLine, 0, ARRAY_SIZE(dataLine));
  12501. }
  12502. fclose(fp);
  12503. DEBUG_INFO("ChargePointMaxProfile.json has %d charging Profile\n", tmpProfileQuantity);
  12504. }
  12505. //Check TxDefaultProfile_%d.json
  12506. for(int idxCon=1; idxCon <= gunTotalNumber; idxCon++)
  12507. {
  12508. memset(fnametemp, 0, ARRAY_SIZE(fnametemp));
  12509. sprintf(fnametemp, "/Storage/OCPP/TxDefaultProfile_%d.json", idxCon);
  12510. if((access(fnametemp,F_OK))!=-1)
  12511. {
  12512. fp = fopen(fnametemp, "r");
  12513. //Check Charging Profile Count
  12514. tmpProfileQuantity = 0;
  12515. while(fscanf(fp, "%s", dataLine) != EOF)
  12516. {
  12517. //DEBUG_INFO("word=%s\n",word);
  12518. if(strstr(dataLine, "chargingProfileId")!= NULL)
  12519. {
  12520. profileQuantity += 1;
  12521. tmpProfileQuantity += 1;
  12522. }
  12523. memset(dataLine, 0, ARRAY_SIZE(dataLine));
  12524. }
  12525. fclose(fp);
  12526. DEBUG_INFO("%s has %d charging Profile\n",fnametemp, tmpProfileQuantity);
  12527. }
  12528. }
  12529. //Check TxProfile_%d.json
  12530. for(int idxCon=1; idxCon <= gunTotalNumber; idxCon++)
  12531. {
  12532. memset(fnametemp, 0, ARRAY_SIZE(fnametemp));
  12533. sprintf(fnametemp, "/Storage/OCPP/TxProfile_%d.json", idxCon);
  12534. if((access(fnametemp,F_OK))!=-1)
  12535. {
  12536. fp = fopen(fnametemp, "r");
  12537. //Check Charging Profile Count
  12538. tmpProfileQuantity = 0;
  12539. while(fscanf(fp, "%s", dataLine) != EOF)
  12540. {
  12541. if(strstr(dataLine, "chargingProfileId")!= NULL)
  12542. {
  12543. profileQuantity += 1;
  12544. tmpProfileQuantity += 1;
  12545. }
  12546. memset(dataLine, 0, ARRAY_SIZE(dataLine));
  12547. }
  12548. fclose(fp);
  12549. DEBUG_INFO("%s has %d charging Profile\n",fnametemp, tmpProfileQuantity);
  12550. }
  12551. }
  12552. DEBUG_INFO("All purpose profile quantity: %d\n", profileQuantity);
  12553. if(profileQuantity > atoi((const char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemData))
  12554. {
  12555. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  12556. DEBUG_WARN("Total profile quantify is over installed limit %s.\n", ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemData);
  12557. goto end;
  12558. }
  12559. }
  12560. //------------------------------End: Check Configuration Key "MaxChargingProfilesInstalled" Logic---------------------------------------//
  12561. //**********************************Write to File********************************************************/
  12562. {
  12563. FILE *infile;
  12564. FILE *outfile;
  12565. char dataLine[4096]={0};
  12566. char filename[128]={0};
  12567. int chkChar=0;
  12568. for(int idxCon=1; idxCon <= (SetProfileReq.ConnectorId==0?gunTotalNumber:1); idxCon++)
  12569. {
  12570. if(strcmp((char*)SetProfileReq.ChargingProfile.ChargingProfilePurpose, ChargingProfilePurposeTypeStr[ChargePointMaxProfile]) == 0)
  12571. {
  12572. sprintf(filename, "%s", ChargePointMaxProfile_JSON);
  12573. }
  12574. else if(strcmp((char*)SetProfileReq.ChargingProfile.ChargingProfilePurpose, ChargingProfilePurposeTypeStr[TxDefaultProfile]) == 0)
  12575. {
  12576. if(SetProfileReq.ConnectorId==0)
  12577. sprintf(filename, "/Storage/OCPP/TxDefaultProfile_%d.json", idxCon);
  12578. else
  12579. sprintf(filename, "/Storage/OCPP/TxDefaultProfile_%d.json", SetProfileReq.ConnectorId);
  12580. }
  12581. else
  12582. {
  12583. sprintf(filename, "/Storage/OCPP/TxProfile_%d.json", SetProfileReq.ConnectorId);
  12584. }
  12585. infile = fopen (filename, "r");
  12586. outfile = fopen (tempfile, "w");
  12587. chkChar = fgetc(infile);
  12588. rewind(infile);
  12589. if(chkChar == EOF)
  12590. {
  12591. // Profile is empty
  12592. if((strcmp((char*)SetProfileReq.ChargingProfile.ChargingProfilePurpose, ChargingProfilePurposeTypeStr[TxDefaultProfile]) == 0) && (SetProfileReq.ConnectorId==0))
  12593. json_object_object_add(SetChargingProfile, "connectorId", json_object_new_int(idxCon));
  12594. fprintf(outfile,"%s\n",json_object_to_json_string_ext(SetChargingProfile, JSON_C_TO_STRING_PLAIN));
  12595. fclose(infile);
  12596. fclose(outfile);
  12597. sprintf(rmFileCmd,"rm -f %s",filename);
  12598. system(rmFileCmd);
  12599. rename(tempfile, filename);
  12600. }
  12601. else
  12602. {
  12603. // Profile is not empty
  12604. int ChargingProfileAdded = FALSE;
  12605. while (fgets(dataLine, ARRAY_SIZE(dataLine), infile) != NULL)
  12606. {
  12607. dataLine[strlen(dataLine) - 1] = '\0'; // eat the newline fgets() stores
  12608. json_object *tmpChargingProfile;
  12609. tmpChargingProfile = json_tokener_parse(dataLine);
  12610. if(!is_error(SetChargingProfile))
  12611. {
  12612. if(json_object_object_get(tmpChargingProfile, "csChargingProfiles") != NULL)
  12613. {
  12614. if(json_object_object_get(json_object_object_get(tmpChargingProfile, "csChargingProfiles"), "chargingProfileId") != NULL)
  12615. {
  12616. tempchargingProfileIdInt = json_object_get_int(json_object_object_get(json_object_object_get(tmpChargingProfile, "csChargingProfiles"), "chargingProfileId"));
  12617. }
  12618. }
  12619. }
  12620. json_object_put(tmpChargingProfile);
  12621. if((tempchargingProfileIdInt == SetProfileReq.ChargingProfile.ChargingProfileId))
  12622. {
  12623. if(ChargingProfileAdded == FALSE)
  12624. {
  12625. if((strcmp((char*)SetProfileReq.ChargingProfile.ChargingProfilePurpose, ChargingProfilePurposeTypeStr[TxDefaultProfile]) == 0) && (SetProfileReq.ConnectorId==0))
  12626. json_object_object_add(SetChargingProfile, "connectorId", json_object_new_int(idxCon));
  12627. fprintf(outfile,"%s\n",json_object_to_json_string_ext(SetChargingProfile, JSON_C_TO_STRING_PLAIN));
  12628. ChargingProfileAdded = TRUE;
  12629. }
  12630. }
  12631. else
  12632. {
  12633. fprintf(outfile,"%s\n",dataLine);
  12634. if(ChargingProfileAdded == FALSE)
  12635. {
  12636. if((strcmp((char*)SetProfileReq.ChargingProfile.ChargingProfilePurpose, ChargingProfilePurposeTypeStr[TxDefaultProfile]) == 0) && (SetProfileReq.ConnectorId==0))
  12637. json_object_object_add(SetChargingProfile, "connectorId", json_object_new_int(idxCon));
  12638. fprintf(outfile,"%s\n",json_object_to_json_string_ext(SetChargingProfile, JSON_C_TO_STRING_PLAIN));
  12639. ChargingProfileAdded = TRUE;
  12640. }
  12641. }
  12642. } // end of while loop
  12643. fclose(infile);
  12644. fclose(outfile);
  12645. sprintf(rmFileCmd,"rm -f %s",filename);
  12646. system(rmFileCmd);
  12647. rename(tempfile, filename);
  12648. }
  12649. }
  12650. sleep(1);
  12651. result = TRUE;
  12652. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Accepted] );
  12653. }
  12654. end:
  12655. json_object_put(SetChargingProfile);
  12656. if(strcmp(comfirmstr, ChargingProfileStatusStr[ChargingProfileStatus_Accepted]) == 0)
  12657. {
  12658. if(SetProfileReq.ConnectorId == 0)
  12659. {
  12660. for(uint8_t idx=0;idx<gunTotalNumber;idx++)
  12661. {
  12662. checkCompositeSchedule((idx+1), 86400, &ShmOCPP16Data->SmartChargingProfile[idx], TRUE);
  12663. }
  12664. }
  12665. else
  12666. checkCompositeSchedule(SetProfileReq.ConnectorId, 86400, &ShmOCPP16Data->SmartChargingProfile[SetProfileReq.ConnectorId-1], TRUE);
  12667. }
  12668. sendSetChargingProfileConfirmation(uuid, comfirmstr);
  12669. system("/bin/fsync -d /dev/mtdblock13;/bin/sync &");
  12670. return result;
  12671. }
  12672. int handleTriggerMessageRequest(char *uuid, char *payload)
  12673. {
  12674. mtrace();
  12675. int result = FAIL;
  12676. int connectorIdIsNULL = FALSE;
  12677. int connectorIdInt =0;
  12678. char sstr[40]={0},sstrtemp[100]={ 0 };
  12679. char requestedMessagestr[40]={0};
  12680. char comfirmstr[20]={0};
  12681. int c = 0;
  12682. char *loc;
  12683. DEBUG_INFO("handleTriggerMessageRequest\n");
  12684. //[2,"266e23f4-27a4-41cf-84cb-aadf56b9523f","TriggerMessage",{"requestedMessage":"DiagnosticsStatusNotification","connectorId":1}]
  12685. strcpy(sstrtemp, stringtrimspace(payload));
  12686. c = 0;
  12687. loc = strstr(sstrtemp, "requestedMessage");
  12688. while (loc[3+strlen("requestedMessage")+c] != '\"')
  12689. {
  12690. sstr[c] = loc[3+strlen("requestedMessage")+c];
  12691. c++;
  12692. }
  12693. sstr[c] = '\0';
  12694. strcpy(requestedMessagestr, sstr);
  12695. c = 0;
  12696. loc = strstr(sstrtemp, "connectorId");
  12697. if(loc == NULL)
  12698. {
  12699. connectorIdIsNULL = TRUE;
  12700. }
  12701. else
  12702. {
  12703. memset(sstr ,0, ARRAY_SIZE(sstr) );
  12704. while ((loc[strlen("connectorId")+2+c] != ',')&&(loc[strlen("connectorId")+2+c] != '}'))
  12705. {
  12706. sstr[c] = loc[strlen("connectorId")+2+c];
  12707. //printf("i=%d sstr=%c\n",c, sstr[c]);
  12708. c++;
  12709. }
  12710. sstr[c] = '\0';
  12711. connectorIdInt = atoi(sstr);
  12712. }
  12713. if((connectorIdIsNULL == TRUE) || ((connectorIdIsNULL == FALSE) && ((connectorIdInt > 0) && (connectorIdInt <= gunTotalNumber /*(CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY)*/ ))) )
  12714. {
  12715. sprintf((char *)ShmOCPP16Data->TriggerMessage[connectorIdInt -1].RequestedMessage, "%s" ,requestedMessagestr);
  12716. ShmOCPP16Data->TriggerMessage[connectorIdInt -1].ConnectorId = connectorIdInt;
  12717. if((strcmp(requestedMessagestr, MessageTriggerStr[FirmwareStatusNotification]) != 0) &&
  12718. (strcmp(requestedMessagestr, MessageTriggerStr[DiagnosticsStatusNotification]) != 0) &&
  12719. (strcmp(requestedMessagestr, MessageTriggerStr[BootNotification]) != 0 ) &&
  12720. (strcmp(requestedMessagestr, MessageTriggerStr[Heartbeat]) != 0) &&
  12721. (strcmp(requestedMessagestr, MessageTriggerStr[MeterValues]) != 0) &&
  12722. (strcmp(requestedMessagestr, MessageTriggerStr[StatusNotification]) != 0 ))
  12723. {
  12724. sprintf(comfirmstr, "%s",TriggerMessageStatusStr[TriggerMessageStatus_NotImplemented] );
  12725. sendTriggerMessageConfirmation(uuid,comfirmstr);
  12726. return TRUE;
  12727. }
  12728. else
  12729. {
  12730. sprintf(comfirmstr, "%s",TriggerMessageStatusStr[TriggerMessageStatus_Accepted] );
  12731. sendTriggerMessageConfirmation(uuid,comfirmstr);
  12732. }
  12733. }
  12734. else if(connectorIdIsNULL == FALSE && ((connectorIdInt <= 0) || (connectorIdInt > gunTotalNumber /*(CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY)*/) ))
  12735. {
  12736. sprintf(comfirmstr, "%s",TriggerMessageStatusStr[TriggerMessageStatus_Rejected] );
  12737. sendTriggerMessageConfirmation(uuid,comfirmstr);
  12738. return TRUE;
  12739. }
  12740. //==========================
  12741. // Trigger message
  12742. //==========================
  12743. if( strcmp(requestedMessagestr, MessageTriggerStr[FirmwareStatusNotification]) == 0)
  12744. {
  12745. if((strlen((char*)ShmOCPP16Data->FirmwareStatusNotification.Status) == 0) ||
  12746. ((FirmwareStatusNotificationStatus != FIRMWARE_STATUS_DOWNLOADING) && (FirmwareStatusNotificationStatus != FIRMWARE_STATUS_DOWNLOADED) && (FirmwareStatusNotificationStatus != FIRMWARE_STATUS_IDLE) && (FirmwareStatusNotificationStatus != FIRMWARE_STATUS_INSTALLING)))
  12747. {
  12748. FirmwareStatusNotificationStatus = FIRMWARE_STATUS_IDLE;
  12749. sprintf((char*)ShmOCPP16Data->FirmwareStatusNotification.Status, "%s", FirmwareStatusStr[FirmwareStatus_Idle]);
  12750. }
  12751. ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationReq = 1;
  12752. }
  12753. else if(strcmp(requestedMessagestr, MessageTriggerStr[DiagnosticsStatusNotification]) == 0 )
  12754. {
  12755. if(strlen((char*)ShmOCPP16Data->DiagnosticsStatusNotification.Status) == 0)
  12756. sprintf((char*)ShmOCPP16Data->DiagnosticsStatusNotification.Status, "%s", DiagnosticsStatusStr[DiagnosticsStatus_Idle]);
  12757. ShmOCPP16Data->SpMsg.bits.DiagnosticsStatusNotificationReq = 1;
  12758. }
  12759. else if(strcmp(requestedMessagestr, MessageTriggerStr[BootNotification]) == 0 )
  12760. {
  12761. //sendBootNotificationRequest();
  12762. server_sign = FALSE;
  12763. }
  12764. else if(strcmp(requestedMessagestr, MessageTriggerStr[Heartbeat]) == 0 )
  12765. {
  12766. refreshStartTimer(&clientTime.Heartbeat);
  12767. clientTime.Heartbeat.tv_sec -= ShmOCPP16Data->BootNotification.ResponseHeartbeatInterval;
  12768. }
  12769. else if (strcmp(requestedMessagestr, MessageTriggerStr[MeterValues]) == 0 )
  12770. {
  12771. if(connectorIdIsNULL == FALSE)
  12772. {
  12773. if((connectorIdInt > 0) && ((connectorIdInt -1) < gunTotalNumber))
  12774. {
  12775. //sendMeterValuesRequest((connectorIdInt -1), ReadingContext_Trigger);
  12776. cpinitateMsg.bits[connectorIdInt -1].TriggerMeterValue = 1;
  12777. }
  12778. }
  12779. else
  12780. {
  12781. for(int idx=0;idx< gunTotalNumber;idx++)
  12782. {
  12783. //sendMeterValuesRequest(idx, ReadingContext_Trigger);
  12784. cpinitateMsg.bits[idx].TriggerMeterValue = 1;
  12785. }
  12786. }
  12787. }
  12788. else if(strcmp(requestedMessagestr, MessageTriggerStr[StatusNotification]) == 0 )
  12789. {
  12790. if(connectorIdIsNULL == FALSE)
  12791. {
  12792. if((connectorIdInt > 0) && ((connectorIdInt-1) < gunTotalNumber))
  12793. {
  12794. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].TriggerMessageReq = 1;
  12795. cpinitateMsg.bits[connectorIdInt-1].TriggerStatusNotificationReq = 1;
  12796. //clientTime.StatusNotification[connectorIdInt-1] = time((time_t*)NULL);
  12797. }
  12798. }
  12799. else
  12800. {
  12801. for(int idx=0;idx< gunTotalNumber;idx++)
  12802. {
  12803. ShmOCPP16Data->CsMsg.bits[idx].TriggerMessageReq = 1;
  12804. cpinitateMsg.bits[idx].TriggerStatusNotificationReq = 1;
  12805. //clientTime.StatusNotification[idx] = time((time_t*)NULL);
  12806. }
  12807. }
  12808. }
  12809. return result;
  12810. }
  12811. int handleUnlockConnectorRequest(char *uuid, char *payload)
  12812. {
  12813. mtrace();
  12814. int result = FAIL;
  12815. int connectorIdInt =0;
  12816. char comfirmstr[20]={0};
  12817. int tempIndex = 0;
  12818. json_object *UnlockConnector;
  12819. //[2,"ba1cbd49-2a76-493a-8f76-fa23e7606532","UnlockConnector",{"connectorId":1}]
  12820. DEBUG_INFO("handleUnlockConnectorRequest ...\n");
  12821. UnlockConnector = json_tokener_parse(payload);
  12822. if(!is_error(UnlockConnector))
  12823. {
  12824. if(json_object_object_get(UnlockConnector, "connectorId") != NULL)
  12825. {
  12826. connectorIdInt = json_object_get_int(json_object_object_get(UnlockConnector, "connectorId"));
  12827. }
  12828. }
  12829. json_object_put(UnlockConnector);
  12830. DEBUG_INFO("Unlock connectorIdInt = %d\n",connectorIdInt);
  12831. if(gunTotalNumber == 0)
  12832. {
  12833. sprintf(comfirmstr, "%s", UnlockStatusStr[UnlockStatus_NotSupported] );
  12834. goto end;
  12835. }
  12836. else if((connectorIdInt > gunTotalNumber/*CHAdeMO_QUANTITY+ CCS_QUANTITY + GB_QUANTITY*/) || (connectorIdInt <= 0))
  12837. {
  12838. //sprintf(comfirmstr, "%s", UnlockStatusStr[UnlockStatus_NotSupported] );
  12839. sprintf(comfirmstr, "%s", UnlockStatusStr[UnlockStatus_NotSupported] );
  12840. goto end;
  12841. }
  12842. else
  12843. {
  12844. //check Transaction active
  12845. if(gunType[connectorIdInt-1] == GUN_TYPE_CHAdeMO)
  12846. {
  12847. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  12848. {
  12849. tempIndex = (((connectorIdInt -1)==2) ? 1: 0);
  12850. }
  12851. else
  12852. {
  12853. tempIndex = connectorIdInt -1;
  12854. }
  12855. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  12856. {
  12857. if ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex ))
  12858. {
  12859. //stop Transaction
  12860. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].UnlockConnectorReq = 1;
  12861. }
  12862. }
  12863. }
  12864. else if(gunType[connectorIdInt-1] == GUN_TYPE_CCS)
  12865. {
  12866. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  12867. {
  12868. tempIndex = (((connectorIdInt -1)==2) ? 1: 0);
  12869. }
  12870. else
  12871. {
  12872. tempIndex = connectorIdInt -1;
  12873. }
  12874. for (int index = 0; index < CCS_QUANTITY; index++)
  12875. {
  12876. if ((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex ))
  12877. {
  12878. //stop Transaction
  12879. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].UnlockConnectorReq = 1;
  12880. }
  12881. }
  12882. }
  12883. else if(gunType[connectorIdInt-1] == GUN_TYPE_GBT)
  12884. {
  12885. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  12886. {
  12887. tempIndex = (((connectorIdInt -1)==2) ? 1: 0);
  12888. }
  12889. else
  12890. {
  12891. tempIndex = connectorIdInt -1;
  12892. }
  12893. for (int index = 0; index < GB_QUANTITY; index++)
  12894. {
  12895. if ((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex ))
  12896. {
  12897. //stop Transaction
  12898. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].UnlockConnectorReq = 1;
  12899. }
  12900. }
  12901. }
  12902. else if(gunType[connectorIdInt-1] == GUN_TYPE_DO)
  12903. {
  12904. tempIndex = connectorIdInt -1;
  12905. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  12906. {
  12907. if ((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex ))
  12908. {
  12909. //stop Transaction
  12910. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].UnlockConnectorReq = 1;
  12911. }
  12912. }
  12913. }
  12914. else
  12915. {
  12916. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  12917. {
  12918. tempIndex = 2;
  12919. }
  12920. else
  12921. {
  12922. tempIndex = connectorIdInt-1;
  12923. }
  12924. for (int index = 0; index < AC_QUANTITY; index++)
  12925. {
  12926. if ((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex ))
  12927. {
  12928. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].UnlockConnectorReq = 1;
  12929. }
  12930. }
  12931. }
  12932. ShmOCPP16Data->UnlockConnector[connectorIdInt-1].ConnectorId = connectorIdInt;
  12933. strcpy((char *)ShmOCPP16Data->UnlockConnector[connectorIdInt-1].guid, uuid);
  12934. result = TRUE;
  12935. return result;
  12936. }
  12937. end:
  12938. //json_object_put(obj); --- remove temporally
  12939. sendUnlockConnectorConfirmation(uuid, comfirmstr);
  12940. return result;
  12941. }
  12942. static char UpdateFirmwarepayloadData[300]={0};
  12943. int handleUpdateFirmwareRequest(char *uuid, char *payload)
  12944. {
  12945. mtrace();
  12946. int result = FAIL;
  12947. pthread_t t;
  12948. sendUpdateFirmwareConfirmation(uuid);
  12949. memset(UpdateFirmwarepayloadData, 0, 300);
  12950. strcpy(UpdateFirmwarepayloadData, stringtrimspace(payload));
  12951. if(!interLock.isUpdateFirmwareGoing)
  12952. {
  12953. interLock.isUpdateFirmwareGoing = 1;
  12954. pthread_create(&t, NULL, UpdateFirmwareProcess, stringtrimspace(payload));
  12955. sleep(1);
  12956. }
  12957. else
  12958. DEBUG_WARN("Other UpdateFirmware request on going.\n");
  12959. ShmOCPP16Data->MsMsg.bits.UpdateFirmwareConf =1;
  12960. return result;
  12961. }
  12962. void *UpdateFirmwareProcess(void *data)
  12963. {
  12964. pthread_detach(pthread_self());
  12965. mtrace();
  12966. int retriesInt =0, retryIntervalInt=0;
  12967. char protocol[10], user[64],password[64],host[128], path[512], ftppath[512],host1[128],path1[512];
  12968. int port=0;
  12969. char locationstr[1024]={0}, retrieveDatestr[36]={0};
  12970. int isSuccess = 0;
  12971. char ftpbuf[1024];
  12972. char temp[1024];
  12973. char * pch;
  12974. DEBUG_INFO("handleUpdateFirmwareRequest ...\n");
  12975. json_object *UpdateFirmware;
  12976. UpdateFirmware = json_tokener_parse(UpdateFirmwarepayloadData);
  12977. if(!is_error(UpdateFirmware))
  12978. {
  12979. // Required data
  12980. if(json_object_object_get(UpdateFirmware, "location") != NULL)
  12981. sprintf((char*)locationstr, "%s", json_object_get_string(json_object_object_get(UpdateFirmware, "location")));
  12982. if(json_object_object_get(UpdateFirmware, "retrieveDate") != NULL)
  12983. sprintf((char*)retrieveDatestr, "%s", json_object_get_string(json_object_object_get(UpdateFirmware, "retrieveDate")));
  12984. // Optional data
  12985. if(json_object_object_get(UpdateFirmware, "retries"))
  12986. {
  12987. retriesInt = json_object_get_int(json_object_object_get(UpdateFirmware, "retries"));
  12988. }
  12989. if(json_object_object_get(UpdateFirmware, "retryInterval"))
  12990. {
  12991. retryIntervalInt = json_object_get_int(json_object_object_get(UpdateFirmware, "retryInterval"));
  12992. }
  12993. }
  12994. json_object_put(UpdateFirmware);
  12995. memset(ftppath, 0, ARRAY_SIZE(ftppath));
  12996. memset(path, 0, ARRAY_SIZE(path));
  12997. // Wait retrieveData
  12998. if(strlen(retrieveDatestr) > 10)
  12999. {
  13000. do
  13001. {
  13002. sleep(1);
  13003. }while(!isOvertNow((uint8_t*)retrieveDatestr));
  13004. }
  13005. // Ready to download
  13006. system("rm -f /mnt/*");
  13007. if(strncmp(locationstr,"http", 4) == 0)
  13008. {
  13009. sscanf(locationstr,"%[^:]:%*2[/]%[^/]/%199[^\n]", protocol, host, path);
  13010. sprintf(ftppath,"/%s", path);
  13011. DEBUG_INFO("locationstr: %s\n", locationstr);
  13012. DEBUG_INFO("protocol: %s\n",protocol);
  13013. DEBUG_INFO("host: %s\n",host);
  13014. DEBUG_INFO("path: %s\n",path);
  13015. DEBUG_INFO("ftppath: %s\n",ftppath);
  13016. int ftppathlen=strlen(ftppath);
  13017. int i=1;
  13018. char filenametemp[50];
  13019. while(i < ftppathlen)
  13020. {
  13021. int len=ftppathlen-i;
  13022. if(ftppath[len]== 47) // '/' ascll code: 47
  13023. {
  13024. DEBUG_INFO("compare '/' all right\n");
  13025. break;
  13026. }
  13027. i=i+1;
  13028. }
  13029. memset(filenametemp, 0, ARRAY_SIZE(filenametemp));
  13030. strncpy(filenametemp, ftppath+(ftppathlen-i+1), i+1);
  13031. filenametemp[i+1] = 0;
  13032. do
  13033. {
  13034. sprintf((char*)ShmOCPP16Data->FirmwareStatusNotification.Status, "%s",FirmwareStatusStr[FirmwareStatus_Downloading]);
  13035. ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationReq = 1;
  13036. sleep(1);
  13037. isSuccess = httpDownLoadFile(host, ftppath, filenametemp, locationstr);
  13038. if(!isSuccess)
  13039. {
  13040. sprintf((char*)ShmOCPP16Data->FirmwareStatusNotification.Status, "%s",FirmwareStatusStr[FirmwareStatus_DownloadFailed]);
  13041. ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationReq = 1;
  13042. if(retriesInt>0)sleep(retryIntervalInt);else sleep(1);
  13043. sprintf((char*)ShmOCPP16Data->FirmwareStatusNotification.Status, "%s",FirmwareStatusStr[FirmwareStatus_Idle]);
  13044. ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationReq = 1;
  13045. }
  13046. else
  13047. {
  13048. sprintf((char*)ShmOCPP16Data->FirmwareStatusNotification.Status, "%s",FirmwareStatusStr[FirmwareStatus_Downloaded]);
  13049. ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationReq = 1;
  13050. }
  13051. retriesInt--;
  13052. }while((isSuccess == 0)&&(retriesInt >= 0));
  13053. }
  13054. else if(strncmp(locationstr,"ftp", 3) == 0) // ftp
  13055. {
  13056. memset(ftpbuf, 0, ARRAY_SIZE(ftpbuf));
  13057. memset(temp, 0, ARRAY_SIZE(temp));
  13058. //DEBUG_INFO("locationstr=%s\n",locationstr);
  13059. strcpy(ftpbuf, locationstr/*"ftp://ipc_ui:pht2016@ftp.phihong.com.tw/DC/log/DemoDC1_2018-07-13_185011_PSULog.zip"*/ );
  13060. int ftppathlen=strlen(ftpbuf);
  13061. int i=1;
  13062. char filenametemp[50];
  13063. while(i < ftppathlen)
  13064. {
  13065. int len=ftppathlen-i;
  13066. if(ftpbuf[len]== 47) // '/' ascll code: 47
  13067. {
  13068. DEBUG_INFO(" compare '/' all right\n");
  13069. break;
  13070. }
  13071. i=i+1;
  13072. }
  13073. memset(filenametemp, 0, ARRAY_SIZE(filenametemp));
  13074. strncpy(filenametemp, ftpbuf+(ftppathlen-i+1), i+1);
  13075. filenametemp[i+1] = 0;
  13076. strncpy(temp, ftpbuf, ftppathlen-i+1);
  13077. pch=strchr(temp,'@');
  13078. if(pch==NULL)
  13079. {
  13080. sscanf(temp,"%[^:]:%*2[/]%[^:]:%i/%[a-zA-Z0-9._/-]",
  13081. protocol, host, &port, path);
  13082. strcpy(user,"anonymous");
  13083. strcpy(password,"");
  13084. }
  13085. else
  13086. {
  13087. sscanf(temp,"%[^:]:%*2[/]%[^:]:%[^@]@%[^:]:%i/%199[^\n]",
  13088. protocol, user, password, host, &port, path);
  13089. }
  13090. sscanf(host,"%[^/]%s",host1, path1);
  13091. sprintf(ftppath,"%s", path1);
  13092. //DEBUG_INFO("protocol =%s\n",protocol);
  13093. //DEBUG_INFO("user =%s\n",user);
  13094. //DEBUG_INFO("password =%s\n",password);
  13095. //DEBUG_INFO("host1 =%s\n",host1);
  13096. //DEBUG_INFO("port =%d\n",port);
  13097. //DEBUG_INFO("path1 =%s\n",path1);
  13098. //DEBUG_INFO("ftppath=%s\n",ftppath);
  13099. //ftpFile(host, user, password, port, ftppath, fname);
  13100. //download firmware pthred
  13101. if(port == 0)
  13102. {
  13103. port = 21;
  13104. }
  13105. do
  13106. {
  13107. sprintf((char*)ShmOCPP16Data->FirmwareStatusNotification.Status, "%s",FirmwareStatusStr[FirmwareStatus_Downloading]);
  13108. ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationReq = 1;
  13109. sleep(1);
  13110. isSuccess = ftpDownLoadFile(host1, user, password, port, ftppath, filenametemp, locationstr);
  13111. if(!isSuccess)
  13112. {
  13113. //BulldogUtil.sleepMs(interval*1000);
  13114. DEBUG_INFO("Update firmware request and download file fail.\n");
  13115. sprintf((char*)ShmOCPP16Data->FirmwareStatusNotification.Status, "%s",FirmwareStatusStr[FirmwareStatus_DownloadFailed]);
  13116. ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationReq = 1;
  13117. if(retriesInt>0)sleep(retryIntervalInt);else sleep(1);
  13118. sprintf((char*)ShmOCPP16Data->FirmwareStatusNotification.Status, "%s",FirmwareStatusStr[FirmwareStatus_Idle]);
  13119. ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationReq = 1;
  13120. }
  13121. else
  13122. {
  13123. sprintf((char*)ShmOCPP16Data->FirmwareStatusNotification.Status, "%s",FirmwareStatusStr[FirmwareStatus_Downloaded]);
  13124. ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationReq = 1;
  13125. }
  13126. retriesInt--;
  13127. }while((!isSuccess)&&(retriesInt >= 0));
  13128. }
  13129. else
  13130. {
  13131. sprintf((char*)ShmOCPP16Data->FirmwareStatusNotification.Status, "%s",FirmwareStatusStr[FirmwareStatus_DownloadFailed]);
  13132. ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationReq = 1;
  13133. sleep(1);
  13134. sprintf((char*)ShmOCPP16Data->FirmwareStatusNotification.Status, "%s",FirmwareStatusStr[FirmwareStatus_Idle]);
  13135. ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationReq = 1;
  13136. }
  13137. if(strstr((char*)ShmOCPP16Data->FirmwareStatusNotification.Status, FirmwareStatusStr[FirmwareStatus_Downloaded]) != NULL)ShmOCPP16Data->MsMsg.bits.UpdateFirmwareReq = 1;
  13138. interLock.isUpdateFirmwareGoing = 0;
  13139. pthread_exit(NULL);
  13140. }
  13141. int handleCertificateSignedRequest(char *uuid, char *payload)
  13142. {
  13143. mtrace();
  13144. int result = PASS;
  13145. json_object *CertificateSigned;
  13146. DEBUG_INFO("handleCertificateSignedRequest...\n");
  13147. CertificateSigned = json_tokener_parse(payload);
  13148. if(!is_error(CertificateSigned))
  13149. {
  13150. sprintf((char*)ShmOCPP16Data->CertificateSigned.certificateChain, "%s", json_object_get_string(json_object_object_get(CertificateSigned, "certificateChain")));
  13151. }
  13152. json_object_put(CertificateSigned);
  13153. FILE *fp = fopen("/Storage/OCPP/certCP.crt", "w");
  13154. fprintf(fp, "%s", ShmOCPP16Data->CertificateSigned.certificateChain);
  13155. fclose(fp);
  13156. system("/bin/fsync -d /dev/mtdblock13;/bin/sync &");
  13157. ShmOCPP16Data->MsMsg.bits.CertificateSignedReq = 1;
  13158. sprintf((char*)ShmOCPP16Data->CertificateSigned.Response_status, "Accepted");
  13159. sendCertificateSignedConfirmation(uuid);
  13160. return result;
  13161. }
  13162. int handleDeleteCertificateRequest(char *uuid, char *payload)
  13163. {
  13164. mtrace();
  13165. int result = PASS;
  13166. json_object *DeleteCertificate;
  13167. DEBUG_INFO("handleDeleteCertificateRequest...\n");
  13168. DeleteCertificate = json_tokener_parse(payload);
  13169. if(!is_error(DeleteCertificate))
  13170. {
  13171. sprintf((char*)ShmOCPP16Data->DeleteCertificate.certificateHashData.hashAlgorithm, "%s", json_object_get_string(json_object_object_get(json_object_object_get(DeleteCertificate, "certificateHashData"), "hashAlgorithm")));
  13172. sprintf((char*)ShmOCPP16Data->DeleteCertificate.certificateHashData.issuerNameHash, "%s", json_object_get_string(json_object_object_get(json_object_object_get(DeleteCertificate, "certificateHashData"), "issuerNameHash")));
  13173. sprintf((char*)ShmOCPP16Data->DeleteCertificate.certificateHashData.issuerKeyHash, "%s", json_object_get_string(json_object_object_get(json_object_object_get(DeleteCertificate, "certificateHashData"), "issuerKeyHash")));
  13174. sprintf((char*)ShmOCPP16Data->DeleteCertificate.certificateHashData.serialNumber, "%s", json_object_get_string(json_object_object_get(json_object_object_get(DeleteCertificate, "certificateHashData"), "serialNumber")));
  13175. }
  13176. json_object_put(DeleteCertificate);
  13177. /*
  13178. * TODO: Delete certificateSigned process
  13179. */
  13180. ShmOCPP16Data->MsMsg.bits.DeleteCertificateReq = 1;
  13181. DEBUG_INFO("hashAlgorithm: %s\n", ShmOCPP16Data->DeleteCertificate.certificateHashData.hashAlgorithm);
  13182. DEBUG_INFO("issuerNameHash: %s\n", ShmOCPP16Data->DeleteCertificate.certificateHashData.issuerNameHash);
  13183. DEBUG_INFO("issuerKeyHash: %s\n", ShmOCPP16Data->DeleteCertificate.certificateHashData.issuerKeyHash);
  13184. DEBUG_INFO("serialNumber: %s\n", ShmOCPP16Data->DeleteCertificate.certificateHashData.serialNumber);
  13185. sprintf((char*)ShmOCPP16Data->DeleteCertificate.Response_status, "NotFound");
  13186. sendDeleteCertificateConfirmation(uuid);
  13187. return result;
  13188. }
  13189. int handleExtendedTriggerMessageRequest(char *uuid, char *payload)
  13190. {
  13191. mtrace();
  13192. int result = PASS;
  13193. json_object *ExtendedTriggerMessage;
  13194. DEBUG_INFO("handleExtendedTriggerMessageRequest...\n");
  13195. ExtendedTriggerMessage = json_tokener_parse(payload);
  13196. if(!is_error(ExtendedTriggerMessage))
  13197. {
  13198. sprintf((char*)ShmOCPP16Data->ExtendedTriggerMessage.requestedMessage, "%s", json_object_get_string(json_object_object_get(ExtendedTriggerMessage, "requestedMessage")));
  13199. if(json_object_object_get(ExtendedTriggerMessage, "connectorId") != NULL)
  13200. {
  13201. ShmOCPP16Data->ExtendedTriggerMessage.connectorId = json_object_get_int(json_object_object_get(ExtendedTriggerMessage, "connectorId"));
  13202. }
  13203. else
  13204. {
  13205. ShmOCPP16Data->ExtendedTriggerMessage.connectorId = -1;
  13206. }
  13207. }
  13208. json_object_put(ExtendedTriggerMessage);
  13209. DEBUG_INFO("requestedMessage: %s\n", ShmOCPP16Data->ExtendedTriggerMessage.requestedMessage);
  13210. DEBUG_INFO("connectorIdInt: %d\n", ShmOCPP16Data->ExtendedTriggerMessage.connectorId);
  13211. if((ShmOCPP16Data->ExtendedTriggerMessage.connectorId == 0) || (ShmOCPP16Data->ExtendedTriggerMessage.connectorId > gunTotalNumber))
  13212. {
  13213. sprintf((char*)ShmOCPP16Data->ExtendedTriggerMessage.Response_status, TriggerMessageStatusStr[TriggerMessageStatus_Rejected]);
  13214. }
  13215. else
  13216. {
  13217. if((strcmp((char*)ShmOCPP16Data->ExtendedTriggerMessage.requestedMessage, MessageTriggerStr[BootNotification]) != 0 ) &&
  13218. (strcmp((char*)ShmOCPP16Data->ExtendedTriggerMessage.requestedMessage, "LogStatusNotification") != 0) &&
  13219. (strcmp((char*)ShmOCPP16Data->ExtendedTriggerMessage.requestedMessage, MessageTriggerStr[FirmwareStatusNotification]) != 0) &&
  13220. (strcmp((char*)ShmOCPP16Data->ExtendedTriggerMessage.requestedMessage, MessageTriggerStr[Heartbeat]) != 0) &&
  13221. (strcmp((char*)ShmOCPP16Data->ExtendedTriggerMessage.requestedMessage, MessageTriggerStr[MeterValues]) != 0) &&
  13222. (strcmp((char*)ShmOCPP16Data->ExtendedTriggerMessage.requestedMessage, "SignChargePointCertificate") != 0 ) &&
  13223. (strcmp((char*)ShmOCPP16Data->ExtendedTriggerMessage.requestedMessage, MessageTriggerStr[StatusNotification]) != 0 ))
  13224. {
  13225. sprintf((char*)ShmOCPP16Data->ExtendedTriggerMessage.Response_status, "%s",TriggerMessageStatusStr[TriggerMessageStatus_NotImplemented] );
  13226. }
  13227. else
  13228. {
  13229. sprintf((char*)ShmOCPP16Data->ExtendedTriggerMessage.Response_status, "%s",TriggerMessageStatusStr[TriggerMessageStatus_Accepted] );
  13230. }
  13231. }
  13232. sendExtendedTriggerMessageConfirmation(uuid);
  13233. //==========================
  13234. // Trigger message
  13235. //==========================
  13236. if(strcmp((char*)ShmOCPP16Data->ExtendedTriggerMessage.requestedMessage, MessageTriggerStr[BootNotification]) == 0 )
  13237. {
  13238. //sendBootNotificationRequest();
  13239. server_sign = FALSE;
  13240. }
  13241. else if( strcmp((char*)ShmOCPP16Data->ExtendedTriggerMessage.requestedMessage, "LogStatusNotification") == 0)
  13242. {
  13243. ShmOCPP16Data->SpMsg.bits.LogStatusNotificationReq = 1;
  13244. }
  13245. else if( strcmp((char*)ShmOCPP16Data->ExtendedTriggerMessage.requestedMessage, MessageTriggerStr[FirmwareStatusNotification]) == 0)
  13246. {
  13247. if((strlen((char*)ShmOCPP16Data->FirmwareStatusNotification.Status) == 0) ||
  13248. ((FirmwareStatusNotificationStatus != FIRMWARE_STATUS_DOWNLOADING) && (FirmwareStatusNotificationStatus != FIRMWARE_STATUS_DOWNLOADED) && (FirmwareStatusNotificationStatus != FIRMWARE_STATUS_IDLE) && (FirmwareStatusNotificationStatus != FIRMWARE_STATUS_INSTALLING)))
  13249. {
  13250. FirmwareStatusNotificationStatus = FIRMWARE_STATUS_IDLE;
  13251. sprintf((char*)ShmOCPP16Data->FirmwareStatusNotification.Status, "%s", FirmwareStatusStr[FirmwareStatus_Idle]);
  13252. }
  13253. ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationReq = 1;
  13254. }
  13255. else if(strcmp((char*)ShmOCPP16Data->ExtendedTriggerMessage.requestedMessage, MessageTriggerStr[Heartbeat]) == 0 )
  13256. {
  13257. refreshStartTimer(&clientTime.Heartbeat);
  13258. clientTime.Heartbeat.tv_sec -= ShmOCPP16Data->BootNotification.ResponseHeartbeatInterval;
  13259. }
  13260. else if (strcmp((char*)ShmOCPP16Data->ExtendedTriggerMessage.requestedMessage, MessageTriggerStr[MeterValues]) == 0 )
  13261. {
  13262. if((ShmOCPP16Data->ExtendedTriggerMessage.connectorId > 0) && (ShmOCPP16Data->ExtendedTriggerMessage.connectorId <= gunTotalNumber))
  13263. {
  13264. cpinitateMsg.bits[ShmOCPP16Data->ExtendedTriggerMessage.connectorId-1].TriggerMeterValue = 1;
  13265. }
  13266. else
  13267. {
  13268. for(int idx=0;idx< gunTotalNumber;idx++)
  13269. {
  13270. //sendMeterValuesRequest(idx, ReadingContext_Trigger);
  13271. cpinitateMsg.bits[idx].TriggerMeterValue = 1;
  13272. }
  13273. }
  13274. }
  13275. else if(strcmp((char*)ShmOCPP16Data->ExtendedTriggerMessage.requestedMessage, "SignChargePointCertificate") == 0 )
  13276. {
  13277. ShmOCPP16Data->SpMsg.bits.SignCertificateReq = 1;
  13278. if(access("/Storage/OCPP/certCP.csr",F_OK) == -1)
  13279. {
  13280. 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\" &");
  13281. }
  13282. }
  13283. else if(strcmp((char*)ShmOCPP16Data->ExtendedTriggerMessage.requestedMessage, MessageTriggerStr[StatusNotification]) == 0 )
  13284. {
  13285. if((ShmOCPP16Data->ExtendedTriggerMessage.connectorId > 0) && (ShmOCPP16Data->ExtendedTriggerMessage.connectorId <= gunTotalNumber))
  13286. {
  13287. cpinitateMsg.bits[ShmOCPP16Data->ExtendedTriggerMessage.connectorId -1].StatusNotificationReq = 1;
  13288. }
  13289. else
  13290. {
  13291. for(int idx=0;idx< gunTotalNumber;idx++)
  13292. cpinitateMsg.bits[idx].StatusNotificationReq = 1;
  13293. }
  13294. }
  13295. return result;
  13296. }
  13297. int handleGetInstalledCertificateIdsRequest(char *uuid, char *payload)
  13298. {
  13299. mtrace();
  13300. int result = PASS;
  13301. json_object *GetInstalledCertificateIds;
  13302. DEBUG_INFO("handleGetInstalledCertificateIdsRequest...\n");
  13303. GetInstalledCertificateIds = json_tokener_parse(payload);
  13304. if(!is_error(GetInstalledCertificateIds))
  13305. {
  13306. sprintf((char*)ShmOCPP16Data->GetInstalledCertificateIds.certificateType, "%s", json_object_get_string(json_object_object_get(GetInstalledCertificateIds, "certificateType")));
  13307. }
  13308. json_object_put(GetInstalledCertificateIds);
  13309. /*
  13310. * TODO: Return installed certificate process
  13311. */
  13312. ShmOCPP16Data->MsMsg.bits.GetInstalledCertificateIdsReq = 1;
  13313. DEBUG_INFO("requestedMessage: %s\n", (char*)ShmOCPP16Data->GetInstalledCertificateIds.certificateType);
  13314. memset(ShmOCPP16Data->GetInstalledCertificateIds.Response_certificateHashData, 0x00, ARRAY_SIZE(ShmOCPP16Data->GetInstalledCertificateIds.Response_certificateHashData)*sizeof(struct CertificateHashDataType));
  13315. sprintf((char*)ShmOCPP16Data->GetInstalledCertificateIds.Response_status, "NotFound");
  13316. sendGetInstalledCertificateIdsConfirmation(uuid);
  13317. return result;
  13318. }
  13319. int handleGetLogRequest(char *uuid, char *payload)
  13320. {
  13321. mtrace();
  13322. int result = PASS;
  13323. json_object *GetLog;
  13324. DEBUG_INFO("handleGetLogRequest...\n");
  13325. GetLog = json_tokener_parse(payload);
  13326. if(!is_error(GetLog))
  13327. {
  13328. sprintf((char*)ShmOCPP16Data->GetLog.logType, "%s", json_object_get_string(json_object_object_get(GetLog, "logType")));
  13329. ShmOCPP16Data->GetLog.requestId = json_object_get_int(json_object_object_get(GetLog, "requestId"));
  13330. if(json_object_object_get(GetLog, "retries") != NULL)
  13331. {
  13332. ShmOCPP16Data->GetLog.retries = json_object_get_int(json_object_object_get(GetLog, "retries"));
  13333. }
  13334. if(json_object_object_get(GetLog, "retryInterval") != NULL)
  13335. {
  13336. ShmOCPP16Data->GetLog.retryInterval = json_object_get_int(json_object_object_get(GetLog, "retryInterval"));
  13337. }
  13338. sprintf((char*)ShmOCPP16Data->GetLog.log.remoteLocation, "%s", json_object_get_string(json_object_object_get(json_object_object_get(GetLog, "log"), "remoteLocation")));
  13339. if(json_object_object_get(json_object_object_get(GetLog, "log"), "oldestTimestamp") != NULL)
  13340. {
  13341. sprintf((char*)ShmOCPP16Data->GetLog.log.oldestTimestamp, "%s", json_object_get_string(json_object_object_get(json_object_object_get(GetLog, "log"), "oldestTimestamp")));
  13342. }
  13343. if(json_object_object_get(json_object_object_get(GetLog, "log"), "latestTimestamp") != NULL)
  13344. {
  13345. sprintf((char*)ShmOCPP16Data->GetLog.log.latestTimestamp, "%s", json_object_get_string(json_object_object_get(json_object_object_get(GetLog, "log"), "latestTimestamp")));
  13346. }
  13347. }
  13348. json_object_put(GetLog);
  13349. /*
  13350. * TODO: Upload log process
  13351. */
  13352. ShmOCPP16Data->MsMsg.bits.GetLogReq = 1;
  13353. DEBUG_INFO("logType: %s\n", ShmOCPP16Data->GetLog.logType);
  13354. DEBUG_INFO("requestId: %d\n", ShmOCPP16Data->GetLog.requestId);
  13355. DEBUG_INFO("retries: %d\n", ShmOCPP16Data->GetLog.retries);
  13356. DEBUG_INFO("retryInterval: %d\n", ShmOCPP16Data->GetLog.retryInterval);
  13357. DEBUG_INFO("remoteLocation: %s\n", ShmOCPP16Data->GetLog.log.remoteLocation);
  13358. DEBUG_INFO("oldestTimestamp: %s\n", ShmOCPP16Data->GetLog.log.oldestTimestamp);
  13359. DEBUG_INFO("latestTimestamp: %s\n", ShmOCPP16Data->GetLog.log.latestTimestamp);
  13360. sprintf((char*)ShmOCPP16Data->GetLog.Response_status, "Rejected");
  13361. sendGetLogConfirmation(uuid);
  13362. return result;
  13363. }
  13364. int handleInstallCertificateRequest(char *uuid, char *payload)
  13365. {
  13366. mtrace();
  13367. int result = PASS;
  13368. json_object *InstallCertificate;
  13369. DEBUG_INFO("handleInstallCertificateRequest...\n");
  13370. InstallCertificate = json_tokener_parse(payload);
  13371. if(!is_error(InstallCertificate))
  13372. {
  13373. sprintf((char*)ShmOCPP16Data->InstallCertificate.certificateType, "%s", json_object_get_string(json_object_object_get(InstallCertificate, "certificateType")));
  13374. sprintf((char*)ShmOCPP16Data->InstallCertificate.certificate, "%s", json_object_get_string(json_object_object_get(InstallCertificate, "certificate")));
  13375. /*
  13376. * TODO: Install certificate process
  13377. */
  13378. ShmOCPP16Data->MsMsg.bits.InstallCertificateReq = 1;
  13379. DEBUG_INFO("certificateType: %s\n", (char*)ShmOCPP16Data->InstallCertificate.certificateType);
  13380. DEBUG_INFO("certificate: %s\n", (char*)ShmOCPP16Data->InstallCertificate.certificate);
  13381. sprintf((char*)ShmOCPP16Data->InstallCertificate.Response_status, "Rejected");
  13382. sendInstallCertificateConfirmation(uuid);
  13383. }
  13384. json_object_put(InstallCertificate);
  13385. return result;
  13386. }
  13387. int handleSignedUpdateFirmwareRequest(char *uuid, char *payload)
  13388. {
  13389. mtrace();
  13390. int result = PASS;
  13391. json_object *SignedUpdateFirmware;
  13392. DEBUG_INFO("handleSignedUpdateFirmwareRequest...\n");
  13393. SignedUpdateFirmware = json_tokener_parse(payload);
  13394. if(!is_error(SignedUpdateFirmware))
  13395. {
  13396. if(json_object_object_get(SignedUpdateFirmware, "retries") != NULL)
  13397. {
  13398. ShmOCPP16Data->SignedUpdateFirmware.retries = json_object_get_int(json_object_object_get(SignedUpdateFirmware, "retries"));
  13399. }
  13400. if(json_object_object_get(SignedUpdateFirmware, "retryInterval") != NULL)
  13401. {
  13402. ShmOCPP16Data->SignedUpdateFirmware.retryInterval = json_object_get_int(json_object_object_get(SignedUpdateFirmware, "retryInterval"));
  13403. }
  13404. ShmOCPP16Data->SignedUpdateFirmware.requestId = json_object_get_int(json_object_object_get(SignedUpdateFirmware, "requestId"));
  13405. sprintf((char*)ShmOCPP16Data->SignedUpdateFirmware.firmware.location, "%s", json_object_get_string(json_object_object_get(json_object_object_get(SignedUpdateFirmware, "firmware"), "location")));
  13406. sprintf((char*)ShmOCPP16Data->SignedUpdateFirmware.firmware.retrieveDateTime, "%s", json_object_get_string(json_object_object_get(json_object_object_get(SignedUpdateFirmware, "firmware"), "retrieveDateTime")));
  13407. if(json_object_object_get(json_object_object_get(SignedUpdateFirmware, "firmware"), "installDateTime") != NULL)
  13408. {
  13409. sprintf((char*)ShmOCPP16Data->SignedUpdateFirmware.firmware.installDateTime, "%s", json_object_get_string(json_object_object_get(json_object_object_get(SignedUpdateFirmware, "firmware"), "installDateTime")));
  13410. }
  13411. sprintf((char*)ShmOCPP16Data->SignedUpdateFirmware.firmware.signingCertificate, "%s", json_object_get_string(json_object_object_get(json_object_object_get(SignedUpdateFirmware, "firmware"), "signingCertificate")));
  13412. sprintf((char*)ShmOCPP16Data->SignedUpdateFirmware.firmware.signature, "%s", json_object_get_string(json_object_object_get(json_object_object_get(SignedUpdateFirmware, "firmware"), "signature")));
  13413. }
  13414. json_object_put(SignedUpdateFirmware);
  13415. /*
  13416. * TODO: Upgrade firmware process
  13417. */
  13418. ShmOCPP16Data->MsMsg.bits.SignedUpdateFirmwareReq = 1;
  13419. DEBUG_INFO("retries: %d\n", ShmOCPP16Data->SignedUpdateFirmware.retries);
  13420. DEBUG_INFO("retryInterval: %d\n", ShmOCPP16Data->SignedUpdateFirmware.retryInterval);
  13421. DEBUG_INFO("requestId: %d\n", ShmOCPP16Data->SignedUpdateFirmware.requestId);
  13422. DEBUG_INFO("location: %s\n", ShmOCPP16Data->SignedUpdateFirmware.firmware.location);
  13423. DEBUG_INFO("retrieveDateTime: %s\n", ShmOCPP16Data->SignedUpdateFirmware.firmware.retrieveDateTime);
  13424. DEBUG_INFO("installDateTime: %s\n", ShmOCPP16Data->SignedUpdateFirmware.firmware.installDateTime);
  13425. DEBUG_INFO("signingCertificate: %s\n", ShmOCPP16Data->SignedUpdateFirmware.firmware.signingCertificate);
  13426. DEBUG_INFO("signature: %s\n", ShmOCPP16Data->SignedUpdateFirmware.firmware.signature);
  13427. sprintf((char*)ShmOCPP16Data->SignedUpdateFirmware.Response_status, "Rejected");
  13428. sendInstallCertificateConfirmation(uuid);
  13429. return result;
  13430. }
  13431. int handleUnknownRequest(char *uuid, char *payload)
  13432. {
  13433. mtrace();
  13434. int result = PASS;
  13435. DEBUG_INFO("handleUnknownRequest...\n");
  13436. sendUnknownConfirmation(uuid);
  13437. result = PASS;
  13438. return result;
  13439. }
  13440. //==========================================
  13441. // Handle server response routine
  13442. //==========================================
  13443. void handleAuthorizeResponse(char *payload, int gun_index)
  13444. {
  13445. mtrace();
  13446. char expiryDatestr[30]={0};
  13447. char parentIdTagstr[20]={0};
  13448. char statusstr[20]={0};
  13449. int expiryDateISNULL=FALSE;
  13450. int parentIdTagISNULL=FALSE;
  13451. DEBUG_INFO("handleAuthorizeResponse...\n");
  13452. json_object *Authorize;
  13453. Authorize = json_tokener_parse(payload);
  13454. if(!is_error(Authorize))
  13455. {
  13456. if(json_object_object_get(Authorize, "idTagInfo") != NULL)
  13457. {
  13458. // Required data
  13459. sprintf((char *)statusstr, "%s", json_object_get_string(json_object_object_get(json_object_object_get(Authorize,"idTagInfo"), "status")));
  13460. // Optional data
  13461. if(json_object_object_get(json_object_object_get(Authorize,"idTagInfo"), "expiryDate") != NULL)
  13462. sprintf((char *)expiryDatestr, "%s", json_object_get_string(json_object_object_get(json_object_object_get(Authorize,"idTagInfo"), "expiryDate")));
  13463. if(json_object_object_get(json_object_object_get(Authorize,"idTagInfo"), "parentIdTag") != NULL)
  13464. sprintf((char *)parentIdTagstr, "%s", json_object_get_string(json_object_object_get(json_object_object_get(Authorize,"idTagInfo"), "parentIdTag")));
  13465. }
  13466. }
  13467. json_object_put(Authorize);
  13468. if(expiryDateISNULL == FALSE)
  13469. strcpy((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.ExpiryDate, expiryDatestr);
  13470. if(parentIdTagISNULL == FALSE)
  13471. strcpy((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.ParentIdTag, parentIdTagstr);
  13472. strcpy((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.Status, statusstr);
  13473. //Update idTag information to authorization cache if supproted
  13474. if((strcmp((const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemData, "TRUE") == 0) && (ShmOCPP16Data->Authorize.ResponseIdTagInfo.ParentIdTag != NULL) && (ShmOCPP16Data->Authorize.ResponseIdTagInfo.ExpiryDate != NULL) )
  13475. {
  13476. OCPP_addLocalCache((char*)ShmOCPP16Data->Authorize.IdTag, parentIdTagstr, expiryDatestr, statusstr);
  13477. }
  13478. ShmOCPP16Data->SpMsg.bits.AuthorizeReq = 0;
  13479. ShmOCPP16Data->SpMsg.bits.AuthorizeConf = 1; // inform csu
  13480. authorizeRetryTimes = 0;
  13481. }
  13482. void handleBootNotificationResponse(char *payload, int gun_index)
  13483. {
  13484. mtrace();
  13485. char statusStr[12]={0};
  13486. char currentTimeStr[30]={0};
  13487. int intervalInt = 0;
  13488. DEBUG_INFO("handleBootNotificationResponse...\n");
  13489. json_object *BootNotification;
  13490. BootNotification = json_tokener_parse(payload);
  13491. if(!is_error(BootNotification))
  13492. {
  13493. // Required data
  13494. sprintf((char *)currentTimeStr, "%s", json_object_get_string(json_object_object_get(BootNotification,"currentTime")));
  13495. intervalInt = json_object_get_int(json_object_object_get(BootNotification,"interval"));
  13496. sprintf((char *)statusStr, "%s", json_object_get_string(json_object_object_get(BootNotification,"status")));
  13497. }
  13498. json_object_put(BootNotification);
  13499. ShmOCPP16Data->BootNotification.ResponseHeartbeatInterval = intervalInt;
  13500. BootNotificationInterval = intervalInt;
  13501. //write back to ShmOCPP16Data->BootNotification
  13502. strcpy((char *)ShmOCPP16Data->BootNotification.ResponseCurrentTime, currentTimeStr);
  13503. ShmOCPP16Data->BootNotification.ResponseHeartbeatInterval = intervalInt;
  13504. strcpy((char *)ShmOCPP16Data->BootNotification.ResponseStatus, statusStr);
  13505. if((strcmp(statusStr, RegistrationStatusStr[RegistrationStatus_Accepted]) == 0 ))
  13506. {
  13507. if((intervalInt == 0) || (intervalInt >= 10))
  13508. {
  13509. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemData, "%d", intervalInt);
  13510. HeartBeatWaitTime = intervalInt;
  13511. DEBUG_INFO("BootNotificationResponse setting interval to %d...\n",intervalInt);
  13512. }
  13513. server_sign = TRUE;
  13514. server_pending =FALSE;
  13515. }
  13516. else if(strcmp(statusStr, RegistrationStatusStr[RegistrationStatus_Pending]) == 0)
  13517. {
  13518. server_pending = TRUE;
  13519. }
  13520. syncDateTimeRTC(ShmOCPP16Data->BootNotification.ResponseCurrentTime);
  13521. srand(time(NULL));
  13522. refreshStartTimer(&clientTime.Heartbeat);
  13523. clientTime.Heartbeat.tv_sec -= (ShmOCPP16Data->BootNotification.ResponseHeartbeatInterval-((rand()%8)+3));
  13524. SetOcppConnStatus(TRUE);
  13525. ShmOCPP16Data->SpMsg.bits.BootNotificationConf = 1;
  13526. }
  13527. void handleDataTransferResponse(char *payload, int gun_index)
  13528. {
  13529. json_object *DataTransfer = json_tokener_parse(payload);
  13530. char status[32];
  13531. if(!is_error(DataTransfer))
  13532. {
  13533. // Required data
  13534. sprintf(status, "%s", json_object_get_string(json_object_object_get(DataTransfer, "status")));
  13535. DEBUG_INFO("Status: %s.\n", status);
  13536. // Optional data
  13537. if(json_object_object_get(DataTransfer, "data") != NULL)
  13538. DEBUG_INFO("Data: %s\n", json_object_get_string(json_object_object_get(DataTransfer, "data")));
  13539. // YES call_reader message confirm
  13540. if(ShmOCPP16Data->YesCustomData.CallReaderReq == 1)
  13541. {
  13542. sprintf((char *)ShmOCPP16Data->YesCustomData.CallReaderStatus, "%s",status);
  13543. ShmOCPP16Data->YesCustomData.CallReaderConf = 1;
  13544. ShmOCPP16Data->YesCustomData.CallReaderReq = 0;
  13545. DEBUG_INFO("Report CallReader status to CSU: %s\n",ShmOCPP16Data->YesCustomData.CallReaderStatus);
  13546. }
  13547. }
  13548. }
  13549. void handleDiagnosticsStatusNotificationResponse(char *payload, int gun_index)
  13550. {
  13551. DEBUG_INFO("handleDiagnosticsStatusNotificationResponse ...\n");
  13552. //struct json_object *obj;
  13553. // obj = json_tokener_parse(payload);
  13554. ShmOCPP16Data->SpMsg.bits.DiagnosticsStatusNotificationReq = 0;
  13555. ShmOCPP16Data->SpMsg.bits.DiagnosticsStatusNotificationConf = 1;
  13556. //No fields are defined.
  13557. }
  13558. void handleFirmwareStatusNotificationResponse(char *payload, int gun_index)
  13559. {
  13560. DEBUG_INFO("handleFirmwareStatusNotificationResponse ...\n");
  13561. //struct json_object *obj;
  13562. // obj = json_tokener_parse(payload);
  13563. ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationReq = 0;
  13564. ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationConf = 1;
  13565. //No fields are defined.
  13566. }
  13567. void handleHeartbeatResponse(char *payload, int gun_index)
  13568. {
  13569. mtrace();
  13570. DEBUG_INFO("handleHeartbeatResponse...\n");
  13571. json_object *Heartbeat;
  13572. Heartbeat = json_tokener_parse(payload);
  13573. if(!is_error(Heartbeat))
  13574. {
  13575. // Required data
  13576. sprintf((char *)ShmOCPP16Data->Heartbeat.ResponseCurrentTime, "%s", json_object_get_string(json_object_object_get(Heartbeat,"currentTime")));
  13577. }
  13578. json_object_put(Heartbeat);
  13579. if(FirstHeartBeat == 0)
  13580. {
  13581. FirstHeartBeat = 1;
  13582. DEBUG_INFO("FirstHeartBeat \n");
  13583. }
  13584. HeartBeatWithNOResponse = 0;
  13585. refreshStartTimer(&clientTime.Heartbeat);
  13586. syncDateTimeRTC(ShmOCPP16Data->Heartbeat.ResponseCurrentTime);
  13587. }
  13588. void handleMeterValuesResponse(char *payload, int gun_index)
  13589. {
  13590. mtrace();
  13591. DEBUG_INFO("handleMeterValuesResponse...\n");
  13592. isQueueSendable = 1;
  13593. }
  13594. void handleStartTransactionResponse(char *payload, int gun_index)
  13595. {
  13596. mtrace();
  13597. //int transactionIdInt = 0;
  13598. FILE *outfile;
  13599. char data[100]={0};
  13600. DEBUG_INFO("handleStartTransactionResponse...\n");
  13601. json_object *StartTransaction;
  13602. StartTransaction = json_tokener_parse(payload);
  13603. if(!is_error(StartTransaction))
  13604. {
  13605. // Required data
  13606. sprintf((char *)ShmOCPP16Data->StartTransaction[gun_index].ResponseIdTagInfo.Status, "%s", json_object_get_string(json_object_object_get(json_object_object_get(StartTransaction,"idTagInfo"), "status")));
  13607. ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId = json_object_get_int(json_object_object_get(StartTransaction,"transactionId"));
  13608. // Optional data
  13609. if(json_object_object_get(json_object_object_get(StartTransaction,"idTagInfo"), "expiryDate") != NULL)
  13610. sprintf((char *)ShmOCPP16Data->StartTransaction[gun_index].ResponseIdTagInfo.ExpiryDate, "%s", json_object_get_string(json_object_object_get(json_object_object_get(StartTransaction,"idTagInfo"), "expiryDate")));
  13611. if(json_object_object_get(json_object_object_get(StartTransaction,"idTagInfo"), "parentIdTag") != NULL)
  13612. sprintf((char *)ShmOCPP16Data->StartTransaction[gun_index].ResponseIdTagInfo.ParentIdTag, "%s", json_object_get_string(json_object_object_get(json_object_object_get(StartTransaction,"idTagInfo"), "parentIdTag")));
  13613. }
  13614. json_object_put(StartTransaction);
  13615. isQueueSendable = 1;
  13616. ShmOCPP16Data->CpMsg.bits[gun_index].StartTransactionConf = 1;
  13617. ShmOCPP16Data->CpMsg.bits[gun_index].StartTransactionReq = 0;
  13618. //-----------Start : write to the Queue TransactionId file -----------------//
  13619. if((access("/Storage/OCPP/QueueTransactionId",F_OK))!=-1)
  13620. {}
  13621. else
  13622. {
  13623. FILE *log = fopen("/Storage/OCPP/QueueTransactionId", "w+");
  13624. if(log == NULL)
  13625. {
  13626. DEBUG_INFO("Can't Create File QueueTransactionId \n");
  13627. return ;
  13628. }
  13629. else
  13630. {
  13631. fclose(log);
  13632. }
  13633. }
  13634. // open file for writing
  13635. //-------------Start: write to the Queue TransactionId file------------------------------------------//
  13636. if((ShmOCPP16Data->StartTransaction[gun_index].ConnectorId !=0)&&(strcmp((const char *)ShmOCPP16Data->StartTransaction[gun_index].IdTag,"")!=0)&&(ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId !=0))
  13637. {
  13638. outfile = fopen ("/Storage/OCPP/QueueTransactionId", "a");
  13639. sprintf(data,"%d,%s,%d\n", ShmOCPP16Data->StartTransaction[gun_index].ConnectorId , ShmOCPP16Data->StartTransaction[gun_index].IdTag, ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId); // GunIndex, idtag, TransactionId
  13640. fputs(data, outfile);
  13641. fclose (outfile);
  13642. }
  13643. DEBUG_INFO("idTagInfo-expiryDate: %s\n", ShmOCPP16Data->StartTransaction[gun_index].ResponseIdTagInfo.ExpiryDate);
  13644. DEBUG_INFO("idTagInfo-parentIdTag: %s\n", ShmOCPP16Data->StartTransaction[gun_index].ResponseIdTagInfo.ParentIdTag);
  13645. DEBUG_INFO("idTagInfo-status: %s\n", ShmOCPP16Data->StartTransaction[gun_index].ResponseIdTagInfo.Status);
  13646. DEBUG_INFO("transactionId: %d\n", ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId);
  13647. system("/bin/fsync -d /dev/mtdblock13;/bin/sync &");
  13648. }
  13649. void handleStatusNotificationResponse(char *payload, int gun_index)
  13650. {
  13651. mtrace();
  13652. DEBUG_INFO("handleStatusNotificationResponse...\n");
  13653. cpinitateMsg.bits[gun_index].TriggerStatusNotificationReq = 0;
  13654. cpinitateMsg.bits[gun_index].StatusNotificationReq = 0;
  13655. cpinitateMsg.bits[gun_index].StatusNotificationConf = 1;
  13656. }
  13657. void handleStopTransactionnResponse(char *payload, int gun_index)
  13658. {
  13659. mtrace();
  13660. DEBUG_INFO("handleStopTransactionnResponse...\n");
  13661. json_object *StopTransaction;
  13662. StopTransaction = json_tokener_parse(payload);
  13663. if(!is_error(StopTransaction))
  13664. {
  13665. // Optional data
  13666. if(json_object_object_get(StopTransaction, "idTagInfo") != NULL)
  13667. {
  13668. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].ResponseIdTagInfo.Status, "%s", json_object_get_string(json_object_object_get(json_object_object_get(StopTransaction,"idTagInfo"), "status")));
  13669. if(json_object_object_get(json_object_object_get(StopTransaction,"idTagInfo"), "expiryDate") != NULL)
  13670. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].ResponseIdTagInfo.ExpiryDate, "%s", json_object_get_string(json_object_object_get(json_object_object_get(StopTransaction,"idTagInfo"), "expiryDate")));
  13671. if(json_object_object_get(json_object_object_get(StopTransaction,"idTagInfo"), "parentIdTag") != NULL)
  13672. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].ResponseIdTagInfo.ParentIdTag, "%s", json_object_get_string(json_object_object_get(json_object_object_get(StopTransaction,"idTagInfo"), "parentIdTag")));
  13673. }
  13674. }
  13675. json_object_put(StopTransaction);
  13676. isQueueSendable = 1;
  13677. ShmOCPP16Data->CpMsg.bits[gun_index].StopTransactionConf = 1;
  13678. ShmOCPP16Data->CpMsg.bits[gun_index].StopTransactionReq = 0;
  13679. DEBUG_INFO("idTagInfo-expiryDate: %s\n", ShmOCPP16Data->StopTransaction[gun_index].ResponseIdTagInfo.ExpiryDate);
  13680. DEBUG_INFO("idTagInfo-parentIdTag: %s\n", ShmOCPP16Data->StopTransaction[gun_index].ResponseIdTagInfo.ParentIdTag);
  13681. DEBUG_INFO("idTagInfo-status: %s\n", ShmOCPP16Data->StopTransaction[gun_index].ResponseIdTagInfo.Status);
  13682. SetTransactionIdZero(queueOpInfo.stopTransactionId);
  13683. }
  13684. void handleLogStatusNotificationResponse(char *payload, int gun_index)
  13685. {
  13686. mtrace();
  13687. DEBUG_INFO("handleLogStatusNotificationResponse...\n");
  13688. ShmOCPP16Data->SpMsg.bits.LogStatusNotificationConf = 1;
  13689. }
  13690. void handleSecurityEventNotificationResponse(char *payload, int gun_index)
  13691. {
  13692. mtrace();
  13693. DEBUG_INFO("handleSecurityEventNotificationResponse...\n");
  13694. ShmOCPP16Data->SpMsg.bits.SecurityEventNotificationConf = 1;
  13695. }
  13696. void handleSignCertificateResponse(char *payload, int gun_index)
  13697. {
  13698. mtrace();
  13699. DEBUG_INFO("handleSignCertificateResponse...\n");
  13700. json_object *SignCertificate;
  13701. SignCertificate = json_tokener_parse(payload);
  13702. if(!is_error(SignCertificate))
  13703. {
  13704. sprintf((char*)ShmOCPP16Data->SignCertificate.Response_status, "%s", json_object_get_string(json_object_object_get(SignCertificate, "status")));
  13705. DEBUG_INFO("status: %s\n", ShmOCPP16Data->SignCertificate.Response_status);
  13706. }
  13707. json_object_put(SignCertificate);
  13708. ShmOCPP16Data->SpMsg.bits.SignCertificateConf = 1;
  13709. }
  13710. void handleSignedFirmwareStatusNotificationResponse(char *payload, int gun_index)
  13711. {
  13712. mtrace();
  13713. DEBUG_INFO("handleSignedFirmwareStatusNotificationResponse...\n");
  13714. ShmOCPP16Data->SpMsg.bits.SignedFirmwareStatusNotificationConf = 1;
  13715. }
  13716. //==========================================
  13717. // Handle Error routine
  13718. //==========================================
  13719. void handleError(char *id, char *errorCode, char *errorDescription,char *payload)
  13720. {
  13721. mtrace();
  13722. #ifdef SystemLogMessage
  13723. DEBUG_INFO("errorCode: %s\n", errorCode);
  13724. DEBUG_INFO("errorDescription: %s\n", errorDescription);
  13725. DEBUG_INFO("errorDetails: %s\n", payload);
  13726. #endif
  13727. }
  13728. //===============================================
  13729. // Common routine
  13730. //===============================================
  13731. int initialConfigurationTable(void)
  13732. {
  13733. //clock_t start_t, end_t, total_t;
  13734. FILE *fp;
  13735. FILE *outfile;
  13736. char str[512]={0};
  13737. char sstr[256]={0};
  13738. int c = 0;
  13739. char *loc;
  13740. int confVersion = 12;
  13741. DEBUG_INFO("initialConfigurationTable...version: %d\n", confVersion);
  13742. //start_t = clock();
  13743. //printf("Starting of the program, start_t = %ld\n", start_t);
  13744. memset(&(ShmOCPP16Data->ConfigurationTable), 0, sizeof(struct OCPP16ConfigurationTable) );
  13745. // Check configuration file size is correct
  13746. if((access("/Storage/OCPP/OCPPConfiguration",F_OK))!=-1)
  13747. {
  13748. struct stat st;
  13749. stat("/Storage/OCPP/OCPPConfiguration", &st);
  13750. if(st.st_size < 3100)
  13751. {
  13752. system("rm -f /Storage/OCPP/OCPPConfiguration");
  13753. DEBUG_INFO("OCPPConfiguration file size: %d is smaller than 3100 bytes, restore to default value.\n", st.st_size);
  13754. }
  13755. }
  13756. if((access("/Storage/OCPP/OCPPConfiguration",F_OK))==-1)
  13757. {
  13758. outfile = fopen("/Storage/OCPP/OCPPConfiguration" , "w+");
  13759. if(outfile == NULL)
  13760. {
  13761. DEBUG_INFO("Error opening file\n");
  13762. return FALSE;
  13763. }
  13764. /*Core Profile*/
  13765. //AllowOfflineTxForUnknownId
  13766. ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemAccessibility = 1;
  13767. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemName, "AllowOfflineTxForUnknownId");
  13768. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemData, "FALSE" );
  13769. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","AllowOfflineTxForUnknownId", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemData);
  13770. //AuthorizationCacheEnabled
  13771. ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemAccessibility = 1;
  13772. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemName, "AuthorizationCacheEnabled");
  13773. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemData, "FALSE" );
  13774. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","AuthorizationCacheEnabled", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemData);
  13775. //AuthorizeRemoteTxRequests
  13776. ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemAccessibility = 0;
  13777. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemName, "AuthorizeRemoteTxRequests");
  13778. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemData, "FALSE" );
  13779. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","AuthorizeRemoteTxRequests", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemData);
  13780. //BlinkRepeat
  13781. ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemAccessibility = 1;
  13782. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemName, "BlinkRepeat");
  13783. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemData, "0" );
  13784. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","BlinkRepeat", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemData);
  13785. //ClockAlignedDataInterval
  13786. ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemAccessibility = 1;
  13787. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemName, "ClockAlignedDataInterval");
  13788. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemData, "0" );
  13789. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ClockAlignedDataInterval", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemData);
  13790. //ConnectionTimeOut
  13791. ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemAccessibility = 1;
  13792. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemName, "ConnectionTimeOut");
  13793. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemData, "180" );
  13794. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ConnectionTimeOut", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemData);
  13795. //GetConfigurationMaxKeys
  13796. ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemAccessibility =0;
  13797. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemName, "GetConfigurationMaxKeys");
  13798. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemData, "%d", _GetConfiguration_CNT);
  13799. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","GetConfigurationMaxKeys", "true", ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemData);
  13800. // HeartbeatInterval
  13801. ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemAccessibility = 1;
  13802. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemName, "HeartbeatInterval");
  13803. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemData, "20" );
  13804. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","HeartbeatInterval", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemData);
  13805. // LightIntensity
  13806. ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemAccessibility = 1;
  13807. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemName, "LightIntensity");
  13808. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemData, "0" );
  13809. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LightIntensity", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemData);
  13810. // LocalAuthorizeOffline
  13811. ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemAccessibility = 1;
  13812. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemName, "LocalAuthorizeOffline");
  13813. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemData, "TRUE" );
  13814. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LocalAuthorizeOffline", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemData);
  13815. // LocalPreAuthorize
  13816. ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemAccessibility = 1;
  13817. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemName, "LocalPreAuthorize");
  13818. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemData, "FALSE" );
  13819. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LocalPreAuthorize", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemData);
  13820. // MaxEnergyOnInvalidId
  13821. ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemAccessibility = 1;
  13822. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemName, "MaxEnergyOnInvalidId");
  13823. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemData, "0" );
  13824. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MaxEnergyOnInvalidId", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemData);
  13825. // MeterValuesAlignedData
  13826. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemAccessibility = 1;
  13827. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemName, "MeterValuesAlignedData");
  13828. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  13829. 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" );
  13830. else
  13831. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, "Current.Import,Energy.Active.Import.Register,Energy.Active.Import.Interval,Power.Active.Import,Voltage,Current.Offered" );
  13832. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValuesAlignedData", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData);
  13833. // MeterValuesAlignedDataMaxLength
  13834. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemAccessibility = 0;
  13835. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemName, "MeterValuesAlignedDataMaxLength");
  13836. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  13837. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemData, "8" );
  13838. else
  13839. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemData, "10" );
  13840. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValuesAlignedDataMaxLength", "true", ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemData);
  13841. // MeterValuesSampledData
  13842. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemAccessibility = 1;
  13843. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemName, "MeterValuesSampledData");
  13844. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  13845. 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" );
  13846. else
  13847. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, "Current.Import,Energy.Active.Import.Register,Energy.Active.Import.Interval,Power.Active.Import,Voltage,Current.Offered" );
  13848. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValuesSampledData", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData);
  13849. // MeterValuesSampledDataMaxLength
  13850. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemAccessibility = 0;
  13851. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemName, "MeterValuesSampledDataMaxLength");
  13852. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  13853. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemData, "8" );
  13854. else
  13855. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemData, "10" );
  13856. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValuesSampledDataMaxLength", "true", ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemData);
  13857. // MeterValueSampleInterval
  13858. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemAccessibility = 1;
  13859. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemName, "MeterValueSampleInterval");
  13860. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemData, "30" );
  13861. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValueSampleInterval", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemData);
  13862. // MinimumStatusDuration
  13863. ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemAccessibility = 1;
  13864. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemName, "MinimumStatusDuration");
  13865. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemData, "120" );
  13866. server_cycle_Status = atoi((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemData); //StatusNotification cycle
  13867. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MinimumStatusDuration", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemData);
  13868. // NumberOfConnectors
  13869. ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemAccessibility = 0;
  13870. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemName, "NumberOfConnectors");
  13871. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  13872. {
  13873. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData, "%d", (CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY));
  13874. }
  13875. else
  13876. {
  13877. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData, "%d", AC_QUANTITY);
  13878. }
  13879. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","NumberOfConnectors", "true", ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData);
  13880. // ResetRetries
  13881. ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemAccessibility = 1;
  13882. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemName, "ResetRetries");
  13883. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemData, "3" );
  13884. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ResetRetries", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemData);
  13885. // ConnectorPhaseRotation
  13886. ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemAccessibility = 1;
  13887. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemName, "ConnectorPhaseRotation");
  13888. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "NotApplicable" );
  13889. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ConnectorPhaseRotation", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData);
  13890. // ConnectorPhaseRotationMaxLength
  13891. ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemAccessibility = 0;
  13892. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemName, "ConnectorPhaseRotationMaxLength");
  13893. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemData, "1" );
  13894. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ConnectorPhaseRotationMaxLength", "true", ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemData);
  13895. // StopTransactionOnEVSideDisconnect
  13896. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemAccessibility = 0;
  13897. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemName, "StopTransactionOnEVSideDisconnect");
  13898. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemData, "TRUE" );
  13899. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTransactionOnEVSideDisconnect", "true", ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemData);
  13900. // StopTransactionOnInvalidId
  13901. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemAccessibility = 1; //1;
  13902. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemName, "StopTransactionOnInvalidId");
  13903. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemData, "FALSE" );
  13904. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTransactionOnInvalidId", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemData);
  13905. // StopTxnAlignedData
  13906. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemAccessibility = 0;
  13907. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemName, "StopTxnAlignedData");
  13908. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemData, "" );
  13909. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTxnAlignedData", "true", ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemData);
  13910. // StopTxnAlignedDataMaxLength
  13911. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemAccessibility = 0;
  13912. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemName, "StopTxnAlignedDataMaxLength");
  13913. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemData, "0" );
  13914. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTxnAlignedDataMaxLength", "true", ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemData);
  13915. // StopTxnSampledData
  13916. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemAccessibility = 1;
  13917. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemName, "StopTxnSampledData");
  13918. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  13919. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Current.Import,Energy.Active.Import.Interval,Power.Active.Import,Voltage,SoC" );
  13920. else
  13921. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Current.Import,Energy.Active.Import.Interval,Power.Active.Import,Voltage" );
  13922. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTxnSampledData", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData);
  13923. // StopTxnSampledDataMaxLength
  13924. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemAccessibility = 0;
  13925. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemName, "StopTxnSampledDataMaxLength");
  13926. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  13927. {
  13928. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemData, "%d", 7);
  13929. }
  13930. else
  13931. {
  13932. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemData, "%d", 9);
  13933. }
  13934. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTxnSampledDataMaxLength", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemData);
  13935. // SupportedFeatureProfiles
  13936. ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemAccessibility = 0;
  13937. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemName, "SupportedFeatureProfiles");
  13938. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemData, "Core,FirmwareManagement,LocalAuthListManagement,Reservation,SmartCharging,RemoteTrigger" );
  13939. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","SupportedFeatureProfiles", "true", ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemData);
  13940. // SupportedFeatureProfilesMaxLength
  13941. ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemAccessibility = 0;
  13942. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemName, "SupportedFeatureProfilesMaxLength");
  13943. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemData, "6" );
  13944. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","SupportedFeatureProfilesMaxLength", "true", ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemData);
  13945. // TransactionMessageAttempts
  13946. ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemAccessibility = 1;
  13947. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemName, "TransactionMessageAttempts");
  13948. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData, "3" );
  13949. TransactionMessageAttemptsValue = atoi((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData);
  13950. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","TransactionMessageAttempts", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData);
  13951. // TransactionMessageRetryInterval
  13952. ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemAccessibility = 1;
  13953. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemName, "TransactionMessageRetryInterval");
  13954. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData, "60" );
  13955. TransactionMessageRetryIntervalValue = atoi((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData);
  13956. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","TransactionMessageRetryInterval", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData);
  13957. // UnlockConnectorOnEVSideDisconnect
  13958. ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemAccessibility = 0;
  13959. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemName, "UnlockConnectorOnEVSideDisconnect");
  13960. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemData, "TRUE" );
  13961. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","UnlockConnectorOnEVSideDisconnect", "true", ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemData);
  13962. // WebSocketPingInterval
  13963. ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemAccessibility = 1;
  13964. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemName, "WebSocketPingInterval");
  13965. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemData, "30" );
  13966. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","WebSocketPingInterval", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemData);
  13967. // QueueOffLineMeterValues
  13968. ShmOCPP16Data->ConfigurationTable.CoreProfile[QueueOffLineMeterValues].ItemAccessibility = 1;
  13969. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[QueueOffLineMeterValues].ItemName, "QueueOffLineMeterValues");
  13970. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[QueueOffLineMeterValues].ItemData, "FALSE" );
  13971. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","QueueOffLineMeterValues", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[QueueOffLineMeterValues].ItemData);
  13972. // AuthorizationKey
  13973. ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationKey].ItemAccessibility = 1;
  13974. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationKey].ItemName, "AuthorizationKey");
  13975. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationKey].ItemData, (char*)ShmSysConfigAndInfo->SysConfig.OcppSecurityPassword);
  13976. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","AuthorizationKey", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationKey].ItemData);
  13977. // SecurityProfile
  13978. ShmOCPP16Data->ConfigurationTable.CoreProfile[SecurityProfile].ItemAccessibility = 1;
  13979. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SecurityProfile].ItemName, "SecurityProfile");
  13980. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SecurityProfile].ItemData, "%d", ShmSysConfigAndInfo->SysConfig.OcppSecurityProfile);
  13981. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","SecurityProfile", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[SecurityProfile].ItemData);
  13982. // DefaultPrice
  13983. ShmOCPP16Data->ConfigurationTable.CoreProfile[DefaultPrice].ItemAccessibility = 1;
  13984. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[DefaultPrice].ItemName, "DefaultPrice");
  13985. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[DefaultPrice].ItemData, "" );
  13986. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","DefaultPrice", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[DefaultPrice].ItemData);
  13987. // CustomDisplayCostAndPrice
  13988. ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemAccessibility = 1;
  13989. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemName, "CustomDisplayCostAndPrice");
  13990. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemData, "FALSE" );
  13991. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","CustomDisplayCostAndPrice", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemData);
  13992. // CustomIdleFeeAfterStop
  13993. ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemAccessibility = 1;
  13994. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemName, "CustomIdleFeeAfterStop");
  13995. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemData, "FALSE" );
  13996. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","CustomIdleFeeAfterStop", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemData);
  13997. // TimeOffset
  13998. ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffset].ItemAccessibility = 1;
  13999. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffset].ItemName, "TimeOffset");
  14000. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffset].ItemData, "+00:00" );
  14001. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","TimeOffset", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffset].ItemData);
  14002. // NextTimeOffsetTransitionDateTime
  14003. ShmOCPP16Data->ConfigurationTable.CoreProfile[NextTimeOffsetTransitionDateTime].ItemAccessibility = 1;
  14004. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NextTimeOffsetTransitionDateTime].ItemName, "NextTimeOffsetTransitionDateTime");
  14005. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NextTimeOffsetTransitionDateTime].ItemData, " " );
  14006. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","NextTimeOffsetTransitionDateTime", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[NextTimeOffsetTransitionDateTime].ItemData);
  14007. // TimeOffsetNextTransition
  14008. ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffsetNextTransition].ItemAccessibility = 1;
  14009. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffsetNextTransition].ItemName, "TimeOffsetNextTransition");
  14010. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffsetNextTransition].ItemData, "+00:00" );
  14011. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","TimeOffsetNextTransition", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffsetNextTransition].ItemData);
  14012. // SystemUptimeSec
  14013. ShmOCPP16Data->ConfigurationTable.CoreProfile[SystemUptimeSec].ItemAccessibility = 1;
  14014. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SystemUptimeSec].ItemName, "SystemUptimeSec");
  14015. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SystemUptimeSec].ItemData, "0" );
  14016. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","SystemUptimeSec", "true", ShmOCPP16Data->ConfigurationTable.CoreProfile[SystemUptimeSec].ItemData);
  14017. // FreeVend
  14018. ShmOCPP16Data->ConfigurationTable.CoreProfile[FreeVend].ItemAccessibility = 1;
  14019. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[FreeVend].ItemName, "Free-FreeVend");
  14020. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[FreeVend].ItemData, (ShmSysConfigAndInfo->SysConfig.AuthorisationMode?"TRUE":"FALSE") );
  14021. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","FreeVend", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[FreeVend].ItemData);
  14022. // OcppServer
  14023. ShmOCPP16Data->ConfigurationTable.CoreProfile[OcppServer].ItemAccessibility = 1;
  14024. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[OcppServer].ItemName, "OcppServer");
  14025. memcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[OcppServer].ItemData, (char*)ShmSysConfigAndInfo->SysConfig.OcppServerURL, 500);
  14026. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","OcppServer", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[OcppServer].ItemData);
  14027. // MaintainServer
  14028. ShmOCPP16Data->ConfigurationTable.CoreProfile[MaintainServer].ItemAccessibility = 1;
  14029. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MaintainServer].ItemName, "MaintainServer");
  14030. memcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MaintainServer].ItemData, (char*)ShmSysConfigAndInfo->SysConfig.MaintainServerURL, 500);
  14031. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MaintainServer", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[MaintainServer].ItemData);
  14032. // StatusNotificationPeriodically
  14033. ShmOCPP16Data->ConfigurationTable.CoreProfile[StatusNotificationPeriodically].ItemAccessibility = 1;
  14034. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StatusNotificationPeriodically].ItemName, "StatusNotificationPeriodically");
  14035. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StatusNotificationPeriodically].ItemData, "FALSE" );
  14036. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StatusNotificationPeriodically", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[StatusNotificationPeriodically].ItemData);
  14037. // StatusNotificationInterval
  14038. ShmOCPP16Data->ConfigurationTable.CoreProfile[StatusNotificationInterval].ItemAccessibility = 1;
  14039. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StatusNotificationInterval].ItemName, "StatusNotificationInterval");
  14040. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StatusNotificationInterval].ItemData, "120" );
  14041. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StatusNotificationInterval", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[StatusNotificationInterval].ItemData);
  14042. // Configuration Version
  14043. ShmOCPP16Data->ConfigurationTable.CoreProfile[ConfigurationVersion].ItemAccessibility = 0;
  14044. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConfigurationVersion].ItemName, "ConfigurationVersion");
  14045. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConfigurationVersion].ItemData, "%d", confVersion);
  14046. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ConfigurationVersion", "true", ShmOCPP16Data->ConfigurationTable.CoreProfile[ConfigurationVersion].ItemData);
  14047. //* Local Auth List Management Profile*/
  14048. #if 0
  14049. //For OCTT Test Case
  14050. ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemAccessibility = 1;
  14051. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemName, "LocalAuthorizationListEnabled");
  14052. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "TRUE" );
  14053. #endif
  14054. #if 1
  14055. //LocalAuthListEnabled
  14056. ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemAccessibility = 1;
  14057. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemName, "LocalAuthListEnabled");
  14058. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "TRUE" );
  14059. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LocalAuthListEnabled", "false", ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData);
  14060. #endif
  14061. //LocalAuthListMaxLength
  14062. ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemAccessibility = 0;
  14063. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemName, "LocalAuthListMaxLength");
  14064. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemData, "100000" );
  14065. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LocalAuthListMaxLength", "true", ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemData);
  14066. //SendLocalListMaxLength
  14067. ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemAccessibility = 0;
  14068. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemName, "SendLocalListMaxLength");
  14069. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemData, "500" );
  14070. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","SendLocalListMaxLength", "true", ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemData);
  14071. //ReserveConnectorZeroSupported
  14072. ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemAccessibility = 0;
  14073. strcpy((char *)ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemName, "ReserveConnectorZeroSupported");
  14074. strcpy((char *)ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemData, "FALSE" );
  14075. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ReserveConnectorZeroSupported", "true", ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemData);
  14076. //* Smart Charging Profile */
  14077. //ChargeProfileMaxStackLevel
  14078. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemAccessibility = 0;
  14079. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemName, "ChargeProfileMaxStackLevel");
  14080. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemData, "3" );
  14081. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ChargeProfileMaxStackLevel", "true", ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemData);
  14082. // ChargingScheduleAllowedChargingRateUnit
  14083. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemAccessibility = 0;
  14084. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemName, "ChargingScheduleAllowedChargingRateUnit");
  14085. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemData, "Current,Power" );
  14086. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ChargingScheduleAllowedChargingRateUnit", "true", ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemData);
  14087. // ChargingScheduleMaxPeriods
  14088. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemAccessibility = 0;
  14089. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemName, "ChargingScheduleMaxPeriods");
  14090. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemData, "10" );
  14091. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ChargingScheduleMaxPeriods", "true", ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemData);
  14092. // ConnectorSwitch3to1PhaseSupported
  14093. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemAccessibility = 0;
  14094. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemName, "ConnectorSwitch3to1PhaseSupported");
  14095. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemData, "FALSE" );
  14096. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ConnectorSwitch3to1PhaseSupported", "true", ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemData);
  14097. // MaxChargingProfilesInstalled
  14098. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemAccessibility = 0;
  14099. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemName, "MaxChargingProfilesInstalled");
  14100. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemData, "10" );
  14101. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MaxChargingProfilesInstalled", "true", ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemData);
  14102. fclose(outfile);
  14103. }
  14104. else
  14105. {
  14106. //DEBUG_INFO("../Storage/OCPP/OCPPConfiguration EXit\n");
  14107. char keystr[60]={0};
  14108. char readonlystr[10]={0};
  14109. char valuestr[256]={0};
  14110. fp = fopen("/Storage/OCPP/OCPPConfiguration" , "r");
  14111. if(fp == NULL) {
  14112. DEBUG_INFO("Error opening file");
  14113. return FALSE;
  14114. }
  14115. while( fgets (str, ARRAY_SIZE(str), fp)!=NULL )
  14116. {
  14117. //DEBUG_INFO("Get Configuration \n");
  14118. if(strlen(str) > 0)
  14119. {
  14120. str[strlen(str) - 1] = '\0'; // eat the newline fgets() stores
  14121. //*************************key*********************************/
  14122. if(strstr(str, "key") != NULL)
  14123. {
  14124. loc = strstr(str, "key");
  14125. c = 0;
  14126. memset(sstr ,0, ARRAY_SIZE(sstr) );
  14127. while ((loc[strlen("key")+3+c] != '\"') && (c < (ARRAY_SIZE(sstr)-1)))
  14128. {
  14129. sstr[c] = loc[strlen("key")+3+c];
  14130. c++;
  14131. }
  14132. sstr[c] = '\0';
  14133. strcpy(keystr,sstr);
  14134. }
  14135. //*************************readonly*********************************/
  14136. if(strstr(str, "readonly") != NULL)
  14137. {
  14138. loc = strstr(str, "readonly");
  14139. c = 0;
  14140. memset(sstr ,0, ARRAY_SIZE(sstr) );
  14141. while ((loc[strlen("readonly")+2+c] != ',') && (c < (ARRAY_SIZE(sstr)-1)))
  14142. {
  14143. sstr[c] = loc[strlen("readonly")+2+c];
  14144. c++;
  14145. }
  14146. sstr[c] = '\0';
  14147. strcpy(readonlystr,sstr);
  14148. }
  14149. //*************************value*********************************/
  14150. if(strstr(str, "value") != NULL)
  14151. {
  14152. loc = strstr(str, "value");
  14153. c = 0;
  14154. memset(sstr ,0, ARRAY_SIZE(sstr) );
  14155. while ((loc[strlen("value")+3+c] != '\"') && (c < (ARRAY_SIZE(sstr)-1)))
  14156. {
  14157. sstr[c] = loc[strlen("value")+3+c];
  14158. c++;
  14159. }
  14160. sstr[c] = '\0';
  14161. strcpy(valuestr,sstr);
  14162. }
  14163. // DEBUG_INFO("keystr=%s\n",keystr);
  14164. // DEBUG_INFO("readonlystr=%s\n",readonlystr);
  14165. // DEBUG_INFO("valuestr=%s\n",valuestr);
  14166. if(strcmp(keystr, "AllowOfflineTxForUnknownId") == 0)
  14167. {
  14168. //Charger.AllowOfflineTxForUnknownId = (value.toLowerCase().equals("true")?true:false);
  14169. ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14170. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemData, "%s", valuestr );
  14171. // DEBUG_INFO("AllowOfflineTxForUnknownId setting\n");
  14172. // DEBUG_INFO("AllowOfflineTxForUnknownId setting\n");
  14173. }
  14174. if(strcmp(keystr, "AuthorizationCacheEnabled") == 0)
  14175. {
  14176. //Charger.AuthorizationCacheEnabled = (value.toLowerCase().equals("true")?true:false);
  14177. ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14178. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemData, "%s", valuestr );
  14179. }
  14180. if(strcmp(keystr, "AuthorizeRemoteTxRequests") == 0)
  14181. {
  14182. ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14183. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemData, "%s", valuestr );
  14184. }
  14185. if(strcmp(keystr, "BlinkRepeat") == 0)
  14186. {
  14187. //Charger.BlinkRepeat = Integer.parseInt(value);
  14188. ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14189. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemData, "%d", atoi(valuestr) );
  14190. }
  14191. if(strcmp(keystr, "ClockAlignedDataInterval") == 0)
  14192. {
  14193. ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14194. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemData, "%d", atoi(valuestr) );
  14195. }
  14196. if(strcmp(keystr, "ConnectionTimeOut") == 0 )
  14197. {
  14198. ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14199. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemData, "%d", atoi(valuestr));
  14200. }
  14201. if(strcmp(keystr, "GetConfigurationMaxKeys") == 0)
  14202. {
  14203. ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14204. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemData, "%d", (atoi(valuestr)!=GetConfigurationMaxKeysNUM?GetConfigurationMaxKeysNUM:atoi(valuestr)));
  14205. }
  14206. if(strcmp(keystr, "HeartbeatInterval") == 0)
  14207. {
  14208. ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14209. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemData, "%d", atoi(valuestr));
  14210. HeartBeatWaitTime = atoi(valuestr);
  14211. }
  14212. if(strcmp(keystr, "LightIntensity") == 0)
  14213. {
  14214. ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14215. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemData, "%d", atoi(valuestr));
  14216. }
  14217. if(strcmp(keystr, "LocalAuthorizeOffline") == 0)
  14218. {
  14219. ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14220. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemData, "%s", valuestr );
  14221. }
  14222. if(strcmp(keystr, "LocalPreAuthorize") == 0)
  14223. {
  14224. ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14225. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemData, "%s", valuestr );
  14226. }
  14227. if(strcmp(keystr, "MaxEnergyOnInvalidId") == 0)
  14228. {
  14229. ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14230. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemData, "%d", atoi(valuestr) );
  14231. }
  14232. if(strcmp(keystr, "MeterValuesAlignedData") == 0)
  14233. {
  14234. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14235. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, "%s", valuestr );
  14236. }
  14237. if(strcmp(keystr, "MeterValuesAlignedDataMaxLength") == 0)
  14238. {
  14239. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14240. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemData, "%d", atoi(valuestr));
  14241. }
  14242. if(strcmp(keystr, "MeterValuesSampledData") == 0 )
  14243. {
  14244. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14245. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, "%s", valuestr );
  14246. }
  14247. if(strcmp(keystr, "MeterValuesSampledDataMaxLength") == 0)
  14248. {
  14249. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14250. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemData, "%d", atoi(valuestr));
  14251. }
  14252. if(strcmp(keystr, "MeterValueSampleInterval") == 0)
  14253. {
  14254. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14255. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemData, "%d", atoi(valuestr));
  14256. }
  14257. if(strcmp(keystr, "MinimumStatusDuration") == 0)
  14258. {
  14259. ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14260. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemData, "%d", atoi(valuestr) );
  14261. server_cycle_Status = atoi(valuestr); //StatusNotification cycle
  14262. }
  14263. if(strcmp(keystr, "NumberOfConnectors") == 0)
  14264. {
  14265. ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14266. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData, "%d", atoi(valuestr) );
  14267. }
  14268. if(strcmp(keystr, "ResetRetries") == 0)
  14269. {
  14270. ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14271. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemData, "%d", atoi(valuestr) );
  14272. }
  14273. if(strcmp(keystr, "ConnectorPhaseRotation") == 0)
  14274. {
  14275. ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14276. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "%s", valuestr );
  14277. }
  14278. if(strcmp(keystr, "ConnectorPhaseRotationMaxLength") == 0)
  14279. {
  14280. ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14281. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemData, "%d", atoi(valuestr) );
  14282. }
  14283. if(strcmp(keystr, "StopTransactionOnEVSideDisconnect") == 0)
  14284. {
  14285. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14286. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemData, "%s", valuestr );
  14287. }
  14288. if(strcmp(keystr, "StopTransactionOnInvalidId") == 0)
  14289. {
  14290. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14291. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemData, "%s", valuestr );
  14292. }
  14293. if(strcmp(keystr, "StopTxnAlignedData") == 0)
  14294. {
  14295. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14296. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemData, "%s", valuestr );
  14297. }
  14298. if(strcmp(keystr, "StopTxnAlignedDataMaxLength") == 0)
  14299. {
  14300. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14301. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemData, "%d", atoi(valuestr) );
  14302. }
  14303. if(strcmp(keystr, "StopTxnSampledData") == 0)
  14304. {
  14305. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14306. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "%s", valuestr );
  14307. }
  14308. if(strcmp(keystr, "StopTxnSampledDataMaxLength") == 0)
  14309. {
  14310. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14311. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemData, "%d", atoi(valuestr) );
  14312. }
  14313. if(strcmp(keystr, "SupportedFeatureProfiles") == 0)
  14314. {
  14315. ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14316. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemData, "%s", valuestr );
  14317. }
  14318. if(strcmp(keystr, "SupportedFeatureProfilesMaxLength") == 0)
  14319. {
  14320. ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14321. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemData, "%d", atoi(valuestr) );
  14322. }
  14323. if(strcmp(keystr, "TransactionMessageAttempts") == 0)
  14324. {
  14325. ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14326. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData, "%d", atoi(valuestr) );
  14327. TransactionMessageAttemptsValue = atoi(valuestr);
  14328. }
  14329. if(strcmp(keystr, "TransactionMessageRetryInterval") == 0)
  14330. {
  14331. ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemAccessibility= (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14332. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData, "%d", atoi(valuestr) );
  14333. TransactionMessageRetryIntervalValue = atoi(valuestr);
  14334. }
  14335. if(strcmp(keystr, "UnlockConnectorOnEVSideDisconnect") == 0)
  14336. {
  14337. ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14338. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemData, "%s", valuestr );
  14339. }
  14340. if(strcmp(keystr, "WebSocketPingInterval") == 0)
  14341. {
  14342. ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14343. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemData, "%d", atoi(valuestr) );
  14344. }
  14345. if(strcmp(keystr, "QueueOffLineMeterValues") == 0)
  14346. {
  14347. ShmOCPP16Data->ConfigurationTable.CoreProfile[QueueOffLineMeterValues].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14348. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[QueueOffLineMeterValues].ItemData, "%s", valuestr);
  14349. }
  14350. if(strcmp(keystr, "AuthorizationKey") == 0)
  14351. {
  14352. ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationKey].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14353. //sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationKey].ItemData, "%s", valuestr);
  14354. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationKey].ItemData, "%s", ShmSysConfigAndInfo->SysConfig.OcppSecurityPassword);
  14355. }
  14356. if(strcmp(keystr, "SecurityProfile") == 0)
  14357. {
  14358. ShmOCPP16Data->ConfigurationTable.CoreProfile[SecurityProfile].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14359. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SecurityProfile].ItemData, "%d", ShmSysConfigAndInfo->SysConfig.OcppSecurityProfile);
  14360. }
  14361. if(strcmp(keystr, "DefaultPrice") == 0)
  14362. {
  14363. ShmOCPP16Data->ConfigurationTable.CoreProfile[DefaultPrice].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14364. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[DefaultPrice].ItemData, "%s", valuestr);
  14365. }
  14366. if(strcmp(keystr, "CustomDisplayCostAndPrice") == 0)
  14367. {
  14368. ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14369. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemData, "%s", valuestr);
  14370. }
  14371. if(strcmp(keystr, "CustomIdleFeeAfterStop") == 0)
  14372. {
  14373. ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14374. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemData, "%s", valuestr);
  14375. }
  14376. if(strcmp(keystr, "TimeOffset") == 0)
  14377. {
  14378. ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffset].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14379. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffset].ItemData, "%s", valuestr);
  14380. }
  14381. if(strcmp(keystr, "NextTimeOffsetTransitionDateTime") == 0)
  14382. {
  14383. ShmOCPP16Data->ConfigurationTable.CoreProfile[NextTimeOffsetTransitionDateTime].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14384. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NextTimeOffsetTransitionDateTime].ItemData, "%s", valuestr);
  14385. }
  14386. if(strcmp(keystr, "TimeOffsetNextTransition") == 0)
  14387. {
  14388. ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffsetNextTransition].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14389. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffsetNextTransition].ItemData, "%s", valuestr);
  14390. }
  14391. if(strcmp(keystr, "SystemUptimeSec") == 0)
  14392. {
  14393. ShmOCPP16Data->ConfigurationTable.CoreProfile[SystemUptimeSec].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14394. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SystemUptimeSec].ItemData, "%s", valuestr);
  14395. }
  14396. if(strcmp(keystr, "FreeVend") == 0)
  14397. {
  14398. ShmOCPP16Data->ConfigurationTable.CoreProfile[FreeVend].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14399. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[FreeVend].ItemData, "%s", (ShmSysConfigAndInfo->SysConfig.AuthorisationMode ? "TRUE" : "FALSE"));
  14400. }
  14401. if(strcmp(keystr, "OcppServer") == 0)
  14402. {
  14403. ShmOCPP16Data->ConfigurationTable.CoreProfile[OcppServer].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14404. memcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[OcppServer].ItemData, (char *)ShmSysConfigAndInfo->SysConfig.OcppServerURL, 500);
  14405. }
  14406. if(strcmp(keystr, "MaintainServer") == 0)
  14407. {
  14408. ShmOCPP16Data->ConfigurationTable.CoreProfile[MaintainServer].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14409. memcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MaintainServer].ItemData, (char *)ShmSysConfigAndInfo->SysConfig.MaintainServerURL,500);
  14410. }
  14411. if(strcmp(keystr, "StatusNotificationPeriodically") == 0)
  14412. {
  14413. ShmOCPP16Data->ConfigurationTable.CoreProfile[StatusNotificationPeriodically].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14414. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StatusNotificationPeriodically].ItemData, "%s", valuestr);
  14415. }
  14416. if(strcmp(keystr, "StatusNotificationInterval") == 0)
  14417. {
  14418. ShmOCPP16Data->ConfigurationTable.CoreProfile[StatusNotificationInterval].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14419. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StatusNotificationInterval].ItemData, "%d", atoi(valuestr));
  14420. }
  14421. if(strcmp(keystr, "ConfigurationVersion") == 0)
  14422. {
  14423. ShmOCPP16Data->ConfigurationTable.CoreProfile[ConfigurationVersion].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14424. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConfigurationVersion].ItemData, "%d", atoi(valuestr));
  14425. }
  14426. if(strcmp(keystr, "LocalAuthListEnabled") == 0)
  14427. {
  14428. ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14429. sprintf((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "%s", valuestr );
  14430. }
  14431. if(strcmp(keystr, "LocalAuthListMaxLength") == 0)
  14432. {
  14433. ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14434. sprintf((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemData, "%d", atoi(valuestr) );
  14435. }
  14436. if(strcmp(keystr, "SendLocalListMaxLength") == 0)
  14437. {
  14438. ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14439. sprintf((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemData, "%d", atoi(valuestr) );
  14440. }
  14441. if(strcmp(keystr, "ReserveConnectorZeroSupported") == 0)
  14442. {
  14443. ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14444. sprintf((char *)ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemData, "%s", valuestr );
  14445. }
  14446. if(strcmp(keystr, "ChargeProfileMaxStackLevel") == 0)
  14447. {
  14448. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14449. sprintf((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemData, "%d", atoi(valuestr) );
  14450. }
  14451. if(strcmp(keystr, "ChargingScheduleAllowedChargingRateUnit") == 0)
  14452. {
  14453. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14454. sprintf((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemData, "%s", valuestr );
  14455. }
  14456. if(strcmp(keystr, "ChargingScheduleMaxPeriods") == 0)
  14457. {
  14458. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14459. sprintf((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemData, "%d", atoi(valuestr) );
  14460. }
  14461. if(strcmp(keystr, "ConnectorSwitch3to1PhaseSupported") == 0)
  14462. {
  14463. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14464. sprintf((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemData, "%s", valuestr);
  14465. }
  14466. if(strcmp(keystr, "MaxChargingProfilesInstalled") == 0)
  14467. {
  14468. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14469. sprintf((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemData, "%d", atoi(valuestr) );
  14470. }
  14471. }
  14472. }
  14473. fclose(fp);
  14474. }
  14475. if(atoi((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConfigurationVersion].ItemData) == confVersion)
  14476. {
  14477. return PASS;
  14478. }
  14479. else
  14480. {
  14481. return FAIL;
  14482. }
  14483. }
  14484. void StoreConfigurationTable(void)
  14485. {
  14486. FILE *outfile;
  14487. outfile = fopen("/Storage/OCPP/OCPPConfiguration" , "w+");
  14488. if(outfile == NULL)
  14489. {
  14490. DEBUG_INFO("Error opening file");
  14491. return ;
  14492. }
  14493. /*Core Profile*/
  14494. //AllowOfflineTxForUnknownId
  14495. /*
  14496. ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemAccessibility = 1;
  14497. printf("AllowoddlineTXForUnknownId type: %d \n", ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemAccessibility);
  14498. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemName, "AllowOfflineTxForUnknownId");
  14499. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemData, "TRUE" );
  14500. */
  14501. //DEBUG_INFO("data=%s\n",data);
  14502. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","AllowOfflineTxForUnknownId", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemData);
  14503. //AuthorizationCacheEnabled
  14504. /*
  14505. ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemAccessibility = 1;
  14506. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemName, "AuthorizationCacheEnabled");
  14507. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemData, "FALSE" );
  14508. */
  14509. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","AuthorizationCacheEnabled", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemData);
  14510. //AuthorizeRemoteTxRequests
  14511. /*
  14512. ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemAccessibility = 0;
  14513. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemName, "AuthorizeRemoteTxRequests");
  14514. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemData, "TRUE" );
  14515. */
  14516. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","AuthorizeRemoteTxRequests", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemData);
  14517. //BlinkRepeat
  14518. /*
  14519. ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemAccessibility = 1;
  14520. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemName, "BlinkRepeat");
  14521. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemData, "0" );
  14522. */
  14523. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","BlinkRepeat", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemData);
  14524. //ClockAlignedDataInterval
  14525. /*
  14526. ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemAccessibility = 1;
  14527. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemName, "ClockAlignedDataInterval");
  14528. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemData, "0" );
  14529. */
  14530. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ClockAlignedDataInterval", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemData);
  14531. //ConnectionTimeOut
  14532. /*
  14533. ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemAccessibility = 1;
  14534. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemName, "ConnectionTimeOut");
  14535. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemData, "180" );
  14536. */
  14537. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ConnectionTimeOut", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemData);
  14538. //GetConfigurationMaxKeys
  14539. /*
  14540. ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemAccessibility =0;
  14541. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemName, "GetConfigurationMaxKeys");
  14542. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemData, "43" );
  14543. */
  14544. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","GetConfigurationMaxKeys", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemData);
  14545. // HeartbeatInterval
  14546. /*
  14547. ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemAccessibility = 1;
  14548. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemName, "HeartbeatInterval");
  14549. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemData, "10" );
  14550. */
  14551. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","HeartbeatInterval", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemData);
  14552. // LightIntensity
  14553. /*
  14554. ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemAccessibility = 1;
  14555. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemName, "LightIntensity");
  14556. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemData, "0" );
  14557. */
  14558. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LightIntensity", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemData);
  14559. // LocalAuthorizeOffline
  14560. /*
  14561. ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemAccessibility = 0;
  14562. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemName, "LocalAuthorizeOffline");
  14563. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemData, "TRUE" );
  14564. */
  14565. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LocalAuthorizeOffline", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemData);
  14566. // LocalPreAuthorize
  14567. /*
  14568. ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemAccessibility = 0;
  14569. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemName, "LocalPreAuthorize");
  14570. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemData, "FALSE" );
  14571. */
  14572. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LocalPreAuthorize", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemData);
  14573. // MaxEnergyOnInvalidId
  14574. /*
  14575. ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemAccessibility = 1;
  14576. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemName, "MaxEnergyOnInvalidId");
  14577. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemData, "0" );
  14578. */
  14579. //ShmSysConfigAndInfo->SysConfig.OfflineMaxChargeEnergy = 0;
  14580. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MaxEnergyOnInvalidId", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemData);
  14581. // MeterValuesAlignedData
  14582. /*
  14583. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemAccessibility = 1;
  14584. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemName, "MeterValuesAlignedData");
  14585. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, "Current.Export,Energy.Active.Export.Interval,Power.Active.Export,Voltage,SOC" );
  14586. */
  14587. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValuesAlignedData", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData);
  14588. // MeterValuesAlignedDataMaxLength
  14589. /*
  14590. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemAccessibility = 0;
  14591. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemName, "MeterValuesAlignedDataMaxLength");
  14592. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemData, "5" );
  14593. */
  14594. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValuesAlignedDataMaxLength", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemData);
  14595. // MeterValuesSampledData
  14596. /*
  14597. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemAccessibility = 1;
  14598. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemName, "MeterValuesSampledData");
  14599. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, "Current.Export,Energy.Active.Export.Interval,Power.Active.Export,Voltage,SOC" );
  14600. */
  14601. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValuesSampledData", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData);
  14602. // MeterValuesSampledDataMaxLength
  14603. /*
  14604. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemAccessibility = 0;
  14605. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemName, "MeterValuesSampledDataMaxLength");
  14606. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemData, "5" );
  14607. */
  14608. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValuesSampledDataMaxLength", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemData);
  14609. // MeterValueSampleInterval
  14610. /*
  14611. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemAccessibility = 1;
  14612. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemName, "MeterValueSampleInterval");
  14613. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemData, "10" );
  14614. */
  14615. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValueSampleInterval", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemData);
  14616. // MinimumStatusDuration
  14617. /*
  14618. ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemAccessibility = 1;
  14619. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemName, "MinimumStatusDuration");
  14620. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemData, "0" );
  14621. */
  14622. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MinimumStatusDuration", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemData);
  14623. // NumberOfConnectors
  14624. /*
  14625. ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemAccessibility = 0;
  14626. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemName, "NumberOfConnectors");
  14627. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  14628. {
  14629. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData, "%d", (CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY));
  14630. }
  14631. else
  14632. {
  14633. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData, "%d", AC_QUANTITY);
  14634. }
  14635. */
  14636. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","NumberOfConnectors", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData);
  14637. // ResetRetries
  14638. /*
  14639. ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemAccessibility = 1;
  14640. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemName, "ResetRetries");
  14641. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemData, "3" );
  14642. */
  14643. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ResetRetries", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemData);
  14644. // ConnectorPhaseRotation
  14645. /*
  14646. ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemAccessibility = 1;
  14647. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemName, "ConnectorPhaseRotation");
  14648. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "NotApplicable" );
  14649. */
  14650. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ConnectorPhaseRotation", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData);
  14651. // ConnectorPhaseRotationMaxLength
  14652. /*
  14653. ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemAccessibility = 0;
  14654. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemName, "ConnectorPhaseRotationMaxLength");
  14655. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemData, "1" );
  14656. */
  14657. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ConnectorPhaseRotationMaxLength", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemData);
  14658. // StopTransactionOnEVSideDisconnect
  14659. /*
  14660. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemAccessibility = 0;
  14661. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemName, "StopTransactionOnEVSideDisconnect");
  14662. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemData, "TRUE" );
  14663. */
  14664. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTransactionOnEVSideDisconnect", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemData);
  14665. // StopTransactionOnInvalidId
  14666. /*
  14667. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemAccessibility = 0;
  14668. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemName, "StopTransactionOnInvalidId");
  14669. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemData, "FALSE" );
  14670. */
  14671. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTransactionOnInvalidId", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemData);
  14672. // StopTxnAlignedData
  14673. /*
  14674. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemAccessibility = 1;
  14675. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemName, "StopTxnAlignedData");
  14676. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemData, "Energy.Active.Import.Register" );
  14677. */
  14678. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTxnAlignedData", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemData);
  14679. // StopTxnAlignedDataMaxLength
  14680. /*
  14681. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemAccessibility = 0;
  14682. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemName, "StopTxnAlignedDataMaxLength");
  14683. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemData, "0" );
  14684. */
  14685. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTxnAlignedDataMaxLength", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemData);
  14686. // StopTxnSampledData
  14687. /*
  14688. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemAccessibility = 1;
  14689. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemName, "StopTxnSampledData");
  14690. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Energy.Active.Import.Register" );
  14691. */
  14692. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTxnSampledData", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData);
  14693. // StopTxnSampledDataMaxLength
  14694. /*
  14695. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemAccessibility = 0;
  14696. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemName, "StopTxnSampledDataMaxLength");
  14697. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemData, "0" );
  14698. */
  14699. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTxnSampledDataMaxLength", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemData);
  14700. // SupportedFeatureProfiles
  14701. /*
  14702. ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemAccessibility = 0;
  14703. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemName, "SupportedFeatureProfiles");
  14704. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemData, "Core,FirmwareManagement,LocalAuthListManagement,Reservation,SmartCharging,RemoteTrigger" );
  14705. */
  14706. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","SupportedFeatureProfiles", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemData);
  14707. // SupportedFeatureProfilesMaxLength
  14708. /*
  14709. ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemAccessibility = 0;
  14710. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemName, "SupportedFeatureProfilesMaxLength");
  14711. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemData, "6" );
  14712. */
  14713. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","SupportedFeatureProfilesMaxLength", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemData);
  14714. // TransactionMessageAttempts
  14715. /*
  14716. ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemAccessibility = 1;
  14717. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemName, "TransactionMessageAttempts");
  14718. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData, "3" );
  14719. */
  14720. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","TransactionMessageAttempts", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData);
  14721. // TransactionMessageRetryInterval
  14722. /*
  14723. ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemAccessibility = 1;
  14724. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemName, "TransactionMessageRetryInterval");
  14725. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData, "60" );
  14726. */
  14727. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","TransactionMessageRetryInterval", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData);
  14728. // UnlockConnectorOnEVSideDisconnect
  14729. /*
  14730. ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemAccessibility = 0;
  14731. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemName, "UnlockConnectorOnEVSideDisconnect");
  14732. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemData, "TRUE" );
  14733. */
  14734. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","UnlockConnectorOnEVSideDisconnect", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemData);
  14735. // WebSocketPingInterval
  14736. /*
  14737. ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemAccessibility = 1;
  14738. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemName, "WebSocketPingInterval");
  14739. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemData, "30" );
  14740. */
  14741. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","WebSocketPingInterval", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemData);
  14742. // QueueOffLineMeterValues
  14743. /*
  14744. ShmOCPP16Data->ConfigurationTable.CoreProfile[QueueOffLineMeterValues].ItemAccessibility = 0;
  14745. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[QueueOffLineMeterValues].ItemName, "QueueOffLineMeterValues");
  14746. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[QueueOffLineMeterValues].ItemData, "TRUE" );
  14747. */
  14748. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","QueueOffLineMeterValues", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[QueueOffLineMeterValues].ItemData);
  14749. // AuthorizationKey
  14750. /*
  14751. ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationKey].ItemAccessibility = 1;
  14752. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationKey].ItemName, "AuthorizationKey");
  14753. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationKey].ItemData, "0" );
  14754. */
  14755. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","AuthorizationKey", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationKey].ItemData);
  14756. // SecurityProfile
  14757. /*
  14758. ShmOCPP16Data->ConfigurationTable.CoreProfile[SecurityProfile].ItemAccessibility = 1;
  14759. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SecurityProfile].ItemName, "SecurityProfile");
  14760. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SecurityProfile].ItemData, "30" );
  14761. */
  14762. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","SecurityProfile", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SecurityProfile].ItemData);
  14763. // DefaultPrice
  14764. /*
  14765. ShmOCPP16Data->ConfigurationTable.CoreProfile[DefaultPrice].ItemAccessibility = 1;
  14766. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[DefaultPrice].ItemName, "DefaultPrice");
  14767. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[DefaultPrice].ItemData, "" );
  14768. */
  14769. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","DefaultPrice", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[DefaultPrice].ItemData);
  14770. // CustomDisplayCostAndPrice
  14771. /*
  14772. ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemAccessibility = 1;
  14773. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemName, "CustomDisplayCostAndPrice");
  14774. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemData, "FALSE" );
  14775. */
  14776. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","CustomDisplayCostAndPrice", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemData);
  14777. // CustomIdleFeeAfterStop
  14778. /*
  14779. ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemAccessibility = 1;
  14780. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemName, "CustomIdleFeeAfterStop");
  14781. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemData, "FALSE" );
  14782. */
  14783. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","CustomIdleFeeAfterStop", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemData);
  14784. // TimeOffset
  14785. /*
  14786. ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffset].ItemAccessibility = 1;
  14787. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffset].ItemName, "TimeOffset");
  14788. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffset].ItemData, "FALSE" );
  14789. */
  14790. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","TimeOffset", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffset].ItemData);
  14791. // NextTimeOffsetTransitionDateTime
  14792. /*
  14793. ShmOCPP16Data->ConfigurationTable.CoreProfile[NextTimeOffsetTransitionDateTime].ItemAccessibility = 1;
  14794. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NextTimeOffsetTransitionDateTime].ItemName, "NextTimeOffsetTransitionDateTime");
  14795. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NextTimeOffsetTransitionDateTime].ItemData, "FALSE" );
  14796. */
  14797. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","NextTimeOffsetTransitionDateTime", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NextTimeOffsetTransitionDateTime].ItemData);
  14798. // TimeOffsetNextTransition
  14799. /*
  14800. ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffsetNextTransition].ItemAccessibility = 1;
  14801. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffsetNextTransition].ItemName, "TimeOffsetNextTransition");
  14802. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffsetNextTransition].ItemData, "FALSE" );
  14803. */
  14804. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","TimeOffsetNextTransition", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffsetNextTransition].ItemData);
  14805. // SystemUptimeSec
  14806. /*
  14807. ShmOCPP16Data->ConfigurationTable.CoreProfile[SystemUptimeSec].ItemAccessibility = 1;
  14808. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SystemUptimeSec].ItemName, "SystemUptimeSec");
  14809. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SystemUptimeSec].ItemData, "0" );
  14810. */
  14811. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","SystemUptimeSec", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SystemUptimeSec].ItemData);
  14812. // FreeVend
  14813. /*
  14814. ShmOCPP16Data->ConfigurationTable.CoreProfile[FreeVend].ItemAccessibility = 1;
  14815. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[FreeVend].ItemName, "FreeVend");
  14816. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[FreeVend].ItemData, "FALSE" );
  14817. */
  14818. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","FreeVend", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[FreeVend].ItemData);
  14819. // OcppServer
  14820. /*
  14821. ShmOCPP16Data->ConfigurationTable.CoreProfile[OcppServer].ItemAccessibility = 1;
  14822. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[OcppServer].ItemName, "OcppServer");
  14823. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[OcppServer].ItemData, "FALSE" );
  14824. */
  14825. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","OcppServer", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[OcppServer].ItemData);
  14826. // MaintainServer
  14827. /*
  14828. ShmOCPP16Data->ConfigurationTable.CoreProfile[MaintainServer].ItemAccessibility = 1;
  14829. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MaintainServer].ItemName, "MaintainServer");
  14830. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MaintainServer].ItemData, "FALSE" );
  14831. */
  14832. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MaintainServer", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MaintainServer].ItemData);
  14833. // StatusNotificationPeriodically
  14834. /*
  14835. ShmOCPP16Data->ConfigurationTable.CoreProfile[StatusNotificationPeriodically].ItemAccessibility =0;
  14836. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StatusNotificationPeriodically].ItemName, "StatusNotificationPeriodically");
  14837. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StatusNotificationPeriodically].ItemData, "FALSE" );
  14838. */
  14839. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StatusNotificationPeriodically", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StatusNotificationPeriodically].ItemData);
  14840. // StatusNotificationInterval
  14841. /*
  14842. ShmOCPP16Data->ConfigurationTable.CoreProfile[StatusNotificationInterval].ItemAccessibility = 1;
  14843. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StatusNotificationInterval].ItemName, "StatusNotificationInterval");
  14844. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StatusNotificationInterval].ItemData, "120" );
  14845. */
  14846. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StatusNotificationInterval", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StatusNotificationInterval].ItemData);
  14847. // ConfigurationVersion
  14848. /*
  14849. ShmOCPP16Data->ConfigurationTable.CoreProfile[ConfigurationVersion].ItemAccessibility = 1;
  14850. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConfigurationVersion].ItemName, "ConfigurationVersion");
  14851. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConfigurationVersion].ItemData, "1" );
  14852. */
  14853. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ConfigurationVersion", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConfigurationVersion].ItemData);
  14854. //* Local Auth List Management Profile*/
  14855. //LocalAuthListEnabled
  14856. /*
  14857. ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemAccessibility = 1;
  14858. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemName, "LocalAuthListEnabled");
  14859. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "TRUE" );
  14860. */
  14861. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LocalAuthListEnabled", "false", (char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData);
  14862. //LocalAuthListMaxLength
  14863. /*
  14864. ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemAccessibility = 0;
  14865. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemName, "LocalAuthListMaxLength");
  14866. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemData, "500" );
  14867. */
  14868. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LocalAuthListMaxLength", "true", (char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemData);
  14869. //SendLocalListMaxLength
  14870. /*
  14871. ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemAccessibility = 0;
  14872. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemName, "SendLocalListMaxLength");
  14873. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemData, "500" );
  14874. */
  14875. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","SendLocalListMaxLength", "true", (char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemData);
  14876. //ReserveConnectorZeroSupported
  14877. /*
  14878. ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemAccessibility = 0;
  14879. strcpy((char *)ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemName, "ReserveConnectorZeroSupported");
  14880. strcpy((char *)ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemData, "FALSE" );
  14881. */
  14882. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ReserveConnectorZeroSupported", "true", (char *)ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemData);
  14883. //* Smart Charging Profile */
  14884. //ChargeProfileMaxStackLevel
  14885. /*
  14886. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemAccessibility = 0;
  14887. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemName, "ChargeProfileMaxStackLevel");
  14888. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemData, "3" );
  14889. */
  14890. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ChargeProfileMaxStackLevel", "true", (char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemData);
  14891. // ChargingScheduleAllowedChargingRateUnit
  14892. /*
  14893. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemAccessibility = 0;
  14894. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemName, "ChargingScheduleAllowedChargingRateUnit");
  14895. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemData, "Current" );
  14896. */
  14897. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ChargingScheduleAllowedChargingRateUnit", "true", (char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemData);
  14898. // ChargingScheduleMaxPeriods
  14899. /*
  14900. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemAccessibility = 0;
  14901. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemName, "ChargingScheduleMaxPeriods");
  14902. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemData, "10" );
  14903. */
  14904. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ChargingScheduleMaxPeriods", "true", (char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemData);
  14905. // ConnectorSwitch3to1PhaseSupported
  14906. /*
  14907. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemAccessibility = 0;
  14908. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemName, "ConnectorSwitch3to1PhaseSupported");
  14909. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemData, "TRUE" );
  14910. */
  14911. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ConnectorSwitch3to1PhaseSupported", "true", (char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemData);
  14912. // MaxChargingProfilesInstalled
  14913. /*
  14914. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemAccessibility = 0;
  14915. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemName, "MaxChargingProfilesInstalled");
  14916. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemData, "10" );
  14917. */
  14918. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MaxChargingProfilesInstalled", "true", (char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemData);
  14919. fclose(outfile);
  14920. system("/bin/fsync -d /dev/mtdblock13;/bin/sync &");
  14921. }
  14922. void getKeyValue(char *keyReq)
  14923. {
  14924. int isEmpty = FALSE;
  14925. int isKnowKey = FALSE;
  14926. DEBUG_INFO("keyReq = %s\n", keyReq);
  14927. if((keyReq == NULL) || (strlen(keyReq) == 0))
  14928. isEmpty = TRUE;
  14929. if(isEmpty || strcmp(keyReq, "AllowOfflineTxForUnknownId") == 0)
  14930. {
  14931. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_AllowOfflineTxForUnknownId].Item, "AllowOfflineTxForUnknownId");
  14932. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AllowOfflineTxForUnknownId].Key, "AllowOfflineTxForUnknownId");
  14933. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemAccessibility == 1)
  14934. {
  14935. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AllowOfflineTxForUnknownId].ReadOnly, "0"/*"FALSE"*/);
  14936. }
  14937. else
  14938. {
  14939. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AllowOfflineTxForUnknownId].ReadOnly, "1"/*"TRUE"*/);
  14940. }
  14941. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AllowOfflineTxForUnknownId].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemData );
  14942. isKnowKey = TRUE;
  14943. }
  14944. if(isEmpty || strcmp(keyReq, "AuthorizationCacheEnabled") == 0 )
  14945. {
  14946. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_AuthorizationCacheEnabled].Item, "AuthorizationCacheEnabled");
  14947. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizationCacheEnabled].Key, "AuthorizationCacheEnabled");
  14948. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemAccessibility == 1)
  14949. {
  14950. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizationCacheEnabled].ReadOnly, "0"/*"FALSE"*/);
  14951. }
  14952. else
  14953. {
  14954. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizationCacheEnabled].ReadOnly, "1"/*"TRUE"*/);
  14955. }
  14956. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizationCacheEnabled].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemData );
  14957. isKnowKey = TRUE;
  14958. }
  14959. if(isEmpty || strcmp(keyReq, "AuthorizeRemoteTxRequests") == 0 )
  14960. {
  14961. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_AuthorizeRemoteTxRequests].Item, "AuthorizeRemoteTxRequests");
  14962. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizeRemoteTxRequests].Key, "AuthorizeRemoteTxRequests");
  14963. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemAccessibility == 1)
  14964. {
  14965. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizeRemoteTxRequests].ReadOnly, "0"/*"FALSE"*/);
  14966. }
  14967. else
  14968. {
  14969. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizeRemoteTxRequests].ReadOnly, "1"/*"TRUE"*/);
  14970. }
  14971. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizeRemoteTxRequests].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemData );
  14972. isKnowKey = TRUE;
  14973. }
  14974. if(isEmpty || strcmp(keyReq, "BlinkRepeat") == 0 )
  14975. {
  14976. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_BlinkRepeat].Item, "BlinkRepeat");
  14977. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_BlinkRepeat].Key, "BlinkRepeat");
  14978. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemAccessibility == 1)
  14979. {
  14980. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_BlinkRepeat].ReadOnly, "0"/*"FALSE"*/);
  14981. }
  14982. else
  14983. {
  14984. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_BlinkRepeat].ReadOnly, "1"/*"TRUE"*/);
  14985. }
  14986. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_BlinkRepeat].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemData );
  14987. isKnowKey = TRUE;
  14988. }
  14989. if(isEmpty || strcmp(keyReq, "ClockAlignedDataInterval") == 0 )
  14990. {
  14991. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_ClockAlignedDataInterval].Item, "ClockAlignedDataInterval");
  14992. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ClockAlignedDataInterval].Key, "ClockAlignedDataInterval");
  14993. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemAccessibility == 1)
  14994. {
  14995. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ClockAlignedDataInterval].ReadOnly, "0"/*"FALSE"*/);
  14996. }
  14997. else
  14998. {
  14999. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ClockAlignedDataInterval].ReadOnly, "1"/*"TRUE"*/);
  15000. }
  15001. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ClockAlignedDataInterval].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemData );
  15002. isKnowKey = TRUE;
  15003. }
  15004. if(isEmpty || strcmp(keyReq, "ConnectionTimeOut") == 0 )
  15005. {
  15006. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_ConnectionTimeOut].Item, "ConnectionTimeOut");
  15007. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectionTimeOut].Key, "ConnectionTimeOut");
  15008. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemAccessibility == 1)
  15009. {
  15010. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectionTimeOut].ReadOnly, "0"/*"FALSE"*/);
  15011. }
  15012. else
  15013. {
  15014. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectionTimeOut].ReadOnly, "1"/*"TRUE"*/);
  15015. }
  15016. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectionTimeOut].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemData );
  15017. isKnowKey = TRUE;
  15018. }
  15019. if(isEmpty || strcmp(keyReq, "GetConfigurationMaxKeys") == 0 )
  15020. {
  15021. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_GetConfigurationMaxKeys].Item, "GetConfigurationMaxKeys");
  15022. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_GetConfigurationMaxKeys].Key, "GetConfigurationMaxKeys");
  15023. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemAccessibility == 1)
  15024. {
  15025. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_GetConfigurationMaxKeys].ReadOnly, "0"/*"FALSE"*/);
  15026. }
  15027. else
  15028. {
  15029. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_GetConfigurationMaxKeys].ReadOnly, "1"/*"TRUE"*/);
  15030. }
  15031. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_GetConfigurationMaxKeys].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemData );
  15032. isKnowKey = TRUE;
  15033. }
  15034. if(isEmpty || strcmp(keyReq, "HeartbeatInterval") == 0 )
  15035. {
  15036. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_HeartbeatInterval].Item, "HeartbeatInterval");
  15037. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_HeartbeatInterval].Key, "HeartbeatInterval");
  15038. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemAccessibility == 1)
  15039. {
  15040. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_HeartbeatInterval].ReadOnly, "0"/*"FALSE"*/);
  15041. }
  15042. else
  15043. {
  15044. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_HeartbeatInterval].ReadOnly, "1"/*"TRUE"*/);
  15045. }
  15046. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_HeartbeatInterval].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemData );
  15047. isKnowKey = TRUE;
  15048. }
  15049. if(isEmpty || strcmp(keyReq, "LightIntensity") == 0 )
  15050. {
  15051. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_LightIntensity].Item, "LightIntensity");
  15052. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LightIntensity].Key, "LightIntensity");
  15053. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemAccessibility == 1)
  15054. {
  15055. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LightIntensity].ReadOnly, "0"/*"FALSE"*/);
  15056. }
  15057. else
  15058. {
  15059. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LightIntensity].ReadOnly, "1"/*"TRUE"*/);
  15060. }
  15061. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LightIntensity].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemData );
  15062. isKnowKey = TRUE;
  15063. }
  15064. if(isEmpty || strcmp(keyReq, "LocalAuthorizeOffline") == 0 )
  15065. {
  15066. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_LocalAuthorizeOffline].Item, "LocalAuthorizeOffline");
  15067. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthorizeOffline].Key, "LocalAuthorizeOffline");
  15068. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemAccessibility == 1)
  15069. {
  15070. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthorizeOffline].ReadOnly, "0"/*"FALSE"*/);
  15071. }
  15072. else
  15073. {
  15074. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthorizeOffline].ReadOnly, "1"/*"TRUE"*/);
  15075. }
  15076. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthorizeOffline].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemData );
  15077. isKnowKey = TRUE;
  15078. }
  15079. if(isEmpty || strcmp(keyReq, "LocalPreAuthorize") == 0 )
  15080. {
  15081. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_LocalPreAuthorize].Item, "LocalPreAuthorize");
  15082. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalPreAuthorize].Key, "LocalPreAuthorize");
  15083. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemAccessibility == 1)
  15084. {
  15085. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalPreAuthorize].ReadOnly, "0"/*"FALSE"*/);
  15086. }
  15087. else
  15088. {
  15089. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalPreAuthorize].ReadOnly, "1"/*"TRUE"*/);
  15090. }
  15091. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalPreAuthorize].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemData );
  15092. isKnowKey = TRUE;
  15093. }
  15094. if(isEmpty || strcmp(keyReq, "MaxEnergyOnInvalidId") == 0 )
  15095. {
  15096. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_MaxEnergyOnInvalidId].Item, "MaxEnergyOnInvalidId");
  15097. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaxEnergyOnInvalidId].Key, "MaxEnergyOnInvalidId");
  15098. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemAccessibility == 1)
  15099. {
  15100. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaxEnergyOnInvalidId].ReadOnly, "0"/*"FALSE"*/);
  15101. }
  15102. else
  15103. {
  15104. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaxEnergyOnInvalidId].ReadOnly, "1"/*"TRUE"*/);
  15105. }
  15106. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaxEnergyOnInvalidId].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemData );
  15107. isKnowKey = TRUE;
  15108. }
  15109. if(isEmpty || strcmp(keyReq, "MeterValuesAlignedData") == 0 )
  15110. {
  15111. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_MeterValuesAlignedData].Item, "MeterValuesAlignedData");
  15112. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesAlignedData].Key, "MeterValuesAlignedData");
  15113. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemAccessibility == 1)
  15114. {
  15115. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesAlignedData].ReadOnly, "0"/*"FALSE"*/);
  15116. }
  15117. else
  15118. {
  15119. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesAlignedData].ReadOnly, "1"/*"TRUE"*/);
  15120. }
  15121. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesAlignedData].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData );
  15122. isKnowKey = TRUE;
  15123. }
  15124. if(isEmpty || strcmp(keyReq, "MeterValuesAlignedDataMaxLength") == 0 )
  15125. {
  15126. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_MeterValuesAlignedDataMaxLength].Item, "MeterValuesAlignedDataMaxLength");
  15127. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesAlignedDataMaxLength].Key, "MeterValuesAlignedDataMaxLength");
  15128. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemAccessibility == 1)
  15129. {
  15130. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesAlignedDataMaxLength].ReadOnly, "0"/*"FALSE"*/);
  15131. }
  15132. else
  15133. {
  15134. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesAlignedDataMaxLength].ReadOnly, "1"/*"TRUE"*/);
  15135. }
  15136. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesAlignedDataMaxLength].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemData );
  15137. isKnowKey = TRUE;
  15138. }
  15139. if(isEmpty || strcmp(keyReq, "MeterValuesSampledData") == 0 )
  15140. {
  15141. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_MeterValuesSampledData].Item, "MeterValuesSampledData");
  15142. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesSampledData].Key, "MeterValuesSampledData");
  15143. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemAccessibility == 1)
  15144. {
  15145. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesSampledData].ReadOnly, "0"/*"FALSE"*/);
  15146. }
  15147. else
  15148. {
  15149. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesSampledData].ReadOnly, "1"/*"TRUE"*/);
  15150. }
  15151. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesSampledData].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData );
  15152. isKnowKey = TRUE;
  15153. }
  15154. if(isEmpty || strcmp(keyReq, "MeterValuesSampledDataMaxLength") == 0 )
  15155. {
  15156. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_MeterValuesSampledDataMaxLength].Item, "MeterValuesSampledDataMaxLength");
  15157. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesSampledDataMaxLength].Key, "MeterValuesSampledDataMaxLength");
  15158. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemAccessibility == 1)
  15159. {
  15160. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesSampledDataMaxLength].ReadOnly, "0"/*"FALSE"*/);
  15161. }
  15162. else
  15163. {
  15164. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesSampledDataMaxLength].ReadOnly, "1"/*"TRUE"*/);
  15165. }
  15166. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesSampledDataMaxLength].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemData );
  15167. isKnowKey = TRUE;
  15168. }
  15169. if(isEmpty || strcmp(keyReq, "MeterValueSampleInterval") == 0 )
  15170. {
  15171. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_MeterValueSampleInterval].Item, "MeterValueSampleInterval");
  15172. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValueSampleInterval].Key, "MeterValueSampleInterval");
  15173. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemAccessibility == 1)
  15174. {
  15175. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValueSampleInterval].ReadOnly, "0"/*"FALSE"*/);
  15176. }
  15177. else
  15178. {
  15179. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValueSampleInterval].ReadOnly, "1"/*"TRUE"*/);
  15180. }
  15181. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValueSampleInterval].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemData );
  15182. isKnowKey = TRUE;
  15183. }
  15184. if(isEmpty || strcmp(keyReq, "MinimumStatusDuration") == 0 )
  15185. {
  15186. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_MinimumStatusDuration].Item, "MinimumStatusDuration");
  15187. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MinimumStatusDuration].Key, "MinimumStatusDuration");
  15188. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemAccessibility == 1)
  15189. {
  15190. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MinimumStatusDuration].ReadOnly, "0"/*"FALSE"*/);
  15191. }
  15192. else
  15193. {
  15194. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MinimumStatusDuration].ReadOnly, "1"/*"TRUE"*/);
  15195. }
  15196. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MinimumStatusDuration].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[17].ItemData );
  15197. isKnowKey = TRUE;
  15198. }
  15199. if(isEmpty || strcmp(keyReq, "NumberOfConnectors") == 0 )
  15200. {
  15201. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_NumberOfConnectors].Item, "NumberOfConnectors");
  15202. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_NumberOfConnectors].Key, "NumberOfConnectors");
  15203. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemAccessibility == 1)
  15204. {
  15205. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_NumberOfConnectors].ReadOnly, "0"/*"FALSE"*/);
  15206. }
  15207. else
  15208. {
  15209. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_NumberOfConnectors].ReadOnly, "1"/*"TRUE"*/);
  15210. }
  15211. sprintf((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData, "%d", gunTotalNumber);
  15212. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_NumberOfConnectors].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData );
  15213. isKnowKey = TRUE;
  15214. }
  15215. if(isEmpty || strcmp(keyReq, "ResetRetries") == 0 )
  15216. {
  15217. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_ResetRetries].Item, "ResetRetries");
  15218. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ResetRetries].Key, "ResetRetries");
  15219. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemAccessibility == 1)
  15220. {
  15221. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ResetRetries].ReadOnly, "0"/*"FALSE"*/);
  15222. }
  15223. else
  15224. {
  15225. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ResetRetries].ReadOnly, "1"/*"TRUE"*/);
  15226. }
  15227. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ResetRetries].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemData );
  15228. isKnowKey = TRUE;
  15229. }
  15230. if(isEmpty || strcmp(keyReq, "ConnectorPhaseRotation") == 0 )
  15231. {
  15232. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_ConnectorPhaseRotation].Item, "ConnectorPhaseRotation");
  15233. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorPhaseRotation].Key, "ConnectorPhaseRotation");
  15234. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemAccessibility == 1)
  15235. {
  15236. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorPhaseRotation].ReadOnly, "0"/*"FALSE"*/);
  15237. }
  15238. else
  15239. {
  15240. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorPhaseRotation].ReadOnly, "1"/*"TRUE"*/);
  15241. }
  15242. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorPhaseRotation].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData );
  15243. isKnowKey = TRUE;
  15244. }
  15245. if(isEmpty || strcmp(keyReq, "ConnectorPhaseRotationMaxLength") == 0 )
  15246. {
  15247. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_ConnectorPhaseRotationMaxLength].Item, "ConnectorPhaseRotationMaxLength");
  15248. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorPhaseRotationMaxLength].Key, "ConnectorPhaseRotationMaxLength");
  15249. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemAccessibility == 1)
  15250. {
  15251. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorPhaseRotationMaxLength].ReadOnly, "0"/*"FALSE"*/);
  15252. }
  15253. else
  15254. {
  15255. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorPhaseRotationMaxLength].ReadOnly, "1"/*"TRUE"*/);
  15256. }
  15257. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorPhaseRotationMaxLength].Value,(const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemData );
  15258. isKnowKey = TRUE;
  15259. }
  15260. if(isEmpty || strcmp(keyReq, "StopTransactionOnEVSideDisconnect") == 0 )
  15261. {
  15262. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_StopTransactionOnEVSideDisconnect].Item, "StopTransactionOnEVSideDisconnect");
  15263. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTransactionOnEVSideDisconnect].Key, "StopTransactionOnEVSideDisconnect");
  15264. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemAccessibility == 1)
  15265. {
  15266. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTransactionOnEVSideDisconnect].ReadOnly, "0"/*"FALSE"*/);
  15267. }
  15268. else
  15269. {
  15270. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTransactionOnEVSideDisconnect].ReadOnly, "1"/*"TRUE"*/);
  15271. }
  15272. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTransactionOnEVSideDisconnect].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemData );
  15273. isKnowKey = TRUE;
  15274. }
  15275. if(isEmpty || strcmp(keyReq, "StopTransactionOnInvalidId") == 0 )
  15276. {
  15277. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_StopTransactionOnInvalidId].Item, "StopTransactionOnInvalidId");
  15278. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTransactionOnInvalidId].Key, "StopTransactionOnInvalidId");
  15279. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemAccessibility == 1)
  15280. {
  15281. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTransactionOnInvalidId].ReadOnly, "0"/*"FALSE"*/);
  15282. }
  15283. else
  15284. {
  15285. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTransactionOnInvalidId].ReadOnly, "1"/*"TRUE"*/);
  15286. }
  15287. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTransactionOnInvalidId].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemData );
  15288. isKnowKey = TRUE;
  15289. }
  15290. if(isEmpty || strcmp(keyReq, "StopTxnAlignedData") == 0 )
  15291. {
  15292. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_StopTxnAlignedData].Item, "StopTxnAlignedData");
  15293. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnAlignedData].Key, "StopTxnAlignedData");
  15294. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemAccessibility == 1)
  15295. {
  15296. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnAlignedData].ReadOnly, "0"/*"FALSE"*/);
  15297. }
  15298. else
  15299. {
  15300. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnAlignedData].ReadOnly, "1"/*"TRUE"*/);
  15301. }
  15302. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnAlignedData].Value,(const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemData );
  15303. isKnowKey = TRUE;
  15304. }
  15305. if(isEmpty || strcmp(keyReq, "StopTxnAlignedDataMaxLength") == 0 )
  15306. {
  15307. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_StopTxnAlignedDataMaxLength].Item, "StopTxnAlignedDataMaxLength");
  15308. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnAlignedDataMaxLength].Key, "StopTxnAlignedDataMaxLength");
  15309. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemAccessibility == 1)
  15310. {
  15311. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnAlignedDataMaxLength].ReadOnly, "0"/*"FALSE"*/);
  15312. }
  15313. else
  15314. {
  15315. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnAlignedDataMaxLength].ReadOnly, "1"/*"TRUE"*/);
  15316. }
  15317. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnAlignedDataMaxLength].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemData );
  15318. isKnowKey = TRUE;
  15319. }
  15320. if(isEmpty || strcmp(keyReq, "StopTxnSampledData") == 0 )
  15321. {
  15322. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_StopTxnSampledData].Item, "StopTxnSampledData");
  15323. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnSampledData].Key, "StopTxnSampledData");
  15324. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemAccessibility == 1)
  15325. {
  15326. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnSampledData].ReadOnly, "0"/*"FALSE"*/);
  15327. }
  15328. else
  15329. {
  15330. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnSampledData].ReadOnly, "1"/*"TRUE"*/);
  15331. }
  15332. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnSampledData].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData );
  15333. isKnowKey = TRUE;
  15334. }
  15335. if(isEmpty || strcmp(keyReq, "StopTxnSampledDataMaxLength") == 0 )
  15336. {
  15337. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_StopTxnSampledDataMaxLength].Item, "StopTxnSampledDataMaxLength");
  15338. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnSampledDataMaxLength].Key, "StopTxnSampledDataMaxLength");
  15339. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemAccessibility == 1)
  15340. {
  15341. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnSampledDataMaxLength].ReadOnly, "0"/*"FALSE"*/);
  15342. }
  15343. else
  15344. {
  15345. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnSampledDataMaxLength].ReadOnly, "1"/*"TRUE"*/);
  15346. }
  15347. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnSampledDataMaxLength].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemData );
  15348. isKnowKey = TRUE;
  15349. }
  15350. if(isEmpty || strcmp(keyReq, "SupportedFeatureProfiles") == 0 )
  15351. {
  15352. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_SupportedFeatureProfiles].Item, "SupportedFeatureProfiles");
  15353. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SupportedFeatureProfiles].Key, "SupportedFeatureProfiles");
  15354. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemAccessibility == 1)
  15355. {
  15356. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SupportedFeatureProfiles].ReadOnly, "0"/*"FALSE"*/);
  15357. }
  15358. else
  15359. {
  15360. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SupportedFeatureProfiles].ReadOnly, "1"/*"TRUE"*/);
  15361. }
  15362. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SupportedFeatureProfiles].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemData );
  15363. isKnowKey = TRUE;
  15364. }
  15365. if(isEmpty || strcmp(keyReq, "SupportedFeatureProfilesMaxLength") == 0 )
  15366. {
  15367. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_SupportedFeatureProfilesMaxLength].Item, "SupportedFeatureProfilesMaxLength");
  15368. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SupportedFeatureProfilesMaxLength].Key, "SupportedFeatureProfilesMaxLength");
  15369. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemAccessibility == 1)
  15370. {
  15371. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SupportedFeatureProfilesMaxLength].ReadOnly, "0"/*"FALSE"*/);
  15372. }
  15373. else
  15374. {
  15375. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SupportedFeatureProfilesMaxLength].ReadOnly, "1"/*"TRUE"*/);
  15376. }
  15377. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SupportedFeatureProfilesMaxLength].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemData );
  15378. isKnowKey = TRUE;
  15379. }
  15380. if(isEmpty || strcmp(keyReq, "TransactionMessageAttempts") == 0 )
  15381. {
  15382. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_TransactionMessageAttempts].Item, "TransactionMessageAttempts");
  15383. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TransactionMessageAttempts].Key, "TransactionMessageAttempts");
  15384. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemAccessibility == 1)
  15385. {
  15386. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TransactionMessageAttempts].ReadOnly, "0"/*"FALSE"*/);
  15387. }
  15388. else
  15389. {
  15390. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TransactionMessageAttempts].ReadOnly, "1"/*"TRUE"*/);
  15391. }
  15392. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TransactionMessageAttempts].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData );
  15393. isKnowKey = TRUE;
  15394. }
  15395. if(isEmpty || strcmp(keyReq, "TransactionMessageRetryInterval") == 0 )
  15396. {
  15397. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_TransactionMessageRetryInterval].Item, "TransactionMessageRetryInterval");
  15398. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TransactionMessageRetryInterval].Key, "TransactionMessageRetryInterval");
  15399. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemAccessibility == 1)
  15400. {
  15401. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TransactionMessageRetryInterval].ReadOnly, "0"/*"FALSE"*/);
  15402. }
  15403. else
  15404. {
  15405. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TransactionMessageRetryInterval].ReadOnly, "1"/*"TRUE"*/);
  15406. }
  15407. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TransactionMessageRetryInterval].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData );
  15408. isKnowKey = TRUE;
  15409. }
  15410. if(isEmpty || strcmp(keyReq, "UnlockConnectorOnEVSideDisconnect") == 0 )
  15411. {
  15412. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_UnlockConnectorOnEVSideDisconnect].Item, "UnlockConnectorOnEVSideDisconnect");
  15413. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_UnlockConnectorOnEVSideDisconnect].Key, "UnlockConnectorOnEVSideDisconnect");
  15414. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemAccessibility == 1)
  15415. {
  15416. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_UnlockConnectorOnEVSideDisconnect].ReadOnly, "0"/*"FALSE"*/);
  15417. }
  15418. else
  15419. {
  15420. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_UnlockConnectorOnEVSideDisconnect].ReadOnly, "1"/*"TRUE"*/);
  15421. }
  15422. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_UnlockConnectorOnEVSideDisconnect].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemData );
  15423. isKnowKey = TRUE;
  15424. }
  15425. if(isEmpty || strcmp(keyReq, "WebSocketPingInterval") == 0 )
  15426. {
  15427. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_WebSocketPingInterval].Item, "WebSocketPingInterval");
  15428. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_WebSocketPingInterval].Key, "WebSocketPingInterval");
  15429. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemAccessibility == 1)
  15430. {
  15431. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_WebSocketPingInterval].ReadOnly, "0"/*"FALSE"*/);
  15432. }
  15433. else
  15434. {
  15435. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_WebSocketPingInterval].ReadOnly, "1"/*"TRUE"*/);
  15436. }
  15437. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_WebSocketPingInterval].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemData );
  15438. isKnowKey = TRUE;
  15439. }
  15440. if(isEmpty || strcmp(keyReq, "QueueOffLineMeterValues") == 0 )
  15441. {
  15442. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_QueueOffLineMeterValues].Item, "QueueOffLineMeterValues");
  15443. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_QueueOffLineMeterValues].Key, "QueueOffLineMeterValues");
  15444. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[QueueOffLineMeterValues].ItemAccessibility == 1)
  15445. {
  15446. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_QueueOffLineMeterValues].ReadOnly, "0"/*"FALSE"*/);
  15447. }
  15448. else
  15449. {
  15450. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_QueueOffLineMeterValues].ReadOnly, "1"/*"TRUE"*/);
  15451. }
  15452. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_QueueOffLineMeterValues].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[QueueOffLineMeterValues].ItemData );
  15453. isKnowKey = TRUE;
  15454. }
  15455. /*
  15456. if(isEmpty || strcmp(keyReq, "AuthorizationKey") == 0 )
  15457. {
  15458. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_AuthorizationKey].Item, "AuthorizationKey");
  15459. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizationKey].Key, "AuthorizationKey");
  15460. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationKey].ItemAccessibility == 1)
  15461. {
  15462. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizationKey].ReadOnly, "0");
  15463. }
  15464. else
  15465. {
  15466. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizationKey].ReadOnly, "1");
  15467. }
  15468. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizationKey].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationKey].ItemData );
  15469. isKnowKey = TRUE;
  15470. }*/
  15471. if(isEmpty || strcmp(keyReq, "SecurityProfile") == 0 )
  15472. {
  15473. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_SecurityProfile].Item, "SecurityProfile");
  15474. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SecurityProfile].Key, "SecurityProfile");
  15475. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[SecurityProfile].ItemAccessibility == 1)
  15476. {
  15477. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SecurityProfile].ReadOnly, "0"/*"FALSE"*/);
  15478. }
  15479. else
  15480. {
  15481. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SecurityProfile].ReadOnly, "1"/*"TRUE"*/);
  15482. }
  15483. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SecurityProfile].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SecurityProfile].ItemData );
  15484. isKnowKey = TRUE;
  15485. }
  15486. if(isEmpty || strcmp(keyReq, "DefaultPrice") == 0 )
  15487. {
  15488. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_DefaultPrice].Item, "DefaultPrice");
  15489. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_DefaultPrice].Key, "DefaultPrice");
  15490. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[DefaultPrice].ItemAccessibility == 1)
  15491. {
  15492. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_DefaultPrice].ReadOnly, "0"/*"FALSE"*/);
  15493. }
  15494. else
  15495. {
  15496. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_DefaultPrice].ReadOnly, "1"/*"TRUE"*/);
  15497. }
  15498. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_DefaultPrice].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[DefaultPrice].ItemData );
  15499. isKnowKey = TRUE;
  15500. }
  15501. if(isEmpty || strcmp(keyReq, "CustomDisplayCostAndPrice") == 0 )
  15502. {
  15503. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_CustomDisplayCostAndPrice].Item, "CustomDisplayCostAndPrice");
  15504. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_CustomDisplayCostAndPrice].Key, "CustomDisplayCostAndPrice");
  15505. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemAccessibility == 1)
  15506. {
  15507. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_CustomDisplayCostAndPrice].ReadOnly, "0"/*"FALSE"*/);
  15508. }
  15509. else
  15510. {
  15511. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_CustomDisplayCostAndPrice].ReadOnly, "1"/*"TRUE"*/);
  15512. }
  15513. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_CustomDisplayCostAndPrice].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemData );
  15514. isKnowKey = TRUE;
  15515. }
  15516. if(isEmpty || strcmp(keyReq, "CustomIdleFeeAfterStop") == 0 )
  15517. {
  15518. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_CustomIdleFeeAfterStop].Item, "CustomIdleFeeAfterStop");
  15519. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_CustomIdleFeeAfterStop].Key, "CustomIdleFeeAfterStop");
  15520. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemAccessibility == 1)
  15521. {
  15522. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_CustomIdleFeeAfterStop].ReadOnly, "0"/*"FALSE"*/);
  15523. }
  15524. else
  15525. {
  15526. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_CustomIdleFeeAfterStop].ReadOnly, "1"/*"TRUE"*/);
  15527. }
  15528. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_CustomIdleFeeAfterStop].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemData );
  15529. isKnowKey = TRUE;
  15530. }
  15531. if(isEmpty || strcmp(keyReq, "TimeOffset") == 0 )
  15532. {
  15533. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_TimeOffset].Item, "TimeOffset");
  15534. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TimeOffset].Key, "TimeOffset");
  15535. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffset].ItemAccessibility == 1)
  15536. {
  15537. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TimeOffset].ReadOnly, "0"/*"FALSE"*/);
  15538. }
  15539. else
  15540. {
  15541. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TimeOffset].ReadOnly, "1"/*"TRUE"*/);
  15542. }
  15543. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TimeOffset].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffset].ItemData );
  15544. isKnowKey = TRUE;
  15545. }
  15546. if(isEmpty || strcmp(keyReq, "NextTimeOffsetTransitionDateTime") == 0 )
  15547. {
  15548. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_NextTimeOffsetTransitionDateTime].Item, "NextTimeOffsetTransitionDateTime");
  15549. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_NextTimeOffsetTransitionDateTime].Key, "NextTimeOffsetTransitionDateTime");
  15550. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[NextTimeOffsetTransitionDateTime].ItemAccessibility == 1)
  15551. {
  15552. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_NextTimeOffsetTransitionDateTime].ReadOnly, "0"/*"FALSE"*/);
  15553. }
  15554. else
  15555. {
  15556. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_NextTimeOffsetTransitionDateTime].ReadOnly, "1"/*"TRUE"*/);
  15557. }
  15558. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_NextTimeOffsetTransitionDateTime].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NextTimeOffsetTransitionDateTime].ItemData );
  15559. isKnowKey = TRUE;
  15560. }
  15561. if(isEmpty || strcmp(keyReq, "TimeOffsetNextTransition") == 0 )
  15562. {
  15563. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_TimeOffsetNextTransition].Item, "TimeOffsetNextTransition");
  15564. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TimeOffsetNextTransition].Key, "TimeOffsetNextTransition");
  15565. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffsetNextTransition].ItemAccessibility == 1)
  15566. {
  15567. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TimeOffsetNextTransition].ReadOnly, "0"/*"FALSE"*/);
  15568. }
  15569. else
  15570. {
  15571. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TimeOffsetNextTransition].ReadOnly, "1"/*"TRUE"*/);
  15572. }
  15573. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TimeOffsetNextTransition].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffsetNextTransition].ItemData );
  15574. isKnowKey = TRUE;
  15575. }
  15576. if(isEmpty || strcmp(keyReq, "SystemUptimeSec") == 0 )
  15577. {
  15578. struct sysinfo s_info;
  15579. int error = sysinfo(&s_info);
  15580. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_SystemUptimeSec].Item, "SystemUptimeSec");
  15581. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SystemUptimeSec].Key, "SystemUptimeSec");
  15582. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[SystemUptimeSec].ItemAccessibility == 1)
  15583. {
  15584. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SystemUptimeSec].ReadOnly, "0"/*"FALSE"*/);
  15585. }
  15586. else
  15587. {
  15588. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SystemUptimeSec].ReadOnly, "1"/*"TRUE"*/);
  15589. }
  15590. if(error != 0)
  15591. {
  15592. DEBUG_WARN("System uptime get error: %d\n", error);
  15593. }
  15594. else
  15595. {
  15596. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SystemUptimeSec].ItemData, "%ld", s_info.uptime);
  15597. sprintf((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SystemUptimeSec].Value, "%ld", s_info.uptime);
  15598. }
  15599. isKnowKey = TRUE;
  15600. }
  15601. if(isEmpty || strcmp(keyReq, "FreeVend") == 0 )
  15602. {
  15603. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_FreeVend].Item, "FreeVend");
  15604. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_FreeVend].Key, "FreeVend");
  15605. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[FreeVend].ItemAccessibility == 1)
  15606. {
  15607. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_FreeVend].ReadOnly, "0"/*"FALSE"*/);
  15608. }
  15609. else
  15610. {
  15611. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_FreeVend].ReadOnly, "1"/*"TRUE"*/);
  15612. }
  15613. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_FreeVend].Value, (ShmSysConfigAndInfo->SysConfig.AuthorisationMode?"TRUE":"FALSE"));
  15614. isKnowKey = TRUE;
  15615. }
  15616. if(isEmpty || strcmp(keyReq, "OcppServer") == 0 )
  15617. {
  15618. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_OcppServer].Item, "OcppServer");
  15619. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_OcppServer].Key, "OcppServer");
  15620. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[OcppServer].ItemAccessibility == 1)
  15621. {
  15622. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_OcppServer].ReadOnly, "0"/*"FALSE"*/);
  15623. }
  15624. else
  15625. {
  15626. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_OcppServer].ReadOnly, "1"/*"TRUE"*/);
  15627. }
  15628. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_OcppServer].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[OcppServer].ItemData);
  15629. isKnowKey = TRUE;
  15630. }
  15631. if(isEmpty || strcmp(keyReq, "MaintainServer") == 0 )
  15632. {
  15633. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_MaintainServer].Item, "MaintainServer");
  15634. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaintainServer].Key, "MaintainServer");
  15635. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MaintainServer].ItemAccessibility == 1)
  15636. {
  15637. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaintainServer].ReadOnly, "0"/*"FALSE"*/);
  15638. }
  15639. else
  15640. {
  15641. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaintainServer].ReadOnly, "1"/*"TRUE"*/);
  15642. }
  15643. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaintainServer].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MaintainServer].ItemData);
  15644. isKnowKey = TRUE;
  15645. }
  15646. if(isEmpty || strcmp(keyReq, "StatusNotificationPeriodically") == 0 )
  15647. {
  15648. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_StatusNotificationPeriodically].Item, "StatusNotificationPeriodically");
  15649. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TransactionMessageAttempts].Key, "StatusNotificationPeriodically");
  15650. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StatusNotificationPeriodically].ItemAccessibility == 1)
  15651. {
  15652. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StatusNotificationPeriodically].ReadOnly, "0"/*"FALSE"*/);
  15653. }
  15654. else
  15655. {
  15656. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StatusNotificationPeriodically].ReadOnly, "1"/*"TRUE"*/);
  15657. }
  15658. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StatusNotificationPeriodically].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StatusNotificationPeriodically].ItemData );
  15659. isKnowKey = TRUE;
  15660. }
  15661. if(isEmpty || strcmp(keyReq, "StatusNotificationInterval") == 0 )
  15662. {
  15663. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_StatusNotificationInterval].Item, "StatusNotificationInterval");
  15664. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StatusNotificationInterval].Key, "StatusNotificationInterval");
  15665. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StatusNotificationInterval].ItemAccessibility == 1)
  15666. {
  15667. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StatusNotificationInterval].ReadOnly, "0"/*"FALSE"*/);
  15668. }
  15669. else
  15670. {
  15671. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StatusNotificationInterval].ReadOnly, "1"/*"TRUE"*/);
  15672. }
  15673. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StatusNotificationInterval].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StatusNotificationInterval].ItemData );
  15674. isKnowKey = TRUE;
  15675. }
  15676. if(isEmpty || strcmp(keyReq, "ConfigurationVersion") == 0 )
  15677. {
  15678. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_ConfigurationVersion].Item, "ConfigurationVersion");
  15679. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConfigurationVersion].Key, "ConfigurationVersion");
  15680. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[ConfigurationVersion].ItemAccessibility == 1)
  15681. {
  15682. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConfigurationVersion].ReadOnly, "0"/*"FALSE"*/);
  15683. }
  15684. else
  15685. {
  15686. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConfigurationVersion].ReadOnly, "1"/*"TRUE"*/);
  15687. }
  15688. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConfigurationVersion].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConfigurationVersion].ItemData );
  15689. isKnowKey = TRUE;
  15690. }
  15691. #if 1
  15692. if(isEmpty || strcmp(keyReq, "LocalAuthListEnabled") == 0 )
  15693. {
  15694. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_LocalAuthListEnabled].Item, "LocalAuthListEnabled");
  15695. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListEnabled].Key, "LocalAuthListEnabled");
  15696. if(ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemAccessibility == 1)
  15697. {
  15698. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListEnabled].ReadOnly, "0"/*"FALSE"*/);
  15699. }
  15700. else
  15701. {
  15702. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListEnabled].ReadOnly, "1"/*"TRUE"*/);
  15703. }
  15704. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListEnabled].Value, (const char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData );
  15705. isKnowKey = TRUE;
  15706. }
  15707. #endif
  15708. if(isEmpty || strcmp(keyReq, "LocalAuthListMaxLength") == 0 )
  15709. {
  15710. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_LocalAuthListMaxLength].Item, "LocalAuthListMaxLength");
  15711. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListMaxLength].Key, "LocalAuthListMaxLength");
  15712. if(ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemAccessibility == 1)
  15713. {
  15714. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListMaxLength].ReadOnly, "0"/*"FALSE"*/);
  15715. }
  15716. else
  15717. {
  15718. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListMaxLength].ReadOnly, "1"/*"TRUE"*/);
  15719. }
  15720. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListMaxLength].Value, (const char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemData );
  15721. isKnowKey = TRUE;
  15722. }
  15723. if(isEmpty || strcmp(keyReq, "SendLocalListMaxLength") == 0 )
  15724. {
  15725. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_SendLocalListMaxLength].Item, "SendLocalListMaxLength");
  15726. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SendLocalListMaxLength].Key, "SendLocalListMaxLength");
  15727. if(ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemAccessibility == 1)
  15728. {
  15729. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SendLocalListMaxLength].ReadOnly, "0"/*"FALSE"*/);
  15730. }
  15731. else
  15732. {
  15733. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SendLocalListMaxLength].ReadOnly, "1"/*"TRUE"*/);
  15734. }
  15735. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SendLocalListMaxLength].Value, (const char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemData );
  15736. isKnowKey = TRUE;
  15737. }
  15738. if(isEmpty || strcmp(keyReq, "ReserveConnectorZeroSupported") == 0 )
  15739. {
  15740. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_ReserveConnectorZeroSupported].Item, "ReserveConnectorZeroSupported");
  15741. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ReserveConnectorZeroSupported].Key, "ReserveConnectorZeroSupported");
  15742. if(ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemAccessibility == 1)
  15743. {
  15744. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ReserveConnectorZeroSupported].ReadOnly, "0"/*"FALSE"*/);
  15745. }
  15746. else
  15747. {
  15748. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ReserveConnectorZeroSupported].ReadOnly, "1"/*"TRUE"*/);
  15749. }
  15750. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ReserveConnectorZeroSupported].Value,(const char *)ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemData);
  15751. isKnowKey = TRUE;
  15752. }
  15753. if(isEmpty || strcmp(keyReq, "ChargeProfileMaxStackLevel") == 0 )
  15754. {
  15755. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_ChargeProfileMaxStackLevel].Item, "ChargeProfileMaxStackLevel");
  15756. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargeProfileMaxStackLevel].Key, "ChargeProfileMaxStackLevel");
  15757. if(ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemAccessibility == 1)
  15758. {
  15759. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargeProfileMaxStackLevel].ReadOnly, "0"/*"FALSE"*/);
  15760. }
  15761. else
  15762. {
  15763. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargeProfileMaxStackLevel].ReadOnly, "1"/*"TRUE"*/);
  15764. }
  15765. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargeProfileMaxStackLevel].Value, (const char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemData);
  15766. isKnowKey = TRUE;
  15767. }
  15768. if(isEmpty || strcmp(keyReq, "ChargingScheduleAllowedChargingRateUnit") == 0 )
  15769. {
  15770. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_ChargingScheduleAllowedChargingRateUnit].Item, "ChargingScheduleAllowedChargingRateUnit");
  15771. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargingScheduleAllowedChargingRateUnit].Key, "ChargingScheduleAllowedChargingRateUnit");
  15772. if(ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemAccessibility == 1)
  15773. {
  15774. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargingScheduleAllowedChargingRateUnit].ReadOnly, "0"/*"FALSE"*/);
  15775. }
  15776. else
  15777. {
  15778. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargingScheduleAllowedChargingRateUnit].ReadOnly, "1"/*"TRUE"*/);
  15779. }
  15780. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargingScheduleAllowedChargingRateUnit].Value, (const char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemData);
  15781. isKnowKey = TRUE;
  15782. }
  15783. if(isEmpty || strcmp(keyReq, "ChargingScheduleMaxPeriods") == 0 )
  15784. {
  15785. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_ChargingScheduleMaxPeriods].Item, "ChargingScheduleMaxPeriods");
  15786. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargingScheduleMaxPeriods].Key, "ChargingScheduleMaxPeriods");
  15787. if(ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemAccessibility == 1)
  15788. {
  15789. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargingScheduleMaxPeriods].ReadOnly, "0"/*"FALSE"*/);
  15790. }
  15791. else
  15792. {
  15793. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargingScheduleMaxPeriods].ReadOnly, "1"/*"TRUE"*/);
  15794. }
  15795. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargingScheduleMaxPeriods].Value, (const char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemData);
  15796. isKnowKey = TRUE;
  15797. }
  15798. if(isEmpty || strcmp(keyReq, "ConnectorSwitch3to1PhaseSupported") == 0 )
  15799. {
  15800. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_ConnectorSwitch3to1PhaseSupported].Item, "ConnectorSwitch3to1PhaseSupported");
  15801. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorSwitch3to1PhaseSupported].Key, "ConnectorSwitch3to1PhaseSupported");
  15802. if(ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemAccessibility == 1)
  15803. {
  15804. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorSwitch3to1PhaseSupported].ReadOnly, "0"/*"FALSE"*/);
  15805. }
  15806. else
  15807. {
  15808. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorSwitch3to1PhaseSupported].ReadOnly, "1"/*"TRUE"*/);
  15809. }
  15810. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorSwitch3to1PhaseSupported].Value, (const char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemData);
  15811. isKnowKey = TRUE;
  15812. }
  15813. if(isEmpty || strcmp(keyReq, "MaxChargingProfilesInstalled") == 0 )
  15814. {
  15815. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_MaxChargingProfilesInstalled].Item, "MaxChargingProfilesInstalled");
  15816. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaxChargingProfilesInstalled].Key, "MaxChargingProfilesInstalled");
  15817. if(ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemAccessibility == 1)
  15818. {
  15819. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaxChargingProfilesInstalled].ReadOnly, "0"/*"FLASE"*/);
  15820. }
  15821. else
  15822. {
  15823. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaxChargingProfilesInstalled].ReadOnly, "1"/*"TRUE"*/);
  15824. }
  15825. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaxChargingProfilesInstalled].Value, (const char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemData);
  15826. isKnowKey = TRUE;
  15827. }
  15828. //=========================================================
  15829. if(!isEmpty && !isKnowKey)
  15830. {
  15831. DEBUG_INFO("unKnowIndex =%d\n", UnknownKeynum);
  15832. strcpy(unknownkey[UnknownKeynum], keyReq);
  15833. UnknownKeynum = UnknownKeynum + 1;
  15834. }
  15835. }
  15836. void processUnkownKey(void)
  15837. {
  15838. DEBUG_INFO("processUnkownKey...\n");
  15839. memset(ShmOCPP16Data->GetConfiguration.ResponseUnknownKey, 0 , sizeof(struct StructConfigurationKeyItems)* 10);
  15840. for(int index=0; index < UnknownKeynum; index++)
  15841. {
  15842. if(ShmOCPP16Data->GetConfiguration.ResponseUnknownKey[index].Item[0] == 0)
  15843. {
  15844. strcpy((char *)(ShmOCPP16Data->GetConfiguration.ResponseUnknownKey[index].Item), unknownkey[index]);
  15845. }
  15846. }
  15847. }
  15848. int setKeyValue(char *key, char *value)
  15849. {
  15850. int isSuccess = NotSupported;
  15851. int check_ascii=0;
  15852. char str[501]={0};
  15853. DEBUG_INFO(" setKeyValue %s = %s\n", key, value);
  15854. if(strcmp(key, "AllowOfflineTxForUnknownId") == 0)
  15855. {
  15856. //Charger.AllowOfflineTxForUnknownId = (value.toLowerCase().equals("true")?true:false);
  15857. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemAccessibility == 1)
  15858. {
  15859. strcpy(str, (const char*)value);
  15860. for(int i = 0; str[i]; i++){
  15861. str[i] = tolower(str[i]);
  15862. }
  15863. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  15864. isSuccess = ConfigurationStatus_Accepted;
  15865. }
  15866. else
  15867. {
  15868. isSuccess = ConfigurationStatus_Rejected;
  15869. }
  15870. }
  15871. if(strcmp(key, "AuthorizationCacheEnabled") == 0)
  15872. {
  15873. //Charger.AuthorizationCacheEnabled = (value.toLowerCase().equals("true")?true:false);
  15874. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemAccessibility == 1)
  15875. {
  15876. strcpy(str, (const char*)value);
  15877. for(int i = 0; str[i]; i++){
  15878. str[i] = tolower(str[i]);
  15879. }
  15880. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  15881. isSuccess = ConfigurationStatus_Accepted;
  15882. //updateSetting("AuthorizationCacheEnabled",(char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[1].ItemData);
  15883. }
  15884. else
  15885. {
  15886. isSuccess = ConfigurationStatus_Rejected;
  15887. }
  15888. }
  15889. if(strcmp(key, "AuthorizeRemoteTxRequests") == 0)
  15890. {
  15891. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemAccessibility == 1)
  15892. {
  15893. strcpy(str, (const char*)value);
  15894. for(int i = 0; str[i]; i++)
  15895. {
  15896. str[i] = tolower(str[i]);
  15897. }
  15898. //Charger.AuthorizeRemoteTxRequests = (value.toLowerCase().equals("true")?true:false);
  15899. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  15900. isSuccess = ConfigurationStatus_Accepted;
  15901. }
  15902. else
  15903. {
  15904. isSuccess = ConfigurationStatus_Rejected;
  15905. }
  15906. }
  15907. if(strcmp(key, "BlinkRepeat") == 0)
  15908. {
  15909. //Charger.BlinkRepeat = Integer.parseInt(value);
  15910. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemAccessibility == 1)
  15911. {
  15912. check_ascii = value[0];
  15913. if( (check_ascii < 48) || (check_ascii > 57) )
  15914. {
  15915. isSuccess = ConfigurationStatus_Rejected;
  15916. }
  15917. else
  15918. {
  15919. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemData, "%d", atoi(value) );
  15920. isSuccess = ConfigurationStatus_Accepted;
  15921. }
  15922. }
  15923. else
  15924. {
  15925. isSuccess = ConfigurationStatus_Rejected;
  15926. }
  15927. }
  15928. if(strcmp(key, "ClockAlignedDataInterval") == 0)
  15929. {
  15930. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemAccessibility == 1)
  15931. {
  15932. check_ascii = value[0];
  15933. if( (check_ascii < 48) || (check_ascii > 57) )
  15934. {
  15935. isSuccess = ConfigurationStatus_Rejected;
  15936. }
  15937. else
  15938. {
  15939. if((atoi(value) == 0) || (atoi(value) >= 5))
  15940. {
  15941. //Charger.ClockAlignedDataInterval = Integer.parseInt(value)*1000;
  15942. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemData, "%d", atoi(value) );
  15943. isSuccess = ConfigurationStatus_Accepted;
  15944. }
  15945. else
  15946. isSuccess = ConfigurationStatus_Rejected;
  15947. }
  15948. }
  15949. else
  15950. {
  15951. isSuccess = ConfigurationStatus_Rejected;
  15952. }
  15953. }
  15954. if(strcmp(key, "ConnectionTimeOut") == 0 )
  15955. {
  15956. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemAccessibility == 1)
  15957. {
  15958. check_ascii = value[0];
  15959. if( (check_ascii < 48) || (check_ascii > 57) )
  15960. {
  15961. isSuccess = ConfigurationStatus_Rejected;
  15962. }
  15963. else
  15964. {
  15965. //Charger.ConnectionTimeOut = Integer.parseInt(value)*1000;
  15966. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemData, "%d", atoi(value));
  15967. isSuccess = ConfigurationStatus_Accepted;
  15968. }
  15969. }
  15970. else
  15971. {
  15972. isSuccess = ConfigurationStatus_Rejected;
  15973. }
  15974. }
  15975. if(strcmp(key, "GetConfigurationMaxKeys") == 0)
  15976. {
  15977. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemAccessibility == 1)
  15978. {
  15979. check_ascii = value[0];
  15980. if( (check_ascii < 48) || (check_ascii > 57) )
  15981. {
  15982. isSuccess = ConfigurationStatus_Rejected;
  15983. }
  15984. else
  15985. {
  15986. //Charger.HeartbeatInterval = Integer.parseInt(value)*1000;
  15987. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemData, "%d", atoi(value) );
  15988. isSuccess = ConfigurationStatus_Accepted;
  15989. }
  15990. }
  15991. else
  15992. {
  15993. isSuccess = ConfigurationStatus_Rejected;
  15994. }
  15995. }
  15996. if(strcmp(key, "HeartbeatInterval") == 0)
  15997. {
  15998. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemAccessibility == 1)
  15999. {
  16000. check_ascii = value[0];
  16001. if( (check_ascii < 48) || (check_ascii > 57) )
  16002. {
  16003. isSuccess = ConfigurationStatus_Rejected;
  16004. }
  16005. else
  16006. {
  16007. if((atoi(value) == 0) || (atoi(value) >= 10))
  16008. {
  16009. //Charger.HeartbeatInterval = Integer.parseInt(value)*1000;
  16010. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemData, "%d", atoi(value));
  16011. HeartBeatWaitTime = atoi(value);
  16012. isSuccess = ConfigurationStatus_Accepted;
  16013. }
  16014. else
  16015. {
  16016. isSuccess = ConfigurationStatus_Rejected;
  16017. }
  16018. }
  16019. }
  16020. else
  16021. {
  16022. isSuccess = ConfigurationStatus_Rejected;
  16023. }
  16024. }
  16025. if(strcmp(key, "LightIntensity") == 0)
  16026. {
  16027. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemAccessibility == 1)
  16028. {
  16029. check_ascii = value[0];
  16030. if( (check_ascii < 48) || (check_ascii > 57) )
  16031. {
  16032. isSuccess = ConfigurationStatus_Rejected;
  16033. }
  16034. else
  16035. {
  16036. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemData, "%d", atoi(value) );
  16037. isSuccess = ConfigurationStatus_Accepted;
  16038. }
  16039. }
  16040. else
  16041. {
  16042. isSuccess = ConfigurationStatus_Rejected;
  16043. }
  16044. }
  16045. if(strcmp(key, "LocalAuthorizeOffline") == 0)
  16046. {
  16047. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemAccessibility == 1)
  16048. {
  16049. strcpy(str, (const char*)value);
  16050. for(int i = 0; str[i]; i++)
  16051. {
  16052. str[i] = tolower(str[i]);
  16053. }
  16054. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  16055. isSuccess = ConfigurationStatus_Accepted;
  16056. //updateSetting("LocalAuthorizeOffline", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemData);
  16057. }
  16058. else
  16059. {
  16060. isSuccess = ConfigurationStatus_Rejected;
  16061. }
  16062. }
  16063. if(strcmp(key, "LocalPreAuthorize") == 0)
  16064. {
  16065. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemAccessibility == 1)
  16066. {
  16067. strcpy(str, (const char*)value);
  16068. for(int i = 0; str[i]; i++)
  16069. {
  16070. str[i] = tolower(str[i]);
  16071. }
  16072. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  16073. isSuccess = ConfigurationStatus_Accepted;
  16074. }
  16075. else
  16076. {
  16077. isSuccess = ConfigurationStatus_Rejected;
  16078. }
  16079. }
  16080. if(strcmp(key, "MaxEnergyOnInvalidId") == 0)
  16081. {
  16082. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemAccessibility == 1)
  16083. {
  16084. check_ascii = value[0];
  16085. if( (check_ascii < 48) || (check_ascii > 57) )
  16086. {
  16087. isSuccess = ConfigurationStatus_Rejected;
  16088. }
  16089. else
  16090. {
  16091. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemData, "%d", atoi(value) );
  16092. isSuccess = ConfigurationStatus_Accepted;
  16093. }
  16094. }
  16095. else
  16096. {
  16097. isSuccess = ConfigurationStatus_Rejected;
  16098. }
  16099. }
  16100. if(strcmp(key, "MeterValuesAlignedData") == 0)
  16101. {
  16102. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemAccessibility == 1)
  16103. {
  16104. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, "%s", value );
  16105. isSuccess = ConfigurationStatus_Accepted;
  16106. }
  16107. else
  16108. {
  16109. isSuccess = ConfigurationStatus_Rejected;
  16110. }
  16111. }
  16112. if(strcmp(key, "MeterValuesAlignedDataMaxLength") == 0)
  16113. {
  16114. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemAccessibility == 1)
  16115. {
  16116. check_ascii = value[0];
  16117. if( (check_ascii < 48) || (check_ascii > 57) )
  16118. {
  16119. isSuccess = ConfigurationStatus_Rejected;
  16120. }
  16121. else
  16122. {
  16123. //Charger.MeterValueSampleInterval = Integer.parseInt(value)*1000;
  16124. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemData, "%d", atoi(value));
  16125. isSuccess = ConfigurationStatus_Accepted;
  16126. }
  16127. }
  16128. else
  16129. {
  16130. isSuccess = ConfigurationStatus_Rejected;
  16131. }
  16132. }
  16133. if(strcmp(key, "MeterValuesSampledData") == 0 )
  16134. {
  16135. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemAccessibility == 1)
  16136. {
  16137. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, "%s", value );
  16138. isSuccess = ConfigurationStatus_Accepted;
  16139. }
  16140. else
  16141. {
  16142. isSuccess = ConfigurationStatus_Rejected;
  16143. }
  16144. }
  16145. if(strcmp(key, "MeterValuesSampledDataMaxLength") == 0)
  16146. {
  16147. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemAccessibility == 1)
  16148. {
  16149. check_ascii = value[0];
  16150. if( (check_ascii < 48) || (check_ascii > 57) )
  16151. {
  16152. isSuccess = ConfigurationStatus_Rejected;
  16153. }
  16154. else
  16155. {
  16156. //Charger.MeterValueSampleInterval = Integer.parseInt(value)*1000;
  16157. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemData, "%d", atoi(value));
  16158. isSuccess = ConfigurationStatus_Accepted;
  16159. }
  16160. }
  16161. else
  16162. {
  16163. isSuccess = ConfigurationStatus_Rejected;
  16164. }
  16165. }
  16166. if(strcmp(key, "MeterValueSampleInterval") == 0)
  16167. {
  16168. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemAccessibility == 1)
  16169. {
  16170. check_ascii = value[0];
  16171. if( (check_ascii < 48) || (check_ascii > 57) )
  16172. {
  16173. isSuccess = ConfigurationStatus_Rejected;
  16174. }
  16175. else
  16176. {
  16177. if((atoi(value) == 0) || (atoi(value) >= 3))
  16178. {
  16179. //Charger.MeterValueSampleInterval = Integer.parseInt(value)*1000;
  16180. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemData, "%d", atoi(value));
  16181. isSuccess = ConfigurationStatus_Accepted;
  16182. }
  16183. else
  16184. {
  16185. isSuccess = ConfigurationStatus_Rejected;
  16186. }
  16187. }
  16188. }
  16189. else
  16190. {
  16191. isSuccess = ConfigurationStatus_Rejected;
  16192. }
  16193. }
  16194. if(strcmp(key, "MinimumStatusDuration") == 0)
  16195. {
  16196. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemAccessibility == 1)
  16197. {
  16198. check_ascii = value[0];
  16199. if( (check_ascii < 48) || (check_ascii > 57) )
  16200. {
  16201. isSuccess = ConfigurationStatus_Rejected;
  16202. }
  16203. else
  16204. {
  16205. if(atoi(value) == 0) // MinimumStatusDuration's value can not be 0
  16206. {
  16207. isSuccess = ConfigurationStatus_Rejected;
  16208. }
  16209. else
  16210. {
  16211. //Charger.MinimumStatusDuration = Integer.parseInt(value);
  16212. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemData, "%d", atoi(value) );
  16213. server_cycle_Status = atoi(value); //StatusNotification Cycle
  16214. isSuccess = ConfigurationStatus_Accepted;
  16215. }
  16216. }
  16217. }
  16218. else
  16219. {
  16220. isSuccess = ConfigurationStatus_Rejected;
  16221. }
  16222. }
  16223. if(strcmp(key, "NumberOfConnectors") == 0)
  16224. {
  16225. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemAccessibility == 1)
  16226. {
  16227. check_ascii = value[0];
  16228. if( (check_ascii < 48) || (check_ascii > 57) )
  16229. {
  16230. isSuccess = ConfigurationStatus_Rejected;
  16231. }
  16232. else
  16233. {
  16234. //Charger.ResetRetries = Integer.parseInt(value);
  16235. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData, "%d", atoi(value) );
  16236. isSuccess = ConfigurationStatus_Accepted;
  16237. }
  16238. }
  16239. else
  16240. {
  16241. isSuccess = ConfigurationStatus_Rejected;
  16242. }
  16243. }
  16244. if(strcmp(key, "ResetRetries") == 0)
  16245. {
  16246. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemAccessibility == 1)
  16247. {
  16248. check_ascii = value[0];
  16249. if( (check_ascii < 48) || (check_ascii > 57) )
  16250. {
  16251. isSuccess = ConfigurationStatus_Rejected;
  16252. }
  16253. else
  16254. {
  16255. //Charger.ResetRetries = Integer.parseInt(value);
  16256. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemData, "%d", atoi(value) );
  16257. isSuccess = ConfigurationStatus_Accepted;
  16258. }
  16259. }
  16260. else
  16261. {
  16262. isSuccess = ConfigurationStatus_Rejected;
  16263. }
  16264. }
  16265. if(strcmp(key, "ConnectorPhaseRotation") == 0)
  16266. {
  16267. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemAccessibility == 1)
  16268. {
  16269. strcpy(str, (const char*)value);
  16270. for(int i = 0; str[i]; i++)
  16271. {
  16272. str[i] = tolower(str[i]);
  16273. }
  16274. if(strcmp(str, "notapplicable")== 0)
  16275. {
  16276. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "%s", "NotApplicable" );
  16277. isSuccess = ConfigurationStatus_Accepted;
  16278. }
  16279. else if(strcmp(str, "unknown")== 0)
  16280. {
  16281. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "%s", "Unknown" );
  16282. isSuccess = ConfigurationStatus_Accepted;
  16283. }
  16284. else if(strcmp(str, "rst")== 0)
  16285. {
  16286. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "%s", "RST" );
  16287. isSuccess = ConfigurationStatus_Accepted;
  16288. }
  16289. else if(strcmp(str, "rts")== 0)
  16290. {
  16291. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "%s", "RTS" );
  16292. isSuccess = ConfigurationStatus_Accepted;
  16293. }
  16294. else if(strcmp(str, "srt")== 0)
  16295. {
  16296. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "%s", "SRT" );
  16297. isSuccess = ConfigurationStatus_Accepted;
  16298. }
  16299. else if(strcmp(str, "str")== 0)
  16300. {
  16301. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "%s", "STR" );
  16302. isSuccess = ConfigurationStatus_Accepted;
  16303. }
  16304. else if(strcmp(str, "trs")== 0)
  16305. {
  16306. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "%s", "TRS" );
  16307. isSuccess = ConfigurationStatus_Accepted;
  16308. }
  16309. else if(strcmp(str, "tsr")== 0)
  16310. {
  16311. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "%s", "TSR" );
  16312. isSuccess = ConfigurationStatus_Accepted;
  16313. }
  16314. else
  16315. {
  16316. isSuccess = ConfigurationStatus_Rejected;
  16317. }
  16318. }
  16319. else
  16320. {
  16321. isSuccess = ConfigurationStatus_Rejected;
  16322. }
  16323. }
  16324. if(strcmp(key, "ConnectorPhaseRotationMaxLength") == 0)
  16325. {
  16326. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemAccessibility == 1)
  16327. {
  16328. check_ascii = value[0];
  16329. if( (check_ascii < 48) || (check_ascii > 57) )
  16330. {
  16331. isSuccess = ConfigurationStatus_Rejected;
  16332. }
  16333. else
  16334. {
  16335. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemData, "%d", atoi(value) );
  16336. isSuccess = ConfigurationStatus_Accepted;
  16337. }
  16338. }
  16339. else
  16340. {
  16341. isSuccess = ConfigurationStatus_Rejected;
  16342. }
  16343. }
  16344. if(strcmp(key, "StopTransactionOnEVSideDisconnect") == 0)
  16345. {
  16346. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemAccessibility == 1)
  16347. {
  16348. strcpy(str, (const char*)value);
  16349. for(int i = 0; str[i]; i++)
  16350. {
  16351. str[i] = tolower(str[i]);
  16352. }
  16353. //Charger.StopTransactionOnEVSideDisconnect = (value.toLowerCase().equals("true")?true:false);
  16354. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  16355. isSuccess = ConfigurationStatus_Accepted;
  16356. }
  16357. else
  16358. {
  16359. isSuccess = ConfigurationStatus_Rejected;
  16360. }
  16361. }
  16362. if(strcmp(key, "StopTransactionOnInvalidId") == 0)
  16363. {
  16364. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemAccessibility == 1)
  16365. {
  16366. strcpy(str, (const char*)value);
  16367. for(int i = 0; str[i]; i++)
  16368. {
  16369. str[i] = tolower(str[i]);
  16370. }
  16371. //Charger.StopTransactionOnInvalidId = (value.toLowerCase().equals("true")?true:false);
  16372. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  16373. isSuccess = ConfigurationStatus_Accepted;
  16374. }
  16375. else
  16376. {
  16377. isSuccess = ConfigurationStatus_Rejected;
  16378. }
  16379. }
  16380. if(strcmp(key, "StopTxnAlignedData") == 0)
  16381. {
  16382. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemAccessibility == 1)
  16383. {
  16384. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemData, "%s", value );
  16385. isSuccess = ConfigurationStatus_Accepted;
  16386. }
  16387. else
  16388. {
  16389. isSuccess = ConfigurationStatus_Rejected;
  16390. }
  16391. }
  16392. if(strcmp(key, "StopTxnAlignedDataMaxLength") == 0)
  16393. {
  16394. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemAccessibility == 1)
  16395. {
  16396. check_ascii = value[0];
  16397. if( (check_ascii < 48) || (check_ascii > 57) )
  16398. {
  16399. isSuccess = ConfigurationStatus_Rejected;
  16400. }
  16401. else
  16402. {
  16403. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemData, "%d", atoi(value) );
  16404. isSuccess = ConfigurationStatus_Accepted;
  16405. }
  16406. }
  16407. else
  16408. {
  16409. isSuccess = ConfigurationStatus_Rejected;
  16410. }
  16411. }
  16412. if(strcmp(key, "StopTxnSampledData") == 0)
  16413. {
  16414. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemAccessibility == 1)
  16415. {
  16416. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "%s", value );
  16417. isSuccess = ConfigurationStatus_Accepted;
  16418. }
  16419. else
  16420. {
  16421. isSuccess = ConfigurationStatus_Rejected;
  16422. }
  16423. }
  16424. if(strcmp(key, "StopTxnSampledDataMaxLength") == 0)
  16425. {
  16426. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemAccessibility == 1)
  16427. {
  16428. check_ascii = value[0];
  16429. if( (check_ascii < 48) || (check_ascii > 57) )
  16430. {
  16431. isSuccess = ConfigurationStatus_Rejected;
  16432. }
  16433. else
  16434. {
  16435. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemData, "%d", atoi(value) );
  16436. isSuccess = ConfigurationStatus_Accepted;
  16437. }
  16438. }
  16439. else
  16440. {
  16441. isSuccess = ConfigurationStatus_Rejected;
  16442. }
  16443. }
  16444. if(strcmp(key, "SupportedFeatureProfiles") == 0)
  16445. {
  16446. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemAccessibility == 1)
  16447. {
  16448. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemData, "%s", value );
  16449. isSuccess = ConfigurationStatus_Accepted;
  16450. }
  16451. else
  16452. {
  16453. isSuccess = ConfigurationStatus_Rejected;
  16454. }
  16455. }
  16456. if(strcmp(key, "SupportedFeatureProfilesMaxLength") == 0)
  16457. {
  16458. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemAccessibility == 1)
  16459. {
  16460. check_ascii = value[0];
  16461. if( (check_ascii < 48) || (check_ascii > 57) )
  16462. {
  16463. isSuccess = ConfigurationStatus_Rejected;
  16464. }
  16465. else
  16466. {
  16467. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemData, "%d", atoi(value) );
  16468. isSuccess = ConfigurationStatus_Accepted;
  16469. }
  16470. }
  16471. else
  16472. {
  16473. isSuccess = ConfigurationStatus_Rejected;
  16474. }
  16475. }
  16476. if(strcmp(key, "TransactionMessageAttempts") == 0)
  16477. {
  16478. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemAccessibility == 1)
  16479. {
  16480. check_ascii = value[0];
  16481. if( (check_ascii < 48) || (check_ascii > 57) )
  16482. {
  16483. isSuccess = ConfigurationStatus_Rejected;
  16484. }
  16485. else
  16486. {
  16487. //Charger.TransactionMessageAttempts = Integer.parseInt(value);
  16488. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData, "%d", atoi(value) );
  16489. TransactionMessageAttemptsValue = atoi(value);
  16490. isSuccess = ConfigurationStatus_Accepted;
  16491. }
  16492. }
  16493. else
  16494. {
  16495. isSuccess = ConfigurationStatus_Rejected;
  16496. }
  16497. }
  16498. if(strcmp(key, "TransactionMessageRetryInterval") == 0)
  16499. {
  16500. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemAccessibility == 1)
  16501. {
  16502. check_ascii = value[0];
  16503. if( (check_ascii < 48) || (check_ascii > 57) )
  16504. {
  16505. isSuccess = ConfigurationStatus_Rejected;
  16506. }
  16507. else
  16508. {
  16509. //Charger.TransactionMessageRetryInterval = Integer.parseInt(value)*1000;
  16510. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData, "%d", atoi(value) );
  16511. TransactionMessageRetryIntervalValue = atoi(value);
  16512. isSuccess = ConfigurationStatus_Accepted;
  16513. }
  16514. }
  16515. else
  16516. {
  16517. isSuccess = ConfigurationStatus_Rejected;
  16518. }
  16519. }
  16520. if(strcmp(key, "UnlockConnectorOnEVSideDisconnect") == 0)
  16521. {
  16522. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemAccessibility == 1)
  16523. {
  16524. strcpy(str, (const char*)value);
  16525. for(int i = 0; str[i]; i++)
  16526. {
  16527. str[i] = tolower(str[i]);
  16528. }
  16529. //Charger.UnlockConnectorOnEVSideDisconnect = (value.toLowerCase().equals("true")?true:false);
  16530. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  16531. isSuccess = ConfigurationStatus_Accepted;
  16532. }
  16533. else
  16534. {
  16535. isSuccess = ConfigurationStatus_Rejected;
  16536. }
  16537. }
  16538. if(strcmp(key, "WebSocketPingInterval") == 0)
  16539. {
  16540. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemAccessibility == 1)
  16541. {
  16542. check_ascii = value[0];
  16543. if( (check_ascii < 48) || (check_ascii > 57) )
  16544. {
  16545. isSuccess = ConfigurationStatus_Rejected;
  16546. }
  16547. else
  16548. {
  16549. if((atoi(value) == 0) || (atoi(value) >= 10))
  16550. {
  16551. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemData, "%d", atoi(value) );
  16552. isSuccess = ConfigurationStatus_Accepted;
  16553. }
  16554. else
  16555. isSuccess = ConfigurationStatus_Rejected;
  16556. }
  16557. }
  16558. else
  16559. {
  16560. isSuccess = ConfigurationStatus_Rejected;
  16561. }
  16562. }
  16563. if(strcmp(key, "QueueOffLineMeterValues") == 0)
  16564. {
  16565. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[QueueOffLineMeterValues].ItemAccessibility == 1)
  16566. {
  16567. strcpy(str, (const char*)value);
  16568. for(int i = 0; str[i]; i++)
  16569. {
  16570. str[i] = tolower(str[i]);
  16571. }
  16572. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[QueueOffLineMeterValues].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  16573. isSuccess = ConfigurationStatus_Accepted;
  16574. }
  16575. else
  16576. {
  16577. isSuccess = ConfigurationStatus_Rejected;
  16578. }
  16579. }
  16580. if(strcmp(key, "AuthorizationKey") == 0)
  16581. {
  16582. if((ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationKey].ItemAccessibility == 1) && (strlen(value) <= 40))
  16583. {
  16584. strcpy(str, (const char*)value);
  16585. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationKey].ItemData, "%s", str);
  16586. strcpy((char*)ShmSysConfigAndInfo->SysConfig.OcppSecurityPassword, (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationKey].ItemData);
  16587. isSuccess = ConfigurationStatus_Accepted;
  16588. }
  16589. else
  16590. {
  16591. isSuccess = ConfigurationStatus_Rejected;
  16592. }
  16593. }
  16594. if(strcmp(key, "SecurityProfile") == 0)
  16595. {
  16596. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[SecurityProfile].ItemAccessibility == 1)
  16597. {
  16598. check_ascii = value[0];
  16599. if( (check_ascii < 0x30) || (check_ascii > 0x33) )
  16600. {
  16601. isSuccess = ConfigurationStatus_Rejected;
  16602. }
  16603. else if(check_ascii == 0x33)
  16604. {
  16605. isSuccess = NotSupported;
  16606. }
  16607. else
  16608. {
  16609. if(atoi((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SecurityProfile].ItemData) <= (check_ascii - 0x30))
  16610. {
  16611. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SecurityProfile].ItemData, "%d", atoi(value) );
  16612. ShmSysConfigAndInfo->SysConfig.OcppSecurityProfile = atoi(value);
  16613. isSuccess = ConfigurationStatus_Accepted;
  16614. }
  16615. else
  16616. isSuccess = ConfigurationStatus_Rejected;
  16617. }
  16618. }
  16619. else
  16620. {
  16621. isSuccess = ConfigurationStatus_Rejected;
  16622. }
  16623. }
  16624. if(strcmp(key, "DefaultPrice") == 0)
  16625. {
  16626. if((ShmOCPP16Data->ConfigurationTable.CoreProfile[DefaultPrice].ItemAccessibility == 1))
  16627. {
  16628. strcpy(str, (const char*)value);
  16629. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[DefaultPrice].ItemData, "%s", str);
  16630. isSuccess = ConfigurationStatus_Accepted;
  16631. }
  16632. else
  16633. {
  16634. isSuccess = ConfigurationStatus_Rejected;
  16635. }
  16636. }
  16637. if(strcmp(key, "CustomDisplayCostAndPrice") == 0)
  16638. {
  16639. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemAccessibility == 1)
  16640. {
  16641. strcpy(str, (const char*)value);
  16642. for(int i = 0; str[i]; i++)
  16643. {
  16644. str[i] = tolower(str[i]);
  16645. }
  16646. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  16647. isSuccess = ConfigurationStatus_Accepted;
  16648. }
  16649. else
  16650. {
  16651. isSuccess = ConfigurationStatus_Rejected;
  16652. }
  16653. }
  16654. if(strcmp(key, "CustomIdleFeeAfterStop") == 0)
  16655. {
  16656. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemAccessibility == 1)
  16657. {
  16658. strcpy(str, (const char*)value);
  16659. for(int i = 0; str[i]; i++)
  16660. {
  16661. str[i] = tolower(str[i]);
  16662. }
  16663. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  16664. isSuccess = ConfigurationStatus_Accepted;
  16665. }
  16666. else
  16667. {
  16668. isSuccess = ConfigurationStatus_Rejected;
  16669. }
  16670. }
  16671. if(strcmp(key, "TimeOffset") == 0)
  16672. {
  16673. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffset].ItemAccessibility == 1)
  16674. {
  16675. strcpy(str, (const char*)value);
  16676. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffset].ItemData, "%s", str);
  16677. isSuccess = ConfigurationStatus_Accepted;
  16678. }
  16679. else
  16680. {
  16681. isSuccess = ConfigurationStatus_Rejected;
  16682. }
  16683. }
  16684. if(strcmp(key, "NextTimeOffsetTransitionDateTime") == 0)
  16685. {
  16686. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[NextTimeOffsetTransitionDateTime].ItemAccessibility == 1)
  16687. {
  16688. strcpy(str, (const char*)value);
  16689. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NextTimeOffsetTransitionDateTime].ItemData, "%s", str);
  16690. isSuccess = ConfigurationStatus_Accepted;
  16691. }
  16692. else
  16693. {
  16694. isSuccess = ConfigurationStatus_Rejected;
  16695. }
  16696. }
  16697. if(strcmp(key, "TimeOffsetNextTransition") == 0)
  16698. {
  16699. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffsetNextTransition].ItemAccessibility == 1)
  16700. {
  16701. strcpy(str, (const char*)value);
  16702. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffsetNextTransition].ItemData, "%s", str);
  16703. isSuccess = ConfigurationStatus_Accepted;
  16704. }
  16705. else
  16706. {
  16707. isSuccess = ConfigurationStatus_Rejected;
  16708. }
  16709. }
  16710. if(strcmp(key, "SystemUptimeSec") == 0)
  16711. {
  16712. isSuccess = NotSupported;
  16713. }
  16714. if(strcmp(key, "FreeVend") == 0)
  16715. {
  16716. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[FreeVend].ItemAccessibility == 1)
  16717. {
  16718. strcpy(str, (const char*)value);
  16719. for(int i = 0; str[i]; i++)
  16720. {
  16721. str[i] = tolower(str[i]);
  16722. }
  16723. ShmSysConfigAndInfo->SysConfig.AuthorisationMode = ((strcmp(str, "true")==0) ? 1 : 0 );
  16724. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[FreeVend].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  16725. isSuccess = ConfigurationStatus_Accepted;
  16726. }
  16727. else
  16728. {
  16729. isSuccess = ConfigurationStatus_Rejected;
  16730. }
  16731. }
  16732. if(strcmp(key, "OcppServer") == 0)
  16733. {
  16734. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[OcppServer].ItemAccessibility == 1)
  16735. {
  16736. strcpy(str, (const char*)value);
  16737. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[OcppServer].ItemData, "%s", str );
  16738. sprintf((char *)ShmSysConfigAndInfo->SysConfig.OcppServerURL, "%s", str );
  16739. isSuccess = ConfigurationStatus_Accepted;
  16740. }
  16741. else
  16742. {
  16743. isSuccess = ConfigurationStatus_Rejected;
  16744. }
  16745. }
  16746. if(strcmp(key, "MaintainServer") == 0)
  16747. {
  16748. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MaintainServer].ItemAccessibility == 1)
  16749. {
  16750. strcpy(str, (const char*)value);
  16751. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MaintainServer].ItemData, "%s", str );
  16752. sprintf((char *)ShmSysConfigAndInfo->SysConfig.MaintainServerURL, "%s", str );
  16753. isSuccess = ConfigurationStatus_Accepted;
  16754. }
  16755. else
  16756. {
  16757. isSuccess = ConfigurationStatus_Rejected;
  16758. }
  16759. }
  16760. if(strcmp(key, "StatusNotificationPeriodically") == 0)
  16761. {
  16762. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StatusNotificationPeriodically].ItemAccessibility == 1)
  16763. {
  16764. strcpy(str, (const char*)value);
  16765. for(int i = 0; str[i]; i++)
  16766. {
  16767. str[i] = tolower(str[i]);
  16768. }
  16769. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StatusNotificationPeriodically].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE");
  16770. isSuccess = ConfigurationStatus_Accepted;
  16771. }
  16772. else
  16773. {
  16774. isSuccess = ConfigurationStatus_Rejected;
  16775. }
  16776. }
  16777. if(strcmp(key, "StatusNotificationInterval") == 0)
  16778. {
  16779. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StatusNotificationInterval].ItemAccessibility == 1)
  16780. {
  16781. check_ascii = value[0];
  16782. if( (check_ascii < 48) || (check_ascii > 57) )
  16783. {
  16784. isSuccess = ConfigurationStatus_Rejected;
  16785. }
  16786. else
  16787. {
  16788. if((atoi(value) == 0) || (atoi(value) >= 10))
  16789. {
  16790. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StatusNotificationInterval].ItemData, "%d", atoi(value) );
  16791. isSuccess = ConfigurationStatus_Accepted;
  16792. }
  16793. else
  16794. isSuccess = ConfigurationStatus_Rejected;
  16795. }
  16796. }
  16797. else
  16798. {
  16799. isSuccess = ConfigurationStatus_Rejected;
  16800. }
  16801. }
  16802. #if 0
  16803. //For OCPP Test Case
  16804. if(strcmp(key, "LocalAuthorizationListEnabled") == 0)
  16805. {
  16806. if(ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemAccessibility == 1)
  16807. {
  16808. strcpy(str, (const char*)value);
  16809. for(int i = 0; str[i]; i++)
  16810. {
  16811. str[i] = tolower(str[i]);
  16812. }
  16813. sprintf((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  16814. isSuccess = ConfigurationStatus_Accepted;
  16815. //updateSetting("LocalAuthorizationListEnabled", (char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData);
  16816. }
  16817. else
  16818. {
  16819. isSuccess = ConfigurationStatus_Rejected;
  16820. }
  16821. }
  16822. #endif
  16823. #if 1
  16824. if(strcmp(key, "LocalAuthListEnabled") == 0)
  16825. {
  16826. if(ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemAccessibility == 1)
  16827. {
  16828. strcpy(str, (const char*)value);
  16829. for(int i = 0; str[i]; i++)
  16830. {
  16831. str[i] = tolower(str[i]);
  16832. }
  16833. sprintf((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  16834. isSuccess = ConfigurationStatus_Accepted;
  16835. //updateSetting("LocalAuthListEnabled", (char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData);
  16836. }
  16837. else
  16838. {
  16839. isSuccess = ConfigurationStatus_Rejected;
  16840. }
  16841. }
  16842. #endif
  16843. if(strcmp(key, "LocalAuthListMaxLength") == 0)
  16844. {
  16845. if(ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemAccessibility == 1)
  16846. {
  16847. check_ascii = value[0];
  16848. if( (check_ascii < 48) || (check_ascii > 57) )
  16849. {
  16850. isSuccess = ConfigurationStatus_Rejected;
  16851. }
  16852. else
  16853. {
  16854. sprintf((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemData, "%d", atoi(value) );
  16855. isSuccess = ConfigurationStatus_Accepted;
  16856. }
  16857. }
  16858. else
  16859. {
  16860. isSuccess = ConfigurationStatus_Rejected;
  16861. }
  16862. }
  16863. if(strcmp(key, "SendLocalListMaxLength") == 0)
  16864. {
  16865. if(ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemAccessibility == 1)
  16866. {
  16867. check_ascii = value[0];
  16868. if( (check_ascii < 48) || (check_ascii > 57) )
  16869. {
  16870. isSuccess = ConfigurationStatus_Rejected;
  16871. }
  16872. else
  16873. {
  16874. sprintf((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemData, "%d", atoi(value) );
  16875. isSuccess = ConfigurationStatus_Accepted;
  16876. }
  16877. }
  16878. else
  16879. {
  16880. isSuccess = ConfigurationStatus_Rejected;
  16881. }
  16882. }
  16883. if(strcmp(key, "ReserveConnectorZeroSupported") == 0)
  16884. {
  16885. if(ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemAccessibility == 1)
  16886. {
  16887. strcpy(str, (const char*)value);
  16888. for(int i = 0; str[i]; i++)
  16889. {
  16890. str[i] = tolower(str[i]);
  16891. }
  16892. sprintf((char *)ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  16893. isSuccess = ConfigurationStatus_Accepted;
  16894. }
  16895. else
  16896. {
  16897. isSuccess = ConfigurationStatus_Rejected;
  16898. }
  16899. }
  16900. if(strcmp(key, "ChargeProfileMaxStackLevel") == 0)
  16901. {
  16902. if(ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemAccessibility == 1)
  16903. {
  16904. check_ascii = value[0];
  16905. if( (check_ascii < 48) || (check_ascii > 57) )
  16906. {
  16907. isSuccess = ConfigurationStatus_Rejected;
  16908. }
  16909. else
  16910. {
  16911. sprintf((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemData, "%d", atoi(value) );
  16912. isSuccess = ConfigurationStatus_Accepted;
  16913. }
  16914. }
  16915. else
  16916. {
  16917. isSuccess = ConfigurationStatus_Rejected;
  16918. }
  16919. }
  16920. if(strcmp(key, "ChargingScheduleAllowedChargingRateUnit") == 0)
  16921. {
  16922. if(ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemAccessibility == 1)
  16923. {
  16924. sprintf((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemData, "%s", value );
  16925. isSuccess = ConfigurationStatus_Accepted;
  16926. }
  16927. else
  16928. {
  16929. isSuccess = ConfigurationStatus_Rejected;
  16930. }
  16931. }
  16932. if(strcmp(key, "ChargingScheduleMaxPeriods") == 0)
  16933. {
  16934. if(ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemAccessibility == 1)
  16935. {
  16936. check_ascii = value[0];
  16937. if( (check_ascii < 48) || (check_ascii > 57) )
  16938. {
  16939. isSuccess = ConfigurationStatus_Rejected;
  16940. }
  16941. else
  16942. {
  16943. sprintf((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemData, "%d", atoi(value) );
  16944. isSuccess = ConfigurationStatus_Accepted;
  16945. }
  16946. }
  16947. else
  16948. {
  16949. isSuccess = ConfigurationStatus_Rejected;
  16950. }
  16951. }
  16952. if(strcmp(key, "ConnectorSwitch3to1PhaseSupported") == 0)
  16953. {
  16954. if(ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemAccessibility == 1)
  16955. {
  16956. strcpy(str, (const char*)value);
  16957. for(int i = 0; str[i]; i++)
  16958. {
  16959. str[i] = tolower(str[i]);
  16960. }
  16961. sprintf((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  16962. isSuccess = ConfigurationStatus_Accepted;
  16963. }
  16964. else
  16965. {
  16966. isSuccess = ConfigurationStatus_Rejected;
  16967. }
  16968. }
  16969. if(strcmp(key, "MaxChargingProfilesInstalled") == 0)
  16970. {
  16971. if(ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemAccessibility == 1)
  16972. {
  16973. check_ascii = value[0];
  16974. if( (check_ascii < 48) || (check_ascii > 57) )
  16975. {
  16976. isSuccess = ConfigurationStatus_Rejected;
  16977. }
  16978. else
  16979. {
  16980. sprintf((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemData, "%d", atoi(value) );
  16981. isSuccess = ConfigurationStatus_Accepted;
  16982. }
  16983. }
  16984. else
  16985. {
  16986. isSuccess = ConfigurationStatus_Rejected;
  16987. }
  16988. }
  16989. system("/bin/fsync -d /dev/mtdblock13;/bin/sync &");
  16990. return isSuccess;
  16991. }
  16992. int TransactionMessageAttemptsGet(void)
  16993. {
  16994. return TransactionMessageAttemptsValue;
  16995. }
  16996. int FirstHeartBeatResponse(void)
  16997. {
  16998. return FirstHeartBeat;
  16999. }
  17000. int TransactionMessageRetryIntervalGet(void)
  17001. {
  17002. return TransactionMessageRetryIntervalValue;//atoi((const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData);
  17003. }
  17004. int ReadHttpStatus(int sock)
  17005. {
  17006. //char c;
  17007. char buff[1024]="",*ptr=buff+1;
  17008. int bytes_received, status;
  17009. DEBUG_INFO("Begin Response ..\n");
  17010. while((bytes_received = recv(sock, ptr, 1, 0))){
  17011. if(bytes_received==-1){
  17012. perror("ReadHttpStatus");
  17013. exit(1);
  17014. }
  17015. if((ptr[-1]=='\r') && (*ptr=='\n' )) break;
  17016. ptr++;
  17017. }
  17018. *ptr=0;
  17019. ptr=buff+1;
  17020. sscanf(ptr,"%*s %d ", &status);
  17021. DEBUG_INFO("%s\n",ptr);
  17022. DEBUG_INFO("status=%d\n",status);
  17023. DEBUG_INFO("End Response ..\n");
  17024. return (bytes_received>0)?status:0;
  17025. }
  17026. //the only filed that it parsed is 'Content-Length'
  17027. int ParseHeader(int sock)
  17028. {
  17029. //char c;
  17030. char buff[1024]="",*ptr=buff+4;
  17031. int bytes_received;
  17032. DEBUG_INFO("Begin HEADER ..\n");
  17033. while((bytes_received = recv(sock, ptr, 1, 0))){
  17034. if(bytes_received==-1){
  17035. perror("Parse Header");
  17036. exit(1);
  17037. }
  17038. if(
  17039. (ptr[-3]=='\r') && (ptr[-2]=='\n' ) &&
  17040. (ptr[-1]=='\r') && (*ptr=='\n' )
  17041. ) break;
  17042. ptr++;
  17043. }
  17044. *ptr=0;
  17045. ptr=buff+4;
  17046. //printf("%s",ptr);
  17047. if(bytes_received){
  17048. ptr=strstr(ptr,"Content-Length:");
  17049. if(ptr){
  17050. sscanf(ptr,"%*s %d",&bytes_received);
  17051. }else
  17052. bytes_received=-1; //unknown size
  17053. DEBUG_INFO("Content-Length: %d\n",bytes_received);
  17054. }
  17055. DEBUG_INFO("End HEADER ..\n");
  17056. return bytes_received ;
  17057. }
  17058. int httpDownLoadFile(char *location, char *path, char *filename,char *url)
  17059. {
  17060. int result = TRUE;
  17061. char rmFileCmd[100]={0};
  17062. char FilePath[100]={0};
  17063. char ftpbuf[200];
  17064. int systemresult;
  17065. sprintf(FilePath,"/mnt/%s",filename);
  17066. system("ping 8.8.8.8 &");
  17067. if((access(FilePath,F_OK))!=-1)
  17068. {
  17069. DEBUG_INFO("filename=%s exist.\n",FilePath);
  17070. sprintf(rmFileCmd,"rm -f %s",FilePath);
  17071. system(rmFileCmd);
  17072. }
  17073. memset(ftpbuf, 0, ARRAY_SIZE(ftpbuf));
  17074. sprintf(ftpbuf, "wget --tries=3 -O /mnt/%s -c %s -T 120 --no-check-certificate",filename, url);
  17075. DEBUG_INFO("Download command: %s\n",ftpbuf);
  17076. systemresult = system(ftpbuf);
  17077. if(systemresult != 0)
  17078. {
  17079. DEBUG_INFO("http DownLoad error!\n");
  17080. result = FALSE;
  17081. }
  17082. system("pkill ping");
  17083. return result;
  17084. }
  17085. int ftpDownLoadFile(char *location, char *user, char *password, int port, char *path, char *filename,char *url)
  17086. {
  17087. int result = TRUE;
  17088. char rmFileCmd[100]={0};
  17089. char FilePath[100]={0};
  17090. char ftpbuf[200];
  17091. int systemresult;
  17092. sprintf(FilePath,"/mnt/%s",filename);
  17093. system("ping 8.8.8.8 &");
  17094. if((access(FilePath,F_OK))!=-1)
  17095. {
  17096. DEBUG_INFO("filename=%s exist.\n",FilePath);
  17097. sprintf(rmFileCmd,"rm -f %s",FilePath);
  17098. system(rmFileCmd);
  17099. }
  17100. memset(ftpbuf, 0, ARRAY_SIZE(ftpbuf));
  17101. sprintf(ftpbuf, "wget --tries=3 -O /mnt/%s -c %s -T 120",filename, url);
  17102. DEBUG_INFO("Download command: %s\n",ftpbuf);
  17103. systemresult = system(ftpbuf);
  17104. if(systemresult != 0)
  17105. {
  17106. sprintf(ftpbuf, "wget --tries=3 -O /mnt/%s -c %s -T 120 --no-passive-ftp",filename, url);
  17107. DEBUG_INFO("Download command: %s\n",ftpbuf);
  17108. systemresult = system(ftpbuf);
  17109. if(systemresult != 0)
  17110. {
  17111. DEBUG_WARN("wget error!\n");
  17112. result = FALSE;
  17113. }
  17114. }
  17115. system("pkill ping");
  17116. return result;
  17117. }
  17118. int httpUploadFile(char *location, char *path, char *filename,char *url)
  17119. {
  17120. char rmFileCmd[100]={0};
  17121. char FilePath[100]={0};
  17122. char buf[512];
  17123. int systemresult = 0;
  17124. //DEBUG_INFO("filename=%s\n",filename);
  17125. //DEBUG_INFO("url=%s\n",url);
  17126. sprintf(FilePath,"%s","/mnt/upload_file.txt");
  17127. if((access(FilePath,F_OK))!=-1)
  17128. {
  17129. DEBUG_INFO("filename=%s exist.\n",FilePath);
  17130. sprintf(rmFileCmd,"rm -f %s",FilePath);
  17131. system(rmFileCmd);
  17132. }
  17133. FILE *fp = fopen("/mnt/upload_file.txt", "w+");
  17134. if(fp == NULL)
  17135. {
  17136. DEBUG_INFO("log is NULL\n");
  17137. return FALSE;
  17138. }
  17139. else
  17140. {
  17141. fprintf(fp, "%s\n", url);
  17142. fprintf(fp, "%s\n", filename);
  17143. fclose(fp);
  17144. }
  17145. FILE *phpFP = popen("/bin/php-cgi /var/www/ocpp_upload.php", "r");
  17146. if(phpFP == NULL)
  17147. {
  17148. DEBUG_INFO("PHP upload fail.\n");
  17149. return FALSE;
  17150. }
  17151. else
  17152. {
  17153. while(fgets(buf, sizeof(buf), phpFP) != NULL)
  17154. {
  17155. if(strstr(buf, "result") != NULL)
  17156. {
  17157. sscanf(buf, "result: %d", &systemresult);
  17158. DEBUG_INFO("PHP HTTP upload result: %d\n", systemresult);
  17159. }
  17160. }
  17161. pclose(phpFP);
  17162. }
  17163. if(systemresult != 1)
  17164. {
  17165. DEBUG_INFO("HTTP upload error!\n");
  17166. return FALSE;
  17167. }
  17168. return TRUE;
  17169. }
  17170. int ftpUploadFile(char *location, char *user, char *password, int port, char *path, char *fnamePlusPath,char *filename)
  17171. {
  17172. int result = FALSE;
  17173. char ftpbuf[200];
  17174. int systemresult;
  17175. /*
  17176. // Domaind name transfer to IP address
  17177. struct hostent* server;
  17178. char *IPbuffer;
  17179. server = gethostbyname(location);
  17180. IPbuffer = inet_ntoa(*((struct in_addr*)server->h_addr_list[0]));*/
  17181. memset(ftpbuf, 0, ARRAY_SIZE(ftpbuf));
  17182. sprintf(ftpbuf, "ftpput -u %s -p %s %s -P %d %s%s %s", user, password, location, port/*21*/, path, filename, fnamePlusPath);
  17183. DEBUG_INFO("ftp command: %s\n",ftpbuf);
  17184. systemresult = system(ftpbuf);
  17185. if(systemresult != 0)
  17186. {
  17187. DEBUG_INFO("ftpput error!\n");
  17188. }
  17189. else
  17190. {
  17191. result = TRUE;
  17192. DEBUG_INFO("ftpput OK!\n");
  17193. }
  17194. return result;
  17195. }
  17196. int GetOcppServerURL()
  17197. {
  17198. int result = FALSE;
  17199. memset(OcppProtocol, 0, ARRAY_SIZE(OcppProtocol));
  17200. memset(OcppHost, 0, ARRAY_SIZE(OcppHost));
  17201. memset(OcppTempPath, 0, ARRAY_SIZE(OcppTempPath));
  17202. struct yuarel url;
  17203. char urlStr[512];
  17204. if((ShmSysConfigAndInfo->SysConfig.OcppServerURL != NULL) && (strcmp((const char *)ShmSysConfigAndInfo->SysConfig.OcppServerURL,"") != 0) )
  17205. {
  17206. /*sscanf((const char *)ShmSysConfigAndInfo->SysConfig.OcppServerURL,
  17207. "%[^:]:%*2[/]%[^:]:%i/%[a-zA-Z0-9._/-]",
  17208. OcppProtocol, OcppHost, &OcppPort, OcppTempPath);*/
  17209. memcpy(urlStr, ShmSysConfigAndInfo->SysConfig.OcppServerURL, ARRAY_SIZE(ShmSysConfigAndInfo->SysConfig.OcppServerURL));
  17210. if(yuarel_parse(&url, urlStr) != -1)
  17211. {
  17212. sprintf(OcppProtocol, "%s", url.scheme);
  17213. sprintf(OcppHost, "%s", url.host);
  17214. if(url.path == NULL)
  17215. OcppTempPath[0] = '\0';
  17216. else
  17217. {
  17218. if((url.path[strlen(url.path)-1] != '/') && (strlen(url.path) > 0))
  17219. {
  17220. sprintf(OcppTempPath, "%s/", url.path);
  17221. }
  17222. else
  17223. {
  17224. sprintf(OcppTempPath, "%s", url.path);
  17225. }
  17226. }
  17227. if(url.port == 0)
  17228. {
  17229. if(strcmp(OcppProtocol, "wss") == 0)
  17230. OcppPort = 443;
  17231. else
  17232. OcppPort = 80;
  17233. }
  17234. else
  17235. OcppPort = url.port;
  17236. result = TRUE;
  17237. }
  17238. }
  17239. else if((ShmOCPP16Data->OcppServerURL != NULL) && (strcmp((const char *)ShmOCPP16Data->OcppServerURL,"") != 0))
  17240. {
  17241. /*sscanf((const char *)ShmOCPP16Data->OcppServerURL,
  17242. "%[^:]:%*2[/]%[^:]:%i/%[a-zA-Z0-9._/-]",
  17243. OcppProtocol, OcppHost, &OcppPort, OcppTempPath);*/
  17244. memcpy(urlStr, ShmOCPP16Data->OcppServerURL, ARRAY_SIZE(ShmOCPP16Data->OcppServerURL));
  17245. if(yuarel_parse(&url, urlStr) != -1)
  17246. {
  17247. sprintf(OcppProtocol, "%s", url.scheme);
  17248. sprintf(OcppHost, "%s", url.host);
  17249. if(url.path == NULL)
  17250. OcppTempPath[0] = '\0';
  17251. else
  17252. sprintf(OcppTempPath, "%s", url.path);
  17253. if(url.port == 0)
  17254. {
  17255. if(strcmp(OcppProtocol, "wss") == 0)
  17256. OcppPort = 443;
  17257. else
  17258. OcppPort = 80;
  17259. }
  17260. else
  17261. OcppPort = url.port;
  17262. result = TRUE;
  17263. }
  17264. }
  17265. else
  17266. {
  17267. strcpy(OcppHost,"");
  17268. }
  17269. return result;
  17270. }
  17271. int GetOcppPath()
  17272. {
  17273. int result = FALSE;
  17274. if((ShmSysConfigAndInfo->SysConfig.ChargeBoxId != NULL) && (strcmp((const char *)ShmSysConfigAndInfo->SysConfig.ChargeBoxId,"") != 0) )
  17275. {
  17276. if(OcppTempPath == NULL)
  17277. {
  17278. sprintf(OcppPath,"/%s",ShmSysConfigAndInfo->SysConfig.ChargeBoxId);
  17279. }
  17280. else
  17281. {
  17282. sprintf(OcppPath,"/%s%s",OcppTempPath,ShmSysConfigAndInfo->SysConfig.ChargeBoxId);
  17283. }
  17284. result = TRUE;
  17285. goto End;
  17286. }
  17287. else if((ShmOCPP16Data->ChargeBoxId != NULL) && (strcmp((const char *)ShmOCPP16Data->ChargeBoxId,"") != 0))
  17288. {
  17289. if(OcppTempPath == NULL)
  17290. {
  17291. sprintf(OcppPath,"/%s",ShmOCPP16Data->ChargeBoxId);
  17292. }
  17293. else
  17294. {
  17295. sprintf(OcppPath,"/%s%s",OcppTempPath,ShmOCPP16Data->ChargeBoxId);
  17296. }
  17297. result = TRUE;
  17298. goto End;
  17299. }
  17300. else
  17301. {
  17302. strcpy(OcppPath,"");
  17303. }
  17304. End:
  17305. return result;
  17306. }
  17307. int GetOcppPort()
  17308. {
  17309. return OcppPort;
  17310. }
  17311. int GetOcppConnStatus(void)
  17312. {
  17313. return ShmOCPP16Data->OcppConnStatus;
  17314. }
  17315. void SetOcppConnStatus(uint8_t status)
  17316. {
  17317. ShmOCPP16Data->OcppConnStatus = status;
  17318. ShmSysConfigAndInfo->SysInfo.OcppConnStatus = status;
  17319. }
  17320. int GetHeartBeatWithNOResponse(void)
  17321. {
  17322. return HeartBeatWithNOResponse;
  17323. }
  17324. void SetHeartBeatWithNOResponse(void)
  17325. {
  17326. HeartBeatWithNOResponse = 0;
  17327. }
  17328. void GetStartTransactionIdTag(int gun_index)
  17329. {
  17330. memset(StartTransactionIdTagTemp, 0 ,ARRAY_SIZE(StartTransactionIdTagTemp));
  17331. strcpy((char *)StartTransactionIdTagTemp, (const char *)ShmOCPP16Data->StartTransaction[gun_index].IdTag);
  17332. }
  17333. int GetTransactionId(int gunindex, unsigned char idTag[], uint8_t isStopTransaction)
  17334. {
  17335. char ch;
  17336. FILE *fptr1;
  17337. int temptransactionId;
  17338. char str[100]={0};
  17339. temptransactionId = 0;
  17340. if(((strcmp((const char*)idTag, "")==0)||(idTag[0]=='\0')) && isStopTransaction)
  17341. {
  17342. DEBUG_INFO("IdTag is empty.\n");
  17343. return temptransactionId;
  17344. }
  17345. /*------ Read the file ----------------*/
  17346. fptr1=fopen("/Storage/OCPP/QueueTransactionId","r");
  17347. if (!fptr1)
  17348. {
  17349. DEBUG_INFO("QueueTransactionId file open error.\n");
  17350. //printf(" File not found or unable to open the input file!!\n");
  17351. return temptransactionId;
  17352. }
  17353. ch=fgetc(fptr1);
  17354. //printf(" Now the content of the file %s is : \n","/Storage/OCPP/QueueTransactionId");
  17355. rewind(fptr1);
  17356. if(ch!=EOF)
  17357. {
  17358. // printf("%c",ch);
  17359. while (fgets(str, 100, fptr1) != NULL)
  17360. {
  17361. str[strlen(str) - 1] = '\0'; // eat the newline fgets() stores
  17362. if(str[0]=='\0')
  17363. {
  17364. break;
  17365. }
  17366. char *revbuf[8] = {0}; // Variable store string split
  17367. int num = 0;// Quantity after string split
  17368. DEBUG_INFO("Transaction queue data= %s\n", str);
  17369. splitstring(str,",",revbuf,&num); // String split
  17370. DEBUG_INFO(" revbuf[0]= %s\n", revbuf[0]);
  17371. DEBUG_INFO(" revbuf[1]= %s\n", revbuf[1]);
  17372. DEBUG_INFO(" revbuf[2]= %s\n", revbuf[2]);
  17373. DEBUG_INFO("------------------------------\n");
  17374. if((revbuf[1][0] != '\0')&&(revbuf[2][0] != '\0'))
  17375. {
  17376. if(isStopTransaction)
  17377. {
  17378. if((atoi(revbuf[0])==gunindex) && (strcmp(revbuf[1],(const char *)idTag)==0))
  17379. {
  17380. temptransactionId = atoi(revbuf[2]);
  17381. //break;
  17382. }
  17383. }
  17384. else
  17385. {
  17386. if((atoi(revbuf[0])==gunindex) || (strcmp(revbuf[1],(const char *)idTag)==0))
  17387. {
  17388. temptransactionId = atoi(revbuf[2]);
  17389. //break;
  17390. }
  17391. }
  17392. }
  17393. }
  17394. }
  17395. else
  17396. DEBUG_INFO("EOF\n");
  17397. fclose(fptr1);
  17398. /*------- End of reading ---------------*/
  17399. return temptransactionId;
  17400. }
  17401. void SetTransactionIdZero(int transactionId)
  17402. {
  17403. char ch;
  17404. FILE *fptr1, *fptr2;
  17405. int temptransactionId = 0;
  17406. char str[100]={0}, strtemp[100]={0}, temp[] = "/Storage/OCPP/QueueTransactionIdtemp.json";
  17407. fptr1 = fopen("/Storage/OCPP/QueueTransactionId", "r");
  17408. if (!fptr1)
  17409. {
  17410. //printf(" File not found or unable to open the input file!!\n");
  17411. return ;
  17412. }
  17413. fptr2 = fopen(temp, "w"); // open the temporary file in write mode
  17414. if (!fptr2)
  17415. {
  17416. DEBUG_INFO("Unable to open a temporary file to write!!\n");
  17417. fclose(fptr1);
  17418. return ;
  17419. }
  17420. ch=fgetc(fptr1);
  17421. rewind(fptr1);
  17422. if(ch!=EOF)
  17423. {
  17424. // copy all contents to the temporary file except the specific line
  17425. while (fgets(str, 100, fptr1) != NULL)
  17426. {
  17427. str[strlen(str) - 1] = '\0'; // eat the newline fgets() stores
  17428. if(str[0]=='\0')
  17429. {
  17430. break;
  17431. }
  17432. char *revbuf[8] = {0};
  17433. int num = 0;
  17434. strcpy(strtemp, str);
  17435. splitstring(str,",",revbuf,&num);
  17436. if(revbuf[2][0] != '\0')
  17437. {
  17438. temptransactionId = atoi(revbuf[2]);
  17439. if(transactionId != temptransactionId)
  17440. {
  17441. fprintf(fptr2, "%s\n", strtemp);
  17442. }
  17443. }
  17444. }
  17445. }
  17446. fclose(fptr1);
  17447. fclose(fptr2);
  17448. remove("/Storage/OCPP/QueueTransactionId"); // remove the original file
  17449. rename(temp, "/Storage/OCPP/QueueTransactionId"); // rename the temporary file to original name
  17450. /*------ Read the file ----------------*/
  17451. }
  17452. int InternetDisconnect(void)
  17453. {
  17454. return (ShmStatusCodeData->InfoCode.InfoEvents.bits.InternetDisconnectVia4Gi && ShmStatusCodeData->InfoCode.InfoEvents.bits.InternetDisconnectViaEthernet && ShmStatusCodeData->InfoCode.InfoEvents.bits.InternetDisconnectViaWiFi );
  17455. }
  17456. //Note: It is not real StopTransaction. It is temporary StopTransaction.
  17457. void storeTempStopTransaction(int gun_index)
  17458. {
  17459. char guid[37]={0};
  17460. int tempIndex = 0;
  17461. char TempStopTransaction[256];
  17462. sprintf(TempStopTransaction, "/Storage/OCPP/TempStopTransaction_%d", (gun_index+1));
  17463. DEBUG_INFO("storeTempStopTransaction...\n");
  17464. memset(queuedata, 0, ARRAY_SIZE(queuedata));
  17465. memset(&ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0], 0, ARRAY_SIZE(ShmOCPP16Data->StopTransaction[gun_index].TransactionData));
  17466. //======================== ENERGY_ACTIVE_IMPORT_REGISTER =======================================
  17467. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DCcc
  17468. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  17469. {
  17470. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  17471. {
  17472. tempIndex = ((gun_index==2) ? 1: 0);
  17473. }
  17474. else
  17475. {
  17476. tempIndex = gun_index;
  17477. }
  17478. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  17479. {
  17480. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  17481. {
  17482. ShmOCPP16Data->StopTransaction[gun_index].MeterStop = (int)(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PowerConsumption*1000);
  17483. }
  17484. }// END OF CHAdeMO_QUANTITY
  17485. }
  17486. else if(gunType[gun_index] == GUN_TYPE_CCS)
  17487. {
  17488. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  17489. {
  17490. tempIndex = ((gun_index==2) ? 1: 0);
  17491. }
  17492. else
  17493. {
  17494. tempIndex = gun_index;
  17495. }
  17496. for (int index = 0; index < CCS_QUANTITY; index++)
  17497. {
  17498. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  17499. {
  17500. ShmOCPP16Data->StopTransaction[gun_index].MeterStop = (int)(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PowerConsumption*1000);
  17501. }
  17502. }// END OF CCS_QUANTITY
  17503. }
  17504. else if(gunType[gun_index] == GUN_TYPE_GBT)
  17505. {
  17506. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  17507. {
  17508. tempIndex = ((gun_index==2) ? 1: 0);
  17509. }
  17510. else
  17511. {
  17512. tempIndex = gun_index;
  17513. }
  17514. for (int index = 0; index < GB_QUANTITY; index++)
  17515. {
  17516. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  17517. {
  17518. ShmOCPP16Data->StopTransaction[gun_index].MeterStop = (int)(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PowerConsumption*1000);
  17519. }
  17520. }// END OF GB_QUANTITY
  17521. }
  17522. else if(gunType[gun_index] == GUN_TYPE_DO)
  17523. {
  17524. tempIndex = gun_index;
  17525. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  17526. {
  17527. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  17528. {
  17529. ShmOCPP16Data->StopTransaction[gun_index].MeterStop = (int)(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PowerConsumption*1000);
  17530. }
  17531. }
  17532. }
  17533. else
  17534. {
  17535. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  17536. {
  17537. tempIndex = 2;
  17538. }
  17539. else
  17540. {
  17541. tempIndex = gun_index;
  17542. }
  17543. for (int index = 0; index < AC_QUANTITY; index++)
  17544. {
  17545. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  17546. {
  17547. ShmOCPP16Data->StopTransaction[gun_index].MeterStop = (int)(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PowerConsumption*1000);
  17548. }
  17549. }// END OF AC_QUANTITY
  17550. }
  17551. //Stop Transaction Time
  17552. struct timeval tmnow;
  17553. struct tm *tm;
  17554. char buf[28];//, usec_buf[6];
  17555. gettimeofday(&tmnow, NULL);
  17556. time_t t;
  17557. t = time(NULL);
  17558. /*UTC time and date*/
  17559. tm = gmtime(&t);
  17560. strftime(buf,28,"%Y-%m-%dT%H:%M:%SZ", tm);
  17561. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].Timestamp,buf);
  17562. ShmOCPP16Data->StopTransaction[gun_index].TransactionId = ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId;
  17563. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].IdTag, (const char*)ShmOCPP16Data->StartTransaction[gun_index].IdTag);
  17564. random_uuid(guid);
  17565. /***********************************transactionData******************************************************/
  17566. memset(ShmOCPP16Data->StopTransaction[gun_index].TransactionData, 0, sizeof(struct StructMeterValue));
  17567. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].TimeStamp, buf);
  17568. //=================================
  17569. //1. Transaction_Begin
  17570. //=================================
  17571. //============================== Energy.Active.Import.Interval ===========================================
  17572. if(strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Energy.Active.Import.Interval") != NULL)
  17573. {
  17574. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Value, "%.3f", 0.0); // MeterStart is 0~6553.5 kWh
  17575. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Context,ReadingContextStr[ReadingContext_Transaction_Begin]);
  17576. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Format,ValueFormatStr[Raw]);
  17577. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Measurand,MeasurandStr[Energy_Active_Import_Interval]);//MeasurandStr[Energy_Active_Export_Interval/*Energy_Reactive_Export_Register*/]);
  17578. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DCcc
  17579. 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))
  17580. {
  17581. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Phase,PhaseStr[L3_N]);
  17582. }
  17583. else
  17584. {
  17585. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Phase,PhaseStr[L1_N]);
  17586. }
  17587. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Location,LocationStr[Location_Outlet]);
  17588. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Unit,UnitOfMeasureStr[UnitOfMeasure_kWh]);
  17589. }
  17590. //=================================
  17591. //2. Transaction_End
  17592. //=================================
  17593. //2.1====================================== Current.Import L1 ==============================================
  17594. if(strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Current.Import") != NULL)
  17595. {
  17596. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G : GBT DC
  17597. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  17598. {
  17599. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  17600. {
  17601. tempIndex = ((gun_index==2) ? 1: 0);
  17602. }
  17603. else
  17604. {
  17605. tempIndex = gun_index;
  17606. }
  17607. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  17608. {
  17609. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  17610. {
  17611. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargingCurrent );// PresentChargingCurrent is 0~6553.5 amp
  17612. }
  17613. }// End of for CHAdeMO_QUANTITY
  17614. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase,PhaseStr[L3_N]);
  17615. }
  17616. else if(gunType[gun_index] == GUN_TYPE_CCS)
  17617. {
  17618. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  17619. {
  17620. tempIndex = ((gun_index==2) ? 1: 0);
  17621. }
  17622. else
  17623. {
  17624. tempIndex = gun_index;
  17625. }
  17626. for (int index = 0; index < CCS_QUANTITY; index++)
  17627. {
  17628. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  17629. {
  17630. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargingCurrent );// PresentChargingCurrent is 0~6553.5 amp
  17631. }
  17632. }// End of for CCS_QUANTITY
  17633. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase,PhaseStr[L3_N]);
  17634. }
  17635. else if(gunType[gun_index] == GUN_TYPE_GBT)
  17636. {
  17637. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  17638. {
  17639. tempIndex = ((gun_index==2) ? 1: 0);
  17640. }
  17641. else
  17642. {
  17643. tempIndex = gun_index;
  17644. }
  17645. for (int index = 0; index < GB_QUANTITY; index++)
  17646. {
  17647. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  17648. {
  17649. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingCurrent );// PresentChargingCurrent is 0~6553.5 amp
  17650. }
  17651. }// End of for GB_QUANTITY
  17652. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase,PhaseStr[L3_N]);
  17653. }
  17654. else if(gunType[gun_index] == GUN_TYPE_DO)
  17655. {
  17656. tempIndex = gun_index;
  17657. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  17658. {
  17659. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  17660. {
  17661. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PresentChargingCurrent );// PresentChargingCurrent is 0~6553.5 amp
  17662. }
  17663. }
  17664. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase,PhaseStr[L3_N]);
  17665. }
  17666. else
  17667. {
  17668. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  17669. {
  17670. tempIndex = 2;
  17671. }
  17672. else
  17673. {
  17674. tempIndex = gun_index;
  17675. }
  17676. for (int index = 0; index < AC_QUANTITY; index++)
  17677. {
  17678. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  17679. {
  17680. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingCurrent );// 0~6553.5 amp for EVSE
  17681. }
  17682. }// End of for AC_QUANTITY
  17683. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase,PhaseStr[L1_N]);
  17684. }
  17685. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  17686. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Format,ValueFormatStr[Raw]);
  17687. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Measurand,MeasurandStr[Current_Import]);
  17688. //strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase,PhaseStr[L1_N]);
  17689. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Location,LocationStr[Location_Outlet]);
  17690. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Unit,UnitOfMeasureStr[UnitOfMeasure_A]);
  17691. }
  17692. //2.2===================================== Energy.Active.Import.Interval ==========================================
  17693. if(strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Energy.Active.Import.Interval") != NULL)
  17694. {
  17695. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  17696. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  17697. {
  17698. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  17699. {
  17700. tempIndex = ((gun_index==2) ? 1: 0);
  17701. }
  17702. else
  17703. {
  17704. tempIndex = gun_index;
  17705. }
  17706. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  17707. {
  17708. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  17709. {
  17710. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargedEnergy );// PresentChargedEnergy is 0~6553.5 kWh
  17711. }
  17712. }// END OF CHAdeMO_QUANTITY
  17713. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase,PhaseStr[L3_N]);
  17714. }
  17715. else if(gunType[gun_index] == GUN_TYPE_CCS)
  17716. {
  17717. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  17718. {
  17719. tempIndex = ((gun_index==2) ? 1: 0);
  17720. }
  17721. else
  17722. {
  17723. tempIndex = gun_index;
  17724. }
  17725. for (int index = 0; index < CCS_QUANTITY; index++)
  17726. {
  17727. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  17728. {
  17729. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargedEnergy );// PresentChargedEnergy is 0~6553.5 kWh
  17730. }
  17731. }// END OF CCS_QUANTITY
  17732. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase,PhaseStr[L3_N]);
  17733. }
  17734. else if(gunType[gun_index] == GUN_TYPE_GBT)
  17735. {
  17736. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  17737. {
  17738. tempIndex = ((gun_index==2) ? 1: 0);
  17739. }
  17740. else
  17741. {
  17742. tempIndex = gun_index;
  17743. }
  17744. for (int index = 0; index < GB_QUANTITY; index++)
  17745. {
  17746. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  17747. {
  17748. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargedEnergy );// PresentChargedEnergy is 0~6553.5 kWh
  17749. }
  17750. }// END OF GB_QUANTITY
  17751. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase,PhaseStr[L3_N]);
  17752. }
  17753. else if(gunType[gun_index] == GUN_TYPE_DO)
  17754. {
  17755. tempIndex = gun_index;
  17756. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  17757. {
  17758. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  17759. {
  17760. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PresentChargedEnergy );// PresentChargedEnergy is 0~6553.5 kWh
  17761. }
  17762. }
  17763. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase,PhaseStr[L3_N]);
  17764. }
  17765. else
  17766. {
  17767. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  17768. {
  17769. tempIndex = 2;
  17770. }
  17771. else
  17772. {
  17773. tempIndex = gun_index;
  17774. }
  17775. for (int index = 0; index < AC_QUANTITY; index++)
  17776. {
  17777. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  17778. {
  17779. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargedEnergy );// PresentChargedEnergy is 0~6553.5 kWh
  17780. }
  17781. }// END OF AC_QUANTITY
  17782. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase,PhaseStr[L1_N]);
  17783. }
  17784. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  17785. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Format,ValueFormatStr[Raw]);
  17786. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Measurand,MeasurandStr[Energy_Active_Import_Interval]);
  17787. //strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase,PhaseStr[L1_N]);
  17788. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Location,LocationStr[Location_Outlet]);
  17789. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Unit,UnitOfMeasureStr[UnitOfMeasure_kWh]);
  17790. }
  17791. //2.3====================================== Power.Active.Import =========================================
  17792. if(strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Power.Active.Import") != NULL)
  17793. {
  17794. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  17795. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  17796. {
  17797. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  17798. {
  17799. tempIndex = ((gun_index==2) ? 1: 0);
  17800. }
  17801. else
  17802. {
  17803. tempIndex = gun_index;
  17804. }
  17805. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  17806. {
  17807. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  17808. {
  17809. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargingPower );// PresentChargingPower is 0~6553.5 kW
  17810. }
  17811. } // End for CHAdeMO_QUANTITY
  17812. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase,PhaseStr[L3_N]);
  17813. }
  17814. else if(gunType[gun_index] == GUN_TYPE_CCS)
  17815. {
  17816. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  17817. {
  17818. tempIndex = ((gun_index==2) ? 1: 0);
  17819. }
  17820. else
  17821. {
  17822. tempIndex = gun_index;
  17823. }
  17824. for (int index = 0; index < CCS_QUANTITY; index++)
  17825. {
  17826. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  17827. {
  17828. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargingPower );// PresentChargingPower is 0~6553.5 kW
  17829. }
  17830. } // END for CCS_QUANTITY
  17831. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase,PhaseStr[L3_N]);
  17832. }
  17833. else if(gunType[gun_index] == GUN_TYPE_GBT)
  17834. {
  17835. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  17836. {
  17837. tempIndex = ((gun_index==2) ? 1: 0);
  17838. }
  17839. else
  17840. {
  17841. tempIndex = gun_index;
  17842. }
  17843. for (int index = 0; index < GB_QUANTITY; index++)
  17844. {
  17845. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  17846. {
  17847. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingPower );// PresentChargingPower is 0~6553.5 kW
  17848. }
  17849. }// END for GB_QUANTITY
  17850. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase,PhaseStr[L3_N]);
  17851. }
  17852. else if(gunType[gun_index] == GUN_TYPE_DO)
  17853. {
  17854. tempIndex = gun_index;
  17855. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  17856. {
  17857. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  17858. {
  17859. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PresentChargingPower );// PresentChargingPower is 0~6553.5 kW
  17860. }
  17861. }
  17862. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase,PhaseStr[L3_N]);
  17863. }
  17864. else
  17865. {
  17866. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  17867. {
  17868. tempIndex = 2;
  17869. }
  17870. else
  17871. {
  17872. tempIndex = gun_index;
  17873. }
  17874. for (int index = 0; index < AC_QUANTITY; index++)
  17875. {
  17876. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  17877. {
  17878. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingPower );// PresentChargingPower is 0~6553.5 kW
  17879. }
  17880. } // END for AC_QUANTITY
  17881. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase,PhaseStr[L1_N]);
  17882. }
  17883. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  17884. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Format,ValueFormatStr[Raw]);
  17885. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Measurand,MeasurandStr[Power_Active_Import]);
  17886. //strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase,PhaseStr[L1_N]);
  17887. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Location,LocationStr[Location_Outlet]);
  17888. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Unit,UnitOfMeasureStr[UnitOfMeasure_kW/*UnitOfMeasure_kWh*/]);
  17889. }
  17890. //2.4====================================== Voltage L1 ====================================================
  17891. if(strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Voltage") != NULL)
  17892. {
  17893. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  17894. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  17895. {
  17896. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  17897. {
  17898. tempIndex = ((gun_index==2) ? 1: 0);
  17899. }
  17900. else
  17901. {
  17902. tempIndex = gun_index;
  17903. }
  17904. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  17905. {
  17906. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  17907. {
  17908. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargingVoltage );// PresentChargingVoltage is 0~6553.5 volt
  17909. }
  17910. } // END OF FOR CHAdeMO_QUANTITY
  17911. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase,PhaseStr[L3_N]);
  17912. }
  17913. else if(gunType[gun_index] == GUN_TYPE_CCS)
  17914. {
  17915. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  17916. {
  17917. tempIndex = ((gun_index==2) ? 1: 0);
  17918. }
  17919. else
  17920. {
  17921. tempIndex = gun_index;
  17922. }
  17923. for (int index = 0; index < CCS_QUANTITY; index++)
  17924. {
  17925. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  17926. {
  17927. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargingVoltage );// PresentChargingVoltage is 0~6553.5 volt
  17928. }
  17929. } // END OF FOR CCS_QUANTITY
  17930. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase,PhaseStr[L3_N]);
  17931. }
  17932. else if(gunType[gun_index] == GUN_TYPE_GBT)
  17933. {
  17934. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  17935. {
  17936. tempIndex = ((gun_index==2) ? 1: 0);
  17937. }
  17938. else
  17939. {
  17940. tempIndex = gun_index;
  17941. }
  17942. for (int index = 0; index < GB_QUANTITY; index++)
  17943. {
  17944. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  17945. {
  17946. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingVoltage );// PresentChargingVoltage is 0~6553.5 volt
  17947. }
  17948. } // END OF FOR GB_QUANTITY
  17949. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase,PhaseStr[L3_N]);
  17950. }
  17951. else if(gunType[gun_index] == GUN_TYPE_DO)
  17952. {
  17953. tempIndex = gun_index;
  17954. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  17955. {
  17956. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  17957. {
  17958. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PresentChargingVoltage );// PresentChargingVoltage is 0~6553.5 volt
  17959. }
  17960. }
  17961. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase,PhaseStr[L3_N]);
  17962. }
  17963. else
  17964. {
  17965. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  17966. {
  17967. tempIndex = 2;
  17968. }
  17969. else
  17970. {
  17971. tempIndex = gun_index;
  17972. }
  17973. for (int index = 0; index < AC_QUANTITY; index++)
  17974. {
  17975. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  17976. {
  17977. 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
  17978. }
  17979. } // END OF FOR AC_QUANTITY
  17980. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase,PhaseStr[L1_N]);
  17981. }
  17982. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  17983. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Format,ValueFormatStr[Raw]);
  17984. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Measurand,MeasurandStr[Voltage]);
  17985. //strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase,PhaseStr[L1_N]);
  17986. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Location,LocationStr[Location_Outlet]);
  17987. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Unit,UnitOfMeasureStr[UnitOfMeasure_V]);
  17988. }
  17989. //2.5============================================== End SoC =========================================================
  17990. if(strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, MeasurandStr[SoC]) != NULL)
  17991. {
  17992. //J : CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  17993. 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))
  17994. {
  17995. if((ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0') && (gunType[gun_index] != GUN_TYPE_DO))
  17996. {
  17997. tempIndex = ((gun_index==2) ? 1: 0);
  17998. }
  17999. else
  18000. {
  18001. tempIndex = gun_index;
  18002. }
  18003. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  18004. {
  18005. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  18006. {
  18007. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  18008. {
  18009. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].EvBatterySoc );// 0~100%
  18010. }
  18011. }
  18012. }
  18013. else if(gunType[gun_index] == GUN_TYPE_CCS)
  18014. {
  18015. for (int index = 0; index < CCS_QUANTITY; index++)
  18016. {
  18017. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  18018. {
  18019. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].EvBatterySoc );// 0~100%
  18020. }
  18021. }
  18022. }
  18023. else if(gunType[gun_index] == GUN_TYPE_GBT)
  18024. {
  18025. for (int index = 0; index < GB_QUANTITY; index++)
  18026. {
  18027. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  18028. {
  18029. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].EvBatterySoc );// 0~100%
  18030. }
  18031. }
  18032. }
  18033. else if(gunType[gun_index] == GUN_TYPE_DO)
  18034. {
  18035. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  18036. {
  18037. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  18038. {
  18039. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.EvBatterySoc );// 0~100%
  18040. }
  18041. }
  18042. }
  18043. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  18044. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Format,ValueFormatStr[Raw]);
  18045. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Measurand,MeasurandStr[SoC/*Energy_Reactive_Export_Register*/]);
  18046. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Phase,PhaseStr[L3_N]);
  18047. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Location,LocationStr[Location_EV]);
  18048. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Unit,UnitOfMeasureStr[UnitOfMeasure_Percent/*UnitOfMeasure_kWh*/]);
  18049. } // END FOR DC CASE
  18050. }
  18051. //2.6====================================== Current.Import L2 ==============================================
  18052. if(strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Current.Import") != NULL)
  18053. {
  18054. // AC 3 phase L2 current
  18055. if((gunType[gun_index] == GUN_TYPE_AC) && ((ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'W') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='D')))
  18056. {
  18057. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  18058. {
  18059. tempIndex = 2;
  18060. }
  18061. else
  18062. {
  18063. tempIndex = gun_index;
  18064. }
  18065. for (int index = 0; index < AC_QUANTITY; index++)
  18066. {
  18067. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  18068. {
  18069. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingCurrentL2);// 0~6553.5 amp for EVSE
  18070. }
  18071. }// End of for AC_QUANTITY
  18072. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Phase,PhaseStr[L2_N]);
  18073. }
  18074. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  18075. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Format,ValueFormatStr[Raw]);
  18076. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Measurand,MeasurandStr[Current_Import]);
  18077. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Location,LocationStr[Location_Outlet]);
  18078. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Unit,UnitOfMeasureStr[UnitOfMeasure_A]);
  18079. }
  18080. //2.7====================================== Current.Import L3 ==============================================
  18081. if(strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Current.Import") != NULL)
  18082. {
  18083. // AC 3 phase L3 current
  18084. if((gunType[gun_index] == GUN_TYPE_AC) && ((ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'W') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='D')))
  18085. {
  18086. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  18087. {
  18088. tempIndex = 2;
  18089. }
  18090. else
  18091. {
  18092. tempIndex = gun_index;
  18093. }
  18094. for (int index = 0; index < AC_QUANTITY; index++)
  18095. {
  18096. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  18097. {
  18098. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingCurrentL3);// 0~6553.5 amp for EVSE
  18099. }
  18100. }// End of for AC_QUANTITY
  18101. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Phase,PhaseStr[L3_N]);
  18102. }
  18103. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  18104. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Format,ValueFormatStr[Raw]);
  18105. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Measurand,MeasurandStr[Current_Import]);
  18106. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Location,LocationStr[Location_Outlet]);
  18107. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Unit,UnitOfMeasureStr[UnitOfMeasure_A]);
  18108. }
  18109. //2.9====================================== Voltage L2 ====================================================
  18110. if(strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Voltage") != NULL)
  18111. {
  18112. // AC 3 phase L2 volatge
  18113. if((gunType[gun_index] == GUN_TYPE_AC) && ((ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'W') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='D')))
  18114. {
  18115. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  18116. {
  18117. tempIndex = 2;
  18118. }
  18119. else
  18120. {
  18121. tempIndex = gun_index;
  18122. }
  18123. for (int index = 0; index < AC_QUANTITY; index++)
  18124. {
  18125. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  18126. {
  18127. 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
  18128. }
  18129. } // END OF FOR AC_QUANTITY
  18130. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Phase,PhaseStr[L2_N]);
  18131. }
  18132. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  18133. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Format,ValueFormatStr[Raw]);
  18134. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Measurand,MeasurandStr[Voltage]);
  18135. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Location,LocationStr[Location_Outlet]);
  18136. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Unit,UnitOfMeasureStr[UnitOfMeasure_V]);
  18137. }
  18138. //2.10====================================== Voltage L3 ====================================================
  18139. if(strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Voltage") != NULL)
  18140. {
  18141. // AC 3 phase L3 volatge
  18142. if((gunType[gun_index] == GUN_TYPE_AC) && ((ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'W') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='D')))
  18143. {
  18144. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  18145. {
  18146. tempIndex = 2;
  18147. }
  18148. else
  18149. {
  18150. tempIndex = gun_index;
  18151. }
  18152. for (int index = 0; index < AC_QUANTITY; index++)
  18153. {
  18154. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  18155. {
  18156. 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
  18157. }
  18158. } // END OF FOR AC_QUANTITY
  18159. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Phase,PhaseStr[L3_N]);
  18160. }
  18161. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  18162. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Format,ValueFormatStr[Raw]);
  18163. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Measurand,MeasurandStr[Voltage]);
  18164. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Location,LocationStr[Location_Outlet]);
  18165. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Unit,UnitOfMeasureStr[UnitOfMeasure_V]);
  18166. }
  18167. //====================== Start SoC ================================
  18168. if(strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, MeasurandStr[SoC]) != NULL)
  18169. {
  18170. //J : CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  18171. 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))
  18172. {
  18173. if((ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0') && (gunType[gun_index] != GUN_TYPE_DO))
  18174. {
  18175. tempIndex = ((gun_index==2) ? 1: 0);
  18176. }
  18177. else
  18178. {
  18179. tempIndex = gun_index;
  18180. }
  18181. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  18182. {
  18183. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  18184. {
  18185. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  18186. {
  18187. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].EvBatteryStartSoc );// 0~100%
  18188. }
  18189. }
  18190. }
  18191. else if(gunType[gun_index] == GUN_TYPE_CCS)
  18192. {
  18193. for (int index = 0; index < CCS_QUANTITY; index++)
  18194. {
  18195. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  18196. {
  18197. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].EvBatteryStartSoc );// 0~100%
  18198. }
  18199. }
  18200. }
  18201. else if(gunType[gun_index] == GUN_TYPE_GBT)
  18202. {
  18203. for (int index = 0; index < GB_QUANTITY; index++)
  18204. {
  18205. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  18206. {
  18207. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].EvBatteryStartSoc );// 0~100%
  18208. }
  18209. }
  18210. }
  18211. else if(gunType[gun_index] == GUN_TYPE_DO)
  18212. {
  18213. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  18214. {
  18215. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  18216. {
  18217. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.EvBatteryStartSoc );// 0~100%
  18218. }
  18219. }
  18220. }
  18221. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Context,ReadingContextStr[ReadingContext_Transaction_Begin]);
  18222. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Format,ValueFormatStr[Raw]);
  18223. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Measurand,MeasurandStr[SoC/*Energy_Reactive_Export_Register*/]);
  18224. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Phase,PhaseStr[L3_N]);
  18225. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Location,LocationStr[Location_EV]);
  18226. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Unit,UnitOfMeasureStr[UnitOfMeasure_Percent/*UnitOfMeasure_kWh*/]);
  18227. } // END FOR DC CASE
  18228. }
  18229. //======================================== Message create ==============================================
  18230. json_object *StopTransaction = json_object_new_object();
  18231. json_object *transactionDatas = json_object_new_array();
  18232. json_object *sampledValues = json_object_new_array();
  18233. if(strlen((char*)ShmOCPP16Data->StopTransaction[gun_index].IdTag) > 0)
  18234. json_object_object_add(StopTransaction, "idTag", json_object_new_string((char*)ShmOCPP16Data->StopTransaction[gun_index].IdTag));
  18235. json_object_object_add(StopTransaction, "meterStop", json_object_new_int(ShmOCPP16Data->StopTransaction[gun_index].MeterStop));
  18236. json_object_object_add(StopTransaction, "transactionId", json_object_new_int(ShmOCPP16Data->StopTransaction[gun_index].TransactionId));
  18237. json_object_object_add(StopTransaction, "timestamp", json_object_new_string((char*)ShmOCPP16Data->StopTransaction[gun_index].Timestamp));
  18238. json_object_object_add(StopTransaction, "reason", json_object_new_string("PowerLoss"));
  18239. for(int idxTrans = 0;idxTrans<ARRAY_SIZE(ShmOCPP16Data->StopTransaction[gun_index].TransactionData);idxTrans++)
  18240. {
  18241. json_object *transactionData = json_object_new_object();
  18242. json_object_object_add(transactionData, "timestamp", json_object_new_string((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].TimeStamp));
  18243. for(int idx=0;idx<ARRAY_SIZE(ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue);idx++)
  18244. {
  18245. if(strlen((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Value) > 0)
  18246. {
  18247. json_object *sampledValue = json_object_new_object();
  18248. json_object_object_add(sampledValue, "value", json_object_new_string((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Value));
  18249. if(strlen((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Context) > 0)
  18250. json_object_object_add(sampledValue, "context", json_object_new_string((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Context));
  18251. if(strlen((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Format) > 0)
  18252. json_object_object_add(sampledValue, "format", json_object_new_string((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Format));
  18253. if(strlen((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Measurand) > 0)
  18254. json_object_object_add(sampledValue, "measurand", json_object_new_string((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Measurand));
  18255. if(strlen((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Phase) > 0)
  18256. json_object_object_add(sampledValue, "phase", json_object_new_string((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Phase));
  18257. if(strlen((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Location) > 0)
  18258. json_object_object_add(sampledValue, "location", json_object_new_string((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Location));
  18259. if(strlen((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Unit) > 0)
  18260. json_object_object_add(sampledValue, "unit", json_object_new_string((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Unit));
  18261. json_object_array_add(sampledValues, sampledValue);
  18262. }
  18263. }
  18264. json_object_object_add(transactionData, "sampledValue", sampledValues);
  18265. json_object_array_add(transactionDatas, transactionData);
  18266. }
  18267. json_object_object_add(StopTransaction, "transactionData", transactionDatas);
  18268. sprintf(queuedata, "%d,[%d,\"%s\",\"StopTransaction\",%s]",(gun_index+1)
  18269. ,MESSAGE_TYPE_CALL
  18270. ,guid
  18271. ,json_object_to_json_string_ext(StopTransaction, JSON_C_TO_STRING_PLAIN));
  18272. json_object_put(StopTransaction);
  18273. // Check File "TempStopTransaction" Exist
  18274. if((access(TempStopTransaction,F_OK))!=-1)
  18275. {
  18276. //DEBUG_INFO("TransactionRelatedQueue exist.\n");
  18277. fclose(fopen(TempStopTransaction, "w"));
  18278. }
  18279. else
  18280. {
  18281. //DEBUG_INFO("TransactionRelatedQueue not exist\n");
  18282. FILE *log = fopen(TempStopTransaction, "w+");
  18283. if(log == NULL)
  18284. {
  18285. //DEBUG_INFO("Can't Create File TransactionRelatedQueue \n");
  18286. return ;
  18287. }
  18288. else
  18289. {
  18290. fclose(log);
  18291. }
  18292. }
  18293. //Add TempStopTransaction | Update TempStopTransaction
  18294. // open file for writing
  18295. FILE *outfile;
  18296. outfile = fopen (TempStopTransaction, "a");
  18297. //DEBUG_INFO("data = %s\n", queuedata);
  18298. fputs(queuedata, outfile);
  18299. fputs("\n", outfile);
  18300. fclose (outfile);
  18301. system("/bin/fsync -d /dev/mtdblock13;/bin/sync &");
  18302. OCPP_updatePeriodEnergy(gun_index);
  18303. }
  18304. void checkTempStopTransaction(int gun_index)
  18305. {
  18306. FILE *fptr1;
  18307. char ch;
  18308. char str[QUEUE_MESSAGE_LENGTH]={0};
  18309. char guid[37]={0};
  18310. char tempdata[65]={0};
  18311. char connectorStr[2]={0};
  18312. char TempStopTransaction[256];
  18313. sprintf(TempStopTransaction, "/Storage/OCPP/TempStopTransaction_%d", (gun_index+1));
  18314. fptr1 = fopen(TempStopTransaction, "r");
  18315. //TempStopTransaction格式: 槍號,StopTransaction封包
  18316. if (!fptr1)
  18317. {
  18318. //printf(" File not found or unable to open the input file!!\n");
  18319. return ;
  18320. }
  18321. ch=fgetc(fptr1);
  18322. //printf(" Now the content of the file %s is : \n",fname);
  18323. rewind(fptr1);
  18324. if(ch!=EOF)
  18325. {
  18326. // copy all contents to the temporary file except the specific line
  18327. while (fgets(str, QUEUE_MESSAGE_LENGTH, fptr1) != NULL)
  18328. {
  18329. str[strlen(str) - 1] = '\0'; // eat the newline fgets() stores
  18330. if(str[0]=='\0')
  18331. {
  18332. break;
  18333. }
  18334. //TempStopTransaction格式: 槍號,StopTransaction封包
  18335. strncpy(connectorStr, str, 1);
  18336. if(atoi(connectorStr) != (gun_index+1))
  18337. {
  18338. DEBUG_INFO("atoi(connectorStr) = %d, gun_index = %d\n", atoi(connectorStr), gun_index);
  18339. fclose(fptr1);
  18340. return ;
  18341. }
  18342. //random_uuid(guid);
  18343. strncpy(guid, str+6, 36); //copy guid
  18344. sprintf(tempdata, "StopTransaction,%d", (gun_index));
  18345. if(hashmap_operation(HASH_OP_ADD, guid, tempdata) == 1)
  18346. {
  18347. //DEBUG_INFO("StopTransaction mapitem pass\n");
  18348. }
  18349. queue_operation(QUEUE_OPERATION_ADD, guid, str);//addq(guid, queuedata); ---> remove temporally
  18350. OCPP_insert_transaction_msg(NO, str);
  18351. memset(str,0,ARRAY_SIZE(str));
  18352. }
  18353. }
  18354. // fptr1=freopen(NULL,"w",fptr1); // reset the fptr1 again
  18355. fclose(fptr1);
  18356. remove(TempStopTransaction); // remove the original file
  18357. system("/bin/fsync -d /dev/mtdblock13;/bin/sync &");
  18358. }
  18359. void FillStartTransaction(int ConnectorId, unsigned char IdTag[], int MeterStart,int ReservationId,unsigned char Timestamp[])
  18360. {
  18361. ShmOCPP16Data->StartTransaction[ConnectorId-1].ConnectorId = ConnectorId;
  18362. ShmOCPP16Data->StartTransaction[ConnectorId-1].ReservationId = ReservationId;
  18363. ShmOCPP16Data->StartTransaction[ConnectorId-1].MeterStart = MeterStart;
  18364. strcpy((char *)ShmOCPP16Data->StartTransaction[ConnectorId-1].IdTag, (char *)IdTag);
  18365. strcpy((char *)ShmOCPP16Data->StartTransaction[ConnectorId-1].Timestamp,(char *) Timestamp);
  18366. }
  18367. int GetWebSocketPingInterval(void)
  18368. {
  18369. return atoi((const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemData);
  18370. }
  18371. int GetServerSign(void)
  18372. {
  18373. return server_sign;
  18374. }
  18375. uint8_t GetOcppSecurityProfile()
  18376. {
  18377. return atoi((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[SecurityProfile].ItemData);
  18378. }
  18379. void GetOcppChargerBoxId(uint8_t *data)
  18380. {
  18381. sprintf((char*)data, "%s", ShmSysConfigAndInfo->SysConfig.ChargeBoxId);
  18382. }
  18383. void GetOcppSecurityPassword(uint8_t *data)
  18384. {
  18385. sprintf((char*)data, "%s", ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationKey].ItemData);
  18386. }
  18387. void SetOcppVersion(uint8_t *version)
  18388. {
  18389. for (uint8_t idx=0; idx<strlen((char*)version); idx++) version[idx] = tolower(version[idx]);
  18390. DEBUG_INFO("ocpp version: %s\n", version);
  18391. if(strstr((char*)version, "ocpp1.6") != NULL)
  18392. {
  18393. ShmSysConfigAndInfo->SysInfo.OcppRunningVer = OCPP_RUNNING_VERSION_16;
  18394. }
  18395. else if(strstr((char*)version, "ocpp2.0") != NULL)
  18396. {
  18397. ShmSysConfigAndInfo->SysInfo.OcppRunningVer = OCPP_RUNNING_VERSION_20;
  18398. system("pkill OcppBackend");
  18399. }
  18400. }
  18401. void SetServerSign(int value)
  18402. {
  18403. server_sign = value;
  18404. }
  18405. int GetBootNotificationInterval(void)
  18406. {
  18407. return BootNotificationInterval;
  18408. }
  18409. int GetInternetConn(void)
  18410. {
  18411. return ShmSysConfigAndInfo->SysInfo.InternetConn;
  18412. }
  18413. int GetBackendConnectionTimeout(void)
  18414. {
  18415. return ShmSysConfigAndInfo->SysConfig.BackendConnTimeout>=0?ShmSysConfigAndInfo->SysConfig.BackendConnTimeout:300;
  18416. }
  18417. int isConnectorInitMode(int gun_index)
  18418. {
  18419. int tempIndex = 0;
  18420. int result = TRUE;
  18421. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DCcc
  18422. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  18423. {
  18424. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  18425. {
  18426. tempIndex = ((gun_index==2) ? 1: 0);
  18427. }
  18428. else
  18429. {
  18430. tempIndex = gun_index;
  18431. }
  18432. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  18433. {
  18434. if ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex))
  18435. {
  18436. result = (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus==SYS_MODE_BOOTING)?TRUE:FALSE;
  18437. } //end of the same index
  18438. }//end of for CHAdeMO_QUANTITY
  18439. }
  18440. else if(gunType[gun_index] == GUN_TYPE_CCS)
  18441. {
  18442. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  18443. {
  18444. tempIndex = ((gun_index==2) ? 1: 0);
  18445. }
  18446. else
  18447. {
  18448. tempIndex = gun_index;
  18449. }
  18450. for (int index = 0; index < CCS_QUANTITY; index++)
  18451. {
  18452. if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  18453. {
  18454. result = (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus==SYS_MODE_BOOTING)?TRUE:FALSE;
  18455. } //end of the same index
  18456. } // end of for CCS_QUANTITY
  18457. }
  18458. else if(gunType[gun_index] == GUN_TYPE_GBT)
  18459. {
  18460. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  18461. {
  18462. tempIndex = ((gun_index==2) ? 1: 0);
  18463. }
  18464. else
  18465. {
  18466. tempIndex = gun_index;
  18467. }
  18468. for (int index = 0; index < GB_QUANTITY; index++)
  18469. {
  18470. if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  18471. {
  18472. result = (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus==SYS_MODE_BOOTING)?TRUE:FALSE;
  18473. } //end of the same index
  18474. } // end of for GB_QUANTITY
  18475. }
  18476. else if(gunType[gun_index] == GUN_TYPE_DO)
  18477. {
  18478. tempIndex = gun_index;
  18479. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  18480. {
  18481. if(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  18482. {
  18483. result = (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus==SYS_MODE_BOOTING)?TRUE:FALSE;
  18484. } //end of the same index
  18485. }
  18486. }
  18487. else
  18488. {
  18489. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  18490. {
  18491. tempIndex = 2;
  18492. }
  18493. else
  18494. {
  18495. tempIndex = gun_index;
  18496. }
  18497. for (int index = 0; index < AC_QUANTITY; index++)
  18498. {
  18499. if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  18500. {
  18501. result = (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus==SYS_MODE_BOOTING)?TRUE:FALSE;
  18502. }//end of the same index
  18503. }//end of for AC_QUANTITY
  18504. }
  18505. return result;
  18506. }
  18507. void refreshProcDogTimer()
  18508. {
  18509. ShmOCPP16Data->procDogTime = time((time_t*)NULL);
  18510. }
  18511. void InitialSystemValue(void)
  18512. {
  18513. server_cycle_Status = atoi((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemData);
  18514. locallistVersion=0;
  18515. BootNotificationInterval = 0;
  18516. authorizeRetryTimes = 0;
  18517. GunStatusInterval = 10;
  18518. TransactionMessageAttemptsValue = atoi((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData);
  18519. TransactionMessageRetryIntervalValue = atoi((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData);
  18520. //Hear Beat
  18521. HeartBeatWithNOResponse = 0;
  18522. HeartBeatWaitTime = atoi((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemData);;
  18523. FirstHeartBeat = 0;
  18524. FirmwareStatusNotificationStatus = FIRMWARE_STATUS_IDLE; // Idle
  18525. DiagnosticsStatusNotificationStatus = DIAGNOSTIC_STATUS_IDLE; // Idle
  18526. memset(CurrentChargingProfileScheduleStr, 0, ARRAY_SIZE(CurrentChargingProfileScheduleStr));
  18527. memset(ChademoPreviousSystemStatus, 0, ARRAY_SIZE(ChademoPreviousSystemStatus));
  18528. memset(CcsPreviousSystemStatus, 0, ARRAY_SIZE(CcsPreviousSystemStatus));
  18529. memset(GbPreviousSystemStatus, 0, ARRAY_SIZE(GbPreviousSystemStatus));
  18530. memset(AcPreviousSystemStatus, 0, ARRAY_SIZE(AcPreviousSystemStatus));
  18531. memset(ChademoPreviousConnectorPlugIn, 0, ARRAY_SIZE(ChademoPreviousConnectorPlugIn));
  18532. memset(CcsPreviousConnectorPlugIn, 0, ARRAY_SIZE(CcsPreviousConnectorPlugIn));
  18533. memset(GbPreviousConnectorPlugIn, 0, ARRAY_SIZE(GbPreviousConnectorPlugIn));
  18534. memset(AcPreviousConnectorPlugIn, 0, ARRAY_SIZE(AcPreviousConnectorPlugIn));
  18535. //Status && ConnectorPlugIn Setting
  18536. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  18537. {
  18538. ChademoPreviousSystemStatus[index]= ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PreviousSystemStatus;
  18539. ChademoPreviousConnectorPlugIn[index] = ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ConnectorPlugIn;
  18540. }
  18541. for (int index = 0; index < CCS_QUANTITY; index++)
  18542. {
  18543. CcsPreviousSystemStatus[index] = ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PreviousSystemStatus;
  18544. CcsPreviousConnectorPlugIn[index] = ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ConnectorPlugIn;
  18545. }
  18546. for (int index = 0; index < GB_QUANTITY; index++)
  18547. {
  18548. GbPreviousSystemStatus[index] = ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PreviousSystemStatus;
  18549. GbPreviousConnectorPlugIn[index] = ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ConnectorPlugIn;
  18550. }
  18551. for (int index = 0; index < AC_QUANTITY; index++)
  18552. {
  18553. AcPreviousSystemStatus[index]= ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PreviousSystemStatus;
  18554. AcPreviousConnectorPlugIn[index] = ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PilotState;
  18555. }
  18556. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  18557. {
  18558. DoPreviousSystemStatus[index]= ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PreviousSystemStatus;
  18559. DoPreviousConnectorPlugIn[index] = ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PilotState;
  18560. }
  18561. for(int gun_index=0; gun_index < gunTotalNumber; gun_index++ )
  18562. {
  18563. cpinitateMsg.bits[gun_index].TriggerStatusNotificationReq = 0;
  18564. cpinitateMsg.bits[gun_index].StatusNotificationReq = 0;
  18565. cpinitateMsg.bits[gun_index].StatusNotificationConf = 0;
  18566. //clientTime.MeterValues[gun_index] = time((time_t*)NULL);
  18567. memset(&ShmOCPP16Data->StatusNotification[gun_index], 0x00, sizeof(struct StructStatusNotification));
  18568. }
  18569. memset( (void *)unknownkey, 0, sizeof(unknownkey));
  18570. refreshStartTimer(&clientTime.Heartbeat);
  18571. sleep(1);
  18572. }
  18573. void LWS_Send(char *str)
  18574. {
  18575. //=====================================================
  18576. // Check InternetConn 0: disconnected, 1: connected
  18577. //====================================================
  18578. if(GetOcppConnStatus() == 0)
  18579. {
  18580. DEBUG_INFO("offline now !!!\n");
  18581. return;
  18582. }
  18583. // Only disable isWebsocketSendable operation initiated by charger
  18584. if((strstr((char*)str, "\"Authorize\"") != NULL)
  18585. || (strstr((char*)str, "\"BootNotification\"") != NULL)
  18586. || (strstr((char*)str, "\"DataTransfer\"") != NULL)
  18587. || (strstr((char*)str, "\"DiagnosticsStatusNotification\"") != NULL)
  18588. || (strstr((char*)str, "\"FirmwareStatusNotification\"") != NULL)
  18589. || (strstr((char*)str, "\"Heartbeat\"") != NULL)
  18590. || (strstr((char*)str, "\"MeterValues\"") != NULL)
  18591. || (strstr((char*)str, "\"StartTransaction\"") != NULL)
  18592. || (strstr((char*)str, "\"StatusNotification\"") != NULL)
  18593. || (strstr((char*)str, "\"StopTransaction\"") != NULL)
  18594. || (strstr((char*)str, "\"LogStatusNotification\"") != NULL)
  18595. || (strstr((char*)str, "\"SecurityEventNotification\"") != NULL)
  18596. || (strstr((char*)str, "\"SignCertificate\"") != NULL)
  18597. || (strstr((char*)str, "\"SignedFirmwareStatusNotification\"") != NULL))
  18598. {
  18599. isWebsocketSendable = 0;
  18600. }
  18601. pthread_mutex_lock(&lock_send);
  18602. memset(SendBuffer, 0, ARRAY_SIZE(SendBuffer));
  18603. sprintf((char *)SendBuffer, "%s", str);
  18604. SendBufLen = strlen(str);
  18605. pthread_mutex_unlock(&lock_send);
  18606. lws_callback_on_writable(wsi_client);
  18607. //lws_service(context, 0);
  18608. //sleep(1);
  18609. }
  18610. void LWS_SendNow(char *str)
  18611. {
  18612. //=====================================================
  18613. // Check InternetConn 0: disconnected, 1: connected
  18614. //====================================================
  18615. if(GetOcppConnStatus() == 0)
  18616. {
  18617. DEBUG_INFO("offline now !!!\n");
  18618. return;
  18619. }
  18620. // Only disable isWebsocketSendable operation initiated by charger
  18621. if((strstr((char*)str, "\"Authorize\"") != NULL)
  18622. || (strstr((char*)str, "\"BootNotification\"") != NULL)
  18623. || (strstr((char*)str, "\"DataTransfer\"") != NULL)
  18624. || (strstr((char*)str, "\"DiagnosticsStatusNotification\"") != NULL)
  18625. || (strstr((char*)str, "\"FirmwareStatusNotification\"") != NULL)
  18626. || (strstr((char*)str, "\"Heartbeat\"") != NULL)
  18627. || (strstr((char*)str, "\"MeterValues\"") != NULL)
  18628. || (strstr((char*)str, "\"StartTransaction\"") != NULL)
  18629. || (strstr((char*)str, "\"StatusNotification\"") != NULL)
  18630. || (strstr((char*)str, "\"StopTransaction\"") != NULL)
  18631. || (strstr((char*)str, "\"LogStatusNotification\"") != NULL)
  18632. || (strstr((char*)str, "\"SecurityEventNotification\"") != NULL)
  18633. || (strstr((char*)str, "\"SignCertificate\"") != NULL)
  18634. || (strstr((char*)str, "\"SignedFirmwareStatusNotification\"") != NULL))
  18635. {
  18636. isWebsocketSendable = 0;
  18637. }
  18638. pthread_mutex_lock(&lock_send);
  18639. memset(SendBuffer, 0, ARRAY_SIZE(SendBuffer));
  18640. sprintf((char *)SendBuffer, "%s", str);
  18641. SendBufLen = strlen(str);
  18642. pthread_mutex_unlock(&lock_send);
  18643. lws_callback_on_writable(wsi_client);
  18644. lws_service(context, 0);
  18645. //sleep(1);
  18646. }