MessageHandler.c 612 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309331033113312331333143315331633173318331933203321332233233324332533263327332833293330333133323333333433353336333733383339334033413342334333443345334633473348334933503351335233533354335533563357335833593360336133623363336433653366336733683369337033713372337333743375337633773378337933803381338233833384338533863387338833893390339133923393339433953396339733983399340034013402340334043405340634073408340934103411341234133414341534163417341834193420342134223423342434253426342734283429343034313432343334343435343634373438343934403441344234433444344534463447344834493450345134523453345434553456345734583459346034613462346334643465346634673468346934703471347234733474347534763477347834793480348134823483348434853486348734883489349034913492349334943495349634973498349935003501350235033504350535063507350835093510351135123513351435153516351735183519352035213522352335243525352635273528352935303531353235333534353535363537353835393540354135423543354435453546354735483549355035513552355335543555355635573558355935603561356235633564356535663567356835693570357135723573357435753576357735783579358035813582358335843585358635873588358935903591359235933594359535963597359835993600360136023603360436053606360736083609361036113612361336143615361636173618361936203621362236233624362536263627362836293630363136323633363436353636363736383639364036413642364336443645364636473648364936503651365236533654365536563657365836593660366136623663366436653666366736683669367036713672367336743675367636773678367936803681368236833684368536863687368836893690369136923693369436953696369736983699370037013702370337043705370637073708370937103711371237133714371537163717371837193720372137223723372437253726372737283729373037313732373337343735373637373738373937403741374237433744374537463747374837493750375137523753375437553756375737583759376037613762376337643765376637673768376937703771377237733774377537763777377837793780378137823783378437853786378737883789379037913792379337943795379637973798379938003801380238033804380538063807380838093810381138123813381438153816381738183819382038213822382338243825382638273828382938303831383238333834383538363837383838393840384138423843384438453846384738483849385038513852385338543855385638573858385938603861386238633864386538663867386838693870387138723873387438753876387738783879388038813882388338843885388638873888388938903891389238933894389538963897389838993900390139023903390439053906390739083909391039113912391339143915391639173918391939203921392239233924392539263927392839293930393139323933393439353936393739383939394039413942394339443945394639473948394939503951395239533954395539563957395839593960396139623963396439653966396739683969397039713972397339743975397639773978397939803981398239833984398539863987398839893990399139923993399439953996399739983999400040014002400340044005400640074008400940104011401240134014401540164017401840194020402140224023402440254026402740284029403040314032403340344035403640374038403940404041404240434044404540464047404840494050405140524053405440554056405740584059406040614062406340644065406640674068406940704071407240734074407540764077407840794080408140824083408440854086408740884089409040914092409340944095409640974098409941004101410241034104410541064107410841094110411141124113411441154116411741184119412041214122412341244125412641274128412941304131413241334134413541364137413841394140414141424143414441454146414741484149415041514152415341544155415641574158415941604161416241634164416541664167416841694170417141724173417441754176417741784179418041814182418341844185418641874188418941904191419241934194419541964197419841994200420142024203420442054206420742084209421042114212421342144215421642174218421942204221422242234224422542264227422842294230423142324233423442354236423742384239424042414242424342444245424642474248424942504251425242534254425542564257425842594260426142624263426442654266426742684269427042714272427342744275427642774278427942804281428242834284428542864287428842894290429142924293429442954296429742984299430043014302430343044305430643074308430943104311431243134314431543164317431843194320432143224323432443254326432743284329433043314332433343344335433643374338433943404341434243434344434543464347434843494350435143524353435443554356435743584359436043614362436343644365436643674368436943704371437243734374437543764377437843794380438143824383438443854386438743884389439043914392439343944395439643974398439944004401440244034404440544064407440844094410441144124413441444154416441744184419442044214422442344244425442644274428442944304431443244334434443544364437443844394440444144424443444444454446444744484449445044514452445344544455445644574458445944604461446244634464446544664467446844694470447144724473447444754476447744784479448044814482448344844485448644874488448944904491449244934494449544964497449844994500450145024503450445054506450745084509451045114512451345144515451645174518451945204521452245234524452545264527452845294530453145324533453445354536453745384539454045414542454345444545454645474548454945504551455245534554455545564557455845594560456145624563456445654566456745684569457045714572457345744575457645774578457945804581458245834584458545864587458845894590459145924593459445954596459745984599460046014602460346044605460646074608460946104611461246134614461546164617461846194620462146224623462446254626462746284629463046314632463346344635463646374638463946404641464246434644464546464647464846494650465146524653465446554656465746584659466046614662466346644665466646674668466946704671467246734674467546764677467846794680468146824683468446854686468746884689469046914692469346944695469646974698469947004701470247034704470547064707470847094710471147124713471447154716471747184719472047214722472347244725472647274728472947304731473247334734473547364737473847394740474147424743474447454746474747484749475047514752475347544755475647574758475947604761476247634764476547664767476847694770477147724773477447754776477747784779478047814782478347844785478647874788478947904791479247934794479547964797479847994800480148024803480448054806480748084809481048114812481348144815481648174818481948204821482248234824482548264827482848294830483148324833483448354836483748384839484048414842484348444845484648474848484948504851485248534854485548564857485848594860486148624863486448654866486748684869487048714872487348744875487648774878487948804881488248834884488548864887488848894890489148924893489448954896489748984899490049014902490349044905490649074908490949104911491249134914491549164917491849194920492149224923492449254926492749284929493049314932493349344935493649374938493949404941494249434944494549464947494849494950495149524953495449554956495749584959496049614962496349644965496649674968496949704971497249734974497549764977497849794980498149824983498449854986498749884989499049914992499349944995499649974998499950005001500250035004500550065007500850095010501150125013501450155016501750185019502050215022502350245025502650275028502950305031503250335034503550365037503850395040504150425043504450455046504750485049505050515052505350545055505650575058505950605061506250635064506550665067506850695070507150725073507450755076507750785079508050815082508350845085508650875088508950905091509250935094509550965097509850995100510151025103510451055106510751085109511051115112511351145115511651175118511951205121512251235124512551265127512851295130513151325133513451355136513751385139514051415142514351445145514651475148514951505151515251535154515551565157515851595160516151625163516451655166516751685169517051715172517351745175517651775178517951805181518251835184518551865187518851895190519151925193519451955196519751985199520052015202520352045205520652075208520952105211521252135214521552165217521852195220522152225223522452255226522752285229523052315232523352345235523652375238523952405241524252435244524552465247524852495250525152525253525452555256525752585259526052615262526352645265526652675268526952705271527252735274527552765277527852795280528152825283528452855286528752885289529052915292529352945295529652975298529953005301530253035304530553065307530853095310531153125313531453155316531753185319532053215322532353245325532653275328532953305331533253335334533553365337533853395340534153425343534453455346534753485349535053515352535353545355535653575358535953605361536253635364536553665367536853695370537153725373537453755376537753785379538053815382538353845385538653875388538953905391539253935394539553965397539853995400540154025403540454055406540754085409541054115412541354145415541654175418541954205421542254235424542554265427542854295430543154325433543454355436543754385439544054415442544354445445544654475448544954505451545254535454545554565457545854595460546154625463546454655466546754685469547054715472547354745475547654775478547954805481548254835484548554865487548854895490549154925493549454955496549754985499550055015502550355045505550655075508550955105511551255135514551555165517551855195520552155225523552455255526552755285529553055315532553355345535553655375538553955405541554255435544554555465547554855495550555155525553555455555556555755585559556055615562556355645565556655675568556955705571557255735574557555765577557855795580558155825583558455855586558755885589559055915592559355945595559655975598559956005601560256035604560556065607560856095610561156125613561456155616561756185619562056215622562356245625562656275628562956305631563256335634563556365637563856395640564156425643564456455646564756485649565056515652565356545655565656575658565956605661566256635664566556665667566856695670567156725673567456755676567756785679568056815682568356845685568656875688568956905691569256935694569556965697569856995700570157025703570457055706570757085709571057115712571357145715571657175718571957205721572257235724572557265727572857295730573157325733573457355736573757385739574057415742574357445745574657475748574957505751575257535754575557565757575857595760576157625763576457655766576757685769577057715772577357745775577657775778577957805781578257835784578557865787578857895790579157925793579457955796579757985799580058015802580358045805580658075808580958105811581258135814581558165817581858195820582158225823582458255826582758285829583058315832583358345835583658375838583958405841584258435844584558465847584858495850585158525853585458555856585758585859586058615862586358645865586658675868586958705871587258735874587558765877587858795880588158825883588458855886588758885889589058915892589358945895589658975898589959005901590259035904590559065907590859095910591159125913591459155916591759185919592059215922592359245925592659275928592959305931593259335934593559365937593859395940594159425943594459455946594759485949595059515952595359545955595659575958595959605961596259635964596559665967596859695970597159725973597459755976597759785979598059815982598359845985598659875988598959905991599259935994599559965997599859996000600160026003600460056006600760086009601060116012601360146015601660176018601960206021602260236024602560266027602860296030603160326033603460356036603760386039604060416042604360446045604660476048604960506051605260536054605560566057605860596060606160626063606460656066606760686069607060716072607360746075607660776078607960806081608260836084608560866087608860896090609160926093609460956096609760986099610061016102610361046105610661076108610961106111611261136114611561166117611861196120612161226123612461256126612761286129613061316132613361346135613661376138613961406141614261436144614561466147614861496150615161526153615461556156615761586159616061616162616361646165616661676168616961706171617261736174617561766177617861796180618161826183618461856186618761886189619061916192619361946195619661976198619962006201620262036204620562066207620862096210621162126213621462156216621762186219622062216222622362246225622662276228622962306231623262336234623562366237623862396240624162426243624462456246624762486249625062516252625362546255625662576258625962606261626262636264626562666267626862696270627162726273627462756276627762786279628062816282628362846285628662876288628962906291629262936294629562966297629862996300630163026303630463056306630763086309631063116312631363146315631663176318631963206321632263236324632563266327632863296330633163326333633463356336633763386339634063416342634363446345634663476348634963506351635263536354635563566357635863596360636163626363636463656366636763686369637063716372637363746375637663776378637963806381638263836384638563866387638863896390639163926393639463956396639763986399640064016402640364046405640664076408640964106411641264136414641564166417641864196420642164226423642464256426642764286429643064316432643364346435643664376438643964406441644264436444644564466447644864496450645164526453645464556456645764586459646064616462646364646465646664676468646964706471647264736474647564766477647864796480648164826483648464856486648764886489649064916492649364946495649664976498649965006501650265036504650565066507650865096510651165126513651465156516651765186519652065216522652365246525652665276528652965306531653265336534653565366537653865396540654165426543654465456546654765486549655065516552655365546555655665576558655965606561656265636564656565666567656865696570657165726573657465756576657765786579658065816582658365846585658665876588658965906591659265936594659565966597659865996600660166026603660466056606660766086609661066116612661366146615661666176618661966206621662266236624662566266627662866296630663166326633663466356636663766386639664066416642664366446645664666476648664966506651665266536654665566566657665866596660666166626663666466656666666766686669667066716672667366746675667666776678667966806681668266836684668566866687668866896690669166926693669466956696669766986699670067016702670367046705670667076708670967106711671267136714671567166717671867196720672167226723672467256726672767286729673067316732673367346735673667376738673967406741674267436744674567466747674867496750675167526753675467556756675767586759676067616762676367646765676667676768676967706771677267736774677567766777677867796780678167826783678467856786678767886789679067916792679367946795679667976798679968006801680268036804680568066807680868096810681168126813681468156816681768186819682068216822682368246825682668276828682968306831683268336834683568366837683868396840684168426843684468456846684768486849685068516852685368546855685668576858685968606861686268636864686568666867686868696870687168726873687468756876687768786879688068816882688368846885688668876888688968906891689268936894689568966897689868996900690169026903690469056906690769086909691069116912691369146915691669176918691969206921692269236924692569266927692869296930693169326933693469356936693769386939694069416942694369446945694669476948694969506951695269536954695569566957695869596960696169626963696469656966696769686969697069716972697369746975697669776978697969806981698269836984698569866987698869896990699169926993699469956996699769986999700070017002700370047005700670077008700970107011701270137014701570167017701870197020702170227023702470257026702770287029703070317032703370347035703670377038703970407041704270437044704570467047704870497050705170527053705470557056705770587059706070617062706370647065706670677068706970707071707270737074707570767077707870797080708170827083708470857086708770887089709070917092709370947095709670977098709971007101710271037104710571067107710871097110711171127113711471157116711771187119712071217122712371247125712671277128712971307131713271337134713571367137713871397140714171427143714471457146714771487149715071517152715371547155715671577158715971607161716271637164716571667167716871697170717171727173717471757176717771787179718071817182718371847185718671877188718971907191719271937194719571967197719871997200720172027203720472057206720772087209721072117212721372147215721672177218721972207221722272237224722572267227722872297230723172327233723472357236723772387239724072417242724372447245724672477248724972507251725272537254725572567257725872597260726172627263726472657266726772687269727072717272727372747275727672777278727972807281728272837284728572867287728872897290729172927293729472957296729772987299730073017302730373047305730673077308730973107311731273137314731573167317731873197320732173227323732473257326732773287329733073317332733373347335733673377338733973407341734273437344734573467347734873497350735173527353735473557356735773587359736073617362736373647365736673677368736973707371737273737374737573767377737873797380738173827383738473857386738773887389739073917392739373947395739673977398739974007401740274037404740574067407740874097410741174127413741474157416741774187419742074217422742374247425742674277428742974307431743274337434743574367437743874397440744174427443744474457446744774487449745074517452745374547455745674577458745974607461746274637464746574667467746874697470747174727473747474757476747774787479748074817482748374847485748674877488748974907491749274937494749574967497749874997500750175027503750475057506750775087509751075117512751375147515751675177518751975207521752275237524752575267527752875297530753175327533753475357536753775387539754075417542754375447545754675477548754975507551755275537554755575567557755875597560756175627563756475657566756775687569757075717572757375747575757675777578757975807581758275837584758575867587758875897590759175927593759475957596759775987599760076017602760376047605760676077608760976107611761276137614761576167617761876197620762176227623762476257626762776287629763076317632763376347635763676377638763976407641764276437644764576467647764876497650765176527653765476557656765776587659766076617662766376647665766676677668766976707671767276737674767576767677767876797680768176827683768476857686768776887689769076917692769376947695769676977698769977007701770277037704770577067707770877097710771177127713771477157716771777187719772077217722772377247725772677277728772977307731773277337734773577367737773877397740774177427743774477457746774777487749775077517752775377547755775677577758775977607761776277637764776577667767776877697770777177727773777477757776777777787779778077817782778377847785778677877788778977907791779277937794779577967797779877997800780178027803780478057806780778087809781078117812781378147815781678177818781978207821782278237824782578267827782878297830783178327833783478357836783778387839784078417842784378447845784678477848784978507851785278537854785578567857785878597860786178627863786478657866786778687869787078717872787378747875787678777878787978807881788278837884788578867887788878897890789178927893789478957896789778987899790079017902790379047905790679077908790979107911791279137914791579167917791879197920792179227923792479257926792779287929793079317932793379347935793679377938793979407941794279437944794579467947794879497950795179527953795479557956795779587959796079617962796379647965796679677968796979707971797279737974797579767977797879797980798179827983798479857986798779887989799079917992799379947995799679977998799980008001800280038004800580068007800880098010801180128013801480158016801780188019802080218022802380248025802680278028802980308031803280338034803580368037803880398040804180428043804480458046804780488049805080518052805380548055805680578058805980608061806280638064806580668067806880698070807180728073807480758076807780788079808080818082808380848085808680878088808980908091809280938094809580968097809880998100810181028103810481058106810781088109811081118112811381148115811681178118811981208121812281238124812581268127812881298130813181328133813481358136813781388139814081418142814381448145814681478148814981508151815281538154815581568157815881598160816181628163816481658166816781688169817081718172817381748175817681778178817981808181818281838184818581868187818881898190819181928193819481958196819781988199820082018202820382048205820682078208820982108211821282138214821582168217821882198220822182228223822482258226822782288229823082318232823382348235823682378238823982408241824282438244824582468247824882498250825182528253825482558256825782588259826082618262826382648265826682678268826982708271827282738274827582768277827882798280828182828283828482858286828782888289829082918292829382948295829682978298829983008301830283038304830583068307830883098310831183128313831483158316831783188319832083218322832383248325832683278328832983308331833283338334833583368337833883398340834183428343834483458346834783488349835083518352835383548355835683578358835983608361836283638364836583668367836883698370837183728373837483758376837783788379838083818382838383848385838683878388838983908391839283938394839583968397839883998400840184028403840484058406840784088409841084118412841384148415841684178418841984208421842284238424842584268427842884298430843184328433843484358436843784388439844084418442844384448445844684478448844984508451845284538454845584568457845884598460846184628463846484658466846784688469847084718472847384748475847684778478847984808481848284838484848584868487848884898490849184928493849484958496849784988499850085018502850385048505850685078508850985108511851285138514851585168517851885198520852185228523852485258526852785288529853085318532853385348535853685378538853985408541854285438544854585468547854885498550855185528553855485558556855785588559856085618562856385648565856685678568856985708571857285738574857585768577857885798580858185828583858485858586858785888589859085918592859385948595859685978598859986008601860286038604860586068607860886098610861186128613861486158616861786188619862086218622862386248625862686278628862986308631863286338634863586368637863886398640864186428643864486458646864786488649865086518652865386548655865686578658865986608661866286638664866586668667866886698670867186728673867486758676867786788679868086818682868386848685868686878688868986908691869286938694869586968697869886998700870187028703870487058706870787088709871087118712871387148715871687178718871987208721872287238724872587268727872887298730873187328733873487358736873787388739874087418742874387448745874687478748874987508751875287538754875587568757875887598760876187628763876487658766876787688769877087718772877387748775877687778778877987808781878287838784878587868787878887898790879187928793879487958796879787988799880088018802880388048805880688078808880988108811881288138814881588168817881888198820882188228823882488258826882788288829883088318832883388348835883688378838883988408841884288438844884588468847884888498850885188528853885488558856885788588859886088618862886388648865886688678868886988708871887288738874887588768877887888798880888188828883888488858886888788888889889088918892889388948895889688978898889989008901890289038904890589068907890889098910891189128913891489158916891789188919892089218922892389248925892689278928892989308931893289338934893589368937893889398940894189428943894489458946894789488949895089518952895389548955895689578958895989608961896289638964896589668967896889698970897189728973897489758976897789788979898089818982898389848985898689878988898989908991899289938994899589968997899889999000900190029003900490059006900790089009901090119012901390149015901690179018901990209021902290239024902590269027902890299030903190329033903490359036903790389039904090419042904390449045904690479048904990509051905290539054905590569057905890599060906190629063906490659066906790689069907090719072907390749075907690779078907990809081908290839084908590869087908890899090909190929093909490959096909790989099910091019102910391049105910691079108910991109111911291139114911591169117911891199120912191229123912491259126912791289129913091319132913391349135913691379138913991409141914291439144914591469147914891499150915191529153915491559156915791589159916091619162916391649165916691679168916991709171917291739174917591769177917891799180918191829183918491859186918791889189919091919192919391949195919691979198919992009201920292039204920592069207920892099210921192129213921492159216921792189219922092219222922392249225922692279228922992309231923292339234923592369237923892399240924192429243924492459246924792489249925092519252925392549255925692579258925992609261926292639264926592669267926892699270927192729273927492759276927792789279928092819282928392849285928692879288928992909291929292939294929592969297929892999300930193029303930493059306930793089309931093119312931393149315931693179318931993209321932293239324932593269327932893299330933193329333933493359336933793389339934093419342934393449345934693479348934993509351935293539354935593569357935893599360936193629363936493659366936793689369937093719372937393749375937693779378937993809381938293839384938593869387938893899390939193929393939493959396939793989399940094019402940394049405940694079408940994109411941294139414941594169417941894199420942194229423942494259426942794289429943094319432943394349435943694379438943994409441944294439444944594469447944894499450945194529453945494559456945794589459946094619462946394649465946694679468946994709471947294739474947594769477947894799480948194829483948494859486948794889489949094919492949394949495949694979498949995009501950295039504950595069507950895099510951195129513951495159516951795189519952095219522952395249525952695279528952995309531953295339534953595369537953895399540954195429543954495459546954795489549955095519552955395549555955695579558955995609561956295639564956595669567956895699570957195729573957495759576957795789579958095819582958395849585958695879588958995909591959295939594959595969597959895999600960196029603960496059606960796089609961096119612961396149615961696179618961996209621962296239624962596269627962896299630963196329633963496359636963796389639964096419642964396449645964696479648964996509651965296539654965596569657965896599660966196629663966496659666966796689669967096719672967396749675967696779678967996809681968296839684968596869687968896899690969196929693969496959696969796989699970097019702970397049705970697079708970997109711971297139714971597169717971897199720972197229723972497259726972797289729973097319732973397349735973697379738973997409741974297439744974597469747974897499750975197529753975497559756975797589759976097619762976397649765976697679768976997709771977297739774977597769777977897799780978197829783978497859786978797889789979097919792979397949795979697979798979998009801980298039804980598069807980898099810981198129813981498159816981798189819982098219822982398249825982698279828982998309831983298339834983598369837983898399840984198429843984498459846984798489849985098519852985398549855985698579858985998609861986298639864986598669867986898699870987198729873987498759876987798789879988098819882988398849885988698879888988998909891989298939894989598969897989898999900990199029903990499059906990799089909991099119912991399149915991699179918991999209921992299239924992599269927992899299930993199329933993499359936993799389939994099419942994399449945994699479948994999509951995299539954995599569957995899599960996199629963996499659966996799689969997099719972997399749975997699779978997999809981998299839984998599869987998899899990999199929993999499959996999799989999100001000110002100031000410005100061000710008100091001010011100121001310014100151001610017100181001910020100211002210023100241002510026100271002810029100301003110032100331003410035100361003710038100391004010041100421004310044100451004610047100481004910050100511005210053100541005510056100571005810059100601006110062100631006410065100661006710068100691007010071100721007310074100751007610077100781007910080100811008210083100841008510086100871008810089100901009110092100931009410095100961009710098100991010010101101021010310104101051010610107101081010910110101111011210113101141011510116101171011810119101201012110122101231012410125101261012710128101291013010131101321013310134101351013610137101381013910140101411014210143101441014510146101471014810149101501015110152101531015410155101561015710158101591016010161101621016310164101651016610167101681016910170101711017210173101741017510176101771017810179101801018110182101831018410185101861018710188101891019010191101921019310194101951019610197101981019910200102011020210203102041020510206102071020810209102101021110212102131021410215102161021710218102191022010221102221022310224102251022610227102281022910230102311023210233102341023510236102371023810239102401024110242102431024410245102461024710248102491025010251102521025310254102551025610257102581025910260102611026210263102641026510266102671026810269102701027110272102731027410275102761027710278102791028010281102821028310284102851028610287102881028910290102911029210293102941029510296102971029810299103001030110302103031030410305103061030710308103091031010311103121031310314103151031610317103181031910320103211032210323103241032510326103271032810329103301033110332103331033410335103361033710338103391034010341103421034310344103451034610347103481034910350103511035210353103541035510356103571035810359103601036110362103631036410365103661036710368103691037010371103721037310374103751037610377103781037910380103811038210383103841038510386103871038810389103901039110392103931039410395103961039710398103991040010401104021040310404104051040610407104081040910410104111041210413104141041510416104171041810419104201042110422104231042410425104261042710428104291043010431104321043310434104351043610437104381043910440104411044210443104441044510446104471044810449104501045110452104531045410455104561045710458104591046010461104621046310464104651046610467104681046910470104711047210473104741047510476104771047810479104801048110482104831048410485104861048710488104891049010491104921049310494104951049610497104981049910500105011050210503105041050510506105071050810509105101051110512105131051410515105161051710518105191052010521105221052310524105251052610527105281052910530105311053210533105341053510536105371053810539105401054110542105431054410545105461054710548105491055010551105521055310554105551055610557105581055910560105611056210563105641056510566105671056810569105701057110572105731057410575105761057710578105791058010581105821058310584105851058610587105881058910590105911059210593105941059510596105971059810599106001060110602106031060410605106061060710608106091061010611106121061310614106151061610617106181061910620106211062210623106241062510626106271062810629106301063110632106331063410635106361063710638106391064010641106421064310644106451064610647106481064910650106511065210653106541065510656106571065810659106601066110662106631066410665106661066710668106691067010671106721067310674106751067610677106781067910680106811068210683106841068510686106871068810689106901069110692106931069410695106961069710698106991070010701107021070310704107051070610707107081070910710107111071210713107141071510716107171071810719107201072110722107231072410725107261072710728107291073010731107321073310734107351073610737107381073910740107411074210743107441074510746107471074810749107501075110752107531075410755107561075710758107591076010761107621076310764107651076610767107681076910770107711077210773107741077510776107771077810779107801078110782107831078410785107861078710788107891079010791107921079310794107951079610797107981079910800108011080210803108041080510806108071080810809108101081110812108131081410815108161081710818108191082010821108221082310824108251082610827108281082910830108311083210833108341083510836108371083810839108401084110842108431084410845108461084710848108491085010851108521085310854108551085610857108581085910860108611086210863108641086510866108671086810869108701087110872108731087410875108761087710878108791088010881108821088310884108851088610887108881088910890108911089210893108941089510896108971089810899109001090110902109031090410905109061090710908109091091010911109121091310914109151091610917109181091910920109211092210923109241092510926109271092810929109301093110932109331093410935109361093710938109391094010941109421094310944109451094610947109481094910950109511095210953109541095510956109571095810959109601096110962109631096410965109661096710968109691097010971109721097310974109751097610977109781097910980109811098210983109841098510986109871098810989109901099110992109931099410995109961099710998109991100011001110021100311004110051100611007110081100911010110111101211013110141101511016110171101811019110201102111022110231102411025110261102711028110291103011031110321103311034110351103611037110381103911040110411104211043110441104511046110471104811049110501105111052110531105411055110561105711058110591106011061110621106311064110651106611067110681106911070110711107211073110741107511076110771107811079110801108111082110831108411085110861108711088110891109011091110921109311094110951109611097110981109911100111011110211103111041110511106111071110811109111101111111112111131111411115111161111711118111191112011121111221112311124111251112611127111281112911130111311113211133111341113511136111371113811139111401114111142111431114411145111461114711148111491115011151111521115311154111551115611157111581115911160111611116211163111641116511166111671116811169111701117111172111731117411175111761117711178111791118011181111821118311184111851118611187111881118911190111911119211193111941119511196111971119811199112001120111202112031120411205112061120711208112091121011211112121121311214112151121611217112181121911220112211122211223112241122511226112271122811229112301123111232112331123411235112361123711238112391124011241112421124311244112451124611247112481124911250112511125211253112541125511256112571125811259112601126111262112631126411265112661126711268112691127011271112721127311274112751127611277112781127911280112811128211283112841128511286112871128811289112901129111292112931129411295112961129711298112991130011301113021130311304113051130611307113081130911310113111131211313113141131511316113171131811319113201132111322113231132411325113261132711328113291133011331113321133311334113351133611337113381133911340113411134211343113441134511346113471134811349113501135111352113531135411355113561135711358113591136011361113621136311364113651136611367113681136911370113711137211373113741137511376113771137811379113801138111382113831138411385113861138711388113891139011391113921139311394113951139611397113981139911400114011140211403114041140511406114071140811409114101141111412114131141411415114161141711418114191142011421114221142311424114251142611427114281142911430114311143211433114341143511436114371143811439114401144111442114431144411445114461144711448114491145011451114521145311454114551145611457114581145911460114611146211463114641146511466114671146811469114701147111472114731147411475114761147711478114791148011481114821148311484114851148611487114881148911490114911149211493114941149511496114971149811499115001150111502115031150411505115061150711508115091151011511115121151311514115151151611517115181151911520115211152211523115241152511526115271152811529115301153111532115331153411535115361153711538115391154011541115421154311544115451154611547115481154911550115511155211553115541155511556115571155811559115601156111562115631156411565115661156711568115691157011571115721157311574115751157611577115781157911580115811158211583115841158511586115871158811589115901159111592115931159411595115961159711598115991160011601116021160311604116051160611607116081160911610116111161211613116141161511616116171161811619116201162111622116231162411625116261162711628116291163011631116321163311634116351163611637116381163911640116411164211643116441164511646116471164811649116501165111652116531165411655116561165711658116591166011661116621166311664116651166611667116681166911670116711167211673116741167511676116771167811679116801168111682116831168411685116861168711688116891169011691116921169311694116951169611697116981169911700117011170211703117041170511706117071170811709117101171111712117131171411715117161171711718117191172011721117221172311724117251172611727117281172911730117311173211733117341173511736117371173811739117401174111742117431174411745117461174711748117491175011751117521175311754117551175611757117581175911760117611176211763117641176511766117671176811769117701177111772117731177411775117761177711778117791178011781117821178311784117851178611787117881178911790117911179211793117941179511796117971179811799118001180111802118031180411805118061180711808118091181011811118121181311814118151181611817118181181911820118211182211823118241182511826118271182811829118301183111832118331183411835118361183711838118391184011841118421184311844118451184611847118481184911850118511185211853118541185511856118571185811859118601186111862118631186411865118661186711868118691187011871118721187311874118751187611877118781187911880118811188211883118841188511886118871188811889118901189111892118931189411895118961189711898118991190011901119021190311904119051190611907119081190911910119111191211913119141191511916119171191811919119201192111922119231192411925119261192711928119291193011931119321193311934119351193611937119381193911940119411194211943119441194511946119471194811949119501195111952119531195411955119561195711958119591196011961119621196311964119651196611967119681196911970119711197211973119741197511976119771197811979119801198111982119831198411985119861198711988119891199011991119921199311994119951199611997119981199912000120011200212003120041200512006120071200812009120101201112012120131201412015120161201712018120191202012021120221202312024120251202612027120281202912030120311203212033120341203512036120371203812039120401204112042120431204412045120461204712048120491205012051120521205312054120551205612057120581205912060120611206212063120641206512066120671206812069120701207112072120731207412075120761207712078120791208012081120821208312084120851208612087120881208912090120911209212093120941209512096120971209812099121001210112102121031210412105121061210712108121091211012111121121211312114121151211612117121181211912120121211212212123121241212512126121271212812129121301213112132121331213412135121361213712138121391214012141121421214312144121451214612147121481214912150121511215212153121541215512156121571215812159121601216112162121631216412165121661216712168121691217012171121721217312174121751217612177121781217912180121811218212183121841218512186121871218812189121901219112192121931219412195121961219712198121991220012201122021220312204122051220612207122081220912210122111221212213122141221512216122171221812219122201222112222122231222412225122261222712228122291223012231122321223312234122351223612237122381223912240122411224212243122441224512246122471224812249122501225112252122531225412255122561225712258122591226012261122621226312264122651226612267122681226912270122711227212273122741227512276122771227812279122801228112282122831228412285122861228712288122891229012291122921229312294122951229612297122981229912300123011230212303123041230512306123071230812309123101231112312123131231412315123161231712318123191232012321123221232312324123251232612327123281232912330123311233212333123341233512336123371233812339123401234112342123431234412345123461234712348123491235012351123521235312354123551235612357123581235912360123611236212363123641236512366123671236812369123701237112372123731237412375123761237712378123791238012381123821238312384123851238612387123881238912390123911239212393123941239512396123971239812399124001240112402124031240412405124061240712408124091241012411124121241312414124151241612417124181241912420124211242212423124241242512426124271242812429124301243112432124331243412435124361243712438124391244012441124421244312444124451244612447124481244912450124511245212453124541245512456124571245812459124601246112462124631246412465124661246712468124691247012471124721247312474124751247612477124781247912480124811248212483124841248512486124871248812489124901249112492124931249412495124961249712498124991250012501125021250312504125051250612507125081250912510125111251212513125141251512516125171251812519125201252112522125231252412525125261252712528125291253012531125321253312534125351253612537125381253912540125411254212543125441254512546125471254812549125501255112552125531255412555125561255712558125591256012561125621256312564125651256612567125681256912570125711257212573125741257512576125771257812579125801258112582125831258412585125861258712588125891259012591125921259312594125951259612597125981259912600126011260212603126041260512606126071260812609126101261112612126131261412615126161261712618126191262012621126221262312624126251262612627126281262912630126311263212633126341263512636126371263812639126401264112642126431264412645126461264712648126491265012651126521265312654126551265612657126581265912660126611266212663126641266512666126671266812669126701267112672126731267412675126761267712678126791268012681126821268312684126851268612687126881268912690126911269212693126941269512696126971269812699127001270112702127031270412705127061270712708127091271012711127121271312714127151271612717127181271912720127211272212723127241272512726127271272812729127301273112732127331273412735127361273712738127391274012741127421274312744127451274612747127481274912750127511275212753127541275512756127571275812759127601276112762127631276412765127661276712768127691277012771127721277312774127751277612777127781277912780127811278212783127841278512786127871278812789127901279112792127931279412795127961279712798127991280012801128021280312804128051280612807128081280912810128111281212813128141281512816128171281812819128201282112822128231282412825128261282712828128291283012831128321283312834128351283612837128381283912840128411284212843128441284512846128471284812849128501285112852128531285412855128561285712858128591286012861128621286312864128651286612867128681286912870128711287212873128741287512876128771287812879128801288112882128831288412885128861288712888128891289012891128921289312894128951289612897128981289912900129011290212903129041290512906129071290812909129101291112912129131291412915129161291712918129191292012921129221292312924129251292612927129281292912930129311293212933129341293512936129371293812939129401294112942129431294412945129461294712948129491295012951129521295312954129551295612957129581295912960129611296212963129641296512966129671296812969129701297112972129731297412975129761297712978129791298012981129821298312984129851298612987129881298912990129911299212993129941299512996129971299812999130001300113002130031300413005130061300713008130091301013011130121301313014130151301613017130181301913020130211302213023130241302513026130271302813029130301303113032130331303413035130361303713038130391304013041130421304313044130451304613047130481304913050130511305213053130541305513056130571305813059130601306113062130631306413065130661306713068130691307013071130721307313074130751307613077130781307913080130811308213083130841308513086130871308813089130901309113092130931309413095130961309713098130991310013101131021310313104131051310613107131081310913110131111311213113131141311513116131171311813119131201312113122131231312413125131261312713128131291313013131131321313313134131351313613137131381313913140131411314213143131441314513146131471314813149131501315113152131531315413155131561315713158131591316013161131621316313164131651316613167131681316913170131711317213173131741317513176131771317813179131801318113182131831318413185131861318713188131891319013191131921319313194131951319613197131981319913200132011320213203132041320513206132071320813209132101321113212132131321413215132161321713218132191322013221132221322313224132251322613227132281322913230132311323213233132341323513236132371323813239132401324113242132431324413245132461324713248132491325013251132521325313254132551325613257132581325913260132611326213263132641326513266132671326813269132701327113272132731327413275132761327713278132791328013281132821328313284132851328613287132881328913290132911329213293132941329513296132971329813299133001330113302133031330413305133061330713308133091331013311133121331313314133151331613317133181331913320133211332213323133241332513326133271332813329133301333113332133331333413335133361333713338133391334013341133421334313344133451334613347133481334913350133511335213353133541335513356133571335813359133601336113362133631336413365133661336713368133691337013371133721337313374133751337613377133781337913380133811338213383133841338513386133871338813389133901339113392133931339413395133961339713398133991340013401134021340313404134051340613407134081340913410134111341213413134141341513416134171341813419134201342113422134231342413425134261342713428134291343013431134321343313434134351343613437134381343913440134411344213443134441344513446134471344813449134501345113452134531345413455134561345713458134591346013461134621346313464134651346613467134681346913470134711347213473134741347513476134771347813479134801348113482134831348413485134861348713488134891349013491134921349313494134951349613497134981349913500135011350213503135041350513506135071350813509135101351113512135131351413515135161351713518135191352013521135221352313524135251352613527135281352913530135311353213533135341353513536135371353813539135401354113542135431354413545135461354713548135491355013551135521355313554135551355613557135581355913560135611356213563135641356513566135671356813569135701357113572135731357413575135761357713578135791358013581135821358313584135851358613587135881358913590135911359213593135941359513596135971359813599136001360113602136031360413605136061360713608136091361013611136121361313614136151361613617136181361913620136211362213623136241362513626136271362813629136301363113632136331363413635136361363713638136391364013641136421364313644136451364613647136481364913650136511365213653136541365513656136571365813659136601366113662136631366413665136661366713668136691367013671136721367313674136751367613677136781367913680136811368213683136841368513686136871368813689136901369113692136931369413695136961369713698136991370013701137021370313704137051370613707137081370913710137111371213713137141371513716137171371813719137201372113722137231372413725137261372713728137291373013731137321373313734137351373613737137381373913740137411374213743137441374513746137471374813749137501375113752137531375413755137561375713758137591376013761137621376313764137651376613767137681376913770137711377213773137741377513776137771377813779137801378113782137831378413785137861378713788137891379013791137921379313794137951379613797137981379913800138011380213803138041380513806138071380813809138101381113812138131381413815138161381713818138191382013821138221382313824138251382613827138281382913830138311383213833138341383513836138371383813839138401384113842138431384413845138461384713848138491385013851138521385313854138551385613857138581385913860138611386213863138641386513866138671386813869138701387113872138731387413875138761387713878138791388013881138821388313884138851388613887138881388913890138911389213893138941389513896138971389813899139001390113902139031390413905139061390713908139091391013911139121391313914139151391613917139181391913920139211392213923139241392513926139271392813929139301393113932139331393413935139361393713938139391394013941139421394313944139451394613947139481394913950139511395213953139541395513956139571395813959139601396113962139631396413965139661396713968139691397013971139721397313974139751397613977139781397913980139811398213983139841398513986139871398813989139901399113992139931399413995139961399713998139991400014001140021400314004140051400614007140081400914010140111401214013140141401514016140171401814019140201402114022140231402414025140261402714028140291403014031140321403314034140351403614037140381403914040140411404214043140441404514046140471404814049140501405114052140531405414055140561405714058140591406014061140621406314064140651406614067140681406914070140711407214073140741407514076140771407814079140801408114082140831408414085140861408714088140891409014091140921409314094140951409614097140981409914100141011410214103141041410514106141071410814109141101411114112141131411414115141161411714118141191412014121141221412314124141251412614127141281412914130141311413214133141341413514136141371413814139141401414114142141431414414145141461414714148141491415014151141521415314154141551415614157141581415914160141611416214163141641416514166141671416814169141701417114172141731417414175141761417714178141791418014181141821418314184141851418614187141881418914190141911419214193141941419514196141971419814199142001420114202142031420414205142061420714208142091421014211142121421314214142151421614217142181421914220142211422214223142241422514226142271422814229142301423114232142331423414235142361423714238142391424014241142421424314244142451424614247142481424914250142511425214253142541425514256142571425814259142601426114262142631426414265142661426714268142691427014271142721427314274142751427614277142781427914280142811428214283142841428514286142871428814289142901429114292142931429414295142961429714298142991430014301143021430314304143051430614307143081430914310143111431214313143141431514316143171431814319143201432114322143231432414325143261432714328143291433014331143321433314334143351433614337143381433914340143411434214343143441434514346143471434814349143501435114352143531435414355143561435714358143591436014361143621436314364143651436614367143681436914370143711437214373143741437514376143771437814379143801438114382143831438414385143861438714388143891439014391143921439314394143951439614397143981439914400144011440214403144041440514406144071440814409144101441114412144131441414415144161441714418144191442014421144221442314424144251442614427144281442914430144311443214433144341443514436144371443814439144401444114442144431444414445144461444714448144491445014451144521445314454144551445614457144581445914460144611446214463144641446514466144671446814469144701447114472144731447414475144761447714478144791448014481144821448314484144851448614487144881448914490144911449214493144941449514496144971449814499145001450114502145031450414505145061450714508145091451014511145121451314514145151451614517145181451914520145211452214523145241452514526145271452814529145301453114532145331453414535145361453714538145391454014541145421454314544145451454614547145481454914550145511455214553145541455514556145571455814559145601456114562145631456414565145661456714568145691457014571145721457314574145751457614577145781457914580145811458214583145841458514586145871458814589145901459114592145931459414595145961459714598145991460014601146021460314604146051460614607146081460914610146111461214613146141461514616146171461814619146201462114622146231462414625146261462714628146291463014631146321463314634146351463614637146381463914640146411464214643146441464514646146471464814649146501465114652146531465414655146561465714658146591466014661146621466314664146651466614667146681466914670146711467214673146741467514676146771467814679146801468114682146831468414685146861468714688146891469014691146921469314694146951469614697146981469914700147011470214703147041470514706147071470814709147101471114712147131471414715147161471714718147191472014721147221472314724147251472614727147281472914730147311473214733147341473514736147371473814739147401474114742147431474414745147461474714748147491475014751147521475314754147551475614757147581475914760147611476214763147641476514766147671476814769147701477114772147731477414775147761477714778147791478014781147821478314784147851478614787147881478914790147911479214793147941479514796147971479814799148001480114802148031480414805148061480714808148091481014811148121481314814148151481614817148181481914820148211482214823148241482514826148271482814829148301483114832148331483414835148361483714838148391484014841148421484314844148451484614847148481484914850148511485214853148541485514856148571485814859148601486114862148631486414865148661486714868148691487014871148721487314874148751487614877148781487914880148811488214883148841488514886148871488814889148901489114892148931489414895148961489714898148991490014901149021490314904149051490614907149081490914910149111491214913149141491514916149171491814919149201492114922149231492414925149261492714928149291493014931149321493314934149351493614937149381493914940149411494214943149441494514946149471494814949149501495114952149531495414955149561495714958149591496014961149621496314964149651496614967149681496914970149711497214973149741497514976149771497814979149801498114982149831498414985149861498714988149891499014991149921499314994149951499614997149981499915000150011500215003150041500515006150071500815009150101501115012150131501415015150161501715018150191502015021150221502315024150251502615027150281502915030150311503215033150341503515036150371503815039150401504115042150431504415045150461504715048150491505015051150521505315054150551505615057150581505915060150611506215063150641506515066150671506815069150701507115072150731507415075150761507715078150791508015081150821508315084150851508615087150881508915090150911509215093150941509515096150971509815099151001510115102151031510415105151061510715108151091511015111151121511315114151151511615117151181511915120151211512215123151241512515126151271512815129151301513115132151331513415135151361513715138151391514015141151421514315144151451514615147151481514915150151511515215153151541515515156151571515815159151601516115162151631516415165151661516715168151691517015171151721517315174151751517615177151781517915180151811518215183151841518515186151871518815189151901519115192151931519415195151961519715198151991520015201152021520315204152051520615207152081520915210152111521215213152141521515216152171521815219152201522115222152231522415225152261522715228152291523015231152321523315234152351523615237152381523915240152411524215243152441524515246152471524815249152501525115252152531525415255152561525715258152591526015261152621526315264152651526615267152681526915270152711527215273152741527515276152771527815279152801528115282152831528415285152861528715288152891529015291152921529315294152951529615297152981529915300153011530215303153041530515306153071530815309153101531115312153131531415315153161531715318153191532015321153221532315324153251532615327153281532915330153311533215333153341533515336153371533815339153401534115342153431534415345153461534715348153491535015351153521535315354153551535615357153581535915360153611536215363153641536515366153671536815369153701537115372153731537415375153761537715378153791538015381153821538315384153851538615387153881538915390153911539215393153941539515396153971539815399154001540115402154031540415405154061540715408154091541015411154121541315414154151541615417154181541915420154211542215423154241542515426154271542815429154301543115432154331543415435154361543715438154391544015441154421544315444154451544615447154481544915450154511545215453154541545515456154571545815459154601546115462154631546415465154661546715468154691547015471154721547315474154751547615477154781547915480154811548215483154841548515486154871548815489154901549115492154931549415495154961549715498154991550015501155021550315504155051550615507155081550915510155111551215513155141551515516155171551815519155201552115522155231552415525155261552715528155291553015531155321553315534155351553615537155381553915540155411554215543155441554515546155471554815549155501555115552155531555415555155561555715558155591556015561155621556315564155651556615567155681556915570155711557215573155741557515576155771557815579155801558115582155831558415585155861558715588155891559015591155921559315594155951559615597155981559915600156011560215603156041560515606156071560815609156101561115612156131561415615156161561715618156191562015621156221562315624156251562615627156281562915630156311563215633156341563515636156371563815639156401564115642156431564415645156461564715648156491565015651156521565315654156551565615657156581565915660156611566215663156641566515666156671566815669156701567115672156731567415675156761567715678156791568015681156821568315684156851568615687156881568915690156911569215693156941569515696156971569815699157001570115702157031570415705157061570715708157091571015711157121571315714157151571615717157181571915720157211572215723157241572515726157271572815729157301573115732157331573415735157361573715738157391574015741157421574315744157451574615747157481574915750157511575215753157541575515756157571575815759157601576115762157631576415765157661576715768157691577015771157721577315774157751577615777157781577915780157811578215783157841578515786157871578815789157901579115792157931579415795157961579715798157991580015801158021580315804158051580615807158081580915810158111581215813158141581515816158171581815819158201582115822158231582415825158261582715828158291583015831158321583315834158351583615837158381583915840158411584215843158441584515846
  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. #define TxDefaultProfile_1_JSON "/Storage/OCPP/TxDefaultProfile_1.json"
  8. #define TxDefaultProfile_2_JSON "/Storage/OCPP/TxDefaultProfile_2.json"
  9. //TxProfile
  10. #define TxProfile_1_JSON "/Storage/OCPP/TxProfile_1.json"
  11. #define TxProfile_2_JSON "/Storage/OCPP/TxProfile_2.json"
  12. #define ChargingProfile_0_JSON "/Storage/OCPP/chargingprofile_0.json"
  13. #define ChargingProfile_1_JSON "/Storage/OCPP/chargingprofile_1.json"
  14. #define ChargingProfile_2_JSON "/Storage/OCPP/chargingprofile_2.json"
  15. #define AuthorizationCache_JSON "/Storage/OCPP/AuthorizationCache.json"
  16. #define LocalAuthorizationList_JSON "/Storage/OCPP/LocalAuthorizationList.json"
  17. //===================================
  18. // Define CP State constant
  19. //===================================
  20. #define CP_STATE_UNKNOWN 0
  21. #define CP_STATE_A 1
  22. #define CP_STATE_B 2
  23. #define CP_STATE_C 3
  24. #define CP_STATE_D 4
  25. #define CP_STATE_E 5
  26. #define CP_STATE_F 6
  27. struct SysConfigAndInfo *ShmSysConfigAndInfo;
  28. struct StatusCodeData *ShmStatusCodeData;
  29. struct PsuData *ShmPsuData ;
  30. struct OCPP16Data *ShmOCPP16Data;
  31. #define MACROSTR(k) #k
  32. //ConfigurationMaxKeys
  33. #define GetConfigurationMaxKeysNUM 43
  34. pthread_mutex_t lock = PTHREAD_MUTEX_INITIALIZER;
  35. char queuedata[2600] = {0};
  36. //=================================
  37. // StatusNotification cycle
  38. //=================================
  39. static int server_cycle_Status = 120;
  40. //===============================
  41. // Configuration: unknownkey
  42. //===============================
  43. static char unknownkey[10][20] = {0};
  44. static int UnknownKeynum = 0;
  45. //===============================
  46. // Gun Total Numbers
  47. //===============================
  48. static int gunTotalNumber = 0;
  49. static unsigned char gunType[4] = {0};
  50. //===============================
  51. // Local List Version
  52. //===============================
  53. static int localversion=0;
  54. static char idTagAuthorization[32] = {0};
  55. //===============================
  56. // OCPP sign variable
  57. //===============================
  58. static int server_sign = FALSE;
  59. int server_pending = FALSE;
  60. int PRE_SYS_MODE[CHAdeMO_QUANTITY+ CCS_QUANTITY + GB_QUANTITY + AC_QUANTITY];
  61. static int BootNotificationInterval = 0;
  62. static int SystemInitial = 0;//= CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY; // System Boot UP
  63. //===============================
  64. // OCPP auth variable
  65. //===============================
  66. static int authorizeRetryTimes = 0; //number of Retry times
  67. //===============================
  68. // OCPP other variables
  69. //===============================
  70. //int isUpdateRequest = FALSE;
  71. static int HeartBeatWaitTime = 10;
  72. static int FirstHeartBeat = 0;
  73. static int FirmwareStatusNotificationStatus = FIRMWARE_STATUS_IDLE; // Idle
  74. static int DiagnosticsStatusNotificationStatus = DIAGNOSTIC_STATUS_IDLE; // Idle
  75. static char CurrentChargingProfileScheduleStr[30] = {0};
  76. //========================================
  77. // OCPP status/previous related variables
  78. //========================================
  79. static int GunStatusInterval = 10;
  80. static int statusModeChage[CHAdeMO_QUANTITY+ CCS_QUANTITY + GB_QUANTITY + AC_QUANTITY] = {FALSE};
  81. static int ChademoPreviousSystemStatus[CHAdeMO_QUANTITY];
  82. static int CcsPreviousSystemStatus[CCS_QUANTITY];
  83. static int GbPreviousSystemStatus[GB_QUANTITY];
  84. static int AcPreviousSystemStatus[AC_QUANTITY];
  85. static int ChademoPreviousConnectorPlugIn[CHAdeMO_QUANTITY];
  86. static int CcsPreviousConnectorPlugIn[CCS_QUANTITY];
  87. static int GbPreviousConnectorPlugIn[GB_QUANTITY];
  88. static int AcPreviousConnectorPlugIn[AC_QUANTITY];
  89. static int TransactionMessageAttemptsValue = 0;
  90. static int TransactionMessageRetryIntervalValue = 0;
  91. static int TempMeterValueInterval = 0;
  92. static struct OCPPAuthLocalElemet
  93. {
  94. int listVersionInt;
  95. char idTagstr[20];
  96. char parentIdTag[20];
  97. char expiryDate[30];
  98. char idTagstatus[16];
  99. }idTagQuery;
  100. //=============================================
  101. // OCPP HeartBeat Response Not Receive Counts
  102. //============================================
  103. static int HeartBeatWithNOResponse = 0;
  104. static int HeartBeatCountPerHour = 0;
  105. extern void ChageWebSocketPingInterval(int WebSocketPingInterval);
  106. extern int GetTransactionQueueNum(void);
  107. extern pthread_mutex_t mutex1;
  108. extern struct Charger_Info Charger;
  109. extern sqlite3 *db;
  110. int TransactionMessageAttemptsGet(void);
  111. int TransactionMessageRetryIntervalGet(void);
  112. int GetOcppConnStatus(void);
  113. void SetOcppConnStatus(uint8_t status);
  114. int setKeyValue(char *key, char *value);
  115. void OCPP_get_TableAuthlocalAllData(void);
  116. void processUnkownKey(void);
  117. struct StructOCPPMeterValue
  118. {
  119. unsigned char TimeStamp[28];
  120. struct StructSampledValue SampledValue[10];
  121. };
  122. struct ClientTime
  123. {
  124. unsigned int Heartbeat;
  125. unsigned int StatusNotification[CHAdeMO_QUANTITY+ CCS_QUANTITY + GB_QUANTITY + AC_QUANTITY];
  126. unsigned int StartTransaction;
  127. unsigned int StopTransaction;
  128. unsigned int MeterValues[CHAdeMO_QUANTITY+ CCS_QUANTITY + GB_QUANTITY + AC_QUANTITY];
  129. }clientTime;
  130. typedef union
  131. {
  132. //Operations Initiated by Central System
  133. unsigned char CsMsgValue[CHAdeMO_QUANTITY+ CCS_QUANTITY + GB_QUANTITY + AC_QUANTITY];
  134. struct
  135. {
  136. //CsMsgValue[0]
  137. unsigned char StatusNotificationReq :1; //bit 0,
  138. unsigned char StatusNotificationConf :1; //bit 0,
  139. unsigned char :6; //bit 2~7
  140. }bits[CHAdeMO_QUANTITY+ CCS_QUANTITY + GB_QUANTITY + AC_QUANTITY];
  141. }CpinitiateMsg;
  142. CpinitiateMsg cpinitateMsg;
  143. //==========================================
  144. // Init all Enumeration & Mapping String
  145. //==========================================
  146. /*ChargePointErrorCode*/
  147. typedef enum {
  148. ConnectorLockFailure,
  149. EVCommunicationError,
  150. GroundFailure,
  151. HighTemperature,
  152. InternalError,
  153. LocalListConflict,
  154. NoError,
  155. OtherError,
  156. OverCurrentFailure,
  157. OverVoltage,
  158. PowerMeterFailure,
  159. PowerSwitchFailure,
  160. ReaderFailure,
  161. ResetFailure,
  162. UnderVoltage,
  163. WeakSignal
  164. } ChargePointErrorCode;
  165. #if 0
  166. static char *ChargePointErrorCodeStr[] = {
  167. MACROSTR(ConnectorLockFailure),
  168. MACROSTR(EVCommunicationError),
  169. MACROSTR(GroundFailure),
  170. MACROSTR(HighTemperature),
  171. MACROSTR(InternalError),
  172. MACROSTR(LocalListConflict),
  173. MACROSTR(NoError),
  174. MACROSTR(OtherError),
  175. MACROSTR(OverCurrentFailure),
  176. MACROSTR(OverVoltage),
  177. MACROSTR(PowerMeterFailure),
  178. MACROSTR(PowerSwitchFailure),
  179. MACROSTR(ReaderFailure),
  180. MACROSTR(ResetFailure),
  181. MACROSTR(UnderVoltage),
  182. MACROSTR(WeakSignal)
  183. };
  184. #endif
  185. /*ChargePointStatus*/
  186. typedef enum {
  187. Available =0,
  188. Preparing,
  189. Charging,
  190. SuspendedEVSE,
  191. SuspendedEV,
  192. Finishing,
  193. Reserved,
  194. Unavailable,
  195. Faulted
  196. } ChargePointStatus;
  197. static char * ChargePointStatusStr[] = {
  198. MACROSTR(Available),
  199. MACROSTR(Preparing),
  200. MACROSTR(Charging),
  201. MACROSTR(SuspendedEVSE),
  202. MACROSTR(SuspendedEV),
  203. MACROSTR(Finishing),
  204. MACROSTR(Reserved),
  205. MACROSTR(Unavailable),
  206. MACROSTR(Faulted)
  207. };
  208. /*AvailabilityType*/
  209. typedef enum {
  210. RegistrationStatus_Accepted,
  211. RegistrationStatus_Pending,
  212. RegistrationStatus_Rejected
  213. } RegistrationStatus;
  214. static char *RegistrationStatusStr[] = {
  215. MACROSTR(Accepted),
  216. MACROSTR(Pending),
  217. MACROSTR(Rejected)
  218. };
  219. /*AvailabilityType*/
  220. typedef enum {
  221. Inoperative,
  222. Operative
  223. } AvailabilityType;
  224. static char *AvailabilityTypeStr[] = {
  225. MACROSTR(Inoperative),
  226. MACROSTR(Operative)
  227. };
  228. /*AvailabilityStatus*/
  229. typedef enum {
  230. Accepted,
  231. Rejected,
  232. Scheduled
  233. } AvailabilityStatus;
  234. static char *AvailabilityStatusStr[] = {
  235. MACROSTR(Accepted),
  236. MACROSTR(Rejected),
  237. MACROSTR(Scheduled)
  238. };
  239. /*ConfigurationStatus*/
  240. typedef enum {
  241. ConfigurationStatus_Accepted,
  242. ConfigurationStatus_Rejected,
  243. RebootRequired,
  244. NotSupported
  245. } ConfigurationStatus;
  246. static char *ConfigurationStatusStr[] = {
  247. MACROSTR(Accepted),
  248. MACROSTR(Rejected),
  249. MACROSTR(RebootRequired),
  250. MACROSTR(NotSupported)
  251. };
  252. /*ClearCacheStatus*/
  253. typedef enum {
  254. ClearCacheStatus_Accepted,
  255. ClearCacheStatus_Rejected
  256. } ClearCacheStatus;
  257. static char *ClearCacheStatusStr[] = {
  258. MACROSTR(Accepted),
  259. MACROSTR(Rejected)
  260. };
  261. /*ChargingProfilePurposeType*/
  262. typedef enum {
  263. ChargePointMaxProfile,
  264. TxDefaultProfile,
  265. TxProfile
  266. } ChargingProfilePurposeType;
  267. static char *ChargingProfilePurposeTypeStr[] = {
  268. MACROSTR(ChargePointMaxProfile),
  269. MACROSTR(TxDefaultProfile),
  270. MACROSTR(TxProfile)
  271. };
  272. /*ChargingProfileStatus*/
  273. typedef enum {
  274. ChargingProfileStatus_Accepted,
  275. ChargingProfileStatus_Rejected,
  276. ChargingProfileStatus_NotSupported
  277. } ChargingProfileStatus;
  278. static char *ChargingProfileStatusStr[] = {
  279. MACROSTR(Accepted),
  280. MACROSTR(Rejected),
  281. MACROSTR(NotSupported)
  282. };
  283. /*ClearChargingProfileStatus*/
  284. typedef enum {
  285. ClearChargingProfileStatus_Accepted,
  286. ClearChargingProfileStatus_Unknown
  287. } ClearChargingProfileStatus;
  288. static char *ClearChargingProfileStatusStr[] = {
  289. MACROSTR(Accepted),
  290. MACROSTR(Unknown)
  291. };
  292. /*GetCompositeScheduleStatus*/
  293. typedef enum {
  294. GetCompositeScheduleStatus_Accepted,
  295. GetCompositeScheduleStatus_Rejected
  296. } GetCompositeScheduleStatus;
  297. static char *GetCompositeScheduleStatusStr[] = {
  298. MACROSTR(Accepted),
  299. MACROSTR(Rejected)
  300. };
  301. /*ChargingRateUnitType*/
  302. typedef enum {
  303. ChargingRateUnitType_W,
  304. ChargingRateUnitType_A
  305. } ChargingRateUnitType;
  306. /*AuthorizationStatus*/
  307. typedef enum {
  308. AuthorizationStatus_Accepted ,
  309. AuthorizationStatus_Blocked ,
  310. AuthorizationStatus_Expired ,
  311. AuthorizationStatus_Invalid ,
  312. AuthorizationStatus_ConcurrentTx
  313. } AuthorizationStatus;
  314. /*UpdateType*/
  315. typedef enum {
  316. Differential ,
  317. Full
  318. } UpdateType;
  319. static char *UpdateTypeStr[] = {
  320. MACROSTR(Differential),
  321. MACROSTR(Full)
  322. };
  323. /*UpdateStatus*/
  324. typedef enum {
  325. UpdateStatus_Accepted ,
  326. UpdateStatus_Failed ,
  327. UpdateStatus_NotSupported ,
  328. UpdateStatus_VersionMismatch
  329. } UpdateStatus;
  330. static char *UpdateStatusStr[] = {
  331. MACROSTR(Accepted),
  332. MACROSTR(Failed),
  333. MACROSTR(NotSupported),
  334. MACROSTR(VersionMismatch)
  335. };
  336. /*RemoteStartStopStatus*/
  337. typedef enum {
  338. RemoteStartStopStatus_Accepted,
  339. RemoteStartStopStatus_Rejected
  340. } RemoteStartStopStatus;
  341. static char *RemoteStartStopStatusStr[] = {
  342. MACROSTR(Accepted),
  343. MACROSTR(Rejected)
  344. };
  345. /*ReservationStatus*/
  346. typedef enum {
  347. ReservationStatus_Accepted,
  348. ReservationStatus_Faulted,
  349. ReservationStatus_Occupied,
  350. ReservationStatus_Rejected,
  351. ReservationStatus_Unavailable
  352. } ReservationStatus;
  353. static char *ReservationStatusStr[] = {
  354. MACROSTR(Accepted),
  355. MACROSTR(Faulted),
  356. MACROSTR(Occupied),
  357. MACROSTR(Rejected),
  358. MACROSTR(Unavailable)
  359. };
  360. /*ResetType*/
  361. typedef enum {
  362. Hard,
  363. Soft
  364. } ResetType;
  365. static char *ResetTypeStr[] = {
  366. MACROSTR(Hard),
  367. MACROSTR(Soft)
  368. };
  369. /*ResetStatus*/
  370. typedef enum {
  371. ResetStatus_Accepted,
  372. ResetStatus_Rejected
  373. } ResetStatus;
  374. static char *ResetStatusStr[] = {
  375. MACROSTR(Accepted),
  376. MACROSTR(Rejected)
  377. };
  378. /*DiagnosticsStatus*/
  379. typedef enum {
  380. DiagnosticsStatus_Idle,
  381. DiagnosticsStatus_Uploaded,
  382. DiagnosticsStatus_UploadFailed,
  383. DiagnosticsStatus_Uploading
  384. } DiagnosticsStatus;
  385. static char * DiagnosticsStatusStr[] = {
  386. MACROSTR(Idle),
  387. MACROSTR(Uploaded),
  388. MACROSTR(UploadFailed),
  389. MACROSTR(Uploading)
  390. };
  391. /*FirmwareStatus*/
  392. typedef enum {
  393. FirmwareStatus_Downloaded,
  394. FirmwareStatus_DownloadFailed,
  395. FirmwareStatus_Downloading,
  396. FirmwareStatus_Idle,
  397. FirmwareStatus_InstallationFailed,
  398. FirmwareStatus_Installing,
  399. FirmwareStatus_Installed
  400. } FirmwareStatus;
  401. static char * FirmwareStatusStr[] = {
  402. MACROSTR(Downloaded),
  403. MACROSTR(DownloadFailed),
  404. MACROSTR(Downloading),
  405. MACROSTR(Idle),
  406. MACROSTR(InstallationFailed),
  407. MACROSTR(Installing),
  408. MACROSTR(Installed)
  409. };
  410. /*MessageTrigger*/
  411. typedef enum {
  412. BootNotification,
  413. DiagnosticsStatusNotification,
  414. FirmwareStatusNotification,
  415. Heartbeat,
  416. MeterValues,
  417. StatusNotification
  418. } MessageTrigger;
  419. static char * MessageTriggerStr[] = {
  420. MACROSTR(BootNotification),
  421. MACROSTR(DiagnosticsStatusNotification),
  422. MACROSTR(FirmwareStatusNotification),
  423. MACROSTR(Heartbeat),
  424. MACROSTR(MeterValues),
  425. MACROSTR(StatusNotification)
  426. };
  427. /*TriggerMessageStatus*/
  428. typedef enum {
  429. TriggerMessageStatus_Accepted ,
  430. TriggerMessageStatus_Rejected ,
  431. TriggerMessageStatus_NotImplemented
  432. } TriggerMessageStatus;
  433. static char * TriggerMessageStatusStr[] = {
  434. MACROSTR(Accepted),
  435. MACROSTR(Rejected),
  436. MACROSTR(NotImplemented)
  437. };
  438. /*UnlockStatus*/
  439. typedef enum {
  440. Unlocked,
  441. UnlockFailed,
  442. UnlockStatus_NotSupported
  443. } UnlockStatus;
  444. static char * UnlockStatusStr[] = {
  445. MACROSTR(Unlocked),
  446. MACROSTR(UnlockFailed),
  447. MACROSTR(NotSupported)
  448. };
  449. /*StopTransactionReason*/
  450. typedef enum {
  451. EmergencyStop,
  452. EVDisconnected,
  453. HardReset,
  454. Local,
  455. Other,
  456. PowerLoss,
  457. Reboot,
  458. Remote,
  459. SoftReset,
  460. UnlockCommand,
  461. DeAuthorized
  462. } StopTransactionReason;
  463. #if 0
  464. static char * StopTransactionReasonStr[] = {
  465. MACROSTR(EmergencyStop),
  466. MACROSTR(EVDisconnected),
  467. MACROSTR(HardReset),
  468. MACROSTR(Local),
  469. MACROSTR(Other),
  470. MACROSTR(PowerLoss),
  471. MACROSTR(Reboot),
  472. MACROSTR(Remote),
  473. MACROSTR(SoftReset),
  474. MACROSTR(UnlockCommand),
  475. MACROSTR(DeAuthorized)
  476. };
  477. #endif
  478. /*CancelReservationStatus*/
  479. typedef enum {
  480. CancelReservationStatus_Accepted,
  481. CancelReservationStatus_Rejected
  482. } CancelReservationStatus;
  483. static char * CancelReservationStatusStr[] = {
  484. MACROSTR(Accepted),
  485. MACROSTR(Rejected)
  486. };
  487. /*ReadingContext*/
  488. typedef enum {
  489. ReadingContext_Interruption_Begin,
  490. ReadingContext_Interruption_End,
  491. ReadingContext_Other,
  492. ReadingContext_Sample_Clock,
  493. ReadingContext_Sample_Periodic ,
  494. ReadingContext_Transaction_Begin ,
  495. ReadingContext_Transaction_End,
  496. ReadingContext_Trigger
  497. } ReadingContext;
  498. static char * ReadingContextStr[] = {
  499. MACROSTR(Interruption.Begin),
  500. MACROSTR(Interruption.End),
  501. MACROSTR(Other),
  502. MACROSTR(Sample.Clock),
  503. MACROSTR(Sample.Periodic),
  504. MACROSTR(Transaction.Begin),
  505. MACROSTR(Transaction.End),
  506. MACROSTR(Trigger)
  507. };
  508. /*ValueFormat*/
  509. typedef enum {
  510. Raw,
  511. SignedData
  512. } ValueFormat;
  513. static char * ValueFormatStr[] = {
  514. MACROSTR(Raw),
  515. MACROSTR(SignedData)
  516. };
  517. /*Measurand*/
  518. typedef enum {
  519. Current_Export ,
  520. Current_Import,
  521. Current_Offered,
  522. Energy_Active_Export_Register,
  523. Energy_Active_Import_Register,
  524. Energy_Reactive_Export_Register,
  525. Energy_Reactive_Import_Register,
  526. Energy_Active_Export_Interval,
  527. Energy_Active_Import_Interval,
  528. Energy_Reactive_Export_Interval,
  529. Energy_Reactive_Import_Interval,
  530. Frequency,
  531. Power_Active_Export ,
  532. Power_Active_Import,
  533. Power_Factor,
  534. Power_Offered,
  535. Power_Reactive_Export,
  536. Power_Reactive_Import,
  537. RPM,
  538. SoC,
  539. Temperature ,
  540. Voltage
  541. } Measurand;
  542. static char * MeasurandStr[] = {
  543. MACROSTR(Current.Export),
  544. MACROSTR(Current.Import),
  545. MACROSTR(Current.Offered),
  546. MACROSTR(Energy.Active.Export.Register),
  547. MACROSTR(Energy.Active.Import.Register),
  548. MACROSTR(Energy.Reactive.Export.Register),
  549. MACROSTR(Energy.Reactive.Import.Register),
  550. MACROSTR(Energy.Active.Export.Interval),
  551. MACROSTR(Energy.Active.Import.Interval),
  552. MACROSTR(Energy.Reactive.Export.Interval),
  553. MACROSTR(Energy.Reactive.Import.Interval),
  554. MACROSTR(Frequency),
  555. MACROSTR(Power.Active.Export),
  556. MACROSTR(Power.Active.Import),
  557. MACROSTR(Power.Factor),
  558. MACROSTR(Power.Offered),
  559. MACROSTR(Power.Reactive.ExportMACROSTR),
  560. MACROSTR(Power.Reactive.Import),
  561. MACROSTR(RPM),
  562. MACROSTR(SoC),
  563. MACROSTR(Temperature),
  564. MACROSTR(Voltage)
  565. };
  566. /*Location*/
  567. typedef enum {
  568. Location_Body,
  569. Location_Cable,
  570. Location_EV,
  571. Location_Inlet ,
  572. Location_Outlet
  573. } Location;
  574. static char * LocationStr[] = {
  575. MACROSTR(Body),
  576. MACROSTR(Cable),
  577. MACROSTR(EV),
  578. MACROSTR(Inlet),
  579. MACROSTR(Outlet)
  580. };
  581. /*Phase*/
  582. typedef enum {
  583. L1,
  584. L2,
  585. L3,
  586. N,
  587. L1_N,
  588. L2_N,
  589. L3_N,
  590. L1_L2,
  591. L2_L3,
  592. L3_L1
  593. } Phase;
  594. static char * PhaseStr[] = {
  595. MACROSTR(L1),
  596. MACROSTR(L2),
  597. MACROSTR(L3),
  598. MACROSTR(N),
  599. MACROSTR(L1-N),
  600. MACROSTR(L2-N),
  601. MACROSTR(L3-N),
  602. MACROSTR(L1-L2),
  603. MACROSTR(L2-L3),
  604. MACROSTR(L3-L1)
  605. };
  606. /*UnitOfMeasure*/
  607. typedef enum {
  608. UnitOfMeasure_Wh,
  609. UnitOfMeasure_kWh ,
  610. UnitOfMeasure_varh ,
  611. UnitOfMeasure_kvarh ,
  612. UnitOfMeasure_W ,
  613. UnitOfMeasure_kW ,
  614. UnitOfMeasure_VA ,
  615. UnitOfMeasure_kVA ,
  616. UnitOfMeasure_var ,
  617. UnitOfMeasure_kvar ,
  618. UnitOfMeasure_A ,
  619. UnitOfMeasure_V ,
  620. UnitOfMeasure_Celsius ,
  621. UnitOfMeasure_Fahrenheit ,
  622. UnitOfMeasure_K ,
  623. UnitOfMeasure_Percent
  624. } UnitOfMeasure;
  625. static char * UnitOfMeasureStr[] = {
  626. MACROSTR(Wh),
  627. MACROSTR(kWh),
  628. MACROSTR(varh),
  629. MACROSTR(kvarh),
  630. MACROSTR(W),
  631. MACROSTR(kW),
  632. MACROSTR(VA),
  633. MACROSTR(kVA),
  634. MACROSTR(var),
  635. MACROSTR(kvar),
  636. MACROSTR(A),
  637. MACROSTR(V),
  638. MACROSTR(Celsius),
  639. MACROSTR(Fahrenheit),
  640. MACROSTR(K),
  641. MACROSTR(Percent)
  642. };
  643. enum LocalAuthListManagementProfile{
  644. LocalAuthListEnabled=0,
  645. LocalAuthListMaxLength,
  646. SendLocalListMaxLength,
  647. _LocalAuthListManagementProfile_CNT
  648. };
  649. enum ReservationProfile{
  650. ReserveConnectorZeroSupported
  651. };
  652. enum SmartChargingProfile{
  653. ChargeProfileMaxStackLevel,
  654. ChargingScheduleAllowedChargingRateUnit,
  655. ChargingScheduleMaxPeriods,
  656. ConnectorSwitch3to1PhaseSupported,
  657. MaxChargingProfilesInstalled
  658. };
  659. enum ChargerSystemStatus{
  660. ChargerSystemStatus_Booting,
  661. ChargerSystemStatus_Idle,
  662. ChargerSystemStatus_Authorizing,
  663. ChargerSystemStatus_Preparing,
  664. ChargerSystemStatus_Charging,
  665. ChargerSystemStatus_Terminating,
  666. ChargerSystemStatus_Alarm,
  667. ChargerSystemStatus_Fault
  668. };
  669. enum GetConfigurationKey {
  670. GetConfiguration_AllowOfflineTxForUnknownId=0,
  671. GetConfiguration_AuthorizationCacheEnabled,
  672. GetConfiguration_AuthorizeRemoteTxRequests,
  673. GetConfiguration_BlinkRepeat,
  674. GetConfiguration_ClockAlignedDataInterval,
  675. GetConfiguration_ConnectionTimeOut,
  676. GetConfiguration_GetConfigurationMaxKeys,
  677. GetConfiguration_HeartbeatInterval,
  678. GetConfiguration_LightIntensity,
  679. GetConfiguration_LocalAuthorizeOffline,
  680. GetConfiguration_LocalPreAuthorize,
  681. GetConfiguration_MaxEnergyOnInvalidId,
  682. GetConfiguration_MeterValuesAlignedData,
  683. GetConfiguration_MeterValuesAlignedDataMaxLength,
  684. GetConfiguration_MeterValuesSampledData,
  685. GetConfiguration_MeterValuesSampledDataMaxLength,
  686. GetConfiguration_MeterValueSampleInterval,
  687. GetConfiguration_MinimumStatusDuration,
  688. GetConfiguration_NumberOfConnectors,
  689. GetConfiguration_ResetRetries,
  690. GetConfiguration_ConnectorPhaseRotation,
  691. GetConfiguration_ConnectorPhaseRotationMaxLength,
  692. GetConfiguration_StopTransactionOnEVSideDisconnect,
  693. GetConfiguration_StopTransactionOnInvalidId,
  694. GetConfiguration_StopTxnAlignedData,
  695. GetConfiguration_StopTxnAlignedDataMaxLength,
  696. GetConfiguration_StopTxnSampledData,
  697. GetConfiguration_StopTxnSampledDataMaxLength,
  698. GetConfiguration_SupportedFeatureProfiles,
  699. GetConfiguration_SupportedFeatureProfilesMaxLength,
  700. GetConfiguration_TransactionMessageAttempts,
  701. GetConfiguration_TransactionMessageRetryInterval,
  702. GetConfiguration_UnlockConnectorOnEVSideDisconnect,
  703. GetConfiguration_WebSocketPingInterval,
  704. GetConfiguration_LocalAuthListEnabled,
  705. GetConfiguration_LocalAuthListMaxLength,
  706. GetConfiguration_SendLocalListMaxLength,
  707. GetConfiguration_ReserveConnectorZeroSupported,
  708. GetConfiguration_ChargeProfileMaxStackLevel,
  709. GetConfiguration_ChargingScheduleAllowedChargingRateUnit,
  710. GetConfiguration_ChargingScheduleMaxPeriods,
  711. GetConfiguration_ConnectorSwitch3to1PhaseSupported,
  712. GetConfiguration_MaxChargingProfilesInstalled,
  713. };
  714. //GetConfiguration Array
  715. struct StructConfigurationKeyItems staticKeyArray[GetConfigurationMaxKeysNUM]={0};
  716. struct StructConfigurationKey staticResponseConfigurationKeyArray[GetConfigurationMaxKeysNUM]={0};
  717. struct StructConfigurationKeyItems staticResponseUnknownKey[10]={0};
  718. struct StructLocalAuthorizationList staticLocalAuthorizationList[500]={0};
  719. //==========================================
  720. // GetCompositeSchedule logic related function
  721. //==========================================
  722. int DiffTimebSec(struct timeb ST, struct timeb ET)
  723. {
  724. //return milli-second
  725. unsigned int StartTime,StopTime;
  726. StartTime=(unsigned int)ST.time;
  727. StopTime=(unsigned int)ET.time;
  728. return (StopTime-StartTime);
  729. }
  730. int DiffTimebWithNowSec(struct timeb ST)
  731. {
  732. //return milli-second
  733. struct timeb ET;
  734. unsigned int StartTime,StopTime;
  735. ftime(&ET);
  736. StartTime=(unsigned int)ST.time;
  737. StopTime=(unsigned int)ET.time;
  738. return (StopTime-StartTime);
  739. }
  740. int getStartStop(uint8_t *start, uint8_t *stop)
  741. {
  742. int result = -1;
  743. struct tm tmStart;
  744. struct timeb tbStart;
  745. struct tm tmStop;
  746. struct timeb tbStop;
  747. 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) &&
  748. (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))
  749. {
  750. tmStart.tm_year -= 1900;
  751. tmStart.tm_mon -= 1;
  752. tbStart.time = mktime(&tmStart);
  753. tbStart.millitm = 0;
  754. tmStop.tm_year -= 1900;
  755. tmStop.tm_mon -= 1;
  756. tbStop.time = mktime(&tmStop);
  757. tbStop.millitm = 0;
  758. result = DiffTimebSec(tbStart, tbStop);
  759. }
  760. else
  761. {
  762. DEBUG_WARN("Start or stop date parsing error.\r\n");
  763. }
  764. return result;
  765. }
  766. int getStartSinceToday(uint8_t *stop)
  767. {
  768. int result = -1;
  769. time_t t;
  770. struct tm *tmStartToday;
  771. struct timeb tbStartToday;
  772. struct tm tmStop;
  773. struct timeb tbStop;
  774. if((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))
  775. {
  776. t=time(NULL);
  777. tmStartToday=localtime(&t);
  778. tmStartToday->tm_hour = 0;
  779. tmStartToday->tm_min = 0;
  780. tmStartToday->tm_sec = 0;
  781. tbStartToday.time = mktime(tmStartToday);
  782. tmStop.tm_year -= 1900;
  783. tmStop.tm_mon -= 1;
  784. tbStop.time = mktime(&tmStop);
  785. tbStop.millitm = 0;
  786. result = DiffTimebSec(tbStartToday, tbStop);
  787. }
  788. return result;
  789. }
  790. int getStartSinceWeek(uint8_t *stop)
  791. {
  792. int result = -1;
  793. time_t t;
  794. struct tm *tmStartWeek;
  795. struct timeb tbStartWeek;
  796. struct tm tmStop;
  797. struct timeb tbStop;
  798. if((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))
  799. {
  800. t=time(NULL);
  801. tmStartWeek=localtime(&t);
  802. t-=86400*tmStartWeek->tm_wday;
  803. tmStartWeek=localtime(&t);
  804. tmStartWeek->tm_hour = 0;
  805. tmStartWeek->tm_min = 0;
  806. tmStartWeek->tm_sec = 0;
  807. tbStartWeek.time = mktime(tmStartWeek);
  808. tmStop.tm_year -= 1900;
  809. tmStop.tm_mon -= 1;
  810. tbStop.time = mktime(&tmStop);
  811. tbStop.millitm = 0;
  812. result = DiffTimebSec(tbStartWeek, tbStop);
  813. }
  814. return result;
  815. }
  816. void checkCompositeSchedule(uint8_t connectorId, uint32_t durationReq, struct StructChargingProfile *compositeProfile)
  817. {
  818. FILE *fp;
  819. char profileFileName[128];
  820. char *line = NULL;
  821. size_t len = 0;
  822. time_t CurrentTime;
  823. struct tm *tmComposite;
  824. struct StructChargingProfile maxProfile;
  825. struct StructChargingProfile defaultTxProfile;
  826. struct StructChargingProfile txProfile;
  827. struct StructChargingSchedulePeriod tmpPeriod;
  828. uint8_t limitMax=0;
  829. uint8_t limitDef=0;
  830. uint8_t limitTx=0;
  831. int compositePeriodIdx = 0;
  832. CurrentTime = time(NULL);
  833. tmComposite=localtime(&CurrentTime);
  834. 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);
  835. sprintf((char*)compositeProfile->ChargingSchedule.ChargingRateUnit, "A");
  836. compositeProfile->ChargingSchedule.Duration = durationReq;
  837. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(compositeProfile->ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  838. {
  839. compositeProfile->ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = -1;
  840. compositeProfile->ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit = -1;
  841. compositeProfile->ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases = 3;
  842. }
  843. compositeProfile->ChargingProfileId = 1;
  844. compositeProfile->StackLevel = 99 ;
  845. sprintf((char*)compositeProfile->ChargingProfileKind ,"Absolute");
  846. maxProfile.ChargingProfileId = -1;
  847. defaultTxProfile.ChargingProfileId = -1;
  848. txProfile.ChargingProfileId = -1;
  849. system("yes|rm /tmp/*.json");
  850. system("cp /Storage/OCPP/*.json /tmp");
  851. /*
  852. * Search valid charging profile
  853. */
  854. //DEBUG_INFO("====================================\n");
  855. // Search max profile
  856. sprintf(profileFileName, "/tmp/ChargePointMaxProfile.json");
  857. if((access(profileFileName, F_OK))!=-1)
  858. {
  859. fp = fopen(profileFileName, "r");
  860. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  861. {
  862. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = -1;
  863. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit = -1;
  864. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases = 3;
  865. }
  866. maxProfile.ChargingProfileId = -1;
  867. maxProfile.StackLevel = -1;
  868. while(getline(&line, &len, fp) != -1)
  869. {
  870. json_object *obj = NULL;
  871. obj = json_tokener_parse(line);
  872. if(is_error(obj))
  873. {
  874. DEBUG_ERROR("Parse MaxProfile from file error.\n");
  875. }
  876. else
  877. {
  878. if((json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "ChargingProfileId")) != maxProfile.ChargingProfileId) &&
  879. (json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "stackLevel")) >= maxProfile.StackLevel)
  880. )
  881. {
  882. if((json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom") != NULL) &&
  883. (json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo") != NULL)
  884. )
  885. {
  886. struct tm tmFrom, tmTo;
  887. struct timeb tbFrom, tbTo;
  888. 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) &&
  889. (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))
  890. {
  891. tmFrom.tm_year -= 1900;
  892. tmFrom.tm_mon -= 1;
  893. tbFrom.time = mktime(&tmFrom);
  894. tmTo.tm_year -= 1900;
  895. tmTo.tm_mon -= 1;
  896. tbTo.time = mktime(&tmTo);
  897. if((DiffTimebWithNowSec(tbFrom)>=0) && (DiffTimebWithNowSec(tbTo)<=0))
  898. {
  899. if(maxProfile.ChargingProfileId == -1)
  900. DEBUG_INFO("MaxProfile found.\n");
  901. else
  902. DEBUG_INFO("MaxProfile updated.\n");
  903. // Required item
  904. maxProfile.ChargingProfileId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileId"));
  905. maxProfile.StackLevel = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "stackLevel"));
  906. sprintf((char*)maxProfile.ChargingProfileKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileKind")));
  907. sprintf((char*)maxProfile.ChargingSchedule.ChargingRateUnit, "A");
  908. 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++)
  909. {
  910. 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"));
  911. 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: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")));
  912. 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?
  913. 3:
  914. 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")));
  915. }
  916. // Optional item
  917. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom") != NULL)
  918. {
  919. sprintf((char*)maxProfile.ValidFrom, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom")));
  920. }
  921. else
  922. {
  923. sprintf((char*)maxProfile.ValidFrom, " ");
  924. }
  925. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo") != NULL)
  926. {
  927. sprintf((char*)maxProfile.ValidTo, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo")));
  928. }
  929. else
  930. {
  931. sprintf((char*)maxProfile.ValidTo, " ");
  932. }
  933. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "RecurrencyKind") != NULL)
  934. {
  935. sprintf((char*)maxProfile.RecurrencyKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "RecurrencyKind")));
  936. }
  937. else
  938. {
  939. sprintf((char*)maxProfile.RecurrencyKind, " ");
  940. }
  941. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId") != NULL)
  942. {
  943. maxProfile.TransactionId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId"));
  944. }
  945. else
  946. {
  947. maxProfile.TransactionId = -1;
  948. }
  949. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration") != NULL)
  950. {
  951. maxProfile.ChargingSchedule.Duration = json_object_get_int(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration"));
  952. }
  953. else
  954. {
  955. maxProfile.ChargingSchedule.Duration = -1;
  956. }
  957. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "startSchedule") != NULL)
  958. {
  959. 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")));
  960. }
  961. else
  962. {
  963. sprintf((char*)maxProfile.ChargingSchedule.StartSchedule, " ");
  964. }
  965. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate") != NULL)
  966. {
  967. maxProfile.ChargingSchedule.MinChargingRate = json_object_get_double(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate"));
  968. }
  969. else
  970. {
  971. maxProfile.ChargingSchedule.MinChargingRate = -1;
  972. }
  973. }
  974. }
  975. }
  976. else
  977. {
  978. if(maxProfile.ChargingProfileId == -1)
  979. DEBUG_INFO("MaxProfile found.\n");
  980. else
  981. DEBUG_INFO("MaxProfile updated.\n");
  982. // Required item
  983. maxProfile.ChargingProfileId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileId"));
  984. maxProfile.StackLevel = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "stackLevel"));
  985. sprintf((char*)maxProfile.ChargingProfileKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileKind")));
  986. sprintf((char*)maxProfile.ChargingSchedule.ChargingRateUnit, "A");
  987. 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++)
  988. {
  989. 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"));
  990. 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: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")));
  991. 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?
  992. 3:
  993. 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")));
  994. }
  995. // Optional item
  996. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom") != NULL)
  997. {
  998. sprintf((char*)maxProfile.ValidFrom, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom")));
  999. }
  1000. else
  1001. {
  1002. sprintf((char*)maxProfile.ValidFrom, " ");
  1003. }
  1004. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo") != NULL)
  1005. {
  1006. sprintf((char*)maxProfile.ValidTo, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo")));
  1007. }
  1008. else
  1009. {
  1010. sprintf((char*)maxProfile.ValidTo, " ");
  1011. }
  1012. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "RecurrencyKind") != NULL)
  1013. {
  1014. sprintf((char*)maxProfile.RecurrencyKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "RecurrencyKind")));
  1015. }
  1016. else
  1017. {
  1018. sprintf((char*)maxProfile.RecurrencyKind, " ");
  1019. }
  1020. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId") != NULL)
  1021. {
  1022. maxProfile.TransactionId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId"));
  1023. }
  1024. else
  1025. {
  1026. maxProfile.TransactionId = -1;
  1027. }
  1028. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration") != NULL)
  1029. {
  1030. maxProfile.ChargingSchedule.Duration = json_object_get_int(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration"));
  1031. }
  1032. else
  1033. {
  1034. maxProfile.ChargingSchedule.Duration = -1;
  1035. }
  1036. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "startSchedule") != NULL)
  1037. {
  1038. 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")));
  1039. }
  1040. else
  1041. {
  1042. sprintf((char*)maxProfile.ChargingSchedule.StartSchedule, " ");
  1043. }
  1044. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate") != NULL)
  1045. {
  1046. maxProfile.ChargingSchedule.MinChargingRate = json_object_get_double(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate"));
  1047. }
  1048. else
  1049. {
  1050. maxProfile.ChargingSchedule.MinChargingRate = -1;
  1051. }
  1052. }
  1053. }
  1054. }
  1055. json_object_put(obj);
  1056. }
  1057. fclose(fp);
  1058. /*
  1059. if(maxProfile.ChargingProfileId !=-1)
  1060. {
  1061. DEBUG_INFO("Profile ID: %d\n", maxProfile.ChargingProfileId);
  1062. DEBUG_INFO("Profile stackLevel: %d\n", maxProfile.StackLevel);
  1063. DEBUG_INFO("Profile TransactionId: %d\n", maxProfile.TransactionId);
  1064. DEBUG_INFO("Profile valid from: %s\n", maxProfile.ValidFrom);
  1065. DEBUG_INFO("Profile valid to: %s\n", maxProfile.ValidTo);
  1066. DEBUG_INFO("Profile ChargingProfileKind: %s\n", maxProfile.ChargingProfileKind);
  1067. DEBUG_INFO("Profile RecurrencyKind: %s\n", maxProfile.RecurrencyKind);
  1068. DEBUG_INFO("Profile start schedule: %s\n", maxProfile.ChargingSchedule.StartSchedule);
  1069. DEBUG_INFO("Profile schedule duration: %d\n", maxProfile.ChargingSchedule.Duration);
  1070. DEBUG_INFO("Profile charging rate unit: %s\n", maxProfile.ChargingSchedule.ChargingRateUnit);
  1071. DEBUG_INFO("Profile charging min rate: %f\n", maxProfile.ChargingSchedule.MinChargingRate);
  1072. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  1073. {
  1074. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod >= 0)
  1075. {
  1076. DEBUG_INFO("Period-%02d startPeriod: %d\n", idxPeriod, maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod);
  1077. DEBUG_INFO("Period-%02d limit: %f\n", idxPeriod, maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit);
  1078. DEBUG_INFO("Period-%02d NumberPhases: %d\n", idxPeriod, maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases);
  1079. }
  1080. }
  1081. }
  1082. else
  1083. DEBUG_INFO("MaxProfile not found.\n");
  1084. DEBUG_INFO("------------------------------------\n");*/
  1085. }
  1086. // Search default tx profile
  1087. sprintf(profileFileName, "/tmp/TxDefaultProfile_%d.json", connectorId);
  1088. if((access(profileFileName, F_OK))==-1)
  1089. sprintf(profileFileName, "/tmp/TxDefaultProfile_0.json");
  1090. if((access(profileFileName, F_OK))!=-1)
  1091. {
  1092. fp = fopen(profileFileName, "r");
  1093. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  1094. {
  1095. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = -1;
  1096. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit = -1;
  1097. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases = 3;
  1098. }
  1099. defaultTxProfile.ChargingProfileId = -1;
  1100. defaultTxProfile.StackLevel = -1;
  1101. while(getline(&line, &len, fp) != -1)
  1102. {
  1103. json_object *obj = NULL;
  1104. obj = json_tokener_parse(line);
  1105. if(is_error(obj))
  1106. {
  1107. DEBUG_ERROR("Parse TxDefaultProfile from file error.\n");
  1108. }
  1109. else
  1110. {
  1111. if((json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "ChargingProfileId")) != defaultTxProfile.ChargingProfileId) &&
  1112. (json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "stackLevel")) >= defaultTxProfile.StackLevel)
  1113. )
  1114. {
  1115. if((json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom") != NULL) &&
  1116. (json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo") != NULL)
  1117. )
  1118. {
  1119. struct tm tmFrom, tmTo;
  1120. struct timeb tbFrom, tbTo;
  1121. 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) &&
  1122. (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))
  1123. {
  1124. tmFrom.tm_year -= 1900;
  1125. tmFrom.tm_mon -= 1;
  1126. tbFrom.time = mktime(&tmFrom);
  1127. tmTo.tm_year -= 1900;
  1128. tmTo.tm_mon -= 1;
  1129. tbTo.time = mktime(&tmTo);
  1130. if((DiffTimebWithNowSec(tbFrom)>=0) && (DiffTimebWithNowSec(tbTo)<=0))
  1131. {
  1132. if(defaultTxProfile.ChargingProfileId == -1)
  1133. DEBUG_INFO("TxDefaultProfile found.\n");
  1134. else
  1135. DEBUG_INFO("TxDefaultProfile updated.\n");
  1136. // Required item
  1137. defaultTxProfile.ChargingProfileId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileId"));
  1138. defaultTxProfile.StackLevel = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "stackLevel"));
  1139. sprintf((char*)defaultTxProfile.ChargingProfileKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileKind")));
  1140. sprintf((char*)defaultTxProfile.ChargingSchedule.ChargingRateUnit, "A");
  1141. 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++)
  1142. {
  1143. 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"));
  1144. 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: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")));
  1145. 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?
  1146. 3:
  1147. 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")));
  1148. }
  1149. // Optional item
  1150. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom") != NULL)
  1151. {
  1152. sprintf((char*)defaultTxProfile.ValidFrom, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom")));
  1153. }
  1154. else
  1155. {
  1156. sprintf((char*)defaultTxProfile.ValidFrom, " ");
  1157. }
  1158. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo") != NULL)
  1159. {
  1160. sprintf((char*)defaultTxProfile.ValidTo, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo")));
  1161. }
  1162. else
  1163. {
  1164. sprintf((char*)defaultTxProfile.ValidTo, " ");
  1165. }
  1166. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "RecurrencyKind") != NULL)
  1167. {
  1168. sprintf((char*)defaultTxProfile.RecurrencyKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "RecurrencyKind")));
  1169. }
  1170. else
  1171. {
  1172. sprintf((char*)defaultTxProfile.RecurrencyKind, " ");
  1173. }
  1174. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId") != NULL)
  1175. {
  1176. defaultTxProfile.TransactionId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId"));
  1177. }
  1178. else
  1179. {
  1180. defaultTxProfile.TransactionId = -1;
  1181. }
  1182. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration") != NULL)
  1183. {
  1184. defaultTxProfile.ChargingSchedule.Duration = json_object_get_int(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration"));
  1185. }
  1186. else
  1187. {
  1188. defaultTxProfile.ChargingSchedule.Duration = -1;
  1189. }
  1190. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "startSchedule") != NULL)
  1191. {
  1192. 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")));
  1193. }
  1194. else
  1195. {
  1196. sprintf((char*)defaultTxProfile.ChargingSchedule.StartSchedule, " ");
  1197. }
  1198. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate") != NULL)
  1199. {
  1200. defaultTxProfile.ChargingSchedule.MinChargingRate = json_object_get_double(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate"));
  1201. }
  1202. else
  1203. {
  1204. defaultTxProfile.ChargingSchedule.MinChargingRate = -1;
  1205. }
  1206. }
  1207. }
  1208. }
  1209. else
  1210. {
  1211. if(defaultTxProfile.ChargingProfileId == -1)
  1212. DEBUG_INFO("TxDefaultProfile found.\n");
  1213. else
  1214. DEBUG_INFO("TxDefaultProfile updated.\n");
  1215. // Required item
  1216. defaultTxProfile.ChargingProfileId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileId"));
  1217. defaultTxProfile.StackLevel = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "stackLevel"));
  1218. sprintf((char*)defaultTxProfile.ChargingProfileKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileKind")));
  1219. sprintf((char*)defaultTxProfile.ChargingSchedule.ChargingRateUnit, "A");
  1220. 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++)
  1221. {
  1222. 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"));
  1223. 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: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")));
  1224. 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?
  1225. 3:
  1226. 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")));
  1227. }
  1228. // Optional item
  1229. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom") != NULL)
  1230. {
  1231. sprintf((char*)defaultTxProfile.ValidFrom, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom")));
  1232. }
  1233. else
  1234. {
  1235. sprintf((char*)defaultTxProfile.ValidFrom, " ");
  1236. }
  1237. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo") != NULL)
  1238. {
  1239. sprintf((char*)defaultTxProfile.ValidTo, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo")));
  1240. }
  1241. else
  1242. {
  1243. sprintf((char*)defaultTxProfile.ValidTo, " ");
  1244. }
  1245. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "RecurrencyKind") != NULL)
  1246. {
  1247. sprintf((char*)defaultTxProfile.RecurrencyKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "RecurrencyKind")));
  1248. }
  1249. else
  1250. {
  1251. sprintf((char*)defaultTxProfile.RecurrencyKind, " ");
  1252. }
  1253. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId") != NULL)
  1254. {
  1255. defaultTxProfile.TransactionId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId"));
  1256. }
  1257. else
  1258. {
  1259. defaultTxProfile.TransactionId = -1;
  1260. }
  1261. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration") != NULL)
  1262. {
  1263. defaultTxProfile.ChargingSchedule.Duration = json_object_get_int(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration"));
  1264. }
  1265. else
  1266. {
  1267. defaultTxProfile.ChargingSchedule.Duration = -1;
  1268. }
  1269. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "startSchedule") != NULL)
  1270. {
  1271. 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")));
  1272. }
  1273. else
  1274. {
  1275. sprintf((char*)defaultTxProfile.ChargingSchedule.StartSchedule, " ");
  1276. }
  1277. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate") != NULL)
  1278. {
  1279. maxProfile.ChargingSchedule.MinChargingRate = json_object_get_double(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate"));
  1280. }
  1281. else
  1282. {
  1283. maxProfile.ChargingSchedule.MinChargingRate = -1;
  1284. }
  1285. }
  1286. }
  1287. }
  1288. json_object_put(obj);
  1289. }
  1290. fclose(fp);
  1291. /*
  1292. if(defaultTxProfile.ChargingProfileId != -1)
  1293. {
  1294. DEBUG_INFO("Profile ID: %d\n", defaultTxProfile.ChargingProfileId);
  1295. DEBUG_INFO("Profile stackLevel: %d\n", defaultTxProfile.StackLevel);
  1296. DEBUG_INFO("Profile TransactionId: %d\n", defaultTxProfile.TransactionId);
  1297. DEBUG_INFO("Profile valid from: %s\n", defaultTxProfile.ValidFrom);
  1298. DEBUG_INFO("Profile valid to: %s\n", defaultTxProfile.ValidTo);
  1299. DEBUG_INFO("Profile ChargingProfileKind: %s\n", defaultTxProfile.ChargingProfileKind);
  1300. DEBUG_INFO("Profile RecurrencyKind: %s\n", defaultTxProfile.RecurrencyKind);
  1301. DEBUG_INFO("Profile start schedule: %s\n", defaultTxProfile.ChargingSchedule.StartSchedule);
  1302. DEBUG_INFO("Profile schedule duration: %d\n", defaultTxProfile.ChargingSchedule.Duration);
  1303. DEBUG_INFO("Profile charging rate unit: %s\n", defaultTxProfile.ChargingSchedule.ChargingRateUnit);
  1304. DEBUG_INFO("Profile charging min rate: %f\n", defaultTxProfile.ChargingSchedule.MinChargingRate);
  1305. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  1306. {
  1307. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod >= 0)
  1308. {
  1309. DEBUG_INFO("Period-%02d startPeriod: %d\n", idxPeriod, defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod);
  1310. DEBUG_INFO("Period-%02d limit: %f\n", idxPeriod, defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit);
  1311. DEBUG_INFO("Period-%02d NumberPhases: %d\n", idxPeriod, defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases);
  1312. }
  1313. }
  1314. }
  1315. else
  1316. DEBUG_INFO("TxDefaultProfile not found.\n");
  1317. DEBUG_INFO("------------------------------------\n");*/
  1318. }
  1319. // Search tx profile
  1320. sprintf(profileFileName, "/tmp/TxProfile_%d.json", connectorId);
  1321. if((access(profileFileName, F_OK))!=-1)
  1322. {
  1323. fp = fopen(profileFileName, "r");
  1324. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(txProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  1325. {
  1326. txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = -1;
  1327. txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit = -1;
  1328. txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases = 3;
  1329. }
  1330. txProfile.ChargingProfileId = -1;
  1331. txProfile.StackLevel = -1;
  1332. while(getline(&line, &len, fp) != -1)
  1333. {
  1334. json_object *obj = NULL;
  1335. obj = json_tokener_parse(line);
  1336. if(is_error(obj))
  1337. {
  1338. DEBUG_ERROR("Parse txProfile from file error.\n");
  1339. }
  1340. else
  1341. {
  1342. if((json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "ChargingProfileId")) != txProfile.ChargingProfileId) &&
  1343. (json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "stackLevel")) >= txProfile.StackLevel)
  1344. )
  1345. {
  1346. if((json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom") != NULL) &&
  1347. (json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo") != NULL)
  1348. )
  1349. {
  1350. struct tm tmFrom, tmTo;
  1351. struct timeb tbFrom, tbTo;
  1352. 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) &&
  1353. (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))
  1354. {
  1355. tmFrom.tm_year -= 1900;
  1356. tmFrom.tm_mon -= 1;
  1357. tbFrom.time = mktime(&tmFrom);
  1358. tmTo.tm_year -= 1900;
  1359. tmTo.tm_mon -= 1;
  1360. tbTo.time = mktime(&tmTo);
  1361. if((DiffTimebWithNowSec(tbFrom)>=0) && (DiffTimebWithNowSec(tbTo)<=0))
  1362. {
  1363. if(txProfile.ChargingProfileId == -1)
  1364. DEBUG_INFO("TxProfile found.\n");
  1365. else
  1366. DEBUG_INFO("TxProfile updated.\n");
  1367. // Required item
  1368. txProfile.ChargingProfileId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileId"));
  1369. txProfile.StackLevel = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "stackLevel"));
  1370. sprintf((char*)txProfile.ChargingProfileKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileKind")));
  1371. sprintf((char*)txProfile.ChargingSchedule.ChargingRateUnit, "A");
  1372. 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++)
  1373. {
  1374. 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"));
  1375. 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: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")));
  1376. 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?
  1377. 3:
  1378. 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")));
  1379. }
  1380. // Optional item
  1381. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom") != NULL)
  1382. {
  1383. sprintf((char*)txProfile.ValidFrom, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom")));
  1384. }
  1385. else
  1386. {
  1387. sprintf((char*)txProfile.ValidFrom, " ");
  1388. }
  1389. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo") != NULL)
  1390. {
  1391. sprintf((char*)txProfile.ValidTo, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo")));
  1392. }
  1393. else
  1394. {
  1395. sprintf((char*)txProfile.ValidTo, " ");
  1396. }
  1397. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "RecurrencyKind") != NULL)
  1398. {
  1399. sprintf((char*)txProfile.RecurrencyKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "RecurrencyKind")));
  1400. }
  1401. else
  1402. {
  1403. sprintf((char*)txProfile.RecurrencyKind, " ");
  1404. }
  1405. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId") != NULL)
  1406. {
  1407. txProfile.TransactionId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId"));
  1408. }
  1409. else
  1410. {
  1411. txProfile.TransactionId = -1;
  1412. }
  1413. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration") != NULL)
  1414. {
  1415. txProfile.ChargingSchedule.Duration = json_object_get_int(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration"));
  1416. }
  1417. else
  1418. {
  1419. txProfile.ChargingSchedule.Duration = -1;
  1420. }
  1421. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "startSchedule") != NULL)
  1422. {
  1423. 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")));
  1424. }
  1425. else
  1426. {
  1427. sprintf((char*)txProfile.ChargingSchedule.StartSchedule, " ");
  1428. }
  1429. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate") != NULL)
  1430. {
  1431. txProfile.ChargingSchedule.MinChargingRate = json_object_get_double(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate"));
  1432. }
  1433. else
  1434. {
  1435. txProfile.ChargingSchedule.MinChargingRate = -1;
  1436. }
  1437. }
  1438. }
  1439. }
  1440. else
  1441. {
  1442. if(txProfile.ChargingProfileId == -1)
  1443. DEBUG_INFO("TxProfile found.\n");
  1444. else
  1445. DEBUG_INFO("TxProfile updated.\n");
  1446. // Required item
  1447. txProfile.ChargingProfileId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileId"));
  1448. txProfile.StackLevel = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "stackLevel"));
  1449. sprintf((char*)txProfile.ChargingProfileKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileKind")));
  1450. sprintf((char*)txProfile.ChargingSchedule.ChargingRateUnit, "A");
  1451. 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++)
  1452. {
  1453. 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"));
  1454. 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: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")));
  1455. 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?
  1456. 3:
  1457. 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")));
  1458. }
  1459. // Optional item
  1460. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom") != NULL)
  1461. {
  1462. sprintf((char*)txProfile.ValidFrom, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom")));
  1463. }
  1464. else
  1465. {
  1466. sprintf((char*)txProfile.ValidFrom, " ");
  1467. }
  1468. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo") != NULL)
  1469. {
  1470. sprintf((char*)txProfile.ValidTo, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo")));
  1471. }
  1472. else
  1473. {
  1474. sprintf((char*)txProfile.ValidTo, " ");
  1475. }
  1476. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "RecurrencyKind") != NULL)
  1477. {
  1478. sprintf((char*)txProfile.RecurrencyKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "RecurrencyKind")));
  1479. }
  1480. else
  1481. {
  1482. sprintf((char*)txProfile.RecurrencyKind, " ");
  1483. }
  1484. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId") != NULL)
  1485. {
  1486. txProfile.TransactionId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId"));
  1487. }
  1488. else
  1489. {
  1490. txProfile.TransactionId = -1;
  1491. }
  1492. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration") != NULL)
  1493. {
  1494. txProfile.ChargingSchedule.Duration = json_object_get_int(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration"));
  1495. }
  1496. else
  1497. {
  1498. txProfile.ChargingSchedule.Duration = -1;
  1499. }
  1500. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "startSchedule") != NULL)
  1501. {
  1502. 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")));
  1503. }
  1504. else
  1505. {
  1506. sprintf((char*)txProfile.ChargingSchedule.StartSchedule, " ");
  1507. }
  1508. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate") != NULL)
  1509. {
  1510. maxProfile.ChargingSchedule.MinChargingRate = json_object_get_double(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate"));
  1511. }
  1512. else
  1513. {
  1514. maxProfile.ChargingSchedule.MinChargingRate = -1;
  1515. }
  1516. }
  1517. }
  1518. }
  1519. json_object_put(obj);
  1520. }
  1521. fclose(fp);
  1522. /*
  1523. if(defaultTxProfile.ChargingProfileId != -1)
  1524. {
  1525. DEBUG_INFO("Profile ID: %d\n", txProfile.ChargingProfileId);
  1526. DEBUG_INFO("Profile stackLevel: %d\n", txProfile.StackLevel);
  1527. DEBUG_INFO("Profile TransactionId: %d\n", txProfile.TransactionId);
  1528. DEBUG_INFO("Profile valid from: %s\n", txProfile.ValidFrom);
  1529. DEBUG_INFO("Profile valid to: %s\n", txProfile.ValidTo);
  1530. DEBUG_INFO("Profile ChargingProfileKind: %s\n", txProfile.ChargingProfileKind);
  1531. DEBUG_INFO("Profile RecurrencyKind: %s\n", txProfile.RecurrencyKind);
  1532. DEBUG_INFO("Profile start schedule: %s\n", txProfile.ChargingSchedule.StartSchedule);
  1533. DEBUG_INFO("Profile schedule duration: %d\n", txProfile.ChargingSchedule.Duration);
  1534. DEBUG_INFO("Profile charging rate unit: %s\n", txProfile.ChargingSchedule.ChargingRateUnit);
  1535. DEBUG_INFO("Profile charging min rate: %f\n", txProfile.ChargingSchedule.MinChargingRate);
  1536. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(txProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  1537. {
  1538. if(txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod >= 0)
  1539. {
  1540. DEBUG_INFO("Period-%02d startPeriod: %d\n", idxPeriod, txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod);
  1541. DEBUG_INFO("Period-%02d limit: %f\n", idxPeriod, txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit);
  1542. DEBUG_INFO("Period-%02d NumberPhases: %d\n", idxPeriod, txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases);
  1543. }
  1544. }
  1545. }
  1546. else
  1547. DEBUG_INFO("TxProfile not found.\n");*/
  1548. }
  1549. /*
  1550. * Align found profile start schedule & periods
  1551. */
  1552. //DEBUG_INFO("====================================\n");
  1553. /*
  1554. // For local test usage, force modify found profile start schedule info
  1555. 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);
  1556. 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);
  1557. 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);
  1558. */
  1559. if(maxProfile.ChargingProfileId != -1)
  1560. {
  1561. if(strstr((char*)maxProfile.ChargingProfileKind, "Absolute") != NULL)
  1562. {
  1563. if(maxProfile.ChargingSchedule.Duration != -1)
  1564. {
  1565. maxProfile.ChargingSchedule.Duration = ((maxProfile.ChargingSchedule.Duration-getStartStop(maxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule))<0?
  1566. 0:
  1567. (maxProfile.ChargingSchedule.Duration-getStartStop(maxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule)));
  1568. }
  1569. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  1570. {
  1571. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  1572. {
  1573. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = ((maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartStop(maxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule))<0?
  1574. 0:
  1575. (maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartStop(maxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule)));
  1576. }
  1577. }
  1578. }
  1579. else if(strstr((char*)maxProfile.ChargingProfileKind, "Relative") != NULL)
  1580. {
  1581. if(maxProfile.ChargingSchedule.Duration != -1)
  1582. {
  1583. maxProfile.ChargingSchedule.Duration = (strstr((char*)ShmOCPP16Data->StatusNotification[(connectorId==0?0:connectorId-1)].Status, "Charging")==NULL)?maxProfile.ChargingSchedule.Duration:((maxProfile.ChargingSchedule.Duration-getStartStop(ShmOCPP16Data->StartTransaction[(connectorId==0?0:connectorId-1)].Timestamp, compositeProfile->ChargingSchedule.StartSchedule))<0?
  1584. 0:
  1585. (maxProfile.ChargingSchedule.Duration-getStartStop(ShmOCPP16Data->StartTransaction[(connectorId==0?0:connectorId-1)].Timestamp, compositeProfile->ChargingSchedule.StartSchedule)));
  1586. }
  1587. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  1588. {
  1589. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  1590. {
  1591. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = (strstr((char*)ShmOCPP16Data->StatusNotification[(connectorId==0?0:connectorId-1)].Status, "Charging")==NULL)?maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod:((maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartStop(ShmOCPP16Data->StartTransaction[(connectorId==0?0:connectorId-1)].Timestamp, compositeProfile->ChargingSchedule.StartSchedule))<0?
  1592. 0:
  1593. (maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartStop(ShmOCPP16Data->StartTransaction[(connectorId==0?0:connectorId-1)].Timestamp, compositeProfile->ChargingSchedule.StartSchedule)));
  1594. }
  1595. }
  1596. }
  1597. else
  1598. {
  1599. if(strstr((char*)maxProfile.RecurrencyKind, "Weekly") != NULL)
  1600. {
  1601. if(maxProfile.ChargingSchedule.Duration != -1)
  1602. {
  1603. maxProfile.ChargingSchedule.Duration = ((maxProfile.ChargingSchedule.Duration-getStartSinceWeek(compositeProfile->ChargingSchedule.StartSchedule))<0?
  1604. 0:
  1605. (maxProfile.ChargingSchedule.Duration-getStartSinceWeek(compositeProfile->ChargingSchedule.StartSchedule)));
  1606. }
  1607. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  1608. {
  1609. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  1610. {
  1611. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = ((maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceWeek(compositeProfile->ChargingSchedule.StartSchedule))<0?
  1612. 0:
  1613. (maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceWeek(compositeProfile->ChargingSchedule.StartSchedule)));
  1614. }
  1615. }
  1616. }
  1617. else
  1618. {
  1619. if(maxProfile.ChargingSchedule.Duration != -1)
  1620. {
  1621. maxProfile.ChargingSchedule.Duration = ((maxProfile.ChargingSchedule.Duration-getStartSinceToday(compositeProfile->ChargingSchedule.StartSchedule))<0?
  1622. 0:
  1623. (maxProfile.ChargingSchedule.Duration-getStartSinceToday(compositeProfile->ChargingSchedule.StartSchedule)));
  1624. }
  1625. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  1626. {
  1627. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  1628. {
  1629. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = ((maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceToday(compositeProfile->ChargingSchedule.StartSchedule))<0?
  1630. 0:
  1631. (maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceToday(compositeProfile->ChargingSchedule.StartSchedule)));
  1632. }
  1633. }
  1634. }
  1635. }
  1636. /*
  1637. DEBUG_INFO("MaxProfile after align.\n");
  1638. DEBUG_INFO("Profile ID: %d\n", maxProfile.ChargingProfileId);
  1639. DEBUG_INFO("Profile stackLevel: %d\n", maxProfile.StackLevel);
  1640. DEBUG_INFO("Profile TransactionId: %d\n", maxProfile.TransactionId);
  1641. DEBUG_INFO("Profile valid from: %s\n", maxProfile.ValidFrom);
  1642. DEBUG_INFO("Profile valid to: %s\n", maxProfile.ValidTo);
  1643. DEBUG_INFO("Profile ChargingProfileKind: %s\n", maxProfile.ChargingProfileKind);
  1644. DEBUG_INFO("Profile RecurrencyKind: %s\n", maxProfile.RecurrencyKind);
  1645. DEBUG_INFO("Profile start schedule: %s\n", compositeProfile->ChargingSchedule.StartSchedule);
  1646. DEBUG_INFO("Profile schedule duration: %d\n", maxProfile.ChargingSchedule.Duration);
  1647. DEBUG_INFO("Profile charging rate unit: %s\n", maxProfile.ChargingSchedule.ChargingRateUnit);
  1648. DEBUG_INFO("Profile charging min rate: %f\n", maxProfile.ChargingSchedule.MinChargingRate);
  1649. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  1650. {
  1651. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod >= 0)
  1652. {
  1653. DEBUG_INFO("Period-%02d startPeriod: %d\n", idxPeriod, maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod);
  1654. DEBUG_INFO("Period-%02d limit: %f\n", idxPeriod, maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit);
  1655. DEBUG_INFO("Period-%02d NumberPhases: %d\n", idxPeriod, maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases);
  1656. }
  1657. }
  1658. DEBUG_INFO("------------------------------------\n");*/
  1659. }
  1660. if(defaultTxProfile.ChargingProfileId != -1)
  1661. {
  1662. if(strstr((char*)defaultTxProfile.ChargingProfileKind, "Absolute") != NULL)
  1663. {
  1664. if(defaultTxProfile.ChargingSchedule.Duration != -1)
  1665. {
  1666. defaultTxProfile.ChargingSchedule.Duration = ((defaultTxProfile.ChargingSchedule.Duration-getStartStop(defaultTxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule))<0?
  1667. 0:
  1668. (defaultTxProfile.ChargingSchedule.Duration-getStartStop(defaultTxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule)));
  1669. }
  1670. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  1671. {
  1672. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  1673. {
  1674. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = ((defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartStop(defaultTxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule))<0?
  1675. 0:
  1676. (defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartStop(defaultTxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule)));
  1677. }
  1678. }
  1679. }
  1680. else if(strstr((char*)defaultTxProfile.ChargingProfileKind, "Relative") != NULL)
  1681. {
  1682. if(defaultTxProfile.ChargingSchedule.Duration != -1)
  1683. {
  1684. defaultTxProfile.ChargingSchedule.Duration = (strstr((char*)ShmOCPP16Data->StatusNotification[(connectorId==0?0:connectorId-1)].Status, "Charging")==NULL)?defaultTxProfile.ChargingSchedule.Duration:((defaultTxProfile.ChargingSchedule.Duration-getStartStop(ShmOCPP16Data->StartTransaction[(connectorId==0?0:connectorId-1)].Timestamp, compositeProfile->ChargingSchedule.StartSchedule))<0?
  1685. 0:
  1686. (defaultTxProfile.ChargingSchedule.Duration-getStartStop(ShmOCPP16Data->StartTransaction[(connectorId==0?0:connectorId-1)].Timestamp, compositeProfile->ChargingSchedule.StartSchedule)));
  1687. }
  1688. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  1689. {
  1690. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  1691. {
  1692. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = (strstr((char*)ShmOCPP16Data->StatusNotification[(connectorId==0?0:connectorId-1)].Status, "Charging")==NULL)?defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod:((defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartStop(ShmOCPP16Data->StartTransaction[(connectorId==0?0:connectorId-1)].Timestamp, compositeProfile->ChargingSchedule.StartSchedule))<0?
  1693. 0:
  1694. (defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartStop(ShmOCPP16Data->StartTransaction[(connectorId==0?0:connectorId-1)].Timestamp, compositeProfile->ChargingSchedule.StartSchedule)));
  1695. }
  1696. }
  1697. }
  1698. else
  1699. {
  1700. if(strstr((char*)defaultTxProfile.RecurrencyKind, "Weekly") != NULL)
  1701. {
  1702. if(defaultTxProfile.ChargingSchedule.Duration != -1)
  1703. {
  1704. defaultTxProfile.ChargingSchedule.Duration = ((defaultTxProfile.ChargingSchedule.Duration-getStartSinceWeek(compositeProfile->ChargingSchedule.StartSchedule))<0?
  1705. 0:
  1706. (defaultTxProfile.ChargingSchedule.Duration-getStartSinceWeek(compositeProfile->ChargingSchedule.StartSchedule)));
  1707. }
  1708. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  1709. {
  1710. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  1711. {
  1712. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = ((defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceWeek(compositeProfile->ChargingSchedule.StartSchedule))<0?
  1713. 0:
  1714. (defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceWeek(compositeProfile->ChargingSchedule.StartSchedule)));
  1715. }
  1716. }
  1717. }
  1718. else
  1719. {
  1720. if(defaultTxProfile.ChargingSchedule.Duration != -1)
  1721. {
  1722. defaultTxProfile.ChargingSchedule.Duration = ((defaultTxProfile.ChargingSchedule.Duration-getStartSinceToday(compositeProfile->ChargingSchedule.StartSchedule))<0?
  1723. 0:
  1724. (defaultTxProfile.ChargingSchedule.Duration-getStartSinceToday(compositeProfile->ChargingSchedule.StartSchedule)));
  1725. }
  1726. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  1727. {
  1728. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  1729. {
  1730. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = ((defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceToday(compositeProfile->ChargingSchedule.StartSchedule))<0?
  1731. 0:
  1732. (defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceToday(compositeProfile->ChargingSchedule.StartSchedule)));
  1733. }
  1734. }
  1735. }
  1736. }
  1737. /*
  1738. DEBUG_INFO("defaultTxProfile after align.\n");
  1739. DEBUG_INFO("Profile ID: %d\n", defaultTxProfile.ChargingProfileId);
  1740. DEBUG_INFO("Profile stackLevel: %d\n", defaultTxProfile.StackLevel);
  1741. DEBUG_INFO("Profile TransactionId: %d\n", defaultTxProfile.TransactionId);
  1742. DEBUG_INFO("Profile valid from: %s\n", defaultTxProfile.ValidFrom);
  1743. DEBUG_INFO("Profile valid to: %s\n", defaultTxProfile.ValidTo);
  1744. DEBUG_INFO("Profile ChargingProfileKind: %s\n", defaultTxProfile.ChargingProfileKind);
  1745. DEBUG_INFO("Profile RecurrencyKind: %s\n", defaultTxProfile.RecurrencyKind);
  1746. DEBUG_INFO("Profile start schedule: %s\n", compositeProfile->ChargingSchedule.StartSchedule);
  1747. DEBUG_INFO("Profile schedule duration: %d\n", defaultTxProfile.ChargingSchedule.Duration);
  1748. DEBUG_INFO("Profile charging rate unit: %s\n", defaultTxProfile.ChargingSchedule.ChargingRateUnit);
  1749. DEBUG_INFO("Profile charging min rate: %f\n", defaultTxProfile.ChargingSchedule.MinChargingRate);
  1750. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  1751. {
  1752. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod >= 0)
  1753. {
  1754. DEBUG_INFO("Period-%02d startPeriod: %d\n", idxPeriod, defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod);
  1755. DEBUG_INFO("Period-%02d limit: %f\n", idxPeriod, defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit);
  1756. DEBUG_INFO("Period-%02d NumberPhases: %d\n", idxPeriod, defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases);
  1757. }
  1758. }
  1759. DEBUG_INFO("------------------------------------\n");*/
  1760. }
  1761. if(txProfile.ChargingProfileId != -1)
  1762. {
  1763. if(strstr((char*)txProfile.ChargingProfileKind, "Absolute") != NULL)
  1764. {
  1765. if(txProfile.ChargingSchedule.Duration != -1)
  1766. {
  1767. txProfile.ChargingSchedule.Duration = ((txProfile.ChargingSchedule.Duration-getStartStop(txProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule))<0?
  1768. 0:
  1769. (txProfile.ChargingSchedule.Duration-getStartStop(txProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule)));
  1770. }
  1771. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(txProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  1772. {
  1773. if(txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  1774. {
  1775. txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = ((txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartStop(txProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule))<0?
  1776. 0:
  1777. (txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartStop(txProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule)));
  1778. }
  1779. }
  1780. }
  1781. else if(strstr((char*)txProfile.ChargingProfileKind, "Relative") != NULL)
  1782. {
  1783. if(txProfile.ChargingSchedule.Duration != -1)
  1784. {
  1785. txProfile.ChargingSchedule.Duration = (strstr((char*)ShmOCPP16Data->StatusNotification[(connectorId==0?0:connectorId-1)].Status, "Charging")==NULL)?txProfile.ChargingSchedule.Duration:((txProfile.ChargingSchedule.Duration-getStartStop(ShmOCPP16Data->StartTransaction[(connectorId==0?0:connectorId-1)].Timestamp, compositeProfile->ChargingSchedule.StartSchedule))<0?
  1786. 0:
  1787. (txProfile.ChargingSchedule.Duration-getStartStop(ShmOCPP16Data->StartTransaction[(connectorId==0?0:connectorId-1)].Timestamp, compositeProfile->ChargingSchedule.StartSchedule)));
  1788. }
  1789. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(txProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  1790. {
  1791. if(txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  1792. {
  1793. txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = (strstr((char*)ShmOCPP16Data->StatusNotification[(connectorId==0?0:connectorId-1)].Status, "Charging")==NULL)?txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod:((txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartStop(ShmOCPP16Data->StartTransaction[(connectorId==0?0:connectorId-1)].Timestamp, compositeProfile->ChargingSchedule.StartSchedule))<0?
  1794. 0:
  1795. (txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartStop(ShmOCPP16Data->StartTransaction[(connectorId==0?0:connectorId-1)].Timestamp, compositeProfile->ChargingSchedule.StartSchedule)));
  1796. }
  1797. }
  1798. }
  1799. else
  1800. {
  1801. if(strstr((char*)txProfile.RecurrencyKind, "Weekly") != NULL)
  1802. {
  1803. if(txProfile.ChargingSchedule.Duration != -1)
  1804. {
  1805. txProfile.ChargingSchedule.Duration = ((txProfile.ChargingSchedule.Duration-getStartSinceWeek(compositeProfile->ChargingSchedule.StartSchedule))<0?
  1806. 0:
  1807. (txProfile.ChargingSchedule.Duration-getStartSinceWeek(compositeProfile->ChargingSchedule.StartSchedule)));
  1808. }
  1809. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(txProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  1810. {
  1811. if(txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  1812. {
  1813. txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = ((txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceWeek(compositeProfile->ChargingSchedule.StartSchedule))<0?
  1814. 0:
  1815. (txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceWeek(compositeProfile->ChargingSchedule.StartSchedule)));
  1816. }
  1817. }
  1818. }
  1819. else
  1820. {
  1821. if(txProfile.ChargingSchedule.Duration != -1)
  1822. {
  1823. txProfile.ChargingSchedule.Duration = ((txProfile.ChargingSchedule.Duration-getStartSinceToday(compositeProfile->ChargingSchedule.StartSchedule))<0?
  1824. 0:
  1825. (txProfile.ChargingSchedule.Duration-getStartSinceToday(compositeProfile->ChargingSchedule.StartSchedule)));
  1826. }
  1827. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(txProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  1828. {
  1829. if(txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  1830. {
  1831. txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = ((txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceToday(compositeProfile->ChargingSchedule.StartSchedule))<0?
  1832. 0:
  1833. (txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceToday(compositeProfile->ChargingSchedule.StartSchedule)));
  1834. }
  1835. }
  1836. }
  1837. }
  1838. /*
  1839. DEBUG_INFO("txProfile after align.\n");
  1840. DEBUG_INFO("Profile ID: %d\n", txProfile.ChargingProfileId);
  1841. DEBUG_INFO("Profile stackLevel: %d\n", txProfile.StackLevel);
  1842. DEBUG_INFO("Profile TransactionId: %d\n", txProfile.TransactionId);
  1843. DEBUG_INFO("Profile valid from: %s\n", txProfile.ValidFrom);
  1844. DEBUG_INFO("Profile valid to: %s\n", txProfile.ValidTo);
  1845. DEBUG_INFO("Profile ChargingProfileKind: %s\n", txProfile.ChargingProfileKind);
  1846. DEBUG_INFO("Profile RecurrencyKind: %s\n", txProfile.RecurrencyKind);
  1847. DEBUG_INFO("Profile start schedule: %s\n", compositeProfile->ChargingSchedule.StartSchedule);
  1848. DEBUG_INFO("Profile schedule duration: %d\n", txProfile.ChargingSchedule.Duration);
  1849. DEBUG_INFO("Profile charging rate unit: %s\n", txProfile.ChargingSchedule.ChargingRateUnit);
  1850. DEBUG_INFO("Profile charging min rate: %f\n", txProfile.ChargingSchedule.MinChargingRate);
  1851. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(txProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  1852. {
  1853. if(txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod >= 0)
  1854. {
  1855. DEBUG_INFO("Period-%02d startPeriod: %d\n", idxPeriod, txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod);
  1856. DEBUG_INFO("Period-%02d limit: %f\n", idxPeriod, txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit);
  1857. DEBUG_INFO("Period-%02d NumberPhases: %d\n", idxPeriod, txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases);
  1858. }
  1859. }*/
  1860. }
  1861. /*
  1862. * Merge to conposite schedule
  1863. */
  1864. //DEBUG_INFO("====================================\n");
  1865. // Find each profile period quantity
  1866. for(int idx=0;idx<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idx++)
  1867. {
  1868. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idx].Limit != -1)
  1869. limitMax = idx+1;
  1870. }
  1871. for(int idx=0;idx<ARRAY_SIZE(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod);idx++)
  1872. {
  1873. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idx].Limit != -1)
  1874. limitDef = idx+1;
  1875. }
  1876. for(int idx=0;idx<ARRAY_SIZE(txProfile.ChargingSchedule.ChargingSchedulePeriod);idx++)
  1877. {
  1878. if(txProfile.ChargingSchedule.ChargingSchedulePeriod[idx].Limit != -1)
  1879. limitTx = idx+1;
  1880. }
  1881. // TxProfile found, composite schedule based on it
  1882. if(txProfile.ChargingProfileId != -1)
  1883. {
  1884. for(int idxTxPeriod=0;idxTxPeriod<limitTx;idxTxPeriod++)
  1885. {
  1886. if((txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod].Limit != -1) &&
  1887. (txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod].StartPeriod < durationReq))
  1888. {
  1889. if(maxProfile.ChargingProfileId != -1)
  1890. {
  1891. for(int idxMaxPeriod=0;idxMaxPeriod<limitMax;idxMaxPeriod++)
  1892. {
  1893. if((txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod].StartPeriod >= maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].StartPeriod) &&
  1894. (maxProfile.ChargingSchedule.Duration > txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod].StartPeriod))
  1895. {
  1896. tmpPeriod.StartPeriod = txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod].StartPeriod;
  1897. tmpPeriod.NumberPhases = txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod].NumberPhases;
  1898. tmpPeriod.Limit = (txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod].Limit>maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].Limit?maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].Limit:txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod].Limit);
  1899. }
  1900. if(idxMaxPeriod == (limitMax-1))
  1901. {
  1902. if(tmpPeriod.Limit != compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].Limit)
  1903. {
  1904. if(tmpPeriod.StartPeriod != compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].StartPeriod)
  1905. {
  1906. memcpy(&compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx], &tmpPeriod , sizeof(struct StructChargingSchedulePeriod));
  1907. compositePeriodIdx++;
  1908. }
  1909. else
  1910. {
  1911. memcpy(&compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)], &tmpPeriod , sizeof(struct StructChargingSchedulePeriod));
  1912. }
  1913. }
  1914. }
  1915. }
  1916. }
  1917. else
  1918. {
  1919. if(txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod].StartPeriod != compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].StartPeriod)
  1920. {
  1921. memcpy(&compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx], &txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod],sizeof(struct StructChargingSchedulePeriod));
  1922. compositePeriodIdx++;
  1923. }
  1924. else
  1925. {
  1926. memcpy(&compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)], &txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod],sizeof(struct StructChargingSchedulePeriod));
  1927. }
  1928. }
  1929. }
  1930. if(idxTxPeriod == (limitTx-1))
  1931. {
  1932. if(defaultTxProfile.ChargingProfileId != -1)
  1933. {
  1934. for(int idxDefPeriod=0;idxDefPeriod<limitDef;idxDefPeriod++)
  1935. {
  1936. if((defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].StartPeriod > txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod].StartPeriod) &&
  1937. (defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].StartPeriod < durationReq))
  1938. {
  1939. if(maxProfile.ChargingProfileId != -1)
  1940. {
  1941. for(int idxMaxPeriod=0;idxMaxPeriod<limitMax;idxMaxPeriod++)
  1942. {
  1943. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].StartPeriod >= maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].StartPeriod)
  1944. {
  1945. tmpPeriod.StartPeriod = defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].StartPeriod;
  1946. tmpPeriod.NumberPhases = defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].NumberPhases;
  1947. tmpPeriod.Limit = (defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].Limit>maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].Limit?maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].Limit:defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod].Limit);
  1948. if(tmpPeriod.Limit != compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].Limit)
  1949. {
  1950. if(tmpPeriod.StartPeriod != compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].StartPeriod)
  1951. {
  1952. memcpy(&compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx], &tmpPeriod , sizeof(struct StructChargingSchedulePeriod));
  1953. compositePeriodIdx++;
  1954. }
  1955. else
  1956. {
  1957. memcpy(&compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)], &tmpPeriod , sizeof(struct StructChargingSchedulePeriod));
  1958. }
  1959. }
  1960. break;
  1961. }
  1962. }
  1963. }
  1964. else
  1965. {
  1966. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].StartPeriod != compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].StartPeriod)
  1967. {
  1968. memcpy(&compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx], &defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod],sizeof(struct StructChargingSchedulePeriod));
  1969. compositePeriodIdx++;
  1970. }
  1971. else
  1972. {
  1973. memcpy(&compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)], &defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod],sizeof(struct StructChargingSchedulePeriod));
  1974. }
  1975. }
  1976. }
  1977. }
  1978. }
  1979. }
  1980. }
  1981. }
  1982. // TxProfile not found but defaultTxProfile found, composite schedule based on it
  1983. else if(defaultTxProfile.ChargingProfileId != -1)
  1984. {
  1985. for(int idxDefPeriod=0;idxDefPeriod<limitDef;idxDefPeriod++)
  1986. {
  1987. if((defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].Limit != -1) &&
  1988. (defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].StartPeriod < durationReq))
  1989. {
  1990. if(maxProfile.ChargingProfileId != -1)
  1991. {
  1992. for(int idxMaxPeriod=0;idxMaxPeriod<limitMax;idxMaxPeriod++)
  1993. {
  1994. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].StartPeriod >= maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].StartPeriod)
  1995. {
  1996. tmpPeriod.StartPeriod = defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].StartPeriod;
  1997. tmpPeriod.NumberPhases = defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].NumberPhases;
  1998. tmpPeriod.Limit = (defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].Limit>maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].Limit?maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].Limit:defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].Limit);
  1999. if(tmpPeriod.Limit != compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].Limit)
  2000. {
  2001. if(tmpPeriod.StartPeriod != compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].StartPeriod)
  2002. {
  2003. memcpy(&compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx], &tmpPeriod , sizeof(struct StructChargingSchedulePeriod));
  2004. compositePeriodIdx++;
  2005. }
  2006. else
  2007. {
  2008. memcpy(&compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)], &tmpPeriod , sizeof(struct StructChargingSchedulePeriod));
  2009. }
  2010. }
  2011. break;
  2012. }
  2013. }
  2014. }
  2015. else
  2016. {
  2017. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].StartPeriod != compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].StartPeriod)
  2018. {
  2019. memcpy(&compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx], &defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod],sizeof(struct StructChargingSchedulePeriod));
  2020. compositePeriodIdx++;
  2021. }
  2022. else
  2023. {
  2024. memcpy(&compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)], &defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod],sizeof(struct StructChargingSchedulePeriod));
  2025. }
  2026. }
  2027. }
  2028. }
  2029. }
  2030. // Fill other period by MaxProfile
  2031. if(maxProfile.ChargingProfileId != -1)
  2032. {
  2033. for(int idxMaxPeriod=0;idxMaxPeriod<limitMax;idxMaxPeriod++)
  2034. {
  2035. if((maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].Limit != -1) &&
  2036. (maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].StartPeriod < durationReq))
  2037. {
  2038. if((maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].StartPeriod >= compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx==0?0:compositePeriodIdx-1].StartPeriod) &&
  2039. (maxProfile.ChargingSchedule.Duration > compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx==0?0:compositePeriodIdx-1].StartPeriod))
  2040. {
  2041. tmpPeriod.StartPeriod = compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx==0?0:compositePeriodIdx-1].StartPeriod;
  2042. tmpPeriod.NumberPhases = compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx==0?0:compositePeriodIdx-1].NumberPhases;
  2043. tmpPeriod.Limit = maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].Limit;
  2044. }
  2045. if(idxMaxPeriod == (limitMax-1))
  2046. {
  2047. if(maxProfile.ChargingSchedule.Duration > compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx==0?0:compositePeriodIdx-1].StartPeriod)
  2048. {
  2049. tmpPeriod.StartPeriod = compositeProfile->ChargingSchedule.Duration;
  2050. tmpPeriod.NumberPhases = maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].NumberPhases;
  2051. tmpPeriod.Limit = maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].Limit;
  2052. }
  2053. if(tmpPeriod.Limit != -1)
  2054. {
  2055. if(tmpPeriod.Limit != compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].Limit)
  2056. {
  2057. if(tmpPeriod.StartPeriod != compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].StartPeriod)
  2058. {
  2059. memcpy(&compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx], &tmpPeriod , sizeof(struct StructChargingSchedulePeriod));
  2060. compositePeriodIdx++;
  2061. }
  2062. else
  2063. {
  2064. memcpy(&compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)], &tmpPeriod , sizeof(struct StructChargingSchedulePeriod));
  2065. }
  2066. }
  2067. }
  2068. }
  2069. }
  2070. }
  2071. }
  2072. DEBUG_INFO("Composite schedule start: %s\n", compositeProfile->ChargingSchedule.StartSchedule);
  2073. DEBUG_INFO("Composite schedule duration: %d\n", compositeProfile->ChargingSchedule.Duration);
  2074. DEBUG_INFO("Composite rate unit: %s\n", compositeProfile->ChargingSchedule.ChargingRateUnit);
  2075. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(compositeProfile->ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  2076. {
  2077. if(compositeProfile->ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod >= 0)
  2078. {
  2079. DEBUG_INFO("Period-%02d startPeriod: %d\n", idxPeriod, compositeProfile->ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod);
  2080. DEBUG_INFO("Period-%02d limit: %f\n", idxPeriod, compositeProfile->ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit);
  2081. DEBUG_INFO("Period-%02d NumberPhases: %d\n", idxPeriod, compositeProfile->ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases);
  2082. }
  2083. if(compositeProfile->ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit == -1)
  2084. compositeProfile->ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit =0;
  2085. if(compositeProfile->ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod == -1)
  2086. compositeProfile->ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod =0;
  2087. }
  2088. if(line)
  2089. free(line);
  2090. }
  2091. //==========================================
  2092. // Init all share memory
  2093. //==========================================
  2094. int InitShareMemory()
  2095. {
  2096. int result = PASS;
  2097. int MeterSMId;
  2098. //creat ShmSysConfigAndInfo
  2099. if ((MeterSMId = shmget(ShmSysConfigAndInfoKey, sizeof(struct SysConfigAndInfo), 0777)) < 0)
  2100. {
  2101. DEBUG_ERROR("shmget ShmSysConfigAndInfo NG\n");
  2102. result = FAIL;
  2103. }
  2104. else if ((ShmSysConfigAndInfo = shmat(MeterSMId, NULL, 0)) == (void *) -1)
  2105. {
  2106. DEBUG_ERROR("shmat ShmSysConfigAndInfo NG\n");
  2107. result = FAIL;
  2108. }
  2109. else
  2110. {}
  2111. if ((MeterSMId = shmget(ShmStatusCodeKey, sizeof(struct StatusCodeData), 0777)) < 0)
  2112. {
  2113. DEBUG_ERROR("shmget ShmStatusCodeData NG\n");
  2114. result = FAIL;
  2115. }
  2116. else if ((ShmStatusCodeData = shmat(MeterSMId, NULL, 0)) == (void *) -1)
  2117. {
  2118. DEBUG_ERROR("shmat ShmStatusCodeData NG\n");
  2119. result = FAIL;
  2120. }
  2121. else
  2122. {}
  2123. //creat ShmPsuData
  2124. if ((MeterSMId = shmget(ShmPsuKey, sizeof(struct PsuData), 0777)) < 0)
  2125. {
  2126. DEBUG_ERROR("shmget ShmPsuData NG\n");
  2127. result = FAIL;
  2128. }
  2129. else if ((ShmPsuData = shmat(MeterSMId, NULL, 0)) == (void *) -1)
  2130. {
  2131. DEBUG_ERROR("shmat ShmPsuData NG\n");
  2132. result = FAIL;
  2133. }
  2134. else
  2135. {}
  2136. //creat ShmOCPP16Data
  2137. if ((MeterSMId = shmget(ShmOcppModuleKey, sizeof(struct OCPP16Data), 0777)) < 0)
  2138. {
  2139. DEBUG_ERROR("shmget ShmOCPP16Data NG");
  2140. result = FAIL;
  2141. }
  2142. else if ((ShmOCPP16Data = shmat(MeterSMId, NULL, 0)) == (void *) -1)
  2143. {
  2144. DEBUG_ERROR("shmat ShmOCPP16Data NG");
  2145. result = FAIL;
  2146. }
  2147. else
  2148. {}
  2149. /****************************** For Initial Settings************************************************/
  2150. ShmOCPP16Data->GetConfiguration.ResponseUnknownKey = NULL;
  2151. ShmOCPP16Data->SendLocalList.LocalAuthorizationList = NULL;
  2152. // allocate Configuration memory address
  2153. ShmOCPP16Data->GetConfiguration.Key = staticKeyArray;
  2154. ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey = staticResponseConfigurationKeyArray;
  2155. ShmOCPP16Data->GetConfiguration.ResponseUnknownKey = staticResponseUnknownKey;
  2156. ShmOCPP16Data->SendLocalList.LocalAuthorizationList = staticLocalAuthorizationList;
  2157. //offline MeterValue Interval
  2158. TempMeterValueInterval = 0;
  2159. return result;
  2160. }
  2161. int ProcessShareMemory()
  2162. {
  2163. if(InitShareMemory() == FAIL)
  2164. {
  2165. DEBUG_ERROR("InitShareMemory NG\n");
  2166. if(ShmStatusCodeData!=NULL)
  2167. {
  2168. ShmStatusCodeData->AlarmCode.AlarmEvents.bits.FailToCreateShareMemory=1;
  2169. }
  2170. sleep(5);
  2171. return FAIL;
  2172. }
  2173. return PASS;
  2174. }
  2175. //---------------------common routine---------------------------//
  2176. int isOFFline(void)
  2177. {
  2178. if(ShmSysConfigAndInfo->SysInfo.InternetConn == 0)
  2179. {
  2180. if(TempMeterValueInterval >= 2 )
  2181. {
  2182. TempMeterValueInterval = 0;
  2183. return TRUE;
  2184. }
  2185. else
  2186. {
  2187. TempMeterValueInterval = TempMeterValueInterval+ 1;
  2188. return FALSE;
  2189. }
  2190. }
  2191. else
  2192. {
  2193. return FALSE;
  2194. }
  2195. }
  2196. //---------------------------------------------
  2197. // new:
  2198. // enum SYSTEM_STATUS
  2199. // {
  2200. // SYS_MODE_BOOTING = 0,
  2201. // SYS_MODE_IDLE = 1,
  2202. // SYS_MODE_AUTHORIZING = 2,
  2203. // SYS_MODE_MODE_REASSIGN_CHECK = 3,
  2204. // SYS_MODE_REASSIGN = 4,
  2205. // SYS_MODE_PREPARING = 5,
  2206. // SYS_MODE_PREPARE_FOR_EV = 6,
  2207. // SYS_MODE_PREPARE_FOR_EVSE = 7,
  2208. // SYS_MODE_CHARGING = 8,
  2209. // SYS_MODE_TERMINATING = 9,
  2210. // SYS_MODE_COMPLETE = 10,
  2211. // SYS_MODE_ALARM = 11,
  2212. // SYS_MODE_FAULT = 12,
  2213. // SYS_MODE_RESERVATION = 13,
  2214. // SYS_MODE_BOOKING = 14,
  2215. // SYS_MODE_MAINTAIN = 15,
  2216. // SYS_MODE_DEBUG = 16,
  2217. // SYS_MODE_CCS_PRECHARGE_STEP0 = 17,
  2218. // SYS_MODE_CCS_PRECHARGE_STEP1 = 18,
  2219. // SYS_MODE_UPDATE = 19
  2220. // };
  2221. //
  2222. //
  2223. //-----------------------------------------
  2224. void CheckSystemValue(void)
  2225. {
  2226. int meterValueSend[CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY + AC_QUANTITY]={0};
  2227. //int IdleModeCnt = 0;
  2228. char filenmae[100]={0};
  2229. char str[100]={0};
  2230. //===============================
  2231. // send Heartbeat
  2232. //===============================
  2233. //HeartBeatWaitTime = ShmOCPP16Data->BootNotification.ResponseHeartbeatInterval;
  2234. if((difftime(time((time_t*)NULL), clientTime.Heartbeat) < 0) || (HeartBeatWaitTime <= 0))
  2235. {
  2236. clientTime.Heartbeat=time((time_t*)NULL);
  2237. if(server_sign == TRUE)
  2238. {
  2239. HeartBeatWaitTime = ShmOCPP16Data->BootNotification.ResponseHeartbeatInterval;
  2240. }
  2241. else
  2242. {
  2243. HeartBeatWaitTime = atoi((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemData);
  2244. }
  2245. }
  2246. if((server_sign == TRUE) && (difftime(time((time_t*)NULL), clientTime.Heartbeat) >= HeartBeatWaitTime))
  2247. {
  2248. //parameter for test
  2249. sendHeartbeatRequest(0);
  2250. //==============================================
  2251. // Reset Waiting Time
  2252. //==============================================
  2253. clientTime.Heartbeat=time((time_t*)NULL);
  2254. HeartBeatWithNOResponse = HeartBeatWithNOResponse + 1;
  2255. }
  2256. for(int gun_index=0;gun_index < gunTotalNumber ;gun_index++)
  2257. {
  2258. //===============================
  2259. // CSU Trigger Reset Conf
  2260. //===============================
  2261. if((server_sign == TRUE) && (ShmOCPP16Data->MsMsg.bits.ResetConf == 1))
  2262. {
  2263. sendResetConfirmation((char *)ShmOCPP16Data->Reset.guid, (char *)ShmOCPP16Data->Reset.ResponseStatus);
  2264. }
  2265. //===============================
  2266. // CSU Trigger Authorize Request
  2267. //===============================
  2268. if((server_sign == TRUE) && (ShmOCPP16Data->SpMsg.bits.AuthorizeReq == 1)&&(authorizeRetryTimes < 3))
  2269. {
  2270. sendAuthorizeRequest(0);
  2271. authorizeRetryTimes = authorizeRetryTimes + 1;
  2272. if(authorizeRetryTimes < 3)
  2273. ShmOCPP16Data->SpMsg.bits.AuthorizeReq = 0;
  2274. }
  2275. else if((server_sign == TRUE) && (ShmOCPP16Data->SpMsg.bits.AuthorizeReq == 1)&&(authorizeRetryTimes >= 3))
  2276. {
  2277. authorizeRetryTimes = 0;
  2278. ShmOCPP16Data->OcppConnStatus = 0; // ocpp offline
  2279. server_sign = FALSE;
  2280. }
  2281. 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))
  2282. {
  2283. sendAuthorizeRequest(0);
  2284. }
  2285. //===============================
  2286. // CSU Trigger Smart Charging Profilw
  2287. //===============================
  2288. if(ShmOCPP16Data->CSUMsg.bits[gun_index].ChargingProfileReq == 1)
  2289. {
  2290. ShmOCPP16Data->CSUMsg.bits[gun_index].ChargingProfileReq = 0;
  2291. checkCompositeSchedule(gun_index+1, 86400, &ShmOCPP16Data->SmartChargingProfile[gun_index]);
  2292. ShmOCPP16Data->CSUMsg.bits[gun_index].ChargingProfileConf = 1;
  2293. }
  2294. //==============================================
  2295. // Charger start transaction
  2296. //==============================================
  2297. if(/*(server_sign == TRUE) &&*/ (ShmOCPP16Data->CpMsg.bits[gun_index].StartTransactionReq == 1))
  2298. {
  2299. ShmOCPP16Data->CpMsg.bits[gun_index].StartTransactionReq =0;
  2300. sendStartTransactionRequest(gun_index);
  2301. clientTime.StartTransaction = time((time_t*)NULL);
  2302. clientTime.MeterValues[gun_index] = time((time_t*)NULL);
  2303. }
  2304. //==============================================
  2305. // Charger stop transaction
  2306. //==============================================
  2307. if(/*(server_sign == TRUE) &&*/ ((ShmOCPP16Data->CpMsg.bits[gun_index].StopTransactionReq == 1)))
  2308. {
  2309. ShmOCPP16Data->CpMsg.bits[gun_index].StopTransactionReq =0;
  2310. sendStopTransactionRequest(gun_index);
  2311. clientTime.StopTransaction = time((time_t*)NULL);
  2312. }
  2313. //==============================================
  2314. // Charger status report
  2315. //==============================================
  2316. //--- Check Mode Change ---//
  2317. // J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DCcc
  2318. if(gunType[gun_index] == 'J')
  2319. {
  2320. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  2321. {
  2322. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == gun_index)
  2323. {
  2324. if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != ChademoPreviousSystemStatus[index]) || (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ConnectorPlugIn != ChademoPreviousConnectorPlugIn[index]) )//if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != ChademoPreviousSystemStatus[index]/*PRE_SYS_MODE[gun_index]*/ )
  2325. {
  2326. //PRE_SYS_MODE[gun_index] = ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus;
  2327. ChademoPreviousSystemStatus[index] = ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus;
  2328. ChademoPreviousConnectorPlugIn[index] = ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ConnectorPlugIn;
  2329. cpinitateMsg.bits[gun_index].StatusNotificationReq = 1;
  2330. statusModeChage[gun_index] = TRUE;
  2331. }
  2332. #if 1 // for TempStopTransaction
  2333. if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_IDLE) && (ShmOCPP16Data->CpMsg.bits[gun_index].StopTransactionReq == 0))
  2334. {
  2335. checkTempStopTransaction(gun_index);
  2336. }
  2337. #endif
  2338. }
  2339. }
  2340. }
  2341. else if((gunType[gun_index] == 'U')||(gunType[gun_index] == 'E'))
  2342. {
  2343. for (int index = 0; index < CCS_QUANTITY; index++)
  2344. {
  2345. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == gun_index)
  2346. {
  2347. if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != CcsPreviousSystemStatus[index]) || (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ConnectorPlugIn != CcsPreviousConnectorPlugIn[index]) )//if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != CcsPreviousSystemStatus[index]/*PRE_SYS_MODE[gun_index]*/ )
  2348. {
  2349. //PRE_SYS_MODE[gun_index] = ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus;
  2350. CcsPreviousSystemStatus[index] = ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus;
  2351. CcsPreviousConnectorPlugIn[index] = ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ConnectorPlugIn;
  2352. cpinitateMsg.bits[gun_index].StatusNotificationReq = 1;
  2353. statusModeChage[gun_index] = TRUE;
  2354. }
  2355. #if 1 // for TempStopTransaction
  2356. if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_IDLE) && (ShmOCPP16Data->CpMsg.bits[gun_index].StopTransactionReq == 0))
  2357. {
  2358. checkTempStopTransaction(gun_index);
  2359. }
  2360. #endif
  2361. }
  2362. }
  2363. }
  2364. else if(gunType[gun_index] == 'G')
  2365. {
  2366. for (int index = 0; index < GB_QUANTITY; index++)
  2367. {
  2368. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == gun_index)
  2369. {
  2370. if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != GbPreviousSystemStatus[index]) || (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ConnectorPlugIn != GbPreviousConnectorPlugIn[index]) )//if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != GbPreviousSystemStatus[index]/*PRE_SYS_MODE[gun_index]*/ )
  2371. {
  2372. //PRE_SYS_MODE[gun_index] = ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus;
  2373. GbPreviousSystemStatus[index] = ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus;
  2374. GbPreviousConnectorPlugIn[index] = ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ConnectorPlugIn;
  2375. cpinitateMsg.bits[gun_index].StatusNotificationReq = 1;
  2376. statusModeChage[gun_index] = TRUE;
  2377. }
  2378. #if 1 // for TempStopTransaction
  2379. if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_IDLE) && (ShmOCPP16Data->CpMsg.bits[gun_index].StopTransactionReq == 0))
  2380. {
  2381. checkTempStopTransaction(gun_index);
  2382. }
  2383. #endif
  2384. }
  2385. }
  2386. }
  2387. else
  2388. {
  2389. for (int index = 0; index < AC_QUANTITY; index++)
  2390. {
  2391. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == gun_index)
  2392. {
  2393. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != AcPreviousSystemStatus[index]) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PilotState != AcPreviousConnectorPlugIn[index]) )//if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != AcPreviousSystemStatus[index]/*PRE_SYS_MODE[gun_index]*/ )
  2394. {
  2395. //PRE_SYS_MODE[gun_index] = ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus;
  2396. AcPreviousSystemStatus[index] = ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus;
  2397. AcPreviousConnectorPlugIn[index] = ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PilotState;
  2398. cpinitateMsg.bits[gun_index].StatusNotificationReq = 1;
  2399. statusModeChage[gun_index] = TRUE;
  2400. }
  2401. #if 1 // for TempStopTransaction
  2402. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_IDLE) && (ShmOCPP16Data->CpMsg.bits[gun_index].StopTransactionReq == 0))
  2403. {
  2404. checkTempStopTransaction(gun_index);
  2405. }
  2406. #endif
  2407. }
  2408. }// END
  2409. }
  2410. if(((server_sign == TRUE) && (SystemInitial > 0)) ||
  2411. ((server_sign == TRUE) && ((statusModeChage[gun_index] == TRUE) || ((time((time_t*)NULL)-clientTime.StatusNotification[gun_index]) > (server_cycle_Status + (GunStatusInterval*gun_index))) || ((cpinitateMsg.bits[gun_index].StatusNotificationReq == 1) && ((time((time_t*)NULL)-clientTime.StatusNotification[gun_index]) > 30)))) )
  2412. {
  2413. if(SystemInitial > 0)
  2414. SystemInitial = SystemInitial -1;
  2415. sendStatusNotificationRequest(gun_index);
  2416. clientTime.StatusNotification[gun_index] = time((time_t*)NULL);
  2417. statusModeChage[gun_index] = FALSE;
  2418. }
  2419. //==============================================
  2420. // Meter report
  2421. //==============================================
  2422. if(/*(server_sign == TRUE) &&*/(isOFFline() == TRUE) || ((time((time_t*)NULL) - clientTime.MeterValues[gun_index])> (atoi((const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemData)- 1 ) ) )
  2423. {
  2424. //check Transaction active
  2425. if(gunType[gun_index] == 'J')
  2426. {
  2427. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  2428. {
  2429. // 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault
  2430. if ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == gun_index)&&(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_CHARGING))
  2431. {
  2432. meterValueSend[gun_index] =1;
  2433. }
  2434. if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == gun_index)&&(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_COMPLETE)) // complete
  2435. {
  2436. sprintf(filenmae,"/Storage/OCPP/TxProfile_%d.json",(gun_index+1));
  2437. if((access(filenmae,F_OK))!=-1)
  2438. {
  2439. DEBUG_INFO("TxProfile exist. OCPP will delete TX Charging Profile\n");
  2440. sprintf(str,"rm -f %s",filenmae);
  2441. system(str);
  2442. }
  2443. }
  2444. }// End for CHAdeMO
  2445. }
  2446. else if((gunType[gun_index] == 'U')||(gunType[gun_index] == 'E'))
  2447. {
  2448. for (int index = 0; index < CCS_QUANTITY; index++)
  2449. {
  2450. // 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault
  2451. if ((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == gun_index)&&(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_CHARGING))
  2452. {
  2453. meterValueSend[gun_index] =1;
  2454. }
  2455. if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == gun_index)&&(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_COMPLETE)) // complete
  2456. {
  2457. sprintf(filenmae,"/Storage/OCPP/TxProfile_%d.json",(gun_index+1));
  2458. if((access(filenmae,F_OK))!=-1)
  2459. {
  2460. DEBUG_INFO("TxProfile exist. OCPP will delete TX Charging Profile\n");
  2461. sprintf(str,"rm -f %s",filenmae);
  2462. system(str);
  2463. }
  2464. }
  2465. } // End for CCS
  2466. }
  2467. else if(gunType[gun_index] == 'G')
  2468. {
  2469. for (int index = 0; index < GB_QUANTITY; index++)
  2470. {
  2471. // 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault
  2472. if ((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == gun_index)&&(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_CHARGING))
  2473. {
  2474. meterValueSend[gun_index] =1;
  2475. }
  2476. if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == gun_index)&&(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_COMPLETE)) // complete
  2477. {
  2478. sprintf(filenmae,"/Storage/OCPP/TxProfile_%d.json",(gun_index+1));
  2479. if((access(filenmae,F_OK))!=-1)
  2480. {
  2481. DEBUG_INFO("TxProfile exist. OCPP will delete TX Charging Profile\n");
  2482. sprintf(str,"rm -f %s",filenmae);
  2483. system(str);
  2484. }
  2485. }
  2486. }// End for GB
  2487. }
  2488. else
  2489. {
  2490. for (int index = 0; index < AC_QUANTITY; index++)
  2491. {
  2492. // 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault
  2493. if ((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == gun_index)&&(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_CHARGING))
  2494. {
  2495. meterValueSend[gun_index] =1;
  2496. }
  2497. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == gun_index)&&(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_COMPLETE)) // complete
  2498. {
  2499. sprintf(filenmae,"/Storage/OCPP/TxProfile_%d.json",(gun_index+1));
  2500. if((access(filenmae,F_OK))!=-1)
  2501. {
  2502. DEBUG_INFO("TxProfile exist. OCPP will delete TX Charging Profile\n");
  2503. sprintf(str,"rm -f %s",filenmae);
  2504. system(str);
  2505. }
  2506. }
  2507. }//End for AC
  2508. }
  2509. clientTime.MeterValues[gun_index] = time((time_t*)NULL);
  2510. if(meterValueSend[gun_index] == 1)
  2511. {
  2512. sendMeterValuesRequest(gun_index);
  2513. #if 1 // for TempStopTransaction
  2514. storeTempStopTransaction(gun_index);
  2515. #endif
  2516. }
  2517. }
  2518. //==============================================
  2519. // Check Connector reserved
  2520. //==============================================
  2521. //===============================
  2522. // Check if Reserve is expired
  2523. //===============================
  2524. if((server_sign == TRUE) && (ShmOCPP16Data->ReserveNow[gun_index].ExpiryDate[0] != 0) )
  2525. {
  2526. double diff_t;
  2527. struct tm tp;
  2528. // current time
  2529. time_t t = time(NULL);
  2530. strptime((char *)ShmOCPP16Data->ReserveNow[gun_index].ExpiryDate, "%Y-%m-%dT%H:%M:%S", &tp);
  2531. tp.tm_isdst = -1;
  2532. time_t utc = mktime(&tp);
  2533. diff_t = difftime(utc, t);
  2534. if(diff_t <= 0)
  2535. {
  2536. DEBUG_INFO("reserve expired.\n");
  2537. memset(ShmOCPP16Data->ReserveNow[gun_index].ExpiryDate,0,sizeof(ShmOCPP16Data->ReserveNow[gun_index].ExpiryDate));
  2538. }
  2539. }//END OF Check if Reserve is expired
  2540. //==========================================
  2541. // csu trigger FirmwareStatusNotificationReq
  2542. //==========================================
  2543. if((server_sign == TRUE) && (ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationReq == 1))
  2544. {
  2545. sendFirmwareStatusNotificationRequest((char *)ShmOCPP16Data->FirmwareStatusNotification.Status);
  2546. }
  2547. //==========================================
  2548. // csu trigger CancelReservationConf
  2549. //==========================================
  2550. if((server_sign == TRUE) && (ShmOCPP16Data->CsMsg.bits[gun_index].CancelReservationConf == 1))
  2551. {
  2552. sendCancelReservationConfirmation((char *)ShmOCPP16Data->CancelReservation[gun_index].guid,(char *)ShmOCPP16Data->CancelReservation[gun_index].ResponseStatus);
  2553. }
  2554. //==========================================
  2555. // csu trigger ChangeAvailabilityConf
  2556. //==========================================
  2557. if((server_sign == TRUE) && (ShmOCPP16Data->CsMsg.bits[gun_index].ChangeAvailabilityConf == 1))
  2558. {
  2559. //sendChangeAvailabilityConfirmation(,(char *)ShmOCPP16Data->ChangeAvailability[gun_index].ResponseStatus);
  2560. }
  2561. //==========================================
  2562. // csu trigger UnlockConnectorConf
  2563. //==========================================
  2564. if((server_sign == TRUE) && (ShmOCPP16Data->CsMsg.bits[gun_index].UnlockConnectorConf == 1))
  2565. {
  2566. sendUnlockConnectorConfirmation((char *)ShmOCPP16Data->UnlockConnector[gun_index].guid, (char *)ShmOCPP16Data->UnlockConnector[gun_index].ResponseStatus);
  2567. ShmOCPP16Data->CsMsg.bits[gun_index].UnlockConnectorConf = 0;
  2568. }
  2569. //==========================================
  2570. // csu trigger ReserveNowConf
  2571. //==========================================
  2572. if((server_sign == TRUE) &&(ShmOCPP16Data->CsMsg.bits[gun_index].ReserveNowConf == 1))
  2573. {
  2574. sendReserveNowTransactionConfirmation((char *)ShmOCPP16Data->ReserveNow[gun_index].guid, (char *)ShmOCPP16Data->ReserveNow[gun_index].ResponseStatus);
  2575. ShmOCPP16Data->CsMsg.bits[gun_index].ReserveNowConf = 0;
  2576. }
  2577. //==========================================
  2578. // csu trigger DataTransferReq
  2579. //==========================================
  2580. if((server_sign == TRUE) &&(ShmOCPP16Data->CsMsg.bits[gun_index].DataTransferReq == 1))
  2581. {
  2582. sendDataTransferRequest(gun_index);
  2583. ShmOCPP16Data->CsMsg.bits[gun_index].DataTransferReq = 0;
  2584. }
  2585. }
  2586. }
  2587. //==========================================
  2588. // send request routine
  2589. //==========================================
  2590. int sendAuthorizeRequest(int gun_index)
  2591. {
  2592. mtrace();
  2593. int result = FAIL;
  2594. char message[100]={0};
  2595. char guid[37];
  2596. char tempdata[65]={0};
  2597. DEBUG_INFO("sendAuthorizeRequest...\n");
  2598. memset(&(ShmOCPP16Data->Authorize.ResponseIdTagInfo),0,sizeof(struct StructIdTagInfo));
  2599. //Local Authorize
  2600. if ((strcmp((const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemData , "TRUE")==0) &&(ShmOCPP16Data->OcppConnStatus == 0))
  2601. {
  2602. DEBUG_INFO("Allow OfflineTx UnknownId Pass !!!!\n");
  2603. strcpy((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.ExpiryDate, "");
  2604. strcpy((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.ParentIdTag, "");
  2605. strcpy((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.Status, "Accepted");
  2606. result = PASS;
  2607. ShmOCPP16Data->SpMsg.bits.AuthorizeReq = 0;
  2608. ShmOCPP16Data->SpMsg.bits.AuthorizeConf = 1; // inform csu
  2609. authorizeRetryTimes = 0;
  2610. return result;
  2611. }
  2612. 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))||
  2613. ((strcmp((const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemData, "TRUE") == 0)&&(strcmp((const char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "TRUE") == 0)))
  2614. {
  2615. OCPP_getIdTag((char *)ShmSysConfigAndInfo->SysConfig.UserId);
  2616. if((strcmp(idTagQuery.idTagstr,"") == 0) || (strcmp(idTagQuery.idTagstatus,"Accepted") != 0) )
  2617. {
  2618. if(strcmp(idTagQuery.idTagstr,"") == 0)
  2619. {
  2620. DEBUG_INFO("offline Local Authorization Fail !!!!, Card %s is blank!!!!\n", idTagQuery.idTagstr);
  2621. }
  2622. if(strcmp(idTagQuery.idTagstatus,"Accepted") != 0)
  2623. {
  2624. DEBUG_INFO("offline Local Authorization Fail !!!!, Card %s is not Accepted!!!!\n", idTagQuery.idTagstr);
  2625. }
  2626. DEBUG_INFO("offline Local Authorization Fail !!!!\n");
  2627. strcpy((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.ExpiryDate, "");
  2628. strcpy((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.ParentIdTag, (const char *)ShmSysConfigAndInfo->SysConfig.UserId);
  2629. strcpy((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.Status, "Invalid");
  2630. ShmOCPP16Data->SpMsg.bits.AuthorizeReq = 0;
  2631. ShmOCPP16Data->SpMsg.bits.AuthorizeConf = 1; // inform csu
  2632. authorizeRetryTimes = 0;
  2633. return result;
  2634. }
  2635. else
  2636. {
  2637. DEBUG_INFO("offline Local Authorization Pass !!!!\n");
  2638. strcpy((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.ExpiryDate, idTagQuery.expiryDate);
  2639. strcpy((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.ParentIdTag, (const char *)ShmSysConfigAndInfo->SysConfig.UserId);
  2640. strcpy((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.Status, idTagQuery.idTagstatus);
  2641. result = PASS;
  2642. ShmOCPP16Data->SpMsg.bits.AuthorizeReq = 0;
  2643. ShmOCPP16Data->SpMsg.bits.AuthorizeConf = 1; // inform csu
  2644. authorizeRetryTimes = 0;
  2645. return result;
  2646. }
  2647. }
  2648. //initailize struct Authorize
  2649. memset(&(ShmOCPP16Data->Authorize), 0 , sizeof(struct StructAuthorize));
  2650. //get data from shared memory
  2651. strcpy((char *)ShmOCPP16Data->Authorize.IdTag, (const char *)ShmSysConfigAndInfo->SysConfig.UserId);
  2652. random_uuid(guid);
  2653. sprintf(message,"[%d,\"%s\",\"Authorize\",{\"idTag\":\"%s\"}]",MESSAGE_TYPE_CALL, guid, ShmOCPP16Data->Authorize.IdTag);
  2654. LWS_Send(message);
  2655. sprintf(tempdata, "Authorize,%d", gun_index);
  2656. if(hashmap_operation(HASH_OP_ADD, guid, tempdata) == 1)
  2657. {
  2658. result = PASS;
  2659. DEBUG_INFO("Authorize mapItem pass\n");
  2660. }
  2661. ShmOCPP16Data->SpMsg.bits.AuthorizeReq = 0;
  2662. return result;
  2663. }
  2664. int sendBootNotificationRequest(void)
  2665. {
  2666. mtrace();
  2667. int result = FAIL;
  2668. char message[500]={0}, payload[700]={0};
  2669. char guid[37]={0};
  2670. char tempdata[65]={0};
  2671. int IsGunCharging = FALSE;
  2672. //check Transaction active
  2673. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  2674. {
  2675. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_CHARGING) //S_CHARGING
  2676. {
  2677. IsGunCharging = TRUE;
  2678. }
  2679. }
  2680. for (int index = 0; index < CCS_QUANTITY; index++)
  2681. {
  2682. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_CHARGING) //S_CHARGING
  2683. {
  2684. IsGunCharging = TRUE;
  2685. }
  2686. }
  2687. for (int index = 0; index < GB_QUANTITY; index++)
  2688. {
  2689. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_CHARGING) //S_CHARGING
  2690. {
  2691. IsGunCharging = TRUE;
  2692. }
  2693. }
  2694. for (int index = 0; index < AC_QUANTITY; index++)
  2695. {
  2696. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_CHARGING) //S_CHARGING
  2697. {
  2698. IsGunCharging = TRUE;
  2699. }
  2700. }
  2701. if(IsGunCharging == TRUE)
  2702. {
  2703. server_sign = TRUE;
  2704. return result;
  2705. }
  2706. // Fill BootNotification fields
  2707. strcpy((char *)ShmOCPP16Data->BootNotification.CbSN,(const char *)ShmOCPP16Data->ChargeBoxId);
  2708. strcpy((char *)ShmOCPP16Data->BootNotification.CpModel,(const char *)ShmSysConfigAndInfo->SysConfig.ModelName);
  2709. strcpy((char *)ShmOCPP16Data->BootNotification.CpSN,(const char *)ShmSysConfigAndInfo->SysConfig.SerialNumber);
  2710. strcpy((char *)ShmOCPP16Data->BootNotification.CpVendor,(const char *)ShmSysConfigAndInfo->SysConfig.chargePointVendor);
  2711. strcpy((char *)ShmOCPP16Data->BootNotification.CpFwVersion,(const char *)ShmSysConfigAndInfo->SysInfo.CsuRootFsFwRev);
  2712. strcpy((char *)ShmOCPP16Data->BootNotification.CpIccid,(const char *)ShmSysConfigAndInfo->SysConfig.TelecomInterface.TelcomSimIccid);
  2713. strcpy((char *)ShmOCPP16Data->BootNotification.CpImsi,(const char *)ShmSysConfigAndInfo->SysConfig.TelecomInterface.TelcomSimImsi);
  2714. sprintf(payload, "{\"chargeBoxSerialNumber\":\"%s\",\"chargePointModel\":\"%s\",\"chargePointSerialNumber\":\"%s\",\"chargePointVendor\":\"%s\",\"firmwareVersion\":\"%s\",\"iccid\":\"%s\",\"imsi\":\"%s\"} ",
  2715. ShmOCPP16Data->ChargeBoxId
  2716. ,ShmSysConfigAndInfo->SysConfig.ModelName
  2717. ,ShmSysConfigAndInfo->SysConfig.SerialNumber
  2718. ,ShmSysConfigAndInfo->SysConfig.chargePointVendor
  2719. ,ShmOCPP16Data->BootNotification.CpFwVersion
  2720. ,ShmOCPP16Data->BootNotification.CpIccid
  2721. ,ShmOCPP16Data->BootNotification.CpImsi);
  2722. random_uuid(guid);
  2723. sprintf(message,"[%d,\"%s\",\"%s\",%s]",MESSAGE_TYPE_CALL, guid, "BootNotification", payload);
  2724. LWS_Send(message);
  2725. sprintf(tempdata, "BootNotification,0");
  2726. 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*/)
  2727. {
  2728. result = PASS;
  2729. }
  2730. memset(queuedata, 0, sizeof(queuedata));
  2731. strcpy(queuedata,message);
  2732. return result;
  2733. }
  2734. int sendDataTransferRequest(int gun_index)
  2735. {
  2736. mtrace();
  2737. char message[1000]={0};
  2738. char guid[37]={0};
  2739. char tempdata[65]={0};
  2740. int result = FAIL;
  2741. //[2,"696e8a35-f394-45e3-a0c7-7098b86f38a6","DataTransfer",{"vendorId":"Phihong","messageId":"FeePerKWH","data":"1"}]
  2742. random_uuid(guid);
  2743. sprintf(message,"[%d,\"%s\",\"DataTransfer\",{\"vendorId\":\"%s\",\"messageId\":\"%s\",\"data\":\"%s\"}]",
  2744. MESSAGE_TYPE_CALL,
  2745. guid,
  2746. ShmOCPP16Data->DataTransfer[gun_index].VendorId,
  2747. ShmOCPP16Data->DataTransfer[gun_index].MessageId,
  2748. ShmOCPP16Data->DataTransfer[gun_index].Data);
  2749. LWS_Send(message);
  2750. sprintf(tempdata, "DataTransfer,%d", (gun_index + 1));
  2751. if(hashmap_operation(HASH_OP_ADD, guid, tempdata) == 1)
  2752. {
  2753. result = PASS;
  2754. DEBUG_INFO("DataTransfer mapItem pass\n");
  2755. }
  2756. return result;
  2757. }
  2758. int sendFirmwareVersionByDataTransfer(void)
  2759. {
  2760. int8_t result = FAIL;
  2761. json_object *FirmwareDataTransfer = json_object_new_object();
  2762. // AC & DC model
  2763. json_object_object_add(FirmwareDataTransfer, "CsuBootLoadFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.CsuBootLoadFwRev));
  2764. json_object_object_add(FirmwareDataTransfer, "CsuKernelFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.CsuKernelFwRev));
  2765. json_object_object_add(FirmwareDataTransfer, "CsuRootFsFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.CsuRootFsFwRev));
  2766. json_object_object_add(FirmwareDataTransfer, "CsuPrimFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.CsuPrimFwRev));
  2767. // DC model
  2768. if((ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D'))
  2769. {
  2770. json_object_object_add(FirmwareDataTransfer, "FanModuleFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.FanModuleFwRev));
  2771. json_object_object_add(FirmwareDataTransfer, "RelayModuleFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.RelayModuleFwRev));
  2772. json_object_object_add(FirmwareDataTransfer, "LedModuleFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.LedModuleFwRev));
  2773. json_object_object_add(FirmwareDataTransfer, "Connector1FwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.Connector1FwRev));
  2774. }
  2775. if((ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D') &&
  2776. ((gunType[1] != '0') || (gunType[2] != '0') || (gunType[3] != '0')))
  2777. {
  2778. json_object_object_add(FirmwareDataTransfer, "Connector2FwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.Connector2FwRev));
  2779. }
  2780. // 4G model
  2781. if((ShmSysConfigAndInfo->SysConfig.ModelName[10]=='T'))
  2782. {
  2783. json_object_object_add(FirmwareDataTransfer, "TelcomModemFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysConfig.TelecomInterface.TelcomSoftwareVer));
  2784. }
  2785. sprintf((char*)ShmOCPP16Data->DataTransfer[0].VendorId, "Phihong Technology");
  2786. sprintf((char*)ShmOCPP16Data->DataTransfer[0].MessageId, "ID_FirmwareVersion");
  2787. sprintf((char*)ShmOCPP16Data->DataTransfer[0].Data, json_object_to_json_string(FirmwareDataTransfer));
  2788. if(sendDataTransferRequest(0))
  2789. {
  2790. result = PASS;
  2791. }
  2792. return result;
  2793. }
  2794. int sendDiagnosticsStatusNotificationRequest(char *status)
  2795. {
  2796. mtrace();
  2797. int result = FAIL;
  2798. char message[110]={0};
  2799. char guid[37]={0};
  2800. char tempdata[65]={0};
  2801. //[ 2, "9f7bced1-b8b1-40ec-b3bb-2e15630e3cdc", "DiagnosticsStatusNotification", { "status": "Idle" } ]
  2802. DEBUG_INFO("sendDiagnosticsStatusNotificationRequest \n");
  2803. sprintf((char *)ShmOCPP16Data->DiagnosticsStatusNotification.Status,"%s",(const char *)status);
  2804. random_uuid(guid);
  2805. sprintf(message,"[%d,\"%s\",\"DiagnosticsStatusNotification\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALL, guid,status);
  2806. LWS_Send(message);
  2807. sprintf(tempdata, "DiagnosticsStatusNotification,%d", 0);
  2808. if(hashmap_operation(HASH_OP_ADD, guid, tempdata) == 1)
  2809. {
  2810. result = PASS;
  2811. //DEBUG_INFO("DiagnosticsStatusNotification mapItem pass\n");
  2812. }
  2813. //#ifdef SystemLogMessage
  2814. //DEBUG_INFO(">>>>>DiagnosticsStatusNotification request\n");
  2815. //DEBUG_INFO("Message: %s\n", SendBuffer);
  2816. //DEBUG_INFO("After push hash length: %d\n", hashmapForMessageLength()/*hashmap_length(hashMap)*/);
  2817. //#endif
  2818. ShmOCPP16Data->SpMsg.bits.DiagnosticsStatusNotificationReq = 0;
  2819. ShmOCPP16Data->SpMsg.bits.DiagnosticsStatusNotificationConf = 0;
  2820. //record status
  2821. if(strcmp(status,"Idle")==0)
  2822. {
  2823. DiagnosticsStatusNotificationStatus = DIAGNOSTIC_STATUS_IDLE;
  2824. }
  2825. else if(strcmp(status,"Uploaded")==0)
  2826. {
  2827. DiagnosticsStatusNotificationStatus = DIAGNOSTIC_STATUS_UPLOADED;
  2828. }
  2829. else if(strcmp(status,"UploadFailed")==0)
  2830. {
  2831. DiagnosticsStatusNotificationStatus = DIAGNOSTIC_STATUS_UPLOAD_FAIL;
  2832. }
  2833. else if(strcmp(status,"Uploading")==0)
  2834. {
  2835. DiagnosticsStatusNotificationStatus = DIAGNOSTIC_STATUS_UPLOADING;
  2836. }
  2837. return result;
  2838. }
  2839. int sendFirmwareStatusNotificationRequest(char *status)
  2840. {
  2841. mtrace();
  2842. int result = FAIL;
  2843. char message[110]={0};
  2844. char guid[37]={0};
  2845. char tempdata[65]={0};
  2846. // [ 2, "eb841424-ae56-42b0-8c84-d5296018c33c", "FirmwareStatusNotification", { "status": "Downloaded" } ]
  2847. DEBUG_INFO("sendFirmwareStatusNotificationRequest \n");
  2848. sprintf((char *)ShmOCPP16Data->FirmwareStatusNotification.Status, "%s", (const char *)status);
  2849. random_uuid(guid);
  2850. sprintf(message,"[%d,\"%s\",\"FirmwareStatusNotification\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALL, guid, status);
  2851. LWS_Send(message);
  2852. sprintf(tempdata, "FirmwareStatusNotification,%d", 0);
  2853. 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*/)
  2854. {
  2855. result = PASS;
  2856. DEBUG_INFO("FirmwareStatusNotification mapItem pass\n");
  2857. }
  2858. //#ifdef SystemLogMessage
  2859. //DEBUG_INFO(">>>>>FirmwareStatusNotification request\n");
  2860. //DEBUG_INFO("Message: %s\n", SendBuffer);
  2861. //#endif
  2862. ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationReq = 0;
  2863. ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationConf = 0;
  2864. //record status
  2865. if(strcmp(status,"Downloaded")==0)
  2866. {
  2867. FirmwareStatusNotificationStatus = FIRMWARE_STATUS_DOWNLOADED;
  2868. }
  2869. else if(strcmp(status,"DownloadFailed")==0)
  2870. {
  2871. FirmwareStatusNotificationStatus = FIRMWARE_STATUS_DOWNLOAD_DAILED;
  2872. }
  2873. else if(strcmp(status,"Downloading")==0)
  2874. {
  2875. FirmwareStatusNotificationStatus = FIRMWARE_STATUS_DOWNLOADING;
  2876. }
  2877. else if(strcmp(status,"Idle")==0)
  2878. {
  2879. FirmwareStatusNotificationStatus = FIRMWARE_STATUS_IDLE;
  2880. }
  2881. else if(strcmp(status,"InstallationFailed")==0)
  2882. {
  2883. FirmwareStatusNotificationStatus = FIRMWARE_STATUS_INSTALLATION_FAILED;
  2884. }
  2885. else if(strcmp(status,"Installing")==0)
  2886. {
  2887. FirmwareStatusNotificationStatus = FIRMWARE_STATUS_INSTALLING;
  2888. }
  2889. else if(strcmp(status,"Installed")==0)
  2890. {
  2891. FirmwareStatusNotificationStatus = FIRMWARE_STATUS_INSTALLED;
  2892. }
  2893. return result;
  2894. }
  2895. int sendHeartbeatRequest(int gun_index)
  2896. {
  2897. mtrace();
  2898. int result = FAIL;
  2899. char message[80]={0};
  2900. char guid[37]={0};
  2901. char tempdata[65]={0};
  2902. random_uuid(guid);
  2903. sprintf(message, "[%d,\"%s\",\"Heartbeat\",{ }]"
  2904. , MESSAGE_TYPE_CALL
  2905. , guid );
  2906. LWS_Send(message);
  2907. sprintf(tempdata, "Heartbeat,%d", 0);
  2908. 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*/)
  2909. {
  2910. result = PASS;
  2911. }
  2912. return result;
  2913. }
  2914. int sendStartTransactionRequest(int gun_index)
  2915. {
  2916. mtrace();
  2917. int result = FAIL;
  2918. char message[250]={0};
  2919. char guid[37]={0};
  2920. struct timeval tmnow;
  2921. struct tm *tm;
  2922. char buf[28];//, usec_buf[6];
  2923. char tempdata[65]={0};
  2924. int tempIndex = 0;
  2925. DEBUG_INFO("sendStartTransactionRequest...\n");
  2926. gettimeofday(&tmnow, NULL);
  2927. time_t t;
  2928. t = time(NULL);
  2929. /*UTC time and date*/
  2930. tm = gmtime(&t);
  2931. strftime(buf,28,"%Y-%m-%dT%H:%M:%SZ", tm);
  2932. ShmOCPP16Data->StartTransaction[gun_index].ConnectorId = gun_index +1 ; // gun start from 1~
  2933. strcpy((char *)ShmOCPP16Data->StartTransaction[gun_index].Timestamp, buf);
  2934. //strcpy((char *)ShmOCPP16Data->StartTransaction[gun_index].IdTag, (const char *)ShmSysConfigAndInfo->SysConfig.UserId);
  2935. // clear StartTransaction Response
  2936. strcpy((char *)ShmOCPP16Data->StartTransaction[gun_index].ResponseIdTagInfo.ExpiryDate, "");
  2937. strcpy((char *)ShmOCPP16Data->StartTransaction[gun_index].ResponseIdTagInfo.ParentIdTag, "");
  2938. strcpy((char *)ShmOCPP16Data->StartTransaction[gun_index].ResponseIdTagInfo.Status, "");
  2939. ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId = 0;
  2940. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DCcc
  2941. if(gunType[gun_index] == 'J')
  2942. {
  2943. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  2944. {
  2945. tempIndex = ((gun_index==2) ? 1: 0);
  2946. }
  2947. else
  2948. {
  2949. tempIndex = gun_index;
  2950. }
  2951. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  2952. {
  2953. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  2954. {
  2955. ShmOCPP16Data->StartTransaction[gun_index].MeterStart = ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargedEnergy;
  2956. ShmOCPP16Data->StartTransaction[gun_index].ReservationId = ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ReservationId;
  2957. }
  2958. }
  2959. }
  2960. else if((gunType[gun_index] == 'U')||(gunType[gun_index] == 'E'))
  2961. {
  2962. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  2963. {
  2964. tempIndex = ((gun_index==2) ? 1: 0);
  2965. }
  2966. else
  2967. {
  2968. tempIndex = gun_index;
  2969. }
  2970. for (int index = 0; index < CCS_QUANTITY; index++)
  2971. {
  2972. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  2973. {
  2974. ShmOCPP16Data->StartTransaction[gun_index].MeterStart = ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargedEnergy;
  2975. ShmOCPP16Data->StartTransaction[gun_index].ReservationId = ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ReservationId;
  2976. }
  2977. }
  2978. }
  2979. else if(gunType[gun_index] == 'G')
  2980. {
  2981. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  2982. {
  2983. tempIndex = ((gun_index==2) ? 1: 0);
  2984. }
  2985. else
  2986. {
  2987. tempIndex = gun_index;
  2988. }
  2989. for (int index = 0; index < GB_QUANTITY; index++)
  2990. {
  2991. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  2992. {
  2993. ShmOCPP16Data->StartTransaction[gun_index].MeterStart = ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargedEnergy;
  2994. ShmOCPP16Data->StartTransaction[gun_index].ReservationId = ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ReservationId;
  2995. }
  2996. }
  2997. }
  2998. else
  2999. {
  3000. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  3001. {
  3002. tempIndex = 2;
  3003. }
  3004. else
  3005. {
  3006. tempIndex = gun_index;
  3007. }
  3008. for (int index = 0; index < AC_QUANTITY; index++)
  3009. {
  3010. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  3011. {
  3012. ShmOCPP16Data->StartTransaction[gun_index].MeterStart = ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PowerConsumption;
  3013. ShmOCPP16Data->StartTransaction[gun_index].ReservationId = ShmSysConfigAndInfo->SysInfo.AcChargingData[index].ReservationId;
  3014. }
  3015. }
  3016. }
  3017. random_uuid(guid);
  3018. if(ShmOCPP16Data->StartTransaction[gun_index].ReservationId == -1)
  3019. {
  3020. sprintf(message, "[%d,\"%s\",\"StartTransaction\",{\"connectorId\":%d,\"idTag\":\"%s\",\"meterStart\":%d,\"timestamp\":\"%s\"}]"
  3021. , MESSAGE_TYPE_CALL
  3022. , guid
  3023. , ShmOCPP16Data->StartTransaction[gun_index].ConnectorId
  3024. , ShmOCPP16Data->StartTransaction[gun_index].IdTag
  3025. , ShmOCPP16Data->StartTransaction[gun_index].MeterStart
  3026. , ShmOCPP16Data->StartTransaction[gun_index].Timestamp );
  3027. }
  3028. else
  3029. {
  3030. sprintf(message, "[%d,\"%s\",\"StartTransaction\",{\"connectorId\":%d,\"idTag\":\"%s\",\"meterStart\":%d,\"reservationId\":%d,\"timestamp\":\"%s\"}]"
  3031. , MESSAGE_TYPE_CALL
  3032. , guid
  3033. , ShmOCPP16Data->StartTransaction[gun_index].ConnectorId
  3034. , ShmOCPP16Data->StartTransaction[gun_index].IdTag
  3035. , ShmOCPP16Data->StartTransaction[gun_index].MeterStart
  3036. , ShmOCPP16Data->StartTransaction[gun_index].ReservationId
  3037. , ShmOCPP16Data->StartTransaction[gun_index].Timestamp );
  3038. }
  3039. sprintf(tempdata, "StartTransaction,%d", (gun_index));
  3040. 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*/)
  3041. {
  3042. result = PASS;
  3043. }
  3044. strcpy(queuedata, message);
  3045. queue_operation(4, guid, queuedata );//addq(guid, queuedata); ---> remove temporally
  3046. if(GetTransactionQueueNum() == 1)
  3047. {
  3048. LWS_Send(message);
  3049. }
  3050. return result;
  3051. }
  3052. int sendStatusNotificationRequest(int gun_index)
  3053. {
  3054. mtrace();
  3055. int result = FAIL;
  3056. char message[600]={0};
  3057. char guid[37];
  3058. int currentStatus = 0;
  3059. struct timeval tmnow;
  3060. struct tm *tm;
  3061. char buf[28];//, usec_buf[6];
  3062. char tempdata[65]={0};
  3063. int tempIndex = 0;
  3064. gettimeofday(&tmnow, NULL);
  3065. time_t t;
  3066. t = time(NULL);
  3067. /*UTC time and date*/
  3068. tm = gmtime(&t);
  3069. strftime(buf,28,"%Y-%m-%dT%H:%M:%SZ", tm);
  3070. printf("%s",buf);
  3071. ShmOCPP16Data->StatusNotification[gun_index].ConnectorId = (gun_index + 1);
  3072. //strcpy(ShmOCPP16Data->StatusNotification[gun_index].ErrorCode, "NoError"); --- CSU Setting
  3073. // it's option
  3074. strcpy((char *)ShmOCPP16Data->StatusNotification[gun_index].Info, "");
  3075. /*
  3076. enum _SYSTEM_STATUS
  3077. {
  3078. S_BOOTING = 0,
  3079. S_IDLE, = 1
  3080. S_AUTHORIZING, =2
  3081. S_REASSIGN_CHECK, =3
  3082. S_REASSIGN, =4
  3083. S_PRECHARGE, =5
  3084. S_PREPARING_FOR_EV, =6
  3085. S_PREPARING_FOR_EVSE, =7
  3086. S_CHARGING, =8
  3087. S_TERMINATING, =9
  3088. S_COMPLETE, =10
  3089. S_ALARM, =11
  3090. S_FAULT =12
  3091. }
  3092. */
  3093. //check Transaction active
  3094. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DCcc
  3095. if(gunType[gun_index] == 'J')
  3096. {
  3097. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  3098. {
  3099. tempIndex = ((gun_index==2) ? 1: 0);
  3100. }
  3101. else
  3102. {
  3103. tempIndex = gun_index;
  3104. }
  3105. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  3106. {
  3107. if ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex))
  3108. {
  3109. if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_IDLE)//S_IDLE
  3110. {
  3111. currentStatus = 0; //OCPP Status: Available
  3112. }
  3113. else if ( ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus >= SYS_MODE_PREPARING)&&( ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus <= SYS_MODE_PREPARE_FOR_EVSE))
  3114. || ( ( ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus >= SYS_MODE_CCS_PRECHARGE_STEP0) && ( ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus <= SYS_MODE_CCS_PRECHARGE_STEP1))
  3115. || (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_AUTHORIZING)) //S_PRECHARGE
  3116. {
  3117. currentStatus = 1; //OCPP Status: Preparing
  3118. }
  3119. else if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_CHARGING) //S_CHARGING
  3120. {
  3121. currentStatus = 2; //OCPP Status: Charging
  3122. }
  3123. else if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_COMPLETE) //S_COMPLETE
  3124. {
  3125. currentStatus = 5; //OCPP Status: Finishing
  3126. }
  3127. else if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_TERMINATING) // S_TERMINATING ---> SuspendedEV
  3128. {
  3129. currentStatus = 4; //OCPP Status: SuspendedEV
  3130. }
  3131. 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)) // ---> Unavailable
  3132. {
  3133. currentStatus = 7; //OCPP Status: Unavailable
  3134. }
  3135. else if ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_FAULT)|| (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_ALARM)) //S_ALARM,S_FAULT ---> Faulted
  3136. {
  3137. currentStatus = 8; //OCPP Status: Faulted
  3138. }
  3139. else if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_RESERVATION) // ---> Reserved
  3140. {
  3141. currentStatus = 6; //OCPP Status: Reserved
  3142. }
  3143. } //end of the same index
  3144. }//end of for CHAdeMO_QUANTITY
  3145. }
  3146. else if((gunType[gun_index] == 'U')||(gunType[gun_index] == 'E'))
  3147. {
  3148. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  3149. {
  3150. tempIndex = ((gun_index==2) ? 1: 0);
  3151. }
  3152. else
  3153. {
  3154. tempIndex = gun_index;
  3155. }
  3156. for (int index = 0; index < CCS_QUANTITY; index++)
  3157. {
  3158. if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  3159. {
  3160. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_IDLE) //S_IDLE
  3161. {
  3162. currentStatus = 0; //OCPP Status: Available
  3163. }
  3164. else if ( ((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus >= SYS_MODE_PREPARING)&&( ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus <= SYS_MODE_PREPARE_FOR_EVSE))
  3165. || ( ( ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus >= SYS_MODE_CCS_PRECHARGE_STEP0) && ( ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus <= SYS_MODE_CCS_PRECHARGE_STEP1))
  3166. || (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_AUTHORIZING)) //S_PRECHARGE
  3167. {
  3168. currentStatus = 1; //OCPP Status: Preparing
  3169. }
  3170. else if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_CHARGING) //S_CHARGING
  3171. {
  3172. currentStatus = 2; //OCPP Status: Charging
  3173. }
  3174. else if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_COMPLETE) //S_COMPLETE
  3175. {
  3176. currentStatus = 5; //OCPP Status: Finishing
  3177. }
  3178. else if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_TERMINATING) //S_TERMINATING ---> SuspendedEV
  3179. {
  3180. currentStatus = 4; //OCPP Status: SuspendedEV
  3181. }
  3182. 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)) // ---> Unavailable
  3183. {
  3184. currentStatus = 7; //OCPP Status : Unavailable
  3185. }
  3186. else if ((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_FAULT) || (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_ALARM)) //S_ALARM ,S_FAULT ---> Faulted
  3187. {
  3188. currentStatus = 8; //OCPP Status: Faulted
  3189. }
  3190. else if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_RESERVATION) // ---> Reserved
  3191. {
  3192. currentStatus = 6; //OCPP Status: Reserved
  3193. }
  3194. } //end of the same index
  3195. } // end of for CCS_QUANTITY
  3196. }
  3197. else if(gunType[gun_index] == 'G')
  3198. {
  3199. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  3200. {
  3201. tempIndex = ((gun_index==2) ? 1: 0);
  3202. }
  3203. else
  3204. {
  3205. tempIndex = gun_index;
  3206. }
  3207. for (int index = 0; index < GB_QUANTITY; index++)
  3208. {
  3209. if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  3210. {
  3211. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_IDLE) //S_IDLE
  3212. {
  3213. currentStatus = 0; //OCPP Status: Available
  3214. }
  3215. else if (((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus >= SYS_MODE_PREPARING)&&( ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus <= SYS_MODE_PREPARE_FOR_EVSE))
  3216. || ( ( ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus >= SYS_MODE_CCS_PRECHARGE_STEP0) && ( ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus <= SYS_MODE_CCS_PRECHARGE_STEP1))
  3217. || (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_AUTHORIZING)) //S_PRECHARGE
  3218. {
  3219. currentStatus = 1; //OCPP Status: Preparing
  3220. }
  3221. else if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_CHARGING) //S_CHARGING
  3222. {
  3223. currentStatus = 2; //OCPP Status: Charging
  3224. }
  3225. else if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_COMPLETE) //S_COMPLETE
  3226. {
  3227. currentStatus = 5; //OCPP Status: Finishing
  3228. }
  3229. else if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_TERMINATING) // S_TERMINATING ---> SuspendedEV
  3230. {
  3231. currentStatus = 4; //OCPP Status: SuspendedEV
  3232. }
  3233. 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)) // ---> Unavailable
  3234. {
  3235. currentStatus = 7; //OCPP Status: Unavailable
  3236. }
  3237. else if ((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_FAULT) || (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_ALARM)) //S_ALARM ,S_FAULT ---> Faulted
  3238. {
  3239. currentStatus = 8; //OCPP Status: Faulted
  3240. }
  3241. else if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_RESERVATION) // ---> Reserved
  3242. {
  3243. currentStatus = 6; //OCPP Status: Reserved
  3244. }
  3245. } //end of the same index
  3246. } // end of for GB_QUANTITY
  3247. }
  3248. else
  3249. {
  3250. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  3251. {
  3252. tempIndex = 2;
  3253. }
  3254. else
  3255. {
  3256. tempIndex = gun_index;
  3257. }
  3258. for (int index = 0; index < AC_QUANTITY; index++)
  3259. {
  3260. if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  3261. {
  3262. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_IDLE) //SYS_MODE_IDLE
  3263. {
  3264. 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))
  3265. {
  3266. currentStatus = 1; //OCPP Status: Preparing
  3267. }
  3268. else
  3269. {
  3270. currentStatus = 0; //OCPP Status: Available
  3271. }
  3272. }
  3273. else if ((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_PREPARING) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_AUTHORIZING)) //SYS_MODE_PREPARING
  3274. {
  3275. currentStatus = 1; //OCPP Status: Preparing
  3276. }
  3277. else if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_CHARGING) //SYS_MODE_CHARGING
  3278. {
  3279. currentStatus = 2; //OCPP Status: Charging
  3280. }
  3281. else if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_COMPLETE) //SYS_MODE_COMPLETE
  3282. {
  3283. currentStatus = 5; //OCPP Status: Finishing
  3284. }
  3285. else if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_TERMINATING) // S_TERMINATING ---> SuspendedEV
  3286. {
  3287. currentStatus = 4; //OCPP Status: SuspendedEV
  3288. }
  3289. 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)) // ---> Unavailable
  3290. {
  3291. currentStatus = 7; //OCPP Status: Unavailable
  3292. }
  3293. else if ((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_FAULT) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_ALARM)) //S_ALARM,S_FAULT ---> Faulted
  3294. {
  3295. currentStatus = 8; //OCPP Status: Faulted
  3296. }
  3297. else if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_RESERVATION) // ---> Reserved
  3298. {
  3299. currentStatus = 6; //OCPP Status: Reserved
  3300. }
  3301. }//end of the same index
  3302. }//end of for AC_QUANTITY
  3303. }
  3304. //it's option
  3305. strcpy((char *)ShmOCPP16Data->StatusNotification[gun_index].Timestamp, buf);
  3306. strcpy((char *)ShmOCPP16Data->StatusNotification[gun_index].VendorId, "PhihongTechnology");
  3307. strcpy((char *)ShmOCPP16Data->StatusNotification[gun_index].Status, ChargePointStatusStr[currentStatus]);
  3308. random_uuid(guid);
  3309. sprintf(message, "[%d,\"%s\",\"StatusNotification\",{\"connectorId\":%d,\"errorCode\":\"%s\",\"info\":\"%s\",\"status\":\"%s\",\"timestamp\":\"%s\",\"vendorId\":\"%s\",\"vendorErrorCode\":\"%s\"}]"
  3310. , MESSAGE_TYPE_CALL
  3311. , guid
  3312. , ShmOCPP16Data->StatusNotification[gun_index].ConnectorId
  3313. , ShmOCPP16Data->StatusNotification[gun_index].ErrorCode
  3314. , ShmOCPP16Data->StatusNotification[gun_index].Info
  3315. , ShmOCPP16Data->StatusNotification[gun_index].Status
  3316. , ShmOCPP16Data->StatusNotification[gun_index].Timestamp
  3317. , ShmOCPP16Data->StatusNotification[gun_index].VendorId
  3318. , ShmOCPP16Data->StatusNotification[gun_index].VendorErrorCode);
  3319. LWS_Send(message);
  3320. sprintf(tempdata, "StatusNotification,%d", (gun_index));
  3321. 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*/)
  3322. {
  3323. result = PASS;
  3324. }
  3325. return result;
  3326. }
  3327. int sendStopTransactionRequest(int gun_index)
  3328. {
  3329. mtrace();
  3330. int result = FAIL;
  3331. //char message[1500]={0};
  3332. char guid[37]={0};
  3333. char tempdata[65]={0};
  3334. int tempIndex = 0;
  3335. //int idx_sample=0;
  3336. DEBUG_INFO("sendStopTransactionRequest...\n");
  3337. memset(queuedata, 0, sizeof(queuedata));
  3338. //ENERGY_ACTIVE_IMPORT_REGISTER
  3339. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DCcc
  3340. if(gunType[gun_index] == 'J')
  3341. {
  3342. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  3343. {
  3344. tempIndex = ((gun_index==2) ? 1: 0);
  3345. }
  3346. else
  3347. {
  3348. tempIndex = gun_index;
  3349. }
  3350. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  3351. {
  3352. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  3353. {
  3354. ShmOCPP16Data->StopTransaction[gun_index].MeterStop = ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PowerConsumption;
  3355. }
  3356. }// END OF CHAdeMO_QUANTITY
  3357. }
  3358. else if((gunType[gun_index] == 'U')||(gunType[gun_index] == 'E'))
  3359. {
  3360. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  3361. {
  3362. tempIndex = ((gun_index==2) ? 1: 0);
  3363. }
  3364. else
  3365. {
  3366. tempIndex = gun_index;
  3367. }
  3368. for (int index = 0; index < CCS_QUANTITY; index++)
  3369. {
  3370. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  3371. {
  3372. ShmOCPP16Data->StopTransaction[gun_index].MeterStop = ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PowerConsumption;
  3373. }
  3374. }// END OF CCS_QUANTITY
  3375. }
  3376. else if(gunType[gun_index] == 'G')
  3377. {
  3378. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  3379. {
  3380. tempIndex = ((gun_index==2) ? 1: 0);
  3381. }
  3382. else
  3383. {
  3384. tempIndex = gun_index;
  3385. }
  3386. for (int index = 0; index < GB_QUANTITY; index++)
  3387. {
  3388. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  3389. {
  3390. ShmOCPP16Data->StopTransaction[gun_index].MeterStop = ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PowerConsumption;
  3391. }
  3392. }// END OF GB_QUANTITY
  3393. }
  3394. else
  3395. {
  3396. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  3397. {
  3398. tempIndex = 2;
  3399. }
  3400. else
  3401. {
  3402. tempIndex = gun_index;
  3403. }
  3404. for (int index = 0; index < AC_QUANTITY; index++)
  3405. {
  3406. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  3407. {
  3408. ShmOCPP16Data->StopTransaction[gun_index].MeterStop = ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PowerConsumption;
  3409. }
  3410. }// END OF AC_QUANTITY
  3411. }
  3412. //Stop Transaction Time
  3413. struct timeval tmnow;
  3414. struct tm *tm;
  3415. char buf[28];//, usec_buf[6];
  3416. gettimeofday(&tmnow, NULL);
  3417. time_t t;
  3418. t = time(NULL);
  3419. /*UTC time and date*/
  3420. tm = gmtime(&t);
  3421. strftime(buf,28,"%Y-%m-%dT%H:%M:%SZ", tm);
  3422. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].Timestamp,buf);
  3423. ShmOCPP16Data->StopTransaction[gun_index].TransactionId = ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId;
  3424. random_uuid(guid);
  3425. /***********************************transactionData******************************************************/
  3426. memset(ShmOCPP16Data->StopTransaction[gun_index].TransactionData, 0, sizeof(sizeof(struct StructMeterValue)));
  3427. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].TimeStamp, buf);
  3428. //=================================
  3429. // Transaction_Begin
  3430. //=================================
  3431. // Energy.Active.Export.Interval
  3432. //idx_sample=0;
  3433. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Value, "%.1f",(float)(ShmOCPP16Data->StartTransaction[gun_index].MeterStart)); // MeterStart is 0~6553.5 kWh
  3434. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Context,ReadingContextStr[ReadingContext_Transaction_Begin]);
  3435. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Format,ValueFormatStr[Raw]);
  3436. 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*/]);
  3437. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DCcc
  3438. if((gunType[gun_index] == 'J')||(gunType[gun_index] == 'U')||(gunType[gun_index] == 'E')||(gunType[gun_index] == 'G'))
  3439. {
  3440. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Phase,PhaseStr[L3_N]);
  3441. }
  3442. else
  3443. {
  3444. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Phase,PhaseStr[L1_N]);
  3445. }
  3446. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Location,LocationStr[Location_Outlet]);
  3447. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Unit,UnitOfMeasureStr[UnitOfMeasure_kWh]);
  3448. //=================================
  3449. // Transaction_End
  3450. //=================================
  3451. //Current.Export
  3452. //idx_sample=1;
  3453. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G : GBT DC
  3454. if(gunType[gun_index] == 'J')
  3455. {
  3456. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  3457. {
  3458. tempIndex = ((gun_index==2) ? 1: 0);
  3459. }
  3460. else
  3461. {
  3462. tempIndex = gun_index;
  3463. }
  3464. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  3465. {
  3466. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  3467. {
  3468. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargingCurrent );// PresentChargingCurrent is 0~6553.5 amp
  3469. }
  3470. }// End of for CHAdeMO_QUANTITY
  3471. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase,PhaseStr[L3_N]);
  3472. }
  3473. else if((gunType[gun_index] == 'U')||(gunType[gun_index] == 'E'))
  3474. {
  3475. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  3476. {
  3477. tempIndex = ((gun_index==2) ? 1: 0);
  3478. }
  3479. else
  3480. {
  3481. tempIndex = gun_index;
  3482. }
  3483. for (int index = 0; index < CCS_QUANTITY; index++)
  3484. {
  3485. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  3486. {
  3487. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargingCurrent );// PresentChargingCurrent is 0~6553.5 amp
  3488. }
  3489. }// End of for CCS_QUANTITY
  3490. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase,PhaseStr[L3_N]);
  3491. }
  3492. else if(gunType[gun_index] == 'G')
  3493. {
  3494. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  3495. {
  3496. tempIndex = ((gun_index==2) ? 1: 0);
  3497. }
  3498. else
  3499. {
  3500. tempIndex = gun_index;
  3501. }
  3502. for (int index = 0; index < GB_QUANTITY; index++)
  3503. {
  3504. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  3505. {
  3506. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingCurrent );// PresentChargingCurrent is 0~6553.5 amp
  3507. }
  3508. }// End of for GB_QUANTITY
  3509. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase,PhaseStr[L3_N]);
  3510. }
  3511. else
  3512. {
  3513. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  3514. {
  3515. tempIndex = 2;
  3516. }
  3517. else
  3518. {
  3519. tempIndex = gun_index;
  3520. }
  3521. for (int index = 0; index < AC_QUANTITY; index++)
  3522. {
  3523. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  3524. {
  3525. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingCurrent );// 0~6553.5 amp for EVSE
  3526. }
  3527. }// End of for AC_QUANTITY
  3528. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase,PhaseStr[L1_N]);
  3529. }
  3530. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  3531. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Format,ValueFormatStr[Raw]);
  3532. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Measurand,MeasurandStr[Current_Import]);
  3533. //strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase,PhaseStr[L1_N]);
  3534. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Location,LocationStr[Location_Outlet]);
  3535. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Unit,UnitOfMeasureStr[UnitOfMeasure_A]);
  3536. //Energy.Active.Export.Interval
  3537. //idx_sample=2;
  3538. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  3539. if(gunType[gun_index] == 'J')
  3540. {
  3541. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  3542. {
  3543. tempIndex = ((gun_index==2) ? 1: 0);
  3544. }
  3545. else
  3546. {
  3547. tempIndex = gun_index;
  3548. }
  3549. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  3550. {
  3551. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  3552. {
  3553. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargedEnergy );// PresentChargedEnergy is 0~6553.5 kWh
  3554. }
  3555. }// END OF CHAdeMO_QUANTITY
  3556. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase,PhaseStr[L3_N]);
  3557. }
  3558. else if((gunType[gun_index] == 'U')||(gunType[gun_index] == 'E'))
  3559. {
  3560. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  3561. {
  3562. tempIndex = ((gun_index==2) ? 1: 0);
  3563. }
  3564. else
  3565. {
  3566. tempIndex = gun_index;
  3567. }
  3568. for (int index = 0; index < CCS_QUANTITY; index++)
  3569. {
  3570. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  3571. {
  3572. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargedEnergy );// PresentChargedEnergy is 0~6553.5 kWh
  3573. }
  3574. }// END OF CCS_QUANTITY
  3575. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase,PhaseStr[L3_N]);
  3576. }
  3577. else if(gunType[gun_index] == 'G')
  3578. {
  3579. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  3580. {
  3581. tempIndex = ((gun_index==2) ? 1: 0);
  3582. }
  3583. else
  3584. {
  3585. tempIndex = gun_index;
  3586. }
  3587. for (int index = 0; index < GB_QUANTITY; index++)
  3588. {
  3589. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  3590. {
  3591. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargedEnergy );// PresentChargedEnergy is 0~6553.5 kWh
  3592. }
  3593. }// END OF GB_QUANTITY
  3594. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase,PhaseStr[L3_N]);
  3595. }
  3596. else
  3597. {
  3598. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  3599. {
  3600. tempIndex = 2;
  3601. }
  3602. else
  3603. {
  3604. tempIndex = gun_index;
  3605. }
  3606. for (int index = 0; index < AC_QUANTITY; index++)
  3607. {
  3608. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  3609. {
  3610. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargedEnergy );// PresentChargedEnergy is 0~6553.5 kWh
  3611. }
  3612. }// END OF AC_QUANTITY
  3613. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase,PhaseStr[L1_N]);
  3614. }
  3615. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  3616. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Format,ValueFormatStr[Raw]);
  3617. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Measurand,MeasurandStr[Energy_Active_Import_Interval]);
  3618. //strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase,PhaseStr[L1_N]);
  3619. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Location,LocationStr[Location_Outlet]);
  3620. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Unit,UnitOfMeasureStr[UnitOfMeasure_kWh]);
  3621. //Power.Active.Export
  3622. //idx_sample=3;
  3623. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  3624. if(gunType[gun_index] == 'J')
  3625. {
  3626. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  3627. {
  3628. tempIndex = ((gun_index==2) ? 1: 0);
  3629. }
  3630. else
  3631. {
  3632. tempIndex = gun_index;
  3633. }
  3634. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  3635. {
  3636. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  3637. {
  3638. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargingPower );// PresentChargingPower is 0~6553.5 kW
  3639. }
  3640. } // End for CHAdeMO_QUANTITY
  3641. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase,PhaseStr[L3_N]);
  3642. }
  3643. else if((gunType[gun_index] == 'U')||(gunType[gun_index] == 'E'))
  3644. {
  3645. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  3646. {
  3647. tempIndex = ((gun_index==2) ? 1: 0);
  3648. }
  3649. else
  3650. {
  3651. tempIndex = gun_index;
  3652. }
  3653. for (int index = 0; index < CCS_QUANTITY; index++)
  3654. {
  3655. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  3656. {
  3657. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargingPower );// PresentChargingPower is 0~6553.5 kW
  3658. }
  3659. } // END for CCS_QUANTITY
  3660. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase,PhaseStr[L3_N]);
  3661. }
  3662. else if(gunType[gun_index] == 'G')
  3663. {
  3664. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  3665. {
  3666. tempIndex = ((gun_index==2) ? 1: 0);
  3667. }
  3668. else
  3669. {
  3670. tempIndex = gun_index;
  3671. }
  3672. for (int index = 0; index < GB_QUANTITY; index++)
  3673. {
  3674. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  3675. {
  3676. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingPower );// PresentChargingPower is 0~6553.5 kW
  3677. }
  3678. }// END for GB_QUANTITY
  3679. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase,PhaseStr[L3_N]);
  3680. }
  3681. else
  3682. {
  3683. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  3684. {
  3685. tempIndex = 2;
  3686. }
  3687. else
  3688. {
  3689. tempIndex = gun_index;
  3690. }
  3691. for (int index = 0; index < AC_QUANTITY; index++)
  3692. {
  3693. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  3694. {
  3695. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingPower );// PresentChargingPower is 0~6553.5 kW
  3696. }
  3697. } // END for AC_QUANTITY
  3698. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase,PhaseStr[L1_N]);
  3699. }
  3700. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  3701. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Format,ValueFormatStr[Raw]);
  3702. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Measurand,MeasurandStr[Power_Active_Import]);
  3703. //strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase,PhaseStr[L1_N]);
  3704. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Location,LocationStr[Location_Outlet]);
  3705. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Unit,UnitOfMeasureStr[UnitOfMeasure_kW/*UnitOfMeasure_kWh*/]);
  3706. //Voltage
  3707. //idx_sample=4;
  3708. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  3709. if(gunType[gun_index] == 'J')
  3710. {
  3711. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  3712. {
  3713. tempIndex = ((gun_index==2) ? 1: 0);
  3714. }
  3715. else
  3716. {
  3717. tempIndex = gun_index;
  3718. }
  3719. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  3720. {
  3721. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  3722. {
  3723. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargingVoltage );// PresentChargingVoltage is 0~6553.5 volt
  3724. }
  3725. } // END OF FOR CHAdeMO_QUANTITY
  3726. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase,PhaseStr[L3_N]);
  3727. }
  3728. else if((gunType[gun_index] == 'U')||(gunType[gun_index] == 'E'))
  3729. {
  3730. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  3731. {
  3732. tempIndex = ((gun_index==2) ? 1: 0);
  3733. }
  3734. else
  3735. {
  3736. tempIndex = gun_index;
  3737. }
  3738. for (int index = 0; index < CCS_QUANTITY; index++)
  3739. {
  3740. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  3741. {
  3742. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargingVoltage );// PresentChargingVoltage is 0~6553.5 volt
  3743. }
  3744. } // END OF FOR CCS_QUANTITY
  3745. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase,PhaseStr[L3_N]);
  3746. }
  3747. else if(gunType[gun_index] == 'G')
  3748. {
  3749. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  3750. {
  3751. tempIndex = ((gun_index==2) ? 1: 0);
  3752. }
  3753. else
  3754. {
  3755. tempIndex = gun_index;
  3756. }
  3757. for (int index = 0; index < GB_QUANTITY; index++)
  3758. {
  3759. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  3760. {
  3761. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingVoltage );// PresentChargingVoltage is 0~6553.5 volt
  3762. }
  3763. } // END OF FOR GB_QUANTITY
  3764. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase,PhaseStr[L3_N]);
  3765. }
  3766. else
  3767. {
  3768. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  3769. {
  3770. tempIndex = 2;
  3771. }
  3772. else
  3773. {
  3774. tempIndex = gun_index;
  3775. }
  3776. for (int index = 0; index < AC_QUANTITY; index++)
  3777. {
  3778. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  3779. {
  3780. 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
  3781. }
  3782. } // END OF FOR AC_QUANTITY
  3783. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase,PhaseStr[L1_N]);
  3784. }
  3785. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  3786. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Format,ValueFormatStr[Raw]);
  3787. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Measurand,MeasurandStr[Voltage]);
  3788. //strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase,PhaseStr[L1_N]);
  3789. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Location,LocationStr[Location_Outlet]);
  3790. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Unit,UnitOfMeasureStr[UnitOfMeasure_V]);
  3791. //SoC
  3792. //idx_sample=5;
  3793. //J : CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  3794. if((gunType[gun_index] == 'J')||(gunType[gun_index] == 'U')||(gunType[gun_index] == 'E')||(gunType[gun_index] == 'G'))
  3795. {
  3796. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  3797. {
  3798. tempIndex = ((gun_index==2) ? 1: 0);
  3799. }
  3800. else
  3801. {
  3802. tempIndex = gun_index;
  3803. }
  3804. if(gunType[gun_index] == 'J')
  3805. {
  3806. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  3807. {
  3808. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  3809. {
  3810. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].EvBatterySoc );// 0~100%
  3811. }
  3812. }
  3813. }
  3814. else if((gunType[gun_index] == 'U')||(gunType[gun_index] == 'E'))
  3815. {
  3816. for (int index = 0; index < CCS_QUANTITY; index++)
  3817. {
  3818. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  3819. {
  3820. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].EvBatterySoc );// 0~100%
  3821. }
  3822. }
  3823. }
  3824. else if(gunType[gun_index] == 'G')
  3825. {
  3826. for (int index = 0; index < GB_QUANTITY; index++)
  3827. {
  3828. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  3829. {
  3830. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].EvBatterySoc );// 0~100%
  3831. }
  3832. }
  3833. }
  3834. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  3835. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Format,ValueFormatStr[Raw]);
  3836. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Measurand,MeasurandStr[SoC/*Energy_Reactive_Export_Register*/]);
  3837. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Phase,PhaseStr[L3_N]);
  3838. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Location,LocationStr[Location_Outlet]);
  3839. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Unit,UnitOfMeasureStr[UnitOfMeasure_Percent/*UnitOfMeasure_kWh*/]);
  3840. } // END FOR DC CASE
  3841. if((gunType[gun_index] == 'J')||(gunType[gun_index] == 'U')||(gunType[gun_index] == 'E')||(gunType[gun_index] == 'G'))
  3842. {
  3843. sprintf(queuedata,"[%d,\"%s\",\"StopTransaction\",{\"idTag\":\"%s\",\"meterStop\":%d,\"timestamp\":\"%s\",\"transactionId\":%d,\"reason\":\"%s\",\"transactionData\":[{\"timestamp\":\"%s\",\"sampledValue\":[{\"value\":\"%s\",\"context\":\"%s\",\"format\":\"%s\",\"measurand\":\"%s\",\"phase\":\"%s\",\"location\":\"%s\",\"unit\":\"%s\"},{\"value\":\"%s\",\"context\":\"%s\",\"format\":\"%s\",\"measurand\":\"%s\",\"phase\":\"%s\",\"location\":\"%s\",\"unit\":\"%s\"},{\"value\":\"%s\",\"context\":\"%s\",\"format\":\"%s\",\"measurand\":\"%s\",\"phase\":\"%s\",\"location\":\"%s\",\"unit\":\"%s\"},{\"value\":\"%s\",\"context\":\"%s\",\"format\":\"%s\",\"measurand\":\"%s\",\"phase\":\"%s\",\"location\":\"%s\",\"unit\":\"%s\"},{\"value\":\"%s\",\"context\":\"%s\",\"format\":\"%s\",\"measurand\":\"%s\",\"phase\":\"%s\",\"location\":\"%s\",\"unit\":\"%s\"},{\"value\":\"%s\",\"context\":\"%s\",\"format\":\"%s\",\"measurand\":\"%s\",\"phase\":\"%s\",\"location\":\"%s\",\"unit\":\"%s\"}]}]}]"
  3844. ,MESSAGE_TYPE_CALL
  3845. ,guid
  3846. ,ShmOCPP16Data->StopTransaction[gun_index].IdTag
  3847. ,ShmOCPP16Data->StopTransaction[gun_index].MeterStop
  3848. ,ShmOCPP16Data->StopTransaction[gun_index].Timestamp
  3849. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionId
  3850. ,ShmOCPP16Data->StopTransaction[gun_index].StopReason
  3851. ,(const char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].TimeStamp
  3852. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Value
  3853. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Context
  3854. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Format
  3855. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Measurand
  3856. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Phase
  3857. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Location
  3858. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Unit
  3859. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value
  3860. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Context
  3861. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Format
  3862. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Measurand
  3863. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase
  3864. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Location
  3865. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Unit
  3866. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Value
  3867. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Context
  3868. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Format
  3869. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Measurand
  3870. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase
  3871. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Location
  3872. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Unit
  3873. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Value
  3874. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Context
  3875. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Format
  3876. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Measurand
  3877. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase
  3878. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Location
  3879. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Unit
  3880. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Value
  3881. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Context
  3882. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Format
  3883. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Measurand
  3884. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase
  3885. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Location
  3886. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Unit
  3887. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Value
  3888. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Context
  3889. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Format
  3890. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Measurand
  3891. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Phase
  3892. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Location
  3893. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Unit
  3894. );
  3895. }
  3896. else
  3897. {
  3898. sprintf(queuedata,"[%d,\"%s\",\"StopTransaction\",{\"idTag\":\"%s\",\"meterStop\":%d,\"timestamp\":\"%s\",\"transactionId\":%d,\"reason\":\"%s\",\"transactionData\":[{\"timestamp\":\"%s\",\"sampledValue\":[{\"value\":\"%s\",\"context\":\"%s\",\"format\":\"%s\",\"measurand\":\"%s\",\"phase\":\"%s\",\"location\":\"%s\",\"unit\":\"%s\"},{\"value\":\"%s\",\"context\":\"%s\",\"format\":\"%s\",\"measurand\":\"%s\",\"phase\":\"%s\",\"location\":\"%s\",\"unit\":\"%s\"},{\"value\":\"%s\",\"context\":\"%s\",\"format\":\"%s\",\"measurand\":\"%s\",\"phase\":\"%s\",\"location\":\"%s\",\"unit\":\"%s\"},{\"value\":\"%s\",\"context\":\"%s\",\"format\":\"%s\",\"measurand\":\"%s\",\"phase\":\"%s\",\"location\":\"%s\",\"unit\":\"%s\"},{\"value\":\"%s\",\"context\":\"%s\",\"format\":\"%s\",\"measurand\":\"%s\",\"phase\":\"%s\",\"location\":\"%s\",\"unit\":\"%s\"}]}]}]"
  3899. ,MESSAGE_TYPE_CALL
  3900. ,guid
  3901. ,ShmOCPP16Data->StopTransaction[gun_index].IdTag
  3902. ,ShmOCPP16Data->StopTransaction[gun_index].MeterStop
  3903. ,ShmOCPP16Data->StopTransaction[gun_index].Timestamp
  3904. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionId
  3905. ,ShmOCPP16Data->StopTransaction[gun_index].StopReason
  3906. ,(const char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].TimeStamp
  3907. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Value
  3908. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Context
  3909. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Format
  3910. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Measurand
  3911. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Phase
  3912. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Location
  3913. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Unit
  3914. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value
  3915. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Context
  3916. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Format
  3917. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Measurand
  3918. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase
  3919. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Location
  3920. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Unit
  3921. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Value
  3922. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Context
  3923. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Format
  3924. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Measurand
  3925. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase
  3926. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Location
  3927. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Unit
  3928. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Value
  3929. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Context
  3930. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Format
  3931. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Measurand
  3932. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase
  3933. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Location
  3934. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Unit
  3935. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Value
  3936. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Context
  3937. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Format
  3938. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Measurand
  3939. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase
  3940. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Location
  3941. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Unit
  3942. );
  3943. }
  3944. #if 1 // for TempStopTransaction
  3945. //Delete TempStopTransaction
  3946. if((access("/Storage/OCPP/TempStopTransaction",F_OK))!=-1)
  3947. {
  3948. remove("/Storage/OCPP/TempStopTransaction"); // remove file "TempStopTransaction"
  3949. }
  3950. #endif
  3951. sprintf(tempdata, "StopTransaction,%d", (gun_index));
  3952. if(hashmap_operation(HASH_OP_ADD, guid, tempdata) == 1)
  3953. {
  3954. result = PASS;
  3955. DEBUG_INFO("StopTransaction mapitem pass\n");
  3956. }
  3957. queue_operation(4, guid, queuedata );//addq(guid, queuedata); ---> remove temporally
  3958. if(GetTransactionQueueNum() == 1)
  3959. {
  3960. LWS_Send(queuedata);
  3961. }
  3962. //----------------------------replace queue StopTransaction TransactionId ---------------------------//
  3963. int gettransactionId = GetTransactionId(gun_index+1, (char*)ShmOCPP16Data->StartTransaction[gun_index].IdTag);
  3964. if((ShmOCPP16Data->StopTransaction[gun_index].TransactionId != 0) && (gettransactionId != 0))
  3965. {
  3966. SetTransactionIdZero(ShmOCPP16Data->StopTransaction[gun_index].TransactionId);
  3967. }
  3968. //for test
  3969. //ShmOCPP16Data->CpMsg.bits[gun_index].StopTransactionReq = 0;
  3970. return result;
  3971. }
  3972. int sendMeterValuesRequest(int gun_index)
  3973. {
  3974. mtrace();
  3975. int result = FAIL;
  3976. // char message[1500]={0};
  3977. char guid[37]={0};
  3978. //int idx_sample=0;
  3979. //int length = 0;
  3980. char tempdata[65]={0};
  3981. int tempIndex = 0;
  3982. DEBUG_INFO("sendMeterValuesRequest...\n");
  3983. if((ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId == 0)&&(ShmOCPP16Data->CsMsg.bits[gun_index].TriggerMessageReq == 0)) // no TransactionId
  3984. {
  3985. DEBUG_ERROR("NOT SENT METER Vlaue\n");
  3986. return result;
  3987. }
  3988. if(ShmOCPP16Data->CsMsg.bits[gun_index].TriggerMessageReq == 1)
  3989. {
  3990. ShmOCPP16Data->CsMsg.bits[gun_index].TriggerMessageReq = 0;
  3991. }
  3992. memset(queuedata, 0, sizeof(queuedata));
  3993. //set value
  3994. ShmOCPP16Data->MeterValues[gun_index].ConnectorId = gun_index + 1; // gun start from 1~
  3995. ShmOCPP16Data->MeterValues[gun_index].TransactionId = ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId;
  3996. random_uuid(guid);
  3997. //UTC Date time
  3998. struct timeval tmnow;
  3999. struct tm *tm;
  4000. char buf[28];//, usec_buf[6];
  4001. gettimeofday(&tmnow, NULL);
  4002. time_t t;
  4003. t = time(NULL);
  4004. /*UTC time and date*/
  4005. tm = gmtime(&t);
  4006. strftime(buf,28,"%Y-%m-%dT%H:%M:%SZ", tm);
  4007. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].TimeStamp, buf);
  4008. DEBUG_INFO( "ShmSysConfigAndInfo->SysConfig.ModelName[0]=%c\n", ShmSysConfigAndInfo->SysConfig.ModelName[0]);
  4009. //idx_sample=0;
  4010. //********************************(1)Current.Export************************************************/
  4011. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  4012. if(gunType[gun_index] == 'J')
  4013. {
  4014. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4015. {
  4016. tempIndex = ((gun_index==2) ? 1: 0);
  4017. }
  4018. else
  4019. {
  4020. tempIndex = gun_index;
  4021. }
  4022. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  4023. {
  4024. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  4025. {
  4026. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargingCurrent );
  4027. }
  4028. }
  4029. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Phase, PhaseStr[L3_N]);
  4030. }
  4031. else if((gunType[gun_index] == 'U')||(gunType[gun_index] == 'E'))
  4032. {
  4033. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4034. {
  4035. tempIndex = ((gun_index==2) ? 1: 0);
  4036. }
  4037. else
  4038. {
  4039. tempIndex = gun_index;
  4040. }
  4041. for (int index = 0; index < CCS_QUANTITY; index++)
  4042. {
  4043. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  4044. {
  4045. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargingCurrent );
  4046. }
  4047. }
  4048. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Phase, PhaseStr[L3_N]);
  4049. }
  4050. else if(gunType[gun_index] == 'G')
  4051. {
  4052. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4053. {
  4054. tempIndex = ((gun_index==2) ? 1: 0);
  4055. }
  4056. else
  4057. {
  4058. tempIndex = gun_index;
  4059. }
  4060. for (int index = 0; index < GB_QUANTITY; index++)
  4061. {
  4062. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  4063. {
  4064. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingCurrent );
  4065. }
  4066. }
  4067. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Phase, PhaseStr[L3_N]);
  4068. }
  4069. else
  4070. {
  4071. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  4072. {
  4073. tempIndex = 2;
  4074. }
  4075. else
  4076. {
  4077. tempIndex = gun_index;
  4078. }
  4079. for (int index = 0; index < AC_QUANTITY; index++)
  4080. {
  4081. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  4082. {
  4083. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingCurrent );
  4084. }
  4085. }
  4086. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Phase, PhaseStr[L1_N]);
  4087. }
  4088. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Context, ReadingContextStr[ReadingContext_Sample_Periodic]);
  4089. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Format, ValueFormatStr[Raw]);
  4090. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Measurand, MeasurandStr[Current_Import]);
  4091. //strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Phase, PhaseStr[L1_N]);
  4092. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Location, LocationStr[Location_Outlet]);
  4093. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Unit,UnitOfMeasureStr[UnitOfMeasure_A]);
  4094. //idx_sample=1;
  4095. //********************************(2)Energy.Active.Import.Register ************************************************/
  4096. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  4097. if(gunType[gun_index] == 'J')
  4098. {
  4099. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4100. {
  4101. tempIndex = ((gun_index==2) ? 1: 0);
  4102. }
  4103. else
  4104. {
  4105. tempIndex = gun_index;
  4106. }
  4107. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  4108. {
  4109. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  4110. {
  4111. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PowerConsumption );
  4112. }
  4113. }
  4114. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Phase, PhaseStr[L3_N]);
  4115. }
  4116. else if((gunType[gun_index] == 'U')||(gunType[gun_index] == 'E'))
  4117. {
  4118. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4119. {
  4120. tempIndex = ((gun_index==2) ? 1: 0);
  4121. }
  4122. else
  4123. {
  4124. tempIndex = gun_index;
  4125. }
  4126. for (int index = 0; index < CCS_QUANTITY; index++)
  4127. {
  4128. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  4129. {
  4130. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PowerConsumption );
  4131. }
  4132. }
  4133. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Phase, PhaseStr[L3_N]);
  4134. }
  4135. else if(gunType[gun_index] == 'G')
  4136. {
  4137. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4138. {
  4139. tempIndex = ((gun_index==2) ? 1: 0);
  4140. }
  4141. else
  4142. {
  4143. tempIndex = gun_index;
  4144. }
  4145. for (int index = 0; index < GB_QUANTITY; index++)
  4146. {
  4147. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  4148. {
  4149. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PowerConsumption );
  4150. }
  4151. }
  4152. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Phase, PhaseStr[L3_N]);
  4153. }
  4154. else
  4155. {
  4156. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  4157. {
  4158. tempIndex = 2;
  4159. }
  4160. else
  4161. {
  4162. tempIndex = gun_index;
  4163. }
  4164. for (int index = 0; index < AC_QUANTITY; index++)
  4165. {
  4166. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  4167. {
  4168. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PowerConsumption );
  4169. }
  4170. }
  4171. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Phase, PhaseStr[L1_N]);
  4172. }
  4173. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Context, ReadingContextStr[ReadingContext_Sample_Periodic]);
  4174. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Format, ValueFormatStr[Raw]);
  4175. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Measurand, MeasurandStr[Energy_Active_Import_Register]);
  4176. //strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Phase, PhaseStr[L1_N]);
  4177. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Location, LocationStr[Location_Outlet]);
  4178. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Unit,UnitOfMeasureStr[UnitOfMeasure_kWh]);
  4179. //idx_sample=2;
  4180. //****************************************************(3)Energy.Active.Export.Interval*********************************************/
  4181. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  4182. if(gunType[gun_index] == 'J')
  4183. {
  4184. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4185. {
  4186. tempIndex = ((gun_index==2) ? 1: 0);
  4187. }
  4188. else
  4189. {
  4190. tempIndex = gun_index;
  4191. }
  4192. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  4193. {
  4194. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  4195. {
  4196. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargedEnergy );
  4197. }
  4198. } // END OF FOR CHAdeMO_QUANTITY
  4199. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Phase, PhaseStr[L3_N]);
  4200. }
  4201. else if((gunType[gun_index] == 'U')||(gunType[gun_index] == 'E'))
  4202. {
  4203. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4204. {
  4205. tempIndex = ((gun_index==2) ? 1: 0);
  4206. }
  4207. else
  4208. {
  4209. tempIndex = gun_index;
  4210. }
  4211. for (int index = 0; index < CCS_QUANTITY; index++)
  4212. {
  4213. // printf("ShmSysConfigAndInfo->SysInfo.CcsChargingData[%d].Index=%d\n",index, ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index );
  4214. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  4215. {
  4216. //ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargedEnergy = 100.0;
  4217. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargedEnergy );
  4218. }
  4219. } // END OF CCS_QUANTITY
  4220. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Phase, PhaseStr[L3_N]);
  4221. }
  4222. else if(gunType[gun_index] == 'G')
  4223. {
  4224. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4225. {
  4226. tempIndex = ((gun_index==2) ? 1: 0);
  4227. }
  4228. else
  4229. {
  4230. tempIndex = gun_index;
  4231. }
  4232. for (int index = 0; index < GB_QUANTITY; index++)
  4233. {
  4234. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  4235. {
  4236. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargedEnergy);
  4237. }
  4238. } // END OF GB_QUANTITY
  4239. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Phase, PhaseStr[L3_N]);
  4240. }
  4241. else
  4242. {
  4243. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  4244. {
  4245. tempIndex = 2;
  4246. }
  4247. else
  4248. {
  4249. tempIndex = gun_index;
  4250. }
  4251. for (int index = 0; index < AC_QUANTITY; index++)
  4252. {
  4253. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  4254. {
  4255. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargedEnergy );
  4256. }
  4257. }
  4258. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Phase, PhaseStr[L1_N]);
  4259. }
  4260. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Context, ReadingContextStr[ReadingContext_Sample_Periodic]);
  4261. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Format, ValueFormatStr[Raw]);
  4262. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Measurand, MeasurandStr[Energy_Active_Import_Interval]);
  4263. //strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Phase, PhaseStr[L1_N]);
  4264. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Location, LocationStr[Location_Outlet]);
  4265. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Unit,UnitOfMeasureStr[UnitOfMeasure_kWh]);
  4266. //idx_sample=3;
  4267. //********************************(4)Power.Active.Export************************************************/
  4268. //J : CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  4269. if(gunType[gun_index] == 'J')
  4270. {
  4271. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4272. {
  4273. tempIndex = ((gun_index==2) ? 1: 0);
  4274. }
  4275. else
  4276. {
  4277. tempIndex = gun_index;
  4278. }
  4279. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  4280. {
  4281. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  4282. {
  4283. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Value, "%.1f" , ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargingPower);
  4284. }
  4285. } // END OF FOR
  4286. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Phase, PhaseStr[L3_N]);
  4287. }
  4288. else if((gunType[gun_index] == 'U')||(gunType[gun_index] == 'E'))
  4289. {
  4290. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4291. {
  4292. tempIndex = ((gun_index==2) ? 1: 0);
  4293. }
  4294. else
  4295. {
  4296. tempIndex = gun_index;
  4297. }
  4298. for (int index = 0; index < CCS_QUANTITY; index++)
  4299. {
  4300. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  4301. {
  4302. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Value, "%.1f" , ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargingPower);
  4303. }
  4304. }
  4305. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Phase, PhaseStr[L3_N]);
  4306. }
  4307. else if(gunType[gun_index] == 'G')
  4308. {
  4309. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4310. {
  4311. tempIndex = ((gun_index==2) ? 1: 0);
  4312. }
  4313. else
  4314. {
  4315. tempIndex = gun_index;
  4316. }
  4317. for (int index = 0; index < GB_QUANTITY; index++)
  4318. {
  4319. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  4320. {
  4321. //ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingPower = 100.0;
  4322. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Value, "%.1f" , ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingPower);
  4323. }
  4324. }
  4325. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Phase, PhaseStr[L3_N]);
  4326. }
  4327. else
  4328. {
  4329. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  4330. {
  4331. tempIndex = 2;
  4332. }
  4333. else
  4334. {
  4335. tempIndex = gun_index;
  4336. }
  4337. for (int index = 0; index < AC_QUANTITY; index++)
  4338. {
  4339. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  4340. {
  4341. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Value, "%.1f" , ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingPower);
  4342. }
  4343. }
  4344. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Phase, PhaseStr[L1_N]);
  4345. }
  4346. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Context, ReadingContextStr[ReadingContext_Sample_Periodic]);
  4347. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Format, ValueFormatStr[Raw]);
  4348. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Measurand, MeasurandStr[Power_Active_Import]);
  4349. //strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Phase, PhaseStr[L1_N]);
  4350. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Location, LocationStr[Location_Outlet]);
  4351. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Unit,UnitOfMeasureStr[UnitOfMeasure_kW]);
  4352. //idx_sample=4;
  4353. //***********************************************(5)VOLTAGE******************************************************/
  4354. //J : CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  4355. if(gunType[gun_index] == 'J')
  4356. {
  4357. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4358. {
  4359. tempIndex = ((gun_index==2) ? 1: 0);
  4360. }
  4361. else
  4362. {
  4363. tempIndex = gun_index;
  4364. }
  4365. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  4366. {
  4367. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  4368. {
  4369. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargingVoltage );
  4370. }
  4371. }
  4372. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Phase, PhaseStr[L3_N]);
  4373. }
  4374. else if((gunType[gun_index] == 'U')||(gunType[gun_index] == 'E'))
  4375. {
  4376. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4377. {
  4378. tempIndex = ((gun_index==2) ? 1: 0);
  4379. }
  4380. else
  4381. {
  4382. tempIndex = gun_index;
  4383. }
  4384. for (int index = 0; index < CCS_QUANTITY; index++)
  4385. {
  4386. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  4387. {
  4388. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargingVoltage );
  4389. }
  4390. }
  4391. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Phase, PhaseStr[L3_N]);
  4392. }
  4393. else if(gunType[gun_index] == 'G')
  4394. {
  4395. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4396. {
  4397. tempIndex = ((gun_index==2) ? 1: 0);
  4398. }
  4399. else
  4400. {
  4401. tempIndex = gun_index;
  4402. }
  4403. for (int index = 0; index < GB_QUANTITY; index++)
  4404. {
  4405. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  4406. {
  4407. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingVoltage );
  4408. }
  4409. }
  4410. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Phase, PhaseStr[L3_N]);
  4411. }
  4412. else
  4413. {
  4414. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  4415. {
  4416. tempIndex = 2;
  4417. }
  4418. else
  4419. {
  4420. tempIndex = gun_index;
  4421. }
  4422. for (int index = 0; index < AC_QUANTITY; index++)
  4423. {
  4424. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  4425. {
  4426. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingVoltage );
  4427. }
  4428. }
  4429. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Phase, PhaseStr[L1_N]);
  4430. }
  4431. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Context, ReadingContextStr[ReadingContext_Sample_Periodic]);
  4432. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Format, ValueFormatStr[Raw]);
  4433. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Measurand, MeasurandStr[Voltage]);
  4434. // strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Phase, PhaseStr[L1_N]);
  4435. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Location, LocationStr[Location_Outlet]);
  4436. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Unit,UnitOfMeasureStr[UnitOfMeasure_V]);
  4437. if((gunType[gun_index] == 'J')||(gunType[gun_index] == 'U')||(gunType[gun_index] == 'E')||(gunType[gun_index] == 'G'))
  4438. {
  4439. //idx_sample=5;
  4440. //sampledValue = NULL;
  4441. //***********************************************(6)SOC******************************************************/
  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. if(gunType[gun_index] == 'J')
  4451. {
  4452. //tempIndex = ((gun_index==2) ? 1: 0);
  4453. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  4454. {
  4455. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  4456. {
  4457. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].EvBatterySoc );
  4458. }
  4459. }
  4460. }
  4461. else if((gunType[gun_index] == 'U')||(gunType[gun_index] == 'E'))
  4462. {
  4463. //tempIndex = ((gun_index==2) ? 1: 0);
  4464. for (int index = 0; index < CCS_QUANTITY; index++)
  4465. {
  4466. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  4467. {
  4468. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].EvBatterySoc );
  4469. }
  4470. }
  4471. }
  4472. else if(gunType[gun_index] == 'G')
  4473. {
  4474. //tempIndex = ((gun_index==2) ? 1: 0);
  4475. for (int index = 0; index < GB_QUANTITY; index++)
  4476. {
  4477. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  4478. {
  4479. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].EvBatterySoc );
  4480. }
  4481. }
  4482. }
  4483. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[5].Context, ReadingContextStr[ReadingContext_Sample_Periodic]);
  4484. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[5].Format, ValueFormatStr[Raw]);
  4485. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[5].Measurand, MeasurandStr[SoC]);
  4486. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[5].Phase, PhaseStr[L3_N]);
  4487. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[5].Location, LocationStr[Location_Outlet]);
  4488. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[5].Unit,UnitOfMeasureStr[UnitOfMeasure_Percent]);
  4489. }
  4490. if((gunType[gun_index] == 'J')||(gunType[gun_index] == 'U')||(gunType[gun_index] == 'E')||(gunType[gun_index] == 'G'))
  4491. {
  4492. sprintf(queuedata,"[%d,\"%s\",\"MeterValues\",{\"connectorId\":%d,\"transactionId\":%d,\"meterValue\":[{\"timestamp\":\"%s\",\"sampledValue\":[{\"value\":\"%s\",\"context\":\"%s\",\"format\":\"%s\",\"measurand\":\"%s\",\"phase\":\"%s\",\"location\":\"%s\",\"unit\":\"%s\"},{\"value\":\"%s\",\"context\":\"%s\",\"format\":\"%s\",\"measurand\":\"%s\",\"phase\":\"%s\",\"location\":\"%s\",\"unit\":\"%s\"},{\"value\":\"%s\",\"context\":\"%s\",\"format\":\"%s\",\"measurand\":\"%s\",\"phase\":\"%s\",\"location\":\"%s\",\"unit\":\"%s\"},{\"value\":\"%s\",\"context\":\"%s\",\"format\":\"%s\",\"measurand\":\"%s\",\"phase\":\"%s\",\"location\":\"%s\",\"unit\":\"%s\"},{\"value\":\"%s\",\"context\":\"%s\",\"format\":\"%s\",\"measurand\":\"%s\",\"phase\":\"%s\",\"location\":\"%s\",\"unit\":\"%s\"},{\"value\":\"%s\",\"context\":\"%s\",\"format\":\"%s\",\"measurand\":\"%s\",\"phase\":\"%s\",\"location\":\"%s\",\"unit\":\"%s\"}]}]}]"
  4493. ,MESSAGE_TYPE_CALL
  4494. ,guid
  4495. ,ShmOCPP16Data->MeterValues[gun_index].ConnectorId
  4496. ,ShmOCPP16Data->MeterValues[gun_index].TransactionId
  4497. ,(const char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].TimeStamp
  4498. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Value
  4499. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Context
  4500. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Format
  4501. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Measurand
  4502. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Phase
  4503. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Location
  4504. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Unit
  4505. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Value
  4506. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Context
  4507. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Format
  4508. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Measurand
  4509. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Phase
  4510. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Location
  4511. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Unit
  4512. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Value
  4513. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Context
  4514. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Format
  4515. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Measurand
  4516. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Phase
  4517. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Location
  4518. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Unit
  4519. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Value
  4520. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Context
  4521. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Format
  4522. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Measurand
  4523. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Phase
  4524. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Location
  4525. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Unit
  4526. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Value
  4527. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Context
  4528. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Format
  4529. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Measurand
  4530. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Phase
  4531. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Location
  4532. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Unit
  4533. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[5].Value
  4534. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[5].Context
  4535. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[5].Format
  4536. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[5].Measurand
  4537. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[5].Phase
  4538. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[5].Location
  4539. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[5].Unit
  4540. );
  4541. }
  4542. else
  4543. {
  4544. sprintf(queuedata,"[%d,\"%s\",\"MeterValues\",{\"connectorId\":%d,\"transactionId\":%d,\"meterValue\":[{\"timestamp\":\"%s\",\"sampledValue\":[{\"value\":\"%s\",\"context\":\"%s\",\"format\":\"%s\",\"measurand\":\"%s\",\"phase\":\"%s\",\"location\":\"%s\",\"unit\":\"%s\"},{\"value\":\"%s\",\"context\":\"%s\",\"format\":\"%s\",\"measurand\":\"%s\",\"phase\":\"%s\",\"location\":\"%s\",\"unit\":\"%s\"},{\"value\":\"%s\",\"context\":\"%s\",\"format\":\"%s\",\"measurand\":\"%s\",\"phase\":\"%s\",\"location\":\"%s\",\"unit\":\"%s\"},{\"value\":\"%s\",\"context\":\"%s\",\"format\":\"%s\",\"measurand\":\"%s\",\"phase\":\"%s\",\"location\":\"%s\",\"unit\":\"%s\"},{\"value\":\"%s\",\"context\":\"%s\",\"format\":\"%s\",\"measurand\":\"%s\",\"phase\":\"%s\",\"location\":\"%s\",\"unit\":\"%s\"}]}]}]"
  4545. ,MESSAGE_TYPE_CALL
  4546. ,guid
  4547. ,ShmOCPP16Data->MeterValues[gun_index].ConnectorId
  4548. ,ShmOCPP16Data->MeterValues[gun_index].TransactionId
  4549. ,(const char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].TimeStamp
  4550. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Value
  4551. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Context
  4552. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Format
  4553. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Measurand
  4554. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Phase
  4555. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Location
  4556. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Unit
  4557. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Value
  4558. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Context
  4559. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Format
  4560. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Measurand
  4561. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Phase
  4562. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Location
  4563. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Unit
  4564. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Value
  4565. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Context
  4566. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Format
  4567. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Measurand
  4568. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Phase
  4569. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Location
  4570. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Unit
  4571. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Value
  4572. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Context
  4573. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Format
  4574. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Measurand
  4575. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Phase
  4576. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Location
  4577. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Unit
  4578. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Value
  4579. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Context
  4580. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Format
  4581. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Measurand
  4582. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Phase
  4583. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Location
  4584. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Unit
  4585. );
  4586. }
  4587. // Put request guid to hash map
  4588. sprintf(tempdata, "MeterValues,%d", (gun_index));
  4589. 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*/)
  4590. {
  4591. result = PASS;
  4592. DEBUG_INFO("MeterValues mapitem pass\n");
  4593. }
  4594. queue_operation(4, guid, queuedata );//addq(guid, queuedata); ---> remove temporally
  4595. if(GetTransactionQueueNum() == 1)
  4596. {
  4597. LWS_Send(queuedata);
  4598. }
  4599. return result;
  4600. }
  4601. //==========================================
  4602. // send confirm routine
  4603. //==========================================
  4604. int sendCancelReservationConfirmation(char *uuid,char *payload)
  4605. {
  4606. mtrace();
  4607. int result = FAIL;
  4608. char message[100]={0};
  4609. DEBUG_INFO("sendCancelReservationConfirmation...\n");
  4610. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT,uuid, payload);
  4611. LWS_Send(message);
  4612. result = TRUE;
  4613. ShmOCPP16Data->CsMsg.bits[0].CancelReservationConf = 0;
  4614. return result;
  4615. }
  4616. int sendChangeAvailabilityConfirmation(char *uuid,char *payload)
  4617. {
  4618. mtrace();
  4619. int result = FAIL;
  4620. char message[100]={0};
  4621. DEBUG_INFO("sendChangeAvailabilityConfirmation...\n");
  4622. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT,uuid, payload);
  4623. LWS_Send(message);
  4624. result = TRUE;
  4625. return result;
  4626. }
  4627. int sendChangeConfigurationConfirmation(char *uuid,char *payload)
  4628. {
  4629. mtrace();
  4630. int result = FAIL;
  4631. char message[100]={0};
  4632. DEBUG_INFO("sendChangeConfigurationConfirmation...\n");
  4633. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT,uuid, payload);
  4634. LWS_Send(message);
  4635. result = TRUE;
  4636. return result;
  4637. }
  4638. int sendClearCacheConfirmation(char *uuid,char *payload)
  4639. {
  4640. mtrace();
  4641. int result = FAIL;
  4642. char message[500]={0};
  4643. DEBUG_INFO("sendClearCacheConfirmation...\n");
  4644. sprintf(message,"[%d,\"%s\",{\"%s\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, "status", payload);
  4645. LWS_Send(message);
  4646. return result;
  4647. }
  4648. int sendClearChargingProfileConfirmation(char *uuid,char *payload)
  4649. {
  4650. mtrace();
  4651. int result = FAIL;
  4652. char message[500]={0};
  4653. DEBUG_INFO("sendClearChargingProfileConfirmation...\n");
  4654. sprintf(message,"[%d,\"%s\",{\"%s\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, "status", payload);
  4655. LWS_Send(message);
  4656. return result;
  4657. }
  4658. int sendDataTransferConfirmation(char *uuid,char *payload)
  4659. {
  4660. mtrace();
  4661. char statusStr[20]={0};
  4662. char dataStr[10]={0};
  4663. char sstr[20]={0};
  4664. int c = 0;
  4665. char *loc;
  4666. int result = FAIL;
  4667. DEBUG_INFO("sendDataTransferConfirmation...\n");
  4668. /**********************status**************************/
  4669. loc = strstr(payload, "status");
  4670. memset(sstr ,0, sizeof(sstr) );
  4671. c = 0;
  4672. while (loc[3+strlen("status")+c] != '\"')
  4673. {
  4674. sstr[c] = loc[3+strlen("status")+c];
  4675. c++;
  4676. }
  4677. sstr[c] = '\0';
  4678. strcpy(statusStr, sstr);
  4679. /**********************data**************************/
  4680. loc = strstr(payload, "data");
  4681. memset(sstr ,0, sizeof(sstr) );
  4682. c = 0;
  4683. while (loc[3+strlen("data")+c] != '\"')
  4684. {
  4685. sstr[c] = loc[3+strlen("data")+c];
  4686. c++;
  4687. }
  4688. sstr[c] = '\0';
  4689. strcpy(dataStr, sstr);
  4690. return result;
  4691. }
  4692. int sendGetCompositeScheduleConfirmation(char *uuid, char *payload, int connectorIdInt, int nPeriod)
  4693. {
  4694. mtrace();
  4695. int result = FAIL;
  4696. char message[1000]={0};
  4697. int CompositeScheduleIndex = 0;
  4698. DEBUG_INFO("sendGetCompositeScheduleConfirmation...\n");
  4699. CompositeScheduleIndex = (connectorIdInt > 0) ?(connectorIdInt -1) : 0;
  4700. if(nPeriod == 0)
  4701. {
  4702. if(strcmp((const char *)ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.StartSchedule,"")==0)
  4703. {
  4704. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\",\"connectorId\":%d}]"
  4705. ,MESSAGE_TYPE_CALLRESULT
  4706. ,uuid
  4707. ,payload
  4708. ,connectorIdInt);
  4709. }
  4710. else
  4711. {
  4712. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\",\"connectorId\":%d,\"scheduleStart\":\"%s\",\"chargingSchedule\":{\"duration\":%d,\"startSchedule\":\"%s\",\"chargingRateUnit\":\"%s\",\"chargingSchedulePeriod\":[{\"startPeriod\":0,\"limit\":0,\"numberPhases\":3}]}}]"
  4713. ,MESSAGE_TYPE_CALLRESULT
  4714. ,uuid
  4715. ,payload
  4716. ,connectorIdInt
  4717. ,ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.StartSchedule
  4718. ,ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.Duration
  4719. ,ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.StartSchedule
  4720. ,ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.ChargingRateUnit);
  4721. }
  4722. }
  4723. else
  4724. {
  4725. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\",\"connectorId\":%d,\"scheduleStart\":\"%s\",\"chargingSchedule\":{\"duration\":%d,\"startSchedule\":\"%s\",\"chargingRateUnit\":\"%s\",\"chargingSchedulePeriod\":["
  4726. ,MESSAGE_TYPE_CALLRESULT
  4727. ,uuid
  4728. ,payload
  4729. ,connectorIdInt
  4730. ,ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.StartSchedule
  4731. ,ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.Duration
  4732. ,ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.StartSchedule
  4733. ,ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.ChargingRateUnit);
  4734. for(int idx_sample=0;idx_sample< nPeriod;idx_sample++)
  4735. {
  4736. if (idx_sample == 0)
  4737. {
  4738. sprintf(message + strlen(message), "{\"startPeriod\":%d,\"limit\":%.1f,\"numberPhases\":%d}"
  4739. , ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[idx_sample].StartPeriod
  4740. , ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[idx_sample].Limit
  4741. , ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[idx_sample].NumberPhases );
  4742. }
  4743. else
  4744. {
  4745. sprintf(message + strlen(message), ",{\"startPeriod\":%d,\"limit\":%.1f,\"numberPhases\":%d}"
  4746. , ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[idx_sample].StartPeriod
  4747. , ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[idx_sample].Limit
  4748. , ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[idx_sample].NumberPhases );
  4749. }
  4750. }
  4751. sprintf(message + strlen(message), "]}}]");
  4752. }
  4753. LWS_Send(message);
  4754. result = TRUE;
  4755. return result;
  4756. }
  4757. int sendGetConfigurationConfirmation(char *uuid)
  4758. {
  4759. mtrace();
  4760. int result = FAIL;
  4761. int MaxKeySupported = 0;
  4762. int sentConfigurationNumber= 0;
  4763. int sentunConfigurationNumber= 0;
  4764. char message[4000]={0};
  4765. DEBUG_INFO("sendGetConfigurationConfirmation...\n");
  4766. MaxKeySupported = atoi((const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemData);
  4767. //DEBUG_INFO("MaxKeySupported=%d\n",MaxKeySupported);
  4768. sprintf(message,"[%d,\"%s\",{\"configurationKey\":["
  4769. ,MESSAGE_TYPE_CALLRESULT
  4770. ,uuid );
  4771. //configuration key
  4772. for(int idx_sample=0;idx_sample< MaxKeySupported/*43*/;idx_sample++)
  4773. {
  4774. if(strcmp((const char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[idx_sample].Key, "")!= 0)
  4775. {
  4776. if (sentConfigurationNumber == 0)
  4777. {
  4778. sprintf(message + strlen(message), "{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}"
  4779. , ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[idx_sample].Key
  4780. , atoi((const char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[idx_sample].ReadOnly) == 1 ? "true":"false"
  4781. , ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[idx_sample].Value );
  4782. }
  4783. else
  4784. {
  4785. sprintf(message + strlen(message), ", {\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}"
  4786. , ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[idx_sample].Key
  4787. , atoi((const char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[idx_sample].ReadOnly) == 1 ? "true":"false"
  4788. , ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[idx_sample].Value );
  4789. }
  4790. sentConfigurationNumber = sentConfigurationNumber + 1;
  4791. }
  4792. }
  4793. sprintf(message + strlen(message), "]");
  4794. if(UnknownKeynum != 0)
  4795. {
  4796. sprintf(message + strlen(message), ",\"unknownKey\":[");
  4797. //unkown key
  4798. for(int idx_sample=0;idx_sample< UnknownKeynum ;idx_sample++)
  4799. {
  4800. // json_object *jstring1 = json_object_new_string((const char *)((ShmOCPP16Data->GetConfiguration.ResponseUnknownKey + idx_sample)->Item));
  4801. DEBUG_INFO("unkown key:%s\n", ShmOCPP16Data->GetConfiguration.ResponseUnknownKey[idx_sample].Item);
  4802. if(sentunConfigurationNumber == 0)
  4803. {
  4804. sprintf(message + strlen(message), "\"%s\""
  4805. , ShmOCPP16Data->GetConfiguration.ResponseUnknownKey[idx_sample].Item );
  4806. }
  4807. else
  4808. {
  4809. sprintf(message + strlen(message), ",\"%s\""
  4810. , ShmOCPP16Data->GetConfiguration.ResponseUnknownKey[idx_sample].Item );
  4811. }
  4812. sentunConfigurationNumber = sentunConfigurationNumber + 1;
  4813. }
  4814. sprintf(message + strlen(message), "]");
  4815. }
  4816. sprintf(message + strlen(message), "}]");
  4817. LWS_Send(message);
  4818. return result;
  4819. }
  4820. int sendGetDiagnosticsConfirmation(char *uuid,char *payload)
  4821. {
  4822. mtrace();
  4823. int result = FAIL;
  4824. char message[400]={0};
  4825. DEBUG_INFO("sendGetDiagnosticsConfirmation...\n");
  4826. if(strcmp(payload,"")==0)
  4827. {
  4828. sprintf(message,"[%d,\"%s\",{}]",MESSAGE_TYPE_CALLRESULT, uuid);
  4829. }
  4830. else
  4831. {
  4832. sprintf(message,"[%d,\"%s\",{\"fileName\":\"%s\"}]", MESSAGE_TYPE_CALLRESULT, uuid, payload);
  4833. }
  4834. LWS_Send(message);
  4835. result = TRUE;
  4836. return result;
  4837. }
  4838. int sendGetLocalListVersionConfirmation(char *uuid,char *payload)
  4839. {
  4840. mtrace();
  4841. int result = FAIL;
  4842. char message[80]={0};
  4843. DEBUG_INFO("sendGetLocalListVersionConfirmation...\n");
  4844. sprintf(message,"[%d,\"%s\",{\"listVersion\":%d}]",MESSAGE_TYPE_CALLRESULT, uuid, ShmOCPP16Data->GetLocalListVersion.ResponseListVersion);
  4845. LWS_Send(message);
  4846. result = TRUE;
  4847. return result;
  4848. }
  4849. int sendRemoteStartConfirmation(char *uuid,char *payload)
  4850. {
  4851. mtrace();
  4852. int result = FAIL;
  4853. char message[80]={0};
  4854. DEBUG_INFO("sendRemoteStartConfirmation...\n");
  4855. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, payload);
  4856. LWS_Send(message);
  4857. result = TRUE;
  4858. return result;
  4859. }
  4860. int sendRemoteStopTransactionConfirmation(char *uuid,char *payload)
  4861. {
  4862. mtrace();
  4863. int result = FAIL;
  4864. char message[80]={0};
  4865. DEBUG_INFO("sendRemoteStopTransactionConfirmation...\n");
  4866. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, payload);
  4867. LWS_Send(message);
  4868. result = TRUE;
  4869. return result;
  4870. }
  4871. int sendReserveNowTransactionConfirmation(char *uuid,char *payload)
  4872. {
  4873. mtrace();
  4874. int result = FAIL;
  4875. char message[80]={0};
  4876. // [3,"287d837d-809e-41ea-8385-fdab7f72a01c",{"status":"Accepted"}]
  4877. DEBUG_INFO("sendReserveNowTransactionConfirmation...\n");
  4878. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, payload);
  4879. LWS_Send(message);
  4880. result = TRUE;
  4881. return result;
  4882. }
  4883. int sendResetConfirmation(char *uuid,char *payload)
  4884. {
  4885. mtrace();
  4886. int result = FAIL;
  4887. //[ 3, "6f88d461-4d17-462c-a69b-1f7a8c5b12df", { "status": 0 } ]
  4888. char message[80]={0};
  4889. ShmOCPP16Data->MsMsg.bits.ResetConf = 0;
  4890. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, payload);
  4891. LWS_Send(message);
  4892. result = TRUE;
  4893. return result;
  4894. }
  4895. int sendSendLocalListConfirmation(char *uuid,char *payload)
  4896. {
  4897. mtrace();
  4898. int result = FAIL;
  4899. char message[500]={0};
  4900. // [ 3, "1571284266109", { "status": "Accepted" } ]
  4901. sprintf(message,"[%d,\"%s\",{\"%s\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, "status", payload);
  4902. LWS_Send(message);
  4903. result = TRUE;
  4904. return result;
  4905. }
  4906. int sendSetChargingProfileConfirmation(char *uuid,char *payload)
  4907. {
  4908. mtrace();
  4909. int result = FAIL;
  4910. //[3,"5748585f-8524-4fa6-9b4f-4a7eca750b90",{"status":"NotSupported"}]
  4911. char message[80]={0};
  4912. DEBUG_INFO("sendSetChargingProfileConfirmation...\n");
  4913. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, payload);
  4914. LWS_Send(message);
  4915. result = TRUE;
  4916. return result;
  4917. }
  4918. int sendTriggerMessageConfirmation(char *uuid,char *payload)
  4919. {
  4920. mtrace();
  4921. int result = FAIL;
  4922. char message[80]={0};
  4923. DEBUG_INFO("sendTriggerMessageConfirmation...\n");
  4924. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, payload);
  4925. LWS_Send(message);
  4926. result = TRUE;
  4927. return result;
  4928. }
  4929. int sendUnlockConnectorConfirmation(char *uuid,char *payload)
  4930. {
  4931. mtrace();
  4932. int result = FAIL;
  4933. char message[80]={0};
  4934. //[ 3, "ba1cbd49-2a76-493a-8f76-fa23e7606532", { "status": "Unlocked" } ]
  4935. DEBUG_INFO("sendUnlockConnectorConfirmation...\n");
  4936. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, payload);
  4937. LWS_Send(message);
  4938. result = TRUE;
  4939. return result;
  4940. }
  4941. int sendUpdateFirmwareConfirmation(char *uuid)
  4942. {
  4943. mtrace();
  4944. int result = FAIL;
  4945. char message[60]={0};
  4946. //[ 3, "ba1cbd49-2a76-493a-8f76-fa23e7606532", { "status": "Unlocked" } ]
  4947. DEBUG_INFO("sendUpdateFirmwareConfirmation...\n");
  4948. sprintf(message,"[%d,\"%s\",{}]",MESSAGE_TYPE_CALLRESULT, uuid);
  4949. LWS_Send(message);
  4950. result = TRUE;
  4951. return result;
  4952. }
  4953. //==========================================
  4954. // send CallError routine
  4955. //==========================================
  4956. void SendCallError(char *uniqueId, char *action, char *errorCode, char *errorDescription)
  4957. {
  4958. mtrace();
  4959. char message[220]={0};
  4960. DEBUG_INFO("An error occurred. Sending this information: uniqueId {}: action: {}, errorCore: {}, errorDescription: {}\n", uniqueId, action, errorCode, errorDescription);
  4961. sprintf(message,"[%d,\"%s\",\"%s\",\"%s\",{}]",MESSAGE_TYPE_CALLERROR, uniqueId, errorCode, errorDescription);
  4962. LWS_Send(message);
  4963. }
  4964. //==========================================
  4965. // Handle server request routine Start
  4966. //==========================================
  4967. int handleCancelReservationRequest(char *uuid, char *payload)
  4968. {
  4969. mtrace();
  4970. int result = FAIL;
  4971. int gunNO = 0;
  4972. int reservationIdInt =0;
  4973. char comfirmstr[20];
  4974. DEBUG_INFO("handleCancelReservationRequest...\n");
  4975. json_object *CancelReservation;
  4976. CancelReservation = json_tokener_parse(payload);
  4977. if(!is_error(CancelReservation))
  4978. {
  4979. // Required data
  4980. reservationIdInt = json_object_get_int(json_object_object_get(CancelReservation, "reservationId"));
  4981. }
  4982. json_object_put(CancelReservation);
  4983. memset(comfirmstr, 0, sizeof comfirmstr);
  4984. sprintf(comfirmstr, "%s", CancelReservationStatusStr[CancelReservationStatus_Rejected]);
  4985. //0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault, 8: Reserved, 9: maintain
  4986. //check Transaction active
  4987. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  4988. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  4989. {
  4990. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ReservationId == reservationIdInt)
  4991. {
  4992. sprintf(comfirmstr, "%s", CancelReservationStatusStr[CancelReservationStatus_Accepted] );
  4993. sprintf((char *)ShmOCPP16Data->CancelReservation[ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index].ResponseStatus, "%s", comfirmstr );
  4994. if(gunType[2] == 'J')
  4995. {
  4996. gunNO = ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index + 1;
  4997. }
  4998. else
  4999. {
  5000. gunNO = ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index;
  5001. }
  5002. ShmOCPP16Data->CsMsg.bits[gunNO].CancelReservationReq = 1;
  5003. goto end;
  5004. }
  5005. }
  5006. for (int index = 0; index < CCS_QUANTITY; index++)
  5007. {
  5008. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ReservationId == reservationIdInt)
  5009. {
  5010. sprintf(comfirmstr, "%s", CancelReservationStatusStr[CancelReservationStatus_Accepted] );
  5011. sprintf((char *)ShmOCPP16Data->CancelReservation[ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index].ResponseStatus, "%s", comfirmstr );
  5012. if((gunType[2] == 'U') || (gunType[2] == 'E'))
  5013. {
  5014. gunNO = ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index + 1;
  5015. }
  5016. else
  5017. {
  5018. gunNO = ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index;
  5019. }
  5020. ShmOCPP16Data->CsMsg.bits[gunNO].CancelReservationReq = 1;
  5021. goto end;
  5022. }
  5023. }
  5024. for (int index = 0; index < GB_QUANTITY; index++)
  5025. {
  5026. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ReservationId == reservationIdInt)
  5027. {
  5028. sprintf(comfirmstr, "%s", CancelReservationStatusStr[CancelReservationStatus_Accepted] );
  5029. sprintf((char *)ShmOCPP16Data->CancelReservation[ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index].ResponseStatus, "%s", comfirmstr );
  5030. if(gunType[2] == 'G')
  5031. {
  5032. gunNO = ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index + 1;
  5033. }
  5034. else
  5035. {
  5036. gunNO = ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index;
  5037. }
  5038. ShmOCPP16Data->CsMsg.bits[gunNO].CancelReservationReq = 1;
  5039. goto end;
  5040. }
  5041. }
  5042. for (int index = 0; index < AC_QUANTITY; index++)
  5043. {
  5044. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].ReservationId == reservationIdInt)
  5045. {
  5046. sprintf(comfirmstr, "%s", CancelReservationStatusStr[CancelReservationStatus_Accepted] );
  5047. sprintf((char *)ShmOCPP16Data->CancelReservation[ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index].ResponseStatus, "%s", comfirmstr );
  5048. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  5049. {
  5050. gunNO = 1; //ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index ;
  5051. }
  5052. else
  5053. {
  5054. gunNO = ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index;
  5055. }
  5056. ShmOCPP16Data->CsMsg.bits[gunNO].CancelReservationReq = 1;
  5057. goto end;
  5058. }
  5059. }
  5060. //The reservationId does NOT match the reservationId
  5061. sendCancelReservationConfirmation(uuid, comfirmstr);
  5062. end:
  5063. // Fill in ocpp packet uuid
  5064. strcpy((char *)ShmOCPP16Data->CancelReservation[gunNO].guid, uuid);
  5065. return result;
  5066. }
  5067. int handleChangeAvailabilityRequest(char *uuid, char *payload)
  5068. {
  5069. mtrace();
  5070. int result = FAIL;
  5071. int gunIndex = 0;
  5072. char typeStr[16]={0};
  5073. char comfirmstr[20];
  5074. int specificId = FALSE;
  5075. DEBUG_INFO("handleChangeAvailabilityRequest...\n");
  5076. json_object *ChangeAvailability;
  5077. ChangeAvailability = json_tokener_parse(payload);
  5078. if(!is_error(ChangeAvailability))
  5079. {
  5080. // Required data
  5081. gunIndex = json_object_get_int(json_object_object_get(ChangeAvailability, "connectorId"));
  5082. sprintf((char*)typeStr, "%s", json_object_get_string(json_object_object_get(ChangeAvailability, "type")));
  5083. }
  5084. json_object_put(ChangeAvailability);
  5085. if(gunIndex != 0)
  5086. {
  5087. ShmOCPP16Data->ChangeAvailability[gunIndex - 1].ConnectorId= gunIndex;
  5088. sprintf((char *)ShmOCPP16Data->ChangeAvailability[gunIndex - 1].Type, "%s", typeStr);
  5089. }
  5090. else
  5091. {
  5092. ShmOCPP16Data->ChangeAvailability[0].ConnectorId= gunIndex;
  5093. sprintf((char *)ShmOCPP16Data->ChangeAvailability[0].Type, "%s", typeStr);
  5094. }
  5095. memset(comfirmstr, 0, sizeof comfirmstr);
  5096. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  5097. if((gunIndex == 0) || ((gunIndex - 1) < gunTotalNumber/*(CHAdeMO_QUANTITY+ CCS_QUANTITY + GB_QUANTITY)*/))
  5098. {
  5099. specificId = TRUE;
  5100. }
  5101. if(specificId == FALSE)
  5102. goto end;
  5103. if(strcmp((const char *)typeStr, AvailabilityTypeStr[Inoperative]) == 0)
  5104. {
  5105. //check Transaction active
  5106. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  5107. {
  5108. if ((gunIndex == 0) || ((gunIndex > 0)&&(gunType[gunIndex-1] == 'J')))
  5109. {
  5110. if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_RESERVATION) ) // S_PRECHARGE
  5111. {
  5112. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  5113. goto end;
  5114. }
  5115. else if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_AUTHORIZING) ||
  5116. (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_PREPARING) ||
  5117. (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_CHARGING) ||
  5118. (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_TERMINATING) ||
  5119. (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_COMPLETE)) // S_CHARGING
  5120. {
  5121. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  5122. goto end;
  5123. }
  5124. else
  5125. {
  5126. DEBUG_INFO("ShmSysConfigAndInfo->SysInfo.ChademoChargingData[%d].SystemStatus = %d\n",index, ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus);
  5127. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  5128. goto end;
  5129. }
  5130. }
  5131. }//END FOR CHAdeMO_QUANTITY
  5132. for (int index = 0; index < CCS_QUANTITY; index++)
  5133. {
  5134. if ((gunIndex == 0)|| ((gunIndex > 0)&&((gunType[gunIndex - 1] == 'U')||(gunType[gunIndex - 1] == 'E'))))
  5135. {
  5136. if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_RESERVATION) )// S_PRECHARGE
  5137. {
  5138. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  5139. goto end;
  5140. }
  5141. else if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_AUTHORIZING) ||
  5142. (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_PREPARING) ||
  5143. (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_CHARGING) ||
  5144. (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_TERMINATING) ||
  5145. (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_COMPLETE)) // S_CHARGING
  5146. {
  5147. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  5148. goto end;
  5149. }
  5150. else
  5151. {
  5152. DEBUG_INFO("ShmSysConfigAndInfo->SysInfo.CcsChargingData[%d].SystemStatus=%d\n",index, ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus);
  5153. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  5154. goto end;
  5155. }
  5156. }
  5157. }//END FOR CCS_QUANTITY
  5158. for (int index = 0; index < GB_QUANTITY; index++)
  5159. {
  5160. if ((gunIndex == 0)|| ((gunIndex > 0)&&(gunType[gunIndex-1] == 'G')))
  5161. {
  5162. if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_RESERVATION)) // S_PRECHARGE
  5163. {
  5164. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  5165. goto end;
  5166. }
  5167. else if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_AUTHORIZING) ||
  5168. (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_PREPARING) ||
  5169. (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_CHARGING) ||
  5170. (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_TERMINATING) ||
  5171. (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_COMPLETE)) // S_CHARGING
  5172. {
  5173. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  5174. goto end;
  5175. }
  5176. else
  5177. {
  5178. DEBUG_INFO("ShmSysConfigAndInfo->SysInfo.GbChargingData[%d].SystemStatus=%d\n",index,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus);
  5179. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  5180. goto end;
  5181. }
  5182. }
  5183. }// END FOR GB_QUANTITY
  5184. for (int index = 0; index < AC_QUANTITY; index++)
  5185. {
  5186. if ((gunIndex == 0) || ((gunIndex > 0)&&((gunType[gunIndex-1] > '0')&&(gunType[gunIndex-1] <= '9'))))
  5187. {
  5188. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_RESERVATION)) // S_PRECHARGE
  5189. {
  5190. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  5191. goto end;
  5192. }
  5193. else if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_AUTHORIZING) ||
  5194. (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_PREPARING) ||
  5195. (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_CHARGING) ||
  5196. (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_TERMINATING) ||
  5197. (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_COMPLETE)) // S_CHARGING
  5198. {
  5199. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  5200. goto end;
  5201. }
  5202. else
  5203. {
  5204. DEBUG_INFO("ShmSysConfigAndInfo->SysInfo.AcChargingData[%d].SystemStatus=%d\n",index, ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus);
  5205. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  5206. goto end;
  5207. }
  5208. }
  5209. }//END FOR AC_QUANTITY
  5210. }//END FOR AvailabilityTypeStr[Inoperative]
  5211. if(strcmp((const char *)typeStr, AvailabilityTypeStr[Operative]) == 0)
  5212. {
  5213. //0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault, 8: Reserved, 9: maintain
  5214. //check Transaction active
  5215. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  5216. {
  5217. if (((gunIndex == 0) || ((gunIndex > 0) && (gunType[gunIndex-1] == 'J'))) && (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_FAULT)) //S_FAULT
  5218. {
  5219. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  5220. goto end;
  5221. }
  5222. }//END FOR CHAdeMO_QUANTITY
  5223. for (int index = 0; index < CCS_QUANTITY; index++)
  5224. {
  5225. if (((gunIndex == 0) || ((gunIndex > 0) && ((gunType[gunIndex - 1] == 'U') || (gunType[gunIndex - 1] == 'E')))) && (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_FAULT)) //S_FAULT
  5226. {
  5227. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  5228. goto end;
  5229. }
  5230. }//END FOR CCS_QUANTITY
  5231. for (int index = 0; index < GB_QUANTITY; index++)
  5232. {
  5233. if (((gunIndex == 0) || ((gunIndex > 0)&&(gunType[gunIndex-1] == 'G'))) && (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_FAULT)) //S_FAULT
  5234. {
  5235. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  5236. goto end;
  5237. }
  5238. }// END FOR GB_QUANTITY
  5239. for (int index = 0; index < AC_QUANTITY; index++)
  5240. {
  5241. if( ((gunIndex == 0) || ((gunIndex > 0) && ((gunType[gunIndex-1] > '0') && (gunType[gunIndex-1] <= '9')))) && (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_FAULT)) //S_FAULT
  5242. {
  5243. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  5244. goto end;
  5245. }
  5246. }//END FOR AC_QUANTITY
  5247. }//END FOR AvailabilityTypeStr[Operative]
  5248. end:
  5249. if(gunIndex != 0)
  5250. {
  5251. sprintf((char *)ShmOCPP16Data->ChangeAvailability[gunIndex - 1].ResponseStatus, "%s", comfirmstr );
  5252. }
  5253. else
  5254. {
  5255. sprintf((char *)ShmOCPP16Data->ChangeAvailability[0].ResponseStatus, "%s", comfirmstr );
  5256. }
  5257. if(gunIndex != 0)
  5258. {
  5259. if(strstr(comfirmstr, AvailabilityStatusStr[Rejected]) == NULL)
  5260. ShmOCPP16Data->CsMsg.bits[gunIndex - 1].ChangeAvailabilityReq = 1;
  5261. }
  5262. else
  5263. {
  5264. if(strstr(comfirmstr, AvailabilityStatusStr[Rejected]) == NULL)
  5265. {
  5266. for(int i=0; i < gunTotalNumber/*(CHAdeMO_QUANTITY+ CCS_QUANTITY + GB_QUANTITY)*/; i++)
  5267. ShmOCPP16Data->CsMsg.bits[i].ChangeAvailabilityReq = 1;
  5268. }
  5269. }
  5270. sendChangeAvailabilityConfirmation(uuid, comfirmstr);
  5271. return result;
  5272. }
  5273. int handleChangeConfigurationRequest(char *uuid, char *payload)
  5274. {
  5275. mtrace();
  5276. int result = FAIL;
  5277. char keystr[40]={0};
  5278. char valuestr[100]={0};
  5279. char comfirmstr[20]={0};
  5280. DEBUG_INFO("handleChangeConfigurationRequest...\n");
  5281. json_object *ChangeConfiguration;
  5282. ChangeConfiguration = json_tokener_parse(payload);
  5283. if(!is_error(ChangeConfiguration))
  5284. {
  5285. // Required data
  5286. sprintf((char*)keystr, "%s", json_object_get_string(json_object_object_get(ChangeConfiguration, "key")));
  5287. sprintf((char*)valuestr, "%s", json_object_get_string(json_object_object_get(ChangeConfiguration, "value")));
  5288. }
  5289. json_object_put(ChangeConfiguration);
  5290. if((uuid==NULL) || (payload ==NULL) )
  5291. {
  5292. DEBUG_ERROR("Payload is null\n");
  5293. sprintf(comfirmstr, "%s", ConfigurationStatusStr[ConfigurationStatus_Rejected] );
  5294. }
  5295. else
  5296. {
  5297. int status = setKeyValue(keystr, valuestr);
  5298. switch(status)
  5299. {
  5300. case ConfigurationStatus_Accepted:
  5301. sprintf(comfirmstr, "%s", ConfigurationStatusStr[ConfigurationStatus_Accepted]);
  5302. ShmOCPP16Data->MsMsg.bits.ChangeConfigurationReq = 1;
  5303. StoreConfigurationTable();
  5304. break;
  5305. case ConfigurationStatus_Rejected:
  5306. sprintf(comfirmstr, "%s", ConfigurationStatusStr[ConfigurationStatus_Rejected] );
  5307. break;
  5308. case RebootRequired:
  5309. sprintf(comfirmstr, "%s", ConfigurationStatusStr[RebootRequired]);
  5310. StoreConfigurationTable();
  5311. break;
  5312. case NotSupported:
  5313. sprintf(comfirmstr, "%s", ConfigurationStatusStr[NotSupported] );
  5314. break;
  5315. default:
  5316. break;
  5317. }
  5318. }
  5319. sendChangeConfigurationConfirmation(uuid, comfirmstr);
  5320. ShmOCPP16Data->MsMsg.bits.ChangeConfigurationConf = 1;
  5321. if((strcmp(keystr,"WebSocketPingInterval")==0)&&(strcmp(comfirmstr,"Accepted")==0))
  5322. {
  5323. ChageWebSocketPingInterval(atoi(valuestr));
  5324. }
  5325. return result;
  5326. }
  5327. int handleClearCacheRequest(char *uuid, char *payload)
  5328. {
  5329. mtrace();
  5330. int result = FAIL;
  5331. char comfirmstr[20];
  5332. int fd;
  5333. char rmFileCmd[100]={0};
  5334. struct stat stats;
  5335. DEBUG_INFO("handleClearCacheRequest...\n");
  5336. stat("/Storage/OCPP", &stats);
  5337. // Check for directory existence
  5338. if (S_ISDIR(stats.st_mode) == 1)
  5339. {}
  5340. else
  5341. {
  5342. DEBUG_INFO("\n OCPP directory not exist, create dir \n");
  5343. sprintf(rmFileCmd,"mkdir -p %s","/Storage/OCPP");
  5344. system(rmFileCmd);
  5345. }
  5346. memset(rmFileCmd, 0, sizeof rmFileCmd);
  5347. if((access(AuthorizationCache_JSON,F_OK))!=-1)
  5348. {
  5349. DEBUG_INFO("AuthorizationCache file exist.\n");
  5350. }
  5351. else
  5352. {
  5353. DEBUG_INFO("AuthorizationCache file not exist\n");
  5354. FILE *log = fopen(AuthorizationCache_JSON, "w+");
  5355. if(log == NULL)
  5356. {
  5357. DEBUG_INFO("AuthorizationCache file is NULL\n");
  5358. sprintf(comfirmstr, "%s", ClearCacheStatusStr[ClearCacheStatus_Rejected] );
  5359. goto end;
  5360. }
  5361. else
  5362. {
  5363. fclose(log);
  5364. }
  5365. }
  5366. if((fd = open(AuthorizationCache_JSON,O_RDWR)) < 0)
  5367. {
  5368. DEBUG_INFO("open AuthorizationCache file failed\n");
  5369. sprintf(comfirmstr, "%s", ClearCacheStatusStr[ClearCacheStatus_Rejected] );
  5370. }
  5371. else
  5372. {
  5373. DEBUG_INFO("open AuthorizationCache file successful\n");
  5374. ftruncate(fd,0);
  5375. lseek(fd,0,SEEK_SET);
  5376. close(fd);
  5377. sprintf(comfirmstr, "%s", ClearCacheStatusStr[ClearCacheStatus_Accepted] );
  5378. }
  5379. end:
  5380. sendClearCacheConfirmation(uuid, comfirmstr);
  5381. return result;
  5382. }
  5383. int handleClearChargingProfileRequest(char *uuid, char *payload)
  5384. {
  5385. mtrace();
  5386. int result = FAIL;
  5387. int resultRename;
  5388. int connectorIdInt, chargingProfileIdInt, stackLevelInt;
  5389. char chargingProfilePurposeStr[26]={0};
  5390. int tempconnectorIdInt, tempchargingProfileIdInt, tempstackLevelInt;
  5391. char tempchargingProfilePurposeStr[26]={0};
  5392. char sstr[160]={0};
  5393. char str[100]={0};
  5394. int c = 0;
  5395. char *loc;
  5396. char fname[200]={0};
  5397. char comfirmstr[20]={0};
  5398. char word[1600]={0};
  5399. int clearflag = FALSE;
  5400. int chargingProfileIdIsNULL = FALSE;
  5401. int connectorIsNULL = FALSE;
  5402. int chargingProfilePurposeIsNULL = FALSE;
  5403. int stackLevelIsNULL = FALSE;
  5404. //int GotoEnd = FALSE;
  5405. FILE *fptr1, *fptr2;
  5406. char temp[] = "/Storage/OCPP/ClearChargingProfiletemp.json"; // Create temp file
  5407. int n_chargingProfile=0;
  5408. int isEmptyFile = FALSE;
  5409. char sLineWord[1600]={0};
  5410. char chargingProfiles[10][100]={0};
  5411. int ChargeProfileCount = 0;
  5412. char ch;
  5413. connectorIdInt = chargingProfileIdInt = stackLevelInt = 0;
  5414. DEBUG_INFO("handleClearChargingProfileRequest...\n");
  5415. json_object *ClearChargingProfile;
  5416. ClearChargingProfile = json_tokener_parse(payload);
  5417. if(!is_error(ClearChargingProfile))
  5418. {
  5419. // Optional data
  5420. if(json_object_object_get(ClearChargingProfile, "id") != NULL)
  5421. chargingProfileIdInt = json_object_get_int(json_object_object_get(ClearChargingProfile, "id"));
  5422. else
  5423. chargingProfileIdIsNULL = TRUE;
  5424. if(json_object_object_get(ClearChargingProfile, "connectorId") != NULL)
  5425. connectorIdInt = json_object_get_int(json_object_object_get(ClearChargingProfile, "connectorId"));
  5426. else
  5427. connectorIsNULL = TRUE;
  5428. if(json_object_object_get(ClearChargingProfile, "chargingProfilePurpose") != NULL)
  5429. sprintf((char*)chargingProfilePurposeStr, "%s", json_object_get_string(json_object_object_get(ClearChargingProfile, "chargingProfilePurpose")));
  5430. else
  5431. chargingProfilePurposeIsNULL = TRUE;
  5432. if(json_object_object_get(ClearChargingProfile, "stackLevel") != NULL)
  5433. stackLevelInt = json_object_get_int(json_object_object_get(ClearChargingProfile, "stackLevel"));
  5434. else
  5435. stackLevelIsNULL = TRUE;
  5436. }
  5437. json_object_put(ClearChargingProfile);
  5438. if(connectorIsNULL == FALSE)
  5439. {
  5440. switch(connectorIdInt)
  5441. {
  5442. case 0:
  5443. if(chargingProfilePurposeIsNULL == TRUE)
  5444. {
  5445. int l = 0;
  5446. strcpy(fname, ChargePointMaxProfile_JSON);
  5447. if((access(fname,F_OK))!=-1)
  5448. {
  5449. strcpy(chargingProfiles[l], fname);
  5450. l = l + 1;
  5451. }
  5452. strcpy(fname, TxDefaultProfile_0_JSON);
  5453. if((access(fname,F_OK))!=-1)
  5454. {
  5455. strcpy(chargingProfiles[l], fname);
  5456. l = l + 1;
  5457. }
  5458. ChargeProfileCount = l;
  5459. }
  5460. else if((chargingProfilePurposeIsNULL == FALSE)&&(strcmp(chargingProfilePurposeStr,"ChargePointMaxProfile")==0))
  5461. {
  5462. strcpy(fname, ChargePointMaxProfile_JSON);
  5463. if((access(fname,F_OK))!=-1)
  5464. {
  5465. strcpy(chargingProfiles[0], fname);
  5466. ChargeProfileCount = 1;
  5467. }
  5468. }
  5469. else if((chargingProfilePurposeIsNULL == FALSE)&&(strcmp(chargingProfilePurposeStr,"TxDefaultProfile")==0))
  5470. {
  5471. strcpy(fname, TxDefaultProfile_0_JSON);
  5472. if((access(fname,F_OK))!=-1)
  5473. {
  5474. strcpy(chargingProfiles[0], fname);
  5475. ChargeProfileCount = 1;
  5476. }
  5477. }
  5478. break;
  5479. default:
  5480. if(chargingProfilePurposeIsNULL == TRUE)
  5481. {
  5482. int m = 0;
  5483. memset(fname, 0, sizeof fname);
  5484. sprintf(fname, "/Storage/OCPP/TxDefaultProfile_%d.json", connectorIdInt);
  5485. if((access(fname,F_OK))!=-1)
  5486. {
  5487. strcpy(chargingProfiles[m], fname);
  5488. m = m + 1;
  5489. }
  5490. memset(fname, 0, sizeof fname);
  5491. sprintf(fname, "/Storage/OCPP/TxProfile_%d.json", connectorIdInt);
  5492. if((access(fname,F_OK))!=-1)
  5493. {
  5494. strcpy(chargingProfiles[m], fname);
  5495. m = m + 1;
  5496. }
  5497. ChargeProfileCount = m;
  5498. }
  5499. else if((chargingProfilePurposeIsNULL == FALSE)&&(strcmp(chargingProfilePurposeStr,"TxDefaultProfile")==0))
  5500. {
  5501. //strcpy(fname, TxDefaultProfile_1_JSON);
  5502. sprintf(fname, "/Storage/OCPP/TxDefaultProfile_%d.json", connectorIdInt);
  5503. if((access(fname,F_OK))!=-1)
  5504. {
  5505. strcpy(chargingProfiles[0], fname);
  5506. ChargeProfileCount = 1;
  5507. }
  5508. }
  5509. else if((chargingProfilePurposeIsNULL == FALSE)&&(strcmp(chargingProfilePurposeStr,"TxProfile")==0))
  5510. {
  5511. sprintf(fname, "/Storage/OCPP/TxProfile_%d.json", connectorIdInt);
  5512. if((access(fname,F_OK))!=-1)
  5513. {
  5514. strcpy(chargingProfiles[0], fname);
  5515. ChargeProfileCount = 1;
  5516. }
  5517. //strcpy(fname, TxProfile_1_JSON);
  5518. }
  5519. //strcpy(fname, ChargePointMaxProfile_JSON );
  5520. break;
  5521. }
  5522. }
  5523. else // Check all Charging Profiles
  5524. {
  5525. int i = 0;
  5526. char fnametemp[200]={0};
  5527. ChargeProfileCount = 0;
  5528. //Check ChargePointMaxProfile.json exit
  5529. if((access("/Storage/OCPP/ChargePointMaxProfile.json",F_OK))!=-1)
  5530. {
  5531. strcpy(chargingProfiles[i], "/Storage/OCPP/ChargePointMaxProfile.json");
  5532. i = i + 1;
  5533. }
  5534. //Check TxDefaultProfile_0.json exit
  5535. if((access("/Storage/OCPP/TxDefaultProfile_0.json",F_OK))!=-1)
  5536. {
  5537. strcpy(chargingProfiles[i], "/Storage/OCPP/TxDefaultProfile_0.json");
  5538. i = i + 1;
  5539. }
  5540. //Check TxDefaultProfile_%d.json
  5541. for(int j=1; j <= gunTotalNumber; j++)
  5542. {
  5543. memset(fnametemp, 0, sizeof fnametemp);
  5544. sprintf(fnametemp, "/Storage/OCPP/TxDefaultProfile_%d.json", j);
  5545. if((access(fnametemp,F_OK))!=-1)
  5546. {
  5547. strcpy(chargingProfiles[i], fnametemp);
  5548. i = i + 1;
  5549. }
  5550. }
  5551. //Check TxProfile_%d.json
  5552. for(int j=1; j <= gunTotalNumber; j++)
  5553. {
  5554. memset(fnametemp, 0, sizeof fnametemp);
  5555. sprintf(fnametemp, "/Storage/OCPP/TxProfile_%d.json", j);
  5556. if((access(fnametemp,F_OK))!=-1)
  5557. {
  5558. strcpy(chargingProfiles[i], fnametemp);
  5559. i = i + 1;
  5560. }
  5561. }
  5562. ChargeProfileCount = i;
  5563. }// End connectorIsNULL is TRUE
  5564. if(ChargeProfileCount == 0)
  5565. {
  5566. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Unknown] );
  5567. goto end;
  5568. }
  5569. if(connectorIsNULL == FALSE && (connectorIdInt != 0) && ( (connectorIdInt-1) > gunTotalNumber) )
  5570. {
  5571. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Unknown] );
  5572. goto end;
  5573. }
  5574. if((connectorIsNULL == FALSE) && (connectorIdInt == 0) )
  5575. {
  5576. memset(str, 0, sizeof str);
  5577. // clear temp file
  5578. sprintf(str,"rm -f %s",temp);
  5579. system(str);
  5580. for(int k=0; k < ChargeProfileCount; k++)
  5581. {
  5582. memset(str, 0, sizeof str);
  5583. //clear file in C
  5584. sprintf(str,"rm -f %s",chargingProfiles[k]);
  5585. system(str);
  5586. }
  5587. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Accepted] );
  5588. goto end;
  5589. }
  5590. else if(connectorIsNULL == TRUE)
  5591. {
  5592. for(int k=0; k < ChargeProfileCount; k++)
  5593. {
  5594. fptr1 = fopen(chargingProfiles[k], "r");
  5595. fptr2 = fopen("/Storage/OCPP/ClearChargingProfiletemp.json", "w+");
  5596. //Check Charging Profile Count
  5597. while(fscanf(fptr1, "%s", word) != EOF)
  5598. {
  5599. //DEBUG_INFO("word=%s\n",word);
  5600. if(strstr(word, "chargingProfileId")!= NULL)
  5601. {
  5602. //DEBUG_INFO("test chargingProfileId \n");
  5603. n_chargingProfile = n_chargingProfile + 1;
  5604. //DEBUG_INFO("chargingProfileId Found\n");
  5605. }
  5606. }
  5607. rewind(fptr1);
  5608. //search Charging Profile Element
  5609. //int i= 0;
  5610. while ( fgets( sLineWord, sizeof sLineWord, fptr1 ) != NULL )
  5611. {
  5612. //------------------------tempconnectorIdInt------------------------//
  5613. loc = strstr(sLineWord, "connectorId");
  5614. c = 0;
  5615. memset(sstr ,0, sizeof(sstr) );
  5616. while (loc[strlen("connectorId")+2+c] != ',')
  5617. {
  5618. sstr[c] = loc[strlen("connectorId")+2+c];
  5619. c++;
  5620. }
  5621. sstr[c] = '\0';
  5622. tempconnectorIdInt = atoi(sstr);
  5623. printf("file's gun number is %d\n", tempconnectorIdInt);
  5624. //--------------------------chargingProfileId--------------------//
  5625. c = 0;
  5626. loc = strstr(sLineWord, "chargingProfileId");
  5627. memset(sstr ,0, sizeof(sstr) );
  5628. while (loc[strlen("chargingProfileId")+2+c] != ',')
  5629. {
  5630. sstr[c] = loc[strlen("chargingProfileId")+2+c];
  5631. //printf("i=%d sstr=%c\n",c, sstr[c]);
  5632. c++;
  5633. }
  5634. sstr[c] = '\0';
  5635. tempchargingProfileIdInt = atoi(sstr);
  5636. //stackLevel
  5637. c = 0;
  5638. loc = strstr(sLineWord, "stackLevel");
  5639. memset(sstr ,0, sizeof(sstr) );
  5640. while (loc[strlen("stackLevel")+2+c] != ',')
  5641. {
  5642. sstr[c] = loc[strlen("stackLevel")+2+c];
  5643. //printf("i=%d sstr=%c\n",c, sstr[c]);
  5644. c++;
  5645. }
  5646. sstr[c] = '\0';
  5647. tempstackLevelInt = atoi(sstr);
  5648. c = 0;
  5649. loc = strstr(sLineWord, "chargingProfilePurpose");
  5650. memset(sstr ,0, sizeof(sstr) );
  5651. while (loc[3+strlen("chargingProfilePurpose")+c] != '\"')
  5652. {
  5653. sstr[c] = loc[3+strlen("chargingProfilePurpose")+c];
  5654. c++;
  5655. }
  5656. sstr[c] = '\0';
  5657. strcpy(tempchargingProfilePurposeStr, sstr);
  5658. if((chargingProfileIdIsNULL == FALSE)&&(tempchargingProfileIdInt == chargingProfileIdInt))
  5659. {
  5660. //------- not write to fptr2-------//
  5661. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Accepted] );
  5662. //clearflag = TRUE;
  5663. }
  5664. else if((chargingProfilePurposeIsNULL == FALSE)&&(strcmp(tempchargingProfilePurposeStr, chargingProfilePurposeStr) == 0))
  5665. {
  5666. //------- not write to fptr2-------//
  5667. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Accepted] );
  5668. }
  5669. else if((stackLevelIsNULL == FALSE) &&(tempstackLevelInt == stackLevelInt))
  5670. {
  5671. //------- not write to fptr2-------//
  5672. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Accepted] );
  5673. }
  5674. else
  5675. {
  5676. fprintf(fptr2, sLineWord);//writing data into file
  5677. }
  5678. memset(sLineWord, 0, sizeof sLineWord);
  5679. } //End of while ( fgets( sLineWord, sizeof sLineWord, fptr1 ) != NULL )
  5680. if(clearflag == TRUE)
  5681. {
  5682. fclose(fptr1);
  5683. fclose(fptr2);
  5684. sprintf(str,"rm -f %s",chargingProfiles[k]);
  5685. system(str);
  5686. // clear temp file
  5687. sprintf(str,"rm -f %s",temp);
  5688. system(str);
  5689. }
  5690. else
  5691. {
  5692. fclose(fptr1);
  5693. fclose(fptr2);
  5694. memset(str, 0, sizeof str);
  5695. sprintf(str,"rm -f %s",chargingProfiles[k]);
  5696. system(str);
  5697. resultRename = rename(temp, chargingProfiles[k]);
  5698. if(resultRename == 0)
  5699. {
  5700. DEBUG_INFO("File ChargingProfile renamed successfully");
  5701. }
  5702. else
  5703. {
  5704. DEBUG_INFO("Error: unable to rename the ChargingProfile file");
  5705. }
  5706. if(comfirmstr[0]== 0)
  5707. {
  5708. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Unknown] );
  5709. }
  5710. //Check chargingProfile is empty file
  5711. /*------ Read the file ----------------*/
  5712. fptr1=fopen(chargingProfiles[k],"r");
  5713. ch=fgetc(fptr1);
  5714. rewind(fptr1);
  5715. memset(sLineWord, 0, sizeof sLineWord);
  5716. if(ch!=EOF)
  5717. {
  5718. while (fgets( sLineWord, sizeof sLineWord, fptr1) != NULL)
  5719. {
  5720. str[strlen(sLineWord) - 1] = '\0'; // eat the newline fgets() stores
  5721. if(sLineWord[0]=='\0')
  5722. {
  5723. isEmptyFile = TRUE;
  5724. break;
  5725. }
  5726. else
  5727. {
  5728. isEmptyFile = FALSE;
  5729. break;
  5730. }
  5731. }
  5732. }
  5733. fclose(fptr1);
  5734. if(isEmptyFile == TRUE)
  5735. {
  5736. memset(str, 0, sizeof str);
  5737. sprintf(str,"rm -f %s",chargingProfiles[k]);
  5738. system(str);
  5739. }
  5740. }
  5741. }// End of while(int k=0; k < ChargePointCount; k++)
  5742. }
  5743. else if((connectorIsNULL == FALSE) && (connectorIdInt != 0) )
  5744. {
  5745. DEBUG_INFO("ChargeProfileCount = %d\n", ChargeProfileCount);
  5746. for(int k=0; k < ChargeProfileCount; k++)
  5747. {
  5748. fptr1 = fopen(chargingProfiles[k], "r");
  5749. fptr2 = fopen(temp, "w+");
  5750. //Check Charging Profile Count
  5751. while(fscanf(fptr1, "%s", word) != EOF)
  5752. {
  5753. //DEBUG_INFO("word=%s\n",word);
  5754. if(strstr(word, "chargingProfileId")!= NULL)
  5755. {
  5756. n_chargingProfile = n_chargingProfile + 1;
  5757. }
  5758. }
  5759. rewind(fptr1);
  5760. //search Charging Profile Element
  5761. //int i= 0;
  5762. while ( fgets( sLineWord, sizeof sLineWord, fptr1 ) != NULL )
  5763. {
  5764. //*************************tempconnectorIdInt*********************************/
  5765. loc = strstr(sLineWord, "connectorId");
  5766. c = 0;
  5767. memset(sstr ,0, sizeof(sstr) );
  5768. while (loc[strlen("connectorId")+2+c] != ',')
  5769. {
  5770. sstr[c] = loc[strlen("connectorId")+2+c];
  5771. c++;
  5772. }
  5773. sstr[c] = '\0';
  5774. tempconnectorIdInt = atoi(sstr);
  5775. //chargingProfileId
  5776. c = 0;
  5777. loc = strstr(sLineWord, "chargingProfileId");
  5778. memset(sstr ,0, sizeof(sstr) );
  5779. while (loc[strlen("chargingProfileId")+2+c] != ',')
  5780. {
  5781. sstr[c] = loc[strlen("chargingProfileId")+2+c];
  5782. //printf("i=%d sstr=%c\n",c, sstr[c]);
  5783. c++;
  5784. }
  5785. sstr[c] = '\0';
  5786. tempchargingProfileIdInt = atoi(sstr);
  5787. //stackLevel
  5788. c = 0;
  5789. loc = strstr(sLineWord, "stackLevel");
  5790. memset(sstr ,0, sizeof(sstr) );
  5791. while (loc[strlen("stackLevel")+2+c] != ',')
  5792. {
  5793. sstr[c] = loc[strlen("stackLevel")+2+c];
  5794. //printf("i=%d sstr=%c\n",c, sstr[c]);
  5795. c++;
  5796. }
  5797. sstr[c] = '\0';
  5798. tempstackLevelInt = atoi(sstr);
  5799. c = 0;
  5800. loc = strstr(sLineWord, "chargingProfilePurpose");
  5801. memset(sstr ,0, sizeof(sstr) );
  5802. while (loc[3+strlen("chargingProfilePurpose")+c] != '\"')
  5803. {
  5804. sstr[c] = loc[3+strlen("chargingProfilePurpose")+c];
  5805. c++;
  5806. }
  5807. sstr[c] = '\0';
  5808. strcpy(tempchargingProfilePurposeStr, sstr);
  5809. if((chargingProfileIdIsNULL == FALSE)&&(tempchargingProfileIdInt == chargingProfileIdInt))
  5810. {
  5811. //------- not write to fptr2-------//
  5812. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Accepted] );
  5813. //clearflag = TRUE;
  5814. }
  5815. else if((stackLevelIsNULL == FALSE) &&(tempstackLevelInt == stackLevelInt))
  5816. {
  5817. //------- not write to fptr2-------//
  5818. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Accepted] );
  5819. }
  5820. else if(stackLevelIsNULL == TRUE)
  5821. {
  5822. //Clear Whole File
  5823. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Accepted] );
  5824. clearflag = TRUE;
  5825. break;
  5826. }
  5827. else
  5828. {
  5829. fprintf(fptr2, sLineWord);//writing data into file
  5830. }
  5831. memset(sLineWord, 0, sizeof sLineWord);
  5832. }
  5833. if(clearflag == TRUE)
  5834. {
  5835. fclose(fptr1);
  5836. fclose(fptr2);
  5837. sprintf(str,"rm -f %s",chargingProfiles[k]);
  5838. system(str);
  5839. // clear temp file
  5840. sprintf(str,"rm -f %s",temp);
  5841. system(str);
  5842. }
  5843. else
  5844. {
  5845. fclose(fptr1);
  5846. fclose(fptr2);
  5847. sprintf(str,"rm -f %s",chargingProfiles[k]);
  5848. system(str);
  5849. resultRename = rename(temp, chargingProfiles[k]);
  5850. if(resultRename == 0)
  5851. {
  5852. DEBUG_INFO("File ChargingProfile renamed successfully");
  5853. }
  5854. else
  5855. {
  5856. DEBUG_INFO("Error: unable to rename the ChargingProfile file");
  5857. }
  5858. if(comfirmstr[0]== 0)
  5859. {
  5860. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Unknown] );
  5861. }
  5862. //Check chargingProfile is empty file
  5863. /*------ Read the file ----------------*/
  5864. fptr1=fopen(chargingProfiles[k],"r");
  5865. ch=fgetc(fptr1);
  5866. rewind(fptr1);
  5867. memset(sLineWord, 0, sizeof sLineWord);
  5868. if(ch!=EOF)
  5869. {
  5870. while (fgets( sLineWord, sizeof sLineWord, fptr1) != NULL)
  5871. {
  5872. str[strlen(sLineWord) - 1] = '\0'; // eat the newline fgets() stores
  5873. if(sLineWord[0]=='\0')
  5874. {
  5875. isEmptyFile = TRUE;
  5876. break;
  5877. }
  5878. else
  5879. {
  5880. isEmptyFile = FALSE;
  5881. break;
  5882. }
  5883. }
  5884. }
  5885. fclose(fptr1);
  5886. if(isEmptyFile == TRUE)
  5887. {
  5888. memset(str, 0, sizeof str);
  5889. sprintf(str,"rm -f %s",chargingProfiles[k]);
  5890. system(str);
  5891. }
  5892. /*------- End of reading ---------------*/
  5893. }
  5894. } // while(int k=0; k < ChargeProfileCount; k++)
  5895. }// (connectorIsNULL == FALSE) && (connectorIdInt != 0)
  5896. end:
  5897. sendClearChargingProfileConfirmation(uuid, comfirmstr);
  5898. return result;
  5899. }
  5900. int handleDataTransferRequest(char *uuid, char *payload)
  5901. {
  5902. mtrace();
  5903. int result = FAIL;
  5904. //Payload={"vendorId":"Phihong","messageId":"MSGID","data":"Data1"}
  5905. char tempvendorId[255]={0};
  5906. char tempmessageId[50]={0};
  5907. char tempdata[50]={0};
  5908. char message[80]={0};
  5909. DEBUG_INFO("handleDataTransferRequest...\n");
  5910. if((uuid != NULL) && (payload != NULL))
  5911. {
  5912. json_object *DataTransfer;
  5913. DataTransfer = json_tokener_parse(payload);
  5914. if(!is_error(DataTransfer))
  5915. {
  5916. // Required data
  5917. sprintf((char*)tempvendorId, "%s", json_object_get_string(json_object_object_get(DataTransfer, "vendorId")));
  5918. // Optional data
  5919. if(json_object_object_get(DataTransfer, "messageId") != NULL)
  5920. sprintf((char*)tempmessageId, "%s", json_object_get_string(json_object_object_get(DataTransfer, "messageId")));
  5921. if(json_object_object_get(DataTransfer, "data") != NULL)
  5922. sprintf((char*)tempdata, "%s", json_object_get_string(json_object_object_get(DataTransfer, "data")));
  5923. result = PASS;
  5924. }
  5925. json_object_put(DataTransfer);
  5926. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\",\"data\":\"vendorId-%s messageId-%s data-%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, "Rejected", tempvendorId, tempmessageId, tempdata );
  5927. }
  5928. else
  5929. {
  5930. char guid[37]={0};
  5931. random_uuid(guid);
  5932. //[2,"1577349264923","DataTransfer",{"vendorId":"Phihong","messageId":"MSGID","data":"Data1"}]
  5933. sprintf(message,"[%d,\"%s\",\"%s\",{\"vendorId\":\"Phihong\",\"messageId\":\"MSGID\",\"data\":\"Data1\"}]",MESSAGE_TYPE_CALL, guid, "DataTransfer");
  5934. }
  5935. LWS_Send(message);
  5936. return result;
  5937. }
  5938. int handleGetCompositeScheduleRequest(char *uuid, char *payload)
  5939. {
  5940. mtrace();
  5941. int result = FAIL;
  5942. int connectorIdInt, durationInt;
  5943. char chargingRateUnitStr[4]={0};
  5944. char comfirmstr[20];
  5945. int confirmPeriods = 0;
  5946. DEBUG_INFO("handleGetCompositeScheduleRequest...\n");
  5947. json_object *GetCompositeSchedule;
  5948. GetCompositeSchedule = json_tokener_parse(payload);
  5949. if(!is_error(GetCompositeSchedule))
  5950. {
  5951. // Required data
  5952. connectorIdInt= json_object_get_int(json_object_object_get(GetCompositeSchedule, "connectorId"));
  5953. durationInt = json_object_get_int(json_object_object_get(GetCompositeSchedule, "duration"));
  5954. // Optional data
  5955. if(json_object_object_get(GetCompositeSchedule, "chargingRateUnit") != NULL)
  5956. sprintf((char*)chargingRateUnitStr, "%s", json_object_get_string(json_object_object_get(GetCompositeSchedule, "chargingRateUnit")));
  5957. }
  5958. json_object_put(GetCompositeSchedule);
  5959. memset(ShmOCPP16Data->GetCompositeSchedule, 0, sizeof(struct StructChargingSchedulePeriod)*gunTotalNumber);
  5960. if((connectorIdInt == 0) ||
  5961. ((connectorIdInt > 0) && ((connectorIdInt -1) < gunTotalNumber)))
  5962. {
  5963. int gun_index = (connectorIdInt==0?0:connectorIdInt-1);
  5964. struct StructChargingProfile tmpProfile[1];
  5965. checkCompositeSchedule(connectorIdInt, durationInt, &tmpProfile[0]);
  5966. for(int idx=0;idx<ARRAY_SIZE(ShmOCPP16Data->GetCompositeSchedule[gun_index].ResponseChargingSchedule.ChargingSchedulePeriod);idx++)
  5967. {
  5968. DEBUG_INFO("Smart Period-%02d start: %d\n", idx, tmpProfile[0].ChargingSchedule.ChargingSchedulePeriod[idx].StartPeriod);
  5969. DEBUG_INFO("Smart Period-%02d limit: %f\n", idx, tmpProfile[0].ChargingSchedule.ChargingSchedulePeriod[idx].Limit);
  5970. }
  5971. ShmOCPP16Data->GetCompositeSchedule[gun_index].ResponseConnectorId = connectorIdInt;
  5972. memcpy(&ShmOCPP16Data->GetCompositeSchedule[gun_index].ResponseChargingSchedule, &tmpProfile[0].ChargingSchedule, sizeof(struct StructChargingSchedule));
  5973. memcpy(&ShmOCPP16Data->GetCompositeSchedule[gun_index].ResponseScheduleStart ,&tmpProfile[0].ChargingSchedule.StartSchedule, ARRAY_SIZE(tmpProfile[0].ChargingSchedule.StartSchedule));
  5974. for(int idx=0;idx<ARRAY_SIZE(ShmOCPP16Data->GetCompositeSchedule[gun_index].ResponseChargingSchedule.ChargingSchedulePeriod);idx++)
  5975. {
  5976. DEBUG_INFO("Composite Period-%02d start: %d\n", idx, ShmOCPP16Data->GetCompositeSchedule[gun_index].ResponseChargingSchedule.ChargingSchedulePeriod[idx].StartPeriod);
  5977. DEBUG_INFO("Composite Period-%02d limit: %f\n", idx, ShmOCPP16Data->GetCompositeSchedule[gun_index].ResponseChargingSchedule.ChargingSchedulePeriod[idx].Limit);
  5978. if((ShmOCPP16Data->GetCompositeSchedule[gun_index].ResponseChargingSchedule.ChargingSchedulePeriod[idx].StartPeriod==0) &&
  5979. (ShmOCPP16Data->GetCompositeSchedule[gun_index].ResponseChargingSchedule.ChargingSchedulePeriod[idx].Limit==0))
  5980. {
  5981. confirmPeriods = idx;
  5982. break;
  5983. }
  5984. }
  5985. sprintf(comfirmstr, "%s", GetCompositeScheduleStatusStr[GetCompositeScheduleStatus_Accepted] );
  5986. }
  5987. else
  5988. {
  5989. sprintf(comfirmstr, "%s", GetCompositeScheduleStatusStr[GetCompositeScheduleStatus_Rejected] );
  5990. }
  5991. sendGetCompositeScheduleConfirmation(uuid, comfirmstr, connectorIdInt, confirmPeriods);
  5992. return result;
  5993. }
  5994. int handleGetConfigurationRequest(char *uuid, char *payload)
  5995. {
  5996. mtrace();
  5997. int result = FAIL;
  5998. int MaxKeySupported = 0;
  5999. int n_keys = 0;
  6000. char requestKey[43][50]={0};
  6001. DEBUG_INFO("handleGetConfigurationRequest...\n");
  6002. json_object *GetConfiguration;
  6003. GetConfiguration = json_tokener_parse(payload);
  6004. if(!is_error(GetConfiguration))
  6005. {
  6006. // Optional data
  6007. if(json_object_object_get(GetConfiguration, "key") != NULL)
  6008. {
  6009. for(int idx=0;idx<json_object_array_length(json_object_object_get(GetConfiguration, "key"));idx++)
  6010. {
  6011. sprintf((char*)requestKey[idx], "%s", json_object_get_string(json_object_array_get_idx(json_object_object_get(GetConfiguration, "key"), idx)));
  6012. n_keys = idx + 1;
  6013. }
  6014. }
  6015. }
  6016. json_object_put(GetConfiguration);
  6017. UnknownKeynum = 0;
  6018. memset( (void *)unknownkey, 0, sizeof(unknownkey));
  6019. MaxKeySupported = GetConfigurationMaxKeysNUM;
  6020. memset(ShmOCPP16Data->GetConfiguration.Key, 0 ,sizeof(struct StructConfigurationKeyItems)*MaxKeySupported);
  6021. memset(ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey, 0, sizeof(struct StructConfigurationKey)*MaxKeySupported);
  6022. if(n_keys != 0)
  6023. {
  6024. for(int i=0;i<n_keys;i++)
  6025. {
  6026. getKeyValue(requestKey[i]);
  6027. }
  6028. }
  6029. else
  6030. {
  6031. DEBUG_INFO("There is no key in Message, get all configuration\n");
  6032. getKeyValue("");
  6033. }
  6034. processUnkownKey();
  6035. sendGetConfigurationConfirmation(uuid);
  6036. return result;
  6037. }
  6038. static char fnamePlusPath[100]={0};
  6039. static char fnamePWithNoPath[60]={0};
  6040. void checkUploadLog(void)
  6041. {
  6042. FILE *fp;
  6043. /* Open the command for reading. */
  6044. fp = popen("find /mnt/ -type f -name \"*.zip\" |xargs ls -t", "r");
  6045. if (fp == NULL) {
  6046. printf("Failed to run command\n" );
  6047. exit(1);
  6048. }
  6049. int ftppathlen = 0;
  6050. memset(fnamePlusPath, 0, sizeof(fnamePlusPath));
  6051. int i = 0;
  6052. /* Read the output a line at a time - output it. */
  6053. while (fgets(fnamePlusPath, sizeof(fnamePlusPath), fp) != NULL) {
  6054. if(i==0)
  6055. {
  6056. ftppathlen = strlen(fnamePlusPath);
  6057. printf("%s\n", fnamePlusPath);
  6058. fnamePlusPath[ftppathlen]='\0';
  6059. break;
  6060. }
  6061. i= i+1;
  6062. }
  6063. /* close */
  6064. pclose(fp);
  6065. for(int k=0; k< sizeof(fnamePlusPath); k++)
  6066. {
  6067. if((fnamePlusPath[k]=='\n') || (fnamePlusPath[k]=='r'))
  6068. {
  6069. fnamePlusPath[k]='\0';
  6070. }
  6071. }
  6072. i=1;
  6073. //char fname[60]={0};
  6074. while(i < ftppathlen)
  6075. {
  6076. int len=ftppathlen-i;
  6077. if(fnamePlusPath[len]== 47) // '/' ascll code: 47
  6078. {
  6079. printf("compare '/' all right\n");
  6080. break;
  6081. }
  6082. i=i+1;
  6083. }
  6084. memset(fnamePWithNoPath, 0, sizeof(fnamePWithNoPath));
  6085. strncpy(fnamePWithNoPath, fnamePlusPath+(ftppathlen-i+1), i+1);
  6086. fnamePWithNoPath[i+1] = '\0';
  6087. for(int j=0; j< sizeof(fnamePWithNoPath); j++)
  6088. {
  6089. if((fnamePWithNoPath[j]=='\n') || (fnamePWithNoPath[j]=='r'))
  6090. {
  6091. fnamePWithNoPath[j]='\0';
  6092. }
  6093. }
  6094. FILE* fp1 = fopen(fnamePlusPath, "r");
  6095. if (fp1)
  6096. {
  6097. printf("testfuc : fnamePlusPath=%s exist.\n", fnamePlusPath);
  6098. // file exists
  6099. fclose(fp1);
  6100. }
  6101. else
  6102. {
  6103. // file doesn't exist
  6104. printf("testfuc : fnamePlusPath=%s not exist!\n", fnamePlusPath);
  6105. }
  6106. }
  6107. int handleGetDiagnosticsRequest(char *uuid, char *payload)
  6108. {
  6109. mtrace();
  6110. int result = FAIL;
  6111. char cmdBuf[512];
  6112. char fName[258];
  6113. time_t CurrentTime;
  6114. struct tm *tm;
  6115. pthread_t th_Status;
  6116. CurrentTime = time(NULL);
  6117. tm = localtime(&CurrentTime);
  6118. sprintf(fName ,"%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);
  6119. sendGetDiagnosticsConfirmation(uuid, fName);
  6120. system("exec /root/logPackTools 'log' 6");
  6121. sprintf(cmdBuf, "mv /mnt/log.zip /mnt/%s", fName);
  6122. system(cmdBuf);
  6123. checkUploadLog();
  6124. pthread_create(&th_Status, NULL, GetDiagnosticsProcess, stringtrimspace(payload));
  6125. return result;
  6126. }
  6127. void* GetDiagnosticsProcess(void* data)
  6128. {
  6129. pthread_detach(pthread_self());
  6130. mtrace();
  6131. int retriesInt=0, retryIntervalInt=0;
  6132. char locationstr[100]={0}, startTimestr[30]={0}, stopTimestr[30]={0} ;
  6133. int retriesIsNULL,retryIntervalIsNULL, startTimeIsNULL, stopTimeIsNULL;
  6134. char protocol[10]={0}, user[50]={0},password[50]={0},host[50]={0}, path[50]={0}, ftppath[60]={0},host1[50]={0},path1[50]={0};
  6135. int port=0;
  6136. char sstr[260]={ 0 };
  6137. int c = 0;
  6138. char *loc;
  6139. int isSuccess = FALSE;
  6140. char ftpbuf[200]={0};
  6141. char * pch;
  6142. char str[300]={ 0 };
  6143. strcpy(str,(const char*)data);
  6144. retriesIsNULL = retryIntervalIsNULL = startTimeIsNULL = stopTimeIsNULL = FALSE;
  6145. DEBUG_INFO("GetDiagnosticsProcess...%s\n", str);
  6146. sendDiagnosticsStatusNotificationRequest(DiagnosticsStatusStr[DiagnosticsStatus_Uploading]);
  6147. //****************location*******************/
  6148. c = 0;
  6149. memset(sstr ,0, sizeof(sstr) );
  6150. loc = strstr(str, "location");
  6151. while (loc[3+strlen("location")+c] != '\"')
  6152. {
  6153. sstr[c] = loc[3+strlen("location")+c];
  6154. c++;
  6155. }
  6156. sstr[c] = '\0';
  6157. strcpy(locationstr,sstr);
  6158. //strcpy(locationstr,"http://test.evsocket.phihong.com.cn:9001/UploadFiles/Diagnostics/");
  6159. if(strcmp(locationstr,"")==0)
  6160. {
  6161. DEBUG_INFO("location is <Empty>!\n");
  6162. sendDiagnosticsStatusNotificationRequest(DiagnosticsStatusStr[DiagnosticsStatus_UploadFailed]);
  6163. goto end;
  6164. }
  6165. //****************retries*******************/
  6166. c = 0;
  6167. loc = strstr(str, "retries");
  6168. if(loc == NULL)
  6169. {
  6170. retriesIsNULL = TRUE;
  6171. }
  6172. else
  6173. {
  6174. while ((loc[strlen("retries")+2+c] != ',')&&(loc[strlen("retries")+2+c] != '}'))
  6175. {
  6176. sstr[c] = loc[strlen("retries")+2+c];
  6177. c++;
  6178. }
  6179. sstr[c] = '\0';
  6180. retriesInt = atoi(sstr);
  6181. }
  6182. if(retriesIsNULL == TRUE)
  6183. {
  6184. retriesInt = 3; // If this field is not present, it is left to Charge Point to decide how many times it wants to retry.
  6185. }
  6186. //****************retryInterval*******************/
  6187. c = 0;
  6188. loc = strstr(str, "retryInterval");
  6189. if(loc == NULL)
  6190. {
  6191. retryIntervalIsNULL = TRUE;
  6192. retryIntervalInt = 30; // if this field is not present, it is left to Charge Point to decide how long to wait between attempts.
  6193. }
  6194. else
  6195. {
  6196. while ((loc[strlen("retryInterval")+2+c] != ',')&&(loc[strlen("retries")+2+c] != '}'))
  6197. {
  6198. sstr[c] = loc[strlen("retryInterval")+2+c];
  6199. c++;
  6200. }
  6201. sstr[c] = '\0';
  6202. retryIntervalInt = atoi(sstr);
  6203. }
  6204. //****************startTime*******************/
  6205. c = 0;
  6206. memset(sstr ,0, sizeof(sstr) );
  6207. loc = strstr(str, "startTime");
  6208. if(loc == NULL)
  6209. {
  6210. startTimeIsNULL = TRUE;
  6211. }
  6212. else
  6213. {
  6214. while (loc[3+strlen("startTime")+c] != '\"')
  6215. {
  6216. sstr[c] = loc[3+strlen("startTime")+c];
  6217. c++;
  6218. }
  6219. sstr[c] = '\0';
  6220. strcpy(startTimestr,sstr);
  6221. }
  6222. //****************stopTime*******************/
  6223. c = 0;
  6224. memset(sstr ,0, sizeof(sstr) );
  6225. loc = strstr(str, "stopTime");
  6226. if(loc == NULL)
  6227. {
  6228. stopTimeIsNULL = TRUE;
  6229. }
  6230. else
  6231. {
  6232. while (loc[3+strlen("stopTime")+c] != '\"')
  6233. {
  6234. sstr[c] = loc[3+strlen("stopTime")+c];
  6235. c++;
  6236. }
  6237. sstr[c] = '\0';
  6238. strcpy(stopTimestr,sstr);
  6239. }
  6240. memset(protocol, 0, sizeof(protocol));
  6241. memset(user, 0, sizeof(user) );
  6242. memset(password, 0, sizeof(password));
  6243. memset(host, 0, sizeof(host));
  6244. memset(path, 0, sizeof(path));
  6245. memset(ftppath, 0, sizeof(ftppath));
  6246. memset(host1, 0, sizeof(host1));
  6247. memset(path1, 0, sizeof(path1));
  6248. /*location: ftp://user:password@host:port/path*/
  6249. //DEBUG_INFO("fnamePlusPath =%s\n",fnamePlusPath);
  6250. if((access(fnamePlusPath,F_OK))!=-1)
  6251. {
  6252. DEBUG_INFO("fnamePlusPath exist.\n");
  6253. }
  6254. else
  6255. {
  6256. DEBUG_INFO("fnamePlusPath not exist!\n");
  6257. sendDiagnosticsStatusNotificationRequest(DiagnosticsStatusStr[DiagnosticsStatus_UploadFailed]);
  6258. goto end;
  6259. }
  6260. pch=strchr(locationstr,'@');
  6261. if(pch==NULL)
  6262. {
  6263. sscanf(locationstr,
  6264. "%[^:]:%*2[/]%[^:]:%i/%[a-zA-Z0-9._/-]",
  6265. protocol, host, &port, path);
  6266. strcpy(user,"anonymous");
  6267. strcpy(password,"");
  6268. }
  6269. else
  6270. {
  6271. //DEBUG_INFO("pch=%s\n", pch);
  6272. sscanf(locationstr,"%[^:]:%*2[/]%[^:]:%[^@]@%[^:]:%i/%199[^\n]",
  6273. protocol, user, password, host, &port, path);
  6274. }
  6275. if((strcmp(protocol,"ftp")!=0)&&(strcmp(protocol,"http")!=0))
  6276. {
  6277. DEBUG_INFO("protocol is not ftp/http ! \n");
  6278. sendDiagnosticsStatusNotificationRequest(DiagnosticsStatusStr[DiagnosticsStatus_UploadFailed]);
  6279. goto end;
  6280. }
  6281. if(strncmp(locationstr,"http", 4) == 0)
  6282. {
  6283. sscanf(locationstr,"%[^:]:%*2[/]%[^/]/%199[^\n]", protocol, host, path);
  6284. sprintf(ftppath,"/%s", path);
  6285. do{
  6286. isSuccess = httpUploadFile(host, ftppath, fnamePlusPath, locationstr);
  6287. sleep(retryIntervalInt);
  6288. }while((isSuccess == 0)&&(retriesInt > 0 && retriesInt --));
  6289. if(!isSuccess)
  6290. {
  6291. DEBUG_INFO("Diagnostics fail.\n");
  6292. sendDiagnosticsStatusNotificationRequest(DiagnosticsStatusStr[DiagnosticsStatus_UploadFailed]);
  6293. }
  6294. else
  6295. {
  6296. DEBUG_INFO("sendDiagnosticsStatusNotificationRequest Uploaded\n");
  6297. sendDiagnosticsStatusNotificationRequest(DiagnosticsStatusStr[DiagnosticsStatus_Uploaded]);
  6298. }
  6299. }
  6300. else
  6301. {
  6302. sscanf(host,"%[^/]%s",host1, path1);
  6303. sprintf(ftppath,"%s", path1);
  6304. int ftppathlen=strlen(ftppath);
  6305. int i=1;
  6306. char filenametemp[50];
  6307. while(i < ftppathlen)
  6308. {
  6309. int len=ftppathlen-i;
  6310. if(ftppath[len]== 47) // '/' ascll code: 47
  6311. {
  6312. DEBUG_INFO("find '/' all right\n");
  6313. break;
  6314. }
  6315. i=i+1;
  6316. }
  6317. memset(filenametemp, 0, sizeof(filenametemp));
  6318. strncpy(filenametemp, ftppath+(ftppathlen-i+1), i+1);
  6319. filenametemp[i+1] = 0;
  6320. memset(ftpbuf, 0, sizeof(ftpbuf));
  6321. if(port == 0)
  6322. port = 21;
  6323. do{
  6324. isSuccess = ftpFile(host1, user, password, port, ftppath, fnamePlusPath, fnamePWithNoPath);
  6325. sleep(retryIntervalInt);
  6326. }while((!isSuccess)&&(retriesInt > 0 && retriesInt --));
  6327. if(!isSuccess)
  6328. {
  6329. DEBUG_INFO("Diagnostics fail.\n");
  6330. sendDiagnosticsStatusNotificationRequest(DiagnosticsStatusStr[DiagnosticsStatus_UploadFailed]);
  6331. }
  6332. else
  6333. {
  6334. DEBUG_INFO("sendDiagnosticsStatusNotificationRequest Uploaded\n");
  6335. sendDiagnosticsStatusNotificationRequest(DiagnosticsStatusStr[DiagnosticsStatus_Uploaded]);
  6336. }
  6337. }
  6338. end:
  6339. DiagnosticsStatusNotificationStatus = DIAGNOSTIC_STATUS_IDLE;
  6340. pthread_exit(NULL);
  6341. }
  6342. int handleGetLocalListVersionRequest(char *uuid, char *payload)
  6343. {
  6344. mtrace();
  6345. int result = FAIL;
  6346. DEBUG_INFO("handle GetLocalListVersionRequest\n");
  6347. if(strcmp((const char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "FALSE") == 0)
  6348. {
  6349. DEBUG_INFO("LocalAuthListEnabled is FALSE \n");
  6350. localversion = -1;
  6351. }
  6352. else
  6353. {
  6354. DEBUG_INFO("handle GetLocalListVersionRequest OCPP_getListVerion \n");
  6355. OCPP_getListVerion();
  6356. }
  6357. //from db.OCPP_getListVerion
  6358. ShmOCPP16Data->GetLocalListVersion.ResponseListVersion = localversion;
  6359. //ShmOCPP16Data->MsMsg.bits.GetLocalListVersionReq = 1;
  6360. sendGetLocalListVersionConfirmation(uuid,"");
  6361. //ShmOCPP16Data->MsMsg.bits.GetLocalListVersionConf = 1;
  6362. return result;
  6363. }
  6364. int handleRemoteStartRequest(char *uuid, char *payload)
  6365. {
  6366. mtrace();
  6367. int result = FAIL;
  6368. int connectorIdInt=0, chargingProfileIdInt=0, transactionIdInt=0, stackLevelInt=0,
  6369. durationInt=0, startPeriodInt[10]={0}, numberPhasesInt[10]={0};
  6370. int tempIndex = 0;
  6371. char idTagstr[20]={0}, chargingProfilePurposestr[30]={0}, chargingProfileKindstr[14]={0}, recurrencyKindstr[10]={0},
  6372. validFromstr[30]={0}, validTostr[30]={0}, startSchedulestr[30]={0}, chargingRateUnitstr[4]={0};
  6373. int connectorIdIsNULL,chargingProfileIsNULL,transactionIdIsNULL,recurrencyKindIsNULL,validFromIsNULL,validToIsNULL,durationIsNULL,startScheduleIsNULL,minChargingRateIsNULL,numberPhasesIsNULL;
  6374. float minChargingRateflaot=0.0, limitflaot[10]={0.0};
  6375. int chargingSchedulePeriodCount = 0;
  6376. char sstr[30]={ 0 },sstrtemp[1600]={ 0 };//sstr[200]={ 0 };
  6377. int c = 0;
  6378. char *loc;
  6379. char comfirmstr[20]={0};
  6380. DEBUG_INFO("handleRemoteStartRequest ...\n");
  6381. if(server_pending == TRUE)
  6382. {
  6383. return 0;
  6384. }
  6385. connectorIdIsNULL = chargingProfileIsNULL = transactionIdIsNULL = recurrencyKindIsNULL = validFromIsNULL = validToIsNULL = durationIsNULL = startScheduleIsNULL = minChargingRateIsNULL = numberPhasesIsNULL= FALSE;
  6386. strcpy(sstrtemp, stringtrimspace(payload));
  6387. //**********connectorId****************/
  6388. c = 0;
  6389. memset(sstr ,0, sizeof(sstr) );
  6390. loc = strstr(sstrtemp, "connectorId");
  6391. if(loc == NULL)
  6392. {
  6393. connectorIdIsNULL = TRUE;
  6394. }
  6395. else
  6396. {
  6397. while ((loc[strlen("connectorId")+2+c] != '}') && (loc[strlen("connectorId")+2+c] != ','))
  6398. {
  6399. sstr[c] = loc[strlen("connectorId")+2+c];
  6400. //printf("i=%d sstr=%c\n",c, sstr[c]);
  6401. c++;
  6402. }
  6403. sstr[c] = '\0';
  6404. connectorIdInt = atoi(sstr);
  6405. }
  6406. if(connectorIdIsNULL == TRUE) // Number of the connector on which to start the transaction. connectorId SHALL be > 0
  6407. {
  6408. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  6409. goto end;
  6410. }
  6411. //****************idTag*******************/
  6412. c = 0;
  6413. memset(sstr ,0, sizeof(sstr) );
  6414. loc = strstr(sstrtemp, "idTag");
  6415. while (loc[3+strlen("idTag")+c] != '\"')
  6416. {
  6417. sstr[c] = loc[3+strlen("idTag")+c];
  6418. c++;
  6419. }
  6420. sstr[c] = '\0';
  6421. strcpy(idTagstr,sstr);
  6422. //****************chargingProfile*******************/
  6423. c = 0;
  6424. memset(sstr ,0, sizeof(sstr) );
  6425. loc = strstr(sstrtemp, "chargingProfile");
  6426. if(loc == NULL)
  6427. {
  6428. chargingProfileIsNULL = TRUE;
  6429. }
  6430. else
  6431. {
  6432. //****************chargingProfileId*******************/
  6433. c=0;
  6434. loc = strstr(sstrtemp, "chargingProfileId");
  6435. memset(sstr ,0, sizeof(sstr) );
  6436. while ((loc[strlen("chargingProfileId")+2+c] != '}') && (loc[strlen("chargingProfileId")+2+c] != ','))
  6437. {
  6438. sstr[c] = loc[strlen("chargingProfileId")+2+c];
  6439. //printf("i=%d sstr=%c\n",c, sstr[c]);
  6440. c++;
  6441. }
  6442. sstr[c] = '\0';
  6443. chargingProfileIdInt = atoi(sstr);
  6444. //****************transactionId*******************/
  6445. loc = strstr(sstrtemp, "transactionId");
  6446. if(loc == NULL)
  6447. {
  6448. transactionIdIsNULL = TRUE;
  6449. }
  6450. else
  6451. {
  6452. c=0;
  6453. memset(sstr ,0, sizeof(sstr) );
  6454. while ((loc[strlen("transactionId")+2+c] != '}') && (loc[strlen("transactionId")+2+c] != ','))
  6455. {
  6456. sstr[c] = loc[strlen("transactionId")+2+c];
  6457. //printf("i=%d sstr=%c\n",c, sstr[c]);
  6458. c++;
  6459. }
  6460. sstr[c] = '\0';
  6461. transactionIdInt = atoi(sstr);
  6462. }
  6463. //****************stackLevel*******************/
  6464. c=0;
  6465. loc = strstr(sstrtemp, "stackLevel");
  6466. memset(sstr ,0, sizeof(sstr) );
  6467. while ((loc[strlen("stackLevel")+2+c] != '}') && (loc[strlen("stackLevel")+2+c] != ','))
  6468. {
  6469. sstr[c] = loc[strlen("stackLevel")+2+c];
  6470. //printf("i=%d sstr=%c\n",c, sstr[c]);
  6471. c++;
  6472. }
  6473. sstr[c] = '\0';
  6474. stackLevelInt = atoi(sstr);
  6475. //****************chargingProfilePurpose*******************/
  6476. c = 0;
  6477. memset(sstr ,0, sizeof(sstr) );
  6478. loc = strstr(sstrtemp, "chargingProfilePurpose");
  6479. while (loc[3+strlen("chargingProfilePurpose")+c] != '\"')
  6480. {
  6481. sstr[c] = loc[3+strlen("chargingProfilePurpose")+c];
  6482. c++;
  6483. }
  6484. sstr[c] = '\0';
  6485. strcpy(chargingProfilePurposestr,sstr);
  6486. //****************chargingProfileKind*******************/
  6487. c = 0;
  6488. memset(sstr ,0, sizeof(sstr) );
  6489. loc = strstr(sstrtemp, "chargingProfileKind");
  6490. while (loc[3+strlen("chargingProfileKind")+c] != '\"')
  6491. {
  6492. sstr[c] = loc[3+strlen("chargingProfileKind")+c];
  6493. c++;
  6494. }
  6495. sstr[c] = '\0';
  6496. strcpy(chargingProfileKindstr,sstr);
  6497. //****************recurrencyKind*******************/
  6498. loc = strstr(sstrtemp, "recurrencyKind");
  6499. if(loc == NULL)
  6500. {
  6501. recurrencyKindIsNULL = TRUE;
  6502. }
  6503. else
  6504. {
  6505. c = 0;
  6506. memset(sstr ,0, sizeof(sstr) );
  6507. while (loc[3+strlen("recurrencyKind")+c] != '\"')
  6508. {
  6509. sstr[c] = loc[3+strlen("recurrencyKind")+c];
  6510. c++;
  6511. }
  6512. sstr[c] = '\0';
  6513. strcpy(recurrencyKindstr,sstr);
  6514. }
  6515. //****************validFrom*******************/
  6516. loc = strstr(sstrtemp, "validFrom");
  6517. if(loc == NULL)
  6518. {
  6519. validFromIsNULL = TRUE;
  6520. }
  6521. else
  6522. {
  6523. c = 0;
  6524. memset(sstr ,0, sizeof(sstr) );
  6525. while (loc[3+strlen("validFrom")+c] != '\"')
  6526. {
  6527. sstr[c] = loc[3+strlen("validFrom")+c];
  6528. c++;
  6529. }
  6530. sstr[c] = '\0';
  6531. strcpy(validFromstr,sstr);
  6532. }
  6533. //****************validTo*******************/
  6534. loc = strstr(sstrtemp, "validTo");
  6535. if(loc == NULL)
  6536. {
  6537. validToIsNULL = TRUE;
  6538. }
  6539. else
  6540. {
  6541. c = 0;
  6542. memset(sstr ,0, sizeof(sstr) );
  6543. while (loc[3+strlen("validTo")+c] != '\"')
  6544. {
  6545. sstr[c] = loc[3+strlen("validTo")+c];
  6546. c++;
  6547. }
  6548. sstr[c] = '\0';
  6549. strcpy(validTostr,sstr);
  6550. }
  6551. //****************chargingSchedule*******************/
  6552. loc = strstr(sstrtemp, "chargingSchedule");
  6553. if(loc != NULL)
  6554. {
  6555. //****************duration*******************/
  6556. loc = strstr(sstrtemp, "duration");
  6557. if(loc == NULL)
  6558. {
  6559. durationIsNULL = TRUE;
  6560. }
  6561. else
  6562. {
  6563. c=0;
  6564. memset(sstr ,0, sizeof(sstr) );
  6565. while ((loc[strlen("duration")+2+c] != '}') && (loc[strlen("duration")+2+c] != ','))
  6566. {
  6567. sstr[c] = loc[strlen("duration")+2+c];
  6568. //printf("i=%d sstr=%c\n",c, sstr[c]);
  6569. c++;
  6570. }
  6571. sstr[c] = '\0';
  6572. durationInt = atoi(sstr);
  6573. }
  6574. //****************startSchedule******************/
  6575. loc = strstr(sstrtemp, "startSchedule");
  6576. if(loc == NULL)
  6577. {
  6578. startScheduleIsNULL = TRUE;
  6579. }
  6580. else
  6581. {
  6582. c = 0;
  6583. memset(sstr ,0, sizeof(sstr) );
  6584. while (loc[3+strlen("startSchedule")+c] != '\"')
  6585. {
  6586. sstr[c] = loc[3+strlen("startSchedule")+c];
  6587. c++;
  6588. }
  6589. sstr[c] = '\0';
  6590. strcpy(startSchedulestr,sstr);
  6591. }
  6592. //****************chargingRateUnit*******************/
  6593. c = 0;
  6594. memset(sstr ,0, sizeof(sstr) );
  6595. loc = strstr(sstrtemp, "chargingRateUnit");
  6596. while (loc[3+strlen("chargingRateUnit")+c] != '\"')
  6597. {
  6598. sstr[c] = loc[3+strlen("chargingRateUnit")+c];
  6599. c++;
  6600. }
  6601. sstr[c] = '\0';
  6602. strcpy(chargingRateUnitstr,sstr);
  6603. //****************minChargingRate*******************/
  6604. loc = strstr(sstrtemp, "minChargingRate");
  6605. if(loc == NULL)
  6606. {
  6607. minChargingRateIsNULL = TRUE;
  6608. }
  6609. else
  6610. {
  6611. c=0;
  6612. memset(sstr ,0, sizeof(sstr) );
  6613. while ((loc[strlen("minChargingRate")+2+c] != '}') && (loc[strlen("minChargingRate")+2+c] != ','))
  6614. {
  6615. sstr[c] = loc[strlen("minChargingRate")+2+c];
  6616. //printf("i=%d sstr=%c\n",c, sstr[c]);
  6617. c++;
  6618. }
  6619. sstr[c] = '\0';
  6620. minChargingRateflaot = atof(sstr);
  6621. }
  6622. //****************chargingSchedulePeriod count*******************/
  6623. int what_len = strlen("startPeriod");
  6624. char *where = sstrtemp;
  6625. while ((where = strstr(where, "startPeriod"))) {
  6626. where += what_len;
  6627. chargingSchedulePeriodCount++;
  6628. }
  6629. where = sstrtemp;
  6630. for(int periodNums=0; periodNums < chargingSchedulePeriodCount; periodNums++)
  6631. {
  6632. //****************startPeriod*******************/
  6633. c=0;
  6634. loc = strstr(where, "startPeriod");
  6635. memset(sstr ,0, sizeof(sstr) );
  6636. while ((loc[strlen("startPeriod")+2+c] != '}') && (loc[strlen("startPeriod")+2+c] != ','))
  6637. {
  6638. sstr[c] = loc[strlen("startPeriod")+2+c];
  6639. //printf("i=%d sstr=%c\n",c, sstr[c]);
  6640. c++;
  6641. }
  6642. sstr[c] = '\0';
  6643. startPeriodInt[periodNums] = atoi(sstr);
  6644. //****************limit*******************/
  6645. c=0;
  6646. loc = strstr(where, "limit");
  6647. memset(sstr ,0, sizeof(sstr) );
  6648. while ((loc[strlen("limit")+2+c] != '}') && (loc[strlen("limit")+2+c] != ','))
  6649. {
  6650. sstr[c] = loc[strlen("limit")+2+c];
  6651. //printf("i=%d sstr=%c\n",c, sstr[c]);
  6652. c++;
  6653. }
  6654. sstr[c] = '\0';
  6655. limitflaot[periodNums] = atof(sstr);
  6656. //****************numberPhases*******************/
  6657. loc = strstr(where, "numberPhases");
  6658. if(loc == NULL)
  6659. {
  6660. numberPhasesIsNULL = TRUE;
  6661. }
  6662. else
  6663. {
  6664. c=0;
  6665. memset(sstr ,0, sizeof(sstr) );
  6666. while ((loc[strlen("numberPhases")+2+c] != '}') && (loc[strlen("numberPhases")+2+c] != ','))
  6667. {
  6668. sstr[c] = loc[strlen("numberPhases")+2+c];
  6669. //printf("i=%d sstr=%c\n",c, sstr[c]);
  6670. c++;
  6671. }
  6672. sstr[c] = '\0';
  6673. numberPhasesInt[periodNums] = atoi(sstr);
  6674. }
  6675. where = loc;
  6676. } // END FOR chargingSchedulePeriodCount
  6677. }// END IF chargingSchedule
  6678. } // END chargingProfile
  6679. /*
  6680. enum _SYSTEM_STATUS
  6681. {
  6682. S_BOOTING = 0,
  6683. S_IDLE, = 1
  6684. S_AUTHORIZING, =2
  6685. S_REASSIGN_CHECK, =3
  6686. S_REASSIGN, =4
  6687. S_PRECHARGE, =5
  6688. S_PREPARING_FOR_EV, =6
  6689. S_PREPARING_FOR_EVSE, =7
  6690. S_CHARGING, =8
  6691. S_TERMINATING, =9
  6692. S_COMPLETE, =10
  6693. S_ALARM, =11
  6694. S_FAULT =12
  6695. }
  6696. */
  6697. if((connectorIdIsNULL == FALSE)&&(connectorIdInt > 0) && ((connectorIdInt -1) <= gunTotalNumber/*(CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY)*/))
  6698. {
  6699. sprintf((char *)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag, "%s" , idTagstr);
  6700. ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.TransactionId = transactionIdInt;
  6701. //0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault 8: Reserved
  6702. //check Transaction active
  6703. if(gunType[connectorIdInt -1] == 'J')
  6704. {
  6705. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  6706. {
  6707. tempIndex = ((connectorIdInt -1) == 2) ? 1: 0;
  6708. }
  6709. else
  6710. {
  6711. tempIndex = connectorIdInt -1;
  6712. }
  6713. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  6714. {
  6715. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex )
  6716. {
  6717. if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ReservationId != -1)&&(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ReservationId >= 0)&&(strcmp((const char *)ShmOCPP16Data->ReserveNow[index].IdTag, idTagstr) == 0))
  6718. {
  6719. //Reserved
  6720. DEBUG_INFO("Reserved now !!!The idTag matches the idTag of Reservation!!!\n");
  6721. }
  6722. else if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ReservationId != -1)&&(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ReservationId >= 0)&&(strcmp((const char *)ShmOCPP16Data->ReserveNow[index].IdTag, idTagstr) != 0))
  6723. {
  6724. //Reserved
  6725. DEBUG_INFO("Reserved now !!! The idTag does NOT match the idTag of Reservation!!! Reject it!!!\n");
  6726. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  6727. goto end;
  6728. }
  6729. else
  6730. {
  6731. if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  6732. && (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_PREPARING ) //S_PRECHARGE
  6733. && (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EV ) //S_PREPARING_FOR_EV
  6734. && (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EVSE )) // S_PREPARING_FOR_EVSE
  6735. {
  6736. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  6737. goto end;
  6738. }
  6739. }//END FOR ELSE
  6740. }
  6741. }// END FOR CHAdeMO_QUANTITY
  6742. }
  6743. else if((gunType[connectorIdInt -1] == 'U')||(gunType[connectorIdInt -1] == 'E'))
  6744. {
  6745. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  6746. {
  6747. tempIndex = ((connectorIdInt -1) == 2) ? 1: 0;
  6748. }
  6749. else
  6750. {
  6751. tempIndex = connectorIdInt -1;
  6752. }
  6753. for (int index = 0; index < CCS_QUANTITY; index++)
  6754. {
  6755. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  6756. {
  6757. if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ReservationId != -1)&&(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ReservationId >= 0)&&(strcmp((const char *)ShmOCPP16Data->ReserveNow[index].IdTag, idTagstr) == 0))
  6758. {
  6759. //Reserved
  6760. DEBUG_INFO("Reserved now !!!The idTag matches the idTag of Reservation!!!\n");
  6761. }
  6762. else if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ReservationId != -1)&&(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ReservationId >= 0)&&(strcmp((const char *)ShmOCPP16Data->ReserveNow[index].IdTag, idTagstr) != 0))
  6763. {
  6764. //Reserved
  6765. DEBUG_INFO("Reserved now !!! The idTag does NOT match the idTag of Reservation!!! Reject it!!!\n");
  6766. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  6767. goto end;
  6768. }
  6769. else
  6770. {
  6771. if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  6772. && (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_PREPARING) //S_PRECHARGE
  6773. && (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EV) //S_PREPARING_FOR_EV
  6774. && (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EVSE)) // S_PREPARING_FOR_EVSE
  6775. {
  6776. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  6777. goto end;
  6778. }
  6779. }// END FOR ELSE
  6780. }
  6781. }// END FOR CCS_QUANTITY
  6782. }
  6783. else if(gunType[connectorIdInt -1] == 'G')
  6784. {
  6785. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  6786. {
  6787. tempIndex = ((connectorIdInt -1) == 2) ? 1: 0;
  6788. }
  6789. else
  6790. {
  6791. tempIndex = connectorIdInt -1;
  6792. }
  6793. for (int index = 0; index < GB_QUANTITY; index++)
  6794. {
  6795. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex )
  6796. {
  6797. if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ReservationId != -1)&&(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ReservationId >= 0)&&(strcmp((const char *)ShmOCPP16Data->ReserveNow[index].IdTag, idTagstr) == 0))
  6798. {
  6799. //Reserved
  6800. DEBUG_INFO("Reserved now !!!The idTag matches the idTag of Reservation!!!\n");
  6801. }
  6802. else if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ReservationId != -1)&&(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ReservationId >= 0)&&(strcmp((const char *)ShmOCPP16Data->ReserveNow[index].IdTag, idTagstr) != 0))
  6803. {
  6804. //Reserved
  6805. DEBUG_INFO("Reserved now !!! The idTag does NOT match the idTag of Reservation!!! Reject it!!!\n");
  6806. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  6807. goto end;
  6808. }
  6809. else
  6810. {
  6811. if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  6812. && (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_PREPARING) //S_PRECHARGE
  6813. && (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EV) //S_PREPARING_FOR_EV
  6814. && (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EVSE)) // S_PREPARING_FOR_EVSE
  6815. {
  6816. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  6817. goto end;
  6818. }
  6819. }// END FOR ELSE
  6820. }
  6821. } // END FOR GB_QUANTITY
  6822. }
  6823. else
  6824. {
  6825. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D') // 'D' means DC
  6826. {
  6827. tempIndex = 2;
  6828. }
  6829. else
  6830. {
  6831. tempIndex = connectorIdInt -1;
  6832. }
  6833. for (int index = 0; index < AC_QUANTITY; index++)
  6834. {
  6835. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex )
  6836. {
  6837. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].ReservationId != -1)&&(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].ReservationId >= 0)&&(strcmp((const char *)ShmOCPP16Data->ReserveNow[index].IdTag, idTagstr) == 0))
  6838. {
  6839. //Reserved
  6840. DEBUG_INFO("Reserved now !!!The idTag matches the idTag of Reservation!!!\n");
  6841. }
  6842. else if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].ReservationId != -1)&&(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].ReservationId >= 0)&&(strcmp((const char *)ShmOCPP16Data->ReserveNow[index].IdTag, idTagstr) != 0))
  6843. {
  6844. //Reserved
  6845. DEBUG_INFO("Reserved now !!! The idTag does NOT match the idTag of Reservation!!! Reject it!!!\n");
  6846. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  6847. goto end;
  6848. }
  6849. else
  6850. {
  6851. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  6852. && (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_PREPARING) //S_PRECHARGE
  6853. && (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EV) //S_PREPARING_FOR_EV
  6854. && (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EVSE)) // S_PREPARING_FOR_EVSE
  6855. {
  6856. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  6857. goto end;
  6858. }
  6859. }//END FOR ELSE
  6860. }
  6861. }// END FOR AC_QUANTITY
  6862. }
  6863. if(chargingProfileIsNULL == FALSE)
  6864. {
  6865. //ChargingProfile
  6866. ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingProfileId = chargingProfileIdInt;
  6867. sprintf((char *)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingProfileKind, "%s" ,chargingProfileKindstr);
  6868. sprintf((char *)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingProfilePurpose, "%s" ,chargingProfilePurposestr);
  6869. if(recurrencyKindIsNULL == FALSE) //OPTION
  6870. sprintf((char *)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.RecurrencyKind, "%s" ,recurrencyKindstr);
  6871. ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.StackLevel = stackLevelInt;
  6872. if(transactionIdIsNULL == FALSE) // OPTION
  6873. ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.TransactionId = transactionIdInt;
  6874. if(validFromIsNULL == FALSE) // OPTION
  6875. sprintf((char *)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ValidFrom, "%s" ,validFromstr);
  6876. if(validToIsNULL == FALSE) //OPTION
  6877. sprintf((char *)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ValidTo, "%s" ,validTostr);
  6878. //ChargingSchedule
  6879. sprintf((char *)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingSchedule.ChargingRateUnit, "%s" ,chargingRateUnitstr);
  6880. if(durationIsNULL == FALSE) //OPTION
  6881. ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingSchedule.Duration = durationInt;
  6882. if(minChargingRateIsNULL == FALSE) //OPTION
  6883. ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingSchedule.MinChargingRate = minChargingRateflaot;
  6884. if(startScheduleIsNULL == FALSE) //OPTION
  6885. sprintf((char *)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingSchedule.StartSchedule, "%s" ,startSchedulestr);
  6886. for(int periodNums=0; periodNums < chargingSchedulePeriodCount; periodNums++)
  6887. {
  6888. //ChargingSchedulePeriod
  6889. ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingSchedule.ChargingSchedulePeriod[periodNums].Limit = limitflaot[periodNums] ;
  6890. if(numberPhasesIsNULL == FALSE)
  6891. {
  6892. ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingSchedule.ChargingSchedulePeriod[periodNums].NumberPhases = numberPhasesInt[periodNums];
  6893. }
  6894. ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingSchedule.ChargingSchedulePeriod[periodNums].StartPeriod = startPeriodInt[periodNums];
  6895. }
  6896. if(strcmp(chargingProfilePurposestr, ChargingProfilePurposeTypeStr[TxProfile]) == 0)
  6897. {
  6898. ShmOCPP16Data->CsMsg.bits[connectorIdInt -1].RemoteStartTransactionReq = 1;
  6899. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Accepted]);
  6900. //memset idTag
  6901. memset((char *)ShmOCPP16Data->StartTransaction[connectorIdInt -1].IdTag,0, 20);
  6902. strcpy((char *)ShmOCPP16Data->StartTransaction[connectorIdInt -1].IdTag, idTagstr);
  6903. memset((char *)ShmOCPP16Data->StopTransaction[connectorIdInt -1].IdTag,0, 20);
  6904. strcpy((char *)ShmOCPP16Data->StopTransaction[connectorIdInt -1].IdTag, idTagstr);
  6905. }
  6906. else
  6907. {
  6908. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  6909. }
  6910. }
  6911. else
  6912. {
  6913. ShmOCPP16Data->CsMsg.bits[connectorIdInt -1].RemoteStartTransactionReq = 1;
  6914. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Accepted]);
  6915. //memset idTag
  6916. memset((char *)ShmOCPP16Data->StartTransaction[connectorIdInt -1].IdTag,0, 20);
  6917. strcpy((char *)ShmOCPP16Data->StartTransaction[connectorIdInt -1].IdTag, idTagstr);
  6918. memset((char *)ShmOCPP16Data->StopTransaction[connectorIdInt -1].IdTag,0, 20);
  6919. strcpy((char *)ShmOCPP16Data->StopTransaction[connectorIdInt -1].IdTag, idTagstr);
  6920. }
  6921. }
  6922. else
  6923. {
  6924. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  6925. //sprintf((char *)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ResponseStatus, "%s" ,comfirmstr);
  6926. }
  6927. end:
  6928. if(connectorIdIsNULL == FALSE)
  6929. ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ConnectorId = connectorIdInt;
  6930. strcpy((char *)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag, idTagstr);
  6931. sprintf((char *)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ResponseStatus, "%s" ,comfirmstr);
  6932. //OCPP send RemoteStartConfirmation by first.
  6933. sendRemoteStartConfirmation(uuid, comfirmstr);
  6934. return result;
  6935. }
  6936. int handleRemoteStopTransactionRequest(char *uuid, char *payload)
  6937. {
  6938. mtrace();
  6939. int result = FAIL;
  6940. int match = FALSE;
  6941. int GunNO = 0;
  6942. int tempIndex = 0;
  6943. int transactionIdInt=0;
  6944. int transactionIdIsNULL= FALSE;
  6945. char sstr[16]={ 0 },sstrtemp[50]={ 0 };//sstr[200]={ 0 };
  6946. int c = 0;
  6947. char *loc;
  6948. char comfirmstr[20];
  6949. //[2,"ff522854-0dea-436e-87ba-23a229269994","RemoteStopTransaction",{"transactionId":1373618380}]
  6950. DEBUG_INFO("handleRemoteStopTransactionRequest...\n");
  6951. if(server_pending == TRUE)
  6952. {
  6953. return 0;
  6954. }
  6955. strcpy(sstrtemp, stringtrimspace(payload));
  6956. c=0;
  6957. loc = strstr(sstrtemp, "transactionId");
  6958. if(loc == NULL)
  6959. {
  6960. transactionIdIsNULL= TRUE;
  6961. }
  6962. else
  6963. {
  6964. memset(sstr ,0, sizeof(sstr) );
  6965. while ((loc[strlen("transactionId")+2+c] != '}') && (loc[strlen("transactionId")+2+c] != ','))
  6966. {
  6967. sstr[c] = loc[strlen("transactionId")+2+c];
  6968. //printf("i=%d sstr=%c\n",c, sstr[c]);
  6969. c++;
  6970. }
  6971. sstr[c] = '\0';
  6972. transactionIdInt = atoi(sstr);
  6973. }
  6974. if(transactionIdIsNULL == FALSE)
  6975. {
  6976. for(int gun_index=0;gun_index < gunTotalNumber;gun_index++)
  6977. {
  6978. if(ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId == transactionIdInt)
  6979. {
  6980. //check Transaction active
  6981. if(gunType[gun_index] == 'J')
  6982. {
  6983. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  6984. {
  6985. tempIndex = ((gun_index==2) ? 1: 0);
  6986. }
  6987. else
  6988. {
  6989. tempIndex = gun_index;
  6990. }
  6991. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  6992. {
  6993. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  6994. {
  6995. if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_TERMINATING)) // SYS_MODE_CHARGING, SYS_MODE_TERMINATING
  6996. {
  6997. match = TRUE;
  6998. GunNO = gun_index;
  6999. }
  7000. }
  7001. }// END FOR CHAdeMO_QUANTITY
  7002. }
  7003. else if((gunType[gun_index] == 'U')||(gunType[gun_index] == 'E'))
  7004. {
  7005. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  7006. {
  7007. tempIndex = ((gun_index==2) ? 1: 0);
  7008. }
  7009. else
  7010. {
  7011. tempIndex = gun_index;
  7012. }
  7013. for (int index = 0; index < CCS_QUANTITY; index++)
  7014. {
  7015. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  7016. {
  7017. if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_TERMINATING) ) // SYS_MODE_CHARGING, SYS_MODE_TERMINATING
  7018. {
  7019. match = TRUE;
  7020. GunNO = gun_index;
  7021. }
  7022. }
  7023. }// END FOR CCS_QUANTITY
  7024. }
  7025. else if(gunType[gun_index] == 'G')
  7026. {
  7027. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  7028. {
  7029. tempIndex = ((gun_index==2) ? 1: 0);
  7030. }
  7031. else
  7032. {
  7033. tempIndex = gun_index;
  7034. }
  7035. for (int index = 0; index < GB_QUANTITY; index++)
  7036. {
  7037. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  7038. {
  7039. if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_TERMINATING)) // SYS_MODE_CHARGING, SYS_MODE_TERMINATING
  7040. {
  7041. match = TRUE;
  7042. GunNO = gun_index;
  7043. }
  7044. }
  7045. }// END FOR GB_QUANTITY
  7046. }
  7047. else
  7048. {
  7049. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D') // 'D' means DC
  7050. {
  7051. tempIndex = 2;
  7052. }
  7053. else
  7054. {
  7055. tempIndex = gun_index;
  7056. }
  7057. for (int index = 0; index < AC_QUANTITY; index++)
  7058. {
  7059. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  7060. {
  7061. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_TERMINATING)) // SYS_MODE_CHARGING, SYS_MODE_TERMINATING
  7062. {
  7063. match = TRUE;
  7064. GunNO = gun_index;
  7065. }
  7066. }
  7067. }// END FOR CHAdeMO_QUANTITY
  7068. } // END FOR AC ELSE
  7069. }// CHECK IF ResponseTransactionId == transactionIdInt
  7070. }//END FOR
  7071. if( match == TRUE)
  7072. {
  7073. ShmOCPP16Data->CsMsg.bits[GunNO].RemoteStopTransactionReq = 1; // inform csu of StopTransaction
  7074. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Accepted]);
  7075. sprintf((char *)ShmOCPP16Data->RemoteStopTransaction[GunNO].ResponseStatus, "%s" ,comfirmstr);
  7076. }
  7077. else
  7078. {
  7079. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  7080. }
  7081. }
  7082. sendRemoteStopTransactionConfirmation(uuid, comfirmstr);
  7083. return result;
  7084. }
  7085. int handleReserveNowTransactionRequest(char *uuid, char *payload)
  7086. {
  7087. mtrace();
  7088. int result = FAIL;
  7089. int connectorIdInt=0, reservationIdInt=0;
  7090. int tempIndex = 0;
  7091. char expiryDatestr[30]={0}, idTagstr[20]={0},parentIdTagstr[20]={0};
  7092. char comfirmstr[20]={0};
  7093. char sstr[180]={ 0 },sstrtemp[200]={ 0 };
  7094. int c = 0;
  7095. char *loc;
  7096. //char *ptr;
  7097. DEBUG_INFO("handleReserveNowTransactionRequest ...\n");
  7098. strcpy(sstrtemp, stringtrimspace(payload));
  7099. //***(1)connectorId ****/
  7100. c=0;
  7101. loc = strstr(sstrtemp, "connectorId");
  7102. memset(sstr ,0, sizeof(sstr) );
  7103. while ((loc != NULL) &&(loc[strlen("connectorId")+2+c] != ',') && (loc[strlen("connectorId")+2+c] != '}'))
  7104. {
  7105. sstr[c] = loc[strlen("connectorId")+2+c];
  7106. //printf("i=%d sstr=%c\n",c, sstr[c]);
  7107. c++;
  7108. }
  7109. sstr[c] = '\0';
  7110. connectorIdInt = atoi(sstr);
  7111. //***(2)expiryDate ****/
  7112. loc = strstr(sstrtemp, "expiryDate");
  7113. memset(sstr ,0, sizeof(sstr) );
  7114. c = 0;
  7115. while ((loc != NULL) &&(loc[3+strlen("expiryDate")+c] != '\"'))
  7116. {
  7117. sstr[c] = loc[3+strlen("expiryDate")+c];
  7118. c++;
  7119. }
  7120. sstr[c] = '\0';
  7121. strcpy(expiryDatestr, sstr);
  7122. //***(3)idTag ****/
  7123. loc = strstr(sstrtemp, "idTag");
  7124. memset(sstr ,0, sizeof(sstr) );
  7125. c = 0;
  7126. while ((loc != NULL) &&(loc[3+strlen("idTag")+c] != '\"'))
  7127. {
  7128. sstr[c] = loc[3+strlen("idTag")+c];
  7129. c++;
  7130. }
  7131. sstr[c] = '\0';
  7132. strcpy(idTagstr, sstr);
  7133. //***(4)parentIdTag ****/
  7134. loc = strstr(sstrtemp, "parentIdTag");
  7135. memset(sstr ,0, sizeof(sstr) );
  7136. c = 0;
  7137. if(loc == NULL)
  7138. {
  7139. strcpy(parentIdTagstr, "");
  7140. }
  7141. else
  7142. {
  7143. while ((loc != NULL) &&(loc[3+strlen("parentIdTag")+c] != '\"'))
  7144. {
  7145. sstr[c] = loc[3+strlen("parentIdTag")+c];
  7146. c++;
  7147. }
  7148. sstr[c] = '\0';
  7149. strcpy(parentIdTagstr, sstr);
  7150. }
  7151. //***(5)reservationId ****/
  7152. c=0;
  7153. loc = strstr(sstrtemp, "reservationId");
  7154. memset(sstr ,0, sizeof(sstr) );
  7155. while ((loc != NULL) &&((loc[strlen("reservationId")+2+c] != '}') && (loc[strlen("reservationId")+2+c] != ',')))
  7156. {
  7157. sstr[c] = loc[strlen("reservationId")+2+c];
  7158. //printf("i=%d sstr=%c\n",c, sstr[c]);
  7159. c++;
  7160. }
  7161. sstr[c] = '\0';
  7162. reservationIdInt = atoi(sstr);
  7163. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  7164. /*
  7165. enum SYSTEM_STATUS
  7166. {
  7167. SYS_MODE_BOOTING = 0,
  7168. SYS_MODE_IDLE = 1,
  7169. SYS_MODE_AUTHORIZING = 2,
  7170. SYS_MODE_MODE_REASSIGN_CHECK = 3,
  7171. SYS_MODE_REASSIGN = 4,
  7172. SYS_MODE_PREPARING = 5,
  7173. SYS_MODE_PREPARE_FOR_EV = 6,
  7174. SYS_MODE_PREPARE_FOR_EVSE = 7,
  7175. SYS_MODE_CHARGING = 8,
  7176. SYS_MODE_TERMINATING = 9,
  7177. SYS_MODE_COMPLETE = 10,
  7178. SYS_MODE_ALARM = 11,
  7179. SYS_MODE_FAULT = 12,
  7180. SYS_MODE_RESERVATION = 13,
  7181. SYS_MODE_BOOKING = 14,
  7182. SYS_MODE_MAINTAIN = 15,
  7183. SYS_MODE_DEBUG = 16,
  7184. SYS_MODE_CCS_PRECHARGE_STEP0 = 17,
  7185. SYS_MODE_CCS_PRECHARGE_STEP1 = 18,
  7186. SYS_MODE_UPDATE = 19
  7187. };
  7188. */
  7189. if((connectorIdInt == 0) &&(strcmp((const char *)ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemData, "FALSE") == 0)) //For OCTT Test case
  7190. {
  7191. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  7192. goto end;
  7193. }
  7194. if((connectorIdInt > 0) && ((connectorIdInt -1) <= gunTotalNumber))
  7195. {
  7196. //check Transaction active
  7197. if(gunType[connectorIdInt -1] == 'J')
  7198. {
  7199. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  7200. {
  7201. tempIndex = (((connectorIdInt -1)==2) ? 1: 0);
  7202. }
  7203. else
  7204. {
  7205. tempIndex = connectorIdInt -1;
  7206. }
  7207. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  7208. {
  7209. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  7210. {
  7211. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ReservationId)
  7212. {
  7213. if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_FAULT)&&(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_ALARM)) //S_FAULT
  7214. {
  7215. if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_IDLE) //S_IDLE
  7216. {
  7217. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  7218. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  7219. }
  7220. 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'))
  7221. {
  7222. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  7223. }
  7224. else if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_PREPARING) || (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_RESERVATION) ) //S_PRECHARGE
  7225. {
  7226. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  7227. }
  7228. else
  7229. {
  7230. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  7231. }
  7232. }
  7233. 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
  7234. {
  7235. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  7236. }
  7237. }
  7238. else
  7239. {
  7240. //replace reservation
  7241. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  7242. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  7243. }
  7244. }
  7245. } // END FOR CHAdeMO_QUANTITY
  7246. }
  7247. else if((gunType[connectorIdInt -1] == 'U')||(gunType[connectorIdInt -1] == 'E'))
  7248. {
  7249. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  7250. {
  7251. tempIndex = (((connectorIdInt -1)==2) ? 1: 0);
  7252. }
  7253. else
  7254. {
  7255. tempIndex = connectorIdInt -1;
  7256. }
  7257. for (int index = 0; index < CCS_QUANTITY; index++)
  7258. {
  7259. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  7260. {
  7261. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ReservationId)
  7262. {
  7263. //SystemStatus: 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault, 8: Reserved, 9: maintain
  7264. if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_FAULT)&&(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_ALARM)) //S_FAULT
  7265. {
  7266. if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_IDLE) //S_IDLE
  7267. {
  7268. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  7269. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  7270. }
  7271. 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'))
  7272. {
  7273. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  7274. }
  7275. else if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_PREPARING) || (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_RESERVATION)) //S_PRECHARGE
  7276. {
  7277. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  7278. }
  7279. else
  7280. {
  7281. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  7282. }
  7283. }
  7284. 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
  7285. {
  7286. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  7287. }
  7288. }
  7289. else
  7290. {
  7291. //replace reservation
  7292. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  7293. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  7294. }
  7295. }
  7296. } // END FOR CCS_QUANTITY
  7297. }
  7298. else if(gunType[connectorIdInt -1] == 'G')
  7299. {
  7300. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  7301. {
  7302. tempIndex = (((connectorIdInt -1)==2) ? 1: 0);
  7303. }
  7304. else
  7305. {
  7306. tempIndex = connectorIdInt -1;
  7307. }
  7308. for (int index = 0; index < GB_QUANTITY; index++)
  7309. {
  7310. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  7311. {
  7312. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ReservationId)
  7313. {
  7314. //SystemStatus: 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault, 8: Reserved, 9: maintain
  7315. if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_FAULT)&&(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_ALARM)) //SYS_MODE_FAULT, SYS_MODE_ALARM
  7316. {
  7317. if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_IDLE) //S_IDLE
  7318. {
  7319. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  7320. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  7321. }
  7322. 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'))
  7323. {
  7324. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  7325. }
  7326. else if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_PREPARING) || (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_RESERVATION) ) //S_PRECHARGE
  7327. {
  7328. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  7329. }
  7330. else
  7331. {
  7332. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  7333. }
  7334. }
  7335. 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
  7336. {
  7337. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  7338. }
  7339. }
  7340. else
  7341. {
  7342. //replace reservation
  7343. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  7344. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  7345. }
  7346. }
  7347. }// END FOR GB_QUANTITY
  7348. }
  7349. else
  7350. {
  7351. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D') // 'D' means DC
  7352. {
  7353. tempIndex = 2;
  7354. }
  7355. else
  7356. {
  7357. tempIndex = (connectorIdInt -1);
  7358. }
  7359. for (int index = 0; index < AC_QUANTITY; index++)
  7360. {
  7361. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  7362. {
  7363. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.AcChargingData[index].ReservationId)
  7364. {
  7365. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_FAULT)&&(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_ALARM)) //SYS_MODE_FAULT, SYS_MODE_ALARM
  7366. {
  7367. if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_IDLE) //S_IDLE
  7368. {
  7369. 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))
  7370. {
  7371. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  7372. }
  7373. else
  7374. {
  7375. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  7376. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  7377. }
  7378. }
  7379. 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'))
  7380. {
  7381. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  7382. }
  7383. else if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_PREPARING) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_RESERVATION) ) //S_PRECHARGE
  7384. {
  7385. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  7386. }
  7387. else
  7388. {
  7389. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  7390. }
  7391. }
  7392. 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
  7393. {
  7394. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  7395. }
  7396. }
  7397. else
  7398. {
  7399. //replace reservation
  7400. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  7401. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  7402. }
  7403. }
  7404. } // END FOR AC_QUANTITY
  7405. }
  7406. sprintf((char *)ShmOCPP16Data->ReserveNow[connectorIdInt-1].ResponseStatus, "%s" ,comfirmstr);
  7407. }
  7408. else if(connectorIdInt == 0)
  7409. {
  7410. //check Transaction active
  7411. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  7412. {
  7413. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ReservationId)
  7414. {
  7415. 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'))
  7416. {
  7417. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  7418. goto end;
  7419. }
  7420. else if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_PREPARING) //S_PRECHARGE
  7421. {
  7422. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  7423. goto end;
  7424. }
  7425. 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
  7426. {
  7427. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  7428. goto end;
  7429. }
  7430. else if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  7431. {
  7432. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  7433. goto end;
  7434. }
  7435. }
  7436. }// END FOR CHAdeMO_QUANTITY
  7437. for (int index = 0; index < CCS_QUANTITY; index++)
  7438. {
  7439. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ReservationId)
  7440. {
  7441. 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'))
  7442. {
  7443. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  7444. goto end;
  7445. }
  7446. else if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_PREPARING) //SYS_MODE_PREPARING
  7447. {
  7448. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  7449. goto end;
  7450. }
  7451. 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
  7452. {
  7453. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  7454. goto end;
  7455. }
  7456. else if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  7457. {
  7458. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  7459. goto end;
  7460. }
  7461. }
  7462. } // END FOR CCS_QUANTITY
  7463. for (int index = 0; index < GB_QUANTITY; index++)
  7464. {
  7465. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ReservationId)
  7466. {
  7467. 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'))
  7468. {
  7469. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  7470. goto end;
  7471. }
  7472. else if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_PREPARING) //S_PRECHARGE
  7473. {
  7474. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  7475. goto end;
  7476. }
  7477. 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
  7478. {
  7479. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  7480. goto end;
  7481. }
  7482. else if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  7483. {
  7484. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  7485. goto end;
  7486. }
  7487. }
  7488. } // END FOR GB_QUANTITY
  7489. for (int index = 0; index < AC_QUANTITY; index++)
  7490. {
  7491. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.AcChargingData[index].ReservationId)
  7492. {
  7493. 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'))
  7494. {
  7495. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  7496. goto end;
  7497. }
  7498. else if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_PREPARING) //S_PRECHARGE
  7499. {
  7500. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  7501. goto end;
  7502. }
  7503. 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
  7504. {
  7505. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  7506. goto end;
  7507. }
  7508. if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_IDLE) //S_IDLE
  7509. {
  7510. 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))
  7511. {
  7512. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  7513. goto end;
  7514. }
  7515. }
  7516. else if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  7517. {
  7518. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  7519. goto end;
  7520. }
  7521. }
  7522. }// END FOR AC_QUANTITY
  7523. //The connectorId is 0
  7524. ShmOCPP16Data->CsMsg.bits[0].ReserveNowReq = 1;
  7525. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  7526. sprintf((char *)ShmOCPP16Data->ReserveNow[0].ResponseStatus, "%s" ,comfirmstr);
  7527. ShmOCPP16Data->ReserveNow[0].ConnectorId = connectorIdInt;
  7528. sprintf((char *)ShmOCPP16Data->ReserveNow[0].ExpiryDate, "%s" , expiryDatestr);
  7529. sprintf((char *)ShmOCPP16Data->ReserveNow[0].IdTag, "%s" , idTagstr);
  7530. sprintf((char *)ShmOCPP16Data->ReserveNow[0].ParentIdTag, "%s" , parentIdTagstr);
  7531. ShmOCPP16Data->ReserveNow[0].ReservationId = reservationIdInt;
  7532. strcpy((char *)ShmOCPP16Data->ReserveNow[0].guid, uuid);
  7533. result = TRUE;
  7534. return result;
  7535. }
  7536. else
  7537. {
  7538. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  7539. sprintf((char *)ShmOCPP16Data->ReserveNow[connectorIdInt-1].ResponseStatus, "%s" ,comfirmstr);
  7540. }
  7541. if(strcmp(comfirmstr,"Accepted") == 0)
  7542. {
  7543. ShmOCPP16Data->ReserveNow[connectorIdInt-1].ConnectorId = connectorIdInt;
  7544. sprintf((char *)ShmOCPP16Data->ReserveNow[connectorIdInt-1].ExpiryDate, "%s" , expiryDatestr);
  7545. sprintf((char *)ShmOCPP16Data->ReserveNow[connectorIdInt-1].IdTag, "%s" , idTagstr);
  7546. sprintf((char *)ShmOCPP16Data->ReserveNow[connectorIdInt-1].ParentIdTag, "%s" , parentIdTagstr);
  7547. ShmOCPP16Data->ReserveNow[connectorIdInt-1].ReservationId = reservationIdInt;
  7548. strcpy((char *)ShmOCPP16Data->ReserveNow[connectorIdInt-1].guid, uuid);
  7549. result = TRUE;
  7550. return result;
  7551. }
  7552. end:
  7553. sendReserveNowTransactionConfirmation(uuid,comfirmstr);
  7554. //ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].ReserveNowConf = 1;
  7555. return result;
  7556. }
  7557. int handleResetRequest(char *uuid, char *payload)
  7558. {
  7559. mtrace();
  7560. int result = FAIL;
  7561. char sstr[10]={0},sstrtemp[30]={ 0 };
  7562. char typestr[10]={0};
  7563. char comfirmstr[20]={0};
  7564. int c = 0;
  7565. char *loc;
  7566. DEBUG_INFO("handleResetRequest...\n");
  7567. strcpy(sstrtemp, stringtrimspace(payload));
  7568. loc = strstr(sstrtemp, "type");
  7569. memset(sstr ,0, sizeof(sstr) );
  7570. c = 0;
  7571. while (loc[3+strlen("type")+c] != '\"')
  7572. {
  7573. sstr[c] = loc[3+strlen("type")+c];
  7574. c++;
  7575. }
  7576. sstr[c] = '\0';
  7577. strcpy(typestr,sstr);
  7578. sprintf((char *)ShmOCPP16Data->Reset.Type, "%s" ,typestr);
  7579. if((strcmp(typestr, ResetTypeStr[Hard])==0) || (strcmp(typestr, ResetTypeStr[Soft])==0))
  7580. {
  7581. ShmOCPP16Data->MsMsg.bits.ResetReq = 1;
  7582. strcpy((char *)ShmOCPP16Data->Reset.guid, uuid);
  7583. result = TRUE;
  7584. return result;
  7585. }
  7586. else
  7587. {
  7588. strcpy(comfirmstr, ResetStatusStr[ResetStatus_Rejected]);
  7589. sprintf((char *)ShmOCPP16Data->Reset.ResponseStatus, "%s" ,comfirmstr);
  7590. goto errorend;
  7591. }
  7592. errorend:
  7593. sendResetConfirmation(uuid, comfirmstr);
  7594. return result;
  7595. }
  7596. int handleSendLocalListRequest(char *uuid, char *payload)
  7597. {
  7598. mtrace();
  7599. int result = FAIL;
  7600. int listVersionInt;
  7601. //char *updateTypestr, *idTagstr, *expiryDatestr, *parentIdTagstr, *statusstr;
  7602. char listsearch[]="listVersion";
  7603. char updateTypesearch[]="updateType";
  7604. char localAuthorizationListsearch[]="localAuthorizationList";
  7605. char sstr[60500]={ 0 },sstrtemp[60500]={ 0 };//sstr[200]={ 0 };
  7606. char CardList[500][160]={0};
  7607. char updateTypestr[15]={0};
  7608. char idTagstr[20]={0};
  7609. char parentIdTag[20]={0};
  7610. char expiryDate[30]={0};
  7611. char idTagstatus[16]={0};
  7612. int c = 0;
  7613. int i = 0;
  7614. char *delim1 = "}";
  7615. char * pch;
  7616. char *loc;
  7617. //char *ptr;
  7618. char comfirmstr[20];
  7619. //int n_localAuthorizations = 0;
  7620. int checkState_Faulted = FALSE;
  7621. DEBUG_INFO("handleSendLocalListRequest...\n");
  7622. if(strcmp((const char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "FALSE") == 0) //For OCTT Test case
  7623. {
  7624. strcpy(comfirmstr, UpdateStatusStr[UpdateStatus_NotSupported]);
  7625. goto end;
  7626. }
  7627. //check Charge Point state
  7628. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  7629. {
  7630. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_FAULT) //S_FAULT ---> Faulted
  7631. {
  7632. checkState_Faulted = TRUE; //OCPP Status: Faulted
  7633. }
  7634. }
  7635. for (int index = 0; index < CCS_QUANTITY; index++)
  7636. {
  7637. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_FAULT) //S_FAULT ---> Faulted
  7638. {
  7639. checkState_Faulted = TRUE; //OCPP Status
  7640. }
  7641. }
  7642. for (int index = 0; index < GB_QUANTITY; index++)
  7643. {
  7644. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_FAULT) //S_FAULT ---> Faulted
  7645. {
  7646. checkState_Faulted = TRUE; //OCPP Status: Faulted
  7647. }
  7648. }
  7649. //check Charge Point state
  7650. for (int index = 0; index < AC_QUANTITY; index++)
  7651. {
  7652. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_FAULT) //S_FAULT ---> Faulted
  7653. {
  7654. checkState_Faulted = TRUE; //OCPP Status: Faulted
  7655. }
  7656. }
  7657. if(checkState_Faulted == TRUE)
  7658. {
  7659. strcpy(comfirmstr, UpdateStatusStr[UpdateStatus_Failed]);
  7660. goto end;
  7661. }
  7662. //Filter payload space
  7663. strcpy(sstrtemp, stringtrimspace(payload));
  7664. //listVersion
  7665. c = 0;
  7666. loc = strstr(sstrtemp, listsearch);
  7667. while ((loc[strlen("listVersion")+2+c] != ',')&&(loc[strlen("listVersion")+2+c] != '}'))
  7668. {
  7669. sstr[c] = loc[strlen("listVersion")+2+c];
  7670. c++;
  7671. }
  7672. sstr[c] = '\0';
  7673. listVersionInt = atoi(sstr);
  7674. ShmOCPP16Data->SendLocalList.ListVersion = listVersionInt;
  7675. //updateType
  7676. loc = strstr(sstrtemp, updateTypesearch);
  7677. c = 0;
  7678. while (loc[3+strlen(updateTypesearch)+c] != '\"')
  7679. {
  7680. sstr[c] = loc[3+strlen(updateTypesearch)+c];
  7681. c++;
  7682. }
  7683. sstr[c] = '\0';
  7684. strcpy(updateTypestr, sstr);
  7685. sprintf((char *)ShmOCPP16Data->SendLocalList.UpdateType, "%s", updateTypestr);
  7686. //localAuthorizationList
  7687. memset(sstr ,0, sizeof(sstr) );
  7688. loc = strstr(sstrtemp, localAuthorizationListsearch);
  7689. if(loc != NULL) // localAuthorizationList is not NULL
  7690. {
  7691. //Check UpdateType
  7692. if(strcmp(updateTypestr, UpdateTypeStr[Full]) == 0)
  7693. {
  7694. //Local list full update
  7695. printf("Local list full update.\n");
  7696. OCPP_getListVerion();
  7697. if(listVersionInt < localversion )//if(listVersionInt <= localversion ) for OCTT Case ---remove temporally
  7698. {
  7699. strcpy(comfirmstr, UpdateStatusStr[UpdateStatus_Failed]);
  7700. goto end;
  7701. }
  7702. OCPP_cleanLocalList();
  7703. }
  7704. else if(strcmp(updateTypestr, UpdateTypeStr[Differential]) == 0)
  7705. {
  7706. //Local list different update
  7707. printf("Local list different update.\n");
  7708. OCPP_getListVerion();
  7709. if(listVersionInt < localversion )//if(listVersionInt <= localversion ) for OCTT Case ---remove temporally
  7710. {
  7711. strcpy(comfirmstr, UpdateStatusStr[UpdateStatus_VersionMismatch]);
  7712. goto end;
  7713. }
  7714. }
  7715. else
  7716. {
  7717. strcpy(comfirmstr, UpdateStatusStr[UpdateStatus_NotSupported]);
  7718. goto end;
  7719. }
  7720. c = 0;
  7721. while (loc[3+strlen(localAuthorizationListsearch)+c] != ']')
  7722. {
  7723. sstr[c] = loc[3+strlen(localAuthorizationListsearch)+c];
  7724. //printf("i=%d sstr=%c\n",c, sstr[c]);
  7725. c++;
  7726. }
  7727. sstr[c] = '\0';
  7728. //DEBUG_INFO("sstr=%s\n", sstr);
  7729. //parsing strings to words
  7730. i = 0;
  7731. pch = strtok(sstr,delim1);
  7732. while (pch != NULL)
  7733. {
  7734. strcpy(CardList[i], pch);
  7735. //DEBUG_INFO("CardList[i]=%s\n", CardList[i]);
  7736. pch = strtok (NULL, delim1);
  7737. i = i + 1;
  7738. }
  7739. //DEBUG_INFO("listVersionInt=%s\n", sstr);
  7740. //local Authorizations List Numbers
  7741. //n_localAuthorizations = i;
  7742. ShmOCPP16Data->SendLocalList.ListVersion = listVersionInt;
  7743. memset(ShmOCPP16Data->SendLocalList.LocalAuthorizationList, 0 , sizeof(struct StructLocalAuthorizationList)* 500);
  7744. c= 0;
  7745. while(c < i) // i is CardList Number
  7746. {
  7747. //Search "IdToken"
  7748. memset(sstr ,0, sizeof(sstr) );
  7749. loc = strstr(CardList[c], "idTag");
  7750. int j = 0;
  7751. while (loc[3+strlen("idTag")+j] != '\"')
  7752. {
  7753. sstr[j] = loc[3+strlen("idTag")+j];
  7754. //printf("i=%d sstr=%c\n",c, sstr[j]);
  7755. j++;
  7756. }
  7757. sstr[j] = '\0';
  7758. strcpy(idTagstr, sstr);
  7759. //DEBUG_INFO("idTagstr=%s\n", idTagstr);
  7760. //Search "expiryDate"
  7761. memset(sstr ,0, sizeof(sstr) );
  7762. loc = strstr(CardList[c], "expiryDate");
  7763. j = 0;
  7764. if(loc != NULL)
  7765. {
  7766. while (loc[3+strlen("expiryDate")+j] != '\"')
  7767. {
  7768. sstr[j] = loc[3+strlen("expiryDate")+j];
  7769. //printf("i=%d sstr=%c\n",c, sstr[j]);
  7770. j++;
  7771. }
  7772. sstr[j] = '\0';
  7773. strcpy(expiryDate, sstr);
  7774. }
  7775. else
  7776. {
  7777. strcpy(expiryDate, "");
  7778. }
  7779. //DEBUG_INFO("expiryDate=%s\n", expiryDate);
  7780. //Search "parentIdTag"
  7781. memset(sstr ,0, sizeof(sstr) );
  7782. loc = strstr(CardList[c], "parentIdTag");
  7783. j = 0;
  7784. if(loc != NULL)
  7785. {
  7786. while (loc[3+strlen("parentIdTag")+j] != '\"')
  7787. {
  7788. sstr[j] = loc[3+strlen("parentIdTag")+j];
  7789. //printf("i=%d sstr=%c\n",c, sstr[j]);
  7790. j++;
  7791. }
  7792. sstr[j] = '\0';
  7793. strcpy(parentIdTag, sstr);
  7794. }
  7795. else
  7796. {
  7797. strcpy(parentIdTag, "");
  7798. }
  7799. //DEBUG_INFO("parentIdTag=%s\n", parentIdTag);
  7800. //Search "status"
  7801. memset(sstr ,0, sizeof(sstr) );
  7802. loc = strstr(CardList[c], "status");
  7803. j = 0;
  7804. while (loc[3+strlen("status")+j] != '\"')
  7805. {
  7806. sstr[j] = loc[3+strlen("status")+j];
  7807. //printf("i=%d sstr=%c\n",c, sstr[j]);
  7808. j++;
  7809. }
  7810. sstr[j] = '\0';
  7811. strcpy(idTagstatus, sstr);
  7812. //DEBUG_INFO("idTagstatus=%s\n", idTagstatus);
  7813. OCPP_getIdTag(idTagstr);
  7814. //OCPP_getIdTag("test"); For Test
  7815. //DEBUG_INFO("idTagAuthorization=%s\n",idTagAuthorization);
  7816. //DEBUG_INFO("updateTypestr=%s\n",updateTypestr);
  7817. if(strcmp(updateTypestr, UpdateTypeStr[Full]) == 0)
  7818. {
  7819. //Local list full update
  7820. DEBUG_INFO("Local list full update.\n");
  7821. // update list
  7822. OCPP_addLocalList_1(listVersionInt, idTagstr, parentIdTag, expiryDate, idTagstatus);
  7823. //DEBUG_INFO("Local list full update. 1\n");
  7824. //OCPP_get_TableAuthlocalAllData();
  7825. //DEBUG_INFO("Local list full update. 2\n");
  7826. }
  7827. else if(strcmp(updateTypestr, UpdateTypeStr[Differential]) == 0)
  7828. {
  7829. OCPP_addLocalList_1(listVersionInt, idTagstr, parentIdTag, expiryDate, idTagstatus); // update or add
  7830. }
  7831. strcpy((char *)ShmOCPP16Data->SendLocalList.LocalAuthorizationList[c].IdTag, idTagstr);
  7832. strcpy((char *)ShmOCPP16Data->SendLocalList.LocalAuthorizationList[c].IdTagInfo.ExpiryDate, expiryDate);
  7833. strcpy((char *)ShmOCPP16Data->SendLocalList.LocalAuthorizationList[c].IdTagInfo.ParentIdTag, parentIdTag);
  7834. strcpy((char *)ShmOCPP16Data->SendLocalList.LocalAuthorizationList[c].IdTagInfo.Status, idTagstatus);
  7835. c++;
  7836. }
  7837. }
  7838. else
  7839. {
  7840. //Check UpdateType
  7841. if(strcmp(updateTypestr, UpdateTypeStr[Full]) == 0)
  7842. {
  7843. //Local list full update
  7844. DEBUG_INFO("If no (empty) localAuthorizationList is given and the updateType is Full, all identifications are removed from the list. \n");
  7845. OCPP_cleanLocalList();
  7846. strcpy(comfirmstr, UpdateStatusStr[UpdateStatus_Accepted]);
  7847. goto end;
  7848. }
  7849. if(strcmp(updateTypestr, UpdateTypeStr[Differential]) == 0)
  7850. {
  7851. //Local list different update
  7852. DEBUG_INFO("Requesting a Differential update without (empty) localAuthorizationList will have no effect on the list\n");
  7853. strcpy(comfirmstr, UpdateStatusStr[UpdateStatus_Accepted]);
  7854. goto end;
  7855. }
  7856. }
  7857. strcpy(comfirmstr, UpdateStatusStr[UpdateStatus_Accepted]);
  7858. end:
  7859. sendSendLocalListConfirmation(uuid, comfirmstr);
  7860. //ShmOCPP16Data->MsMsg.bits.SendLocalListConf = 1;
  7861. return result;
  7862. }
  7863. #define MAX 200
  7864. int handleSetChargingProfileRequest(char *uuid, char *payload)
  7865. {
  7866. mtrace();
  7867. int result = FAIL;
  7868. int connectorIdInt=0, chargingProfileIdInt=0, transactionIdInt=0,stackLevelInt=0, durationInt=0, startPeriodInt[10]={0}, numberPhasesInt[10]={0};
  7869. int tempconnectorIdInt=0, tempchargingProfileIdInt=0, tempstackLevelInt=0;
  7870. char chargingProfilePurposeStr[30]={0};
  7871. char chargingProfileKindStr[16]={0};
  7872. char recurrencyKindStr[10]={0};
  7873. char validFromStr[30]={0}, validToStr[30]={0}, startScheduleStr[30]={0}, chargingRateUnitStr[6]={0};
  7874. float minChargingRateFloat = 0.0, limitflaot[10] = {0.0};
  7875. int chargingSchedulePeriodCount = 0;
  7876. //int updateflag = FALSE;
  7877. char comfirmstr[20]={0};
  7878. int meet= FALSE;
  7879. char sstr[10]={0},sstrtemp[1600]={ 0 };
  7880. int c = 0;
  7881. char *loc;
  7882. FILE *fptr1;//, *fptr2;
  7883. //int lno=0;//, linectr = 0;
  7884. //int modifyflag = FALSE;
  7885. char filename[MAX]={0};
  7886. char tempfile[] = "/Storage/OCPP/SetChargingProfiletemp.json";
  7887. //int resultRename=0;
  7888. char rmFileCmd[50]={0};
  7889. char tempchargingProfilePurposeStr[30]={0};
  7890. char word[1600]={0};
  7891. int n_chargingProfile = 0;
  7892. //[2,"d65bcbca-0b07-49c1-b679-e6c6ff9f5627","SetChargingProfile",{"connectorId":0,"csChargingProfiles":{"chargingProfileId":1,"transactionId":0,"stackLevel":0,"chargingProfilePurpose":"TxDefaultProfile","chargingProfileKind":"Absolute","recurrencyKind":"Daily","validFrom":"2019-07-01T02:39:55.000Z","validTo":"2019-07-04T02:39:55.000Z","chargingSchedule":{"duration":86400,"startSchedule":"2019-07-01T02:39:55.000Z","chargingRateUnit":"A","chargingSchedulePeriod":[{"startPeriod":0,"limit":20.0,"numberPhases":3},{"startPeriod":300,"limit":10.0,"numberPhases":3},{"startPeriod":600,"limit":20.0,"numberPhases":3},{"startPeriod":1200,"limit":10.0,"numberPhases":3},{"startPeriod":1800,"limit":20.0,"numberPhases":3},{"startPeriod":2400,"limit":10.0,"numberPhases":3},{"startPeriod":3000,"limit":20.0,"numberPhases":3}],"minChargingRate":20.1}}}]
  7893. DEBUG_INFO("handleSetChargingProfileRequest\n");
  7894. connectorIdInt = chargingProfileIdInt = transactionIdInt = stackLevelInt = 0;
  7895. //Filter string space
  7896. strcpy(sstrtemp, stringtrimspace(payload));
  7897. //*********************connectorId***************************/
  7898. loc = strstr(sstrtemp, "connectorId");
  7899. c = 0;
  7900. memset(sstr ,0, sizeof(sstr) );
  7901. while (loc[strlen("connectorId")+2+c] != ',')
  7902. {
  7903. sstr[c] = loc[strlen("connectorId")+2+c];
  7904. c++;
  7905. }
  7906. sstr[c] = '\0';
  7907. connectorIdInt = atoi(sstr);
  7908. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  7909. {
  7910. ShmOCPP16Data->SetChargingProfile[0].ConnectorId = connectorIdInt;
  7911. }
  7912. else
  7913. {
  7914. ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ConnectorId = connectorIdInt;
  7915. }
  7916. //DEBUG_INFO("handleSetChargingProfileRequest -1\n");
  7917. //*********************chargingProfileId***************************/
  7918. loc = strstr(sstrtemp, "chargingProfileId");
  7919. c = 0;
  7920. memset(sstr ,0, sizeof(sstr) );
  7921. while (loc[strlen("chargingProfileId")+2+c] != ',')
  7922. {
  7923. sstr[c] = loc[strlen("chargingProfileId")+2+c];
  7924. c++;
  7925. }
  7926. sstr[c] = '\0';
  7927. chargingProfileIdInt = atoi(sstr);
  7928. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  7929. {
  7930. ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.ChargingProfileId = chargingProfileIdInt;
  7931. }
  7932. else
  7933. {
  7934. ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.ChargingProfileId = chargingProfileIdInt;
  7935. }
  7936. //DEBUG_INFO("handleSetChargingProfileRequest -2\n");
  7937. //*********************transactionId***************************/
  7938. loc = strstr(sstrtemp, "transactionId");
  7939. if(loc != NULL)
  7940. {
  7941. c = 0;
  7942. memset(sstr ,0, sizeof(sstr) );
  7943. while (loc[strlen("transactionId")+2+c] != ',')
  7944. {
  7945. sstr[c] = loc[strlen("transactionId")+2+c];
  7946. c++;
  7947. }
  7948. sstr[c] = '\0';
  7949. transactionIdInt = atoi(sstr);
  7950. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  7951. {
  7952. ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.TransactionId = transactionIdInt;
  7953. }
  7954. else
  7955. {
  7956. ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.TransactionId = transactionIdInt;
  7957. }
  7958. }
  7959. //DEBUG_INFO("handleSetChargingProfileRequest -3\n");
  7960. //*********************stackLevel***************************/
  7961. loc = strstr(sstrtemp, "stackLevel");
  7962. c = 0;
  7963. memset(sstr ,0, sizeof(sstr) );
  7964. while (loc[strlen("stackLevel")+2+c] != ',')
  7965. {
  7966. sstr[c] = loc[strlen("stackLevel")+2+c];
  7967. c++;
  7968. }
  7969. sstr[c] = '\0';
  7970. stackLevelInt = atoi(sstr);
  7971. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  7972. {
  7973. ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.StackLevel = stackLevelInt;
  7974. }
  7975. else
  7976. {
  7977. ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.StackLevel = stackLevelInt;
  7978. }
  7979. //DEBUG_INFO("handleSetChargingProfileRequest -4\n");
  7980. //*********************chargingProfilePurpose***************************/
  7981. loc = strstr(sstrtemp, "chargingProfilePurpose");
  7982. c = 0;
  7983. memset(sstr ,0, sizeof(sstr) );
  7984. while (loc[3+strlen("chargingProfilePurpose")+c] != '\"')
  7985. {
  7986. sstr[c] = loc[3+strlen("chargingProfilePurpose")+c];
  7987. //printf("i=%d sstr=%c\n",c, sstr[c]);
  7988. c++;
  7989. }
  7990. sstr[c] = '\0';
  7991. strcpy(chargingProfilePurposeStr,sstr);
  7992. //DEBUG_INFO("chargingProfilePurposeStr=%s\n",chargingProfilePurposeStr);
  7993. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  7994. {
  7995. strcpy((char *)ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.ChargingProfilePurpose, chargingProfilePurposeStr);
  7996. }
  7997. else
  7998. {
  7999. strcpy((char *)ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.ChargingProfilePurpose, chargingProfilePurposeStr);
  8000. }
  8001. //DEBUG_INFO("handleSetChargingProfileRequest -6\n");
  8002. //*********************chargingProfileKind***************************/
  8003. loc = strstr(sstrtemp, "chargingProfileKind");
  8004. c = 0;
  8005. memset(sstr ,0, sizeof(sstr) );
  8006. while (loc[3+strlen("chargingProfileKind")+c] != '\"')
  8007. {
  8008. sstr[c] = loc[3+strlen("chargingProfileKind")+c];
  8009. //printf("i=%d sstr=%c\n",c, sstr[c]);
  8010. c++;
  8011. }
  8012. sstr[c] = '\0';
  8013. strcpy(chargingProfileKindStr,sstr);
  8014. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  8015. {
  8016. strcpy((char *)ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.ChargingProfileKind, chargingProfileKindStr);
  8017. }
  8018. else
  8019. {
  8020. strcpy((char *)ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.ChargingProfileKind, chargingProfileKindStr);
  8021. }
  8022. //DEBUG_INFO("handleSetChargingProfileRequest -7\n");
  8023. //*********************recurrencyKind***************************/
  8024. loc = strstr(sstrtemp, "recurrencyKind");
  8025. if(loc != NULL)
  8026. {
  8027. c = 0;
  8028. memset(sstr ,0, sizeof(sstr) );
  8029. while (loc[3+strlen("recurrencyKind")+c] != '\"')
  8030. {
  8031. sstr[c] = loc[3+strlen("recurrencyKind")+c];
  8032. //printf("i=%d sstr=%c\n",c, sstr[c]);
  8033. c++;
  8034. }
  8035. sstr[c] = '\0';
  8036. strcpy(recurrencyKindStr,sstr);
  8037. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  8038. {
  8039. strcpy((char *)ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.RecurrencyKind, recurrencyKindStr);
  8040. }
  8041. else
  8042. {
  8043. strcpy((char *)ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.RecurrencyKind, recurrencyKindStr);
  8044. }
  8045. }
  8046. else
  8047. {
  8048. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  8049. {
  8050. strcpy((char *)ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.RecurrencyKind, "");
  8051. }
  8052. else
  8053. {
  8054. strcpy((char *)ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.RecurrencyKind, "");
  8055. }
  8056. }
  8057. //DEBUG_INFO("handleSetChargingProfileRequest -8\n");
  8058. //*********************validFrom***************************/
  8059. loc = strstr(sstrtemp, "validFrom");
  8060. if(loc != NULL)
  8061. {
  8062. c = 0;
  8063. memset(sstr ,0, sizeof(sstr) );
  8064. while (loc[3+strlen("validFrom")+c] != '\"')
  8065. {
  8066. sstr[c] = loc[3+strlen("validFrom")+c];
  8067. //printf("i=%d sstr=%c\n",c, sstr[c]);
  8068. c++;
  8069. }
  8070. sstr[c] = '\0';
  8071. strcpy(validFromStr,sstr);
  8072. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  8073. {
  8074. strcpy((char *)ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.ValidFrom, validFromStr);
  8075. }
  8076. else
  8077. {
  8078. strcpy((char *)ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.ValidFrom, validFromStr);
  8079. }
  8080. }
  8081. else
  8082. {
  8083. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  8084. {
  8085. strcpy((char *)ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.ValidFrom, "");
  8086. }
  8087. else
  8088. {
  8089. strcpy((char *)ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.ValidFrom, "");
  8090. }
  8091. }
  8092. //DEBUG_INFO("handleSetChargingProfileRequest -9\n");
  8093. //*********************validTo***************************/
  8094. loc = strstr(sstrtemp, "validTo");
  8095. if(loc != NULL)
  8096. {
  8097. c = 0;
  8098. memset(sstr ,0, sizeof(sstr) );
  8099. while (loc[3+strlen("validTo")+c] != '\"')
  8100. {
  8101. sstr[c] = loc[3+strlen("validTo")+c];
  8102. //printf("i=%d sstr=%c\n",c, sstr[c]);
  8103. c++;
  8104. }
  8105. sstr[c] = '\0';
  8106. strcpy(validToStr,sstr);
  8107. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  8108. {
  8109. strcpy((char *)ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.ValidTo, validToStr);
  8110. }
  8111. else
  8112. {
  8113. strcpy((char *)ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.ValidTo, validToStr);
  8114. }
  8115. }
  8116. else
  8117. {
  8118. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  8119. {
  8120. strcpy((char *)ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.ValidTo, "");
  8121. }
  8122. else
  8123. {
  8124. strcpy((char *)ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.ValidTo, "");
  8125. }
  8126. }
  8127. //DEBUG_INFO("handleSetChargingProfileRequest -10\n");
  8128. //*********************duration***************************/
  8129. loc = strstr(sstrtemp, "duration");
  8130. if(loc != NULL)
  8131. {
  8132. c = 0;
  8133. memset(sstr ,0, sizeof(sstr) );
  8134. while (loc[strlen("duration")+2+c] != ',')
  8135. {
  8136. sstr[c] = loc[strlen("duration")+2+c];
  8137. c++;
  8138. }
  8139. sstr[c] = '\0';
  8140. durationInt = atoi(sstr);
  8141. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  8142. {
  8143. ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.ChargingSchedule.Duration = durationInt;
  8144. }
  8145. else
  8146. {
  8147. ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.ChargingSchedule.Duration = durationInt;
  8148. }
  8149. }
  8150. else
  8151. {
  8152. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  8153. {
  8154. ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.ChargingSchedule.Duration = 0;
  8155. }
  8156. else
  8157. {
  8158. ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.ChargingSchedule.Duration = 0;
  8159. }
  8160. }
  8161. //DEBUG_INFO("handleSetChargingProfileRequest -11\n");
  8162. //*********************startSchedule***************************/
  8163. loc = strstr(sstrtemp, "startSchedule");
  8164. if(loc != NULL)
  8165. {
  8166. c = 0;
  8167. memset(sstr ,0, sizeof(sstr) );
  8168. while (loc[3+strlen("startSchedule")+c] != '\"')
  8169. {
  8170. sstr[c] = loc[3+strlen("startSchedule")+c];
  8171. //printf("i=%d sstr=%c\n",c, sstr[c]);
  8172. c++;
  8173. }
  8174. sstr[c] = '\0';
  8175. strcpy(startScheduleStr,sstr);
  8176. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  8177. {
  8178. strcpy((char *)ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.ChargingSchedule.StartSchedule,startScheduleStr);
  8179. }
  8180. else
  8181. {
  8182. strcpy((char *)ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.ChargingSchedule.StartSchedule,startScheduleStr);
  8183. }
  8184. }
  8185. else
  8186. {
  8187. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  8188. {
  8189. strcpy((char *)ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.ChargingSchedule.StartSchedule,"");
  8190. }
  8191. else
  8192. {
  8193. strcpy((char *)ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.ChargingSchedule.StartSchedule,"");
  8194. }
  8195. }
  8196. //DEBUG_INFO("handleSetChargingProfileRequest -12\n");
  8197. //*********************chargingRateUnit***************************/
  8198. loc = strstr(sstrtemp, "chargingRateUnit");
  8199. if(loc != NULL)
  8200. {
  8201. c = 0;
  8202. memset(sstr ,0, sizeof(sstr) );
  8203. while (loc[3+strlen("chargingRateUnit")+c] != '\"')
  8204. {
  8205. sstr[c] = loc[3+strlen("chargingRateUnit")+c];
  8206. //printf("i=%d sstr=%c\n",c, sstr[c]);
  8207. c++;
  8208. }
  8209. sstr[c] = '\0';
  8210. strcpy(chargingRateUnitStr,sstr);
  8211. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  8212. {
  8213. strcpy((char *)ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.ChargingSchedule.ChargingRateUnit,chargingRateUnitStr);
  8214. }
  8215. else
  8216. {
  8217. strcpy((char *)ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.ChargingSchedule.ChargingRateUnit,chargingRateUnitStr);
  8218. }
  8219. }
  8220. //DEBUG_INFO("handleSetChargingProfileRequest -13\n");
  8221. //****************chargingSchedulePeriod count start*******************/
  8222. int what_len = strlen("startPeriod");
  8223. char tempChargingProfile[1600]={0};
  8224. strcpy(tempChargingProfile,(const char*)sstrtemp);
  8225. char *where = tempChargingProfile;
  8226. if (what_len)
  8227. {
  8228. while ((where = strstr(where, "startPeriod"))) {
  8229. where += what_len;
  8230. chargingSchedulePeriodCount++;
  8231. }
  8232. }
  8233. if( chargingSchedulePeriodCount > atoi((const char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemData))
  8234. {
  8235. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  8236. goto end;
  8237. }
  8238. //DEBUG_INFO("chargingSchedulePeriodCount=%d\n",chargingSchedulePeriodCount);
  8239. //where = payload;
  8240. int templength = 0;
  8241. //int searchstart = 0;
  8242. for(int periodNums=0; periodNums < chargingSchedulePeriodCount; periodNums++)
  8243. {
  8244. //****************startPeriod*******************/
  8245. c=0;
  8246. loc = strstr(tempChargingProfile + templength, "startPeriod");
  8247. memset(sstr ,0, sizeof(sstr) );
  8248. while ((loc[strlen("startPeriod")+2+c] != '}') && (loc[strlen("startPeriod")+2+c] != ','))
  8249. {
  8250. sstr[c] = loc[strlen("startPeriod")+2+c];
  8251. //printf("i=%d sstr=%c\n",c, sstr[c]);
  8252. c++;
  8253. }
  8254. sstr[c] = '\0';
  8255. startPeriodInt[periodNums] = atoi(sstr);
  8256. //DEBUG_INFO("sstr=%d\n",atoi(sstr));
  8257. //DEBUG_INFO("handleSetChargingProfileRequest -13 -1 -1\n");
  8258. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  8259. {
  8260. ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.ChargingSchedule.ChargingSchedulePeriod[periodNums].StartPeriod = startPeriodInt[periodNums];
  8261. }
  8262. else
  8263. {
  8264. ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.ChargingSchedule.ChargingSchedulePeriod[periodNums].StartPeriod = startPeriodInt[periodNums];
  8265. }
  8266. templength = strlen("startPeriod")+2+c;
  8267. //DEBUG_INFO("handleSetChargingProfileRequest -13 -2\n");
  8268. //****************limit*******************/
  8269. c=0;
  8270. loc = strstr(tempChargingProfile + templength, "limit");
  8271. memset(sstr ,0, sizeof(sstr) );
  8272. while ((loc[strlen("limit")+2+c] != '}') && (loc[strlen("limit")+2+c] != ','))
  8273. {
  8274. sstr[c] = loc[strlen("limit")+2+c];
  8275. //printf("i=%d sstr=%c\n",c, sstr[c]);
  8276. c++;
  8277. }
  8278. sstr[c] = '\0';
  8279. limitflaot[periodNums] = atof(sstr);
  8280. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  8281. {
  8282. ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.ChargingSchedule.ChargingSchedulePeriod[periodNums].Limit = limitflaot[periodNums];
  8283. }
  8284. else
  8285. {
  8286. ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.ChargingSchedule.ChargingSchedulePeriod[periodNums].Limit = limitflaot[periodNums];
  8287. }
  8288. templength = templength + strlen("limit")+2+c;
  8289. //****************numberPhases*******************/
  8290. loc = strstr(tempChargingProfile + templength, "numberPhases");
  8291. if(loc != NULL)
  8292. {
  8293. c=0;
  8294. memset(sstr ,0, sizeof(sstr) );
  8295. while ((loc[strlen("numberPhases")+2+c] != '}') && (loc[strlen("numberPhases")+2+c] != ','))
  8296. {
  8297. sstr[c] = loc[strlen("numberPhases")+2+c];
  8298. //printf("i=%d sstr=%c\n",c, sstr[c]);
  8299. c++;
  8300. }
  8301. sstr[c] = '\0';
  8302. numberPhasesInt[periodNums] = atoi(sstr);
  8303. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  8304. {
  8305. ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.ChargingSchedule.ChargingSchedulePeriod[periodNums].NumberPhases = numberPhasesInt[periodNums];
  8306. }
  8307. else
  8308. {
  8309. ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.ChargingSchedule.ChargingSchedulePeriod[periodNums].NumberPhases = numberPhasesInt[periodNums];
  8310. }
  8311. templength = templength + strlen("numberPhases")+2+c;
  8312. }
  8313. //where = loc;
  8314. }
  8315. //****************chargingSchedulePeriod count end*******************/
  8316. //*********************minChargingRate***************************/
  8317. loc = strstr(sstrtemp, "minChargingRate");
  8318. if(loc != NULL)
  8319. {
  8320. c = 0;
  8321. memset(sstr ,0, sizeof(sstr) );
  8322. while ((loc[strlen("minChargingRate")+2+c] != ',')&&(loc[strlen("minChargingRate")+2+c] != '}'))
  8323. {
  8324. sstr[c] = loc[strlen("minChargingRate")+2+c];
  8325. c++;
  8326. }
  8327. sstr[c] = '\0';
  8328. minChargingRateFloat = atof(sstr);
  8329. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  8330. {
  8331. ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.ChargingSchedule.MinChargingRate = minChargingRateFloat;
  8332. }
  8333. else
  8334. {
  8335. ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.ChargingSchedule.MinChargingRate = minChargingRateFloat;
  8336. }
  8337. }
  8338. else
  8339. {
  8340. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  8341. {
  8342. ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.ChargingSchedule.MinChargingRate = 0.0;
  8343. }
  8344. else
  8345. {
  8346. ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.ChargingSchedule.MinChargingRate = 0.0;
  8347. }
  8348. }
  8349. if(strcmp(chargingProfilePurposeStr, ChargingProfilePurposeTypeStr[ChargePointMaxProfile]) == 0)
  8350. {
  8351. DEBUG_INFO("chargingProfilePurposeStr is ChargePointMaxProfile !!! \n");
  8352. if(connectorIdInt != 0)
  8353. {
  8354. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  8355. goto end;
  8356. }
  8357. strcpy(filename, ChargePointMaxProfile_JSON );
  8358. fptr1 = fopen(filename, "r");
  8359. if (!fptr1)
  8360. {
  8361. //file not exist
  8362. DEBUG_INFO("Unable to open the input file!!\n");
  8363. fptr1 = fopen(filename, "w+");
  8364. }
  8365. else
  8366. {
  8367. //Check Charging Profile Count
  8368. while(fscanf(fptr1, "%s", word) != EOF)
  8369. {
  8370. //DEBUG_INFO("word=%s\n",word);
  8371. if(strstr(word, "chargingProfileId")!= NULL)
  8372. {
  8373. //DEBUG_INFO("test chargingProfileId \n");
  8374. n_chargingProfile = n_chargingProfile + 1;
  8375. //DEBUG_INFO("chargingProfileId Found\n");
  8376. }
  8377. }
  8378. }
  8379. fclose(fptr1);
  8380. }
  8381. else if(strcmp(chargingProfilePurposeStr, ChargingProfilePurposeTypeStr[TxDefaultProfile]) == 0)
  8382. {
  8383. DEBUG_INFO("chargingProfilePurposeStr is TxDefaultProfile !!! \n");
  8384. if((connectorIdInt != 0) && (connectorIdInt > gunTotalNumber /*(CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY)*/))
  8385. {
  8386. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  8387. goto end;
  8388. }
  8389. memset(filename, 0, sizeof filename);
  8390. sprintf(filename, "/Storage/OCPP/TxDefaultProfile_%d.json", connectorIdInt);
  8391. fptr1 = fopen(filename, "r");
  8392. if (!fptr1)
  8393. {
  8394. //file not exist
  8395. //DEBUG_INFO("Unable to open the input file!!\n");
  8396. fptr1 = fopen(filename, "w+");
  8397. }
  8398. else
  8399. {
  8400. //Check Charging Profile Count
  8401. while(fscanf(fptr1, "%s", word) != EOF)
  8402. {
  8403. //DEBUG_INFO("word=%s\n",word);
  8404. if(strstr(word, "chargingProfileId")!= NULL)
  8405. {
  8406. //DEBUG_INFO("test chargingProfileId \n");
  8407. n_chargingProfile = n_chargingProfile + 1;
  8408. //DEBUG_INFO("chargingProfileId Found\n");
  8409. }
  8410. }
  8411. }
  8412. fclose(fptr1);
  8413. }
  8414. else if(strcmp(chargingProfilePurposeStr, ChargingProfilePurposeTypeStr[TxProfile]) == 0)
  8415. {
  8416. //printf("set chargingProfile 1-4\n");
  8417. DEBUG_INFO("chargingProfilePurposeStr is TxProfile !!! \n");
  8418. //---TxProfile SHALL only be set at Charge Point ConnectorId > 0. ---//
  8419. if(connectorIdInt == 0)
  8420. {
  8421. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  8422. goto end;
  8423. }
  8424. int tempIndex = 0;
  8425. //check Transaction active
  8426. if(gunType[connectorIdInt -1] == 'J')
  8427. {
  8428. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  8429. {
  8430. tempIndex = (((connectorIdInt -1)==2) ? 1: 0);
  8431. }
  8432. else
  8433. {
  8434. tempIndex = connectorIdInt -1;
  8435. }
  8436. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  8437. {
  8438. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  8439. {
  8440. if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_CHARGING) // S_CHARGING
  8441. {
  8442. if(transactionIdInt == ShmOCPP16Data->StartTransaction[connectorIdInt -1].ResponseTransactionId)
  8443. {
  8444. meet = TRUE;
  8445. break;
  8446. }
  8447. }
  8448. }
  8449. }
  8450. }
  8451. else if((gunType[connectorIdInt -1] == 'U')||(gunType[connectorIdInt -1] == 'E'))
  8452. {
  8453. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  8454. {
  8455. tempIndex = (((connectorIdInt -1)==2) ? 1: 0);
  8456. }
  8457. else
  8458. {
  8459. tempIndex = connectorIdInt -1;
  8460. }
  8461. for (int index = 0; index < CCS_QUANTITY; index++)
  8462. {
  8463. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  8464. {
  8465. if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_CHARGING) // S_CHARGING
  8466. {
  8467. if(transactionIdInt == ShmOCPP16Data->StartTransaction[connectorIdInt -1].ResponseTransactionId)
  8468. {
  8469. meet = TRUE;
  8470. break;
  8471. }
  8472. }
  8473. }
  8474. }
  8475. }
  8476. else if(gunType[connectorIdInt -1] == 'G')
  8477. {
  8478. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  8479. {
  8480. tempIndex = (((connectorIdInt -1)==2) ? 1: 0);
  8481. }
  8482. else
  8483. {
  8484. tempIndex = connectorIdInt -1;
  8485. }
  8486. for (int index = 0; index < GB_QUANTITY; index++)
  8487. {
  8488. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  8489. {
  8490. if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_CHARGING) // S_CHARGING
  8491. {
  8492. if(transactionIdInt == ShmOCPP16Data->StartTransaction[connectorIdInt -1].ResponseTransactionId)
  8493. {
  8494. meet = TRUE;
  8495. break;
  8496. }
  8497. }
  8498. }
  8499. }
  8500. }
  8501. else
  8502. {
  8503. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D') // 'D' means DC
  8504. {
  8505. tempIndex = 2;
  8506. }
  8507. else
  8508. {
  8509. tempIndex = (connectorIdInt -1);
  8510. }
  8511. for (int index = 0; index < AC_QUANTITY; index++)
  8512. {
  8513. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  8514. {
  8515. if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_CHARGING) // S_CHARGING
  8516. {
  8517. if(transactionIdInt == ShmOCPP16Data->StartTransaction[connectorIdInt -1].ResponseTransactionId)
  8518. {
  8519. meet = TRUE;
  8520. break;
  8521. }
  8522. }
  8523. }
  8524. }
  8525. }
  8526. //check Transaction active
  8527. if(meet == FALSE)
  8528. {
  8529. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  8530. goto end;
  8531. }
  8532. if((connectorIdInt != 0) && (connectorIdInt > gunTotalNumber /*(CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY)*/))
  8533. {
  8534. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  8535. goto end;
  8536. }
  8537. sprintf(filename, "/Storage/OCPP/TxProfile_%d.json", connectorIdInt);
  8538. fptr1 = fopen(filename, "r");
  8539. if (!fptr1)
  8540. {
  8541. //file not exist
  8542. DEBUG_INFO("Unable to open the input file!!\n");
  8543. fptr1 = fopen(filename, "w+");
  8544. }
  8545. else
  8546. {
  8547. //Check Charging Profile Count
  8548. while(fscanf(fptr1, "%s", word) != EOF)
  8549. {
  8550. //DEBUG_INFO("word=%s\n",word);
  8551. if(strstr(word, "chargingProfileId")!= NULL)
  8552. {
  8553. //DEBUG_INFO("test chargingProfileId \n");
  8554. n_chargingProfile = n_chargingProfile + 1;
  8555. //DEBUG_INFO("chargingProfileId Found\n");
  8556. }
  8557. }
  8558. }
  8559. fclose(fptr1);
  8560. }
  8561. // Check ChargeProfileMaxStackLevel
  8562. if(n_chargingProfile >= atoi((const char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemData))
  8563. {
  8564. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  8565. goto end;
  8566. }
  8567. //------------------------------Satrt: Check Configuration Key "MaxChargingProfilesInstalled" Logic---------------------------------------//
  8568. {
  8569. int i = 0;
  8570. char fnametemp[200]={0};
  8571. n_chargingProfile = 0;
  8572. //Check ChargePointMaxProfile.json exit
  8573. if((access("/Storage/OCPP/ChargePointMaxProfile.json",F_OK))!=-1)
  8574. {
  8575. fptr1 = fopen("/Storage/OCPP/ChargePointMaxProfile.json", "r");
  8576. //Check Charging Profile Count
  8577. while(fscanf(fptr1, "%s", word) != EOF)
  8578. {
  8579. //DEBUG_INFO("word=%s\n",word);
  8580. if(strstr(word, "chargingProfileId")!= NULL)
  8581. {
  8582. //DEBUG_INFO("test chargingProfileId \n");
  8583. n_chargingProfile = n_chargingProfile + 1;
  8584. i = i + 1;
  8585. //DEBUG_INFO("chargingProfileId Found\n");
  8586. }
  8587. memset(word, 0, sizeof word);
  8588. }
  8589. fclose(fptr1);
  8590. DEBUG_INFO("ChargePointMaxProfile.json has %d charging Profile\n",i );
  8591. }
  8592. //Check TxDefaultProfile_0.json exit
  8593. if((access("/Storage/OCPP/TxDefaultProfile_0.json",F_OK))!=-1)
  8594. {
  8595. i = 0;
  8596. fptr1 = fopen("/Storage/OCPP/TxDefaultProfile_0.json", "r");
  8597. //Check Charging Profile Count
  8598. while(fscanf(fptr1, "%s", word) != EOF)
  8599. {
  8600. //DEBUG_INFO("word=%s\n",word);
  8601. if(strstr(word, "chargingProfileId")!= NULL)
  8602. {
  8603. //DEBUG_INFO("test chargingProfileId \n");
  8604. n_chargingProfile = n_chargingProfile + 1;
  8605. i = i + 1;
  8606. //DEBUG_INFO("chargingProfileId Found\n");
  8607. }
  8608. memset(word, 0, sizeof word);
  8609. }
  8610. fclose(fptr1);
  8611. DEBUG_INFO("TxDefaultProfile_0.json has %d charging Profile\n",i );
  8612. }
  8613. //Check TxDefaultProfile_%d.json
  8614. for(int j=1; j <= gunTotalNumber; j++)
  8615. {
  8616. memset(fnametemp, 0, sizeof fnametemp);
  8617. sprintf(fnametemp, "/Storage/OCPP/TxDefaultProfile_%d.json", j);
  8618. if((access(fnametemp,F_OK))!=-1)
  8619. {
  8620. i = 0;
  8621. fptr1 = fopen(fnametemp, "r");
  8622. //Check Charging Profile Count
  8623. while(fscanf(fptr1, "%s", word) != EOF)
  8624. {
  8625. //DEBUG_INFO("word=%s\n",word);
  8626. if(strstr(word, "chargingProfileId")!= NULL)
  8627. {
  8628. //DEBUG_INFO("test chargingProfileId \n");
  8629. n_chargingProfile = n_chargingProfile + 1;
  8630. i = i + 1;
  8631. //DEBUG_INFO("chargingProfileId Found\n");
  8632. }
  8633. memset(word, 0, sizeof word);
  8634. }
  8635. fclose(fptr1);
  8636. DEBUG_INFO("%s has %d charging Profile\n",fnametemp, i);
  8637. }
  8638. }
  8639. //Check TxProfile_%d.json
  8640. for(int j=1; j <= gunTotalNumber; j++)
  8641. {
  8642. memset(fnametemp, 0, sizeof fnametemp);
  8643. sprintf(fnametemp, "/Storage/OCPP/TxProfile_%d.json", j);
  8644. if((access(fnametemp,F_OK))!=-1)
  8645. {
  8646. i = 0;
  8647. fptr1 = fopen(fnametemp, "r");
  8648. //Check Charging Profile Count
  8649. while(fscanf(fptr1, "%s", word) != EOF)
  8650. {
  8651. //DEBUG_INFO("word=%s\n",word);
  8652. if(strstr(word, "chargingProfileId")!= NULL)
  8653. {
  8654. //DEBUG_INFO("test chargingProfileId \n");
  8655. n_chargingProfile = n_chargingProfile + 1;
  8656. i = i + 1;
  8657. //DEBUG_INFO("chargingProfileId Found\n");
  8658. }
  8659. memset(word, 0, sizeof word);
  8660. }
  8661. fclose(fptr1);
  8662. DEBUG_INFO("%s has %d charging Profile\n",fnametemp, i);
  8663. }
  8664. }
  8665. if( n_chargingProfile > atoi((const char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemData))
  8666. {
  8667. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  8668. goto end;
  8669. }
  8670. }
  8671. //------------------------------End: Check Configuration Key "MaxChargingProfilesInstalled" Logic---------------------------------------//
  8672. //**********************************Write to File********************************************************/
  8673. FILE *infile;
  8674. FILE *outfile;
  8675. // open file for writing
  8676. infile = fopen (filename, "r");
  8677. outfile = fopen (tempfile, "w");
  8678. int d =0;
  8679. d = fgetc(infile);
  8680. //DEBUG_INFO("d:%d\n",d);
  8681. rewind(infile);
  8682. //*璉 瘚 辣蝏     1嚗   0 */
  8683. if(d == EOF)
  8684. {
  8685. //DEBUG_INFO("ChargingProfile content is NULL\n");
  8686. fprintf(outfile,"%s\n",payload);
  8687. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Accepted] );
  8688. fclose(infile);
  8689. fclose(outfile);
  8690. sprintf(rmFileCmd,"rm -f %s",filename);
  8691. system(rmFileCmd);
  8692. rename(tempfile, filename);
  8693. sleep(1);
  8694. //sprintf(rmFileCmd,"rm -f %s",tempfile);
  8695. //system(rmFileCmd);
  8696. }
  8697. else
  8698. {
  8699. char buf[1000]={0};
  8700. int ChargingProfileAdded = FALSE;
  8701. while (fgets(buf, sizeof(buf), infile) != NULL)
  8702. {
  8703. buf[strlen(buf) - 1] = '\0'; // eat the newline fgets() stores
  8704. //*************************tempconnectorIdInt*********************************/
  8705. loc = strstr(buf, "connectorId");
  8706. c = 0;
  8707. memset(sstr ,0, sizeof(sstr) );
  8708. while (loc[strlen("connectorId")+2+c] != ',')
  8709. {
  8710. sstr[c] = loc[strlen("connectorId")+2+c];
  8711. c++;
  8712. }
  8713. sstr[c] = '\0';
  8714. tempconnectorIdInt = atoi(sstr);
  8715. //*************************tempchargingProfileIdInt*********************************/
  8716. loc = strstr(buf, "chargingProfileId");
  8717. c = 0;
  8718. memset(sstr ,0, sizeof(sstr) );
  8719. while (loc[strlen("chargingProfileId")+2+c] != ',')
  8720. {
  8721. sstr[c] = loc[strlen("chargingProfileId")+2+c];
  8722. c++;
  8723. }
  8724. sstr[c] = '\0';
  8725. tempchargingProfileIdInt = atoi(sstr);
  8726. //*************************tempstackLevelInt*********************************/
  8727. loc = strstr(buf, "stackLevel");
  8728. c = 0;
  8729. memset(sstr ,0, sizeof(sstr) );
  8730. while (loc[strlen("stackLevel")+2+c] != ',')
  8731. {
  8732. sstr[c] = loc[strlen("stackLevel")+2+c];
  8733. c++;
  8734. }
  8735. sstr[c] = '\0';
  8736. tempstackLevelInt = atoi(sstr);
  8737. //*************************tempchargingProfilePurposeStr*********************************/
  8738. loc = strstr(payload, "chargingProfilePurpose");
  8739. c = 0;
  8740. memset(sstr ,0, sizeof(sstr) );
  8741. while (loc[3+strlen("chargingProfilePurpose")+c] != '\"')
  8742. {
  8743. sstr[c] = loc[3+strlen("chargingProfilePurpose")+c];
  8744. //printf("i=%d sstr=%c\n",c, sstr[c]);
  8745. c++;
  8746. }
  8747. sstr[c] = '\0';
  8748. strcpy(tempchargingProfilePurposeStr,sstr);
  8749. if((tempconnectorIdInt == connectorIdInt) && (tempchargingProfileIdInt == chargingProfileIdInt))
  8750. {
  8751. if((tempstackLevelInt == stackLevelInt) && (strcmp(tempchargingProfilePurposeStr, chargingProfilePurposeStr) == 0))
  8752. {
  8753. //DEBUG_INFO("update set chargingProfile to file -0\n");
  8754. if(ChargingProfileAdded == FALSE)
  8755. {
  8756. fprintf(outfile,"%s\n",payload);
  8757. ChargingProfileAdded = TRUE;
  8758. }
  8759. }
  8760. else
  8761. {
  8762. if(tempstackLevelInt < stackLevelInt)
  8763. {
  8764. if(ChargingProfileAdded == FALSE)
  8765. {
  8766. fprintf(outfile,"%s\n",payload);
  8767. ChargingProfileAdded = TRUE;
  8768. fprintf(outfile,"%s\n",buf);
  8769. }
  8770. else
  8771. {
  8772. fprintf(outfile,"%s\n",buf);
  8773. }
  8774. }
  8775. else
  8776. {
  8777. if(ChargingProfileAdded == FALSE)
  8778. {
  8779. fprintf(outfile,"%s\n",buf);
  8780. fprintf(outfile,"%s\n",payload);
  8781. ChargingProfileAdded = TRUE;
  8782. }
  8783. else
  8784. {
  8785. fprintf(outfile,"%s\n",buf);
  8786. }
  8787. }
  8788. }
  8789. }
  8790. else
  8791. {
  8792. if(tempchargingProfileIdInt < chargingProfileIdInt)
  8793. {
  8794. if(ChargingProfileAdded == FALSE)
  8795. {
  8796. fprintf(outfile,"%s\n",payload);
  8797. ChargingProfileAdded = TRUE;
  8798. fprintf(outfile,"%s\n",buf);
  8799. }
  8800. else
  8801. {
  8802. fprintf(outfile,"%s\n",buf);
  8803. }
  8804. }
  8805. else if(tempstackLevelInt < stackLevelInt)
  8806. {
  8807. if(ChargingProfileAdded == FALSE)
  8808. {
  8809. fprintf(outfile,"%s\n",payload);
  8810. ChargingProfileAdded = TRUE;
  8811. fprintf(outfile,"%s\n",buf);
  8812. }
  8813. else
  8814. {
  8815. fprintf(outfile,"%s\n",buf);
  8816. }
  8817. }
  8818. else
  8819. {
  8820. if(ChargingProfileAdded == FALSE)
  8821. {
  8822. fprintf(outfile,"%s\n",buf);
  8823. fprintf(outfile,"%s\n",payload);
  8824. ChargingProfileAdded = TRUE;
  8825. }
  8826. else
  8827. {
  8828. fprintf(outfile,"%s\n",buf);
  8829. }
  8830. }
  8831. }
  8832. } // end of while loop
  8833. fclose(infile);
  8834. fclose(outfile);
  8835. sprintf(rmFileCmd,"rm -f %s",filename);
  8836. system(rmFileCmd);
  8837. rename(tempfile, filename);
  8838. sleep(1);
  8839. result = TRUE;
  8840. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Accepted] );
  8841. }
  8842. end:
  8843. sendSetChargingProfileConfirmation(uuid, comfirmstr);
  8844. return result;
  8845. return result;
  8846. }
  8847. int handleTriggerMessageRequest(char *uuid, char *payload)
  8848. {
  8849. mtrace();
  8850. int result = FAIL;
  8851. int connectorIdIsNULL = FALSE;
  8852. int connectorIdInt =0;
  8853. char sstr[40]={0},sstrtemp[100]={ 0 };
  8854. char requestedMessagestr[40]={0};
  8855. char comfirmstr[20]={0};
  8856. int c = 0;
  8857. char *loc;
  8858. DEBUG_INFO("handleTriggerMessageRequest\n");
  8859. //[2,"266e23f4-27a4-41cf-84cb-aadf56b9523f","TriggerMessage",{"requestedMessage":"DiagnosticsStatusNotification","connectorId":1}]
  8860. strcpy(sstrtemp, stringtrimspace(payload));
  8861. c = 0;
  8862. loc = strstr(sstrtemp, "requestedMessage");
  8863. while (loc[3+strlen("requestedMessage")+c] != '\"')
  8864. {
  8865. sstr[c] = loc[3+strlen("requestedMessage")+c];
  8866. c++;
  8867. }
  8868. sstr[c] = '\0';
  8869. strcpy(requestedMessagestr, sstr);
  8870. c = 0;
  8871. loc = strstr(sstrtemp, "connectorId");
  8872. if(loc == NULL)
  8873. {
  8874. connectorIdIsNULL = TRUE;
  8875. }
  8876. else
  8877. {
  8878. memset(sstr ,0, sizeof(sstr) );
  8879. while ((loc[strlen("connectorId")+2+c] != ',')&&(loc[strlen("connectorId")+2+c] != '}'))
  8880. {
  8881. sstr[c] = loc[strlen("connectorId")+2+c];
  8882. //printf("i=%d sstr=%c\n",c, sstr[c]);
  8883. c++;
  8884. }
  8885. sstr[c] = '\0';
  8886. connectorIdInt = atoi(sstr);
  8887. }
  8888. if(connectorIdIsNULL == FALSE && ((connectorIdInt > 0) && (connectorIdInt <= gunTotalNumber /*(CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY)*/ )))
  8889. {
  8890. //connectorIdInt = json_object_get_int(connectorId);
  8891. sprintf((char *)ShmOCPP16Data->TriggerMessage[connectorIdInt -1].RequestedMessage, "%s" ,requestedMessagestr);
  8892. ShmOCPP16Data->TriggerMessage[connectorIdInt -1].ConnectorId = connectorIdInt;
  8893. //ShmOCPP16Data->CsMsg.bits[connectorIdInt -1].TriggerMessageReq = 1;
  8894. sprintf(comfirmstr, "%s",TriggerMessageStatusStr[TriggerMessageStatus_Accepted] );
  8895. sendTriggerMessageConfirmation(uuid,comfirmstr);
  8896. }
  8897. else if(connectorIdIsNULL == FALSE && ((connectorIdInt <= 0) || (connectorIdInt > gunTotalNumber /*(CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY)*/) ))
  8898. {
  8899. sprintf(comfirmstr, "%s",TriggerMessageStatusStr[TriggerMessageStatus_Rejected] );
  8900. sendTriggerMessageConfirmation(uuid,comfirmstr);
  8901. return TRUE;
  8902. }
  8903. if((strcmp(requestedMessagestr, MessageTriggerStr[FirmwareStatusNotification]) != 0) &&
  8904. (strcmp(requestedMessagestr, MessageTriggerStr[DiagnosticsStatusNotification]) != 0) &&
  8905. (strcmp(requestedMessagestr, MessageTriggerStr[BootNotification]) != 0 ) &&
  8906. (strcmp(requestedMessagestr, MessageTriggerStr[Heartbeat]) != 0) &&
  8907. (strcmp(requestedMessagestr, MessageTriggerStr[MeterValues]) != 0) &&
  8908. (strcmp(requestedMessagestr, MessageTriggerStr[StatusNotification]) != 0 ))
  8909. {
  8910. sprintf(comfirmstr, "%s",TriggerMessageStatusStr[TriggerMessageStatus_NotImplemented] );
  8911. sendTriggerMessageConfirmation(uuid,comfirmstr);
  8912. return TRUE;
  8913. }
  8914. else
  8915. {
  8916. sprintf(comfirmstr, "%s",TriggerMessageStatusStr[TriggerMessageStatus_Accepted] );
  8917. sendTriggerMessageConfirmation(uuid,comfirmstr);
  8918. }
  8919. if( strcmp(requestedMessagestr, MessageTriggerStr[FirmwareStatusNotification]) == 0)
  8920. {
  8921. if((FirmwareStatusNotificationStatus != FIRMWARE_STATUS_DOWNLOADING) &&
  8922. (FirmwareStatusNotificationStatus != FIRMWARE_STATUS_IDLE) &&
  8923. (FirmwareStatusNotificationStatus != FIRMWARE_STATUS_INSTALLING) )
  8924. {
  8925. FirmwareStatusNotificationStatus = FIRMWARE_STATUS_IDLE;
  8926. }
  8927. sendFirmwareStatusNotificationRequest(FirmwareStatusStr[FirmwareStatusNotificationStatus]);
  8928. //sprintf(comfirmstr, "%s",TriggerMessageStatusStr[TriggerMessageStatus_Accepted] );
  8929. }
  8930. else if(strcmp(requestedMessagestr, MessageTriggerStr[DiagnosticsStatusNotification]) == 0 )
  8931. {
  8932. //printf("DiagnosticsStatusStr[DiagnosticsStatus_Idle] =%s\n",DiagnosticsStatusStr[DiagnosticsStatus_Idle]);
  8933. sendDiagnosticsStatusNotificationRequest(DiagnosticsStatusStr[DiagnosticsStatusNotificationStatus]);
  8934. //sprintf(comfirmstr, "%s",TriggerMessageStatusStr[TriggerMessageStatus_Accepted] );
  8935. }
  8936. else if(strcmp(requestedMessagestr, MessageTriggerStr[BootNotification]) == 0 )
  8937. {
  8938. sendBootNotificationRequest();
  8939. //sprintf(comfirmstr, "%s",TriggerMessageStatusStr[TriggerMessageStatus_Accepted] );
  8940. }
  8941. else if(strcmp(requestedMessagestr, MessageTriggerStr[Heartbeat]) == 0 )
  8942. {
  8943. sendHeartbeatRequest(connectorIdInt);
  8944. //sprintf(comfirmstr, "%s",TriggerMessageStatusStr[TriggerMessageStatus_Accepted] );
  8945. }
  8946. else if (strcmp(requestedMessagestr, MessageTriggerStr[MeterValues]) == 0 )
  8947. {
  8948. if(connectorIdIsNULL == FALSE)
  8949. {
  8950. if((connectorIdInt > 0) && ((connectorIdInt -1) < gunTotalNumber))
  8951. {
  8952. ShmOCPP16Data->CsMsg.bits[connectorIdInt -1].TriggerMessageReq = 1;
  8953. sendMeterValuesRequest(connectorIdInt -1);
  8954. //sprintf(comfirmstr, "%s",TriggerMessageStatusStr[TriggerMessageStatus_Accepted] );
  8955. }
  8956. }
  8957. else
  8958. {
  8959. for(int idx=0;idx< gunTotalNumber;idx++)
  8960. {
  8961. ShmOCPP16Data->CsMsg.bits[idx].TriggerMessageReq = 1;
  8962. sendMeterValuesRequest(idx);
  8963. }
  8964. }
  8965. }
  8966. else if(strcmp(requestedMessagestr, MessageTriggerStr[StatusNotification]) == 0 )
  8967. {
  8968. if(connectorIdIsNULL == FALSE)
  8969. {
  8970. if((connectorIdInt > 0) && ((connectorIdInt -1) < gunTotalNumber))
  8971. {
  8972. sendStatusNotificationRequest(connectorIdInt -1);
  8973. //sprintf(comfirmstr, "%s",TriggerMessageStatusStr[TriggerMessageStatus_Accepted] );
  8974. }
  8975. }
  8976. else
  8977. {
  8978. for(int idx=0;idx< gunTotalNumber;idx++)
  8979. sendStatusNotificationRequest(idx);
  8980. //sprintf(comfirmstr, "%s",TriggerMessageStatusStr[TriggerMessageStatus_Accepted] );
  8981. }
  8982. }
  8983. return result;
  8984. }
  8985. int handleUnlockConnectorRequest(char *uuid, char *payload)
  8986. {
  8987. mtrace();
  8988. int result = FAIL;
  8989. char sstr[6]={0},sstrtemp[50]={ 0 };
  8990. int connectorIdInt =0;
  8991. char comfirmstr[20]={0};
  8992. int c = 0;
  8993. int tempIndex = 0;
  8994. char *loc;
  8995. //[2,"ba1cbd49-2a76-493a-8f76-fa23e7606532","UnlockConnector",{"connectorId":1}]
  8996. DEBUG_INFO("handleUnlockConnectorRequest ...\n");
  8997. strcpy(sstrtemp, stringtrimspace(payload));
  8998. c = 0;
  8999. loc = strstr(sstrtemp, "connectorId");
  9000. memset(sstr ,0, sizeof(sstr) );
  9001. while (loc[strlen("connectorId")+2+c] != '}')
  9002. {
  9003. sstr[c] = loc[strlen("connectorId")+2+c];
  9004. //printf("i=%d sstr=%c\n",c, sstr[c]);
  9005. c++;
  9006. }
  9007. sstr[c] = '\0';
  9008. connectorIdInt = atoi(sstr);
  9009. DEBUG_INFO("\n unlock connectorIdInt=%d\n",connectorIdInt);
  9010. if(gunTotalNumber == 0)
  9011. {
  9012. sprintf(comfirmstr, "%s", UnlockStatusStr[UnlockStatus_NotSupported] );
  9013. goto end;
  9014. }
  9015. else if((connectorIdInt > gunTotalNumber/*CHAdeMO_QUANTITY+ CCS_QUANTITY + GB_QUANTITY*/) || (connectorIdInt <= 0))
  9016. {
  9017. //sprintf(comfirmstr, "%s", UnlockStatusStr[UnlockStatus_NotSupported] );
  9018. sprintf(comfirmstr, "%s", UnlockStatusStr[UnlockStatus_NotSupported] );
  9019. goto end;
  9020. }
  9021. else
  9022. {
  9023. //check Transaction active
  9024. if(gunType[connectorIdInt-1] == 'J')
  9025. {
  9026. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  9027. {
  9028. tempIndex = (((connectorIdInt -1)==2) ? 1: 0);
  9029. }
  9030. else
  9031. {
  9032. tempIndex = connectorIdInt -1;
  9033. }
  9034. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  9035. {
  9036. if ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex ) && ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_IDLE) ))
  9037. {
  9038. //stop Transaction
  9039. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].UnlockConnectorReq = 1;
  9040. }
  9041. }
  9042. }
  9043. else if((gunType[connectorIdInt-1] == 'U')||(gunType[connectorIdInt-1] == 'E'))
  9044. {
  9045. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  9046. {
  9047. tempIndex = (((connectorIdInt -1)==2) ? 1: 0);
  9048. }
  9049. else
  9050. {
  9051. tempIndex = connectorIdInt -1;
  9052. }
  9053. for (int index = 0; index < CCS_QUANTITY; index++)
  9054. {
  9055. if ((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex ) && ((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_IDLE) ))
  9056. {
  9057. //stop Transaction
  9058. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].UnlockConnectorReq = 1;
  9059. }
  9060. }
  9061. }
  9062. else if(gunType[connectorIdInt-1] == 'G')
  9063. {
  9064. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  9065. {
  9066. tempIndex = (((connectorIdInt -1)==2) ? 1: 0);
  9067. }
  9068. else
  9069. {
  9070. tempIndex = connectorIdInt -1;
  9071. }
  9072. for (int index = 0; index < GB_QUANTITY; index++)
  9073. {
  9074. if ((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex ) &&((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_CHARGING)||(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_IDLE)))
  9075. {
  9076. //stop Transaction
  9077. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].UnlockConnectorReq = 1;
  9078. }
  9079. }
  9080. }
  9081. else
  9082. {
  9083. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  9084. {
  9085. tempIndex = 2;
  9086. }
  9087. else
  9088. {
  9089. tempIndex = connectorIdInt-1;
  9090. }
  9091. for (int index = 0; index < AC_QUANTITY; index++)
  9092. {
  9093. if ((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex ) && ((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_IDLE) ))
  9094. {
  9095. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].UnlockConnectorReq = 1;
  9096. }
  9097. }
  9098. }
  9099. ShmOCPP16Data->UnlockConnector[connectorIdInt-1].ConnectorId = connectorIdInt;
  9100. strcpy((char *)ShmOCPP16Data->UnlockConnector[connectorIdInt-1].guid, uuid);
  9101. result = TRUE;
  9102. return result;
  9103. }
  9104. end:
  9105. //json_object_put(obj); --- remove temporally
  9106. sendUnlockConnectorConfirmation(uuid, comfirmstr);
  9107. return result;
  9108. }
  9109. static char UpdateFirmwarepayloadData[300]={0};
  9110. int handleUpdateFirmwareRequest(char *uuid, char *payload)
  9111. {
  9112. mtrace();
  9113. int result = FAIL;
  9114. pthread_t t;
  9115. sendUpdateFirmwareConfirmation(uuid);
  9116. memset(UpdateFirmwarepayloadData, 0, 300);
  9117. strcpy(UpdateFirmwarepayloadData, stringtrimspace(payload));
  9118. pthread_create(&t, NULL, UpdateFirmwareProcess, stringtrimspace(payload));
  9119. ////pthread_join(t, NULL); //
  9120. //pthread_detach(t);
  9121. //sendUpdateFirmwareConfirmation(uuid);
  9122. ShmOCPP16Data->MsMsg.bits.UpdateFirmwareConf =1;
  9123. //ShmOCPP16Data->MsMsg.bits.UpdateFirmwareReq = 1;
  9124. return result;
  9125. }
  9126. void *UpdateFirmwareProcess(void *data)
  9127. {
  9128. pthread_detach(pthread_self());
  9129. mtrace();
  9130. int retriesInt =0, retryIntervalInt=0;
  9131. char protocol[10], user[50],password[50],host[50], path[50], ftppath[60],host1[50],path1[20];
  9132. int port=0;
  9133. char locationstr[160]={0}, retrieveDatestr[30]={0};
  9134. //char fname[50]="00000_2018-09-07 160902_CSULog.zip";
  9135. //char comfirmstr[20];
  9136. int isSuccess = 0;
  9137. char ftpbuf[200];
  9138. char temp[100];
  9139. char * pch;
  9140. int retriesISNULL=FALSE;
  9141. int retryInterval=FALSE;
  9142. int c = 0;
  9143. //int i = 0;
  9144. char *loc;
  9145. char sstr[300]={ 0 };
  9146. char str[300]={ 0 };
  9147. //char *str = (char*) data; // ? ?頛詨鞈 ?
  9148. DEBUG_INFO("handleUpdateFirmwareRequest ...\n");
  9149. //DEBUG_INFO("packet=%s\n", (const char*)payloadData);
  9150. strcpy(str,(const char*)UpdateFirmwarepayloadData);
  9151. //***************location **************/
  9152. loc = strstr(str, "location");
  9153. memset(sstr ,0, sizeof(sstr) );
  9154. c = 0;
  9155. while (loc[3+strlen("location")+c] != '\"')
  9156. {
  9157. sstr[c] = loc[3+strlen("location")+c];
  9158. c++;
  9159. }
  9160. sstr[c] = '\0';
  9161. strcpy(locationstr, sstr);
  9162. //***************retries**************/
  9163. c = 0;
  9164. loc = strstr(str, "retries");
  9165. if(loc == NULL)
  9166. {
  9167. retriesISNULL=TRUE;
  9168. }
  9169. else
  9170. {
  9171. memset(sstr ,0, sizeof(sstr) );
  9172. while (loc[strlen("retries")+2+c] != ',')
  9173. {
  9174. sstr[c] = loc[strlen("retries")+2+c];
  9175. //printf("i=%d sstr=%c\n",c, sstr[c]);
  9176. c++;
  9177. }
  9178. sstr[c] = '\0';
  9179. }
  9180. if(retriesISNULL == FALSE)
  9181. {
  9182. retriesInt = atoi(sstr);
  9183. }
  9184. //***************retrieveDate **************/
  9185. loc = strstr(str, "retrieveDate");
  9186. memset(sstr ,0, sizeof(sstr) );
  9187. c = 0;
  9188. while (loc[3+strlen("retrieveDate")+c] != '\"')
  9189. {
  9190. sstr[c] = loc[3+strlen("retrieveDate")+c];
  9191. c++;
  9192. }
  9193. sstr[c] = '\0';
  9194. strcpy(retrieveDatestr, sstr);
  9195. //***************retryInterval **************/
  9196. c = 0;
  9197. loc = strstr(str, "retryInterval");
  9198. memset(sstr ,0, sizeof(sstr) );
  9199. if(loc == NULL)
  9200. {
  9201. retryInterval=TRUE;
  9202. }
  9203. else
  9204. {
  9205. while ((loc[strlen("retryInterval")+2+c] != ',') && (loc[strlen("retryInterval")+2+c] != '}'))
  9206. {
  9207. sstr[c] = loc[strlen("retryInterval")+2+c];
  9208. //DEBUG_INFO("i=%d sstr=%c\n",c, sstr[c]);
  9209. c++;
  9210. }
  9211. sstr[c] = '\0';
  9212. }
  9213. if(retryInterval==FALSE)
  9214. {
  9215. retryIntervalInt = atoi(sstr);
  9216. }
  9217. memset(ftppath, 0, sizeof(ftppath));
  9218. memset(path, 0, sizeof(path));
  9219. sendFirmwareStatusNotificationRequest(FirmwareStatusStr[FirmwareStatus_Downloading]);
  9220. ShmOCPP16Data->MsMsg.bits.UpdateFirmwareReq = 1;
  9221. if(strncmp(locationstr,"http", 4) == 0)
  9222. {
  9223. sscanf(locationstr,"%[^:]:%*2[/]%[^/]/%199[^\n]",
  9224. protocol, host, path);
  9225. //sscanf(locationstr,"%[^:]:%*2[/]%[^:]:%[^@]@%[^/]%199[^\n]",
  9226. // protocol, user, password, host, path);
  9227. sprintf(ftppath,"/%s", path);
  9228. //DEBUG_INFO("protocol =%s\n",protocol);
  9229. //DEBUG_INFO("host =%s\n",host);
  9230. //DEBUG_INFO("path =%s\n",path);
  9231. //DEBUG_INFO("ftppath=%s\n",ftppath);
  9232. int ftppathlen=strlen(ftppath);
  9233. int i=1;
  9234. char filenametemp[50];
  9235. while(i < ftppathlen)
  9236. {
  9237. int len=ftppathlen-i;
  9238. if(ftppath[len]== 47) // '/' ascll code: 47
  9239. {
  9240. DEBUG_INFO("compare '/' all right\n");
  9241. break;
  9242. }
  9243. i=i+1;
  9244. }
  9245. memset(filenametemp, 0, sizeof(filenametemp));
  9246. strncpy(filenametemp, ftppath+(ftppathlen-i+1), i+1);
  9247. filenametemp[i+1] = 0;
  9248. //sendFirmwareStatusNotificationRequest(FirmwareStatusStr[FirmwareStatus_Downloading]);
  9249. do{
  9250. isSuccess = httpDownLoadFile(host, ftppath, filenametemp, locationstr);
  9251. sleep(retryIntervalInt);
  9252. }while((isSuccess == 0)&&(retriesInt > 0 && retriesInt --));
  9253. // isSuccess = httpDownLoadFile(host, ftppath, filenametemp, locationstr);
  9254. if(!isSuccess)
  9255. {
  9256. sendFirmwareStatusNotificationRequest(FirmwareStatusStr[FirmwareStatus_DownloadFailed]);
  9257. }
  9258. else
  9259. {
  9260. //ShmOCPP16Data->MsMsg.bits.UpdateFirmwareReq = 1;
  9261. sendFirmwareStatusNotificationRequest(FirmwareStatusStr[FirmwareStatus_Downloaded]);
  9262. //isUpdateRequest = TRUE;
  9263. }
  9264. }
  9265. else if(strncmp(locationstr,"ftp", 3) == 0) // ftp
  9266. {
  9267. memset(ftpbuf, 0, sizeof(ftpbuf));
  9268. memset(temp, 0, sizeof(temp));
  9269. //DEBUG_INFO("locationstr=%s\n",locationstr);
  9270. strcpy(ftpbuf, locationstr/*"ftp://ipc_ui:pht2016@ftp.phihong.com.tw/DC/log/DemoDC1_2018-07-13_185011_PSULog.zip"*/ );
  9271. int ftppathlen=strlen(ftpbuf);
  9272. int i=1;
  9273. char filenametemp[50];
  9274. while(i < ftppathlen)
  9275. {
  9276. int len=ftppathlen-i;
  9277. if(ftpbuf[len]== 47) // '/' ascll code: 47
  9278. {
  9279. DEBUG_INFO(" compare '/' all right\n");
  9280. break;
  9281. }
  9282. i=i+1;
  9283. }
  9284. memset(filenametemp, 0, sizeof(filenametemp));
  9285. strncpy(filenametemp, ftpbuf+(ftppathlen-i+1), i+1);
  9286. filenametemp[i+1] = 0;
  9287. strncpy(temp, ftpbuf, ftppathlen-i+1);
  9288. pch=strchr(temp,'@');
  9289. if(pch==NULL)
  9290. {
  9291. sscanf(temp,"%[^:]:%*2[/]%[^:]:%i/%[a-zA-Z0-9._/-]",
  9292. protocol, host, &port, path);
  9293. strcpy(user,"anonymous");
  9294. strcpy(password,"");
  9295. }
  9296. else
  9297. {
  9298. sscanf(temp,"%[^:]:%*2[/]%[^:]:%[^@]@%[^:]:%i/%199[^\n]",
  9299. protocol, user, password, host, &port, path);
  9300. }
  9301. sscanf(host,"%[^/]%s",host1, path1);
  9302. sprintf(ftppath,"%s", path1);
  9303. //DEBUG_INFO("protocol =%s\n",protocol);
  9304. //DEBUG_INFO("user =%s\n",user);
  9305. //DEBUG_INFO("password =%s\n",password);
  9306. //DEBUG_INFO("host1 =%s\n",host1);
  9307. //DEBUG_INFO("port =%d\n",port);
  9308. //DEBUG_INFO("path1 =%s\n",path1);
  9309. //DEBUG_INFO("ftppath=%s\n",ftppath);
  9310. //ftpFile(host, user, password, port, ftppath, fname);
  9311. //download firmware pthred
  9312. if(port == 0)
  9313. {
  9314. port = 21;
  9315. }
  9316. //sendFirmwareStatusNotificationRequest(FirmwareStatusStr[FirmwareStatus_Downloading]);
  9317. do{
  9318. isSuccess = ftpDownLoadFile(host1, user, password, port, ftppath, filenametemp, locationstr);
  9319. sleep(retryIntervalInt);
  9320. }while((!isSuccess)&&(retriesInt > 0 && retriesInt --));
  9321. if(!isSuccess)
  9322. {
  9323. //BulldogUtil.sleepMs(interval*1000);
  9324. DEBUG_INFO("Update firmware request and download file fail.\n");
  9325. sendFirmwareStatusNotificationRequest(FirmwareStatusStr[FirmwareStatus_DownloadFailed]);
  9326. }
  9327. else
  9328. {
  9329. //ShmOCPP16Data->MsMsg.bits.UpdateFirmwareReq = 1;
  9330. sendFirmwareStatusNotificationRequest(FirmwareStatusStr[FirmwareStatus_Downloaded]);
  9331. //isUpdateRequest = TRUE;
  9332. }
  9333. ShmOCPP16Data->MsMsg.bits.UpdateFirmwareReq = 1;
  9334. }
  9335. else
  9336. {
  9337. sendFirmwareStatusNotificationRequest(FirmwareStatusStr[FirmwareStatus_DownloadFailed]);
  9338. //ShmOCPP16Data->MsMsg.bits.UpdateFirmwareReq = 1;
  9339. }
  9340. pthread_exit(NULL);
  9341. }
  9342. //==========================================
  9343. // Handle server response routine
  9344. //==========================================
  9345. void handleAuthorizeResponse(char *payload, int gun_index)
  9346. {
  9347. mtrace();
  9348. char expiryDatestr[30]={0};
  9349. char parentIdTagstr[20]={0};
  9350. char statusstr[20]={0};
  9351. char expiryDatestrtemp[30]={0};
  9352. char parentIdTagstrtemp[20]={0};
  9353. char IdTagstrtemp[20]={0};
  9354. char statusstrtemp[20]={0};
  9355. int expiryDateISNULL=FALSE;
  9356. int parentIdTagISNULL=FALSE;
  9357. char sstr[160]={0};
  9358. char* filename = AuthorizationCache_JSON;
  9359. char tempfile[] = "/Storage/OCPP/Authorizetemp.json";
  9360. char *loc;
  9361. int resultRename=0;
  9362. int responseIdTagInfoAsZero= 0;
  9363. char rmFileCmd[50]={0};
  9364. DEBUG_INFO("handleAuthorizeResponse...\n");
  9365. json_object *Authorize;
  9366. Authorize = json_tokener_parse(payload);
  9367. if(!is_error(Authorize))
  9368. {
  9369. if(json_object_object_get(Authorize, "idTagInfo") != NULL)
  9370. {
  9371. // Required data
  9372. sprintf((char *)statusstr, "%s", json_object_get_string(json_object_object_get(json_object_object_get(Authorize,"idTagInfo"), "status")));
  9373. // Optional data
  9374. if(json_object_object_get(json_object_object_get(Authorize,"idTagInfo"), "expiryDate") != NULL)
  9375. sprintf((char *)expiryDatestr, "%s", json_object_get_string(json_object_object_get(json_object_object_get(Authorize,"idTagInfo"), "expiryDate")));
  9376. if(json_object_object_get(json_object_object_get(Authorize,"idTagInfo"), "parentIdTag") != NULL)
  9377. sprintf((char *)parentIdTagstr, "%s", json_object_get_string(json_object_object_get(json_object_object_get(Authorize,"idTagInfo"), "parentIdTag")));
  9378. }
  9379. }
  9380. json_object_put(Authorize);
  9381. if(expiryDateISNULL == FALSE)
  9382. strcpy((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.ExpiryDate, expiryDatestr);
  9383. if(parentIdTagISNULL == FALSE)
  9384. strcpy((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.ParentIdTag, parentIdTagstr);
  9385. strcpy((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.Status, statusstr);
  9386. //Update idTag information to authorization cache if supproted
  9387. if((strcmp((const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemData, "TRUE") == 0) && (ShmOCPP16Data->Authorize.ResponseIdTagInfo.ParentIdTag != NULL) && (ShmOCPP16Data->Authorize.ResponseIdTagInfo.ExpiryDate != NULL) )
  9388. {
  9389. if((access(filename,F_OK))!=-1)
  9390. {
  9391. printf("AuthorizationCache exist.\n");
  9392. }
  9393. else
  9394. {
  9395. printf("AuthorizationCache not exist\n");
  9396. FILE *log = fopen(filename, "w+");
  9397. if(log == NULL)
  9398. {
  9399. printf("log is NULL\n");
  9400. goto out;
  9401. }
  9402. else
  9403. {
  9404. fclose(log);
  9405. }
  9406. }
  9407. FILE *infile;
  9408. FILE *outfile;
  9409. // open file for writing
  9410. infile = fopen (filename, "r");
  9411. outfile = fopen (tempfile, "w");
  9412. int c;
  9413. c = fgetc(infile);
  9414. //DEBUG_INFO("c:%d\n",c);
  9415. rewind(infile);
  9416. if(c == EOF)
  9417. {
  9418. DEBUG_INFO("Orignal File is NULL\n");
  9419. if(ShmOCPP16Data->Authorize.ResponseIdTagInfo.ExpiryDate != NULL)
  9420. {
  9421. strcpy(expiryDatestrtemp, (const char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.ExpiryDate);
  9422. }
  9423. else
  9424. {
  9425. strcpy(expiryDatestrtemp, "");
  9426. }
  9427. if(ShmOCPP16Data->Authorize.ResponseIdTagInfo.ParentIdTag != NULL)
  9428. {
  9429. strcpy(parentIdTagstrtemp, (const char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.ParentIdTag);
  9430. }
  9431. else
  9432. {
  9433. strcpy(parentIdTagstrtemp, (const char *)ShmOCPP16Data->Authorize.IdTag);
  9434. }
  9435. strcpy(statusstrtemp, (const char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.Status);
  9436. fprintf(outfile,"[{\"idTag\":\"%s\",\"idTagInfo\":{\"expiryDate\":\"%s\",\"parentIdTag\":\"%s\",\"status\":\"%s\"}}]\n",ShmOCPP16Data->Authorize.IdTag, expiryDatestrtemp, parentIdTagstrtemp, statusstrtemp);
  9437. fclose(infile);
  9438. fclose(outfile);
  9439. sprintf(rmFileCmd,"rm -f %s",filename);
  9440. system(rmFileCmd);
  9441. resultRename = rename(tempfile, filename);
  9442. if(resultRename == 0)
  9443. {
  9444. printf("File renamed successfully");
  9445. }
  9446. else
  9447. {
  9448. printf("Error: unable to rename the file");
  9449. }
  9450. }
  9451. else
  9452. {
  9453. char buf[160]={0};
  9454. while (fgets(buf, sizeof(buf), infile) != NULL)
  9455. {
  9456. buf[strlen(buf) - 1] = '\0'; // eat the newline fgets() stores
  9457. memset(expiryDatestr, 0, sizeof(expiryDatestrtemp));
  9458. memset(parentIdTagstr,0, sizeof(parentIdTagstrtemp));
  9459. memset(statusstr, 0, sizeof(statusstrtemp));
  9460. memset(IdTagstrtemp, 0, sizeof(IdTagstrtemp));
  9461. memset(expiryDatestrtemp, 0, sizeof(expiryDatestrtemp));
  9462. memset(parentIdTagstrtemp, 0, sizeof(parentIdTagstrtemp));
  9463. memset(statusstrtemp, 0, sizeof(statusstrtemp));
  9464. //------------------IdTag-----------------------
  9465. loc = strstr(buf, "idTag");
  9466. memset(sstr ,0, sizeof(sstr) );
  9467. c = 0;
  9468. while (loc[3+strlen("idTag")+c] != '\"')
  9469. {
  9470. sstr[c] = loc[3+strlen("idTag")+c];
  9471. c++;
  9472. }
  9473. sstr[c] = '\0';
  9474. strcpy(IdTagstrtemp,sstr);
  9475. //*********************expiryDate***************/
  9476. loc = strstr(buf, "expiryDate");
  9477. memset(sstr ,0, sizeof(sstr) );
  9478. c = 0;
  9479. while (loc[3+strlen("expiryDate")+c] != '\"')
  9480. {
  9481. sstr[c] = loc[3+strlen("expiryDate")+c];
  9482. c++;
  9483. }
  9484. sstr[c] = '\0';
  9485. strcpy(expiryDatestr,sstr);
  9486. //*********************parentIdTag***************/
  9487. loc = strstr(buf, "parentIdTag");
  9488. memset(sstr ,0, sizeof(sstr) );
  9489. c = 0;
  9490. while (loc[3+strlen("parentIdTag")+c] != '\"')
  9491. {
  9492. sstr[c] = loc[3+strlen("parentIdTag")+c];
  9493. c++;
  9494. }
  9495. sstr[c] = '\0';
  9496. strcpy(parentIdTagstr,sstr);
  9497. //*********************status***************/
  9498. loc = strstr(buf, "status");
  9499. memset(sstr ,0, sizeof(sstr) );
  9500. c = 0;
  9501. while (loc[3+strlen("status")+c] != '\"')
  9502. {
  9503. sstr[c] = loc[3+strlen("status")+c];
  9504. c++;
  9505. }
  9506. sstr[c] = '\0';
  9507. strcpy(statusstr,sstr);
  9508. if(((ShmOCPP16Data->Authorize.ResponseIdTagInfo.ParentIdTag == NULL) || strcmp((const char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.ParentIdTag, "") == 0) || (strcmp((const char *)ShmOCPP16Data->Authorize.IdTag, IdTagstrtemp) == 0))
  9509. {
  9510. DEBUG_INFO("ShmOCPP16Data->Authorize.ResponseIdTagInfo.ParentIdTag is NULL\n");
  9511. responseIdTagInfoAsZero = 1;
  9512. }
  9513. else
  9514. {
  9515. DEBUG_INFO("ShmOCPP16Data->Authorize.ResponseIdTagInfo.ParentIdTag=%s\n",ShmOCPP16Data->Authorize.ResponseIdTagInfo.ParentIdTag);
  9516. }
  9517. if((responseIdTagInfoAsZero == 0)&&((strcmp(parentIdTagstr,(const char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.ParentIdTag) == 0)|| (strcmp(IdTagstrtemp,(const char *)ShmOCPP16Data->Authorize.IdTag) == 0)))
  9518. {
  9519. //modify item
  9520. if(ShmOCPP16Data->Authorize.ResponseIdTagInfo.ExpiryDate != NULL)
  9521. {
  9522. strcpy(expiryDatestrtemp,(const char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.ExpiryDate);
  9523. }
  9524. else
  9525. {
  9526. strcpy(expiryDatestrtemp, "");
  9527. }
  9528. if(ShmOCPP16Data->Authorize.ResponseIdTagInfo.ParentIdTag != NULL)
  9529. {
  9530. strcpy(parentIdTagstrtemp,(const char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.ParentIdTag);
  9531. }
  9532. else
  9533. {
  9534. strcpy(parentIdTagstrtemp, parentIdTagstr);
  9535. }
  9536. strcpy(statusstrtemp,(const char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.Status);
  9537. }
  9538. else
  9539. {
  9540. //wrie original item
  9541. strcpy(expiryDatestrtemp, expiryDatestr);
  9542. strcpy(parentIdTagstrtemp, parentIdTagstr);
  9543. strcpy(statusstrtemp, statusstr);
  9544. }
  9545. fprintf(outfile,"[{\"idTag\":\"%s\",\"idTagInfo\":{\"expiryDate\":\"%s\",\"parentIdTag\":\"%s\",\"status\":\"%s\"}}]\n",ShmOCPP16Data->Authorize.IdTag, expiryDatestrtemp, parentIdTagstrtemp, statusstrtemp);
  9546. }
  9547. fclose(infile);
  9548. fclose(outfile);
  9549. sprintf(rmFileCmd,"rm -f %s",filename);
  9550. system(rmFileCmd);
  9551. resultRename = rename(tempfile, filename);
  9552. if(resultRename == 0)
  9553. {
  9554. DEBUG_INFO("File renamed successfully");
  9555. }
  9556. else
  9557. {
  9558. DEBUG_INFO("Error: unable to rename the file");
  9559. }
  9560. }
  9561. }
  9562. out:
  9563. ShmOCPP16Data->SpMsg.bits.AuthorizeReq = 0;
  9564. ShmOCPP16Data->SpMsg.bits.AuthorizeConf = 1; // inform csu
  9565. authorizeRetryTimes = 0;
  9566. }
  9567. char * strtrimc( char * s )
  9568. {
  9569. char * p1 = s;
  9570. char * p2 = s;
  9571. while(*p1 != '\0')
  9572. {
  9573. while(*p1 == ' ' || *p1 == '\t' || *p1 == '\"' || *p1 == '\n' || *p1 == '}' || *p1 == '\r')
  9574. {
  9575. if(*p1 != ',')
  9576. {
  9577. p1 ++;
  9578. }
  9579. else
  9580. {
  9581. break;
  9582. }
  9583. }
  9584. if(*p1 != ',')
  9585. {
  9586. * p2 ++ = *p1 ++;
  9587. //printf("p2=%s\n",p2);
  9588. }
  9589. else
  9590. {
  9591. break;
  9592. }
  9593. }
  9594. *p2 = '\0';
  9595. return (s);
  9596. }
  9597. void handleBootNotificationResponse(char *payload, int gun_index)
  9598. {
  9599. mtrace();
  9600. char statusStr[12]={0};
  9601. char currentTimeStr[30]={0};
  9602. int intervalInt = 0;
  9603. struct tm tp;
  9604. char buf[28]={0};
  9605. char timebuf[50]={0};
  9606. DEBUG_INFO("handleBootNotificationResponse...\n");
  9607. json_object *BootNotification;
  9608. BootNotification = json_tokener_parse(payload);
  9609. if(!is_error(BootNotification))
  9610. {
  9611. // Required data
  9612. sprintf((char *)currentTimeStr, "%s", json_object_get_string(json_object_object_get(BootNotification,"currentTime")));
  9613. intervalInt = json_object_get_int(json_object_object_get(BootNotification,"interval"));
  9614. sprintf((char *)statusStr, "%s", json_object_get_string(json_object_object_get(BootNotification,"status")));
  9615. }
  9616. json_object_put(BootNotification);
  9617. ShmOCPP16Data->BootNotification.ResponseHeartbeatInterval = intervalInt;
  9618. BootNotificationInterval = intervalInt;
  9619. HeartBeatWaitTime = intervalInt;
  9620. //write back to ShmOCPP16Data->BootNotification
  9621. strcpy((char *)ShmOCPP16Data->BootNotification.ResponseCurrentTime, currentTimeStr);
  9622. ShmOCPP16Data->BootNotification.ResponseHeartbeatInterval = intervalInt;
  9623. strcpy((char *)ShmOCPP16Data->BootNotification.ResponseStatus, statusStr);
  9624. if((strcmp(statusStr, RegistrationStatusStr[RegistrationStatus_Accepted]) == 0 ))
  9625. {
  9626. server_sign = TRUE;
  9627. server_pending =FALSE;
  9628. }
  9629. else if(strcmp(statusStr, RegistrationStatusStr[RegistrationStatus_Pending]) == 0)
  9630. {
  9631. server_pending = TRUE;
  9632. }
  9633. strptime((const char *)ShmOCPP16Data->BootNotification.ResponseCurrentTime, "%Y-%m-%dT%H:%M:%S", &tp);
  9634. tp.tm_isdst = -1;
  9635. //time_t utc = mktime(&tp);
  9636. strftime(buf, 28, "%Y-%m-%d %H:%M:%S", &tp);
  9637. memset(timebuf, 0, sizeof timebuf);
  9638. sprintf(timebuf,"date -s '%s'",buf);
  9639. system(timebuf);
  9640. clientTime.Heartbeat = time((time_t*)NULL) - (ShmOCPP16Data->BootNotification.ResponseHeartbeatInterval-5);
  9641. //==============================================
  9642. // RTC sync
  9643. //==============================================
  9644. system("/sbin/hwclock -w --systohc");
  9645. ShmOCPP16Data->OcppConnStatus = 1; ////0: disconnected, 1: connected
  9646. ShmOCPP16Data->SpMsg.bits.BootNotificationConf = 1;
  9647. sendFirmwareVersionByDataTransfer();
  9648. }
  9649. void handleDataTransferResponse(char *payload, int gun_index)
  9650. {
  9651. char sstr[160]={0};//sstr[200]={ 0 };
  9652. int c = 0;
  9653. char *loc;
  9654. DEBUG_INFO("handleDataTransferResponse ...\n");
  9655. loc = strstr(payload, "status");
  9656. printf("loc=%s\n",loc);
  9657. c = 0;
  9658. while (loc[3+strlen("status")+c] != '\"')
  9659. {
  9660. sstr[c] = loc[3+strlen("status")+c];
  9661. //printf("i=%d sstr=%c\n",c, sstr[c]);
  9662. c++;
  9663. }
  9664. sstr[c] = '\0';
  9665. DEBUG_INFO(" DataTransferResponse=%s\n", sstr);
  9666. }
  9667. void handleDiagnosticsStatusNotificationResponse(char *payload, int gun_index)
  9668. {
  9669. DEBUG_INFO("handleDiagnosticsStatusNotificationResponse ...\n");
  9670. //struct json_object *obj;
  9671. // obj = json_tokener_parse(payload);
  9672. ShmOCPP16Data->SpMsg.bits.DiagnosticsStatusNotificationReq = 0;
  9673. ShmOCPP16Data->SpMsg.bits.DiagnosticsStatusNotificationConf = 1;
  9674. //No fields are defined.
  9675. }
  9676. void handleFirmwareStatusNotificationResponse(char *payload, int gun_index)
  9677. {
  9678. DEBUG_INFO("handleFirmwareStatusNotificationResponse ...\n");
  9679. //struct json_object *obj;
  9680. // obj = json_tokener_parse(payload);
  9681. ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationReq = 0;
  9682. ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationConf = 1;
  9683. //No fields are defined.
  9684. }
  9685. void handleHeartbeatResponse(char *payload, int gun_index)
  9686. {
  9687. mtrace();
  9688. struct tm tp;
  9689. char buf[28]={0};
  9690. char timebuf[50]={0};
  9691. DEBUG_INFO("handleHeartbeatResponse...\n");
  9692. json_object *Heartbeat;
  9693. Heartbeat = json_tokener_parse(payload);
  9694. if(!is_error(Heartbeat))
  9695. {
  9696. // Required data
  9697. sprintf((char *)ShmOCPP16Data->Heartbeat.ResponseCurrentTime, "%s", json_object_get_string(json_object_object_get(Heartbeat,"currentTime")));
  9698. }
  9699. json_object_put(BootNotification);
  9700. if(FirstHeartBeat == 0)
  9701. {
  9702. FirstHeartBeat = 1;
  9703. DEBUG_INFO("FirstHeartBeat \n");
  9704. }
  9705. HeartBeatWithNOResponse = 0;
  9706. strptime((const char *)ShmOCPP16Data->Heartbeat.ResponseCurrentTime, "%Y-%m-%dT%H:%M:%S", &tp);
  9707. tp.tm_isdst = -1;
  9708. //time_t utc = mktime(&tp);
  9709. strftime(buf, 28, "%Y-%m-%d %H:%M:%S", &tp);
  9710. memset(timebuf, 0, sizeof timebuf);
  9711. sprintf(timebuf,"date -s '%s'",buf);
  9712. system(timebuf);
  9713. //==============================================
  9714. // RTC sync
  9715. //==============================================
  9716. system("/sbin/hwclock -w --systohc");
  9717. //===============================================
  9718. //Print Out HeartBeat log
  9719. //===============================================
  9720. {
  9721. double diff_t;
  9722. struct tm tp,tp1;
  9723. // BootNotification Receive Time
  9724. strptime((const char *)ShmOCPP16Data->BootNotification.ResponseCurrentTime, "%Y-%m-%dT%H:%M:%S", &tp);
  9725. tp.tm_isdst = -1;
  9726. time_t BootNotificationReceiveTime = mktime(&tp);
  9727. //HeartBeat Receive Time
  9728. strptime((const char *)ShmOCPP16Data->Heartbeat.ResponseCurrentTime, "%Y-%m-%dT%H:%M:%S", &tp1);
  9729. tp1.tm_isdst = -1;
  9730. time_t HeartBeatReceiveTime = mktime(&tp1);
  9731. diff_t = difftime(HeartBeatReceiveTime, BootNotificationReceiveTime);
  9732. printf("handleHeartbeatResponse differnt time=%f..\n",diff_t);
  9733. if(((int)diff_t / 3600) > HeartBeatCountPerHour)
  9734. {
  9735. HeartBeatCountPerHour = (int)diff_t / 3600;
  9736. DEBUG_INFO("handleHeartbeatResponse ...\n");
  9737. DEBUG_INFO("After 1 hour, It will print out Heartbeat.\n");
  9738. }
  9739. }
  9740. }
  9741. void handleMeterValuesResponse(char *payload, int gun_index)
  9742. {
  9743. mtrace();
  9744. DEBUG_INFO("handleMeterValuesResponse...\n");
  9745. }
  9746. void handleStartTransactionResponse(char *payload, int gun_index)
  9747. {
  9748. mtrace();
  9749. //int transactionIdInt = 0;
  9750. FILE *outfile;
  9751. char data[100]={0};
  9752. DEBUG_INFO("handleStartTransactionResponse...\n");
  9753. json_object *StartTransaction;
  9754. StartTransaction = json_tokener_parse(payload);
  9755. if(!is_error(StartTransaction))
  9756. {
  9757. // Required data
  9758. sprintf((char *)ShmOCPP16Data->StartTransaction[gun_index].ResponseIdTagInfo.Status, "%s", json_object_get_string(json_object_object_get(json_object_object_get(StartTransaction,"idTagInfo"), "status")));
  9759. ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId = json_object_get_int(json_object_object_get(StartTransaction,"transactionId"));
  9760. // Optional data
  9761. if(json_object_object_get(json_object_object_get(StartTransaction,"idTagInfo"), "expiryDate") != NULL)
  9762. sprintf((char *)ShmOCPP16Data->StartTransaction[gun_index].ResponseIdTagInfo.ExpiryDate, "%s", json_object_get_string(json_object_object_get(json_object_object_get(StartTransaction,"idTagInfo"), "expiryDate")));
  9763. if(json_object_object_get(json_object_object_get(StartTransaction,"idTagInfo"), "parentIdTag") != NULL)
  9764. sprintf((char *)ShmOCPP16Data->StartTransaction[gun_index].ResponseIdTagInfo.ParentIdTag, "%s", json_object_get_string(json_object_object_get(json_object_object_get(StartTransaction,"idTagInfo"), "parentIdTag")));
  9765. }
  9766. json_object_put(StartTransaction);
  9767. ShmOCPP16Data->CpMsg.bits[gun_index].StartTransactionConf = 1;
  9768. ShmOCPP16Data->CpMsg.bits[gun_index].StartTransactionReq = 0;
  9769. //-----------Start : write to the Queue TransactionId file -----------------//
  9770. if((access("/Storage/OCPP/QueueTransactionId",F_OK))!=-1)
  9771. {}
  9772. else
  9773. {
  9774. FILE *log = fopen("/Storage/OCPP/QueueTransactionId", "w+");
  9775. if(log == NULL)
  9776. {
  9777. DEBUG_INFO("Can't Create File QueueTransactionId \n");
  9778. return ;
  9779. }
  9780. else
  9781. {
  9782. fclose(log);
  9783. }
  9784. }
  9785. // open file for writing
  9786. //-------------Start: write to the Queue TransactionId file------------------------------------------//
  9787. if((ShmOCPP16Data->StartTransaction[gun_index].ConnectorId !=0)&&(strcmp((const char *)ShmOCPP16Data->StartTransaction[gun_index].IdTag,"")!=0)&&(ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId !=0))
  9788. {
  9789. outfile = fopen ("/Storage/OCPP/QueueTransactionId", "a");
  9790. sprintf(data,"%d,%s,%d\n", ShmOCPP16Data->StartTransaction[gun_index].ConnectorId , ShmOCPP16Data->StartTransaction[gun_index].IdTag, ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId); // GunIndex, idtag, TransactionId
  9791. fputs(data, outfile);
  9792. fclose (outfile);
  9793. }
  9794. DEBUG_INFO("idTagInfo-expiryDate: %s\n", ShmOCPP16Data->StartTransaction[gun_index].ResponseIdTagInfo.ExpiryDate);
  9795. DEBUG_INFO("idTagInfo-parentIdTag: %s\n", ShmOCPP16Data->StartTransaction[gun_index].ResponseIdTagInfo.ParentIdTag);
  9796. DEBUG_INFO("idTagInfo-status: %s\n", ShmOCPP16Data->StartTransaction[gun_index].ResponseIdTagInfo.Status);
  9797. DEBUG_INFO("transactionId: %d\n", ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId);
  9798. }
  9799. void handleStatusNotificationResponse(char *payload, int gun_index)
  9800. {
  9801. mtrace();
  9802. DEBUG_INFO("handleStatusNotificationResponse...\n");
  9803. cpinitateMsg.bits[gun_index].StatusNotificationReq = 0;
  9804. cpinitateMsg.bits[gun_index].StatusNotificationConf = 1;
  9805. }
  9806. void handleStopTransactionnResponse(char *payload, int gun_index)
  9807. {
  9808. mtrace();
  9809. DEBUG_INFO("handleStopTransactionnResponse...\n");
  9810. json_object *StopTransaction;
  9811. StopTransaction = json_tokener_parse(payload);
  9812. if(!is_error(StopTransaction))
  9813. {
  9814. // Optional data
  9815. if(json_object_object_get(StopTransaction, "idTagInfo") != NULL)
  9816. {
  9817. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].ResponseIdTagInfo.Status, "%s", json_object_get_string(json_object_object_get(json_object_object_get(StopTransaction,"idTagInfo"), "status")));
  9818. if(json_object_object_get(json_object_object_get(StopTransaction,"idTagInfo"), "expiryDate") != NULL)
  9819. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].ResponseIdTagInfo.ExpiryDate, "%s", json_object_get_string(json_object_object_get(json_object_object_get(StopTransaction,"idTagInfo"), "expiryDate")));
  9820. if(json_object_object_get(json_object_object_get(StopTransaction,"idTagInfo"), "parentIdTag") != NULL)
  9821. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].ResponseIdTagInfo.ParentIdTag, "%s", json_object_get_string(json_object_object_get(json_object_object_get(StopTransaction,"idTagInfo"), "parentIdTag")));
  9822. }
  9823. }
  9824. json_object_put(StopTransaction);
  9825. ShmOCPP16Data->CpMsg.bits[gun_index].StopTransactionConf = 1;
  9826. ShmOCPP16Data->CpMsg.bits[gun_index].StopTransactionReq = 0;
  9827. DEBUG_INFO("idTagInfo-expiryDate: %s\n", ShmOCPP16Data->StopTransaction[gun_index].ResponseIdTagInfo.ExpiryDate);
  9828. DEBUG_INFO("idTagInfo-parentIdTag: %s\n", ShmOCPP16Data->StopTransaction[gun_index].ResponseIdTagInfo.ParentIdTag);
  9829. DEBUG_INFO("idTagInfo-status: %s\n", ShmOCPP16Data->StopTransaction[gun_index].ResponseIdTagInfo.Status);
  9830. }
  9831. //==========================================
  9832. // Handle Error routine
  9833. //==========================================
  9834. void handleError(char *id, char *errorCode, char *errorDescription,char *payload)
  9835. {
  9836. mtrace();
  9837. #ifdef SystemLogMessage
  9838. DEBUG_INFO("errorCode: %s\n", errorCode);
  9839. DEBUG_INFO("errorDescription: %s\n", errorDescription);
  9840. DEBUG_INFO("errorDetails: %s\n", payload);
  9841. #endif
  9842. }
  9843. //===============================================
  9844. // Common routine
  9845. //===============================================
  9846. int initialConfigurationTable(void)
  9847. {
  9848. //clock_t start_t, end_t, total_t;
  9849. FILE *fp;
  9850. FILE *outfile;
  9851. char str[200]={0};
  9852. char sstr[100]={0};
  9853. int c = 0;
  9854. char *loc;
  9855. DEBUG_INFO("initialConfigurationTable...\n");
  9856. //start_t = clock();
  9857. //printf("Starting of the program, start_t = %ld\n", start_t);
  9858. memset(&(ShmOCPP16Data->ConfigurationTable), 0, sizeof(struct OCPP16ConfigurationTable) );
  9859. if((access("/Storage/OCPP/OCPPConfiguration",F_OK))==-1)
  9860. {
  9861. outfile = fopen("/Storage/OCPP/OCPPConfiguration" , "w+");
  9862. if(outfile == NULL)
  9863. {
  9864. DEBUG_INFO("Error opening file\n");
  9865. return FALSE;
  9866. }
  9867. /*Core Profile*/
  9868. //AllowOfflineTxForUnknownId
  9869. ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemAccessibility = 1;
  9870. printf("AllowoddlineTXForUnknownId type: %d \n", ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemAccessibility);
  9871. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemName, "AllowOfflineTxForUnknownId");
  9872. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemData, "FALSE" );
  9873. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","AllowOfflineTxForUnknownId", "false", "FALSE");
  9874. //AuthorizationCacheEnabled
  9875. ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemAccessibility = 1;
  9876. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemName, "AuthorizationCacheEnabled");
  9877. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemData, "FALSE" );
  9878. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","AuthorizationCacheEnabled", "false", "FALSE");
  9879. //AuthorizeRemoteTxRequests
  9880. ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemAccessibility = 0;
  9881. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemName, "AuthorizeRemoteTxRequests");
  9882. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemData, "FALSE" );
  9883. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","AuthorizeRemoteTxRequests", "true", "FALSE");
  9884. //BlinkRepeat
  9885. ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemAccessibility = 1;
  9886. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemName, "BlinkRepeat");
  9887. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemData, "0" );
  9888. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","BlinkRepeat", "false", "0");
  9889. //ClockAlignedDataInterval
  9890. ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemAccessibility = 1;
  9891. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemName, "ClockAlignedDataInterval");
  9892. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemData, "0" );
  9893. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ClockAlignedDataInterval", "false", "0");
  9894. //ConnectionTimeOut
  9895. ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemAccessibility = 1;
  9896. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemName, "ConnectionTimeOut");
  9897. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemData, "180" );
  9898. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ConnectionTimeOut", "false", "180");
  9899. //GetConfigurationMaxKeys
  9900. ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemAccessibility =0;
  9901. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemName, "GetConfigurationMaxKeys");
  9902. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemData, "43" );
  9903. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","GetConfigurationMaxKeys", "true", "43");
  9904. // HeartbeatInterval
  9905. ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemAccessibility = 1;
  9906. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemName, "HeartbeatInterval");
  9907. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemData, "10" );
  9908. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","HeartbeatInterval", "false", "10");
  9909. // LightIntensity
  9910. ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemAccessibility = 1;
  9911. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemName, "LightIntensity");
  9912. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemData, "0" );
  9913. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LightIntensity", "false", "0");
  9914. // LocalAuthorizeOffline
  9915. ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemAccessibility = 0;
  9916. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemName, "LocalAuthorizeOffline");
  9917. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemData, "TRUE" );
  9918. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LocalAuthorizeOffline", "true", "TRUE");
  9919. // LocalPreAuthorize
  9920. ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemAccessibility = 0;
  9921. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemName, "LocalPreAuthorize");
  9922. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemData, "FALSE" );
  9923. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LocalPreAuthorize", "true", "FALSE");
  9924. // MaxEnergyOnInvalidId
  9925. ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemAccessibility = 1;
  9926. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemName, "MaxEnergyOnInvalidId");
  9927. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemData, "0" );
  9928. ShmSysConfigAndInfo->SysConfig.OfflineMaxChargeEnergy = 0;
  9929. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MaxEnergyOnInvalidId", "false", "0");
  9930. // MeterValuesAlignedData
  9931. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemAccessibility = 0;
  9932. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemName, "MeterValuesAlignedData");
  9933. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, "" );
  9934. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValuesAlignedData", "true", "");
  9935. // MeterValuesAlignedDataMaxLength
  9936. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemAccessibility = 0;
  9937. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemName, "MeterValuesAlignedDataMaxLength");
  9938. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemData, "5" );
  9939. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValuesAlignedDataMaxLength", "true", "5");
  9940. // MeterValuesSampledData
  9941. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemAccessibility = 0;
  9942. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemName, "MeterValuesSampledData");
  9943. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, "Current.Import,Energy.Active.Import.Register,Energy.Active.Import.Interval,Power.Active.Import,Voltage,SOC" );
  9944. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValuesSampledData", "true", "Current.Import,Energy.Active.Import.Register,Energy.Active.Import.Interval,Power.Active.Import,Voltage,SOC");
  9945. // MeterValuesSampledDataMaxLength
  9946. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemAccessibility = 0;
  9947. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemName, "MeterValuesSampledDataMaxLength");
  9948. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemData, "6" );
  9949. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValuesSampledDataMaxLength", "true", "6");
  9950. // MeterValueSampleInterval
  9951. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemAccessibility = 1;
  9952. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemName, "MeterValueSampleInterval");
  9953. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemData, "10" );
  9954. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValueSampleInterval", "false", "10");
  9955. // MinimumStatusDuration
  9956. ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemAccessibility = 1;
  9957. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemName, "MinimumStatusDuration");
  9958. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemData, "120" );
  9959. server_cycle_Status = 120; //StatusNotification cycle
  9960. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MinimumStatusDuration", "false", "120");
  9961. // NumberOfConnectors
  9962. ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemAccessibility = 0;
  9963. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemName, "NumberOfConnectors");
  9964. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  9965. {
  9966. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData, "%d", (CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY));
  9967. }
  9968. else
  9969. {
  9970. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData, "%d", AC_QUANTITY);
  9971. }
  9972. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","NumberOfConnectors", "true", ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData);
  9973. // ResetRetries
  9974. ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemAccessibility = 1;
  9975. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemName, "ResetRetries");
  9976. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemData, "3" );
  9977. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ResetRetries", "false", "3");
  9978. // ConnectorPhaseRotation
  9979. ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemAccessibility = 1;
  9980. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemName, "ConnectorPhaseRotation");
  9981. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "NotApplicable" );
  9982. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ConnectorPhaseRotation", "false", "NotApplicable");
  9983. // ConnectorPhaseRotationMaxLength
  9984. ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemAccessibility = 0;
  9985. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemName, "ConnectorPhaseRotationMaxLength");
  9986. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemData, "1" );
  9987. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ConnectorPhaseRotationMaxLength", "true", "1");
  9988. // StopTransactionOnEVSideDisconnect
  9989. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemAccessibility = 0;
  9990. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemName, "StopTransactionOnEVSideDisconnect");
  9991. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemData, "TRUE" );
  9992. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTransactionOnEVSideDisconnect", "true", "TRUE");
  9993. // StopTransactionOnInvalidId
  9994. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemAccessibility = 0; //1;
  9995. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemName, "StopTransactionOnInvalidId");
  9996. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemData, "FALSE" );
  9997. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTransactionOnInvalidId", "true", "FALSE");
  9998. // StopTxnAlignedData
  9999. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemAccessibility = 0;
  10000. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemName, "StopTxnAlignedData");
  10001. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemData, "Energy.Active.Import.Register" );
  10002. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTxnAlignedData", "true", "Energy.Active.Import.Register");
  10003. // StopTxnAlignedDataMaxLength
  10004. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemAccessibility = 0;
  10005. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemName, "StopTxnAlignedDataMaxLength");
  10006. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemData, "0" );
  10007. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTxnAlignedDataMaxLength", "true", "0");
  10008. // StopTxnSampledData
  10009. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemAccessibility = 0;
  10010. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemName, "StopTxnSampledData");
  10011. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Current.Import,Energy.Active.Import.Interval,Power.Active.Import,Voltage,SOC" );
  10012. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTxnSampledData", "true", "Current.Import,Energy.Active.Import.Interval,Power.Active.Import,Voltage,SOC");
  10013. // StopTxnSampledDataMaxLength
  10014. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemAccessibility = 0;
  10015. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemName, "StopTxnSampledDataMaxLength");
  10016. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  10017. {
  10018. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemData, "%d", 6);
  10019. }
  10020. else
  10021. {
  10022. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemData, "%d", 5);
  10023. }
  10024. //strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemData, "0" );
  10025. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTxnSampledDataMaxLength", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemData);
  10026. // SupportedFeatureProfiles
  10027. ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemAccessibility = 0;
  10028. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemName, "SupportedFeatureProfiles");
  10029. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemData, "Core,FirmwareManagement,LocalAuthListManagement,Reservation,SmartCharging,RemoteTrigger" );
  10030. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","SupportedFeatureProfiles", "true", "Core,FirmwareManagement,LocalAuthListManagement,Reservation,SmartCharging,RemoteTrigger");
  10031. // SupportedFeatureProfilesMaxLength
  10032. ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemAccessibility = 0;
  10033. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemName, "SupportedFeatureProfilesMaxLength");
  10034. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemData, "6" );
  10035. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","SupportedFeatureProfilesMaxLength", "true", "6");
  10036. // TransactionMessageAttempts
  10037. ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemAccessibility = 1;
  10038. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemName, "TransactionMessageAttempts");
  10039. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData, "3" );
  10040. TransactionMessageAttemptsValue = atoi((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData);
  10041. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","TransactionMessageAttempts", "false", "3");
  10042. // TransactionMessageRetryInterval
  10043. ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemAccessibility = 1;
  10044. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemName, "TransactionMessageRetryInterval");
  10045. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData, "60" );
  10046. TransactionMessageRetryIntervalValue = atoi((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData);
  10047. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","TransactionMessageRetryInterval", "false", "60");
  10048. // UnlockConnectorOnEVSideDisconnect
  10049. ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemAccessibility = 0;
  10050. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemName, "UnlockConnectorOnEVSideDisconnect");
  10051. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemData, "TRUE" );
  10052. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","UnlockConnectorOnEVSideDisconnect", "true", "TRUE");
  10053. // WebSocketPingInterval
  10054. ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemAccessibility = 1;
  10055. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemName, "WebSocketPingInterval");
  10056. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemData, "30" );
  10057. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","WebSocketPingInterval", "false", "30");
  10058. //* Local Auth List Management Profile*/
  10059. #if 0
  10060. //For OCTT Test Case
  10061. ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemAccessibility = 1;
  10062. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemName, "LocalAuthorizationListEnabled");
  10063. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "TRUE" );
  10064. #endif
  10065. #if 1
  10066. //LocalAuthListEnabled
  10067. ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemAccessibility = 1;
  10068. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemName, "LocalAuthListEnabled");
  10069. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "TRUE" );
  10070. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LocalAuthListEnabled", "false", "TRUE");
  10071. #endif
  10072. //LocalAuthListMaxLength
  10073. ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemAccessibility = 0;
  10074. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemName, "LocalAuthListMaxLength");
  10075. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemData, "500" );
  10076. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LocalAuthListMaxLength", "true", "500");
  10077. //SendLocalListMaxLength
  10078. ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemAccessibility = 0;
  10079. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemName, "SendLocalListMaxLength");
  10080. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemData, "500" );
  10081. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","SendLocalListMaxLength", "true", "500");
  10082. //ReserveConnectorZeroSupported
  10083. ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemAccessibility = 0;
  10084. strcpy((char *)ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemName, "ReserveConnectorZeroSupported");
  10085. strcpy((char *)ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemData, "FALSE" );
  10086. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ReserveConnectorZeroSupported", "true", "FALSE");
  10087. //* Smart Charging Profile */
  10088. //ChargeProfileMaxStackLevel
  10089. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemAccessibility = 0;
  10090. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemName, "ChargeProfileMaxStackLevel");
  10091. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemData, "3" );
  10092. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ChargeProfileMaxStackLevel", "true", "3");
  10093. // ChargingScheduleAllowedChargingRateUnit
  10094. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemAccessibility = 0;
  10095. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemName, "ChargingScheduleAllowedChargingRateUnit");
  10096. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemData, "Current" );
  10097. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ChargingScheduleAllowedChargingRateUnit", "true", "Current");
  10098. // ChargingScheduleMaxPeriods
  10099. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemAccessibility = 0;
  10100. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemName, "ChargingScheduleMaxPeriods");
  10101. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemData, "10" );
  10102. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ChargingScheduleMaxPeriods", "true", "10");
  10103. // ConnectorSwitch3to1PhaseSupported
  10104. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemAccessibility = 0;
  10105. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemName, "ConnectorSwitch3to1PhaseSupported");
  10106. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemData, "TRUE" );
  10107. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ConnectorSwitch3to1PhaseSupported", "true", "TRUE");
  10108. // MaxChargingProfilesInstalled
  10109. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemAccessibility = 0;
  10110. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemName, "MaxChargingProfilesInstalled");
  10111. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemData, "3" );
  10112. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MaxChargingProfilesInstalled", "true", "3");
  10113. fclose(outfile);
  10114. }
  10115. else
  10116. {
  10117. //DEBUG_INFO("../Storage/OCPP/OCPPConfiguration EXit\n");
  10118. char keystr[60]={0};
  10119. char readonlystr[10]={0};
  10120. char valuestr[100]={0};
  10121. fp = fopen("/Storage/OCPP/OCPPConfiguration" , "r");
  10122. if(fp == NULL) {
  10123. DEBUG_INFO("Error opening file");
  10124. return FALSE;
  10125. }
  10126. while( fgets (str, sizeof(str), fp)!=NULL )
  10127. {
  10128. //DEBUG_INFO("Get Configuration \n");
  10129. str[strlen(str) - 1] = '\0'; // eat the newline fgets() stores
  10130. //*************************key*********************************/
  10131. loc = strstr(str, "key");
  10132. c = 0;
  10133. memset(sstr ,0, sizeof(sstr) );
  10134. while (loc[strlen("key")+3+c] != '\"')
  10135. {
  10136. sstr[c] = loc[strlen("key")+3+c];
  10137. c++;
  10138. }
  10139. sstr[c] = '\0';
  10140. strcpy(keystr,sstr);
  10141. //*************************readonly*********************************/
  10142. loc = strstr(str, "readonly");
  10143. c = 0;
  10144. memset(sstr ,0, sizeof(sstr) );
  10145. while (loc[strlen("readonly")+2+c] != ',')
  10146. {
  10147. sstr[c] = loc[strlen("readonly")+2+c];
  10148. c++;
  10149. }
  10150. sstr[c] = '\0';
  10151. strcpy(readonlystr,sstr);
  10152. //*************************value*********************************/
  10153. loc = strstr(str, "value");
  10154. c = 0;
  10155. memset(sstr ,0, sizeof(sstr) );
  10156. while (loc[strlen("value")+3+c] != '\"')
  10157. {
  10158. sstr[c] = loc[strlen("value")+3+c];
  10159. c++;
  10160. }
  10161. sstr[c] = '\0';
  10162. strcpy(valuestr,sstr);
  10163. // DEBUG_INFO("keystr=%s\n",keystr);
  10164. // DEBUG_INFO("readonlystr=%s\n",readonlystr);
  10165. // DEBUG_INFO("valuestr=%s\n",valuestr);
  10166. if(strcmp(keystr, "AllowOfflineTxForUnknownId") == 0)
  10167. {
  10168. //Charger.AllowOfflineTxForUnknownId = (value.toLowerCase().equals("true")?true:false);
  10169. ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10170. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemData, "%s", valuestr );
  10171. // DEBUG_INFO("AllowOfflineTxForUnknownId setting\n");
  10172. // DEBUG_INFO("AllowOfflineTxForUnknownId setting\n");
  10173. }
  10174. if(strcmp(keystr, "AuthorizationCacheEnabled") == 0)
  10175. {
  10176. //Charger.AuthorizationCacheEnabled = (value.toLowerCase().equals("true")?true:false);
  10177. ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10178. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemData, "%s", valuestr );
  10179. }
  10180. if(strcmp(keystr, "AuthorizeRemoteTxRequests") == 0)
  10181. {
  10182. ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10183. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemData, "%s", valuestr );
  10184. }
  10185. if(strcmp(keystr, "BlinkRepeat") == 0)
  10186. {
  10187. //Charger.BlinkRepeat = Integer.parseInt(value);
  10188. ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10189. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemData, "%d", atoi(valuestr) );
  10190. }
  10191. if(strcmp(keystr, "ClockAlignedDataInterval") == 0)
  10192. {
  10193. ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10194. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemData, "%d", atoi(valuestr) );
  10195. }
  10196. if(strcmp(keystr, "ConnectionTimeOut") == 0 )
  10197. {
  10198. ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10199. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemData, "%d", atoi(valuestr));
  10200. }
  10201. if(strcmp(keystr, "GetConfigurationMaxKeys") == 0)
  10202. {
  10203. ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10204. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemData, "%d", atoi(valuestr));
  10205. }
  10206. if(strcmp(keystr, "HeartbeatInterval") == 0)
  10207. {
  10208. ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10209. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemData, "%d", atoi(valuestr));
  10210. HeartBeatWaitTime = atoi(valuestr);
  10211. }
  10212. if(strcmp(keystr, "LightIntensity") == 0)
  10213. {
  10214. ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10215. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemData, "%d", atoi(valuestr));
  10216. }
  10217. if(strcmp(keystr, "LocalAuthorizeOffline") == 0)
  10218. {
  10219. ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10220. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemData, "%s", valuestr );
  10221. }
  10222. if(strcmp(keystr, "LocalPreAuthorize") == 0)
  10223. {
  10224. ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10225. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemData, "%s", valuestr );
  10226. }
  10227. if(strcmp(keystr, "MaxEnergyOnInvalidId") == 0)
  10228. {
  10229. ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10230. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemData, "%d", atoi(valuestr) );
  10231. ShmSysConfigAndInfo->SysConfig.OfflineMaxChargeEnergy = atoi(valuestr)/1000;
  10232. }
  10233. if(strcmp(keystr, "MeterValuesAlignedData") == 0)
  10234. {
  10235. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10236. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, "%s", valuestr );
  10237. }
  10238. if(strcmp(keystr, "MeterValuesAlignedDataMaxLength") == 0)
  10239. {
  10240. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10241. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemData, "%d", atoi(valuestr));
  10242. }
  10243. if(strcmp(keystr, "MeterValuesSampledData") == 0 )
  10244. {
  10245. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10246. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, "%s", valuestr );
  10247. }
  10248. if(strcmp(keystr, "MeterValuesSampledDataMaxLength") == 0)
  10249. {
  10250. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10251. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemData, "%d", atoi(valuestr));
  10252. }
  10253. if(strcmp(keystr, "MeterValueSampleInterval") == 0)
  10254. {
  10255. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10256. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemData, "%d", atoi(valuestr));
  10257. }
  10258. if(strcmp(keystr, "MinimumStatusDuration") == 0)
  10259. {
  10260. ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10261. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemData, "%d", atoi(valuestr) );
  10262. server_cycle_Status = atoi(valuestr); //StatusNotification cycle
  10263. }
  10264. if(strcmp(keystr, "NumberOfConnectors") == 0)
  10265. {
  10266. ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10267. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData, "%d", atoi(valuestr) );
  10268. }
  10269. if(strcmp(keystr, "ResetRetries") == 0)
  10270. {
  10271. ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10272. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemData, "%d", atoi(valuestr) );
  10273. }
  10274. if(strcmp(keystr, "ConnectorPhaseRotation") == 0)
  10275. {
  10276. ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10277. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "%s", valuestr );
  10278. }
  10279. if(strcmp(keystr, "ConnectorPhaseRotationMaxLength") == 0)
  10280. {
  10281. ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10282. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemData, "%d", atoi(valuestr) );
  10283. }
  10284. if(strcmp(keystr, "StopTransactionOnEVSideDisconnect") == 0)
  10285. {
  10286. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10287. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemData, "%s", valuestr );
  10288. }
  10289. if(strcmp(keystr, "StopTransactionOnInvalidId") == 0)
  10290. {
  10291. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10292. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemData, "%s", valuestr );
  10293. }
  10294. if(strcmp(keystr, "StopTxnAlignedData") == 0)
  10295. {
  10296. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10297. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemData, "%s", valuestr );
  10298. }
  10299. if(strcmp(keystr, "StopTxnAlignedDataMaxLength") == 0)
  10300. {
  10301. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10302. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemData, "%d", atoi(valuestr) );
  10303. }
  10304. if(strcmp(keystr, "StopTxnSampledData") == 0)
  10305. {
  10306. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10307. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "%s", valuestr );
  10308. }
  10309. if(strcmp(keystr, "StopTxnSampledDataMaxLength") == 0)
  10310. {
  10311. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10312. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemData, "%d", atoi(valuestr) );
  10313. }
  10314. if(strcmp(keystr, "SupportedFeatureProfiles") == 0)
  10315. {
  10316. ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10317. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemData, "%s", valuestr );
  10318. }
  10319. if(strcmp(keystr, "SupportedFeatureProfilesMaxLength") == 0)
  10320. {
  10321. ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10322. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemData, "%d", atoi(valuestr) );
  10323. }
  10324. if(strcmp(keystr, "TransactionMessageAttempts") == 0)
  10325. {
  10326. ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10327. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData, "%d", atoi(valuestr) );
  10328. TransactionMessageAttemptsValue = atoi(valuestr);
  10329. }
  10330. if(strcmp(keystr, "TransactionMessageRetryInterval") == 0)
  10331. {
  10332. ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemAccessibility= (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10333. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData, "%d", atoi(valuestr) );
  10334. TransactionMessageRetryIntervalValue = atoi(valuestr);
  10335. }
  10336. if(strcmp(keystr, "UnlockConnectorOnEVSideDisconnect") == 0)
  10337. {
  10338. ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10339. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemData, "%s", valuestr );
  10340. }
  10341. if(strcmp(keystr, "WebSocketPingInterval") == 0)
  10342. {
  10343. ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10344. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemData, "%d", atoi(valuestr) );
  10345. }
  10346. if(strcmp(keystr, "LocalAuthListEnabled") == 0)
  10347. {
  10348. ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10349. sprintf((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "%s", valuestr );
  10350. }
  10351. if(strcmp(keystr, "LocalAuthListMaxLength") == 0)
  10352. {
  10353. ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10354. sprintf((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemData, "%d", atoi(valuestr) );
  10355. }
  10356. if(strcmp(keystr, "SendLocalListMaxLength") == 0)
  10357. {
  10358. ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10359. sprintf((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemData, "%d", atoi(valuestr) );
  10360. }
  10361. if(strcmp(keystr, "ReserveConnectorZeroSupported") == 0)
  10362. {
  10363. ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10364. sprintf((char *)ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemData, "%s", valuestr );
  10365. }
  10366. if(strcmp(keystr, "ChargeProfileMaxStackLevel") == 0)
  10367. {
  10368. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10369. sprintf((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemData, "%d", atoi(valuestr) );
  10370. }
  10371. if(strcmp(keystr, "ChargingScheduleAllowedChargingRateUnit") == 0)
  10372. {
  10373. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10374. sprintf((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemData, "%s", valuestr );
  10375. }
  10376. if(strcmp(keystr, "ChargingScheduleMaxPeriods") == 0)
  10377. {
  10378. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10379. sprintf((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemData, "%d", atoi(valuestr) );
  10380. }
  10381. if(strcmp(keystr, "ConnectorSwitch3to1PhaseSupported") == 0)
  10382. {
  10383. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10384. sprintf((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemData, "%s", valuestr);
  10385. }
  10386. if(strcmp(keystr, "MaxChargingProfilesInstalled") == 0)
  10387. {
  10388. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10389. sprintf((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemData, "%d", atoi(valuestr) );
  10390. }
  10391. }
  10392. fclose(fp);
  10393. }
  10394. return 0;
  10395. }
  10396. void StoreConfigurationTable(void)
  10397. {
  10398. FILE *outfile;
  10399. outfile = fopen("/Storage/OCPP/OCPPConfiguration" , "w+");
  10400. if(outfile == NULL)
  10401. {
  10402. DEBUG_INFO("Error opening file");
  10403. return ;
  10404. }
  10405. /*Core Profile*/
  10406. //AllowOfflineTxForUnknownId
  10407. /*
  10408. ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemAccessibility = 1;
  10409. printf("AllowoddlineTXForUnknownId type: %d \n", ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemAccessibility);
  10410. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemName, "AllowOfflineTxForUnknownId");
  10411. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemData, "TRUE" );
  10412. */
  10413. //DEBUG_INFO("data=%s\n",data);
  10414. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","AllowOfflineTxForUnknownId", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemData);
  10415. //AuthorizationCacheEnabled
  10416. /*
  10417. ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemAccessibility = 1;
  10418. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemName, "AuthorizationCacheEnabled");
  10419. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemData, "FALSE" );
  10420. */
  10421. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","AuthorizationCacheEnabled", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemData);
  10422. //AuthorizeRemoteTxRequests
  10423. /*
  10424. ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemAccessibility = 0;
  10425. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemName, "AuthorizeRemoteTxRequests");
  10426. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemData, "TRUE" );
  10427. */
  10428. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","AuthorizeRemoteTxRequests", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemData);
  10429. //BlinkRepeat
  10430. /*
  10431. ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemAccessibility = 1;
  10432. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemName, "BlinkRepeat");
  10433. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemData, "0" );
  10434. */
  10435. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","BlinkRepeat", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemData);
  10436. //ClockAlignedDataInterval
  10437. /*
  10438. ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemAccessibility = 1;
  10439. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemName, "ClockAlignedDataInterval");
  10440. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemData, "0" );
  10441. */
  10442. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ClockAlignedDataInterval", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemData);
  10443. //ConnectionTimeOut
  10444. /*
  10445. ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemAccessibility = 1;
  10446. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemName, "ConnectionTimeOut");
  10447. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemData, "180" );
  10448. */
  10449. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ConnectionTimeOut", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemData);
  10450. //GetConfigurationMaxKeys
  10451. /*
  10452. ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemAccessibility =0;
  10453. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemName, "GetConfigurationMaxKeys");
  10454. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemData, "43" );
  10455. */
  10456. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","GetConfigurationMaxKeys", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemData);
  10457. // HeartbeatInterval
  10458. /*
  10459. ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemAccessibility = 1;
  10460. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemName, "HeartbeatInterval");
  10461. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemData, "10" );
  10462. */
  10463. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","HeartbeatInterval", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemData);
  10464. // LightIntensity
  10465. /*
  10466. ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemAccessibility = 1;
  10467. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemName, "LightIntensity");
  10468. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemData, "0" );
  10469. */
  10470. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LightIntensity", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemData);
  10471. // LocalAuthorizeOffline
  10472. /*
  10473. ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemAccessibility = 0;
  10474. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemName, "LocalAuthorizeOffline");
  10475. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemData, "TRUE" );
  10476. */
  10477. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LocalAuthorizeOffline", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemData);
  10478. // LocalPreAuthorize
  10479. /*
  10480. ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemAccessibility = 0;
  10481. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemName, "LocalPreAuthorize");
  10482. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemData, "FALSE" );
  10483. */
  10484. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LocalPreAuthorize", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemData);
  10485. // MaxEnergyOnInvalidId
  10486. /*
  10487. ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemAccessibility = 1;
  10488. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemName, "MaxEnergyOnInvalidId");
  10489. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemData, "0" );
  10490. */
  10491. //ShmSysConfigAndInfo->SysConfig.OfflineMaxChargeEnergy = 0;
  10492. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MaxEnergyOnInvalidId", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemData);
  10493. // MeterValuesAlignedData
  10494. /*
  10495. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemAccessibility = 1;
  10496. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemName, "MeterValuesAlignedData");
  10497. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, "Current.Export,Energy.Active.Export.Interval,Power.Active.Export,Voltage,SOC" );
  10498. */
  10499. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValuesAlignedData", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData);
  10500. // MeterValuesAlignedDataMaxLength
  10501. /*
  10502. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemAccessibility = 0;
  10503. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemName, "MeterValuesAlignedDataMaxLength");
  10504. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemData, "5" );
  10505. */
  10506. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValuesAlignedDataMaxLength", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemData);
  10507. // MeterValuesSampledData
  10508. /*
  10509. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemAccessibility = 1;
  10510. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemName, "MeterValuesSampledData");
  10511. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, "Current.Export,Energy.Active.Export.Interval,Power.Active.Export,Voltage,SOC" );
  10512. */
  10513. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValuesSampledData", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData);
  10514. // MeterValuesSampledDataMaxLength
  10515. /*
  10516. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemAccessibility = 0;
  10517. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemName, "MeterValuesSampledDataMaxLength");
  10518. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemData, "5" );
  10519. */
  10520. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValuesSampledDataMaxLength", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemData);
  10521. // MeterValueSampleInterval
  10522. /*
  10523. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemAccessibility = 1;
  10524. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemName, "MeterValueSampleInterval");
  10525. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemData, "10" );
  10526. */
  10527. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValueSampleInterval", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemData);
  10528. // MinimumStatusDuration
  10529. /*
  10530. ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemAccessibility = 1;
  10531. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemName, "MinimumStatusDuration");
  10532. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemData, "0" );
  10533. */
  10534. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MinimumStatusDuration", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemData);
  10535. // NumberOfConnectors
  10536. /*
  10537. ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemAccessibility = 0;
  10538. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemName, "NumberOfConnectors");
  10539. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  10540. {
  10541. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData, "%d", (CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY));
  10542. }
  10543. else
  10544. {
  10545. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData, "%d", AC_QUANTITY);
  10546. }
  10547. */
  10548. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","NumberOfConnectors", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData);
  10549. // ResetRetries
  10550. /*
  10551. ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemAccessibility = 1;
  10552. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemName, "ResetRetries");
  10553. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemData, "3" );
  10554. */
  10555. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ResetRetries", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemData);
  10556. // ConnectorPhaseRotation
  10557. /*
  10558. ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemAccessibility = 1;
  10559. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemName, "ConnectorPhaseRotation");
  10560. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "NotApplicable" );
  10561. */
  10562. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ConnectorPhaseRotation", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData);
  10563. // ConnectorPhaseRotationMaxLength
  10564. /*
  10565. ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemAccessibility = 0;
  10566. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemName, "ConnectorPhaseRotationMaxLength");
  10567. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemData, "1" );
  10568. */
  10569. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ConnectorPhaseRotationMaxLength", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemData);
  10570. // StopTransactionOnEVSideDisconnect
  10571. /*
  10572. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemAccessibility = 0;
  10573. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemName, "StopTransactionOnEVSideDisconnect");
  10574. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemData, "TRUE" );
  10575. */
  10576. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTransactionOnEVSideDisconnect", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemData);
  10577. // StopTransactionOnInvalidId
  10578. /*
  10579. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemAccessibility = 0;
  10580. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemName, "StopTransactionOnInvalidId");
  10581. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemData, "FALSE" );
  10582. */
  10583. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTransactionOnInvalidId", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemData);
  10584. // StopTxnAlignedData
  10585. /*
  10586. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemAccessibility = 1;
  10587. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemName, "StopTxnAlignedData");
  10588. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemData, "Energy.Active.Import.Register" );
  10589. */
  10590. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTxnAlignedData", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemData);
  10591. // StopTxnAlignedDataMaxLength
  10592. /*
  10593. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemAccessibility = 0;
  10594. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemName, "StopTxnAlignedDataMaxLength");
  10595. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemData, "0" );
  10596. */
  10597. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTxnAlignedDataMaxLength", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemData);
  10598. // StopTxnSampledData
  10599. /*
  10600. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemAccessibility = 1;
  10601. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemName, "StopTxnSampledData");
  10602. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Energy.Active.Import.Register" );
  10603. */
  10604. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTxnSampledData", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData);
  10605. // StopTxnSampledDataMaxLength
  10606. /*
  10607. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemAccessibility = 0;
  10608. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemName, "StopTxnSampledDataMaxLength");
  10609. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemData, "0" );
  10610. */
  10611. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTxnSampledDataMaxLength", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemData);
  10612. // SupportedFeatureProfiles
  10613. /*
  10614. ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemAccessibility = 0;
  10615. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemName, "SupportedFeatureProfiles");
  10616. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemData, "Core,FirmwareManagement,LocalAuthListManagement,Reservation,SmartCharging,RemoteTrigger" );
  10617. */
  10618. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","SupportedFeatureProfiles", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemData);
  10619. // SupportedFeatureProfilesMaxLength
  10620. /*
  10621. ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemAccessibility = 0;
  10622. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemName, "SupportedFeatureProfilesMaxLength");
  10623. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemData, "6" );
  10624. */
  10625. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","SupportedFeatureProfilesMaxLength", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemData);
  10626. // TransactionMessageAttempts
  10627. /*
  10628. ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemAccessibility = 1;
  10629. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemName, "TransactionMessageAttempts");
  10630. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData, "3" );
  10631. */
  10632. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","TransactionMessageAttempts", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData);
  10633. // TransactionMessageRetryInterval
  10634. /*
  10635. ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemAccessibility = 1;
  10636. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemName, "TransactionMessageRetryInterval");
  10637. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData, "60" );
  10638. */
  10639. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","TransactionMessageRetryInterval", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData);
  10640. // UnlockConnectorOnEVSideDisconnect
  10641. /*
  10642. ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemAccessibility = 0;
  10643. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemName, "UnlockConnectorOnEVSideDisconnect");
  10644. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemData, "TRUE" );
  10645. */
  10646. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","UnlockConnectorOnEVSideDisconnect", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemData);
  10647. // WebSocketPingInterval
  10648. /*
  10649. ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemAccessibility = 1;
  10650. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemName, "WebSocketPingInterval");
  10651. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemData, "30" );
  10652. */
  10653. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","WebSocketPingInterval", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemData);
  10654. //* Local Auth List Management Profile*/
  10655. //LocalAuthListEnabled
  10656. /*
  10657. ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemAccessibility = 1;
  10658. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemName, "LocalAuthListEnabled");
  10659. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "TRUE" );
  10660. */
  10661. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LocalAuthListEnabled", "false", (char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData);
  10662. //LocalAuthListMaxLength
  10663. /*
  10664. ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemAccessibility = 0;
  10665. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemName, "LocalAuthListMaxLength");
  10666. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemData, "500" );
  10667. */
  10668. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LocalAuthListMaxLength", "true", (char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemData);
  10669. //SendLocalListMaxLength
  10670. /*
  10671. ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemAccessibility = 0;
  10672. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemName, "SendLocalListMaxLength");
  10673. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemData, "500" );
  10674. */
  10675. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","SendLocalListMaxLength", "true", (char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemData);
  10676. //ReserveConnectorZeroSupported
  10677. /*
  10678. ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemAccessibility = 0;
  10679. strcpy((char *)ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemName, "ReserveConnectorZeroSupported");
  10680. strcpy((char *)ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemData, "FALSE" );
  10681. */
  10682. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ReserveConnectorZeroSupported", "true", (char *)ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemData);
  10683. //* Smart Charging Profile */
  10684. //ChargeProfileMaxStackLevel
  10685. /*
  10686. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemAccessibility = 0;
  10687. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemName, "ChargeProfileMaxStackLevel");
  10688. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemData, "3" );
  10689. */
  10690. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ChargeProfileMaxStackLevel", "true", (char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemData);
  10691. // ChargingScheduleAllowedChargingRateUnit
  10692. /*
  10693. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemAccessibility = 0;
  10694. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemName, "ChargingScheduleAllowedChargingRateUnit");
  10695. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemData, "Current" );
  10696. */
  10697. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ChargingScheduleAllowedChargingRateUnit", "true", (char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemData);
  10698. // ChargingScheduleMaxPeriods
  10699. /*
  10700. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemAccessibility = 0;
  10701. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemName, "ChargingScheduleMaxPeriods");
  10702. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemData, "10" );
  10703. */
  10704. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ChargingScheduleMaxPeriods", "true", (char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemData);
  10705. // ConnectorSwitch3to1PhaseSupported
  10706. /*
  10707. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemAccessibility = 0;
  10708. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemName, "ConnectorSwitch3to1PhaseSupported");
  10709. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemData, "TRUE" );
  10710. */
  10711. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ConnectorSwitch3to1PhaseSupported", "true", (char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemData);
  10712. // MaxChargingProfilesInstalled
  10713. /*
  10714. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemAccessibility = 0;
  10715. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemName, "MaxChargingProfilesInstalled");
  10716. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemData, "3" );
  10717. */
  10718. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MaxChargingProfilesInstalled", "true", (char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemData);
  10719. fclose(outfile);
  10720. }
  10721. void getKeyValue(char *keyReq)
  10722. {
  10723. int isEmpty = FALSE;
  10724. int isKnowKey = FALSE;
  10725. DEBUG_INFO("keyReq = %s\n", keyReq);
  10726. if((keyReq == NULL) || (strlen(keyReq) == 0))
  10727. isEmpty = TRUE;
  10728. if(isEmpty || strcmp(keyReq, "AllowOfflineTxForUnknownId") == 0)
  10729. {
  10730. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_AllowOfflineTxForUnknownId].Item, "AllowOfflineTxForUnknownId");
  10731. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AllowOfflineTxForUnknownId].Key, "AllowOfflineTxForUnknownId");
  10732. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemAccessibility == 1)
  10733. {
  10734. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AllowOfflineTxForUnknownId].ReadOnly, "0"/*"FALSE"*/);
  10735. }
  10736. else
  10737. {
  10738. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AllowOfflineTxForUnknownId].ReadOnly, "1"/*"TRUE"*/);
  10739. }
  10740. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AllowOfflineTxForUnknownId].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemData );
  10741. isKnowKey = TRUE;
  10742. }
  10743. if(isEmpty || strcmp(keyReq, "AuthorizationCacheEnabled") == 0 )
  10744. {
  10745. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_AuthorizationCacheEnabled].Item, "AuthorizationCacheEnabled");
  10746. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizationCacheEnabled].Key, "AuthorizationCacheEnabled");
  10747. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemAccessibility == 1)
  10748. {
  10749. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizationCacheEnabled].ReadOnly, "0"/*"FALSE"*/);
  10750. }
  10751. else
  10752. {
  10753. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizationCacheEnabled].ReadOnly, "1"/*"TRUE"*/);
  10754. }
  10755. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizationCacheEnabled].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemData );
  10756. isKnowKey = TRUE;
  10757. }
  10758. if(isEmpty || strcmp(keyReq, "AuthorizeRemoteTxRequests") == 0 )
  10759. {
  10760. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_AuthorizeRemoteTxRequests].Item, "AuthorizeRemoteTxRequests");
  10761. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizeRemoteTxRequests].Key, "AuthorizeRemoteTxRequests");
  10762. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemAccessibility == 1)
  10763. {
  10764. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizeRemoteTxRequests].ReadOnly, "0"/*"FALSE"*/);
  10765. }
  10766. else
  10767. {
  10768. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizeRemoteTxRequests].ReadOnly, "1"/*"TRUE"*/);
  10769. }
  10770. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizeRemoteTxRequests].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemData );
  10771. isKnowKey = TRUE;
  10772. }
  10773. if(isEmpty || strcmp(keyReq, "BlinkRepeat") == 0 )
  10774. {
  10775. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_BlinkRepeat].Item, "BlinkRepeat");
  10776. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_BlinkRepeat].Key, "BlinkRepeat");
  10777. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemAccessibility == 1)
  10778. {
  10779. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_BlinkRepeat].ReadOnly, "0"/*"FALSE"*/);
  10780. }
  10781. else
  10782. {
  10783. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_BlinkRepeat].ReadOnly, "1"/*"TRUE"*/);
  10784. }
  10785. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_BlinkRepeat].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemData );
  10786. isKnowKey = TRUE;
  10787. }
  10788. if(isEmpty || strcmp(keyReq, "ClockAlignedDataInterval") == 0 )
  10789. {
  10790. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_ClockAlignedDataInterval].Item, "ClockAlignedDataInterval");
  10791. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ClockAlignedDataInterval].Key, "ClockAlignedDataInterval");
  10792. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemAccessibility == 1)
  10793. {
  10794. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ClockAlignedDataInterval].ReadOnly, "0"/*"FALSE"*/);
  10795. }
  10796. else
  10797. {
  10798. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ClockAlignedDataInterval].ReadOnly, "1"/*"TRUE"*/);
  10799. }
  10800. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ClockAlignedDataInterval].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemData );
  10801. isKnowKey = TRUE;
  10802. }
  10803. if(isEmpty || strcmp(keyReq, "ConnectionTimeOut") == 0 )
  10804. {
  10805. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_ConnectionTimeOut].Item, "ConnectionTimeOut");
  10806. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectionTimeOut].Key, "ConnectionTimeOut");
  10807. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemAccessibility == 1)
  10808. {
  10809. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectionTimeOut].ReadOnly, "0"/*"FALSE"*/);
  10810. }
  10811. else
  10812. {
  10813. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectionTimeOut].ReadOnly, "1"/*"TRUE"*/);
  10814. }
  10815. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectionTimeOut].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemData );
  10816. isKnowKey = TRUE;
  10817. }
  10818. if(isEmpty || strcmp(keyReq, "GetConfigurationMaxKeys") == 0 )
  10819. {
  10820. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_GetConfigurationMaxKeys].Item, "GetConfigurationMaxKeys");
  10821. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_GetConfigurationMaxKeys].Key, "GetConfigurationMaxKeys");
  10822. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemAccessibility == 1)
  10823. {
  10824. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_GetConfigurationMaxKeys].ReadOnly, "0"/*"FALSE"*/);
  10825. }
  10826. else
  10827. {
  10828. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_GetConfigurationMaxKeys].ReadOnly, "1"/*"TRUE"*/);
  10829. }
  10830. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_GetConfigurationMaxKeys].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemData );
  10831. isKnowKey = TRUE;
  10832. }
  10833. if(isEmpty || strcmp(keyReq, "HeartbeatInterval") == 0 )
  10834. {
  10835. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_HeartbeatInterval].Item, "HeartbeatInterval");
  10836. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_HeartbeatInterval].Key, "HeartbeatInterval");
  10837. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemAccessibility == 1)
  10838. {
  10839. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_HeartbeatInterval].ReadOnly, "0"/*"FALSE"*/);
  10840. }
  10841. else
  10842. {
  10843. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_HeartbeatInterval].ReadOnly, "1"/*"TRUE"*/);
  10844. }
  10845. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_HeartbeatInterval].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemData );
  10846. isKnowKey = TRUE;
  10847. }
  10848. if(isEmpty || strcmp(keyReq, "LightIntensity") == 0 )
  10849. {
  10850. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_LightIntensity].Item, "LightIntensity");
  10851. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LightIntensity].Key, "LightIntensity");
  10852. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemAccessibility == 1)
  10853. {
  10854. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LightIntensity].ReadOnly, "0"/*"FALSE"*/);
  10855. }
  10856. else
  10857. {
  10858. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LightIntensity].ReadOnly, "1"/*"TRUE"*/);
  10859. }
  10860. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LightIntensity].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemData );
  10861. isKnowKey = TRUE;
  10862. }
  10863. if(isEmpty || strcmp(keyReq, "LocalAuthorizeOffline") == 0 )
  10864. {
  10865. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_LocalAuthorizeOffline].Item, "LocalAuthorizeOffline");
  10866. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthorizeOffline].Key, "LocalAuthorizeOffline");
  10867. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemAccessibility == 1)
  10868. {
  10869. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthorizeOffline].ReadOnly, "0"/*"FALSE"*/);
  10870. }
  10871. else
  10872. {
  10873. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthorizeOffline].ReadOnly, "1"/*"TRUE"*/);
  10874. }
  10875. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthorizeOffline].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemData );
  10876. isKnowKey = TRUE;
  10877. }
  10878. if(isEmpty || strcmp(keyReq, "LocalPreAuthorize") == 0 )
  10879. {
  10880. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_LocalPreAuthorize].Item, "LocalPreAuthorize");
  10881. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalPreAuthorize].Key, "LocalPreAuthorize");
  10882. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemAccessibility == 1)
  10883. {
  10884. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalPreAuthorize].ReadOnly, "0"/*"FALSE"*/);
  10885. }
  10886. else
  10887. {
  10888. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalPreAuthorize].ReadOnly, "1"/*"TRUE"*/);
  10889. }
  10890. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalPreAuthorize].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemData );
  10891. isKnowKey = TRUE;
  10892. }
  10893. if(isEmpty || strcmp(keyReq, "MaxEnergyOnInvalidId") == 0 )
  10894. {
  10895. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_MaxEnergyOnInvalidId].Item, "MaxEnergyOnInvalidId");
  10896. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaxEnergyOnInvalidId].Key, "MaxEnergyOnInvalidId");
  10897. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemAccessibility == 1)
  10898. {
  10899. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaxEnergyOnInvalidId].ReadOnly, "0"/*"FALSE"*/);
  10900. }
  10901. else
  10902. {
  10903. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaxEnergyOnInvalidId].ReadOnly, "1"/*"TRUE"*/);
  10904. }
  10905. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaxEnergyOnInvalidId].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemData );
  10906. ShmSysConfigAndInfo->SysConfig.OfflineMaxChargeEnergy = atoi((const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemData)/1000;
  10907. isKnowKey = TRUE;
  10908. }
  10909. if(isEmpty || strcmp(keyReq, "MeterValuesAlignedData") == 0 )
  10910. {
  10911. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_MeterValuesAlignedData].Item, "MeterValuesAlignedData");
  10912. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesAlignedData].Key, "MeterValuesAlignedData");
  10913. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemAccessibility == 1)
  10914. {
  10915. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesAlignedData].ReadOnly, "0"/*"FALSE"*/);
  10916. }
  10917. else
  10918. {
  10919. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesAlignedData].ReadOnly, "1"/*"TRUE"*/);
  10920. }
  10921. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesAlignedData].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData );
  10922. isKnowKey = TRUE;
  10923. }
  10924. if(isEmpty || strcmp(keyReq, "MeterValuesAlignedDataMaxLength") == 0 )
  10925. {
  10926. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_MeterValuesAlignedDataMaxLength].Item, "MeterValuesAlignedDataMaxLength");
  10927. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesAlignedDataMaxLength].Key, "MeterValuesAlignedDataMaxLength");
  10928. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemAccessibility == 1)
  10929. {
  10930. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesAlignedDataMaxLength].ReadOnly, "0"/*"FALSE"*/);
  10931. }
  10932. else
  10933. {
  10934. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesAlignedDataMaxLength].ReadOnly, "1"/*"TRUE"*/);
  10935. }
  10936. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesAlignedDataMaxLength].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemData );
  10937. isKnowKey = TRUE;
  10938. }
  10939. if(isEmpty || strcmp(keyReq, "MeterValuesSampledData") == 0 )
  10940. {
  10941. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_MeterValuesSampledData].Item, "MeterValuesSampledData");
  10942. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesSampledData].Key, "MeterValuesSampledData");
  10943. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemAccessibility == 1)
  10944. {
  10945. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesSampledData].ReadOnly, "0"/*"FALSE"*/);
  10946. }
  10947. else
  10948. {
  10949. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesSampledData].ReadOnly, "1"/*"TRUE"*/);
  10950. }
  10951. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesSampledData].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData );
  10952. isKnowKey = TRUE;
  10953. }
  10954. if(isEmpty || strcmp(keyReq, "MeterValuesSampledDataMaxLength") == 0 )
  10955. {
  10956. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_MeterValuesSampledDataMaxLength].Item, "MeterValuesSampledDataMaxLength");
  10957. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesSampledDataMaxLength].Key, "MeterValuesSampledDataMaxLength");
  10958. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemAccessibility == 1)
  10959. {
  10960. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesSampledDataMaxLength].ReadOnly, "0"/*"FALSE"*/);
  10961. }
  10962. else
  10963. {
  10964. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesSampledDataMaxLength].ReadOnly, "1"/*"TRUE"*/);
  10965. }
  10966. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesSampledDataMaxLength].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemData );
  10967. isKnowKey = TRUE;
  10968. }
  10969. if(isEmpty || strcmp(keyReq, "MeterValueSampleInterval") == 0 )
  10970. {
  10971. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_MeterValueSampleInterval].Item, "MeterValueSampleInterval");
  10972. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValueSampleInterval].Key, "MeterValueSampleInterval");
  10973. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemAccessibility == 1)
  10974. {
  10975. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValueSampleInterval].ReadOnly, "0"/*"FALSE"*/);
  10976. }
  10977. else
  10978. {
  10979. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValueSampleInterval].ReadOnly, "1"/*"TRUE"*/);
  10980. }
  10981. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValueSampleInterval].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemData );
  10982. isKnowKey = TRUE;
  10983. }
  10984. if(isEmpty || strcmp(keyReq, "MinimumStatusDuration") == 0 )
  10985. {
  10986. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_MinimumStatusDuration].Item, "MinimumStatusDuration");
  10987. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MinimumStatusDuration].Key, "MinimumStatusDuration");
  10988. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemAccessibility == 1)
  10989. {
  10990. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MinimumStatusDuration].ReadOnly, "0"/*"FALSE"*/);
  10991. }
  10992. else
  10993. {
  10994. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MinimumStatusDuration].ReadOnly, "1"/*"TRUE"*/);
  10995. }
  10996. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MinimumStatusDuration].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[17].ItemData );
  10997. isKnowKey = TRUE;
  10998. }
  10999. if(isEmpty || strcmp(keyReq, "NumberOfConnectors") == 0 )
  11000. {
  11001. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_NumberOfConnectors].Item, "NumberOfConnectors");
  11002. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_NumberOfConnectors].Key, "NumberOfConnectors");
  11003. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemAccessibility == 1)
  11004. {
  11005. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_NumberOfConnectors].ReadOnly, "0"/*"FALSE"*/);
  11006. }
  11007. else
  11008. {
  11009. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_NumberOfConnectors].ReadOnly, "1"/*"TRUE"*/);
  11010. }
  11011. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_NumberOfConnectors].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData );
  11012. isKnowKey = TRUE;
  11013. }
  11014. if(isEmpty || strcmp(keyReq, "ResetRetries") == 0 )
  11015. {
  11016. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_ResetRetries].Item, "ResetRetries");
  11017. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ResetRetries].Key, "ResetRetries");
  11018. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemAccessibility == 1)
  11019. {
  11020. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ResetRetries].ReadOnly, "0"/*"FALSE"*/);
  11021. }
  11022. else
  11023. {
  11024. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ResetRetries].ReadOnly, "1"/*"TRUE"*/);
  11025. }
  11026. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ResetRetries].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemData );
  11027. isKnowKey = TRUE;
  11028. }
  11029. if(isEmpty || strcmp(keyReq, "ConnectorPhaseRotation") == 0 )
  11030. {
  11031. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_ConnectorPhaseRotation].Item, "ConnectorPhaseRotation");
  11032. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorPhaseRotation].Key, "ConnectorPhaseRotation");
  11033. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemAccessibility == 1)
  11034. {
  11035. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorPhaseRotation].ReadOnly, "0"/*"FALSE"*/);
  11036. }
  11037. else
  11038. {
  11039. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorPhaseRotation].ReadOnly, "1"/*"TRUE"*/);
  11040. }
  11041. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorPhaseRotation].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData );
  11042. isKnowKey = TRUE;
  11043. }
  11044. if(isEmpty || strcmp(keyReq, "ConnectorPhaseRotationMaxLength") == 0 )
  11045. {
  11046. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_ConnectorPhaseRotationMaxLength].Item, "ConnectorPhaseRotationMaxLength");
  11047. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorPhaseRotationMaxLength].Key, "ConnectorPhaseRotationMaxLength");
  11048. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemAccessibility == 1)
  11049. {
  11050. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorPhaseRotationMaxLength].ReadOnly, "0"/*"FALSE"*/);
  11051. }
  11052. else
  11053. {
  11054. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorPhaseRotationMaxLength].ReadOnly, "1"/*"TRUE"*/);
  11055. }
  11056. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorPhaseRotationMaxLength].Value,(const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemData );
  11057. isKnowKey = TRUE;
  11058. }
  11059. if(isEmpty || strcmp(keyReq, "StopTransactionOnEVSideDisconnect") == 0 )
  11060. {
  11061. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_StopTransactionOnEVSideDisconnect].Item, "StopTransactionOnEVSideDisconnect");
  11062. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTransactionOnEVSideDisconnect].Key, "StopTransactionOnEVSideDisconnect");
  11063. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemAccessibility == 1)
  11064. {
  11065. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTransactionOnEVSideDisconnect].ReadOnly, "0"/*"FALSE"*/);
  11066. }
  11067. else
  11068. {
  11069. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTransactionOnEVSideDisconnect].ReadOnly, "1"/*"TRUE"*/);
  11070. }
  11071. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTransactionOnEVSideDisconnect].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemData );
  11072. isKnowKey = TRUE;
  11073. }
  11074. if(isEmpty || strcmp(keyReq, "StopTransactionOnInvalidId") == 0 )
  11075. {
  11076. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_StopTransactionOnInvalidId].Item, "StopTransactionOnInvalidId");
  11077. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTransactionOnInvalidId].Key, "StopTransactionOnInvalidId");
  11078. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemAccessibility == 1)
  11079. {
  11080. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTransactionOnInvalidId].ReadOnly, "0"/*"FALSE"*/);
  11081. }
  11082. else
  11083. {
  11084. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTransactionOnInvalidId].ReadOnly, "1"/*"TRUE"*/);
  11085. }
  11086. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTransactionOnInvalidId].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemData );
  11087. isKnowKey = TRUE;
  11088. }
  11089. if(isEmpty || strcmp(keyReq, "StopTxnAlignedData") == 0 )
  11090. {
  11091. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_StopTxnAlignedData].Item, "StopTxnAlignedData");
  11092. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnAlignedData].Key, "StopTxnAlignedData");
  11093. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemAccessibility == 1)
  11094. {
  11095. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnAlignedData].ReadOnly, "0"/*"FALSE"*/);
  11096. }
  11097. else
  11098. {
  11099. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnAlignedData].ReadOnly, "1"/*"TRUE"*/);
  11100. }
  11101. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnAlignedData].Value,(const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemData );
  11102. isKnowKey = TRUE;
  11103. }
  11104. if(isEmpty || strcmp(keyReq, "StopTxnAlignedDataMaxLength") == 0 )
  11105. {
  11106. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_StopTxnAlignedDataMaxLength].Item, "StopTxnAlignedDataMaxLength");
  11107. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnAlignedDataMaxLength].Key, "StopTxnAlignedDataMaxLength");
  11108. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemAccessibility == 1)
  11109. {
  11110. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnAlignedDataMaxLength].ReadOnly, "0"/*"FALSE"*/);
  11111. }
  11112. else
  11113. {
  11114. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnAlignedDataMaxLength].ReadOnly, "1"/*"TRUE"*/);
  11115. }
  11116. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnAlignedDataMaxLength].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemData );
  11117. isKnowKey = TRUE;
  11118. }
  11119. if(isEmpty || strcmp(keyReq, "StopTxnSampledData") == 0 )
  11120. {
  11121. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_StopTxnSampledData].Item, "StopTxnSampledData");
  11122. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnSampledData].Key, "StopTxnSampledData");
  11123. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemAccessibility == 1)
  11124. {
  11125. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnSampledData].ReadOnly, "0"/*"FALSE"*/);
  11126. }
  11127. else
  11128. {
  11129. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnSampledData].ReadOnly, "1"/*"TRUE"*/);
  11130. }
  11131. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnSampledData].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData );
  11132. isKnowKey = TRUE;
  11133. }
  11134. if(isEmpty || strcmp(keyReq, "StopTxnSampledDataMaxLength") == 0 )
  11135. {
  11136. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_StopTxnSampledDataMaxLength].Item, "StopTxnSampledDataMaxLength");
  11137. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnSampledDataMaxLength].Key, "StopTxnSampledDataMaxLength");
  11138. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemAccessibility == 1)
  11139. {
  11140. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnSampledDataMaxLength].ReadOnly, "0"/*"FALSE"*/);
  11141. }
  11142. else
  11143. {
  11144. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnSampledDataMaxLength].ReadOnly, "1"/*"TRUE"*/);
  11145. }
  11146. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnSampledDataMaxLength].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemData );
  11147. isKnowKey = TRUE;
  11148. }
  11149. if(isEmpty || strcmp(keyReq, "SupportedFeatureProfiles") == 0 )
  11150. {
  11151. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_SupportedFeatureProfiles].Item, "SupportedFeatureProfiles");
  11152. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SupportedFeatureProfiles].Key, "SupportedFeatureProfiles");
  11153. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemAccessibility == 1)
  11154. {
  11155. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SupportedFeatureProfiles].ReadOnly, "0"/*"FALSE"*/);
  11156. }
  11157. else
  11158. {
  11159. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SupportedFeatureProfiles].ReadOnly, "1"/*"TRUE"*/);
  11160. }
  11161. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SupportedFeatureProfiles].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemData );
  11162. isKnowKey = TRUE;
  11163. }
  11164. if(isEmpty || strcmp(keyReq, "SupportedFeatureProfilesMaxLength") == 0 )
  11165. {
  11166. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_SupportedFeatureProfilesMaxLength].Item, "SupportedFeatureProfilesMaxLength");
  11167. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SupportedFeatureProfilesMaxLength].Key, "SupportedFeatureProfilesMaxLength");
  11168. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemAccessibility == 1)
  11169. {
  11170. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SupportedFeatureProfilesMaxLength].ReadOnly, "0"/*"FALSE"*/);
  11171. }
  11172. else
  11173. {
  11174. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SupportedFeatureProfilesMaxLength].ReadOnly, "1"/*"TRUE"*/);
  11175. }
  11176. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SupportedFeatureProfilesMaxLength].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemData );
  11177. isKnowKey = TRUE;
  11178. }
  11179. if(isEmpty || strcmp(keyReq, "TransactionMessageAttempts") == 0 )
  11180. {
  11181. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_TransactionMessageAttempts].Item, "TransactionMessageAttempts");
  11182. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TransactionMessageAttempts].Key, "TransactionMessageAttempts");
  11183. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemAccessibility == 1)
  11184. {
  11185. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TransactionMessageAttempts].ReadOnly, "0"/*"FALSE"*/);
  11186. }
  11187. else
  11188. {
  11189. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TransactionMessageAttempts].ReadOnly, "1"/*"TRUE"*/);
  11190. }
  11191. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TransactionMessageAttempts].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData );
  11192. isKnowKey = TRUE;
  11193. }
  11194. if(isEmpty || strcmp(keyReq, "TransactionMessageRetryInterval") == 0 )
  11195. {
  11196. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_TransactionMessageRetryInterval].Item, "TransactionMessageRetryInterval");
  11197. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TransactionMessageRetryInterval].Key, "TransactionMessageRetryInterval");
  11198. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemAccessibility == 1)
  11199. {
  11200. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TransactionMessageRetryInterval].ReadOnly, "0"/*"FALSE"*/);
  11201. }
  11202. else
  11203. {
  11204. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TransactionMessageRetryInterval].ReadOnly, "1"/*"TRUE"*/);
  11205. }
  11206. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TransactionMessageRetryInterval].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData );
  11207. isKnowKey = TRUE;
  11208. }
  11209. if(isEmpty || strcmp(keyReq, "UnlockConnectorOnEVSideDisconnect") == 0 )
  11210. {
  11211. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_UnlockConnectorOnEVSideDisconnect].Item, "UnlockConnectorOnEVSideDisconnect");
  11212. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_UnlockConnectorOnEVSideDisconnect].Key, "UnlockConnectorOnEVSideDisconnect");
  11213. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemAccessibility == 1)
  11214. {
  11215. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_UnlockConnectorOnEVSideDisconnect].ReadOnly, "0"/*"FALSE"*/);
  11216. }
  11217. else
  11218. {
  11219. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_UnlockConnectorOnEVSideDisconnect].ReadOnly, "1"/*"TRUE"*/);
  11220. }
  11221. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_UnlockConnectorOnEVSideDisconnect].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemData );
  11222. isKnowKey = TRUE;
  11223. }
  11224. if(isEmpty || strcmp(keyReq, "WebSocketPingInterval") == 0 )
  11225. {
  11226. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_WebSocketPingInterval].Item, "WebSocketPingInterval");
  11227. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_WebSocketPingInterval].Key, "WebSocketPingInterval");
  11228. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemAccessibility == 1)
  11229. {
  11230. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_WebSocketPingInterval].ReadOnly, "0"/*"FALSE"*/);
  11231. }
  11232. else
  11233. {
  11234. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_WebSocketPingInterval].ReadOnly, "1"/*"TRUE"*/);
  11235. }
  11236. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_WebSocketPingInterval].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemData );
  11237. isKnowKey = TRUE;
  11238. }
  11239. #if 1
  11240. if(isEmpty || strcmp(keyReq, "LocalAuthListEnabled") == 0 )
  11241. {
  11242. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_LocalAuthListEnabled].Item, "LocalAuthListEnabled");
  11243. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListEnabled].Key, "LocalAuthListEnabled");
  11244. if(ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemAccessibility == 1)
  11245. {
  11246. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListEnabled].ReadOnly, "0"/*"FALSE"*/);
  11247. }
  11248. else
  11249. {
  11250. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListEnabled].ReadOnly, "1"/*"TRUE"*/);
  11251. }
  11252. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListEnabled].Value, (const char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData );
  11253. isKnowKey = TRUE;
  11254. }
  11255. #endif
  11256. if(isEmpty || strcmp(keyReq, "LocalAuthListMaxLength") == 0 )
  11257. {
  11258. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_LocalAuthListMaxLength].Item, "LocalAuthListMaxLength");
  11259. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListMaxLength].Key, "LocalAuthListMaxLength");
  11260. if(ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemAccessibility == 1)
  11261. {
  11262. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListMaxLength].ReadOnly, "0"/*"FALSE"*/);
  11263. }
  11264. else
  11265. {
  11266. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListMaxLength].ReadOnly, "1"/*"TRUE"*/);
  11267. }
  11268. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListMaxLength].Value, (const char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemData );
  11269. isKnowKey = TRUE;
  11270. }
  11271. if(isEmpty || strcmp(keyReq, "SendLocalListMaxLength") == 0 )
  11272. {
  11273. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_SendLocalListMaxLength].Item, "SendLocalListMaxLength");
  11274. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SendLocalListMaxLength].Key, "SendLocalListMaxLength");
  11275. if(ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemAccessibility == 1)
  11276. {
  11277. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SendLocalListMaxLength].ReadOnly, "0"/*"FALSE"*/);
  11278. }
  11279. else
  11280. {
  11281. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SendLocalListMaxLength].ReadOnly, "1"/*"TRUE"*/);
  11282. }
  11283. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SendLocalListMaxLength].Value, (const char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemData );
  11284. isKnowKey = TRUE;
  11285. }
  11286. if(isEmpty || strcmp(keyReq, "ReserveConnectorZeroSupported") == 0 )
  11287. {
  11288. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_ReserveConnectorZeroSupported].Item, "ReserveConnectorZeroSupported");
  11289. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ReserveConnectorZeroSupported].Key, "ReserveConnectorZeroSupported");
  11290. if(ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemAccessibility == 1)
  11291. {
  11292. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ReserveConnectorZeroSupported].ReadOnly, "0"/*"FALSE"*/);
  11293. }
  11294. else
  11295. {
  11296. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ReserveConnectorZeroSupported].ReadOnly, "1"/*"TRUE"*/);
  11297. }
  11298. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ReserveConnectorZeroSupported].Value,(const char *)ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemData);
  11299. isKnowKey = TRUE;
  11300. }
  11301. if(isEmpty || strcmp(keyReq, "ChargeProfileMaxStackLevel") == 0 )
  11302. {
  11303. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_ChargeProfileMaxStackLevel].Item, "ChargeProfileMaxStackLevel");
  11304. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargeProfileMaxStackLevel].Key, "ChargeProfileMaxStackLevel");
  11305. if(ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemAccessibility == 1)
  11306. {
  11307. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargeProfileMaxStackLevel].ReadOnly, "0"/*"FALSE"*/);
  11308. }
  11309. else
  11310. {
  11311. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargeProfileMaxStackLevel].ReadOnly, "1"/*"TRUE"*/);
  11312. }
  11313. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargeProfileMaxStackLevel].Value, (const char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemData);
  11314. isKnowKey = TRUE;
  11315. }
  11316. if(isEmpty || strcmp(keyReq, "ChargingScheduleAllowedChargingRateUnit") == 0 )
  11317. {
  11318. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_ChargingScheduleAllowedChargingRateUnit].Item, "ChargingScheduleAllowedChargingRateUnit");
  11319. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargingScheduleAllowedChargingRateUnit].Key, "ChargingScheduleAllowedChargingRateUnit");
  11320. if(ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemAccessibility == 1)
  11321. {
  11322. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargingScheduleAllowedChargingRateUnit].ReadOnly, "0"/*"FALSE"*/);
  11323. }
  11324. else
  11325. {
  11326. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargingScheduleAllowedChargingRateUnit].ReadOnly, "1"/*"TRUE"*/);
  11327. }
  11328. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargingScheduleAllowedChargingRateUnit].Value, (const char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemData);
  11329. isKnowKey = TRUE;
  11330. }
  11331. if(isEmpty || strcmp(keyReq, "ChargingScheduleMaxPeriods") == 0 )
  11332. {
  11333. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_ChargingScheduleMaxPeriods].Item, "ChargingScheduleMaxPeriods");
  11334. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargingScheduleMaxPeriods].Key, "ChargingScheduleMaxPeriods");
  11335. if(ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemAccessibility == 1)
  11336. {
  11337. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargingScheduleMaxPeriods].ReadOnly, "0"/*"FALSE"*/);
  11338. }
  11339. else
  11340. {
  11341. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargingScheduleMaxPeriods].ReadOnly, "1"/*"TRUE"*/);
  11342. }
  11343. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargingScheduleMaxPeriods].Value, (const char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemData);
  11344. isKnowKey = TRUE;
  11345. }
  11346. if(isEmpty || strcmp(keyReq, "ConnectorSwitch3to1PhaseSupported") == 0 )
  11347. {
  11348. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_ConnectorSwitch3to1PhaseSupported].Item, "ConnectorSwitch3to1PhaseSupported");
  11349. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorSwitch3to1PhaseSupported].Key, "ConnectorSwitch3to1PhaseSupported");
  11350. if(ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemAccessibility == 1)
  11351. {
  11352. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorSwitch3to1PhaseSupported].ReadOnly, "0"/*"FALSE"*/);
  11353. }
  11354. else
  11355. {
  11356. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorSwitch3to1PhaseSupported].ReadOnly, "1"/*"TRUE"*/);
  11357. }
  11358. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorSwitch3to1PhaseSupported].Value, (const char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemData);
  11359. isKnowKey = TRUE;
  11360. }
  11361. if(isEmpty || strcmp(keyReq, "MaxChargingProfilesInstalled") == 0 )
  11362. {
  11363. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_MaxChargingProfilesInstalled].Item, "MaxChargingProfilesInstalled");
  11364. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaxChargingProfilesInstalled].Key, "MaxChargingProfilesInstalled");
  11365. if(ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemAccessibility == 1)
  11366. {
  11367. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaxChargingProfilesInstalled].ReadOnly, "0"/*"FLASE"*/);
  11368. }
  11369. else
  11370. {
  11371. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaxChargingProfilesInstalled].ReadOnly, "1"/*"TRUE"*/);
  11372. }
  11373. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaxChargingProfilesInstalled].Value, (const char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemData);
  11374. isKnowKey = TRUE;
  11375. }
  11376. //=========================================================
  11377. if(!isEmpty && !isKnowKey)
  11378. {
  11379. DEBUG_INFO("unKnowIndex =%d\n", UnknownKeynum);
  11380. strcpy(unknownkey[UnknownKeynum], keyReq);
  11381. UnknownKeynum = UnknownKeynum + 1;
  11382. }
  11383. }
  11384. void processUnkownKey(void)
  11385. {
  11386. DEBUG_INFO("processUnkownKey...\n");
  11387. memset(ShmOCPP16Data->GetConfiguration.ResponseUnknownKey, 0 , sizeof(struct StructConfigurationKeyItems)* 10);
  11388. for(int index=0; index < UnknownKeynum; index++)
  11389. {
  11390. if(ShmOCPP16Data->GetConfiguration.ResponseUnknownKey[index].Item[0] == 0)
  11391. {
  11392. strcpy((char *)(ShmOCPP16Data->GetConfiguration.ResponseUnknownKey[index].Item), unknownkey[index]);
  11393. }
  11394. }
  11395. }
  11396. int setKeyValue(char *key, char *value)
  11397. {
  11398. int isSuccess = NotSupported;
  11399. int check_ascii=0;
  11400. char str[10]={0};
  11401. DEBUG_INFO(" setKeyValue %s = %s\n", key, value);
  11402. if(strcmp(key, "AllowOfflineTxForUnknownId") == 0)
  11403. {
  11404. //Charger.AllowOfflineTxForUnknownId = (value.toLowerCase().equals("true")?true:false);
  11405. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemAccessibility == 1)
  11406. {
  11407. strcpy(str, (const char*)value);
  11408. for(int i = 0; str[i]; i++){
  11409. str[i] = tolower(str[i]);
  11410. }
  11411. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  11412. isSuccess = ConfigurationStatus_Accepted;
  11413. }
  11414. else
  11415. {
  11416. isSuccess = ConfigurationStatus_Rejected;
  11417. }
  11418. }
  11419. if(strcmp(key, "AuthorizationCacheEnabled") == 0)
  11420. {
  11421. //Charger.AuthorizationCacheEnabled = (value.toLowerCase().equals("true")?true:false);
  11422. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemAccessibility == 1)
  11423. {
  11424. strcpy(str, (const char*)value);
  11425. for(int i = 0; str[i]; i++){
  11426. str[i] = tolower(str[i]);
  11427. }
  11428. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  11429. isSuccess = ConfigurationStatus_Accepted;
  11430. //updateSetting("AuthorizationCacheEnabled",(char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[1].ItemData);
  11431. }
  11432. else
  11433. {
  11434. isSuccess = ConfigurationStatus_Rejected;
  11435. }
  11436. }
  11437. if(strcmp(key, "AuthorizeRemoteTxRequests") == 0)
  11438. {
  11439. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemAccessibility == 1)
  11440. {
  11441. strcpy(str, (const char*)value);
  11442. for(int i = 0; str[i]; i++)
  11443. {
  11444. str[i] = tolower(str[i]);
  11445. }
  11446. //Charger.AuthorizeRemoteTxRequests = (value.toLowerCase().equals("true")?true:false);
  11447. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  11448. isSuccess = ConfigurationStatus_Accepted;
  11449. }
  11450. else
  11451. {
  11452. isSuccess = ConfigurationStatus_Rejected;
  11453. }
  11454. }
  11455. if(strcmp(key, "BlinkRepeat") == 0)
  11456. {
  11457. //Charger.BlinkRepeat = Integer.parseInt(value);
  11458. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemAccessibility == 1)
  11459. {
  11460. check_ascii = value[0];
  11461. if( (check_ascii < 48) || (check_ascii > 57) )
  11462. {
  11463. isSuccess = ConfigurationStatus_Rejected;
  11464. }
  11465. else
  11466. {
  11467. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemData, "%d", atoi(value) );
  11468. isSuccess = ConfigurationStatus_Accepted;
  11469. }
  11470. }
  11471. else
  11472. {
  11473. isSuccess = ConfigurationStatus_Rejected;
  11474. }
  11475. }
  11476. if(strcmp(key, "ClockAlignedDataInterval") == 0)
  11477. {
  11478. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemAccessibility == 1)
  11479. {
  11480. check_ascii = value[0];
  11481. if( (check_ascii < 48) || (check_ascii > 57) )
  11482. {
  11483. isSuccess = ConfigurationStatus_Rejected;
  11484. }
  11485. else
  11486. {
  11487. //Charger.ClockAlignedDataInterval = Integer.parseInt(value)*1000;
  11488. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemData, "%d", atoi(value) );
  11489. isSuccess = ConfigurationStatus_Accepted;
  11490. }
  11491. }
  11492. else
  11493. {
  11494. isSuccess = ConfigurationStatus_Rejected;
  11495. }
  11496. }
  11497. if(strcmp(key, "ConnectionTimeOut") == 0 )
  11498. {
  11499. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemAccessibility == 1)
  11500. {
  11501. check_ascii = value[0];
  11502. if( (check_ascii < 48) || (check_ascii > 57) )
  11503. {
  11504. isSuccess = ConfigurationStatus_Rejected;
  11505. }
  11506. else
  11507. {
  11508. //Charger.ConnectionTimeOut = Integer.parseInt(value)*1000;
  11509. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemData, "%d", atoi(value));
  11510. isSuccess = ConfigurationStatus_Accepted;
  11511. }
  11512. }
  11513. else
  11514. {
  11515. isSuccess = ConfigurationStatus_Rejected;
  11516. }
  11517. }
  11518. if(strcmp(key, "GetConfigurationMaxKeys") == 0)
  11519. {
  11520. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemAccessibility == 1)
  11521. {
  11522. check_ascii = value[0];
  11523. if( (check_ascii < 48) || (check_ascii > 57) )
  11524. {
  11525. isSuccess = ConfigurationStatus_Rejected;
  11526. }
  11527. else
  11528. {
  11529. //Charger.HeartbeatInterval = Integer.parseInt(value)*1000;
  11530. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemData, "%d", atoi(value) );
  11531. isSuccess = ConfigurationStatus_Accepted;
  11532. }
  11533. }
  11534. else
  11535. {
  11536. isSuccess = ConfigurationStatus_Rejected;
  11537. }
  11538. }
  11539. if(strcmp(key, "HeartbeatInterval") == 0)
  11540. {
  11541. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemAccessibility == 1)
  11542. {
  11543. check_ascii = value[0];
  11544. if( (check_ascii < 48) || (check_ascii > 57) )
  11545. {
  11546. isSuccess = ConfigurationStatus_Rejected;
  11547. }
  11548. else
  11549. {
  11550. //Charger.HeartbeatInterval = Integer.parseInt(value)*1000;
  11551. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemData, "%d", atoi(value));
  11552. HeartBeatWaitTime = atoi(value);
  11553. isSuccess = ConfigurationStatus_Accepted;
  11554. }
  11555. }
  11556. else
  11557. {
  11558. isSuccess = ConfigurationStatus_Rejected;
  11559. }
  11560. }
  11561. if(strcmp(key, "LightIntensity") == 0)
  11562. {
  11563. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemAccessibility == 1)
  11564. {
  11565. check_ascii = value[0];
  11566. if( (check_ascii < 48) || (check_ascii > 57) )
  11567. {
  11568. isSuccess = ConfigurationStatus_Rejected;
  11569. }
  11570. else
  11571. {
  11572. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemData, "%d", atoi(value) );
  11573. isSuccess = ConfigurationStatus_Accepted;
  11574. }
  11575. }
  11576. else
  11577. {
  11578. isSuccess = ConfigurationStatus_Rejected;
  11579. }
  11580. }
  11581. if(strcmp(key, "LocalAuthorizeOffline") == 0)
  11582. {
  11583. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemAccessibility == 1)
  11584. {
  11585. strcpy(str, (const char*)value);
  11586. for(int i = 0; str[i]; i++)
  11587. {
  11588. str[i] = tolower(str[i]);
  11589. }
  11590. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  11591. isSuccess = ConfigurationStatus_Accepted;
  11592. //updateSetting("LocalAuthorizeOffline", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemData);
  11593. }
  11594. else
  11595. {
  11596. isSuccess = ConfigurationStatus_Rejected;
  11597. }
  11598. }
  11599. if(strcmp(key, "LocalPreAuthorize") == 0)
  11600. {
  11601. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemAccessibility == 1)
  11602. {
  11603. strcpy(str, (const char*)value);
  11604. for(int i = 0; str[i]; i++)
  11605. {
  11606. str[i] = tolower(str[i]);
  11607. }
  11608. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  11609. isSuccess = ConfigurationStatus_Accepted;
  11610. }
  11611. else
  11612. {
  11613. isSuccess = ConfigurationStatus_Rejected;
  11614. }
  11615. }
  11616. if(strcmp(key, "MaxEnergyOnInvalidId") == 0)
  11617. {
  11618. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemAccessibility == 1)
  11619. {
  11620. check_ascii = value[0];
  11621. if( (check_ascii < 48) || (check_ascii > 57) )
  11622. {
  11623. isSuccess = ConfigurationStatus_Rejected;
  11624. }
  11625. else
  11626. {
  11627. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemData, "%d", atoi(value) );
  11628. ShmSysConfigAndInfo->SysConfig.OfflineMaxChargeEnergy = atoi(value)/1000;
  11629. isSuccess = ConfigurationStatus_Accepted;
  11630. }
  11631. }
  11632. else
  11633. {
  11634. isSuccess = ConfigurationStatus_Rejected;
  11635. }
  11636. }
  11637. if(strcmp(key, "MeterValuesAlignedData") == 0)
  11638. {
  11639. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemAccessibility == 1)
  11640. {
  11641. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, "%s", value );
  11642. isSuccess = ConfigurationStatus_Accepted;
  11643. }
  11644. else
  11645. {
  11646. isSuccess = ConfigurationStatus_Rejected;
  11647. }
  11648. }
  11649. if(strcmp(key, "MeterValuesAlignedDataMaxLength") == 0)
  11650. {
  11651. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemAccessibility == 1)
  11652. {
  11653. check_ascii = value[0];
  11654. if( (check_ascii < 48) || (check_ascii > 57) )
  11655. {
  11656. isSuccess = ConfigurationStatus_Rejected;
  11657. }
  11658. else
  11659. {
  11660. //Charger.MeterValueSampleInterval = Integer.parseInt(value)*1000;
  11661. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemData, "%d", atoi(value));
  11662. isSuccess = ConfigurationStatus_Accepted;
  11663. }
  11664. }
  11665. else
  11666. {
  11667. isSuccess = ConfigurationStatus_Rejected;
  11668. }
  11669. }
  11670. if(strcmp(key, "MeterValuesSampledData") == 0 )
  11671. {
  11672. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemAccessibility == 1)
  11673. {
  11674. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, "%s", value );
  11675. isSuccess = ConfigurationStatus_Accepted;
  11676. }
  11677. else
  11678. {
  11679. isSuccess = ConfigurationStatus_Rejected;
  11680. }
  11681. }
  11682. if(strcmp(key, "MeterValuesSampledDataMaxLength") == 0)
  11683. {
  11684. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemAccessibility == 1)
  11685. {
  11686. check_ascii = value[0];
  11687. if( (check_ascii < 48) || (check_ascii > 57) )
  11688. {
  11689. isSuccess = ConfigurationStatus_Rejected;
  11690. }
  11691. else
  11692. {
  11693. //Charger.MeterValueSampleInterval = Integer.parseInt(value)*1000;
  11694. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemData, "%d", atoi(value));
  11695. isSuccess = ConfigurationStatus_Accepted;
  11696. }
  11697. }
  11698. else
  11699. {
  11700. isSuccess = ConfigurationStatus_Rejected;
  11701. }
  11702. }
  11703. if(strcmp(key, "MeterValueSampleInterval") == 0)
  11704. {
  11705. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemAccessibility == 1)
  11706. {
  11707. check_ascii = value[0];
  11708. if( (check_ascii < 48) || (check_ascii > 57) )
  11709. {
  11710. isSuccess = ConfigurationStatus_Rejected;
  11711. }
  11712. else
  11713. {
  11714. //Charger.MeterValueSampleInterval = Integer.parseInt(value)*1000;
  11715. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemData, "%d", atoi(value));
  11716. isSuccess = ConfigurationStatus_Accepted;
  11717. }
  11718. }
  11719. else
  11720. {
  11721. isSuccess = ConfigurationStatus_Rejected;
  11722. }
  11723. }
  11724. if(strcmp(key, "MinimumStatusDuration") == 0)
  11725. {
  11726. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemAccessibility == 1)
  11727. {
  11728. check_ascii = value[0];
  11729. if( (check_ascii < 48) || (check_ascii > 57) )
  11730. {
  11731. isSuccess = ConfigurationStatus_Rejected;
  11732. }
  11733. else
  11734. {
  11735. if(atoi(value) == 0) // MinimumStatusDuration's value can not be 0
  11736. {
  11737. isSuccess = ConfigurationStatus_Rejected;
  11738. }
  11739. else
  11740. {
  11741. //Charger.MinimumStatusDuration = Integer.parseInt(value);
  11742. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemData, "%d", atoi(value) );
  11743. server_cycle_Status = atoi(value); //StatusNotification Cycle
  11744. isSuccess = ConfigurationStatus_Accepted;
  11745. }
  11746. }
  11747. }
  11748. else
  11749. {
  11750. isSuccess = ConfigurationStatus_Rejected;
  11751. }
  11752. }
  11753. if(strcmp(key, "NumberOfConnectors") == 0)
  11754. {
  11755. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemAccessibility == 1)
  11756. {
  11757. check_ascii = value[0];
  11758. if( (check_ascii < 48) || (check_ascii > 57) )
  11759. {
  11760. isSuccess = ConfigurationStatus_Rejected;
  11761. }
  11762. else
  11763. {
  11764. //Charger.ResetRetries = Integer.parseInt(value);
  11765. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData, "%d", atoi(value) );
  11766. isSuccess = ConfigurationStatus_Accepted;
  11767. }
  11768. }
  11769. else
  11770. {
  11771. isSuccess = ConfigurationStatus_Rejected;
  11772. }
  11773. }
  11774. if(strcmp(key, "ResetRetries") == 0)
  11775. {
  11776. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemAccessibility == 1)
  11777. {
  11778. check_ascii = value[0];
  11779. if( (check_ascii < 48) || (check_ascii > 57) )
  11780. {
  11781. isSuccess = ConfigurationStatus_Rejected;
  11782. }
  11783. else
  11784. {
  11785. //Charger.ResetRetries = Integer.parseInt(value);
  11786. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemData, "%d", atoi(value) );
  11787. isSuccess = ConfigurationStatus_Accepted;
  11788. }
  11789. }
  11790. else
  11791. {
  11792. isSuccess = ConfigurationStatus_Rejected;
  11793. }
  11794. }
  11795. if(strcmp(key, "ConnectorPhaseRotation") == 0)
  11796. {
  11797. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemAccessibility == 1)
  11798. {
  11799. strcpy(str, (const char*)value);
  11800. for(int i = 0; str[i]; i++)
  11801. {
  11802. str[i] = tolower(str[i]);
  11803. }
  11804. if(strcmp(str, "notapplicable")== 0)
  11805. {
  11806. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "%s", "NotApplicable" );
  11807. isSuccess = ConfigurationStatus_Accepted;
  11808. }
  11809. else if(strcmp(str, "unknown")== 0)
  11810. {
  11811. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "%s", "Unknown" );
  11812. isSuccess = ConfigurationStatus_Accepted;
  11813. }
  11814. else if(strcmp(str, "rst")== 0)
  11815. {
  11816. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "%s", "RST" );
  11817. isSuccess = ConfigurationStatus_Accepted;
  11818. }
  11819. else if(strcmp(str, "rts")== 0)
  11820. {
  11821. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "%s", "RTS" );
  11822. isSuccess = ConfigurationStatus_Accepted;
  11823. }
  11824. else if(strcmp(str, "srt")== 0)
  11825. {
  11826. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "%s", "SRT" );
  11827. isSuccess = ConfigurationStatus_Accepted;
  11828. }
  11829. else if(strcmp(str, "str")== 0)
  11830. {
  11831. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "%s", "STR" );
  11832. isSuccess = ConfigurationStatus_Accepted;
  11833. }
  11834. else if(strcmp(str, "trs")== 0)
  11835. {
  11836. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "%s", "TRS" );
  11837. isSuccess = ConfigurationStatus_Accepted;
  11838. }
  11839. else if(strcmp(str, "tsr")== 0)
  11840. {
  11841. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "%s", "TSR" );
  11842. isSuccess = ConfigurationStatus_Accepted;
  11843. }
  11844. else
  11845. {
  11846. isSuccess = ConfigurationStatus_Rejected;
  11847. }
  11848. }
  11849. else
  11850. {
  11851. isSuccess = ConfigurationStatus_Rejected;
  11852. }
  11853. }
  11854. if(strcmp(key, "ConnectorPhaseRotationMaxLength") == 0)
  11855. {
  11856. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemAccessibility == 1)
  11857. {
  11858. check_ascii = value[0];
  11859. if( (check_ascii < 48) || (check_ascii > 57) )
  11860. {
  11861. isSuccess = ConfigurationStatus_Rejected;
  11862. }
  11863. else
  11864. {
  11865. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemData, "%d", atoi(value) );
  11866. isSuccess = ConfigurationStatus_Accepted;
  11867. }
  11868. }
  11869. else
  11870. {
  11871. isSuccess = ConfigurationStatus_Rejected;
  11872. }
  11873. }
  11874. if(strcmp(key, "StopTransactionOnEVSideDisconnect") == 0)
  11875. {
  11876. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemAccessibility == 1)
  11877. {
  11878. strcpy(str, (const char*)value);
  11879. for(int i = 0; str[i]; i++)
  11880. {
  11881. str[i] = tolower(str[i]);
  11882. }
  11883. //Charger.StopTransactionOnEVSideDisconnect = (value.toLowerCase().equals("true")?true:false);
  11884. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  11885. isSuccess = ConfigurationStatus_Accepted;
  11886. }
  11887. else
  11888. {
  11889. isSuccess = ConfigurationStatus_Rejected;
  11890. }
  11891. }
  11892. if(strcmp(key, "StopTransactionOnInvalidId") == 0)
  11893. {
  11894. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemAccessibility == 1)
  11895. {
  11896. strcpy(str, (const char*)value);
  11897. for(int i = 0; str[i]; i++)
  11898. {
  11899. str[i] = tolower(str[i]);
  11900. }
  11901. //Charger.StopTransactionOnInvalidId = (value.toLowerCase().equals("true")?true:false);
  11902. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  11903. isSuccess = ConfigurationStatus_Accepted;
  11904. }
  11905. else
  11906. {
  11907. isSuccess = ConfigurationStatus_Rejected;
  11908. }
  11909. }
  11910. if(strcmp(key, "StopTxnAlignedData") == 0)
  11911. {
  11912. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemAccessibility == 1)
  11913. {
  11914. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemData, "%s", value );
  11915. isSuccess = ConfigurationStatus_Accepted;
  11916. }
  11917. else
  11918. {
  11919. isSuccess = ConfigurationStatus_Rejected;
  11920. }
  11921. }
  11922. if(strcmp(key, "StopTxnAlignedDataMaxLength") == 0)
  11923. {
  11924. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemAccessibility == 1)
  11925. {
  11926. check_ascii = value[0];
  11927. if( (check_ascii < 48) || (check_ascii > 57) )
  11928. {
  11929. isSuccess = ConfigurationStatus_Rejected;
  11930. }
  11931. else
  11932. {
  11933. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemData, "%d", atoi(value) );
  11934. isSuccess = ConfigurationStatus_Accepted;
  11935. }
  11936. }
  11937. else
  11938. {
  11939. isSuccess = ConfigurationStatus_Rejected;
  11940. }
  11941. }
  11942. if(strcmp(key, "StopTxnSampledData") == 0)
  11943. {
  11944. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemAccessibility == 1)
  11945. {
  11946. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "%s", value );
  11947. isSuccess = ConfigurationStatus_Accepted;
  11948. }
  11949. else
  11950. {
  11951. isSuccess = ConfigurationStatus_Rejected;
  11952. }
  11953. }
  11954. if(strcmp(key, "StopTxnSampledDataMaxLength") == 0)
  11955. {
  11956. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemAccessibility == 1)
  11957. {
  11958. check_ascii = value[0];
  11959. if( (check_ascii < 48) || (check_ascii > 57) )
  11960. {
  11961. isSuccess = ConfigurationStatus_Rejected;
  11962. }
  11963. else
  11964. {
  11965. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemData, "%d", atoi(value) );
  11966. isSuccess = ConfigurationStatus_Accepted;
  11967. }
  11968. }
  11969. else
  11970. {
  11971. isSuccess = ConfigurationStatus_Rejected;
  11972. }
  11973. }
  11974. if(strcmp(key, "SupportedFeatureProfiles") == 0)
  11975. {
  11976. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemAccessibility == 1)
  11977. {
  11978. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemData, "%s", value );
  11979. isSuccess = ConfigurationStatus_Accepted;
  11980. }
  11981. else
  11982. {
  11983. isSuccess = ConfigurationStatus_Rejected;
  11984. }
  11985. }
  11986. if(strcmp(key, "SupportedFeatureProfilesMaxLength") == 0)
  11987. {
  11988. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemAccessibility == 1)
  11989. {
  11990. check_ascii = value[0];
  11991. if( (check_ascii < 48) || (check_ascii > 57) )
  11992. {
  11993. isSuccess = ConfigurationStatus_Rejected;
  11994. }
  11995. else
  11996. {
  11997. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemData, "%d", atoi(value) );
  11998. isSuccess = ConfigurationStatus_Accepted;
  11999. }
  12000. }
  12001. else
  12002. {
  12003. isSuccess = ConfigurationStatus_Rejected;
  12004. }
  12005. }
  12006. if(strcmp(key, "TransactionMessageAttempts") == 0)
  12007. {
  12008. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemAccessibility == 1)
  12009. {
  12010. check_ascii = value[0];
  12011. if( (check_ascii < 48) || (check_ascii > 57) )
  12012. {
  12013. isSuccess = ConfigurationStatus_Rejected;
  12014. }
  12015. else
  12016. {
  12017. //Charger.TransactionMessageAttempts = Integer.parseInt(value);
  12018. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData, "%d", atoi(value) );
  12019. TransactionMessageAttemptsValue = atoi(value);
  12020. isSuccess = ConfigurationStatus_Accepted;
  12021. }
  12022. }
  12023. else
  12024. {
  12025. isSuccess = ConfigurationStatus_Rejected;
  12026. }
  12027. }
  12028. if(strcmp(key, "TransactionMessageRetryInterval") == 0)
  12029. {
  12030. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemAccessibility == 1)
  12031. {
  12032. check_ascii = value[0];
  12033. if( (check_ascii < 48) || (check_ascii > 57) )
  12034. {
  12035. isSuccess = ConfigurationStatus_Rejected;
  12036. }
  12037. else
  12038. {
  12039. //Charger.TransactionMessageRetryInterval = Integer.parseInt(value)*1000;
  12040. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData, "%d", atoi(value) );
  12041. TransactionMessageRetryIntervalValue = atoi(value);
  12042. isSuccess = ConfigurationStatus_Accepted;
  12043. }
  12044. }
  12045. else
  12046. {
  12047. isSuccess = ConfigurationStatus_Rejected;
  12048. }
  12049. }
  12050. if(strcmp(key, "UnlockConnectorOnEVSideDisconnect") == 0)
  12051. {
  12052. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemAccessibility == 1)
  12053. {
  12054. strcpy(str, (const char*)value);
  12055. for(int i = 0; str[i]; i++)
  12056. {
  12057. str[i] = tolower(str[i]);
  12058. }
  12059. //Charger.UnlockConnectorOnEVSideDisconnect = (value.toLowerCase().equals("true")?true:false);
  12060. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  12061. isSuccess = ConfigurationStatus_Accepted;
  12062. }
  12063. else
  12064. {
  12065. isSuccess = ConfigurationStatus_Rejected;
  12066. }
  12067. }
  12068. if(strcmp(key, "WebSocketPingInterval") == 0)
  12069. {
  12070. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemAccessibility == 1)
  12071. {
  12072. check_ascii = value[0];
  12073. if( (check_ascii < 48) || (check_ascii > 57) )
  12074. {
  12075. isSuccess = ConfigurationStatus_Rejected;
  12076. }
  12077. else
  12078. {
  12079. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemData, "%d", atoi(value) );
  12080. isSuccess = ConfigurationStatus_Accepted;
  12081. }
  12082. }
  12083. else
  12084. {
  12085. isSuccess = ConfigurationStatus_Rejected;
  12086. }
  12087. }
  12088. #if 0
  12089. //For OCPP Test Case
  12090. if(strcmp(key, "LocalAuthorizationListEnabled") == 0)
  12091. {
  12092. if(ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemAccessibility == 1)
  12093. {
  12094. sprintf((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "%s", (strcmp(value, "true")==0) ?"TRUE":"FALSE" );
  12095. isSuccess = ConfigurationStatus_Accepted;
  12096. //updateSetting("LocalAuthorizationListEnabled", (char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData);
  12097. }
  12098. else
  12099. {
  12100. isSuccess = ConfigurationStatus_Rejected;
  12101. }
  12102. }
  12103. #endif
  12104. #if 1
  12105. if(strcmp(key, "LocalAuthListEnabled") == 0)
  12106. {
  12107. if(ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemAccessibility == 1)
  12108. {
  12109. strcpy(str, (const char*)value);
  12110. for(int i = 0; str[i]; i++)
  12111. {
  12112. str[i] = tolower(str[i]);
  12113. }
  12114. sprintf((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  12115. isSuccess = ConfigurationStatus_Accepted;
  12116. //updateSetting("LocalAuthListEnabled", (char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData);
  12117. }
  12118. else
  12119. {
  12120. isSuccess = ConfigurationStatus_Rejected;
  12121. }
  12122. }
  12123. #endif
  12124. if(strcmp(key, "LocalAuthListMaxLength") == 0)
  12125. {
  12126. if(ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemAccessibility == 1)
  12127. {
  12128. check_ascii = value[0];
  12129. if( (check_ascii < 48) || (check_ascii > 57) )
  12130. {
  12131. isSuccess = ConfigurationStatus_Rejected;
  12132. }
  12133. else
  12134. {
  12135. sprintf((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemData, "%d", atoi(value) );
  12136. isSuccess = ConfigurationStatus_Accepted;
  12137. }
  12138. }
  12139. else
  12140. {
  12141. isSuccess = ConfigurationStatus_Rejected;
  12142. }
  12143. }
  12144. if(strcmp(key, "SendLocalListMaxLength") == 0)
  12145. {
  12146. if(ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemAccessibility == 1)
  12147. {
  12148. check_ascii = value[0];
  12149. if( (check_ascii < 48) || (check_ascii > 57) )
  12150. {
  12151. isSuccess = ConfigurationStatus_Rejected;
  12152. }
  12153. else
  12154. {
  12155. sprintf((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemData, "%d", atoi(value) );
  12156. isSuccess = ConfigurationStatus_Accepted;
  12157. }
  12158. }
  12159. else
  12160. {
  12161. isSuccess = ConfigurationStatus_Rejected;
  12162. }
  12163. }
  12164. if(strcmp(key, "ReserveConnectorZeroSupported") == 0)
  12165. {
  12166. if(ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemAccessibility == 1)
  12167. {
  12168. strcpy(str, (const char*)value);
  12169. for(int i = 0; str[i]; i++)
  12170. {
  12171. str[i] = tolower(str[i]);
  12172. }
  12173. sprintf((char *)ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  12174. isSuccess = ConfigurationStatus_Accepted;
  12175. }
  12176. else
  12177. {
  12178. isSuccess = ConfigurationStatus_Rejected;
  12179. }
  12180. }
  12181. if(strcmp(key, "ChargeProfileMaxStackLevel") == 0)
  12182. {
  12183. if(ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemAccessibility == 1)
  12184. {
  12185. check_ascii = value[0];
  12186. if( (check_ascii < 48) || (check_ascii > 57) )
  12187. {
  12188. isSuccess = ConfigurationStatus_Rejected;
  12189. }
  12190. else
  12191. {
  12192. sprintf((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemData, "%d", atoi(value) );
  12193. isSuccess = ConfigurationStatus_Accepted;
  12194. }
  12195. }
  12196. else
  12197. {
  12198. isSuccess = ConfigurationStatus_Rejected;
  12199. }
  12200. }
  12201. if(strcmp(key, "ChargingScheduleAllowedChargingRateUnit") == 0)
  12202. {
  12203. if(ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemAccessibility == 1)
  12204. {
  12205. sprintf((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemData, "%s", value );
  12206. isSuccess = ConfigurationStatus_Accepted;
  12207. }
  12208. else
  12209. {
  12210. isSuccess = ConfigurationStatus_Rejected;
  12211. }
  12212. }
  12213. if(strcmp(key, "ChargingScheduleMaxPeriods") == 0)
  12214. {
  12215. if(ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemAccessibility == 1)
  12216. {
  12217. check_ascii = value[0];
  12218. if( (check_ascii < 48) || (check_ascii > 57) )
  12219. {
  12220. isSuccess = ConfigurationStatus_Rejected;
  12221. }
  12222. else
  12223. {
  12224. sprintf((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemData, "%d", atoi(value) );
  12225. isSuccess = ConfigurationStatus_Accepted;
  12226. }
  12227. }
  12228. else
  12229. {
  12230. isSuccess = ConfigurationStatus_Rejected;
  12231. }
  12232. }
  12233. if(strcmp(key, "ConnectorSwitch3to1PhaseSupported") == 0)
  12234. {
  12235. if(ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemAccessibility == 1)
  12236. {
  12237. strcpy(str, (const char*)value);
  12238. for(int i = 0; str[i]; i++)
  12239. {
  12240. str[i] = tolower(str[i]);
  12241. }
  12242. sprintf((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  12243. isSuccess = ConfigurationStatus_Accepted;
  12244. }
  12245. else
  12246. {
  12247. isSuccess = ConfigurationStatus_Rejected;
  12248. }
  12249. }
  12250. if(strcmp(key, "MaxChargingProfilesInstalled") == 0)
  12251. {
  12252. if(ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemAccessibility == 1)
  12253. {
  12254. check_ascii = value[0];
  12255. if( (check_ascii < 48) || (check_ascii > 57) )
  12256. {
  12257. isSuccess = ConfigurationStatus_Rejected;
  12258. }
  12259. else
  12260. {
  12261. sprintf((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemData, "%d", atoi(value) );
  12262. isSuccess = ConfigurationStatus_Accepted;
  12263. }
  12264. }
  12265. else
  12266. {
  12267. isSuccess = ConfigurationStatus_Rejected;
  12268. }
  12269. }
  12270. return isSuccess;
  12271. }
  12272. int TransactionMessageAttemptsGet(void)
  12273. {
  12274. return TransactionMessageAttemptsValue;
  12275. }
  12276. int FirstHeartBeatResponse(void)
  12277. {
  12278. return FirstHeartBeat;
  12279. }
  12280. int TransactionMessageRetryIntervalGet(void)
  12281. {
  12282. return TransactionMessageRetryIntervalValue;//atoi((const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData);
  12283. }
  12284. int ReadHttpStatus(int sock)
  12285. {
  12286. //char c;
  12287. char buff[1024]="",*ptr=buff+1;
  12288. int bytes_received, status;
  12289. DEBUG_INFO("Begin Response ..\n");
  12290. while((bytes_received = recv(sock, ptr, 1, 0))){
  12291. if(bytes_received==-1){
  12292. perror("ReadHttpStatus");
  12293. exit(1);
  12294. }
  12295. if((ptr[-1]=='\r') && (*ptr=='\n' )) break;
  12296. ptr++;
  12297. }
  12298. *ptr=0;
  12299. ptr=buff+1;
  12300. sscanf(ptr,"%*s %d ", &status);
  12301. DEBUG_INFO("%s\n",ptr);
  12302. DEBUG_INFO("status=%d\n",status);
  12303. DEBUG_INFO("End Response ..\n");
  12304. return (bytes_received>0)?status:0;
  12305. }
  12306. //the only filed that it parsed is 'Content-Length'
  12307. int ParseHeader(int sock)
  12308. {
  12309. //char c;
  12310. char buff[1024]="",*ptr=buff+4;
  12311. int bytes_received;
  12312. DEBUG_INFO("Begin HEADER ..\n");
  12313. while((bytes_received = recv(sock, ptr, 1, 0))){
  12314. if(bytes_received==-1){
  12315. perror("Parse Header");
  12316. exit(1);
  12317. }
  12318. if(
  12319. (ptr[-3]=='\r') && (ptr[-2]=='\n' ) &&
  12320. (ptr[-1]=='\r') && (*ptr=='\n' )
  12321. ) break;
  12322. ptr++;
  12323. }
  12324. *ptr=0;
  12325. ptr=buff+4;
  12326. //printf("%s",ptr);
  12327. if(bytes_received){
  12328. ptr=strstr(ptr,"Content-Length:");
  12329. if(ptr){
  12330. sscanf(ptr,"%*s %d",&bytes_received);
  12331. }else
  12332. bytes_received=-1; //unknown size
  12333. DEBUG_INFO("Content-Length: %d\n",bytes_received);
  12334. }
  12335. DEBUG_INFO("End HEADER ..\n");
  12336. return bytes_received ;
  12337. }
  12338. int httpDownLoadFile(char *location, char *path, char *filename,char *url)
  12339. {
  12340. char rmFileCmd[100]={0};
  12341. char FilePath[100]={0};
  12342. char ftpbuf[200];
  12343. int systemresult;
  12344. //DEBUG_INFO("filename=%s\n",filename);
  12345. //DEBUG_INFO("url=%s\n",url);
  12346. sprintf(FilePath,"/mnt/%s",filename);
  12347. if((access(FilePath,F_OK))!=-1)
  12348. {
  12349. DEBUG_INFO("filename=%s exist.\n",FilePath);
  12350. sprintf(rmFileCmd,"rm -f %s",FilePath);
  12351. system(rmFileCmd);
  12352. }
  12353. memset(ftpbuf, 0, sizeof(ftpbuf));
  12354. sprintf(ftpbuf, "wget --tries=3 -O /mnt/%s -c %s",filename, url);
  12355. //sprintf(ftpbuf, "ftpput -u %s -p %s %s -P %d %s%s %s",user,password,IPbuffer,21,filename,filename,path);
  12356. systemresult = system(ftpbuf);
  12357. //DEBUG_INFO("systemresult=%d\n",systemresult);
  12358. if(systemresult != 0)
  12359. {
  12360. DEBUG_INFO("http DownLoad error!\n");
  12361. return FALSE;
  12362. }
  12363. return TRUE;
  12364. }
  12365. int ftpDownLoadFile(char *location, char *user, char *password, int port, char *path, char *filename,char *url)
  12366. {
  12367. char rmFileCmd[100]={0};
  12368. char FilePath[100]={0};
  12369. char ftpbuf[200];
  12370. int systemresult;
  12371. //char temp[100];
  12372. sprintf(FilePath,"/mnt/%s",filename);
  12373. if((access(FilePath,F_OK))!=-1)
  12374. {
  12375. DEBUG_INFO("filename=%s exist.\n",FilePath);
  12376. sprintf(rmFileCmd,"rm -f %s",FilePath);
  12377. system(rmFileCmd);
  12378. }
  12379. memset(ftpbuf, 0, sizeof(ftpbuf));
  12380. sprintf(ftpbuf, "wget --tries=3 -O /mnt/%s -c %s",filename, url);
  12381. //sprintf(ftpbuf, "ftpget -u %s -p %s %s -P %d %s %s%s",user,password,IPbuffer,port/*21*/,filename,path,filename); --- remove temporally
  12382. //DEBUG_INFO("ftpbuf=%s\n",ftpbuf);
  12383. //sprintf(ftpbuf, "ftpput -u %s -p %s %s -P %d %s%s %s",user,password,IPbuffer,21,filename,filename,path);
  12384. systemresult = system(ftpbuf);
  12385. //DEBUG_INFO("systemresult=%d\n",systemresult);
  12386. if(systemresult != 0)
  12387. {
  12388. printf("wget error!\n");
  12389. return FALSE;
  12390. }
  12391. return TRUE;
  12392. }
  12393. int httpUploadFile(char *location, char *path, char *filename,char *url)
  12394. {
  12395. char rmFileCmd[100]={0};
  12396. char FilePath[100]={0};
  12397. char ftpbuf[200];
  12398. int systemresult;
  12399. //DEBUG_INFO("filename=%s\n",filename);
  12400. //DEBUG_INFO("url=%s\n",url);
  12401. sprintf(FilePath,"%s","/mnt/upload_file.txt");
  12402. if((access(FilePath,F_OK))!=-1)
  12403. {
  12404. DEBUG_INFO("filename=%s exist.\n",FilePath);
  12405. sprintf(rmFileCmd,"rm -f %s",FilePath);
  12406. system(rmFileCmd);
  12407. }
  12408. FILE *fp = fopen("/mnt/upload_file.txt", "w+");
  12409. if(fp == NULL)
  12410. {
  12411. DEBUG_INFO("log is NULL\n");
  12412. return FALSE;
  12413. }
  12414. else
  12415. {
  12416. fprintf(fp, "%s\n", url);
  12417. fprintf(fp, "%s\n", filename);
  12418. fclose(fp);
  12419. }
  12420. memset(ftpbuf, 0, sizeof(ftpbuf));
  12421. sprintf(ftpbuf, "%s","/bin/php-cgi /var/www/ocpp_upload.php");
  12422. systemresult = system(ftpbuf);
  12423. DEBUG_INFO("systemresult = %d\n",systemresult);
  12424. if(systemresult != 0)
  12425. {
  12426. DEBUG_INFO("http upload error!\n");
  12427. return FALSE;
  12428. }
  12429. return TRUE;
  12430. }
  12431. int ftpFile(char *location, char *user, char *password, int port, char *path, char *fnamePlusPath,char *filename)
  12432. {
  12433. struct hostent* server;
  12434. char *IPbuffer;
  12435. char ftpbuf[200];
  12436. int systemresult;
  12437. // To retrieve host information
  12438. server = gethostbyname(location);
  12439. // To convert an Internet network
  12440. // address into ASCII string
  12441. IPbuffer = inet_ntoa(*((struct in_addr*)
  12442. server->h_addr_list[0]));
  12443. memset(ftpbuf, 0, sizeof(ftpbuf));
  12444. /* format : ftpput -u phihong -p y42j%2f4cj84 112.91.88.35 -P 21 /2020-02.zip ../mnt/2020-02.zip*/
  12445. /* format : ftpput -u username -p passwd IP target source*/
  12446. sprintf(ftpbuf, "ftpput -u %s -p %s %s -P %d %s%s %s",user,password,IPbuffer,port/*21*/,path,filename,fnamePlusPath);
  12447. DEBUG_INFO("ftpbuf=%s\n",ftpbuf);
  12448. //sprintf(ftpbuf, "ftpput -u %s -p %s %s -P %d %s%s %s",user,password,IPbuffer,21,filename,filename,path);
  12449. systemresult = system(ftpbuf);
  12450. DEBUG_INFO("systemresult=%d\n",systemresult);
  12451. if(systemresult != 0)
  12452. {
  12453. DEBUG_INFO("ftpput error!\n");
  12454. return FALSE;
  12455. }
  12456. return TRUE;
  12457. }
  12458. /**
  12459. * Place the contents of the specified file into a memory buffer
  12460. *
  12461. * @param[in] filename The path and name of the file to read
  12462. * @param[out] filebuffer A pointer to the contents in memory
  12463. * @return status 0 success, 1 on failure
  12464. */
  12465. int get_file_contents(const char* filename, char** outbuffer) {
  12466. FILE* file = NULL;
  12467. long filesize;
  12468. const int blocksize = 1;
  12469. size_t readsize;
  12470. char* filebuffer;
  12471. // Open the file
  12472. file = fopen(filename, "r");
  12473. if (NULL == file)
  12474. {
  12475. printf("'%s' not opened\n", filename);
  12476. exit(EXIT_FAILURE);
  12477. }
  12478. // Determine the file size
  12479. fseek(file, 0, SEEK_END);
  12480. filesize = ftell(file);
  12481. rewind (file);
  12482. // Allocate memory for the file contents
  12483. filebuffer = (char*) malloc(sizeof(char) * filesize);
  12484. *outbuffer = filebuffer;
  12485. if (filebuffer == NULL)
  12486. {
  12487. fputs ("malloc out-of-memory", stderr);
  12488. exit(EXIT_FAILURE);
  12489. }
  12490. // Read in the file
  12491. readsize = fread(filebuffer, blocksize, filesize, file);
  12492. if (readsize != filesize)
  12493. {
  12494. fputs ("didn't read file completely",stderr);
  12495. exit(EXIT_FAILURE);
  12496. }
  12497. // Clean exit
  12498. fclose(file);
  12499. return EXIT_SUCCESS;
  12500. }
  12501. static int selectSqlCount = 0;
  12502. static int callback(void *data, int argc, char **argv, char **azColName){
  12503. int i;
  12504. //printf("%s: ", (const char*)data);
  12505. selectSqlCount = argc;
  12506. for(i = 0; i<argc; i++){
  12507. // printf("%s = %s\n", azColName[i], argv[i] ? argv[i] : "NULL");
  12508. }
  12509. //printf("\n");
  12510. return 0;
  12511. }
  12512. static int versioncallback(void *data, int argc, char **argv, char **azColName){
  12513. //int i;
  12514. //printf("%s:\n", (const char*)data);
  12515. localversion = argv[5] ? atoi(argv[5]) : 0;
  12516. //printf("localversion=%d\n", localversion);
  12517. return 0;
  12518. }
  12519. static int IdTagcallback(void *data, int argc, char **argv, char **azColName){
  12520. //int i;
  12521. //printf("%s:\n", (const char*)data);
  12522. //idTag
  12523. sprintf(idTagAuthorization,"%s", argv[1] ? argv[1] : "NULL");
  12524. sprintf(idTagQuery.idTagstr,"%s", argv[1] ? argv[1] : "NULL");
  12525. //parentIdTag
  12526. sprintf(idTagQuery.parentIdTag,"%s", argv[2] ? argv[2] : "NULL");
  12527. //expir_date
  12528. sprintf(idTagQuery.expiryDate,"%s", argv[3] ? argv[3] : "NULL");
  12529. //status
  12530. sprintf(idTagQuery.idTagstatus,"%s", argv[4] ? argv[4] : "NULL");
  12531. //version
  12532. idTagQuery.listVersionInt = atoi(argv[5]);
  12533. //DEBUG_INFO("IdTag=%s\n", idTagAuthorization);
  12534. return 0;
  12535. }
  12536. static int deleteIdTagcallback(void *data, int argc, char **argv, char **azColName)
  12537. {
  12538. // localversion = argv[5] ? atoi(argv[5]) : 0;
  12539. // printf("localversion=%d\n", localversion);
  12540. return 0;
  12541. }
  12542. //=========================================
  12543. // Sqlite3 related function
  12544. //=========================================
  12545. int sqlite3_exec_callback(void *data, int n_columns, char **col_values, char **col_names)
  12546. {
  12547. for (int i = 0; i < n_columns; i++)
  12548. {
  12549. DEBUG_INFO("%s/t", col_values[i]);
  12550. }
  12551. DEBUG_INFO("/n");
  12552. return 0;
  12553. }
  12554. void OCPP_getListVerion()
  12555. {
  12556. int rc = 0;
  12557. // const char* data = "Callback function called";
  12558. char sql[100];
  12559. char zErrMsg[100];
  12560. memset(sql, 0, 100);
  12561. memset(zErrMsg, 0, 100);
  12562. strcpy(sql, "select * from ocpp_auth_local order by idx");
  12563. /* Execute SQL statement */
  12564. rc = sqlite3_exec(db, sql, versioncallback, 0, (char **)&zErrMsg);
  12565. if( rc != SQLITE_OK )
  12566. {
  12567. DEBUG_INFO("SQL error: %s", zErrMsg);
  12568. }
  12569. }
  12570. void OCPP_getIdTag(char idTag[])
  12571. {
  12572. int rc = 0;
  12573. // const char* data = "Callback function called";
  12574. char sql[100];
  12575. char zErrMsg[100];
  12576. memset(sql, 0, 100);
  12577. memset(zErrMsg, 0, 100);
  12578. memset(idTagAuthorization, 0, sizeof(idTagAuthorization));
  12579. memset(&idTagQuery, 0, sizeof(idTagQuery));
  12580. //DEBUG_INFO("look up card: %s in ocpp_auth_local table", idTag);
  12581. sprintf(sql,"select * from ocpp_auth_local where idtag='%s'", idTag);
  12582. /* Execute SQL statement */
  12583. rc = sqlite3_exec(db, sql, IdTagcallback, 0, (char **)&zErrMsg);
  12584. if( rc != SQLITE_OK )
  12585. {
  12586. DEBUG_INFO("SQL error: %s", zErrMsg);
  12587. }
  12588. //return ver;
  12589. }
  12590. void OCPP_get_TableAuthlocalAllData(void)
  12591. {
  12592. int rc = 0;
  12593. char sql[100];
  12594. char zErrMsg[100];
  12595. memset(sql, 0, 100);
  12596. memset(zErrMsg, 0, 100);
  12597. sprintf(sql,"select * from ocpp_auth_local ");
  12598. /* Execute SQL statement */
  12599. rc = sqlite3_exec(db, sql, &sqlite3_exec_callback, 0,(char **)&zErrMsg);
  12600. if( rc != SQLITE_OK )
  12601. {
  12602. DEBUG_INFO("SQL error: %s", zErrMsg);
  12603. }
  12604. //return ver;
  12605. }
  12606. int OCPP_cleanLocalList()
  12607. {
  12608. char * sqlcleanLocalList = "delete from ocpp_auth_local";
  12609. char *errMsg = 0;
  12610. int rc =sqlite3_exec(db, sqlcleanLocalList, 0, 0, &errMsg);
  12611. if (SQLITE_OK != rc)
  12612. {
  12613. DEBUG_INFO("%s\n",errMsg);
  12614. return FALSE;
  12615. }
  12616. return TRUE;
  12617. }
  12618. int OCPP_addLocalList_1(int version, char *idTag, char *parentTage, char *expiryDate, char *status)
  12619. {
  12620. int isSuccess = FALSE;
  12621. int ret = 0;
  12622. //const char* data = "Callback function called";
  12623. char sql[300];
  12624. char zErrMsg[200];
  12625. memset(sql, 0, 300);
  12626. memset(zErrMsg, 0, 200);
  12627. 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);
  12628. //* Execute SQL statement */
  12629. ret = sqlite3_exec(db, sql, callback, 0, (char **)&zErrMsg);
  12630. if( ret != SQLITE_OK )
  12631. {
  12632. DEBUG_INFO("SQL error: %s\n", zErrMsg);
  12633. return isSuccess;
  12634. }
  12635. memset(sql, 0, 300);
  12636. sprintf(sql, "UPDATE ocpp_auth_local SET version=%d",version);
  12637. ret = sqlite3_exec(db, sql, NULL, NULL, (char **)&zErrMsg);
  12638. if( ret != SQLITE_OK )
  12639. {
  12640. DEBUG_INFO("SQL error: %s\n", zErrMsg);
  12641. return isSuccess;
  12642. }
  12643. isSuccess = TRUE;
  12644. return isSuccess;
  12645. }
  12646. void OCPP_deleteIdTag(char idTag[])
  12647. {
  12648. //int ver = 0;
  12649. //int isSuccess = FALSE;
  12650. int rc = 0;
  12651. char sql[100];
  12652. char zErrMsg[100];
  12653. memset(sql, 0, 100);
  12654. memset(zErrMsg, 0, 100);
  12655. sprintf(sql,"DELETE from ocpp_auth_local where idtag='%s'; SELECT * from ocpp_auth_local;", idTag);
  12656. //* Execute SQL statement */
  12657. rc = sqlite3_exec(db, sql, deleteIdTagcallback, 0,(char **)&zErrMsg);
  12658. if( rc != SQLITE_OK )
  12659. {
  12660. DEBUG_INFO("SQL error: %s", zErrMsg);
  12661. }
  12662. }
  12663. int GetOcppServerURL()
  12664. {
  12665. int result = FALSE;
  12666. memset(OcppProtocol, 0, sizeof(OcppProtocol));
  12667. memset(OcppHost, 0, sizeof(OcppHost));
  12668. memset(OcppTempPath, 0, sizeof(OcppTempPath));
  12669. if((ShmSysConfigAndInfo->SysConfig.OcppServerURL != NULL) && (strcmp((const char *)ShmSysConfigAndInfo->SysConfig.OcppServerURL,"") != 0) )
  12670. {
  12671. #if 1
  12672. sscanf((const char *)ShmSysConfigAndInfo->SysConfig.OcppServerURL,
  12673. "%[^:]:%*2[/]%[^:]:%i/%[a-zA-Z0-9._/-]",
  12674. OcppProtocol, OcppHost, &OcppPort, OcppTempPath);
  12675. #endif
  12676. result = TRUE;
  12677. goto End;
  12678. }
  12679. else if((ShmOCPP16Data->OcppServerURL != NULL) && (strcmp((const char *)ShmOCPP16Data->OcppServerURL,"") != 0))
  12680. {
  12681. sscanf((const char *)ShmOCPP16Data->OcppServerURL,
  12682. "%[^:]:%*2[/]%[^:]:%i/%[a-zA-Z0-9._/-]",
  12683. OcppProtocol, OcppHost, &OcppPort, OcppTempPath);
  12684. result = TRUE;
  12685. goto End;
  12686. }
  12687. else
  12688. {
  12689. strcpy(OcppHost,"");
  12690. }
  12691. End:
  12692. return result;
  12693. }
  12694. int GetOcppPath()
  12695. {
  12696. int result = FALSE;
  12697. if((ShmSysConfigAndInfo->SysConfig.ChargeBoxId != NULL) && (strcmp((const char *)ShmSysConfigAndInfo->SysConfig.ChargeBoxId,"") != 0) )
  12698. {
  12699. if(OcppTempPath == NULL)
  12700. {
  12701. sprintf(OcppPath,"/%s",ShmSysConfigAndInfo->SysConfig.ChargeBoxId);
  12702. }
  12703. else
  12704. {
  12705. sprintf(OcppPath,"/%s%s",OcppTempPath,ShmSysConfigAndInfo->SysConfig.ChargeBoxId);
  12706. }
  12707. result = TRUE;
  12708. goto End;
  12709. }
  12710. else if((ShmOCPP16Data->ChargeBoxId != NULL) && (strcmp((const char *)ShmOCPP16Data->ChargeBoxId,"") != 0))
  12711. {
  12712. if(OcppTempPath == NULL)
  12713. {
  12714. sprintf(OcppPath,"/%s",ShmOCPP16Data->ChargeBoxId);
  12715. }
  12716. else
  12717. {
  12718. sprintf(OcppPath,"/%s%s",OcppTempPath,ShmOCPP16Data->ChargeBoxId);
  12719. }
  12720. result = TRUE;
  12721. goto End;
  12722. }
  12723. else
  12724. {
  12725. strcpy(OcppPath,"");
  12726. }
  12727. End:
  12728. return result;
  12729. }
  12730. int GetOcppPort()
  12731. {
  12732. return OcppPort;
  12733. }
  12734. int GetOcppConnStatus(void)
  12735. {
  12736. return ShmOCPP16Data->OcppConnStatus;
  12737. }
  12738. void SetOcppConnStatus(uint8_t status)
  12739. {
  12740. ShmOCPP16Data->OcppConnStatus = status;
  12741. ShmSysConfigAndInfo->SysInfo.OcppConnStatus = status;
  12742. }
  12743. int GetHeartBeatWithNOResponse(void)
  12744. {
  12745. return HeartBeatWithNOResponse;
  12746. }
  12747. void SetHeartBeatWithNOResponse(void)
  12748. {
  12749. HeartBeatWithNOResponse = 0;
  12750. }
  12751. void GetStartTransactionIdTag(int gun_index)
  12752. {
  12753. memset(StartTransactionIdTagTemp, 0 ,sizeof(StartTransactionIdTagTemp));
  12754. strcpy(StartTransactionIdTagTemp, (const char *)ShmOCPP16Data->StartTransaction[gun_index].IdTag);
  12755. }
  12756. int GetTransactionId(int gunindex, char idTag[])
  12757. {
  12758. char ch;
  12759. FILE *fptr1;
  12760. int temptransactionId;
  12761. char str[100]={0};
  12762. temptransactionId = 0;
  12763. if((strcmp((const char*)idTag, "")==0)||(idTag[0]=='\0'))
  12764. {
  12765. return temptransactionId;
  12766. }
  12767. /*------ Read the file ----------------*/
  12768. fptr1=fopen("/Storage/OCPP/QueueTransactionId", "r");
  12769. if (!fptr1)
  12770. {
  12771. return temptransactionId;
  12772. }
  12773. ch=fgetc(fptr1);
  12774. rewind(fptr1);
  12775. if(ch!=EOF)
  12776. {
  12777. while (fgets(str, 100, fptr1) != NULL)
  12778. {
  12779. str[strlen(str) - 1] = '\0'; // eat the newline fgets() stores
  12780. if(str[0]=='\0')
  12781. {
  12782. break;
  12783. }
  12784. char *revbuf[8] = {0};
  12785. int num = 0;
  12786. splitstring(str,",",revbuf,&num);
  12787. if((revbuf[1][0] != '\0')&&(revbuf[2][0] != '\0'))
  12788. {
  12789. if((atoi(revbuf[0])==gunindex) || (strcmp(revbuf[1],(const char *)idTag)==0))
  12790. {
  12791. temptransactionId = atoi(revbuf[2]);
  12792. break;
  12793. }
  12794. }
  12795. }
  12796. }
  12797. fclose(fptr1);
  12798. /*------- End of reading ---------------*/
  12799. return temptransactionId;
  12800. }
  12801. void SetTransactionIdZero(int transactionId)
  12802. {
  12803. char ch;
  12804. FILE *fptr1, *fptr2;
  12805. int temptransactionId = 0;
  12806. char str[100]={0}, strtemp[100]={0}, temp[] = "/Storage/OCPP/QueueTransactionIdtemp.json";
  12807. fptr1 = fopen("/Storage/OCPP/QueueTransactionId", "r");
  12808. if (!fptr1)
  12809. {
  12810. //printf(" File not found or unable to open the input file!!\n");
  12811. return ;
  12812. }
  12813. fptr2 = fopen(temp, "w"); // open the temporary file in write mode
  12814. if (!fptr2)
  12815. {
  12816. DEBUG_INFO("Unable to open a temporary file to write!!\n");
  12817. fclose(fptr1);
  12818. return ;
  12819. }
  12820. ch=fgetc(fptr1);
  12821. rewind(fptr1);
  12822. if(ch!=EOF)
  12823. {
  12824. // copy all contents to the temporary file except the specific line
  12825. while (fgets(str, 100, fptr1) != NULL)
  12826. {
  12827. str[strlen(str) - 1] = '\0'; // eat the newline fgets() stores
  12828. if(str[0]=='\0')
  12829. {
  12830. break;
  12831. }
  12832. char *revbuf[8] = {0};
  12833. int num = 0;
  12834. strcpy(strtemp, str);
  12835. splitstring(str,",",revbuf,&num);
  12836. if(revbuf[2][0] != '\0')
  12837. {
  12838. temptransactionId = atoi(revbuf[2]);
  12839. if(transactionId != temptransactionId)
  12840. {
  12841. fprintf(fptr2, "%s\n", strtemp);
  12842. }
  12843. }
  12844. }
  12845. }
  12846. fclose(fptr1);
  12847. fclose(fptr2);
  12848. remove("/Storage/OCPP/QueueTransactionId"); // remove the original file
  12849. rename(temp, "/Storage/OCPP/QueueTransactionId"); // rename the temporary file to original name
  12850. /*------ Read the file ----------------*/
  12851. }
  12852. int InternetDisconnect(void)
  12853. {
  12854. return (ShmStatusCodeData->InfoCode.InfoEvents.bits.InternetDisconnectVia4Gi && ShmStatusCodeData->InfoCode.InfoEvents.bits.InternetDisconnectViaEthernet && ShmStatusCodeData->InfoCode.InfoEvents.bits.InternetDisconnectViaWiFi );
  12855. }
  12856. //Note: It is not real StopTransaction. It is temporary StopTransaction.
  12857. void storeTempStopTransaction(int gun_index)
  12858. {
  12859. char guid[37]={0};
  12860. int tempIndex = 0;
  12861. DEBUG_INFO("storeTempStopTransaction...\n");
  12862. memset(queuedata, 0, sizeof(queuedata));
  12863. //ENERGY_ACTIVE_IMPORT_REGISTER
  12864. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DCcc
  12865. if(gunType[gun_index] == 'J')
  12866. {
  12867. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  12868. {
  12869. tempIndex = ((gun_index==2) ? 1: 0);
  12870. }
  12871. else
  12872. {
  12873. tempIndex = gun_index;
  12874. }
  12875. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  12876. {
  12877. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  12878. {
  12879. ShmOCPP16Data->StopTransaction[gun_index].MeterStop = ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PowerConsumption;
  12880. }
  12881. }// END OF CHAdeMO_QUANTITY
  12882. }
  12883. else if((gunType[gun_index] == 'U')||(gunType[gun_index] == 'E'))
  12884. {
  12885. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  12886. {
  12887. tempIndex = ((gun_index==2) ? 1: 0);
  12888. }
  12889. else
  12890. {
  12891. tempIndex = gun_index;
  12892. }
  12893. for (int index = 0; index < CCS_QUANTITY; index++)
  12894. {
  12895. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  12896. {
  12897. ShmOCPP16Data->StopTransaction[gun_index].MeterStop = ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PowerConsumption;
  12898. }
  12899. }// END OF CCS_QUANTITY
  12900. }
  12901. else if(gunType[gun_index] == 'G')
  12902. {
  12903. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  12904. {
  12905. tempIndex = ((gun_index==2) ? 1: 0);
  12906. }
  12907. else
  12908. {
  12909. tempIndex = gun_index;
  12910. }
  12911. for (int index = 0; index < GB_QUANTITY; index++)
  12912. {
  12913. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  12914. {
  12915. ShmOCPP16Data->StopTransaction[gun_index].MeterStop = ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PowerConsumption;
  12916. }
  12917. }// END OF GB_QUANTITY
  12918. }
  12919. else
  12920. {
  12921. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  12922. {
  12923. tempIndex = 2;
  12924. }
  12925. else
  12926. {
  12927. tempIndex = gun_index;
  12928. }
  12929. for (int index = 0; index < AC_QUANTITY; index++)
  12930. {
  12931. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  12932. {
  12933. ShmOCPP16Data->StopTransaction[gun_index].MeterStop = ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PowerConsumption;
  12934. }
  12935. }// END OF AC_QUANTITY
  12936. }
  12937. //Stop Transaction Time
  12938. struct timeval tmnow;
  12939. struct tm *tm;
  12940. char buf[28];//, usec_buf[6];
  12941. gettimeofday(&tmnow, NULL);
  12942. time_t t;
  12943. t = time(NULL);
  12944. /*UTC time and date*/
  12945. tm = gmtime(&t);
  12946. strftime(buf,28,"%Y-%m-%dT%H:%M:%SZ", tm);
  12947. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].Timestamp,buf);
  12948. ShmOCPP16Data->StopTransaction[gun_index].TransactionId = ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId;
  12949. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].IdTag, (const char*)ShmOCPP16Data->StartTransaction[gun_index].IdTag);
  12950. random_uuid(guid);
  12951. /***********************************transactionData******************************************************/
  12952. memset(ShmOCPP16Data->StopTransaction[gun_index].TransactionData, 0, sizeof(sizeof(struct StructMeterValue)));
  12953. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].TimeStamp, buf);
  12954. //=================================
  12955. //1. Transaction_Begin
  12956. //=================================
  12957. // Energy.Active.Export.Interval
  12958. //idx_sample=0;
  12959. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Value, "%.1f",(float)(ShmOCPP16Data->StartTransaction[gun_index].MeterStart)); // MeterStart is 0~6553.5 kWh
  12960. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Context,ReadingContextStr[ReadingContext_Transaction_Begin]);
  12961. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Format,ValueFormatStr[Raw]);
  12962. 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*/]);
  12963. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DCcc
  12964. if((gunType[gun_index] == 'J')||(gunType[gun_index] == 'U')||(gunType[gun_index] == 'E')||(gunType[gun_index] == 'G'))
  12965. {
  12966. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Phase,PhaseStr[L3_N]);
  12967. }
  12968. else
  12969. {
  12970. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Phase,PhaseStr[L1_N]);
  12971. }
  12972. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Location,LocationStr[Location_Outlet]);
  12973. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Unit,UnitOfMeasureStr[UnitOfMeasure_kWh]);
  12974. //=================================
  12975. //2. Transaction_End
  12976. //=================================
  12977. //2.1 Current.Export
  12978. //idx_sample=1;
  12979. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G : GBT DC
  12980. if(gunType[gun_index] == 'J')
  12981. {
  12982. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  12983. {
  12984. tempIndex = ((gun_index==2) ? 1: 0);
  12985. }
  12986. else
  12987. {
  12988. tempIndex = gun_index;
  12989. }
  12990. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  12991. {
  12992. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  12993. {
  12994. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargingCurrent );// PresentChargingCurrent is 0~6553.5 amp
  12995. }
  12996. }// End of for CHAdeMO_QUANTITY
  12997. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase,PhaseStr[L3_N]);
  12998. }
  12999. else if((gunType[gun_index] == 'U')||(gunType[gun_index] == 'E'))
  13000. {
  13001. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  13002. {
  13003. tempIndex = ((gun_index==2) ? 1: 0);
  13004. }
  13005. else
  13006. {
  13007. tempIndex = gun_index;
  13008. }
  13009. for (int index = 0; index < CCS_QUANTITY; index++)
  13010. {
  13011. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  13012. {
  13013. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargingCurrent );// PresentChargingCurrent is 0~6553.5 amp
  13014. }
  13015. }// End of for CCS_QUANTITY
  13016. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase,PhaseStr[L3_N]);
  13017. }
  13018. else if(gunType[gun_index] == 'G')
  13019. {
  13020. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  13021. {
  13022. tempIndex = ((gun_index==2) ? 1: 0);
  13023. }
  13024. else
  13025. {
  13026. tempIndex = gun_index;
  13027. }
  13028. for (int index = 0; index < GB_QUANTITY; index++)
  13029. {
  13030. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  13031. {
  13032. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingCurrent );// PresentChargingCurrent is 0~6553.5 amp
  13033. }
  13034. }// End of for GB_QUANTITY
  13035. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase,PhaseStr[L3_N]);
  13036. }
  13037. else
  13038. {
  13039. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  13040. {
  13041. tempIndex = 2;
  13042. }
  13043. else
  13044. {
  13045. tempIndex = gun_index;
  13046. }
  13047. for (int index = 0; index < AC_QUANTITY; index++)
  13048. {
  13049. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  13050. {
  13051. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingCurrent );// 0~6553.5 amp for EVSE
  13052. }
  13053. }// End of for AC_QUANTITY
  13054. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase,PhaseStr[L1_N]);
  13055. }
  13056. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  13057. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Format,ValueFormatStr[Raw]);
  13058. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Measurand,MeasurandStr[Current_Import]);
  13059. //strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase,PhaseStr[L1_N]);
  13060. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Location,LocationStr[Location_Outlet]);
  13061. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Unit,UnitOfMeasureStr[UnitOfMeasure_A]);
  13062. //2.2 Energy.Active.Export.Interval
  13063. //idx_sample=2;
  13064. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  13065. if(gunType[gun_index] == 'J')
  13066. {
  13067. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  13068. {
  13069. tempIndex = ((gun_index==2) ? 1: 0);
  13070. }
  13071. else
  13072. {
  13073. tempIndex = gun_index;
  13074. }
  13075. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  13076. {
  13077. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  13078. {
  13079. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargedEnergy );// PresentChargedEnergy is 0~6553.5 kWh
  13080. }
  13081. }// END OF CHAdeMO_QUANTITY
  13082. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase,PhaseStr[L3_N]);
  13083. }
  13084. else if((gunType[gun_index] == 'U')||(gunType[gun_index] == 'E'))
  13085. {
  13086. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  13087. {
  13088. tempIndex = ((gun_index==2) ? 1: 0);
  13089. }
  13090. else
  13091. {
  13092. tempIndex = gun_index;
  13093. }
  13094. for (int index = 0; index < CCS_QUANTITY; index++)
  13095. {
  13096. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  13097. {
  13098. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargedEnergy );// PresentChargedEnergy is 0~6553.5 kWh
  13099. }
  13100. }// END OF CCS_QUANTITY
  13101. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase,PhaseStr[L3_N]);
  13102. }
  13103. else if(gunType[gun_index] == 'G')
  13104. {
  13105. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  13106. {
  13107. tempIndex = ((gun_index==2) ? 1: 0);
  13108. }
  13109. else
  13110. {
  13111. tempIndex = gun_index;
  13112. }
  13113. for (int index = 0; index < GB_QUANTITY; index++)
  13114. {
  13115. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  13116. {
  13117. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargedEnergy );// PresentChargedEnergy is 0~6553.5 kWh
  13118. }
  13119. }// END OF GB_QUANTITY
  13120. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase,PhaseStr[L3_N]);
  13121. }
  13122. else
  13123. {
  13124. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  13125. {
  13126. tempIndex = 2;
  13127. }
  13128. else
  13129. {
  13130. tempIndex = gun_index;
  13131. }
  13132. for (int index = 0; index < AC_QUANTITY; index++)
  13133. {
  13134. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  13135. {
  13136. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargedEnergy );// PresentChargedEnergy is 0~6553.5 kWh
  13137. }
  13138. }// END OF AC_QUANTITY
  13139. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase,PhaseStr[L1_N]);
  13140. }
  13141. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  13142. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Format,ValueFormatStr[Raw]);
  13143. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Measurand,MeasurandStr[Energy_Active_Import_Interval]);
  13144. //strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase,PhaseStr[L1_N]);
  13145. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Location,LocationStr[Location_Outlet]);
  13146. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Unit,UnitOfMeasureStr[UnitOfMeasure_kWh]);
  13147. //2.3 Power.Active.Export
  13148. //idx_sample=3;
  13149. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  13150. if(gunType[gun_index] == 'J')
  13151. {
  13152. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  13153. {
  13154. tempIndex = ((gun_index==2) ? 1: 0);
  13155. }
  13156. else
  13157. {
  13158. tempIndex = gun_index;
  13159. }
  13160. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  13161. {
  13162. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  13163. {
  13164. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargingPower );// PresentChargingPower is 0~6553.5 kW
  13165. }
  13166. } // End for CHAdeMO_QUANTITY
  13167. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase,PhaseStr[L3_N]);
  13168. }
  13169. else if((gunType[gun_index] == 'U')||(gunType[gun_index] == 'E'))
  13170. {
  13171. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  13172. {
  13173. tempIndex = ((gun_index==2) ? 1: 0);
  13174. }
  13175. else
  13176. {
  13177. tempIndex = gun_index;
  13178. }
  13179. for (int index = 0; index < CCS_QUANTITY; index++)
  13180. {
  13181. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  13182. {
  13183. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargingPower );// PresentChargingPower is 0~6553.5 kW
  13184. }
  13185. } // END for CCS_QUANTITY
  13186. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase,PhaseStr[L3_N]);
  13187. }
  13188. else if(gunType[gun_index] == 'G')
  13189. {
  13190. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  13191. {
  13192. tempIndex = ((gun_index==2) ? 1: 0);
  13193. }
  13194. else
  13195. {
  13196. tempIndex = gun_index;
  13197. }
  13198. for (int index = 0; index < GB_QUANTITY; index++)
  13199. {
  13200. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  13201. {
  13202. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingPower );// PresentChargingPower is 0~6553.5 kW
  13203. }
  13204. }// END for GB_QUANTITY
  13205. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase,PhaseStr[L3_N]);
  13206. }
  13207. else
  13208. {
  13209. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  13210. {
  13211. tempIndex = 2;
  13212. }
  13213. else
  13214. {
  13215. tempIndex = gun_index;
  13216. }
  13217. for (int index = 0; index < AC_QUANTITY; index++)
  13218. {
  13219. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  13220. {
  13221. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingPower );// PresentChargingPower is 0~6553.5 kW
  13222. }
  13223. } // END for AC_QUANTITY
  13224. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase,PhaseStr[L1_N]);
  13225. }
  13226. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  13227. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Format,ValueFormatStr[Raw]);
  13228. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Measurand,MeasurandStr[Power_Active_Import]);
  13229. //strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase,PhaseStr[L1_N]);
  13230. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Location,LocationStr[Location_Outlet]);
  13231. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Unit,UnitOfMeasureStr[UnitOfMeasure_kW/*UnitOfMeasure_kWh*/]);
  13232. //2.4 Voltage
  13233. //idx_sample=4;
  13234. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  13235. if(gunType[gun_index] == 'J')
  13236. {
  13237. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  13238. {
  13239. tempIndex = ((gun_index==2) ? 1: 0);
  13240. }
  13241. else
  13242. {
  13243. tempIndex = gun_index;
  13244. }
  13245. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  13246. {
  13247. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  13248. {
  13249. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargingVoltage );// PresentChargingVoltage is 0~6553.5 volt
  13250. }
  13251. } // END OF FOR CHAdeMO_QUANTITY
  13252. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase,PhaseStr[L3_N]);
  13253. }
  13254. else if((gunType[gun_index] == 'U')||(gunType[gun_index] == 'E'))
  13255. {
  13256. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  13257. {
  13258. tempIndex = ((gun_index==2) ? 1: 0);
  13259. }
  13260. else
  13261. {
  13262. tempIndex = gun_index;
  13263. }
  13264. for (int index = 0; index < CCS_QUANTITY; index++)
  13265. {
  13266. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  13267. {
  13268. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargingVoltage );// PresentChargingVoltage is 0~6553.5 volt
  13269. }
  13270. } // END OF FOR CCS_QUANTITY
  13271. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase,PhaseStr[L3_N]);
  13272. }
  13273. else if(gunType[gun_index] == 'G')
  13274. {
  13275. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  13276. {
  13277. tempIndex = ((gun_index==2) ? 1: 0);
  13278. }
  13279. else
  13280. {
  13281. tempIndex = gun_index;
  13282. }
  13283. for (int index = 0; index < GB_QUANTITY; index++)
  13284. {
  13285. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  13286. {
  13287. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingVoltage );// PresentChargingVoltage is 0~6553.5 volt
  13288. }
  13289. } // END OF FOR GB_QUANTITY
  13290. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase,PhaseStr[L3_N]);
  13291. }
  13292. else
  13293. {
  13294. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  13295. {
  13296. tempIndex = 2;
  13297. }
  13298. else
  13299. {
  13300. tempIndex = gun_index;
  13301. }
  13302. for (int index = 0; index < AC_QUANTITY; index++)
  13303. {
  13304. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  13305. {
  13306. 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
  13307. }
  13308. } // END OF FOR AC_QUANTITY
  13309. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase,PhaseStr[L1_N]);
  13310. }
  13311. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  13312. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Format,ValueFormatStr[Raw]);
  13313. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Measurand,MeasurandStr[Voltage]);
  13314. //strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase,PhaseStr[L1_N]);
  13315. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Location,LocationStr[Location_Outlet]);
  13316. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Unit,UnitOfMeasureStr[UnitOfMeasure_V]);
  13317. //2.5 SoC
  13318. //idx_sample=5;
  13319. //J : CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  13320. if((gunType[gun_index] == 'J')||(gunType[gun_index] == 'U')||(gunType[gun_index] == 'E')||(gunType[gun_index] == 'G'))
  13321. {
  13322. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  13323. {
  13324. tempIndex = ((gun_index==2) ? 1: 0);
  13325. }
  13326. else
  13327. {
  13328. tempIndex = gun_index;
  13329. }
  13330. if(gunType[gun_index] == 'J')
  13331. {
  13332. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  13333. {
  13334. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  13335. {
  13336. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].EvBatterySoc );// 0~100%
  13337. }
  13338. }
  13339. }
  13340. else if((gunType[gun_index] == 'U')||(gunType[gun_index] == 'E'))
  13341. {
  13342. for (int index = 0; index < CCS_QUANTITY; index++)
  13343. {
  13344. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  13345. {
  13346. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].EvBatterySoc );// 0~100%
  13347. }
  13348. }
  13349. }
  13350. else if(gunType[gun_index] == 'G')
  13351. {
  13352. for (int index = 0; index < GB_QUANTITY; index++)
  13353. {
  13354. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  13355. {
  13356. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].EvBatterySoc );// 0~100%
  13357. }
  13358. }
  13359. }
  13360. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  13361. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Format,ValueFormatStr[Raw]);
  13362. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Measurand,MeasurandStr[SoC/*Energy_Reactive_Export_Register*/]);
  13363. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Phase,PhaseStr[L3_N]);
  13364. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Location,LocationStr[Location_Outlet]);
  13365. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Unit,UnitOfMeasureStr[UnitOfMeasure_Percent/*UnitOfMeasure_kWh*/]);
  13366. } // END FOR DC CASE
  13367. if((gunType[gun_index] == 'J')||(gunType[gun_index] == 'U')||(gunType[gun_index] == 'E')||(gunType[gun_index] == 'G'))
  13368. {
  13369. sprintf(queuedata,"[%d,\"%s\",\"StopTransaction\",{\"idTag\":\"%s\",\"meterStop\":%d,\"timestamp\":\"%s\",\"transactionId\":%d,\"reason\":\"%s\",\"transactionData\":[{\"timestamp\":\"%s\",\"sampledValue\":[{\"value\":\"%s\",\"context\":\"%s\",\"format\":\"%s\",\"measurand\":\"%s\",\"phase\":\"%s\",\"location\":\"%s\",\"unit\":\"%s\"},{\"value\":\"%s\",\"context\":\"%s\",\"format\":\"%s\",\"measurand\":\"%s\",\"phase\":\"%s\",\"location\":\"%s\",\"unit\":\"%s\"},{\"value\":\"%s\",\"context\":\"%s\",\"format\":\"%s\",\"measurand\":\"%s\",\"phase\":\"%s\",\"location\":\"%s\",\"unit\":\"%s\"},{\"value\":\"%s\",\"context\":\"%s\",\"format\":\"%s\",\"measurand\":\"%s\",\"phase\":\"%s\",\"location\":\"%s\",\"unit\":\"%s\"},{\"value\":\"%s\",\"context\":\"%s\",\"format\":\"%s\",\"measurand\":\"%s\",\"phase\":\"%s\",\"location\":\"%s\",\"unit\":\"%s\"},{\"value\":\"%s\",\"context\":\"%s\",\"format\":\"%s\",\"measurand\":\"%s\",\"phase\":\"%s\",\"location\":\"%s\",\"unit\":\"%s\"}]}]}]"
  13370. ,MESSAGE_TYPE_CALL
  13371. ,guid
  13372. ,ShmOCPP16Data->StopTransaction[gun_index].IdTag
  13373. ,ShmOCPP16Data->StopTransaction[gun_index].MeterStop
  13374. ,ShmOCPP16Data->StopTransaction[gun_index].Timestamp
  13375. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionId
  13376. ,"PowerLoss"
  13377. ,(const char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].TimeStamp
  13378. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Value
  13379. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Context
  13380. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Format
  13381. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Measurand
  13382. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Phase
  13383. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Location
  13384. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Unit
  13385. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value
  13386. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Context
  13387. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Format
  13388. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Measurand
  13389. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase
  13390. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Location
  13391. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Unit
  13392. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Value
  13393. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Context
  13394. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Format
  13395. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Measurand
  13396. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase
  13397. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Location
  13398. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Unit
  13399. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Value
  13400. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Context
  13401. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Format
  13402. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Measurand
  13403. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase
  13404. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Location
  13405. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Unit
  13406. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Value
  13407. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Context
  13408. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Format
  13409. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Measurand
  13410. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase
  13411. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Location
  13412. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Unit
  13413. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Value
  13414. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Context
  13415. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Format
  13416. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Measurand
  13417. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Phase
  13418. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Location
  13419. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Unit
  13420. );
  13421. }
  13422. else
  13423. {
  13424. sprintf(queuedata,"[%d,\"%s\",\"StopTransaction\",{\"idTag\":\"%s\",\"meterStop\":%d,\"timestamp\":\"%s\",\"transactionId\":%d,\"reason\":\"%s\",\"transactionData\":[{\"timestamp\":\"%s\",\"sampledValue\":[{\"value\":\"%s\",\"context\":\"%s\",\"format\":\"%s\",\"measurand\":\"%s\",\"phase\":\"%s\",\"location\":\"%s\",\"unit\":\"%s\"},{\"value\":\"%s\",\"context\":\"%s\",\"format\":\"%s\",\"measurand\":\"%s\",\"phase\":\"%s\",\"location\":\"%s\",\"unit\":\"%s\"},{\"value\":\"%s\",\"context\":\"%s\",\"format\":\"%s\",\"measurand\":\"%s\",\"phase\":\"%s\",\"location\":\"%s\",\"unit\":\"%s\"},{\"value\":\"%s\",\"context\":\"%s\",\"format\":\"%s\",\"measurand\":\"%s\",\"phase\":\"%s\",\"location\":\"%s\",\"unit\":\"%s\"},{\"value\":\"%s\",\"context\":\"%s\",\"format\":\"%s\",\"measurand\":\"%s\",\"phase\":\"%s\",\"location\":\"%s\",\"unit\":\"%s\"}]}]}]"
  13425. ,MESSAGE_TYPE_CALL
  13426. ,guid
  13427. ,ShmOCPP16Data->StopTransaction[gun_index].IdTag
  13428. ,ShmOCPP16Data->StopTransaction[gun_index].MeterStop
  13429. ,ShmOCPP16Data->StopTransaction[gun_index].Timestamp
  13430. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionId
  13431. ,"PowerLoss"
  13432. ,(const char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].TimeStamp
  13433. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Value
  13434. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Context
  13435. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Format
  13436. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Measurand
  13437. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Phase
  13438. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Location
  13439. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Unit
  13440. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value
  13441. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Context
  13442. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Format
  13443. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Measurand
  13444. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase
  13445. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Location
  13446. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Unit
  13447. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Value
  13448. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Context
  13449. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Format
  13450. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Measurand
  13451. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase
  13452. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Location
  13453. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Unit
  13454. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Value
  13455. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Context
  13456. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Format
  13457. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Measurand
  13458. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase
  13459. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Location
  13460. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Unit
  13461. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Value
  13462. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Context
  13463. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Format
  13464. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Measurand
  13465. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase
  13466. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Location
  13467. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Unit
  13468. );
  13469. }
  13470. // Check File "TempStopTransaction" Exist
  13471. if((access("/Storage/OCPP/TempStopTransaction",F_OK))!=-1)
  13472. {
  13473. //DEBUG_INFO("TransactionRelatedQueue exist.\n");
  13474. fclose(fopen("/Storage/OCPP/TempStopTransaction", "w"));
  13475. }
  13476. else
  13477. {
  13478. //DEBUG_INFO("TransactionRelatedQueue not exist\n");
  13479. FILE *log = fopen("/Storage/OCPP/TempStopTransaction", "w+");
  13480. if(log == NULL)
  13481. {
  13482. //DEBUG_INFO("Can't Create File TransactionRelatedQueue \n");
  13483. return ;
  13484. }
  13485. else
  13486. {
  13487. fclose(log);
  13488. }
  13489. }
  13490. //Add TempStopTransaction | Update TempStopTransaction
  13491. // open file for writing
  13492. FILE *outfile;
  13493. outfile = fopen ("/Storage/OCPP/TempStopTransaction", "a");
  13494. //DEBUG_INFO("data = %s\n", queuedata);
  13495. fputs(queuedata, outfile);
  13496. fputs("\n", outfile);
  13497. fclose (outfile);
  13498. }
  13499. void checkTempStopTransaction(int gun_index)
  13500. {
  13501. FILE *fptr1;
  13502. char ch;
  13503. char str[1200]={0};
  13504. char guid[37]={0};
  13505. char tempdata[65]={0};
  13506. fptr1 = fopen("/Storage/OCPP/TempStopTransaction", "r");
  13507. if (!fptr1)
  13508. {
  13509. //printf(" File not found or unable to open the input file!!\n");
  13510. return ;
  13511. }
  13512. ch=fgetc(fptr1);
  13513. //printf(" Now the content of the file %s is : \n",fname);
  13514. rewind(fptr1);
  13515. if(ch!=EOF)
  13516. {
  13517. // copy all contents to the temporary file except the specific line
  13518. while (fgets(str, 1200, fptr1) != NULL)
  13519. {
  13520. str[strlen(str) - 1] = '\0'; // eat the newline fgets() stores
  13521. if(str[0]=='\0')
  13522. {
  13523. break;
  13524. }
  13525. //random_uuid(guid);
  13526. strncpy(guid, str+4, 36); //skip 4 bytes( [2," ),copy guid
  13527. sprintf(tempdata, "StopTransaction,%d", (gun_index));
  13528. if(hashmap_operation(HASH_OP_ADD, guid, tempdata) == 1)
  13529. {
  13530. DEBUG_INFO("StopTransaction mapitem pass\n");
  13531. }
  13532. queue_operation(QUEUE_OPERATION_ADD, guid, str );//addq(guid, queuedata); ---> remove temporally
  13533. memset(str,0,sizeof str);
  13534. }
  13535. }
  13536. // fptr1=freopen(NULL,"w",fptr1); // reset the fptr1 again
  13537. fclose(fptr1);
  13538. remove("/Storage/OCPP/TempStopTransaction"); // remove the original file
  13539. }
  13540. void FillStartTransaction(int ConnectorId, unsigned char IdTag[], int MeterStart,int ReservationId,unsigned char Timestamp[])
  13541. {
  13542. ShmOCPP16Data->StartTransaction[ConnectorId-1].ConnectorId = ConnectorId;
  13543. ShmOCPP16Data->StartTransaction[ConnectorId-1].ReservationId = ReservationId;
  13544. ShmOCPP16Data->StartTransaction[ConnectorId-1].MeterStart = MeterStart;
  13545. strcpy((char *)ShmOCPP16Data->StartTransaction[ConnectorId-1].IdTag, (char *)IdTag);
  13546. strcpy((char *)ShmOCPP16Data->StartTransaction[ConnectorId-1].Timestamp,(char *) Timestamp);
  13547. }
  13548. int GetWebSocketPingInterval(void)
  13549. {
  13550. return atoi((const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemData);
  13551. }
  13552. int GetServerSign(void)
  13553. {
  13554. return server_sign;
  13555. }
  13556. void SetServerSign(int value)
  13557. {
  13558. server_sign = value;
  13559. }
  13560. int GetBootNotificationInterval(void)
  13561. {
  13562. return BootNotificationInterval;
  13563. }
  13564. int GetInternetConn(void)
  13565. {
  13566. return ShmSysConfigAndInfo->SysInfo.InternetConn;
  13567. }
  13568. void InitialSystemValue(void)
  13569. {
  13570. int connectorIndex = 0;
  13571. //int valueASCII = 0;
  13572. server_cycle_Status = 120;
  13573. gunTotalNumber=0;
  13574. SystemInitial = 0;
  13575. localversion=0;
  13576. BootNotificationInterval = 0;
  13577. authorizeRetryTimes = 0;
  13578. GunStatusInterval = 10;
  13579. TransactionMessageAttemptsValue = 0;
  13580. TransactionMessageRetryIntervalValue = 0;
  13581. //Hear Beat
  13582. HeartBeatWithNOResponse = 0;
  13583. HeartBeatCountPerHour = 0;
  13584. HeartBeatWaitTime = atoi((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemData);;
  13585. FirstHeartBeat = 0;
  13586. FirmwareStatusNotificationStatus = FIRMWARE_STATUS_IDLE; // Idle
  13587. DiagnosticsStatusNotificationStatus = DIAGNOSTIC_STATUS_IDLE; // Idle
  13588. memset(CurrentChargingProfileScheduleStr, 0, sizeof(CurrentChargingProfileScheduleStr));
  13589. memset(statusModeChage, 0, sizeof(statusModeChage));
  13590. memset(ChademoPreviousSystemStatus, 0, sizeof(ChademoPreviousSystemStatus));
  13591. memset(CcsPreviousSystemStatus, 0, sizeof(CcsPreviousSystemStatus));
  13592. memset(GbPreviousSystemStatus, 0, sizeof(GbPreviousSystemStatus));
  13593. memset(AcPreviousSystemStatus, 0, sizeof(AcPreviousSystemStatus));
  13594. memset(ChademoPreviousConnectorPlugIn, 0, sizeof(ChademoPreviousConnectorPlugIn));
  13595. memset(CcsPreviousConnectorPlugIn, 0, sizeof(CcsPreviousConnectorPlugIn));
  13596. memset(GbPreviousConnectorPlugIn, 0, sizeof(GbPreviousConnectorPlugIn));
  13597. memset(AcPreviousConnectorPlugIn, 0, sizeof(AcPreviousConnectorPlugIn));
  13598. memset(gunType, 0, sizeof(gunType));
  13599. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D') // 'D' means DC
  13600. {
  13601. //check connector / socket type (index: 8, 9, 10)
  13602. for(int index=7; index <10 ; index++)
  13603. {
  13604. if(index != 8)
  13605. {
  13606. // DC Connector
  13607. if ((ShmSysConfigAndInfo->SysConfig.ModelName[index] >= 'A') && (ShmSysConfigAndInfo->SysConfig.ModelName[index] <= 'Z'))
  13608. {
  13609. SystemInitial = SystemInitial + 1;
  13610. gunTotalNumber = gunTotalNumber + 1;
  13611. gunType[connectorIndex] = ShmSysConfigAndInfo->SysConfig.ModelName[index];
  13612. connectorIndex = connectorIndex + 1;
  13613. }
  13614. }
  13615. else
  13616. {
  13617. // AC Connector
  13618. if ((ShmSysConfigAndInfo->SysConfig.ModelName[index] > '0') && (ShmSysConfigAndInfo->SysConfig.ModelName[index] <= '9'))
  13619. {
  13620. SystemInitial = SystemInitial + 1;
  13621. gunTotalNumber = gunTotalNumber + 1;
  13622. gunType[connectorIndex] = ShmSysConfigAndInfo->SysConfig.ModelName[index];
  13623. connectorIndex = connectorIndex + 1;
  13624. }
  13625. }
  13626. }
  13627. //DEBUG_INFO("DC ...\n");
  13628. }
  13629. else if (ShmSysConfigAndInfo->SysConfig.ModelName[0]=='A') //'A' means AC
  13630. {
  13631. //check connector / socket type (index: 8, 9, 10)
  13632. for(int index=7; index <10 ; index++)
  13633. {
  13634. if ((ShmSysConfigAndInfo->SysConfig.ModelName[index] > '0') && (ShmSysConfigAndInfo->SysConfig.ModelName[index] <= '9'))
  13635. {
  13636. SystemInitial = SystemInitial + 1;
  13637. gunTotalNumber = gunTotalNumber + 1;
  13638. gunType[connectorIndex] = ShmSysConfigAndInfo->SysConfig.ModelName[index];
  13639. connectorIndex = connectorIndex + 1;
  13640. //DEBUG_INFO("AC: %d, %c\n", index, ShmSysConfigAndInfo->SysConfig.ModelName[index]);
  13641. }
  13642. }
  13643. }
  13644. //Status && ConnectorPlugIn Setting
  13645. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  13646. {
  13647. ChademoPreviousSystemStatus[index]= ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PreviousSystemStatus;
  13648. ChademoPreviousConnectorPlugIn[index] = ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ConnectorPlugIn;
  13649. }
  13650. for (int index = 0; index < CCS_QUANTITY; index++)
  13651. {
  13652. CcsPreviousSystemStatus[index] = ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PreviousSystemStatus;
  13653. CcsPreviousConnectorPlugIn[index] = ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ConnectorPlugIn;
  13654. }
  13655. for (int index = 0; index < GB_QUANTITY; index++)
  13656. {
  13657. GbPreviousSystemStatus[index] = ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PreviousSystemStatus;
  13658. GbPreviousConnectorPlugIn[index] = ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ConnectorPlugIn;
  13659. }
  13660. for (int index = 0; index < AC_QUANTITY; index++)
  13661. {
  13662. AcPreviousSystemStatus[index]= ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PreviousSystemStatus;
  13663. AcPreviousConnectorPlugIn[index] = ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PilotState;
  13664. }
  13665. for(int gun_index=0; gun_index < gunTotalNumber; gun_index++ )
  13666. {
  13667. cpinitateMsg.bits[gun_index].StatusNotificationReq = 0;
  13668. cpinitateMsg.bits[gun_index].StatusNotificationConf = 0;
  13669. clientTime.MeterValues[gun_index] = time((time_t*)NULL);
  13670. clientTime.StatusNotification[gun_index] = time((time_t*)NULL);
  13671. }
  13672. // Charger PRE_SYS_MODE
  13673. memset(PRE_SYS_MODE, 0, sizeof(PRE_SYS_MODE));
  13674. memset( (void *)unknownkey, 0, sizeof(unknownkey));
  13675. clientTime.Heartbeat=time((time_t*)NULL);
  13676. sleep(1);
  13677. }
  13678. void LWS_Send(char * str)
  13679. {
  13680. //=====================================================
  13681. // Check InternetConn 0: disconnected, 1: connected
  13682. //====================================================
  13683. if(ShmSysConfigAndInfo->SysInfo.InternetConn == 0)
  13684. {
  13685. DEBUG_INFO("\n offline now !!!\n");
  13686. return;
  13687. }
  13688. pthread_mutex_lock(&lock);
  13689. memset(SendBuffer, 0, SendBufLen);
  13690. sprintf((char *)SendBuffer, "%s", str);
  13691. pthread_mutex_unlock(&lock);
  13692. lws_callback_on_writable(wsi_client);
  13693. lws_service(context, 100);//timeout_ms
  13694. }